-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
149 lines (131 loc) · 4.67 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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<void>;
up(opts?: UpToOptions): Promise<Migration[]>;
down(opts?: DownToOptions): Promise<Migration[]>;
next(): Promise<Migration[]>;
prev(): Promise<Migration[]>;
status(): {
pending: string[],
executed: string[],
};
}
interface UmzugMigrateCallback {
(query: QueryInterface, sequelize: Sequelize, promise?: typeof Promise): Promise<Migration[]>;
}
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<void> };
(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<Model>;
var clear: (deps: Model[], opts?: DestroyOptions) => Promise<number[]>;
}
export interface JSONSchemaSequelizerInterface {
add(model: ModelDefinition, isClass: true): ModelCtor<Model>;
add(model: ModelDefinition, isClass?: boolean): this;
scan(cb: Function): this;
refs(cwd: string, prefix: string): this;
sync(opts: SyncOptions): Promise<this>;
close(): this;
ready(cb: Function): this;
connect(): Promise<this>;
}
export interface ResourceRepositoryOf<DB> extends JSONSchemaSequelizerInterface {
resource<M extends Model>(name: keyof DB, opts?: ResourceOptions): ResourceModel<M>;
}
export interface ResourceRepository extends JSONSchemaSequelizerInterface {
resource<M extends Model>(name: string, opts?: ResourceOptions): ResourceModel<M>;
}
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<void>;
}
export interface ResourceModel<T> {
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<T[]>;
findOne(opts?: FindOptions): Promise<T | null>;
destroy(opts?: DestroyOptions): Promise<number>;
count(opts?: CountOptions): Promise<number>;
};
}
export interface ModelDefinition {
$class?: ModelCtor<Model>;
$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 };