@orion-js/typed-model 3.7.4 → 3.7.6
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.
|
@@ -47,8 +47,10 @@ function getModelForClass(target) {
|
|
|
47
47
|
parent = Object.getPrototypeOf(parent);
|
|
48
48
|
}
|
|
49
49
|
const model = (0, models_1.createModel)({
|
|
50
|
-
name:
|
|
50
|
+
name: targetAsModel.name,
|
|
51
51
|
schema,
|
|
52
|
+
clean: targetAsModel.clean,
|
|
53
|
+
validate: targetAsModel.validate,
|
|
52
54
|
resolvers: {
|
|
53
55
|
...resolverMap,
|
|
54
56
|
...modelResolvers
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const models_1 = require("@orion-js/models");
|
|
13
|
+
const decorators_1 = require("../decorators");
|
|
14
|
+
const getModelForClass_1 = require("./getModelForClass");
|
|
15
|
+
describe('getModelForClass', () => {
|
|
16
|
+
it('should correctly pass the clean option to submodels', async () => {
|
|
17
|
+
const clean = () => ({ name: 'hello' });
|
|
18
|
+
const FileModel = (0, models_1.createModel)({
|
|
19
|
+
name: 'File',
|
|
20
|
+
schema: {
|
|
21
|
+
name: {
|
|
22
|
+
type: String
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
clean
|
|
26
|
+
});
|
|
27
|
+
let Config = class Config {
|
|
28
|
+
};
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, decorators_1.Prop)({
|
|
31
|
+
type: [FileModel]
|
|
32
|
+
}),
|
|
33
|
+
__metadata("design:type", Object)
|
|
34
|
+
], Config.prototype, "files", void 0);
|
|
35
|
+
Config = __decorate([
|
|
36
|
+
(0, decorators_1.TypedSchema)()
|
|
37
|
+
], Config);
|
|
38
|
+
const ConfigAsModel = (0, models_1.createModel)({
|
|
39
|
+
name: 'Config',
|
|
40
|
+
schema: {
|
|
41
|
+
files: {
|
|
42
|
+
type: [FileModel]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const modelForClass = (0, getModelForClass_1.getModelForClass)(Config);
|
|
47
|
+
const example = {
|
|
48
|
+
files: [
|
|
49
|
+
{
|
|
50
|
+
_id: '1'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
const cleanedAsModel = await ConfigAsModel.cleanAndValidate(example);
|
|
55
|
+
expect(cleanedAsModel.files[0].name).toEqual('hello');
|
|
56
|
+
const cleanedAsClass = await modelForClass.cleanAndValidate(example);
|
|
57
|
+
expect(cleanedAsClass).toEqual(cleanedAsModel);
|
|
58
|
+
});
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/typed-model",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.6",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/helpers": "^3.7.4",
|
|
21
|
-
"@orion-js/models": "^3.7.
|
|
21
|
+
"@orion-js/models": "^3.7.6",
|
|
22
22
|
"@orion-js/resolvers": "^3.7.4",
|
|
23
23
|
"@orion-js/schema": "^3.7.4",
|
|
24
24
|
"@orion-js/services": "^3.7.4",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c1bb048206f0309f38d32796b0ca5729a2052ec6"
|
|
45
45
|
}
|