@orion-js/models 3.11.15 → 3.12.0

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