@tsed/json-mapper 8.25.2 → 8.25.4
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.
|
@@ -70,9 +70,11 @@ export class JsonDeserializer extends JsonMapperCompiler {
|
|
|
70
70
|
}
|
|
71
71
|
return super.compile(model, groups);
|
|
72
72
|
}
|
|
73
|
-
eval(mapper, { id, groupsId, model }) {
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
eval(mapper, { id, groupsId, model, storeGroups }) {
|
|
74
|
+
if (typeof model === "function") {
|
|
75
|
+
this.constructors[id] = model;
|
|
76
|
+
}
|
|
77
|
+
return super.eval(mapper, { id, groupsId, model, storeGroups });
|
|
76
78
|
}
|
|
77
79
|
newInstanceOf(id, obj, options) {
|
|
78
80
|
try {
|
|
@@ -69,18 +69,17 @@ export class JsonMapperCompiler {
|
|
|
69
69
|
this.globals[key] = value;
|
|
70
70
|
return this;
|
|
71
71
|
}
|
|
72
|
-
eval(mapper, { id, groupsId, model }) {
|
|
73
|
-
this.addGlobal("cache", this.cache);
|
|
72
|
+
eval(mapper, { id, groupsId, model, storeGroups }) {
|
|
74
73
|
const { globals, schemes } = this;
|
|
75
74
|
const injectGlobals = Object.keys(globals)
|
|
76
75
|
.map((name) => {
|
|
77
76
|
return `const ${name} = globals.${name};`;
|
|
78
77
|
})
|
|
79
78
|
.join("\n");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const store =
|
|
79
|
+
const compileMapper = new Function("globals", "storeGroups", "schemes", "groupsId", "id", `${injectGlobals}
|
|
80
|
+
storeGroups.set(groupsId, {id, fn: (${mapper})});
|
|
81
|
+
return storeGroups.get(groupsId);`);
|
|
82
|
+
const store = compileMapper(globals, storeGroups, schemes, groupsId, id);
|
|
84
83
|
this.mappers[id] = store.fn;
|
|
85
84
|
return store;
|
|
86
85
|
}
|
|
@@ -111,7 +110,7 @@ export class JsonMapperCompiler {
|
|
|
111
110
|
});
|
|
112
111
|
const mapper = opts.mapper ? opts.mapper(id, groups) : this.createMapper(token, id, groups);
|
|
113
112
|
try {
|
|
114
|
-
return this.eval(mapper, { id, model: token,
|
|
113
|
+
return this.eval(mapper, { id, groupsId, model: token, storeGroups });
|
|
115
114
|
}
|
|
116
115
|
catch (err) {
|
|
117
116
|
throw new Error(`Fail to compile mapper for ${nameOf(model)}. See the error above: ${err.message}.\n${mapper}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import { JsonDeserializerOptions } from "./JsonDeserializerOptions.js";
|
|
3
|
-
import { CachedJsonMapper, JsonMapperCompiler } from "./JsonMapperCompiler.js";
|
|
3
|
+
import { CachedGroupsJsonMapper, CachedJsonMapper, JsonMapperCompiler } from "./JsonMapperCompiler.js";
|
|
4
4
|
/**
|
|
5
5
|
* Deserializes raw JSON data into class instances based on schema metadata,
|
|
6
6
|
* handling collections, discriminators, hooks, and registered type mappers.
|
|
@@ -14,10 +14,11 @@ export declare class JsonDeserializer extends JsonMapperCompiler<JsonDeserialize
|
|
|
14
14
|
constructor();
|
|
15
15
|
map<Model = any>(input: any, options?: JsonDeserializerOptions): Model;
|
|
16
16
|
compile(model: Type<any>, groups: false | string[]): CachedJsonMapper<JsonDeserializerOptions>;
|
|
17
|
-
eval(mapper: string, { id, groupsId, model }: {
|
|
17
|
+
eval(mapper: string, { id, groupsId, model, storeGroups }: {
|
|
18
18
|
id: string;
|
|
19
|
-
model: Type<any
|
|
19
|
+
model: Type<any> | string;
|
|
20
20
|
groupsId: string;
|
|
21
|
+
storeGroups: CachedGroupsJsonMapper<JsonDeserializerOptions>;
|
|
21
22
|
}): CachedJsonMapper<JsonDeserializerOptions>;
|
|
22
23
|
protected newInstanceOf(id: string, obj: any, options: any): any;
|
|
23
24
|
protected createMapper(model: Type<any>, id: string, groups: false | string[]): string;
|
|
@@ -51,10 +51,11 @@ export declare abstract class JsonMapperCompiler<Options extends Record<string,
|
|
|
51
51
|
addTypeMapper(model: Type<any> | string, fn: any): this;
|
|
52
52
|
removeTypeMapper(model: Type<any> | string): void;
|
|
53
53
|
addGlobal(key: string, value: any): this;
|
|
54
|
-
eval(mapper: string, { id, groupsId, model }: {
|
|
54
|
+
eval(mapper: string, { id, groupsId, model, storeGroups }: {
|
|
55
55
|
id: string;
|
|
56
|
-
model: Type<any> | string;
|
|
57
56
|
groupsId: string;
|
|
57
|
+
model: Type<any> | string;
|
|
58
|
+
storeGroups: CachedGroupsJsonMapper<Options>;
|
|
58
59
|
}): CachedJsonMapper<Options>;
|
|
59
60
|
createContext(options: Options): Options & {
|
|
60
61
|
cache: Map<string | Type<any>, CachedGroupsJsonMapper<Options>>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/json-mapper",
|
|
3
3
|
"description": "Json mapper module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.25.
|
|
5
|
+
"version": "8.25.4",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"tslib": "2.7.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@tsed/barrels": "8.25.
|
|
45
|
-
"@tsed/core": "8.25.
|
|
46
|
-
"@tsed/schema": "8.25.
|
|
47
|
-
"@tsed/typescript": "8.25.
|
|
44
|
+
"@tsed/barrels": "8.25.4",
|
|
45
|
+
"@tsed/core": "8.25.4",
|
|
46
|
+
"@tsed/schema": "8.25.4",
|
|
47
|
+
"@tsed/typescript": "8.25.4",
|
|
48
48
|
"eslint": "9.12.0",
|
|
49
49
|
"typescript": "5.9.3",
|
|
50
50
|
"vitest": "3.2.4"
|