@orion-js/models 3.7.4 → 3.9.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.
@@ -71,6 +71,12 @@ function createModel(modelOptions) {
71
71
  const schema = getSchema();
72
72
  return await (0, schema_1.clean)(schema, doc);
73
73
  },
74
+ cleanAndValidate: async (doc) => {
75
+ const schema = getSchema();
76
+ const cleaned = await (0, schema_1.clean)(schema, doc);
77
+ await (0, schema_1.validate)(schema, cleaned);
78
+ return cleaned;
79
+ },
74
80
  clone: (cloneOptions) => {
75
81
  return (0, clone_1.default)({
76
82
  createModel,
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const __1 = require("..");
7
6
  const _1 = __importDefault(require("."));
8
7
  const schema_1 = require("@orion-js/schema");
9
8
  it('should add the __model field when converting to schema', async () => {
@@ -18,30 +17,33 @@ it('should add the __model field when converting to schema', async () => {
18
17
  expect(schema.__model.name).toEqual('test');
19
18
  });
20
19
  it('can clean a schema with nested models', async () => {
21
- const modelSchema = {
22
- name: {
23
- type: String,
24
- clean: () => 'Model Schema'
25
- }
26
- };
27
20
  const model = (0, _1.default)({
28
21
  name: 'AModel',
29
- schema: modelSchema
30
- });
31
- const schema = {
32
- subModel: {
33
- type: model
34
- },
35
- subModelArray: {
36
- type: [model]
22
+ schema: {
23
+ name: {
24
+ type: String
25
+ }
37
26
  },
38
- primitive: {
39
- type: String,
40
- clean: () => 'Primitive'
27
+ clean: () => ({ name: 'Model Schema' })
28
+ });
29
+ const finalModel = (0, _1.default)({
30
+ name: 'Test',
31
+ schema: {
32
+ subModel: {
33
+ type: model
34
+ },
35
+ subModelArray: {
36
+ type: [model]
37
+ },
38
+ primitive: {
39
+ type: String,
40
+ clean: () => 'Primitive'
41
+ }
41
42
  }
42
- };
43
+ });
43
44
  const doc = { subModel: { name: 'Joaquin' }, subModelArray: [{ name: 'Roberto' }], primitive: 'hello' };
44
- expect(await (0, schema_1.clean)((0, __1.modelToSchema)(schema), doc)).toEqual({
45
+ const schema = finalModel.getSchema();
46
+ expect(await (0, schema_1.clean)(schema, doc)).toEqual({
45
47
  subModel: { name: 'Model Schema' },
46
48
  subModelArray: [{ name: 'Model Schema' }],
47
49
  primitive: 'Primitive'
@@ -82,7 +82,11 @@ export interface Model<TSchema = any> {
82
82
  /**
83
83
  * Cleans an item using @orion-js/schema
84
84
  */
85
- clean: (item: any) => Promise<any>;
85
+ clean: (item: any) => Promise<TSchema>;
86
+ /**
87
+ * Cleans and validates an item using @orion-js/schema
88
+ */
89
+ cleanAndValidate: (item: any) => Promise<TSchema>;
86
90
  /**
87
91
  * Creates a new model using this one as a base
88
92
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/models",
3
- "version": "3.7.4",
3
+ "version": "3.9.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -17,15 +17,15 @@
17
17
  "upgrade-interactive": "yarn upgrade-interactive"
18
18
  },
19
19
  "dependencies": {
20
- "@orion-js/helpers": "^3.7.4",
21
- "@orion-js/resolvers": "^3.7.4",
22
- "@orion-js/schema": "^3.7.4"
20
+ "@orion-js/helpers": "^3.9.0",
21
+ "@orion-js/resolvers": "^3.9.0",
22
+ "@orion-js/schema": "^3.9.0"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "@orion-js/cache": "^3.0.0-alpha.10"
26
26
  },
27
27
  "devDependencies": {
28
- "@orion-js/cache": "^3.7.4",
28
+ "@orion-js/cache": "^3.9.0",
29
29
  "@shelf/jest-mongodb": "^2.1.0",
30
30
  "@types/jest": "^27.0.2",
31
31
  "@types/lodash": "4.14.176",
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "c77b95ffc592ddce0ba6b95ae5e34f3e273c4cd5"
39
+ "gitHead": "23e0eda5348153dcc07b307a97b641d52eb41f39"
40
40
  }