import type { Model, ModelCtor, ModelOptions, Sequelize, Options, QueryInterface, FindOptions, CountOptions, CreateOptions, UpdateOptions, DestroyOptions, SyncOptions, } from 'sequelize'; import type { JsonObject } from 'type-fest'; import type { DownToOptions, UpToOptions, Migration } from 'umzug'; import type { JSONSchema4 } from 'json-schema'; export type { JSONSchema4 } from 'json-schema'; export * from 'sequelize'; interface UmzugInterface { run(script: string): Promise; up(opts?: UpToOptions): Promise; down(opts?: DownToOptions): Promise; next(): Promise; prev(): Promise; status(): { pending: string[], executed: string[], }; } interface UmzugMigrateCallback { (query: QueryInterface, sequelize: Sequelize, promise?: typeof Promise): Promise; } type UmzugMigrateOptions = { configFile?: string; baseDir?: string; logging?: boolean | ((sql: string, timing?: number) => void); database?: { modelName?: string; tableName?: string; columnName?: string; }; }; interface ConnectionSettings extends Options { connection?: string; } interface JSONSchemaSequelizerMap { (def: ModelDefinition, name: string, sequelize: Sequelize): ModelDefinition; } export type JSONSchemaSequelizerRefs = JSONSchema4[] | { [k: string]: JSONSchema4 }; export type JSONSchemaSequelizerDefs = { definitions?: { [k: string]: JSONSchema4 } }; declare function JSONSchemaSequelizer(settings: ConnectionSettings, refs?: JSONSchemaSequelizerRefs, cwd?: string): ResourceRepository; declare namespace JSONSchemaSequelizer { var migrate: { (sequelize: Sequelize, options: { [key: string]: UmzugMigrateCallback }, bind: true): { [key: string]: () => Promise }; (sequelize: Sequelize, options: UmzugMigrateOptions, bind?: boolean): UmzugInterface; } var bundle: (schemas: JSONSchema4[], definitions?: string | { [k: string]: JSONSchema4 }, description?: string) => void; var generate: (dump: JSONSchemaSequelizerDefs | null, models: Model[], squash?: boolean, globalOptions?: ModelOptions) => void; var scan: (cwd: string, cb: JSONSchemaSequelizerMap) => ModelDefinition[]; var refs: (cwd: string, prefix?: string) => JSONSchema4[]; var sync: (deps: Model[], opts?: SyncOptions) => Promise; var clear: (deps: Model[], opts?: DestroyOptions) => Promise; } export interface JSONSchemaSequelizerInterface { add(model: ModelDefinition, isClass: true): ModelCtor; add(model: ModelDefinition, isClass?: boolean): this; scan(cb: Function): this; refs(cwd: string, prefix: string): this; sync(opts: SyncOptions): Promise; close(): this; ready(cb: Function): this; connect(): Promise; } export interface ResourceRepositoryOf extends JSONSchemaSequelizerInterface { resource(name: keyof DB, opts?: ResourceOptions): ResourceModel; } export interface ResourceRepository extends JSONSchemaSequelizerInterface { resource(name: string, opts?: ResourceOptions): ResourceModel; } export interface ResourceAttachment { path: string; name?: string; size?: number; type?: string; lastModifiedDate?: string; } export interface ResourceOptions { keys?: string[]; where?: string; reload?: boolean; payload?: JsonObject; logging?: boolean | ((sql: string, timing?: number) => void); fallthrough?: boolean; attachments?: { files?: { [key: string]: ResourceAttachment | ResourceAttachment[]; }; baseDir?: string; uploadDir?: string; }; upload?(params: { payload: JsonObject, metadata: ResourceAttachment, destFile: string, field: string, schema: JSONSchema4, }): Promise; } export interface ResourceModel { options: { model: string; refs: { [key: string]: JSONSchema4 }; schema: JSONSchema4; uiSchema: JsonObject; attributes: JsonObject; }; actions: { update(payload: JsonObject, opts?: UpdateOptions): Promise<[number, number | undefined]>; create(payload: JsonObject, opts?: CreateOptions): Promise<[T, JsonObject]>; findAll(opts?: FindOptions): Promise; findOne(opts?: FindOptions): Promise; destroy(opts?: DestroyOptions): Promise; count(opts?: CountOptions): Promise; }; } export interface ModelDefinition { $class?: ModelCtor; $schema: JSONSchema4; $uiSchema?: JsonObject; $attributes?: ModelAttributes; } export interface ModelAttributes { findAll?: ModelAttribute[]; findOne?: ModelAttribute[]; destroy?: ModelAttribute[]; create?: ModelAttribute[]; update?: ModelAttribute[]; count?: ModelAttribute[]; } export type ModelAttribute = string | { prop: string };