@orion-js/models 3.11.8 → 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 +5180 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +5152 -0
- package/package.json +24 -19
- package/LICENSE +0 -21
- package/lib/createModel/clone.d.ts +0 -9
- package/lib/createModel/clone.js +0 -57
- package/lib/createModel/clone.test.d.ts +0 -1
- package/lib/createModel/clone.test.js +0 -49
- package/lib/createModel/index.d.ts +0 -2
- package/lib/createModel/index.js +0 -92
- package/lib/createModel/initItem.d.ts +0 -8
- package/lib/createModel/initItem.js +0 -52
- package/lib/createModel/initItem.test.d.ts +0 -1
- package/lib/createModel/initItem.test.js +0 -28
- package/lib/createModel/modelToSchema.d.ts +0 -9
- package/lib/createModel/modelToSchema.js +0 -57
- package/lib/createModel/modelToSchema.test.d.ts +0 -1
- package/lib/createModel/modelToSchema.test.js +0 -64
- package/lib/createModel/resolveParam.d.ts +0 -1
- package/lib/createModel/resolveParam.js +0 -11
- package/lib/createModel/resolvers.test.d.ts +0 -1
- package/lib/createModel/resolvers.test.js +0 -55
- package/lib/createModel/validation.test.d.ts +0 -1
- package/lib/createModel/validation.test.js +0 -72
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -22
- package/lib/types/index.d.ts +0 -99
- package/lib/types/index.js +0 -2
- package/lib/types/index.test.d.ts +0 -1
- package/lib/types/index.test.js +0 -35
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
4
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
5
|
+
export interface StoredCacheData {
|
|
6
|
+
value: any;
|
|
7
|
+
expires?: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface SetCacheOptions {
|
|
10
|
+
ttl?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface GetCacheOptions {
|
|
13
|
+
ttl?: number;
|
|
14
|
+
fallback?(): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
export interface OrionCache {
|
|
17
|
+
/**
|
|
18
|
+
* Save data in the cache
|
|
19
|
+
*/
|
|
20
|
+
set(key: string, value: any, options?: SetCacheOptions): Promise<void> | void;
|
|
21
|
+
/**
|
|
22
|
+
* Get data from the cache
|
|
23
|
+
*/
|
|
24
|
+
get(key: string, options?: GetCacheOptions): Promise<StoredCacheData>;
|
|
25
|
+
/**
|
|
26
|
+
* Removes data from the cache
|
|
27
|
+
*/
|
|
28
|
+
invalidate(key: string): Promise<void> | void;
|
|
29
|
+
}
|
|
30
|
+
export type Blackbox = {
|
|
31
|
+
[name: string]: any;
|
|
32
|
+
};
|
|
33
|
+
export type GlobalResolverResolve = (params: any, viewer: any, info?: any) => Promise<any>;
|
|
34
|
+
export type ModelResolverResolve = (item: any, params: any, viewer: any, info?: any) => Promise<any>;
|
|
35
|
+
export type GlobalCheckPermissions = (params: any, viewer: any, info?: any) => Promise<string | void>;
|
|
36
|
+
export type ModelCheckPermissions = (parent: any, params: any, viewer: any, info?: any) => Promise<string | void>;
|
|
37
|
+
export type GlobalGetCacheKey = (params: any, viewer: any, info: any) => Promise<any>;
|
|
38
|
+
export type ModelGetCacheKey = (parent: any, params: any, viewer: any, info: any) => Promise<any>;
|
|
39
|
+
export interface ExecuteOptions {
|
|
40
|
+
params: Blackbox;
|
|
41
|
+
viewer: any;
|
|
42
|
+
parent?: any;
|
|
43
|
+
info?: any;
|
|
44
|
+
options: ResolverOptions;
|
|
45
|
+
}
|
|
46
|
+
export type Parameters$1<T> = T extends (...args: infer P) => any ? P : never;
|
|
47
|
+
export type ReturnType$1<T> = T extends (...args: any) => infer R ? R : any;
|
|
48
|
+
export type ResolverParams<Resolve, IsModel> = IsModel extends undefined ? Parameters$1<Resolve>[0] : Parameters$1<Resolve>[1];
|
|
49
|
+
export interface ExecuteParams<Resolve = Function, IsModel = undefined> {
|
|
50
|
+
params?: ResolverParams<Resolve, IsModel>;
|
|
51
|
+
viewer?: any;
|
|
52
|
+
parent?: IsModel extends undefined ? undefined : Parameters$1<Resolve>[0];
|
|
53
|
+
info?: any;
|
|
54
|
+
}
|
|
55
|
+
export type Execute<Resolve = Function, IsModel = undefined> = (executeOptions: ExecuteParams<Resolve, IsModel>) => ReturnType$1<Resolve>;
|
|
56
|
+
export interface SharedResolverOptions {
|
|
57
|
+
resolverId?: string;
|
|
58
|
+
params?: any;
|
|
59
|
+
returns?: any;
|
|
60
|
+
mutation?: boolean;
|
|
61
|
+
private?: boolean;
|
|
62
|
+
checkPermission?: GlobalCheckPermissions | ModelCheckPermissions;
|
|
63
|
+
getCacheKey?: GlobalGetCacheKey | ModelGetCacheKey;
|
|
64
|
+
cache?: number;
|
|
65
|
+
cacheProvider?: OrionCache;
|
|
66
|
+
permissionsOptions?: any;
|
|
67
|
+
middlewares?: ResolverMiddleware[];
|
|
68
|
+
}
|
|
69
|
+
export interface ResolverOptions<Resolve = Function> extends SharedResolverOptions {
|
|
70
|
+
resolve: Resolve;
|
|
71
|
+
}
|
|
72
|
+
export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
73
|
+
export interface Resolver<Resolve = Function, IsModel = undefined> extends SharedResolverOptions {
|
|
74
|
+
execute: Execute<Resolve, IsModel>;
|
|
75
|
+
resolve: Resolve;
|
|
76
|
+
modelResolve: IsModel extends undefined ? undefined : OmitFirstArg<Resolve>;
|
|
77
|
+
}
|
|
78
|
+
export type ModelResolver<Resolve = Function> = Resolver<Resolve, true>;
|
|
79
|
+
export type ResolverMiddleware = (executeOptions: ExecuteOptions, next: () => Promise<any>) => Promise<any>;
|
|
80
|
+
export interface FieldType {
|
|
81
|
+
name: string;
|
|
82
|
+
validate: ValidateFunction;
|
|
83
|
+
clean: CleanFunction;
|
|
84
|
+
meta?: any;
|
|
85
|
+
toGraphQLType?: (GraphQL: any) => any;
|
|
86
|
+
_isFieldType: boolean;
|
|
87
|
+
}
|
|
88
|
+
export type Constructor<T> = new (...args: any[]) => T;
|
|
89
|
+
export type FieldTypesList = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
|
|
90
|
+
export type TypedModelOnSchema = Function;
|
|
91
|
+
export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
|
|
92
|
+
export type SchemaRecursiveNodeTypeExtras = {
|
|
93
|
+
_isFieldType?: boolean;
|
|
94
|
+
__clean?: CleanFunction;
|
|
95
|
+
__validate?: ValidateFunction;
|
|
96
|
+
__skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
|
|
97
|
+
};
|
|
98
|
+
export interface Schema {
|
|
99
|
+
[key: string]: SchemaNode | Function;
|
|
100
|
+
}
|
|
101
|
+
export type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
|
|
102
|
+
export type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
|
|
103
|
+
export type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
|
|
104
|
+
export type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
|
|
105
|
+
export type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
|
|
106
|
+
export interface SchemaNode {
|
|
107
|
+
/**
|
|
108
|
+
* The type of the field. Used for type validations. Can also contain a subschema.
|
|
109
|
+
*/
|
|
110
|
+
type: SchemaMetaFieldType;
|
|
111
|
+
/**
|
|
112
|
+
* Defaults to false
|
|
113
|
+
*/
|
|
114
|
+
optional?: boolean;
|
|
115
|
+
allowedValues?: Array<any>;
|
|
116
|
+
defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
|
|
117
|
+
/**
|
|
118
|
+
* Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
|
|
119
|
+
*/
|
|
120
|
+
validate?: ValidateFunction;
|
|
121
|
+
/**
|
|
122
|
+
* Function that preprocesses a value before it is set.
|
|
123
|
+
*/
|
|
124
|
+
clean?: CleanFunction;
|
|
125
|
+
autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
|
|
126
|
+
/**
|
|
127
|
+
* The minimum value if it's a number, the minimum length if it's a string or array.
|
|
128
|
+
*/
|
|
129
|
+
min?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The maximum value if it's a number, the maximum length if it's a string or array.
|
|
132
|
+
*/
|
|
133
|
+
max?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Internal use only.
|
|
136
|
+
*/
|
|
137
|
+
isBlackboxChild?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated
|
|
140
|
+
*/
|
|
141
|
+
custom?: ValidateFunction;
|
|
142
|
+
/**
|
|
143
|
+
* Used in GraphQL. If true, the field will be omitted from the schema.
|
|
144
|
+
*/
|
|
145
|
+
private?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Used in GraphQL. When in GraphQL, this resolver will replace the static field.
|
|
148
|
+
*/
|
|
149
|
+
graphQLResolver?: (...args: any) => any;
|
|
150
|
+
/**
|
|
151
|
+
* Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
|
|
152
|
+
*/
|
|
153
|
+
key?: string;
|
|
154
|
+
/**
|
|
155
|
+
* The name that would be displayed in a front-end form
|
|
156
|
+
*/
|
|
157
|
+
label?: string;
|
|
158
|
+
/**
|
|
159
|
+
* The description that would be displayed in a front-end form
|
|
160
|
+
*/
|
|
161
|
+
description?: string;
|
|
162
|
+
/**
|
|
163
|
+
* The placeholder that would be displayed in a front-end form
|
|
164
|
+
*/
|
|
165
|
+
placeholder?: string;
|
|
166
|
+
/**
|
|
167
|
+
* The field type that would be used in a front-end form
|
|
168
|
+
*/
|
|
169
|
+
fieldType?: string;
|
|
170
|
+
/**
|
|
171
|
+
* The field options that will be passed as props to the front-end field
|
|
172
|
+
*/
|
|
173
|
+
fieldOptions?: any;
|
|
174
|
+
}
|
|
175
|
+
export interface CurrentNodeInfoOptions {
|
|
176
|
+
autoConvert?: boolean;
|
|
177
|
+
filter?: boolean;
|
|
178
|
+
trimStrings?: boolean;
|
|
179
|
+
removeEmptyStrings?: boolean;
|
|
180
|
+
forceDoc?: any;
|
|
181
|
+
omitRequired?: boolean;
|
|
182
|
+
}
|
|
183
|
+
export interface CurrentNodeInfo {
|
|
184
|
+
/**
|
|
185
|
+
* The global schema, prefaced by {type: {...}} to be compatible with subschemas
|
|
186
|
+
* Sometimes it's given without {type: {...}}. TODO: Normalize this.
|
|
187
|
+
*/
|
|
188
|
+
schema?: SchemaNode | Schema;
|
|
189
|
+
/**
|
|
190
|
+
* The current node subschema
|
|
191
|
+
*/
|
|
192
|
+
currentSchema?: Partial<SchemaNode>;
|
|
193
|
+
value: any;
|
|
194
|
+
doc?: any;
|
|
195
|
+
currentDoc?: any;
|
|
196
|
+
options?: CurrentNodeInfoOptions;
|
|
197
|
+
args?: any[];
|
|
198
|
+
type?: SchemaMetaFieldType;
|
|
199
|
+
keys?: string[];
|
|
200
|
+
addError?: (keys: string[], code: string | object) => void;
|
|
201
|
+
}
|
|
202
|
+
export interface ModelsSchemaNode extends Omit<SchemaNode, "type"> {
|
|
203
|
+
type: Model | [
|
|
204
|
+
Model
|
|
205
|
+
] | SchemaMetaFieldType;
|
|
206
|
+
}
|
|
207
|
+
export interface ModelSchema {
|
|
208
|
+
[key: string]: ModelsSchemaNode;
|
|
209
|
+
}
|
|
210
|
+
export interface CreateModelOptions {
|
|
211
|
+
/**
|
|
212
|
+
* The name of the model, used for example for GraphQL
|
|
213
|
+
*/
|
|
214
|
+
name: string;
|
|
215
|
+
/**
|
|
216
|
+
* Pass a function that returns the schema. For example: () => require('./schema').
|
|
217
|
+
* This is used like this to allow circular dependencies
|
|
218
|
+
*/
|
|
219
|
+
schema?: ModelSchema | (() => {
|
|
220
|
+
default: ModelSchema;
|
|
221
|
+
});
|
|
222
|
+
/**
|
|
223
|
+
* Pass a function that returns the resolvers. For example: () => require('./resolvers')
|
|
224
|
+
* This is used like this to allow circular dependencies
|
|
225
|
+
*/
|
|
226
|
+
resolvers?: ModelResolversMap | (() => {
|
|
227
|
+
default: ModelResolversMap;
|
|
228
|
+
});
|
|
229
|
+
/**
|
|
230
|
+
* Optional function that will process the document before being returned.
|
|
231
|
+
* @param doc The current document
|
|
232
|
+
* @return The processed document promise
|
|
233
|
+
*/
|
|
234
|
+
clean?: (doc: any) => Promise<any> | any;
|
|
235
|
+
/**
|
|
236
|
+
* Optional function that will validate the document before being returned.
|
|
237
|
+
* @param doc The current document
|
|
238
|
+
*/
|
|
239
|
+
validate?: (doc: any) => Promise<void> | void;
|
|
240
|
+
}
|
|
241
|
+
export interface ModelResolversMap {
|
|
242
|
+
[key: string]: ModelResolver<ModelResolverResolve>;
|
|
243
|
+
}
|
|
244
|
+
export interface GlobalResolversMap {
|
|
245
|
+
[key: string]: Resolver<GlobalResolverResolve>;
|
|
246
|
+
}
|
|
247
|
+
export interface CloneOptions {
|
|
248
|
+
name: string;
|
|
249
|
+
omitFields?: string[];
|
|
250
|
+
pickFields?: string[];
|
|
251
|
+
mapFields?: (field: any, key: string) => any;
|
|
252
|
+
extendSchema?: Schema;
|
|
253
|
+
extendResolvers?: ModelResolversMap;
|
|
254
|
+
}
|
|
255
|
+
export interface Model<TSchema = any> {
|
|
256
|
+
__isModel: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* The name of the model, used for example for GraphQL
|
|
259
|
+
*/
|
|
260
|
+
name: string;
|
|
261
|
+
/**
|
|
262
|
+
* Returns the schema of the model
|
|
263
|
+
*/
|
|
264
|
+
getSchema: () => Schema & {
|
|
265
|
+
__model: Model;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Returns the schema without adding __model to the schema
|
|
269
|
+
*/
|
|
270
|
+
getCleanSchema: () => Schema;
|
|
271
|
+
/**
|
|
272
|
+
* Returns the model resolvers
|
|
273
|
+
*/
|
|
274
|
+
getResolvers: () => ModelResolversMap;
|
|
275
|
+
/**
|
|
276
|
+
* Adds the model resolvers to a item
|
|
277
|
+
*/
|
|
278
|
+
initItem: (item: any) => any;
|
|
279
|
+
/**
|
|
280
|
+
* Validates an item using @orion-js/schema
|
|
281
|
+
*/
|
|
282
|
+
validate: (item: any) => Promise<any>;
|
|
283
|
+
/**
|
|
284
|
+
* Cleans an item using @orion-js/schema
|
|
285
|
+
*/
|
|
286
|
+
clean: (item: any) => Promise<TSchema>;
|
|
287
|
+
/**
|
|
288
|
+
* Cleans and validates an item using @orion-js/schema
|
|
289
|
+
*/
|
|
290
|
+
cleanAndValidate: (item: any) => Promise<TSchema>;
|
|
291
|
+
/**
|
|
292
|
+
* Creates a new model using this one as a base
|
|
293
|
+
*/
|
|
294
|
+
clone: (cloneOptions: CloneOptions) => Model;
|
|
295
|
+
/**
|
|
296
|
+
* The type of the model. Only use this in typescript
|
|
297
|
+
*/
|
|
298
|
+
type: TSchema;
|
|
299
|
+
}
|
|
300
|
+
export type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
|
|
301
|
+
export function createModel<TSchema = any>(modelOptions: CreateModelOptions): Model<TSchema>;
|
|
302
|
+
export declare function modelToSchema(modelSchema: ModelSchema, { cleanSchema }?: {
|
|
303
|
+
cleanSchema?: boolean;
|
|
304
|
+
}): Schema;
|
|
305
|
+
export declare function modelToSchemaWithModel(modelSchema: ModelSchema, model?: Model): Schema | {
|
|
306
|
+
__model: Model<any>;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export {};
|