@tsed/json-mapper 7.35.0 → 7.36.0-rc.1
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.
- package/jest.config.js +3 -3
- package/lib/browser/json-mapper.umd.min.js +1 -1
- package/lib/browser/json-mapper.umd.min.js.map +1 -1
- package/lib/cjs/components/DateMapper.js +1 -1
- package/lib/cjs/components/DateMapper.js.map +1 -1
- package/lib/cjs/components/PrimitiveMapper.js +30 -26
- package/lib/cjs/components/PrimitiveMapper.js.map +1 -1
- package/lib/cjs/components/SymbolMapper.js.map +1 -1
- package/lib/cjs/domain/JsonDeserializer.js +275 -0
- package/lib/cjs/domain/JsonDeserializer.js.map +1 -0
- package/lib/cjs/domain/JsonDeserializerOptions.js +3 -0
- package/lib/cjs/domain/JsonDeserializerOptions.js.map +1 -0
- package/lib/cjs/domain/JsonMapperCompiler.js +167 -0
- package/lib/cjs/domain/JsonMapperCompiler.js.map +1 -0
- package/lib/cjs/domain/JsonSerializer.js +219 -0
- package/lib/cjs/domain/JsonSerializer.js.map +1 -0
- package/lib/cjs/domain/JsonSerializerOptions.js +3 -0
- package/lib/cjs/domain/JsonSerializerOptions.js.map +1 -0
- package/lib/cjs/domain/Writer.js +141 -0
- package/lib/cjs/domain/Writer.js.map +1 -0
- package/lib/cjs/hooks/alterOnDeserialize.js +8 -0
- package/lib/cjs/hooks/alterOnDeserialize.js.map +1 -0
- package/lib/cjs/hooks/alterOnSerialize.js +8 -0
- package/lib/cjs/hooks/alterOnSerialize.js.map +1 -0
- package/lib/cjs/index.js +9 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils/deserialize.js +5 -202
- package/lib/cjs/utils/deserialize.js.map +1 -1
- package/lib/cjs/utils/getObjectProperties.js +9 -0
- package/lib/cjs/utils/getObjectProperties.js.map +1 -0
- package/lib/cjs/utils/serialize.js +5 -143
- package/lib/cjs/utils/serialize.js.map +1 -1
- package/lib/esm/components/DateMapper.js +1 -1
- package/lib/esm/components/DateMapper.js.map +1 -1
- package/lib/esm/components/PrimitiveMapper.js +30 -26
- package/lib/esm/components/PrimitiveMapper.js.map +1 -1
- package/lib/esm/components/SymbolMapper.js.map +1 -1
- package/lib/esm/domain/JsonDeserializer.js +271 -0
- package/lib/esm/domain/JsonDeserializer.js.map +1 -0
- package/lib/esm/domain/JsonDeserializerOptions.js +2 -0
- package/lib/esm/domain/JsonDeserializerOptions.js.map +1 -0
- package/lib/esm/domain/JsonMapperCompiler.js +163 -0
- package/lib/esm/domain/JsonMapperCompiler.js.map +1 -0
- package/lib/esm/domain/JsonSerializer.js +215 -0
- package/lib/esm/domain/JsonSerializer.js.map +1 -0
- package/lib/esm/domain/JsonSerializerOptions.js +2 -0
- package/lib/esm/domain/JsonSerializerOptions.js.map +1 -0
- package/lib/esm/domain/Writer.js +137 -0
- package/lib/esm/domain/Writer.js.map +1 -0
- package/lib/esm/hooks/alterOnDeserialize.js +4 -0
- package/lib/esm/hooks/alterOnDeserialize.js.map +1 -0
- package/lib/esm/hooks/alterOnSerialize.js +4 -0
- package/lib/esm/hooks/alterOnSerialize.js.map +1 -0
- package/lib/esm/index.js +9 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils/deserialize.js +4 -200
- package/lib/esm/utils/deserialize.js.map +1 -1
- package/lib/esm/utils/getObjectProperties.js +5 -0
- package/lib/esm/utils/getObjectProperties.js.map +1 -0
- package/lib/esm/utils/serialize.js +4 -141
- package/lib/esm/utils/serialize.js.map +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/components/PrimitiveMapper.d.ts +4 -0
- package/lib/types/domain/JsonDeserializer.d.ts +33 -0
- package/lib/types/domain/JsonDeserializerOptions.d.ts +31 -0
- package/lib/types/domain/JsonMapperCompiler.d.ts +58 -0
- package/lib/types/domain/JsonSerializer.d.ts +21 -0
- package/lib/types/domain/JsonSerializerOptions.d.ts +13 -0
- package/lib/types/domain/Writer.d.ts +43 -0
- package/lib/types/hooks/alterOnDeserialize.d.ts +2 -0
- package/lib/types/hooks/alterOnSerialize.d.ts +2 -0
- package/lib/types/index.d.ts +9 -4
- package/lib/types/utils/deserialize.d.ts +2 -47
- package/lib/types/utils/getObjectProperties.d.ts +1 -0
- package/lib/types/utils/serialize.d.ts +2 -18
- package/package.json +11 -8
- package/lib/cjs/components/ArrayMapper.js +0 -23
- package/lib/cjs/components/ArrayMapper.js.map +0 -1
- package/lib/cjs/components/MapMapper.js +0 -30
- package/lib/cjs/components/MapMapper.js.map +0 -1
- package/lib/cjs/components/SetMapper.js +0 -30
- package/lib/cjs/components/SetMapper.js.map +0 -1
- package/lib/cjs/domain/JsonMapperContext.js +0 -27
- package/lib/cjs/domain/JsonMapperContext.js.map +0 -1
- package/lib/esm/components/ArrayMapper.js +0 -20
- package/lib/esm/components/ArrayMapper.js.map +0 -1
- package/lib/esm/components/MapMapper.js +0 -27
- package/lib/esm/components/MapMapper.js.map +0 -1
- package/lib/esm/components/SetMapper.js +0 -27
- package/lib/esm/components/SetMapper.js.map +0 -1
- package/lib/esm/domain/JsonMapperContext.js +0 -23
- package/lib/esm/domain/JsonMapperContext.js.map +0 -1
- package/lib/types/components/ArrayMapper.d.ts +0 -10
- package/lib/types/components/MapMapper.d.ts +0 -12
- package/lib/types/components/SetMapper.d.ts +0 -10
- package/lib/types/domain/JsonMapperContext.d.ts +0 -20
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { classOf, hasJsonMethod, isClassObject, isCollection, isDate, isMomentObject, isMongooseObject, isNil, isObject, isPrimitive, nameOf } from "@tsed/core";
|
|
2
|
+
import { getPropertiesStores, JsonEntityStore } from "@tsed/schema";
|
|
3
|
+
import { alterOnSerialize } from "../hooks/alterOnSerialize.js";
|
|
4
|
+
import { getObjectProperties } from "../utils/getObjectProperties.js";
|
|
5
|
+
import { JsonMapperCompiler } from "./JsonMapperCompiler.js";
|
|
6
|
+
import { getJsonMapperTypes } from "./JsonMapperTypesContainer.js";
|
|
7
|
+
import { Writer } from "./Writer.js";
|
|
8
|
+
function getBestType(type, obj) {
|
|
9
|
+
const dataType = classOf(obj);
|
|
10
|
+
if (dataType && !isClassObject(dataType)) {
|
|
11
|
+
return dataType;
|
|
12
|
+
}
|
|
13
|
+
return type || Object;
|
|
14
|
+
}
|
|
15
|
+
export class JsonSerializer extends JsonMapperCompiler {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.addTypeMapper(Object, this.mapObject.bind(this));
|
|
19
|
+
this.addTypeMapper(Array, this.mapArray.bind(this));
|
|
20
|
+
this.addTypeMapper(Map, this.mapMap.bind(this));
|
|
21
|
+
this.addTypeMapper(Set, this.mapSet.bind(this));
|
|
22
|
+
this.addGlobal("mapJSON", this.mapJSON.bind(this));
|
|
23
|
+
this.addTypeMapper("ObjectId", (value) => String(value));
|
|
24
|
+
}
|
|
25
|
+
map(input, options = {}) {
|
|
26
|
+
if (isNil(input)) {
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
options = this.mapOptions(options);
|
|
30
|
+
const model = getBestType(options.type, input);
|
|
31
|
+
const mapper = this.compile(model, options.groups);
|
|
32
|
+
return mapper.fn(input, this.createContext(options));
|
|
33
|
+
}
|
|
34
|
+
alterValue(schemaId, value, options) {
|
|
35
|
+
return alterOnSerialize(this.schemes[schemaId], value, options);
|
|
36
|
+
}
|
|
37
|
+
createMapper(model, id, groups) {
|
|
38
|
+
const entity = JsonEntityStore.from(model);
|
|
39
|
+
const properties = new Set();
|
|
40
|
+
const schemaProperties = [...getPropertiesStores(entity).values()];
|
|
41
|
+
const writer = new Writer().arrow("input", "options");
|
|
42
|
+
writer.if("isNil(input)").return("input");
|
|
43
|
+
// prepare options
|
|
44
|
+
writer.const("obj", "{}");
|
|
45
|
+
writer.set("options", "{...options, self: input}");
|
|
46
|
+
// detect some special case
|
|
47
|
+
writer.add(this.mapPrecondition(id));
|
|
48
|
+
if (!schemaProperties.length) {
|
|
49
|
+
return writer.return("input").root().toString();
|
|
50
|
+
}
|
|
51
|
+
// properties
|
|
52
|
+
writer.add(...schemaProperties.flatMap((propertyStore) => {
|
|
53
|
+
properties.add(propertyStore.propertyKey);
|
|
54
|
+
if (propertyStore.schema?.$hooks?.has("groups") && this.alterGroups(propertyStore.schema, groups)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return this.mapProperty(propertyStore, id, groups);
|
|
58
|
+
}));
|
|
59
|
+
// discriminator
|
|
60
|
+
writer.add(this.mapDiscriminator(entity));
|
|
61
|
+
// additional properties
|
|
62
|
+
writer.add(this.mapAdditionalProperties(entity, properties));
|
|
63
|
+
return writer.return("obj").root().toString();
|
|
64
|
+
}
|
|
65
|
+
mapOptions({ groups = false, useAlias = true, types, ...options }) {
|
|
66
|
+
const customMappers = {};
|
|
67
|
+
types = types || getJsonMapperTypes();
|
|
68
|
+
types.forEach((mapper, model) => {
|
|
69
|
+
if (![Array, Set, Map].includes(model)) {
|
|
70
|
+
this.addTypeMapper(model, mapper.serialize.bind(mapper));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
...options,
|
|
75
|
+
groups,
|
|
76
|
+
useAlias,
|
|
77
|
+
customMappers
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
mapProperty(propertyStore, id, groups) {
|
|
81
|
+
const key = String(propertyStore.propertyKey);
|
|
82
|
+
const aliasKey = String(propertyStore.parent.schema.getAliasOf(key) || key);
|
|
83
|
+
const schemaId = this.getSchemaId(id, key);
|
|
84
|
+
let writer = new Writer().add(`// Map ${key} ${id} ${groups || ""}`);
|
|
85
|
+
// ignore hook (deprecated)
|
|
86
|
+
if (propertyStore.schema?.$hooks?.has("ignore")) {
|
|
87
|
+
this.schemes[schemaId] = propertyStore.schema;
|
|
88
|
+
writer = writer.if(`!alterIgnore('${schemaId}', {...options, self: input})`);
|
|
89
|
+
}
|
|
90
|
+
writer = writer.add(`let ${key} = input.${key};`).if(`${key} !== undefined`);
|
|
91
|
+
const format = propertyStore.itemSchema.get("format");
|
|
92
|
+
const formatOpts = format && `options: {format: '${format}'}`;
|
|
93
|
+
// pre hook
|
|
94
|
+
const hasSerializer = propertyStore.schema?.$hooks?.has("onSerialize");
|
|
95
|
+
if (hasSerializer) {
|
|
96
|
+
this.schemes[schemaId] = propertyStore.schema;
|
|
97
|
+
const opts = Writer.options(formatOpts);
|
|
98
|
+
writer.set(key, `alterValue('${schemaId}', ${key}, ${opts})`);
|
|
99
|
+
}
|
|
100
|
+
const fill = this.getPropertyFiller(propertyStore, key, groups, formatOpts);
|
|
101
|
+
if (hasSerializer) {
|
|
102
|
+
fill(writer.if(`${key} === input.${key}`));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
fill(writer);
|
|
106
|
+
}
|
|
107
|
+
if (aliasKey !== key) {
|
|
108
|
+
writer.set(`obj[options.useAlias ? '${aliasKey}' : '${key}']`, key);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
writer.set(`obj.${key}`, key);
|
|
112
|
+
}
|
|
113
|
+
return writer.root();
|
|
114
|
+
}
|
|
115
|
+
getPropertyFiller(propertyStore, key, groups, formatOpts) {
|
|
116
|
+
if (propertyStore.isCollection) {
|
|
117
|
+
const type = propertyStore.getBestType();
|
|
118
|
+
const nestedMapper = this.compile(type, groups);
|
|
119
|
+
return (writer) => writer.callMapper(nameOf(propertyStore.collectionType), key, `id: '${nestedMapper.id}'`, formatOpts);
|
|
120
|
+
}
|
|
121
|
+
const type = propertyStore.getBestType();
|
|
122
|
+
const nestedMapper = this.compile(type, groups);
|
|
123
|
+
return (writer) => writer.callMapper(nestedMapper.id, key, formatOpts);
|
|
124
|
+
}
|
|
125
|
+
mapPrecondition(id) {
|
|
126
|
+
const writer = new Writer();
|
|
127
|
+
writer.if("input && isCollection(input)").return(Writer.mapperFrom("input", `{...options, id: '${id}'}`));
|
|
128
|
+
writer.if("hasJsonMethod(input)").return(`mapJSON(input, {...options, id: '${id}'})`);
|
|
129
|
+
return writer;
|
|
130
|
+
}
|
|
131
|
+
mapDiscriminator(entity) {
|
|
132
|
+
if (entity.discriminatorAncestor) {
|
|
133
|
+
const discriminator = entity.discriminatorAncestor.schema.discriminator();
|
|
134
|
+
const type = discriminator.getDefaultValue(entity.target);
|
|
135
|
+
if (type) {
|
|
136
|
+
const writer = new Writer();
|
|
137
|
+
writer.if(`!obj.${discriminator.propertyName}`).set(`obj.${discriminator.propertyName}`, `'${type}'`);
|
|
138
|
+
return writer;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
mapAdditionalProperties(entity, properties) {
|
|
143
|
+
const additionalProperties = !!entity.schema.get("additionalProperties");
|
|
144
|
+
if (additionalProperties) {
|
|
145
|
+
const exclude = [...properties.values()].map((key) => `'${key}'`).join(", ");
|
|
146
|
+
const writer = new Writer();
|
|
147
|
+
writer.add("// add additional properties");
|
|
148
|
+
writer.each("objectKeys(input)", ["key"]).if(`![${exclude}].includes(key)`).set("obj[key]", "input[key]");
|
|
149
|
+
return writer;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
mapObject(input, { type, ...options }) {
|
|
153
|
+
if ((input && isPrimitive(input)) || !input) {
|
|
154
|
+
// prevent mongoose mapping error
|
|
155
|
+
return input;
|
|
156
|
+
}
|
|
157
|
+
if (input && isCollection(input)) {
|
|
158
|
+
return this.execMapper(nameOf(classOf(input)), input, options);
|
|
159
|
+
}
|
|
160
|
+
if (hasJsonMethod(input)) {
|
|
161
|
+
return this.mapJSON(input, options);
|
|
162
|
+
}
|
|
163
|
+
return getObjectProperties(input)
|
|
164
|
+
.filter(([, value]) => value !== undefined)
|
|
165
|
+
.reduce((obj, [key, value]) => {
|
|
166
|
+
if (isNil(value)) {
|
|
167
|
+
return {
|
|
168
|
+
...obj,
|
|
169
|
+
[key]: value
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const mapper = this.compile(classOf(value), options.groups);
|
|
173
|
+
return {
|
|
174
|
+
...obj,
|
|
175
|
+
[key]: mapper.fn(value, options)
|
|
176
|
+
};
|
|
177
|
+
}, {});
|
|
178
|
+
}
|
|
179
|
+
mapSet(input, options) {
|
|
180
|
+
return [...input.values()].map((item) => {
|
|
181
|
+
return this.mapItem(item, options);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
mapArray(input, options) {
|
|
185
|
+
return [].concat(input).map((item) => {
|
|
186
|
+
return this.mapItem(item, options);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
mapMap(input, options) {
|
|
190
|
+
return [...input.entries()].reduce((obj, [key, item]) => {
|
|
191
|
+
return {
|
|
192
|
+
...obj,
|
|
193
|
+
[key]: this.mapItem(item, options)
|
|
194
|
+
};
|
|
195
|
+
}, {});
|
|
196
|
+
}
|
|
197
|
+
mapItem(input, { id, ...options }) {
|
|
198
|
+
if (!id && input) {
|
|
199
|
+
return this.compile(classOf(input), options.groups).fn(input, options);
|
|
200
|
+
}
|
|
201
|
+
return id ? this.execMapper(id, input, options) : input;
|
|
202
|
+
}
|
|
203
|
+
mapJSON(input, { id, ...options }) {
|
|
204
|
+
if (isMongooseObject(input)) {
|
|
205
|
+
return input.toJSON({ ...options, id });
|
|
206
|
+
}
|
|
207
|
+
id = id || nameOf(classOf(input));
|
|
208
|
+
if (this.mappers[id] && (isDate(input) || isMomentObject(input))) {
|
|
209
|
+
return this.execMapper(id, input, options);
|
|
210
|
+
}
|
|
211
|
+
input = input.toJSON();
|
|
212
|
+
return isObject(input) ? this.execMapper(id, input, options) : input;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=JsonSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSerializer.js","sourceRoot":"","sources":["../../../src/domain/JsonSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,aAAa,EACb,YAAY,EACZ,MAAM,EACN,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,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSerializerOptions.js","sourceRoot":"","sources":["../../../src/domain/JsonSerializerOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export class Writer {
|
|
2
|
+
static object = {
|
|
3
|
+
assign(...args) {
|
|
4
|
+
return `{ ${args.filter(Boolean).join(", ")} }`;
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
_root;
|
|
8
|
+
body = [];
|
|
9
|
+
_indent;
|
|
10
|
+
constructor(root) {
|
|
11
|
+
this._root = root;
|
|
12
|
+
}
|
|
13
|
+
static indent(lines) {
|
|
14
|
+
return lines.map((p) => `\t${p}`);
|
|
15
|
+
}
|
|
16
|
+
static mapper(mapperId, key, options) {
|
|
17
|
+
return `execMapper('${mapperId}', ${key}, ${options})`;
|
|
18
|
+
}
|
|
19
|
+
static mapperFrom(key, options) {
|
|
20
|
+
return `execMapper(nameOf(classOf(${key})), ${key}, ${options})`;
|
|
21
|
+
}
|
|
22
|
+
static options(...args) {
|
|
23
|
+
args = args.filter(Boolean);
|
|
24
|
+
return !args.length ? "options" : Writer.object.assign("...options", ...args);
|
|
25
|
+
}
|
|
26
|
+
add(...lines) {
|
|
27
|
+
lines = lines.filter((line) => line !== undefined);
|
|
28
|
+
lines.length && this.body.push(...lines);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
arrow(...args) {
|
|
32
|
+
this.add(`(${args}) => {`);
|
|
33
|
+
const writer = this.new();
|
|
34
|
+
this.add("}");
|
|
35
|
+
return writer;
|
|
36
|
+
}
|
|
37
|
+
build() {
|
|
38
|
+
const result = this.body.flatMap((line) => {
|
|
39
|
+
return line instanceof Writer ? line.build() : line;
|
|
40
|
+
});
|
|
41
|
+
return this._indent ? result.map((item) => "\t" + item) : result;
|
|
42
|
+
}
|
|
43
|
+
callMapper(id, key, ...options) {
|
|
44
|
+
return this.set(key, Writer.mapper(id, key, Writer.options(...options)));
|
|
45
|
+
}
|
|
46
|
+
returnCallMapper(id, key, ...options) {
|
|
47
|
+
return this.return(Writer.mapper(id, key, Writer.options(...options)));
|
|
48
|
+
}
|
|
49
|
+
const(name, line) {
|
|
50
|
+
this.add(`const ${name} = ${line};`);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
each(iterable, args = []) {
|
|
54
|
+
const writer = this.add(iterable + ".forEach((" + args.join(", ") + ") => {").new();
|
|
55
|
+
this.add("});");
|
|
56
|
+
return writer;
|
|
57
|
+
}
|
|
58
|
+
if(condition) {
|
|
59
|
+
const writer = new IfWriter(condition, this);
|
|
60
|
+
this.add(writer);
|
|
61
|
+
return writer;
|
|
62
|
+
}
|
|
63
|
+
switch(input) {
|
|
64
|
+
const sw = new SwitchWriter(input);
|
|
65
|
+
this.add(sw);
|
|
66
|
+
return sw;
|
|
67
|
+
}
|
|
68
|
+
indent(indent) {
|
|
69
|
+
this._indent = indent;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
new(indent = true) {
|
|
73
|
+
const writer = new Writer(this.root());
|
|
74
|
+
writer.indent(indent);
|
|
75
|
+
this.add(writer);
|
|
76
|
+
return writer;
|
|
77
|
+
}
|
|
78
|
+
return(line) {
|
|
79
|
+
this.add(`return ${line};`);
|
|
80
|
+
return this.root();
|
|
81
|
+
}
|
|
82
|
+
root() {
|
|
83
|
+
return this._root || this;
|
|
84
|
+
}
|
|
85
|
+
set(left, right) {
|
|
86
|
+
this.add(`${left} = ${right};`);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
toString() {
|
|
90
|
+
return this.build().join("\n");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
class IfWriter extends Writer {
|
|
94
|
+
condition;
|
|
95
|
+
elseWriter;
|
|
96
|
+
constructor(condition, root) {
|
|
97
|
+
super();
|
|
98
|
+
this.condition = condition;
|
|
99
|
+
this._root = root;
|
|
100
|
+
}
|
|
101
|
+
else() {
|
|
102
|
+
const writer = new Writer(this._root);
|
|
103
|
+
this.elseWriter = writer;
|
|
104
|
+
return writer;
|
|
105
|
+
}
|
|
106
|
+
build() {
|
|
107
|
+
return [
|
|
108
|
+
`if (${this.condition}) {`,
|
|
109
|
+
...Writer.indent(super.build()),
|
|
110
|
+
"}",
|
|
111
|
+
this.elseWriter ? [`else {`, ...Writer.indent(this.elseWriter.build()), "}"] : []
|
|
112
|
+
].flat();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class SwitchWriter extends Writer {
|
|
116
|
+
input;
|
|
117
|
+
#map = new Map();
|
|
118
|
+
constructor(input) {
|
|
119
|
+
super();
|
|
120
|
+
this.input = input;
|
|
121
|
+
}
|
|
122
|
+
case(condition) {
|
|
123
|
+
const writer = new Writer();
|
|
124
|
+
this.#map.set(condition, writer);
|
|
125
|
+
return writer;
|
|
126
|
+
}
|
|
127
|
+
build() {
|
|
128
|
+
return [
|
|
129
|
+
`switch (${this.input}) {`,
|
|
130
|
+
...Writer.indent(Array.from(this.#map.entries()).flatMap(([condition, writer]) => {
|
|
131
|
+
return [condition === "default" ? `${condition}:` : `case ${condition}:`, ...Writer.indent(writer.build())];
|
|
132
|
+
})),
|
|
133
|
+
"}"
|
|
134
|
+
].flat();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=Writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Writer.js","sourceRoot":"","sources":["../../../src/domain/Writer.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,MAAM;IACjB,MAAM,CAAC,MAAM,GAAG;QACd,MAAM,CAAC,GAAG,IAAc;YACtB,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAClD,CAAC;KACF,CAAC;IAEQ,KAAK,CAAU;IACf,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,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE;gBAC9D,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,QAAQ,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAC9G,CAAC,CAAC,CACH;YACD,GAAG;SACJ,CAAC,IAAI,EAAE,CAAC;IACX,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alterOnDeserialize.js","sourceRoot":"","sources":["../../../src/hooks/alterOnDeserialize.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,MAAkB,EAAE,KAAU,EAAE,OAAwB;IACzF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alterOnSerialize.js","sourceRoot":"","sources":["../../../src/hooks/alterOnSerialize.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,MAAkB,EAAE,KAAU,EAAE,OAAwB;IACvF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9D,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Automatically generated by barrelsby.
|
|
3
3
|
*/
|
|
4
|
-
export * from "./components/ArrayMapper.js";
|
|
5
4
|
export * from "./components/DateMapper.js";
|
|
6
|
-
export * from "./components/MapMapper.js";
|
|
7
5
|
export * from "./components/PrimitiveMapper.js";
|
|
8
|
-
export * from "./components/SetMapper.js";
|
|
9
6
|
export * from "./components/SymbolMapper.js";
|
|
10
7
|
export * from "./decorators/afterDeserialize.js";
|
|
11
8
|
export * from "./decorators/beforeDeserialize.js";
|
|
12
9
|
export * from "./decorators/jsonMapper.js";
|
|
13
10
|
export * from "./decorators/onDeserialize.js";
|
|
14
11
|
export * from "./decorators/onSerialize.js";
|
|
15
|
-
export * from "./domain/
|
|
12
|
+
export * from "./domain/JsonDeserializer.js";
|
|
13
|
+
export * from "./domain/JsonDeserializerOptions.js";
|
|
14
|
+
export * from "./domain/JsonMapperCompiler.js";
|
|
16
15
|
export * from "./domain/JsonMapperSettings.js";
|
|
17
16
|
export * from "./domain/JsonMapperTypesContainer.js";
|
|
17
|
+
export * from "./domain/JsonSerializer.js";
|
|
18
|
+
export * from "./domain/JsonSerializerOptions.js";
|
|
19
|
+
export * from "./domain/Writer.js";
|
|
18
20
|
export * from "./hooks/alterAfterDeserialize.js";
|
|
19
21
|
export * from "./hooks/alterBeforeDeserialize.js";
|
|
22
|
+
export * from "./hooks/alterOnDeserialize.js";
|
|
23
|
+
export * from "./hooks/alterOnSerialize.js";
|
|
20
24
|
export * from "./interfaces/JsonMapperMethods.js";
|
|
21
25
|
export * from "./utils/deserialize.js";
|
|
26
|
+
export * from "./utils/getObjectProperties.js";
|
|
22
27
|
export * from "./utils/serialize.js";
|
|
23
28
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,205 +1,9 @@
|
|
|
1
|
-
import { getValue, isArray, isBoolean, isClass, isEmpty, isNil, nameOf, objectKeys } from "@tsed/core";
|
|
2
|
-
import { alterIgnore, Discriminator, getProperties, JsonEntityStore, JsonParameterStore, JsonPropertyStore, JsonSchema } from "@tsed/schema";
|
|
3
|
-
import "../components/ArrayMapper.js";
|
|
4
1
|
import "../components/DateMapper.js";
|
|
5
|
-
import "../components/MapMapper.js";
|
|
6
2
|
import "../components/PrimitiveMapper.js";
|
|
7
|
-
import "../components/SetMapper.js";
|
|
8
3
|
import "../components/SymbolMapper.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { alterBeforeDeserialize } from "../hooks/alterBeforeDeserialize.js";
|
|
14
|
-
function isDeserializable(obj, options) {
|
|
15
|
-
if ((!!options.collectionType && isNil(obj)) || obj === undefined) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return !(isEmpty(options.type) || (options.type === Object && !options.collectionType));
|
|
19
|
-
}
|
|
20
|
-
function alterValue(schema, value, options) {
|
|
21
|
-
return schema.$hooks.alter("onDeserialize", value, [options]);
|
|
22
|
-
}
|
|
23
|
-
function transformCollection(src, options) {
|
|
24
|
-
const { types, type = Object, collectionType } = options;
|
|
25
|
-
const context = new JsonMapperContext({
|
|
26
|
-
type,
|
|
27
|
-
collectionType,
|
|
28
|
-
options,
|
|
29
|
-
next: (data, { collectionType, ...options }) => deserialize(data, options)
|
|
30
|
-
});
|
|
31
|
-
return types?.get(options.collectionType)?.deserialize(src, context);
|
|
32
|
-
}
|
|
33
|
-
function transformType(src, options) {
|
|
34
|
-
const { types, type = Object } = options;
|
|
35
|
-
const context = new JsonMapperContext({
|
|
36
|
-
type,
|
|
37
|
-
options,
|
|
38
|
-
next: (data, { type, ...options }) => deserialize(data, options)
|
|
39
|
-
});
|
|
40
|
-
return types?.get(type)?.deserialize(src, context);
|
|
41
|
-
}
|
|
42
|
-
function getAdditionalProperties(nbProps, store, options) {
|
|
43
|
-
const additionalProperties = store.schema.get("additionalProperties");
|
|
44
|
-
if (isBoolean(additionalProperties) || isClass(additionalProperties)) {
|
|
45
|
-
return additionalProperties;
|
|
46
|
-
}
|
|
47
|
-
return nbProps === 0 || !!options.additionalProperties;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Transform given plain object to class.
|
|
51
|
-
* @param src
|
|
52
|
-
* @param options
|
|
53
|
-
*/
|
|
54
|
-
export function plainObjectToClass(src, options) {
|
|
55
|
-
if (isEmpty(src)) {
|
|
56
|
-
return src;
|
|
57
|
-
}
|
|
58
|
-
const { type, store = JsonEntityStore.from(type) } = options;
|
|
59
|
-
const propertiesMap = getProperties(store, { ...options, withIgnoredProps: true });
|
|
60
|
-
let keys = new Set(objectKeys(src));
|
|
61
|
-
const additionalProperties = getAdditionalProperties(propertiesMap.size, store, options);
|
|
62
|
-
src = alterBeforeDeserialize(src, store.schema, options);
|
|
63
|
-
const out = new type(options.disableUnsecureConstructor ? {} : src);
|
|
64
|
-
propertiesMap.forEach((propStore) => {
|
|
65
|
-
const key = options.useAlias
|
|
66
|
-
? propStore.parent.schema.getAliasOf(propStore.propertyName) || propStore.propertyName
|
|
67
|
-
: propStore.propertyName;
|
|
68
|
-
keys.delete(key);
|
|
69
|
-
if (alterIgnore(propStore.schema, options)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
let value = alterValue(propStore.schema, src[key], { ...options, self: src });
|
|
73
|
-
value =
|
|
74
|
-
value === src[key]
|
|
75
|
-
? deserialize(value, {
|
|
76
|
-
...options,
|
|
77
|
-
store: propStore,
|
|
78
|
-
format: propStore.itemSchema.get("format"),
|
|
79
|
-
self: src,
|
|
80
|
-
collectionType: propStore.collectionType
|
|
81
|
-
})
|
|
82
|
-
: value;
|
|
83
|
-
if (!propStore.isGetterOnly()) {
|
|
84
|
-
if (value !== undefined) {
|
|
85
|
-
out[propStore.propertyName] = value;
|
|
86
|
-
}
|
|
87
|
-
else if (options.partial) {
|
|
88
|
-
delete out[propStore.propertyName];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
if (additionalProperties) {
|
|
93
|
-
if (isBoolean(additionalProperties)) {
|
|
94
|
-
keys.forEach((key) => {
|
|
95
|
-
out[key] = src[key];
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const type = additionalProperties.getComputedType();
|
|
100
|
-
keys.forEach((key) => {
|
|
101
|
-
out[key] = deserialize(src[key], {
|
|
102
|
-
...options,
|
|
103
|
-
type
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return alterAfterDeserialize(out, store.schema, options);
|
|
109
|
-
}
|
|
110
|
-
function mapPropStoreOptions(store, options) {
|
|
111
|
-
const itemOpts = {
|
|
112
|
-
...options,
|
|
113
|
-
store: undefined,
|
|
114
|
-
type: store.computedType
|
|
115
|
-
};
|
|
116
|
-
if (store.itemSchema.isDiscriminator) {
|
|
117
|
-
itemOpts.type = store.itemSchema.discriminator();
|
|
118
|
-
}
|
|
119
|
-
if (store.schema.hasGenerics) {
|
|
120
|
-
itemOpts.nestedGenerics = store.schema.nestedGenerics;
|
|
121
|
-
}
|
|
122
|
-
else if (store.schema.isGeneric && options.nestedGenerics) {
|
|
123
|
-
const [genericTypes = [], ...nestedGenerics] = options.nestedGenerics;
|
|
124
|
-
const genericLabels = store.parent.schema.genericLabels || [];
|
|
125
|
-
itemOpts.type = genericTypes[genericLabels.indexOf(store.schema.genericType)] || Object;
|
|
126
|
-
if (itemOpts.type instanceof JsonSchema) {
|
|
127
|
-
itemOpts.type = itemOpts.type.getTarget();
|
|
128
|
-
}
|
|
129
|
-
itemOpts.nestedGenerics = nestedGenerics;
|
|
130
|
-
}
|
|
131
|
-
return itemOpts;
|
|
132
|
-
}
|
|
133
|
-
function mapParamStoreOptions(store, options) {
|
|
134
|
-
return {
|
|
135
|
-
...options,
|
|
136
|
-
store: undefined,
|
|
137
|
-
type: store.getBestType(),
|
|
138
|
-
collectionType: store.collectionType,
|
|
139
|
-
groups: store.parameter.groups,
|
|
140
|
-
genericTypes: store.nestedGenerics[0],
|
|
141
|
-
nestedGenerics: store.nestedGenerics
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function buildOptions(options) {
|
|
145
|
-
if (options.store instanceof JsonPropertyStore) {
|
|
146
|
-
return buildOptions(mapPropStoreOptions(options.store, options));
|
|
147
|
-
}
|
|
148
|
-
if (options.store instanceof JsonParameterStore) {
|
|
149
|
-
return buildOptions(mapParamStoreOptions(options.store, options));
|
|
150
|
-
}
|
|
151
|
-
if (options.store instanceof JsonEntityStore) {
|
|
152
|
-
options.type = options.store.computedType;
|
|
153
|
-
options.collectionType = options.store.collectionType;
|
|
154
|
-
options.store = undefined;
|
|
155
|
-
}
|
|
156
|
-
else if (isClass(options.type)) {
|
|
157
|
-
const store = JsonEntityStore.from(options.type);
|
|
158
|
-
if (store.schema.isDiscriminator) {
|
|
159
|
-
options.type = JsonEntityStore.from(options.type).schema.discriminator();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
groups: false,
|
|
164
|
-
useAlias: true,
|
|
165
|
-
...options,
|
|
166
|
-
additionalProperties: getValue(options, "additionalProperties", JsonMapperSettings.additionalProperties),
|
|
167
|
-
disableUnsecureConstructor: getValue(options, "disableUnsecureConstructor", JsonMapperSettings.disableUnsecureConstructor),
|
|
168
|
-
partial: options.groups ? options.groups.includes("partial") : false,
|
|
169
|
-
type: options.type ? options.type : undefined,
|
|
170
|
-
types: options.types ? options.types : getJsonMapperTypes()
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Transform given source to class base on the given `options.type`.
|
|
175
|
-
*
|
|
176
|
-
* @param src
|
|
177
|
-
* @param options
|
|
178
|
-
*/
|
|
179
|
-
export function deserialize(src, options = {}) {
|
|
180
|
-
options = buildOptions(options);
|
|
181
|
-
if (!isDeserializable(src, options)) {
|
|
182
|
-
return src;
|
|
183
|
-
}
|
|
184
|
-
if (!options.collectionType && isArray(src)) {
|
|
185
|
-
options.collectionType = Array;
|
|
186
|
-
}
|
|
187
|
-
if (options.collectionType) {
|
|
188
|
-
if (!options.types?.has(options.collectionType)) {
|
|
189
|
-
throw new Error(`${nameOf(options.collectionType)} is not supported by JsonMapper.`);
|
|
190
|
-
}
|
|
191
|
-
return transformCollection(src, options);
|
|
192
|
-
}
|
|
193
|
-
if (options.types?.has(options.type)) {
|
|
194
|
-
return transformType(src, options);
|
|
195
|
-
}
|
|
196
|
-
if (options.type instanceof Discriminator) {
|
|
197
|
-
const discriminator = options.type;
|
|
198
|
-
const discriminatorValue = src[discriminator.propertyName];
|
|
199
|
-
const type = discriminator.getType(discriminatorValue);
|
|
200
|
-
return plainObjectToClass(src, { ...options, type });
|
|
201
|
-
}
|
|
202
|
-
// class converter
|
|
203
|
-
return plainObjectToClass(src, options);
|
|
4
|
+
import { JsonDeserializer } from "../domain/JsonDeserializer.js";
|
|
5
|
+
const deserializer = new JsonDeserializer();
|
|
6
|
+
export function deserialize(input, options) {
|
|
7
|
+
return deserializer.map(input, options);
|
|
204
8
|
}
|
|
205
9
|
//# sourceMappingURL=deserialize.js.map
|