@orion-js/models 3.0.37 → 3.0.38

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,8 +1,9 @@
1
- import { CreateModel, CloneOptions } from '../types';
1
+ import { CreateModel, CloneOptions, CreateModelOptions } from '../types';
2
2
  interface CloneInfo {
3
3
  createModel: CreateModel;
4
4
  getSchema: () => any;
5
5
  getResolvers: () => any;
6
+ modelOptions: CreateModelOptions;
6
7
  }
7
8
  declare const clone: (cloneInfo: CloneInfo, options: CloneOptions) => import("../types").Model;
8
9
  export default clone;
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const includes_1 = __importDefault(require("lodash/includes"));
7
7
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
8
8
  const clone = (cloneInfo, options) => {
9
- const { createModel, getSchema, getResolvers } = cloneInfo;
9
+ const { createModel, getSchema, getResolvers, modelOptions } = cloneInfo;
10
10
  return createModel({
11
11
  name: options.name,
12
+ clean: modelOptions.clean,
13
+ validate: modelOptions.validate,
12
14
  resolvers: () => {
13
15
  if (!options.extendResolvers)
14
16
  return getResolvers();
@@ -4,27 +4,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const index_1 = __importDefault(require("./index"));
7
- it('cloned model should pick fields correctly', async () => {
8
- const type = {
9
- type: String
10
- };
11
- const model1 = (0, index_1.default)({
12
- name: 'AModel',
13
- schema: {
14
- a: type,
15
- b: type,
16
- c: type
17
- }
7
+ describe('Cloning models', () => {
8
+ it('cloned model should pick fields correctly', async () => {
9
+ const type = {
10
+ type: String
11
+ };
12
+ const model1 = (0, index_1.default)({
13
+ name: 'AModel',
14
+ schema: {
15
+ a: type,
16
+ b: type,
17
+ c: type
18
+ }
19
+ });
20
+ const model2 = model1.clone({
21
+ name: 'Cloned2',
22
+ pickFields: ['a', 'b']
23
+ });
24
+ const model3 = model2.clone({
25
+ name: 'Cloned3',
26
+ omitFields: ['b']
27
+ });
28
+ const schema = model3.getSchema();
29
+ const keys = Object.keys(schema).filter(key => !key.startsWith('__'));
30
+ expect(keys).toEqual(['a']);
18
31
  });
19
- const model2 = model1.clone({
20
- name: 'Cloned2',
21
- pickFields: ['a', 'b']
32
+ it('should pass __clean and __validate to the cloned model schema', () => {
33
+ const clean = name => `clean ${name}`;
34
+ const model1 = (0, index_1.default)({
35
+ name: 'Model1',
36
+ schema: {
37
+ name: { type: String }
38
+ },
39
+ clean
40
+ });
41
+ const model2 = model1.clone({
42
+ name: 'Model2'
43
+ });
44
+ const schema1 = model1.getSchema();
45
+ const schema2 = model2.getSchema();
46
+ expect(schema1.__clean).toBe(clean);
47
+ expect(schema2.__clean).toBe(clean);
22
48
  });
23
- const model3 = model2.clone({
24
- name: 'Cloned3',
25
- omitFields: ['b']
26
- });
27
- const schema = model3.getSchema();
28
- const keys = Object.keys(schema).filter(key => !key.startsWith('__'));
29
- expect(keys).toEqual(['a']);
30
49
  });
@@ -75,7 +75,8 @@ const createModel = modelOptions => {
75
75
  return (0, clone_1.default)({
76
76
  createModel,
77
77
  getSchema,
78
- getResolvers
78
+ getResolvers,
79
+ modelOptions
79
80
  }, cloneOptions);
80
81
  }
81
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/models",
3
- "version": "3.0.37",
3
+ "version": "3.0.38",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "741691d7603f3d42e6e3e8fa9dc0f9de51a29424"
39
+ "gitHead": "00903f1488b72e13b7d5031a916eb897d0d80e0c"
40
40
  }