@orion-js/models 4.0.0-alpha.3 → 4.0.0-next.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 +1834 -4545
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +111 -0
- package/dist/index.d.ts +107 -305
- package/dist/index.js +1812 -4510
- package/dist/index.js.map +1 -0
- package/package.json +16 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,309 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
import { ModelResolver, ModelResolverResolve, Resolver, GlobalResolverResolve } from '@orion-js/resolvers';
|
|
2
|
+
import { SchemaNode, Schema, SchemaMetaFieldType } from '@orion-js/schema';
|
|
2
3
|
|
|
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
|
-
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;
|
|
4
|
+
interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
|
|
5
|
+
type: Model | [Model] | SchemaMetaFieldType;
|
|
6
|
+
}
|
|
7
|
+
interface ModelSchema {
|
|
8
|
+
[key: string]: ModelsSchemaNode;
|
|
9
|
+
}
|
|
10
|
+
interface CreateModelOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the model, used for example for GraphQL
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* Pass a function that returns the schema. For example: () => require('./schema').
|
|
17
|
+
* This is used like this to allow circular dependencies
|
|
18
|
+
*/
|
|
19
|
+
schema?: ModelSchema | (() => {
|
|
20
|
+
default: ModelSchema;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Pass a function that returns the resolvers. For example: () => require('./resolvers')
|
|
24
|
+
* This is used like this to allow circular dependencies
|
|
25
|
+
*/
|
|
26
|
+
resolvers?: ModelResolversMap | (() => {
|
|
27
|
+
default: ModelResolversMap;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Optional function that will process the document before being returned.
|
|
31
|
+
* @param doc The current document
|
|
32
|
+
* @return The processed document promise
|
|
33
|
+
*/
|
|
34
|
+
clean?: (doc: any) => Promise<any> | any;
|
|
35
|
+
/**
|
|
36
|
+
* Optional function that will validate the document before being returned.
|
|
37
|
+
* @param doc The current document
|
|
38
|
+
*/
|
|
39
|
+
validate?: (doc: any) => Promise<void> | void;
|
|
40
|
+
}
|
|
41
|
+
interface ModelResolversMap {
|
|
42
|
+
[key: string]: ModelResolver<ModelResolverResolve>;
|
|
43
|
+
}
|
|
44
|
+
interface GlobalResolversMap {
|
|
45
|
+
[key: string]: Resolver<GlobalResolverResolve>;
|
|
46
|
+
}
|
|
47
|
+
interface CloneOptions {
|
|
48
|
+
name: string;
|
|
49
|
+
omitFields?: string[];
|
|
50
|
+
pickFields?: string[];
|
|
51
|
+
mapFields?: (field: any, key: string) => any;
|
|
52
|
+
extendSchema?: Schema;
|
|
53
|
+
extendResolvers?: ModelResolversMap;
|
|
54
|
+
}
|
|
55
|
+
interface Model<TSchema = any> {
|
|
56
|
+
__isModel: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The name of the model, used for example for GraphQL
|
|
59
|
+
*/
|
|
60
|
+
name: string;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the schema of the model
|
|
63
|
+
*/
|
|
64
|
+
getSchema: () => Schema & {
|
|
65
|
+
__model: Model;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Returns the schema without adding __model to the schema
|
|
69
|
+
*/
|
|
70
|
+
getCleanSchema: () => Schema;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the model resolvers
|
|
73
|
+
*/
|
|
74
|
+
getResolvers: () => ModelResolversMap;
|
|
75
|
+
/**
|
|
76
|
+
* Adds the model resolvers to a item
|
|
77
|
+
*/
|
|
78
|
+
initItem: (item: any) => any;
|
|
79
|
+
/**
|
|
80
|
+
* Validates an item using @orion-js/schema
|
|
81
|
+
*/
|
|
82
|
+
validate: (item: any) => Promise<any>;
|
|
83
|
+
/**
|
|
84
|
+
* Cleans an item using @orion-js/schema
|
|
85
|
+
*/
|
|
86
|
+
clean: (item: any) => Promise<TSchema>;
|
|
87
|
+
/**
|
|
88
|
+
* Cleans and validates an item using @orion-js/schema
|
|
89
|
+
*/
|
|
90
|
+
cleanAndValidate: (item: any) => Promise<TSchema>;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new model using this one as a base
|
|
93
|
+
*/
|
|
94
|
+
clone: (cloneOptions: CloneOptions) => Model;
|
|
95
|
+
/**
|
|
96
|
+
* The type of the model. Only use this in typescript
|
|
97
|
+
*/
|
|
98
|
+
type: TSchema;
|
|
99
|
+
}
|
|
100
|
+
type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
|
|
101
|
+
|
|
102
|
+
declare function createModel<TSchema = any>(modelOptions: CreateModelOptions): Model<TSchema>;
|
|
103
|
+
|
|
104
|
+
declare function modelToSchema(modelSchema: ModelSchema, { cleanSchema }?: {
|
|
105
|
+
cleanSchema?: boolean;
|
|
304
106
|
}): Schema;
|
|
305
|
-
|
|
306
|
-
|
|
107
|
+
declare function modelToSchemaWithModel(modelSchema: ModelSchema, model?: Model): Schema | {
|
|
108
|
+
__model: Model<any>;
|
|
307
109
|
};
|
|
308
110
|
|
|
309
|
-
export {};
|
|
111
|
+
export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema, modelToSchemaWithModel };
|