@orion-js/models 4.0.0-next.0 → 4.0.0-next.3
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/LICENSE +21 -0
- package/dist/index.cjs +1678 -4519
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +111 -0
- package/dist/index.d.ts +100 -102
- package/dist/index.js +1627 -4455
- package/dist/index.js.map +1 -0
- package/package.json +16 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,113 +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
|
-
export interface ModelsSchemaNode extends Omit<SchemaNode, "type"> {
|
|
7
|
-
type: Model | [
|
|
8
|
-
Model
|
|
9
|
-
] | SchemaMetaFieldType;
|
|
4
|
+
interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
|
|
5
|
+
type: Model | [Model] | SchemaMetaFieldType;
|
|
10
6
|
}
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
interface ModelSchema {
|
|
8
|
+
[key: string]: ModelsSchemaNode;
|
|
13
9
|
}
|
|
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
|
-
|
|
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;
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
interface ModelResolversMap {
|
|
42
|
+
[key: string]: ModelResolver<ModelResolverResolve>;
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
interface GlobalResolversMap {
|
|
45
|
+
[key: string]: Resolver<GlobalResolverResolve>;
|
|
50
46
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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;
|
|
58
54
|
}
|
|
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
|
-
|
|
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;
|
|
103
99
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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;
|
|
108
106
|
}): Schema;
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
declare function modelToSchemaWithModel(modelSchema: ModelSchema, model?: Model): Schema | {
|
|
108
|
+
__model: Model<any>;
|
|
111
109
|
};
|
|
112
110
|
|
|
113
|
-
export {};
|
|
111
|
+
export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema, modelToSchemaWithModel };
|