@orion-js/models 4.3.1 → 4.4.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.
- package/LICENSE +21 -0
- package/dist/createModel/clone.d.ts +10 -0
- package/dist/createModel/index.d.ts +3 -0
- package/dist/createModel/modelToSchema.d.ts +12 -0
- package/dist/index.d.ts +4 -100
- package/dist/{index.d.cts → types/index.d.ts} +10 -24
- package/package.json +13 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Orionjs Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CreateModel, CloneOptions, CreateModelOptions, ModelResolversMap } from '../types';
|
|
2
|
+
import { Schema } from '@orion-js/schema';
|
|
3
|
+
interface CloneInfo {
|
|
4
|
+
createModel: CreateModel;
|
|
5
|
+
getSchema: () => Schema;
|
|
6
|
+
getResolvers: () => ModelResolversMap;
|
|
7
|
+
modelOptions: CreateModelOptions;
|
|
8
|
+
}
|
|
9
|
+
declare const clone: (cloneInfo: CloneInfo, options: CloneOptions) => import("..").Model<any>;
|
|
10
|
+
export default clone;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema, SchemaNode } from '@orion-js/schema';
|
|
2
|
+
import { ModelResolversMap } from '../types';
|
|
3
|
+
export declare function processModelSchemaKey(schemaNode: SchemaNode): SchemaNode;
|
|
4
|
+
interface ModelToSchemaOptions {
|
|
5
|
+
modelSchema: Schema;
|
|
6
|
+
modelName?: string;
|
|
7
|
+
cleanOptions?: any;
|
|
8
|
+
validateOptions?: any;
|
|
9
|
+
resolvers?: ModelResolversMap;
|
|
10
|
+
}
|
|
11
|
+
export declare function modelToSchema(options: ModelToSchemaOptions): Schema;
|
|
12
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type: Model | [Model] | SchemaFieldType;
|
|
6
|
-
}
|
|
7
|
-
interface ModelSchema {
|
|
8
|
-
[key: string]: ModelsSchemaNode;
|
|
9
|
-
}
|
|
10
|
-
interface CreateModelOptions<TSchema extends Schema = any> {
|
|
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?: TSchema;
|
|
20
|
-
/**
|
|
21
|
-
* Pass a function that returns the resolvers. For example: () => require('./resolvers')
|
|
22
|
-
* This is used like this to allow circular dependencies
|
|
23
|
-
*/
|
|
24
|
-
resolvers?: ModelResolversMap;
|
|
25
|
-
/**
|
|
26
|
-
* Optional function that will process the document before being returned.
|
|
27
|
-
* @param doc The current document
|
|
28
|
-
* @return The processed document promise
|
|
29
|
-
*/
|
|
30
|
-
clean?: (doc: any) => Promise<any> | any;
|
|
31
|
-
/**
|
|
32
|
-
* Optional function that will validate the document before being returned.
|
|
33
|
-
* @param doc The current document
|
|
34
|
-
*/
|
|
35
|
-
validate?: (doc: any) => Promise<void> | void;
|
|
36
|
-
}
|
|
37
|
-
interface ModelResolversMap {
|
|
38
|
-
[key: string]: ModelResolver;
|
|
39
|
-
}
|
|
40
|
-
interface GlobalResolversMap {
|
|
41
|
-
[key: string]: GlobalResolver;
|
|
42
|
-
}
|
|
43
|
-
interface CloneOptions {
|
|
44
|
-
name: string;
|
|
45
|
-
omitFields?: string[];
|
|
46
|
-
pickFields?: string[];
|
|
47
|
-
mapFields?: (field: any, key: string) => any;
|
|
48
|
-
extendSchema?: Schema;
|
|
49
|
-
extendResolvers?: ModelResolversMap;
|
|
50
|
-
}
|
|
51
|
-
interface Model<TSchema = any> {
|
|
52
|
-
__isModel: true;
|
|
53
|
-
__modelName: string;
|
|
54
|
-
/**
|
|
55
|
-
* The name of the model, used for example for GraphQL
|
|
56
|
-
*/
|
|
57
|
-
name: string;
|
|
58
|
-
/**
|
|
59
|
-
* Returns the schema of the model
|
|
60
|
-
*/
|
|
61
|
-
getSchema: () => Schema;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the model resolvers
|
|
64
|
-
*/
|
|
65
|
-
getResolvers: () => ModelResolversMap;
|
|
66
|
-
/**
|
|
67
|
-
* Validates an item using @orion-js/schema
|
|
68
|
-
*/
|
|
69
|
-
validate: (item: any) => Promise<any>;
|
|
70
|
-
/**
|
|
71
|
-
* Cleans an item using @orion-js/schema
|
|
72
|
-
*/
|
|
73
|
-
clean: (item: any) => Promise<TSchema>;
|
|
74
|
-
/**
|
|
75
|
-
* Cleans and validates an item using @orion-js/schema
|
|
76
|
-
*/
|
|
77
|
-
cleanAndValidate: (item: any) => Promise<TSchema>;
|
|
78
|
-
/**
|
|
79
|
-
* Creates a new model using this one as a base
|
|
80
|
-
*/
|
|
81
|
-
clone: (cloneOptions: CloneOptions) => Model;
|
|
82
|
-
/**
|
|
83
|
-
* The type of the model. Only use this in typescript
|
|
84
|
-
*/
|
|
85
|
-
type: TSchema;
|
|
86
|
-
}
|
|
87
|
-
type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
|
|
88
|
-
|
|
89
|
-
declare function createModel<TSchema extends Schema>(modelOptions: CreateModelOptions<TSchema>): Model<TSchema>;
|
|
90
|
-
|
|
91
|
-
interface ModelToSchemaOptions {
|
|
92
|
-
modelSchema: Schema;
|
|
93
|
-
modelName?: string;
|
|
94
|
-
cleanOptions?: any;
|
|
95
|
-
validateOptions?: any;
|
|
96
|
-
resolvers?: ModelResolversMap;
|
|
97
|
-
}
|
|
98
|
-
declare function modelToSchema(options: ModelToSchemaOptions): Schema;
|
|
99
|
-
|
|
100
|
-
export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema };
|
|
1
|
+
import createModel from './createModel';
|
|
2
|
+
import { modelToSchema } from './createModel/modelToSchema';
|
|
3
|
+
export { createModel, modelToSchema };
|
|
4
|
+
export * from './types';
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Schema,
|
|
3
|
-
|
|
4
|
-
interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
|
|
1
|
+
import { GlobalResolver, ModelResolver } from '@orion-js/resolvers';
|
|
2
|
+
import { Schema, SchemaFieldType, SchemaNode } from '@orion-js/schema';
|
|
3
|
+
export interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
|
|
5
4
|
type: Model | [Model] | SchemaFieldType;
|
|
6
5
|
}
|
|
7
|
-
interface ModelSchema {
|
|
6
|
+
export interface ModelSchema {
|
|
8
7
|
[key: string]: ModelsSchemaNode;
|
|
9
8
|
}
|
|
10
|
-
interface CreateModelOptions<TSchema extends Schema = any> {
|
|
9
|
+
export interface CreateModelOptions<TSchema extends Schema = any> {
|
|
11
10
|
/**
|
|
12
11
|
* The name of the model, used for example for GraphQL
|
|
13
12
|
*/
|
|
@@ -34,13 +33,13 @@ interface CreateModelOptions<TSchema extends Schema = any> {
|
|
|
34
33
|
*/
|
|
35
34
|
validate?: (doc: any) => Promise<void> | void;
|
|
36
35
|
}
|
|
37
|
-
interface ModelResolversMap {
|
|
36
|
+
export interface ModelResolversMap {
|
|
38
37
|
[key: string]: ModelResolver;
|
|
39
38
|
}
|
|
40
|
-
interface GlobalResolversMap {
|
|
39
|
+
export interface GlobalResolversMap {
|
|
41
40
|
[key: string]: GlobalResolver;
|
|
42
41
|
}
|
|
43
|
-
interface CloneOptions {
|
|
42
|
+
export interface CloneOptions {
|
|
44
43
|
name: string;
|
|
45
44
|
omitFields?: string[];
|
|
46
45
|
pickFields?: string[];
|
|
@@ -48,7 +47,7 @@ interface CloneOptions {
|
|
|
48
47
|
extendSchema?: Schema;
|
|
49
48
|
extendResolvers?: ModelResolversMap;
|
|
50
49
|
}
|
|
51
|
-
interface Model<TSchema = any> {
|
|
50
|
+
export interface Model<TSchema = any> {
|
|
52
51
|
__isModel: true;
|
|
53
52
|
__modelName: string;
|
|
54
53
|
/**
|
|
@@ -84,17 +83,4 @@ interface Model<TSchema = any> {
|
|
|
84
83
|
*/
|
|
85
84
|
type: TSchema;
|
|
86
85
|
}
|
|
87
|
-
type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
|
|
88
|
-
|
|
89
|
-
declare function createModel<TSchema extends Schema>(modelOptions: CreateModelOptions<TSchema>): Model<TSchema>;
|
|
90
|
-
|
|
91
|
-
interface ModelToSchemaOptions {
|
|
92
|
-
modelSchema: Schema;
|
|
93
|
-
modelName?: string;
|
|
94
|
-
cleanOptions?: any;
|
|
95
|
-
validateOptions?: any;
|
|
96
|
-
resolvers?: ModelResolversMap;
|
|
97
|
-
}
|
|
98
|
-
declare function modelToSchema(options: ModelToSchemaOptions): Schema;
|
|
99
|
-
|
|
100
|
-
export { type CloneOptions, type CreateModel, type CreateModelOptions, type GlobalResolversMap, type Model, type ModelResolversMap, type ModelSchema, type ModelsSchemaNode, createModel, modelToSchema };
|
|
86
|
+
export type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/models",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -8,25 +8,18 @@
|
|
|
8
8
|
],
|
|
9
9
|
"author": "nicolaslopezj",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"test": "bun test",
|
|
13
|
-
"prepare": "bun run build",
|
|
14
|
-
"clean": "rm -rf ./dist",
|
|
15
|
-
"build": "tsup",
|
|
16
|
-
"dev": "tsup --watch"
|
|
17
|
-
},
|
|
18
11
|
"dependencies": {
|
|
19
|
-
"@orion-js/helpers": "4.
|
|
20
|
-
"@orion-js/resolvers": "4.
|
|
21
|
-
"@orion-js/schema": "4.
|
|
12
|
+
"@orion-js/helpers": "4.4.0",
|
|
13
|
+
"@orion-js/resolvers": "4.4.0",
|
|
14
|
+
"@orion-js/schema": "4.4.0"
|
|
22
15
|
},
|
|
23
16
|
"peerDependencies": {
|
|
24
|
-
"@orion-js/logger": "4.
|
|
17
|
+
"@orion-js/logger": "4.4.0"
|
|
25
18
|
},
|
|
26
19
|
"devDependencies": {
|
|
27
20
|
"@types/node": "^18.0.0",
|
|
28
21
|
"tsup": "^8.0.1",
|
|
29
|
-
"typescript": "^
|
|
22
|
+
"typescript": "^7.0.2"
|
|
30
23
|
},
|
|
31
24
|
"publishConfig": {
|
|
32
25
|
"access": "public"
|
|
@@ -38,5 +31,11 @@
|
|
|
38
31
|
"types": "./dist/index.d.ts",
|
|
39
32
|
"import": "./dist/index.js",
|
|
40
33
|
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "bun test",
|
|
37
|
+
"clean": "rm -rf ./dist",
|
|
38
|
+
"build": "tsup && bun run ../../scripts/emit-declarations.ts",
|
|
39
|
+
"dev": "tsup --watch"
|
|
41
40
|
}
|
|
42
|
-
}
|
|
41
|
+
}
|