@orion-js/models 4.0.0-next.2 → 4.0.0-next.4

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.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ModelResolver, ModelResolverResolve, Resolver, GlobalResolverResolve } from '@orion-js/resolvers';
2
- import { SchemaNode, Schema, SchemaMetaFieldType } from '@orion-js/schema';
2
+ import { Schema, SchemaNode, SchemaFieldType } from '@orion-js/schema';
3
3
 
4
4
  interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
5
- type: Model | [Model] | SchemaMetaFieldType;
5
+ type: Model | [Model] | SchemaFieldType;
6
6
  }
7
7
  interface ModelSchema {
8
8
  [key: string]: ModelsSchemaNode;
9
9
  }
10
- interface CreateModelOptions {
10
+ interface CreateModelOptions<TSchema extends Schema = any> {
11
11
  /**
12
12
  * The name of the model, used for example for GraphQL
13
13
  */
@@ -16,16 +16,12 @@ interface CreateModelOptions {
16
16
  * Pass a function that returns the schema. For example: () => require('./schema').
17
17
  * This is used like this to allow circular dependencies
18
18
  */
19
- schema?: ModelSchema | (() => {
20
- default: ModelSchema;
21
- });
19
+ schema?: TSchema;
22
20
  /**
23
21
  * Pass a function that returns the resolvers. For example: () => require('./resolvers')
24
22
  * This is used like this to allow circular dependencies
25
23
  */
26
- resolvers?: ModelResolversMap | (() => {
27
- default: ModelResolversMap;
28
- });
24
+ resolvers?: ModelResolversMap;
29
25
  /**
30
26
  * Optional function that will process the document before being returned.
31
27
  * @param doc The current document
@@ -53,7 +49,8 @@ interface CloneOptions {
53
49
  extendResolvers?: ModelResolversMap;
54
50
  }
55
51
  interface Model<TSchema = any> {
56
- __isModel: boolean;
52
+ __isModel: true;
53
+ __modelName: string;
57
54
  /**
58
55
  * The name of the model, used for example for GraphQL
59
56
  */
@@ -61,21 +58,11 @@ interface Model<TSchema = any> {
61
58
  /**
62
59
  * Returns the schema of the model
63
60
  */
64
- getSchema: () => Schema & {
65
- __model: Model;
66
- };
67
- /**
68
- * Returns the schema without adding __model to the schema
69
- */
70
- getCleanSchema: () => Schema;
61
+ getSchema: () => Schema;
71
62
  /**
72
63
  * Returns the model resolvers
73
64
  */
74
65
  getResolvers: () => ModelResolversMap;
75
- /**
76
- * Adds the model resolvers to a item
77
- */
78
- initItem: (item: any) => any;
79
66
  /**
80
67
  * Validates an item using @orion-js/schema
81
68
  */
@@ -99,13 +86,14 @@ interface Model<TSchema = any> {
99
86
  }
100
87
  type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
101
88
 
102
- declare function createModel<TSchema = any>(modelOptions: CreateModelOptions): Model<TSchema>;
89
+ declare function createModel<TSchema extends Schema>(modelOptions: CreateModelOptions<TSchema>): Model<TSchema>;
103
90
 
104
- declare function modelToSchema(modelSchema: ModelSchema, { cleanSchema }?: {
105
- cleanSchema?: boolean;
106
- }): Schema;
107
- declare function modelToSchemaWithModel(modelSchema: ModelSchema, model?: Model): Schema | {
108
- __model: Model<any>;
109
- };
91
+ interface ModelToSchemaOptions {
92
+ modelSchema: Schema;
93
+ modelName?: string;
94
+ cleanOptions?: any;
95
+ validateOptions?: any;
96
+ }
97
+ declare function modelToSchema(options: ModelToSchemaOptions): Schema;
110
98
 
111
- export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema, modelToSchemaWithModel };
99
+ export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema };