@orion-js/typed-model 3.0.27 → 3.0.33
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.
|
@@ -5,6 +5,7 @@ exports.getModelForClass = void 0;
|
|
|
5
5
|
const models_1 = require("@orion-js/models");
|
|
6
6
|
const metadataStorage_1 = require("../storage/metadataStorage");
|
|
7
7
|
const processSchemaForProp_1 = require("./helpers/processSchemaForProp");
|
|
8
|
+
const modelCache = new Map();
|
|
8
9
|
function processModelSchemaForProp(prop) {
|
|
9
10
|
if (prop.type?.__isModel === true) {
|
|
10
11
|
return prop;
|
|
@@ -12,6 +13,10 @@ function processModelSchemaForProp(prop) {
|
|
|
12
13
|
return (0, processSchemaForProp_1.processSchemaForProp)(prop);
|
|
13
14
|
}
|
|
14
15
|
function getModelForClass(target) {
|
|
16
|
+
const schemaId = target.__schemaId;
|
|
17
|
+
if (modelCache.has(schemaId)) {
|
|
18
|
+
return modelCache.get(schemaId);
|
|
19
|
+
}
|
|
15
20
|
const schema = {};
|
|
16
21
|
const resolverMap = {};
|
|
17
22
|
let parent = target;
|
|
@@ -29,10 +34,12 @@ function getModelForClass(target) {
|
|
|
29
34
|
});
|
|
30
35
|
parent = Object.getPrototypeOf(parent);
|
|
31
36
|
}
|
|
32
|
-
|
|
37
|
+
const model = (0, models_1.createModel)({
|
|
33
38
|
name: target.name,
|
|
34
39
|
schema,
|
|
35
40
|
resolvers: resolverMap
|
|
36
41
|
});
|
|
42
|
+
modelCache.set(schemaId, model);
|
|
43
|
+
return model;
|
|
37
44
|
}
|
|
38
45
|
exports.getModelForClass = getModelForClass;
|
package/lib/index.test.js
CHANGED
|
@@ -552,6 +552,19 @@ describe('typed-schema e2e tests', () => {
|
|
|
552
552
|
expect((0, index_1.getModelForClass)(Spec).name).toEqual(expected.name);
|
|
553
553
|
expect((0, index_1.getModelForClass)(Spec).getCleanSchema()).toEqual(expected.getCleanSchema());
|
|
554
554
|
});
|
|
555
|
+
it('Should return the same object when calling getModelForClass multiple times', () => {
|
|
556
|
+
let Spec = class Spec {
|
|
557
|
+
};
|
|
558
|
+
__decorate([
|
|
559
|
+
(0, index_1.Prop)(),
|
|
560
|
+
__metadata("design:type", String)
|
|
561
|
+
], Spec.prototype, "name", void 0);
|
|
562
|
+
Spec = __decorate([
|
|
563
|
+
(0, index_1.TypedModel)()
|
|
564
|
+
], Spec);
|
|
565
|
+
const model = (0, index_1.getModelForClass)(Spec);
|
|
566
|
+
expect((0, index_1.getModelForClass)(Spec)).toBe(model);
|
|
567
|
+
});
|
|
555
568
|
});
|
|
556
569
|
describe('using resolvers', () => {
|
|
557
570
|
it('allows passing resolvers to the model', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/typed-model",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.33",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"test": "jest --config jest.config.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@orion-js/helpers": "^3.0.
|
|
21
|
-
"@orion-js/models": "^3.0.
|
|
22
|
-
"@orion-js/resolvers": "^3.0.
|
|
23
|
-
"@orion-js/schema": "^3.0.
|
|
20
|
+
"@orion-js/helpers": "^3.0.31",
|
|
21
|
+
"@orion-js/models": "^3.0.32",
|
|
22
|
+
"@orion-js/resolvers": "^3.0.32",
|
|
23
|
+
"@orion-js/schema": "^3.0.32",
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"reflect-metadata": "0.1.13"
|
|
26
26
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3ae1a9b2872f026dca2edb6684d87d66151bd71e"
|
|
43
43
|
}
|