@orion-js/migrations 3.11.9 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +219745 -0
- package/dist/index.d.ts +647 -0
- package/dist/index.js +219719 -0
- package/package.json +26 -21
- package/LICENSE +0 -21
- package/lib/MigrationsService.d.ts +0 -9
- package/lib/MigrationsService.js +0 -70
- package/lib/Repo.d.ts +0 -7
- package/lib/Repo.js +0 -35
- package/lib/Schema.d.ts +0 -6
- package/lib/Schema.js +0 -30
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -21
- package/lib/index.test.d.ts +0 -1
- package/lib/index.test.js +0 -96
- package/lib/loadMigrations/index.d.ts +0 -5
- package/lib/loadMigrations/index.js +0 -30
- package/lib/service/index.d.ts +0 -10
- package/lib/service/index.js +0 -29
- package/lib/service/index.test.d.ts +0 -1
- package/lib/service/index.test.js +0 -40
- package/lib/tests/setup.d.ts +0 -1
- package/lib/tests/setup.js +0 -19
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import * as MongoDB from 'mongodb';
|
|
4
|
+
import { Db, MongoClient } from 'mongodb';
|
|
5
|
+
|
|
6
|
+
export interface Options {
|
|
7
|
+
lockTime?: number;
|
|
8
|
+
omitJob?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function loadMigrations(migrationServices: any[], options?: Options): MigrationExecutable[];
|
|
11
|
+
export type Blackbox = {
|
|
12
|
+
[name: string]: any;
|
|
13
|
+
};
|
|
14
|
+
export type LogFunction = (message: string, metadata?: any) => void;
|
|
15
|
+
export interface OrionLogger {
|
|
16
|
+
debug: LogFunction;
|
|
17
|
+
info: LogFunction;
|
|
18
|
+
warn: LogFunction;
|
|
19
|
+
error: LogFunction;
|
|
20
|
+
addContext: (module: NodeJS.Module) => OrionLogger;
|
|
21
|
+
addMetadata: (metadata: any) => OrionLogger;
|
|
22
|
+
}
|
|
23
|
+
export interface JobToRun {
|
|
24
|
+
jobId: string;
|
|
25
|
+
executionId: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: "event" | "recurrent";
|
|
28
|
+
params: Blackbox;
|
|
29
|
+
tries: number;
|
|
30
|
+
lockTime: number;
|
|
31
|
+
priority: number;
|
|
32
|
+
uniqueIdentifier?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ExecutionContext {
|
|
35
|
+
record: JobToRun;
|
|
36
|
+
definition: JobDefinition;
|
|
37
|
+
tries: number;
|
|
38
|
+
logger: OrionLogger;
|
|
39
|
+
extendLockTime: (extraTime: number) => Promise<void>;
|
|
40
|
+
clearStaleTimeout: () => void;
|
|
41
|
+
}
|
|
42
|
+
export interface JobRetryResultBase {
|
|
43
|
+
action: "retry" | "dismiss";
|
|
44
|
+
}
|
|
45
|
+
export type JobRetryResultRunIn = JobRetryResultBase & {
|
|
46
|
+
runIn: number;
|
|
47
|
+
};
|
|
48
|
+
export type JobRetryResultRunAt = JobRetryResultBase & {
|
|
49
|
+
runAt: Date;
|
|
50
|
+
};
|
|
51
|
+
export type JobRetryResult = JobRetryResultRunIn | JobRetryResultRunAt | JobRetryResultBase;
|
|
52
|
+
export interface BaseJobDefinition {
|
|
53
|
+
/**
|
|
54
|
+
* The function to execute when the job is executed.
|
|
55
|
+
*/
|
|
56
|
+
resolve: (params: Blackbox, context: ExecutionContext) => Promise<Blackbox | void>;
|
|
57
|
+
/**
|
|
58
|
+
* Called if the job fails.
|
|
59
|
+
*/
|
|
60
|
+
onError?: (error: Error, params: Blackbox, context: ExecutionContext) => Promise<JobRetryResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Called if the job locktime is expired. The job will be executed again.
|
|
63
|
+
*/
|
|
64
|
+
onStale?: (params: Blackbox, context: ExecutionContext) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Save the executions of the job time in milliseconds. Default is 1 week. Set to 0 to disable.
|
|
67
|
+
*/
|
|
68
|
+
saveExecutionsFor?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface RecurrentJobDefinition extends BaseJobDefinition {
|
|
71
|
+
/**
|
|
72
|
+
* Type of the job.
|
|
73
|
+
*/
|
|
74
|
+
type: "recurrent";
|
|
75
|
+
/**
|
|
76
|
+
* A function executed after each execution that returns the date of the next run.
|
|
77
|
+
*/
|
|
78
|
+
getNextRun?: () => Date;
|
|
79
|
+
/**
|
|
80
|
+
* Run every x milliseconds. This will be ignored if getNextRun is defined.
|
|
81
|
+
*/
|
|
82
|
+
runEvery?: number;
|
|
83
|
+
/**
|
|
84
|
+
* The priority of the job. Higher is more priority. Default is 100.
|
|
85
|
+
*/
|
|
86
|
+
priority?: number;
|
|
87
|
+
}
|
|
88
|
+
export interface EventJobDefinition extends BaseJobDefinition {
|
|
89
|
+
/**
|
|
90
|
+
* Type of the job.
|
|
91
|
+
*/
|
|
92
|
+
type: "event";
|
|
93
|
+
}
|
|
94
|
+
export type JobDefinition = RecurrentJobDefinition | EventJobDefinition;
|
|
95
|
+
export interface MigrationServiceOptions {
|
|
96
|
+
name: string;
|
|
97
|
+
useMongoTransactions: false;
|
|
98
|
+
}
|
|
99
|
+
export declare function MigrationService(options: MigrationServiceOptions): ClassDecorator;
|
|
100
|
+
export type MigrationExecutable = {
|
|
101
|
+
runMigration(context: ExecutionContext): Promise<void>;
|
|
102
|
+
} & MigrationServiceOptions;
|
|
103
|
+
export declare function getMigrationsFromServices(services: any[]): MigrationExecutable[];
|
|
104
|
+
export declare class MigrationsService {
|
|
105
|
+
private migrationsRepo;
|
|
106
|
+
getNextMigration(migrationsList: MigrationExecutable[]): Promise<MigrationExecutable>;
|
|
107
|
+
runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext): Promise<void>;
|
|
108
|
+
runMigration(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
|
|
109
|
+
runAsTransaction(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
112
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
113
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
114
|
+
export interface StoredCacheData {
|
|
115
|
+
value: any;
|
|
116
|
+
expires?: Date;
|
|
117
|
+
}
|
|
118
|
+
export interface SetCacheOptions {
|
|
119
|
+
ttl?: number;
|
|
120
|
+
}
|
|
121
|
+
export interface GetCacheOptions {
|
|
122
|
+
ttl?: number;
|
|
123
|
+
fallback?(): Promise<any>;
|
|
124
|
+
}
|
|
125
|
+
export interface OrionCache {
|
|
126
|
+
/**
|
|
127
|
+
* Save data in the cache
|
|
128
|
+
*/
|
|
129
|
+
set(key: string, value: any, options?: SetCacheOptions): Promise<void> | void;
|
|
130
|
+
/**
|
|
131
|
+
* Get data from the cache
|
|
132
|
+
*/
|
|
133
|
+
get(key: string, options?: GetCacheOptions): Promise<StoredCacheData>;
|
|
134
|
+
/**
|
|
135
|
+
* Removes data from the cache
|
|
136
|
+
*/
|
|
137
|
+
invalidate(key: string): Promise<void> | void;
|
|
138
|
+
}
|
|
139
|
+
type Blackbox$1 = {
|
|
140
|
+
[name: string]: any;
|
|
141
|
+
};
|
|
142
|
+
export type ModelResolverResolve = (item: any, params: any, viewer: any, info?: any) => Promise<any>;
|
|
143
|
+
export type GlobalCheckPermissions = (params: any, viewer: any, info?: any) => Promise<string | void>;
|
|
144
|
+
export type ModelCheckPermissions = (parent: any, params: any, viewer: any, info?: any) => Promise<string | void>;
|
|
145
|
+
export type GlobalGetCacheKey = (params: any, viewer: any, info: any) => Promise<any>;
|
|
146
|
+
export type ModelGetCacheKey = (parent: any, params: any, viewer: any, info: any) => Promise<any>;
|
|
147
|
+
export interface ExecuteOptions {
|
|
148
|
+
params: Blackbox$1;
|
|
149
|
+
viewer: any;
|
|
150
|
+
parent?: any;
|
|
151
|
+
info?: any;
|
|
152
|
+
options: ResolverOptions;
|
|
153
|
+
}
|
|
154
|
+
export type Parameters$1<T> = T extends (...args: infer P) => any ? P : never;
|
|
155
|
+
export type ReturnType$1<T> = T extends (...args: any) => infer R ? R : any;
|
|
156
|
+
export type ResolverParams<Resolve, IsModel> = IsModel extends undefined ? Parameters$1<Resolve>[0] : Parameters$1<Resolve>[1];
|
|
157
|
+
export interface ExecuteParams<Resolve = Function, IsModel = undefined> {
|
|
158
|
+
params?: ResolverParams<Resolve, IsModel>;
|
|
159
|
+
viewer?: any;
|
|
160
|
+
parent?: IsModel extends undefined ? undefined : Parameters$1<Resolve>[0];
|
|
161
|
+
info?: any;
|
|
162
|
+
}
|
|
163
|
+
export type Execute<Resolve = Function, IsModel = undefined> = (executeOptions: ExecuteParams<Resolve, IsModel>) => ReturnType$1<Resolve>;
|
|
164
|
+
export interface SharedResolverOptions {
|
|
165
|
+
resolverId?: string;
|
|
166
|
+
params?: any;
|
|
167
|
+
returns?: any;
|
|
168
|
+
mutation?: boolean;
|
|
169
|
+
private?: boolean;
|
|
170
|
+
checkPermission?: GlobalCheckPermissions | ModelCheckPermissions;
|
|
171
|
+
getCacheKey?: GlobalGetCacheKey | ModelGetCacheKey;
|
|
172
|
+
cache?: number;
|
|
173
|
+
cacheProvider?: OrionCache;
|
|
174
|
+
permissionsOptions?: any;
|
|
175
|
+
middlewares?: ResolverMiddleware[];
|
|
176
|
+
}
|
|
177
|
+
export interface ResolverOptions<Resolve = Function> extends SharedResolverOptions {
|
|
178
|
+
resolve: Resolve;
|
|
179
|
+
}
|
|
180
|
+
export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
181
|
+
export interface Resolver<Resolve = Function, IsModel = undefined> extends SharedResolverOptions {
|
|
182
|
+
execute: Execute<Resolve, IsModel>;
|
|
183
|
+
resolve: Resolve;
|
|
184
|
+
modelResolve: IsModel extends undefined ? undefined : OmitFirstArg<Resolve>;
|
|
185
|
+
}
|
|
186
|
+
export type ModelResolver<Resolve = Function> = Resolver<Resolve, true>;
|
|
187
|
+
export type ResolverMiddleware = (executeOptions: ExecuteOptions, next: () => Promise<any>) => Promise<any>;
|
|
188
|
+
export interface FieldType {
|
|
189
|
+
name: string;
|
|
190
|
+
validate: ValidateFunction;
|
|
191
|
+
clean: CleanFunction;
|
|
192
|
+
meta?: any;
|
|
193
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
194
|
+
_isFieldType: boolean;
|
|
195
|
+
}
|
|
196
|
+
export type Constructor<T> = new (...args: any[]) => T;
|
|
197
|
+
export type FieldTypesList = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
|
|
198
|
+
export type TypedModelOnSchema = Function;
|
|
199
|
+
export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
|
|
200
|
+
export type SchemaRecursiveNodeTypeExtras = {
|
|
201
|
+
_isFieldType?: boolean;
|
|
202
|
+
__clean?: CleanFunction;
|
|
203
|
+
__validate?: ValidateFunction;
|
|
204
|
+
__skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
|
|
205
|
+
};
|
|
206
|
+
export interface Schema {
|
|
207
|
+
[key: string]: SchemaNode | Function;
|
|
208
|
+
}
|
|
209
|
+
export type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
|
|
210
|
+
export type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
|
|
211
|
+
export type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
|
|
212
|
+
export type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
|
|
213
|
+
export type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
|
|
214
|
+
export interface SchemaNode {
|
|
215
|
+
/**
|
|
216
|
+
* The type of the field. Used for type validations. Can also contain a subschema.
|
|
217
|
+
*/
|
|
218
|
+
type: SchemaMetaFieldType;
|
|
219
|
+
/**
|
|
220
|
+
* Defaults to false
|
|
221
|
+
*/
|
|
222
|
+
optional?: boolean;
|
|
223
|
+
allowedValues?: Array<any>;
|
|
224
|
+
defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
|
|
225
|
+
/**
|
|
226
|
+
* Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
|
|
227
|
+
*/
|
|
228
|
+
validate?: ValidateFunction;
|
|
229
|
+
/**
|
|
230
|
+
* Function that preprocesses a value before it is set.
|
|
231
|
+
*/
|
|
232
|
+
clean?: CleanFunction;
|
|
233
|
+
autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
|
|
234
|
+
/**
|
|
235
|
+
* The minimum value if it's a number, the minimum length if it's a string or array.
|
|
236
|
+
*/
|
|
237
|
+
min?: number;
|
|
238
|
+
/**
|
|
239
|
+
* The maximum value if it's a number, the maximum length if it's a string or array.
|
|
240
|
+
*/
|
|
241
|
+
max?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Internal use only.
|
|
244
|
+
*/
|
|
245
|
+
isBlackboxChild?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* @deprecated
|
|
248
|
+
*/
|
|
249
|
+
custom?: ValidateFunction;
|
|
250
|
+
/**
|
|
251
|
+
* Used in GraphQL. If true, the field will be omitted from the schema.
|
|
252
|
+
*/
|
|
253
|
+
private?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Used in GraphQL. When in GraphQL, this resolver will replace the static field.
|
|
256
|
+
*/
|
|
257
|
+
graphQLResolver?: (...args: any) => any;
|
|
258
|
+
/**
|
|
259
|
+
* Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
|
|
260
|
+
*/
|
|
261
|
+
key?: string;
|
|
262
|
+
/**
|
|
263
|
+
* The name that would be displayed in a front-end form
|
|
264
|
+
*/
|
|
265
|
+
label?: string;
|
|
266
|
+
/**
|
|
267
|
+
* The description that would be displayed in a front-end form
|
|
268
|
+
*/
|
|
269
|
+
description?: string;
|
|
270
|
+
/**
|
|
271
|
+
* The placeholder that would be displayed in a front-end form
|
|
272
|
+
*/
|
|
273
|
+
placeholder?: string;
|
|
274
|
+
/**
|
|
275
|
+
* The field type that would be used in a front-end form
|
|
276
|
+
*/
|
|
277
|
+
fieldType?: string;
|
|
278
|
+
/**
|
|
279
|
+
* The field options that will be passed as props to the front-end field
|
|
280
|
+
*/
|
|
281
|
+
fieldOptions?: any;
|
|
282
|
+
}
|
|
283
|
+
export interface CurrentNodeInfoOptions {
|
|
284
|
+
autoConvert?: boolean;
|
|
285
|
+
filter?: boolean;
|
|
286
|
+
trimStrings?: boolean;
|
|
287
|
+
removeEmptyStrings?: boolean;
|
|
288
|
+
forceDoc?: any;
|
|
289
|
+
omitRequired?: boolean;
|
|
290
|
+
}
|
|
291
|
+
export interface CurrentNodeInfo {
|
|
292
|
+
/**
|
|
293
|
+
* The global schema, prefaced by {type: {...}} to be compatible with subschemas
|
|
294
|
+
* Sometimes it's given without {type: {...}}. TODO: Normalize this.
|
|
295
|
+
*/
|
|
296
|
+
schema?: SchemaNode | Schema;
|
|
297
|
+
/**
|
|
298
|
+
* The current node subschema
|
|
299
|
+
*/
|
|
300
|
+
currentSchema?: Partial<SchemaNode>;
|
|
301
|
+
value: any;
|
|
302
|
+
doc?: any;
|
|
303
|
+
currentDoc?: any;
|
|
304
|
+
options?: CurrentNodeInfoOptions;
|
|
305
|
+
args?: any[];
|
|
306
|
+
type?: SchemaMetaFieldType;
|
|
307
|
+
keys?: string[];
|
|
308
|
+
addError?: (keys: string[], code: string | object) => void;
|
|
309
|
+
}
|
|
310
|
+
export interface ModelResolversMap {
|
|
311
|
+
[key: string]: ModelResolver<ModelResolverResolve>;
|
|
312
|
+
}
|
|
313
|
+
export interface CloneOptions {
|
|
314
|
+
name: string;
|
|
315
|
+
omitFields?: string[];
|
|
316
|
+
pickFields?: string[];
|
|
317
|
+
mapFields?: (field: any, key: string) => any;
|
|
318
|
+
extendSchema?: Schema;
|
|
319
|
+
extendResolvers?: ModelResolversMap;
|
|
320
|
+
}
|
|
321
|
+
export interface Model<TSchema = any> {
|
|
322
|
+
__isModel: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* The name of the model, used for example for GraphQL
|
|
325
|
+
*/
|
|
326
|
+
name: string;
|
|
327
|
+
/**
|
|
328
|
+
* Returns the schema of the model
|
|
329
|
+
*/
|
|
330
|
+
getSchema: () => Schema & {
|
|
331
|
+
__model: Model;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Returns the schema without adding __model to the schema
|
|
335
|
+
*/
|
|
336
|
+
getCleanSchema: () => Schema;
|
|
337
|
+
/**
|
|
338
|
+
* Returns the model resolvers
|
|
339
|
+
*/
|
|
340
|
+
getResolvers: () => ModelResolversMap;
|
|
341
|
+
/**
|
|
342
|
+
* Adds the model resolvers to a item
|
|
343
|
+
*/
|
|
344
|
+
initItem: (item: any) => any;
|
|
345
|
+
/**
|
|
346
|
+
* Validates an item using @orion-js/schema
|
|
347
|
+
*/
|
|
348
|
+
validate: (item: any) => Promise<any>;
|
|
349
|
+
/**
|
|
350
|
+
* Cleans an item using @orion-js/schema
|
|
351
|
+
*/
|
|
352
|
+
clean: (item: any) => Promise<TSchema>;
|
|
353
|
+
/**
|
|
354
|
+
* Cleans and validates an item using @orion-js/schema
|
|
355
|
+
*/
|
|
356
|
+
cleanAndValidate: (item: any) => Promise<TSchema>;
|
|
357
|
+
/**
|
|
358
|
+
* Creates a new model using this one as a base
|
|
359
|
+
*/
|
|
360
|
+
clone: (cloneOptions: CloneOptions) => Model;
|
|
361
|
+
/**
|
|
362
|
+
* The type of the model. Only use this in typescript
|
|
363
|
+
*/
|
|
364
|
+
type: TSchema;
|
|
365
|
+
}
|
|
366
|
+
export interface FieldType$1 {
|
|
367
|
+
name: string;
|
|
368
|
+
validate: ValidateFunction$1;
|
|
369
|
+
clean: CleanFunction$1;
|
|
370
|
+
meta?: any;
|
|
371
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
372
|
+
_isFieldType: boolean;
|
|
373
|
+
}
|
|
374
|
+
export type Constructor$1<T> = new (...args: any[]) => T;
|
|
375
|
+
export type Blackbox$1 = {
|
|
376
|
+
[name: string]: any;
|
|
377
|
+
};
|
|
378
|
+
export type FieldTypesList$1 = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
|
|
379
|
+
export type TypedModelOnSchema$1 = Function;
|
|
380
|
+
export type ConstructorsTypesList$1 = Constructor$1<String> | Constructor$1<Number> | Constructor$1<Boolean> | Constructor$1<Date>;
|
|
381
|
+
export type SchemaRecursiveNodeTypeExtras$1 = {
|
|
382
|
+
_isFieldType?: boolean;
|
|
383
|
+
__clean?: CleanFunction$1;
|
|
384
|
+
__validate?: ValidateFunction$1;
|
|
385
|
+
__skipChildValidation?: (value: any, info: CurrentNodeInfo$1) => Promise<boolean>;
|
|
386
|
+
};
|
|
387
|
+
export interface Schema$1 {
|
|
388
|
+
[key: string]: SchemaNode$1 | Function;
|
|
389
|
+
}
|
|
390
|
+
export type SchemaRecursiveNodeType$1 = Schema$1 & SchemaRecursiveNodeTypeExtras$1;
|
|
391
|
+
export type SchemaMetaFieldTypeSingle$1 = FieldTypesList$1 | ConstructorsTypesList$1 | SchemaRecursiveNodeType$1 | FieldType$1 | TypedModelOnSchema$1;
|
|
392
|
+
export type SchemaMetaFieldType$1 = SchemaMetaFieldTypeSingle$1 | SchemaMetaFieldTypeSingle$1[];
|
|
393
|
+
export type ValidateFunction$1 = (value: any, info?: Partial<CurrentNodeInfo$1>, ...args: any[]) => object | string | void | Promise<object | string | void>;
|
|
394
|
+
export type CleanFunction$1 = (value: any, info?: Partial<CurrentNodeInfo$1>, ...args: any[]) => any | Promise<any>;
|
|
395
|
+
export interface SchemaNode$1 {
|
|
396
|
+
/**
|
|
397
|
+
* The type of the field. Used for type validations. Can also contain a subschema.
|
|
398
|
+
*/
|
|
399
|
+
type: SchemaMetaFieldType$1;
|
|
400
|
+
/**
|
|
401
|
+
* Defaults to false
|
|
402
|
+
*/
|
|
403
|
+
optional?: boolean;
|
|
404
|
+
allowedValues?: Array<any>;
|
|
405
|
+
defaultValue?: ((info: CurrentNodeInfo$1, ...args: any[]) => any | Promise<any>) | any;
|
|
406
|
+
/**
|
|
407
|
+
* Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
|
|
408
|
+
*/
|
|
409
|
+
validate?: ValidateFunction$1;
|
|
410
|
+
/**
|
|
411
|
+
* Function that preprocesses a value before it is set.
|
|
412
|
+
*/
|
|
413
|
+
clean?: CleanFunction$1;
|
|
414
|
+
autoValue?: (value: any, info: CurrentNodeInfo$1, ...args: any[]) => any | Promise<any>;
|
|
415
|
+
/**
|
|
416
|
+
* The minimum value if it's a number, the minimum length if it's a string or array.
|
|
417
|
+
*/
|
|
418
|
+
min?: number;
|
|
419
|
+
/**
|
|
420
|
+
* The maximum value if it's a number, the maximum length if it's a string or array.
|
|
421
|
+
*/
|
|
422
|
+
max?: number;
|
|
423
|
+
/**
|
|
424
|
+
* Internal use only.
|
|
425
|
+
*/
|
|
426
|
+
isBlackboxChild?: boolean;
|
|
427
|
+
/**
|
|
428
|
+
* @deprecated
|
|
429
|
+
*/
|
|
430
|
+
custom?: ValidateFunction$1;
|
|
431
|
+
/**
|
|
432
|
+
* Used in GraphQL. If true, the field will be omitted from the schema.
|
|
433
|
+
*/
|
|
434
|
+
private?: boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Used in GraphQL. When in GraphQL, this resolver will replace the static field.
|
|
437
|
+
*/
|
|
438
|
+
graphQLResolver?: (...args: any) => any;
|
|
439
|
+
/**
|
|
440
|
+
* Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
|
|
441
|
+
*/
|
|
442
|
+
key?: string;
|
|
443
|
+
/**
|
|
444
|
+
* The name that would be displayed in a front-end form
|
|
445
|
+
*/
|
|
446
|
+
label?: string;
|
|
447
|
+
/**
|
|
448
|
+
* The description that would be displayed in a front-end form
|
|
449
|
+
*/
|
|
450
|
+
description?: string;
|
|
451
|
+
/**
|
|
452
|
+
* The placeholder that would be displayed in a front-end form
|
|
453
|
+
*/
|
|
454
|
+
placeholder?: string;
|
|
455
|
+
/**
|
|
456
|
+
* The field type that would be used in a front-end form
|
|
457
|
+
*/
|
|
458
|
+
fieldType?: string;
|
|
459
|
+
/**
|
|
460
|
+
* The field options that will be passed as props to the front-end field
|
|
461
|
+
*/
|
|
462
|
+
fieldOptions?: any;
|
|
463
|
+
}
|
|
464
|
+
export interface CurrentNodeInfoOptions$1 {
|
|
465
|
+
autoConvert?: boolean;
|
|
466
|
+
filter?: boolean;
|
|
467
|
+
trimStrings?: boolean;
|
|
468
|
+
removeEmptyStrings?: boolean;
|
|
469
|
+
forceDoc?: any;
|
|
470
|
+
omitRequired?: boolean;
|
|
471
|
+
}
|
|
472
|
+
export interface CurrentNodeInfo$1 {
|
|
473
|
+
/**
|
|
474
|
+
* The global schema, prefaced by {type: {...}} to be compatible with subschemas
|
|
475
|
+
* Sometimes it's given without {type: {...}}. TODO: Normalize this.
|
|
476
|
+
*/
|
|
477
|
+
schema?: SchemaNode$1 | Schema$1;
|
|
478
|
+
/**
|
|
479
|
+
* The current node subschema
|
|
480
|
+
*/
|
|
481
|
+
currentSchema?: Partial<SchemaNode$1>;
|
|
482
|
+
value: any;
|
|
483
|
+
doc?: any;
|
|
484
|
+
currentDoc?: any;
|
|
485
|
+
options?: CurrentNodeInfoOptions$1;
|
|
486
|
+
args?: any[];
|
|
487
|
+
type?: SchemaMetaFieldType$1;
|
|
488
|
+
keys?: string[];
|
|
489
|
+
addError?: (keys: string[], code: string | object) => void;
|
|
490
|
+
}
|
|
491
|
+
export interface OrionMongoClient {
|
|
492
|
+
client: MongoClient;
|
|
493
|
+
db: Db;
|
|
494
|
+
uri: string;
|
|
495
|
+
dbName: string;
|
|
496
|
+
connectionPromise: Promise<MongoClient>;
|
|
497
|
+
connectionName: string;
|
|
498
|
+
}
|
|
499
|
+
export type RemoveFunctions<T extends ModelClassBase> = Pick<T, {
|
|
500
|
+
[Key in keyof T]-?: T[Key] extends Function ? never : Key;
|
|
501
|
+
}[keyof T]> & {
|
|
502
|
+
_id: ModelClassBase["_id"];
|
|
503
|
+
};
|
|
504
|
+
export type ModelClassBase = {
|
|
505
|
+
_id: string;
|
|
506
|
+
} & Blackbox$1;
|
|
507
|
+
export type DocumentWithIdOptional<T extends ModelClassBase> = Omit<T, "_id"> & {
|
|
508
|
+
/**
|
|
509
|
+
* The ID of the document
|
|
510
|
+
*/
|
|
511
|
+
_id?: T["_id"];
|
|
512
|
+
};
|
|
513
|
+
export type DocumentWithoutId<T> = Omit<T, "_id">;
|
|
514
|
+
export type ModelToDocumentType<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
515
|
+
export type ModelToDocumentTypeWithoutId<ModelClass extends ModelClassBase> = DocumentWithoutId<ModelToDocumentType<ModelClass>>;
|
|
516
|
+
export type ModelToDocumentTypeWithIdOptional<ModelClass extends ModelClassBase> = DocumentWithIdOptional<ModelToDocumentType<ModelClass>>;
|
|
517
|
+
export type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoSelector<ModelToDocumentType<ModelClass>>;
|
|
518
|
+
export type ModelToUpdateFilter<ModelClass extends ModelClassBase> = MongoDB.UpdateFilter<ModelToDocumentTypeWithoutId<ModelClass>> | Partial<ModelToDocumentTypeWithoutId<ModelClass>>;
|
|
519
|
+
export interface CollectionIndex {
|
|
520
|
+
keys: MongoDB.IndexSpecification;
|
|
521
|
+
options?: MongoDB.CreateIndexesOptions;
|
|
522
|
+
}
|
|
523
|
+
declare namespace DataLoader {
|
|
524
|
+
interface LoadDataOptionsBase<ModelClass extends ModelClassBase> {
|
|
525
|
+
key: keyof ModelClass;
|
|
526
|
+
match?: MongoFilter<ModelClass>;
|
|
527
|
+
sort?: MongoDB.Sort;
|
|
528
|
+
project?: MongoDB.Document;
|
|
529
|
+
timeout?: number;
|
|
530
|
+
debug?: boolean;
|
|
531
|
+
}
|
|
532
|
+
export interface LoadDataOptions<ModelClass extends ModelClassBase> extends LoadDataOptionsBase<ModelClass> {
|
|
533
|
+
value?: any;
|
|
534
|
+
values?: Array<any>;
|
|
535
|
+
}
|
|
536
|
+
export interface LoadOneOptions<ModelClass extends ModelClassBase> extends LoadDataOptionsBase<ModelClass> {
|
|
537
|
+
value: any;
|
|
538
|
+
}
|
|
539
|
+
export type LoadData<ModelClass extends ModelClassBase> = (options: LoadDataOptions<ModelClass>) => Promise<Array<ModelClass>>;
|
|
540
|
+
export type LoadOne<ModelClass extends ModelClassBase> = (options: LoadOneOptions<ModelClass>) => Promise<ModelClass>;
|
|
541
|
+
export type LoadMany<ModelClass extends ModelClassBase> = (options: LoadDataOptions<ModelClass>) => Promise<Array<ModelClass>>;
|
|
542
|
+
export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass["_id"]) => Promise<ModelClass>;
|
|
543
|
+
export {};
|
|
544
|
+
}
|
|
545
|
+
export type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass> & ({
|
|
546
|
+
_id?: ModelClass["_id"];
|
|
547
|
+
} | {
|
|
548
|
+
_id?: {
|
|
549
|
+
$in: ModelClass["_id"][];
|
|
550
|
+
};
|
|
551
|
+
});
|
|
552
|
+
export type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass["_id"] | MongoFilter<ModelClass>;
|
|
553
|
+
export interface FindCursor<ModelClass> extends MongoDB.FindCursor {
|
|
554
|
+
toArray: () => Promise<Array<ModelClass>>;
|
|
555
|
+
}
|
|
556
|
+
export interface UpdateOptions {
|
|
557
|
+
clean?: boolean;
|
|
558
|
+
validate?: boolean;
|
|
559
|
+
mongoOptions?: MongoDB.UpdateOptions;
|
|
560
|
+
}
|
|
561
|
+
export interface FindOneAndUpdateUpdateOptions {
|
|
562
|
+
clean?: boolean;
|
|
563
|
+
validate?: boolean;
|
|
564
|
+
mongoOptions?: MongoDB.FindOneAndUpdateOptions;
|
|
565
|
+
}
|
|
566
|
+
export interface InsertOptions {
|
|
567
|
+
clean?: boolean;
|
|
568
|
+
validate?: boolean;
|
|
569
|
+
mongoOptions?: MongoDB.InsertOneOptions;
|
|
570
|
+
}
|
|
571
|
+
export type InitItem<ModelClass extends ModelClassBase> = (doc: any) => ModelClass;
|
|
572
|
+
export type FindOne<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => Promise<ModelClass>;
|
|
573
|
+
export type Find<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => FindCursor<ModelClass>;
|
|
574
|
+
export type FindOneAndUpdate<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
575
|
+
export type UpdateAndFind<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
576
|
+
export type UpdateItem<ModelClass extends ModelClassBase> = (item: ModelClass, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<void>;
|
|
577
|
+
export type InsertOne<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass["_id"]>;
|
|
578
|
+
export type InsertMany<ModelClass extends ModelClassBase> = (doc: Array<ModelToDocumentTypeWithIdOptional<ModelClass>>, options?: InsertOptions) => Promise<Array<ModelClass["_id"]>>;
|
|
579
|
+
export type InsertAndFind<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass>;
|
|
580
|
+
export type DeleteMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
581
|
+
export type DeleteOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
582
|
+
export type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
583
|
+
export type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult | MongoDB.Document>;
|
|
584
|
+
export type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
585
|
+
export type EstimatedDocumentCount<ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
|
|
586
|
+
export type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
|
|
587
|
+
export interface Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
588
|
+
name: string;
|
|
589
|
+
connectionName?: string;
|
|
590
|
+
schema?: Schema$1;
|
|
591
|
+
/**
|
|
592
|
+
* @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
|
|
593
|
+
*/
|
|
594
|
+
model?: Model;
|
|
595
|
+
indexes: Array<CollectionIndex>;
|
|
596
|
+
generateId: () => ModelClass["_id"];
|
|
597
|
+
getSchema: () => Schema$1;
|
|
598
|
+
db: MongoDB.Db;
|
|
599
|
+
client: OrionMongoClient;
|
|
600
|
+
rawCollection: MongoDB.Collection<ModelClass>;
|
|
601
|
+
initItem: InitItem<ModelClass>;
|
|
602
|
+
findOne: FindOne<ModelClass>;
|
|
603
|
+
find: Find<ModelClass>;
|
|
604
|
+
insertOne: InsertOne<ModelClass>;
|
|
605
|
+
insertMany: InsertMany<ModelClass>;
|
|
606
|
+
insertAndFind: InsertAndFind<ModelClass>;
|
|
607
|
+
deleteMany: DeleteMany<ModelClass>;
|
|
608
|
+
deleteOne: DeleteOne<ModelClass>;
|
|
609
|
+
updateOne: UpdateOne<ModelClass>;
|
|
610
|
+
updateMany: UpdateMany<ModelClass>;
|
|
611
|
+
upsert: Upsert<ModelClass>;
|
|
612
|
+
findOneAndUpdate: FindOneAndUpdate<ModelClass>;
|
|
613
|
+
/**
|
|
614
|
+
* Updates a document and returns the updated document with the changes
|
|
615
|
+
*/
|
|
616
|
+
updateAndFind: UpdateAndFind<ModelClass>;
|
|
617
|
+
updateItem: UpdateItem<ModelClass>;
|
|
618
|
+
estimatedDocumentCount: EstimatedDocumentCount<ModelClass>;
|
|
619
|
+
countDocuments: CountDocuments<ModelClass>;
|
|
620
|
+
aggregate: <T = MongoDB.Document>(pipeline?: MongoDB.Document[], options?: MongoDB.AggregateOptions) => MongoDB.AggregationCursor<T>;
|
|
621
|
+
watch: <T = MongoDB.Document>(pipeline?: MongoDB.Document[], options?: MongoDB.ChangeStreamOptions) => MongoDB.ChangeStream<T>;
|
|
622
|
+
loadData: DataLoader.LoadData<ModelClass>;
|
|
623
|
+
loadOne: DataLoader.LoadOne<ModelClass>;
|
|
624
|
+
loadMany: DataLoader.LoadMany<ModelClass>;
|
|
625
|
+
loadById: DataLoader.LoadById<ModelClass>;
|
|
626
|
+
/**
|
|
627
|
+
* Use this function if you are using tests and you pass the
|
|
628
|
+
* env var DONT_CREATE_INDEXES_AUTOMATICALLY and you need to
|
|
629
|
+
* create the indexes for this collection
|
|
630
|
+
*/
|
|
631
|
+
createIndexes: () => Promise<string[]>;
|
|
632
|
+
createIndexesPromise: Promise<string[]>;
|
|
633
|
+
connectionPromise: Promise<MongoDB.MongoClient>;
|
|
634
|
+
}
|
|
635
|
+
export type MigrationId = `scnmg-${string}`;
|
|
636
|
+
export declare class MigrationSchema {
|
|
637
|
+
_id: MigrationId;
|
|
638
|
+
name: string;
|
|
639
|
+
completedAt: Date;
|
|
640
|
+
}
|
|
641
|
+
export declare class MigrationsRepo {
|
|
642
|
+
collection: Collection<MigrationSchema>;
|
|
643
|
+
getCompletedMigrationNames(): Promise<string[]>;
|
|
644
|
+
saveCompletedMigration(name: string): Promise<void>;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export {};
|