@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.
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_1 = __importDefault(require("./index"));
7
- const resolvers_1 = require("@orion-js/resolvers");
8
- it('should validate a schema', async () => {
9
- const model = (0, index_1.default)({
10
- name: 'AModel',
11
- schema: {
12
- name: {
13
- type: String
14
- }
15
- }
16
- });
17
- await model.validate({ name: 'String' });
18
- });
19
- it('should allow deep model validation', async () => {
20
- const model2 = (0, index_1.default)({
21
- name: 'AModel',
22
- schema: {
23
- firstName: {
24
- type: String
25
- },
26
- lastName: {
27
- type: String
28
- }
29
- }
30
- });
31
- const model1 = (0, index_1.default)({
32
- name: 'AModel2',
33
- schema: {
34
- data: {
35
- type: model2
36
- }
37
- }
38
- });
39
- await model1.validate({ data: { firstName: 'Nicolás', lastName: 'López' } });
40
- expect.assertions(1);
41
- try {
42
- await model1.validate({});
43
- }
44
- catch (error) {
45
- expect(error.code).toBe('validationError');
46
- }
47
- });
48
- it('[regression test]: should allow correct doc cleaning for resolver params', async () => {
49
- const Point = (0, index_1.default)({
50
- name: 'Point',
51
- schema: {
52
- latitude: {
53
- type: Number
54
- },
55
- longitude: {
56
- type: Number
57
- }
58
- }
59
- });
60
- const resolver1 = (0, resolvers_1.resolver)({
61
- params: {
62
- point: {
63
- type: Point
64
- }
65
- },
66
- async resolve({ point }) {
67
- return point;
68
- }
69
- });
70
- const doc = await resolver1.resolve({ point: { latitude: '11', longitude: '12' } });
71
- expect(doc).toEqual({ latitude: 11, longitude: 12 });
72
- });
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import createModel from './createModel';
2
- import { modelToSchema, modelToSchemaWithModel } from './createModel/modelToSchema';
3
- export { createModel, modelToSchema, modelToSchemaWithModel };
4
- export * from './types';
package/lib/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.modelToSchemaWithModel = exports.modelToSchema = exports.createModel = void 0;
17
- const createModel_1 = __importDefault(require("./createModel"));
18
- exports.createModel = createModel_1.default;
19
- const modelToSchema_1 = require("./createModel/modelToSchema");
20
- Object.defineProperty(exports, "modelToSchema", { enumerable: true, get: function () { return modelToSchema_1.modelToSchema; } });
21
- Object.defineProperty(exports, "modelToSchemaWithModel", { enumerable: true, get: function () { return modelToSchema_1.modelToSchemaWithModel; } });
22
- __exportStar(require("./types"), exports);
@@ -1,99 +0,0 @@
1
- import { GlobalResolverResolve, ModelResolver, ModelResolverResolve, Resolver } from '@orion-js/resolvers';
2
- import { Schema, SchemaMetaFieldType, SchemaNode } from '@orion-js/schema';
3
- export interface ModelsSchemaNode extends Omit<SchemaNode, 'type'> {
4
- type: Model | [Model] | SchemaMetaFieldType;
5
- }
6
- export interface ModelSchema {
7
- [key: string]: ModelsSchemaNode;
8
- }
9
- export interface CreateModelOptions {
10
- /**
11
- * The name of the model, used for example for GraphQL
12
- */
13
- name: string;
14
- /**
15
- * Pass a function that returns the schema. For example: () => require('./schema').
16
- * This is used like this to allow circular dependencies
17
- */
18
- schema?: ModelSchema | (() => {
19
- default: ModelSchema;
20
- });
21
- /**
22
- * Pass a function that returns the resolvers. For example: () => require('./resolvers')
23
- * This is used like this to allow circular dependencies
24
- */
25
- resolvers?: ModelResolversMap | (() => {
26
- default: ModelResolversMap;
27
- });
28
- /**
29
- * Optional function that will process the document before being returned.
30
- * @param doc The current document
31
- * @return The processed document promise
32
- */
33
- clean?: (doc: any) => Promise<any> | any;
34
- /**
35
- * Optional function that will validate the document before being returned.
36
- * @param doc The current document
37
- */
38
- validate?: (doc: any) => Promise<void> | void;
39
- }
40
- export interface ModelResolversMap {
41
- [key: string]: ModelResolver<ModelResolverResolve>;
42
- }
43
- export interface GlobalResolversMap {
44
- [key: string]: Resolver<GlobalResolverResolve>;
45
- }
46
- export interface CloneOptions {
47
- name: string;
48
- omitFields?: string[];
49
- pickFields?: string[];
50
- mapFields?: (field: any, key: string) => any;
51
- extendSchema?: Schema;
52
- extendResolvers?: ModelResolversMap;
53
- }
54
- export interface Model<TSchema = any> {
55
- __isModel: boolean;
56
- /**
57
- * The name of the model, used for example for GraphQL
58
- */
59
- name: string;
60
- /**
61
- * Returns the schema of the model
62
- */
63
- getSchema: () => Schema & {
64
- __model: Model;
65
- };
66
- /**
67
- * Returns the schema without adding __model to the schema
68
- */
69
- getCleanSchema: () => Schema;
70
- /**
71
- * Returns the model resolvers
72
- */
73
- getResolvers: () => ModelResolversMap;
74
- /**
75
- * Adds the model resolvers to a item
76
- */
77
- initItem: (item: any) => any;
78
- /**
79
- * Validates an item using @orion-js/schema
80
- */
81
- validate: (item: any) => Promise<any>;
82
- /**
83
- * Cleans an item using @orion-js/schema
84
- */
85
- clean: (item: any) => Promise<TSchema>;
86
- /**
87
- * Cleans and validates an item using @orion-js/schema
88
- */
89
- cleanAndValidate: (item: any) => Promise<TSchema>;
90
- /**
91
- * Creates a new model using this one as a base
92
- */
93
- clone: (cloneOptions: CloneOptions) => Model;
94
- /**
95
- * The type of the model. Only use this in typescript
96
- */
97
- type: TSchema;
98
- }
99
- export declare type CreateModel<TSchema = any> = (options: CreateModelOptions) => Model<TSchema>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("..");
4
- it('should create correctly a model with its schema', async () => {
5
- const model1 = (0, __1.createModel)({
6
- name: 'Name',
7
- schema: {
8
- services: {
9
- type: 'blackbox'
10
- }
11
- }
12
- });
13
- const model2 = (0, __1.createModel)({
14
- name: 'Name',
15
- schema: {
16
- services: {
17
- type: model1,
18
- private: true
19
- }
20
- }
21
- });
22
- const model3 = (0, __1.createModel)({
23
- name: 'Name',
24
- schema: {
25
- services: {
26
- type: [model2],
27
- optional: true
28
- }
29
- }
30
- });
31
- const model4 = (0, __1.createModel)({
32
- name: 'Name',
33
- schema: {}
34
- });
35
- });