@tsed/json-mapper 8.0.0-alpha.4 → 8.0.0-alpha.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.
Files changed (87) hide show
  1. package/lib/browser/json-mapper.umd.min.js.map +1 -1
  2. package/lib/esm/utils/deserialize.js.map +1 -1
  3. package/lib/esm/utils/serialize.js.map +1 -1
  4. package/lib/types/utils/deserialize.d.ts +3 -3
  5. package/lib/types/utils/serialize.d.ts +3 -3
  6. package/package.json +11 -11
  7. package/lib/cjs/components/DateMapper.js +0 -30
  8. package/lib/cjs/components/DateMapper.js.map +0 -1
  9. package/lib/cjs/components/PrimitiveMapper.js +0 -64
  10. package/lib/cjs/components/PrimitiveMapper.js.map +0 -1
  11. package/lib/cjs/components/SymbolMapper.js +0 -24
  12. package/lib/cjs/components/SymbolMapper.js.map +0 -1
  13. package/lib/cjs/decorators/afterDeserialize.js +0 -39
  14. package/lib/cjs/decorators/afterDeserialize.js.map +0 -1
  15. package/lib/cjs/decorators/beforeDeserialize.js +0 -39
  16. package/lib/cjs/decorators/beforeDeserialize.js.map +0 -1
  17. package/lib/cjs/decorators/jsonMapper.js +0 -18
  18. package/lib/cjs/decorators/jsonMapper.js.map +0 -1
  19. package/lib/cjs/decorators/onDeserialize.js +0 -29
  20. package/lib/cjs/decorators/onDeserialize.js.map +0 -1
  21. package/lib/cjs/decorators/onSerialize.js +0 -29
  22. package/lib/cjs/decorators/onSerialize.js.map +0 -1
  23. package/lib/cjs/domain/JsonDeserializer.js +0 -295
  24. package/lib/cjs/domain/JsonDeserializer.js.map +0 -1
  25. package/lib/cjs/domain/JsonDeserializerOptions.js +0 -3
  26. package/lib/cjs/domain/JsonDeserializerOptions.js.map +0 -1
  27. package/lib/cjs/domain/JsonMapperCompiler.js +0 -167
  28. package/lib/cjs/domain/JsonMapperCompiler.js.map +0 -1
  29. package/lib/cjs/domain/JsonMapperGlobalOptions.js +0 -3
  30. package/lib/cjs/domain/JsonMapperGlobalOptions.js.map +0 -1
  31. package/lib/cjs/domain/JsonMapperSettings.js +0 -9
  32. package/lib/cjs/domain/JsonMapperSettings.js.map +0 -1
  33. package/lib/cjs/domain/JsonMapperTypesContainer.js +0 -23
  34. package/lib/cjs/domain/JsonMapperTypesContainer.js.map +0 -1
  35. package/lib/cjs/domain/JsonSerializer.js +0 -273
  36. package/lib/cjs/domain/JsonSerializer.js.map +0 -1
  37. package/lib/cjs/domain/JsonSerializerOptions.js +0 -3
  38. package/lib/cjs/domain/JsonSerializerOptions.js.map +0 -1
  39. package/lib/cjs/domain/Writer.js +0 -137
  40. package/lib/cjs/domain/Writer.js.map +0 -1
  41. package/lib/cjs/hooks/alterAfterDeserialize.js +0 -8
  42. package/lib/cjs/hooks/alterAfterDeserialize.js.map +0 -1
  43. package/lib/cjs/hooks/alterBeforeDeserialize.js +0 -8
  44. package/lib/cjs/hooks/alterBeforeDeserialize.js.map +0 -1
  45. package/lib/cjs/hooks/alterOnDeserialize.js +0 -8
  46. package/lib/cjs/hooks/alterOnDeserialize.js.map +0 -1
  47. package/lib/cjs/hooks/alterOnSerialize.js +0 -8
  48. package/lib/cjs/hooks/alterOnSerialize.js.map +0 -1
  49. package/lib/cjs/index.js +0 -32
  50. package/lib/cjs/index.js.map +0 -1
  51. package/lib/cjs/interfaces/JsonMapperMethods.js +0 -3
  52. package/lib/cjs/interfaces/JsonMapperMethods.js.map +0 -1
  53. package/lib/cjs/package.json +0 -3
  54. package/lib/cjs/utils/deserialize.js +0 -13
  55. package/lib/cjs/utils/deserialize.js.map +0 -1
  56. package/lib/cjs/utils/getObjectProperties.js +0 -9
  57. package/lib/cjs/utils/getObjectProperties.js.map +0 -1
  58. package/lib/cjs/utils/serialize.js +0 -13
  59. package/lib/cjs/utils/serialize.js.map +0 -1
  60. package/lib/esm/package.json +0 -3
  61. package/lib/types-esm/components/DateMapper.d.ts +0 -11
  62. package/lib/types-esm/components/PrimitiveMapper.d.ts +0 -18
  63. package/lib/types-esm/components/SymbolMapper.d.ts +0 -11
  64. package/lib/types-esm/decorators/afterDeserialize.d.ts +0 -33
  65. package/lib/types-esm/decorators/beforeDeserialize.d.ts +0 -33
  66. package/lib/types-esm/decorators/jsonMapper.d.ts +0 -7
  67. package/lib/types-esm/decorators/onDeserialize.d.ts +0 -23
  68. package/lib/types-esm/decorators/onSerialize.d.ts +0 -23
  69. package/lib/types-esm/domain/JsonDeserializer.d.ts +0 -33
  70. package/lib/types-esm/domain/JsonDeserializerOptions.d.ts +0 -28
  71. package/lib/types-esm/domain/JsonMapperCompiler.d.ts +0 -60
  72. package/lib/types-esm/domain/JsonMapperGlobalOptions.d.ts +0 -14
  73. package/lib/types-esm/domain/JsonMapperSettings.d.ts +0 -2
  74. package/lib/types-esm/domain/JsonMapperTypesContainer.d.ts +0 -10
  75. package/lib/types-esm/domain/JsonSerializer.d.ts +0 -22
  76. package/lib/types-esm/domain/JsonSerializerOptions.d.ts +0 -14
  77. package/lib/types-esm/domain/Writer.d.ts +0 -43
  78. package/lib/types-esm/hooks/alterAfterDeserialize.d.ts +0 -4
  79. package/lib/types-esm/hooks/alterBeforeDeserialize.d.ts +0 -4
  80. package/lib/types-esm/hooks/alterOnDeserialize.d.ts +0 -2
  81. package/lib/types-esm/hooks/alterOnSerialize.d.ts +0 -2
  82. package/lib/types-esm/index.d.ts +0 -28
  83. package/lib/types-esm/interfaces/JsonMapperMethods.d.ts +0 -28
  84. package/lib/types-esm/utils/deserialize.d.ts +0 -5
  85. package/lib/types-esm/utils/getObjectProperties.d.ts +0 -1
  86. package/lib/types-esm/utils/serialize.d.ts +0 -5
  87. /package/{webpack.config.js → webpack.config.cjs} +0 -0
@@ -1,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonMapperCompiler = void 0;
4
- const core_1 = require("@tsed/core");
5
- class JsonMapperCompiler {
6
- constructor() {
7
- /**
8
- * Cached mappers metadata
9
- * @protected
10
- */
11
- this.cache = new Map();
12
- /**
13
- * Cached executable mappers by his id
14
- * @protected
15
- */
16
- this.mappers = {};
17
- /**
18
- * Cached schemas
19
- * @protected
20
- */
21
- this.schemes = {};
22
- /**
23
- * Cached classes by his id
24
- * @protected
25
- */
26
- this.constructors = {};
27
- /**
28
- * Global variables available in the mapper
29
- * @protected
30
- */
31
- this.globals = {
32
- isCollection: core_1.isCollection,
33
- isClass: core_1.isClass,
34
- isObject: core_1.isObject,
35
- classOf: core_1.classOf,
36
- nameOf: core_1.nameOf,
37
- hasJsonMethod: core_1.hasJsonMethod,
38
- isMongooseObject: core_1.isMongooseObject,
39
- isNil: core_1.isNil,
40
- isDate: core_1.isDate,
41
- objectKeys: core_1.objectKeys,
42
- isMomentObject: core_1.isMomentObject
43
- };
44
- this.addGlobal("alterIgnore", this.alterIgnore.bind(this));
45
- this.addGlobal("alterValue", this.alterValue.bind(this));
46
- this.addGlobal("execMapper", this.execMapper.bind(this));
47
- this.addGlobal("compileAndMap", this.map.bind(this));
48
- }
49
- addTypeMapper(model, fn) {
50
- const id = (0, core_1.nameOf)(model);
51
- this.cache.set(model, new Map().set("typeMapper", {
52
- id,
53
- fn
54
- }));
55
- this.mappers[id] = fn;
56
- return this;
57
- }
58
- removeTypeMapper(model) {
59
- const store = this.cache.get(model);
60
- if (store) {
61
- const { id } = store.get("typeMapper");
62
- delete this.mappers[id];
63
- this.cache.delete(model);
64
- }
65
- }
66
- addGlobal(key, value) {
67
- this.globals[key] = value;
68
- return this;
69
- }
70
- eval(mapper, { id, groupsId, model }) {
71
- this.addGlobal("cache", this.cache);
72
- const { globals, schemes } = this;
73
- const injectGlobals = Object.keys(globals)
74
- .map((name) => {
75
- return `const ${name} = globals.${name};`;
76
- })
77
- .join("\n");
78
- eval(`${injectGlobals};
79
-
80
- cache.get(model).set(groupsId, { id: '${id}', fn: ${mapper} })`);
81
- const store = this.cache.get(model).get(groupsId);
82
- this.mappers[id] = store.fn;
83
- return store;
84
- }
85
- createContext(options) {
86
- const { cache } = this;
87
- return {
88
- ...options,
89
- cache
90
- };
91
- }
92
- compile(model, groups, opts = {}) {
93
- const token = (0, core_1.isString)(model) ? model : this.getType(model);
94
- const groupsId = this.getGroupsId(groups);
95
- let storeGroups = this.cache.get(token) || this.cache.get((0, core_1.nameOf)(token));
96
- if (!storeGroups) {
97
- storeGroups = new Map();
98
- this.cache.set(token, storeGroups);
99
- }
100
- if (storeGroups.has("typeMapper")) {
101
- return storeGroups.get("typeMapper");
102
- }
103
- // generate mapper for the given groups
104
- if (!storeGroups.has(groupsId)) {
105
- const id = this.getId(token, groupsId);
106
- // prevent circular dependencies
107
- storeGroups.set(groupsId, {
108
- id
109
- });
110
- const mapper = opts.mapper ? opts.mapper(id, groups) : this.createMapper(token, id, groups);
111
- try {
112
- return this.eval(mapper, { id, model: token, groupsId });
113
- }
114
- catch (err) {
115
- throw new Error(`Fail to compile mapper for ${(0, core_1.nameOf)(model)}. See the error above: ${err.message}.\n${mapper}`);
116
- }
117
- }
118
- return storeGroups.get(groupsId);
119
- }
120
- execMapper(id, value, options) {
121
- if ((0, core_1.isObjectID)(value)) {
122
- return value.toString();
123
- }
124
- return this.mappers[id || (0, core_1.nameOf)((0, core_1.classOf)(value))](value, options);
125
- }
126
- getType(model) {
127
- if (!model) {
128
- return Object;
129
- }
130
- if ((0, core_1.isClass)(model) && !(0, core_1.isCollection)(model)) {
131
- const type = [Array, Map, Set].find((t) => (0, core_1.ancestorsOf)(model).includes(t));
132
- if (type) {
133
- return type;
134
- }
135
- }
136
- return model;
137
- }
138
- alterIgnore(id, options) {
139
- let result = this.schemes[id]?.$hooks?.alter("ignore", false, [options]);
140
- if (result) {
141
- return result;
142
- }
143
- }
144
- alterGroups(schema, groups) {
145
- if (groups !== false) {
146
- return schema.$hooks.alter("groups", false, [groups]);
147
- }
148
- return false;
149
- }
150
- getGroupsId(groups) {
151
- if (groups === false) {
152
- return "default";
153
- }
154
- if (groups.length === 0) {
155
- return "-";
156
- }
157
- return groups.join(",");
158
- }
159
- getId(model, groupsId) {
160
- return `${(0, core_1.isString)(model) ? model : (0, core_1.nameOf)(model)}:${(0, core_1.getRandomId)()}:${groupsId}`;
161
- }
162
- getSchemaId(id, propertyKey) {
163
- return `${id}:${propertyKey}`;
164
- }
165
- }
166
- exports.JsonMapperCompiler = JsonMapperCompiler;
167
- //# sourceMappingURL=JsonMapperCompiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonMapperCompiler.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperCompiler.ts"],"names":[],"mappings":";;;AAAA,qCAiBoB;AAWpB,MAAsB,kBAAkB;IAwCtC;QAvCA;;;WAGG;QACO,UAAK,GAAG,IAAI,GAAG,EAAuD,CAAC;QACjF;;;WAGG;QACO,YAAO,GAAgD,EAAE,CAAC;QACpE;;;WAGG;QACO,YAAO,GAAwB,EAAE,CAAC;QAE5C;;;WAGG;QACO,iBAAY,GAA8B,EAAE,CAAC;QACvD;;;WAGG;QACO,YAAO,GAAwB;YACvC,YAAY,EAAZ,mBAAY;YACZ,OAAO,EAAP,cAAO;YACP,QAAQ,EAAR,eAAQ;YACR,OAAO,EAAP,cAAO;YACP,MAAM,EAAN,aAAM;YACN,aAAa,EAAb,oBAAa;YACb,gBAAgB,EAAhB,uBAAgB;YAChB,KAAK,EAAL,YAAK;YACL,MAAM,EAAN,aAAM;YACN,UAAU,EAAV,iBAAU;YACV,cAAc,EAAd,qBAAc;SACf,CAAC;QAGA,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,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;QACnD,OAAO,GAAG,EAAE,IAAI,WAAW,EAAE,CAAC;IAChC,CAAC;CACF;AA1ND,gDA0NC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=JsonMapperGlobalOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonMapperGlobalOptions.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperGlobalOptions.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonMapperSettings = void 0;
4
- exports.JsonMapperSettings = {
5
- disableUnsecureConstructor: true,
6
- additionalProperties: false,
7
- strictGroups: false
8
- };
9
- //# sourceMappingURL=JsonMapperSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonMapperSettings.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperSettings.ts"],"names":[],"mappings":";;;AAEa,QAAA,kBAAkB,GAA4B;IACzD,0BAA0B,EAAE,IAAI;IAChC,oBAAoB,EAAE,KAAK;IAC3B,YAAY,EAAE,KAAK;CACpB,CAAC"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJsonMapperTypes = exports.registerJsonTypeMapper = void 0;
4
- /**
5
- * @ignore
6
- */
7
- // tslint:disable-next-line:variable-name
8
- const JsonMapperTypesContainer = new Map();
9
- /**
10
- * @ignore
11
- */
12
- function registerJsonTypeMapper(type, token) {
13
- JsonMapperTypesContainer.set(type, new token());
14
- }
15
- exports.registerJsonTypeMapper = registerJsonTypeMapper;
16
- /**
17
- * @ignore
18
- */
19
- function getJsonMapperTypes() {
20
- return JsonMapperTypesContainer;
21
- }
22
- exports.getJsonMapperTypes = getJsonMapperTypes;
23
- //# sourceMappingURL=JsonMapperTypesContainer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonMapperTypesContainer.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperTypesContainer.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,yCAAyC;AACzC,MAAM,wBAAwB,GAAwD,IAAI,GAAG,EAAE,CAAC;AAChG;;GAEG;AACH,SAAgB,sBAAsB,CAAC,IAAiC,EAAE,KAA8B;IACtG,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC;AAFD,wDAEC;AACD;;GAEG;AACH,SAAgB,kBAAkB;IAChC,OAAO,wBAAwB,CAAC;AAClC,CAAC;AAFD,gDAEC"}
@@ -1,273 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonSerializer = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- const alterOnSerialize_js_1 = require("../hooks/alterOnSerialize.js");
7
- const getObjectProperties_js_1 = require("../utils/getObjectProperties.js");
8
- const JsonMapperCompiler_js_1 = require("./JsonMapperCompiler.js");
9
- const JsonMapperSettings_js_1 = require("./JsonMapperSettings.js");
10
- const JsonMapperTypesContainer_js_1 = require("./JsonMapperTypesContainer.js");
11
- const Writer_js_1 = require("./Writer.js");
12
- const getCollectionType = (input) => {
13
- return (0, core_1.isArray)(input) ? "Array" : input instanceof Set ? "Set" : input instanceof Map ? "Map" : undefined;
14
- };
15
- function getBestType(type, obj) {
16
- const dataType = (0, core_1.classOf)(obj);
17
- if (dataType && !(0, core_1.isClassObject)(dataType) && !(0, core_1.isCollection)(obj)) {
18
- return dataType;
19
- }
20
- return type || Object;
21
- }
22
- function varKey(k) {
23
- return `__${k}`;
24
- }
25
- class JsonSerializer extends JsonMapperCompiler_js_1.JsonMapperCompiler {
26
- constructor() {
27
- super();
28
- this.addTypeMapper(Object, this.mapObject.bind(this));
29
- this.addTypeMapper(Array, this.mapArray.bind(this));
30
- this.addTypeMapper(Map, this.mapMap.bind(this));
31
- this.addTypeMapper(Set, this.mapSet.bind(this));
32
- this.addGlobal("mapJSON", this.mapJSON.bind(this));
33
- this.addTypeMapper("ObjectId", (value) => String(value));
34
- }
35
- map(input, options = {}) {
36
- if ((0, core_1.isNil)(input)) {
37
- return input;
38
- }
39
- options = this.mapOptions(options);
40
- const model = getBestType(options.type, input);
41
- const mapper = this.compile(model, options.groups);
42
- return mapper.fn(input, this.createContext(options));
43
- }
44
- alterValue(schemaId, value, options) {
45
- return (0, alterOnSerialize_js_1.alterOnSerialize)(this.schemes[schemaId], value, options);
46
- }
47
- createMapper(model, id, groups) {
48
- const entity = schema_1.JsonEntityStore.from(model);
49
- const properties = new Set();
50
- const schemaProperties = [...(0, schema_1.getPropertiesStores)(entity).values()];
51
- const writer = new Writer_js_1.Writer().arrow("input", "options");
52
- writer.if("isNil(input)").return("input");
53
- // prepare options
54
- writer.const("obj", "{}");
55
- writer.set("options", "{...options, self: input}");
56
- // detect some special case
57
- writer.add(this.mapPrecondition(id));
58
- if (!schemaProperties.length) {
59
- return writer.return("isObject(input) ? {...input} : input").root().toString();
60
- }
61
- // properties
62
- writer.add(...schemaProperties.flatMap((propertyStore) => {
63
- properties.add(propertyStore.propertyKey);
64
- if ((propertyStore.schema?.$ignore && (0, core_1.isBoolean)(propertyStore.schema?.$ignore)) ||
65
- (propertyStore.schema?.$hooks?.has("groups") && this.alterGroups(propertyStore.schema, groups))) {
66
- return;
67
- }
68
- return this.mapProperty(propertyStore, id, groups);
69
- }));
70
- // discriminator
71
- writer.add(this.mapDiscriminatorKeyValue(entity));
72
- // additional properties
73
- writer.add(this.mapAdditionalProperties(entity, properties));
74
- return writer.return("obj").root().toString();
75
- }
76
- mapOptions({ groups, useAlias = true, types, ...options }) {
77
- const customMappers = {};
78
- types = types || (0, JsonMapperTypesContainer_js_1.getJsonMapperTypes)();
79
- types.forEach((mapper, model) => {
80
- if (![Array, Set, Map].includes(model)) {
81
- this.addTypeMapper(model, (value, options) => mapper.serialize(value, {
82
- ...options,
83
- type: model
84
- }));
85
- }
86
- });
87
- const strictGroups = options.strictGroups ?? JsonMapperSettings_js_1.JsonMapperSettings.strictGroups;
88
- return {
89
- ...options,
90
- groups: groups === undefined ? (strictGroups ? [] : false) : groups || false,
91
- useAlias,
92
- customMappers
93
- };
94
- }
95
- mapProperty(propertyStore, id, groups) {
96
- const key = String(propertyStore.propertyKey);
97
- const aliasKey = String(propertyStore.parent.schema.getAliasOf(key) || key);
98
- const schemaId = this.getSchemaId(id, key);
99
- const format = propertyStore.itemSchema.get("format");
100
- const formatOpts = format && `options: {format: '${format}'}`;
101
- let writer = new Writer_js_1.Writer().add(`// Map ${key} ${id} ${groups || ""}`);
102
- // ignore hook (deprecated)
103
- if (propertyStore.schema?.$hooks?.has("ignore")) {
104
- this.schemes[schemaId] = propertyStore.schema;
105
- writer = writer.if(`!alterIgnore('${schemaId}', {...options, self: input})`);
106
- }
107
- // pre hook
108
- const hasSerializer = propertyStore.schema?.$hooks?.has("onSerialize");
109
- let getter = `input.${key}`;
110
- if (hasSerializer) {
111
- this.schemes[schemaId] = propertyStore.schema;
112
- const opts = Writer_js_1.Writer.options(formatOpts);
113
- getter = `alterValue('${schemaId}', input.${key}, ${opts})`;
114
- }
115
- writer = writer.set(`let ${varKey(key)}`, getter).if(`${varKey(key)} !== undefined`);
116
- const fill = this.getPropertyFiller(propertyStore, key, groups, formatOpts);
117
- if (hasSerializer) {
118
- fill(writer.if(`${varKey(key)} === input.${key}`));
119
- }
120
- else {
121
- fill(writer);
122
- }
123
- if (aliasKey !== key) {
124
- writer.set(`obj[options.useAlias ? '${aliasKey}' : '${key}']`, varKey(key));
125
- }
126
- else {
127
- writer.set(`obj.${key}`, varKey(key));
128
- }
129
- return writer.root();
130
- }
131
- getPropertyFiller(propertyStore, key, groups, formatOpts) {
132
- const isGeneric = propertyStore.itemSchema.isGeneric;
133
- const hasDiscriminator = propertyStore.itemSchema.hasDiscriminator;
134
- if (propertyStore.isCollection) {
135
- const type = propertyStore.getBestType();
136
- let nestedMapper;
137
- if (hasDiscriminator) {
138
- const targetName = propertyStore.parent.targetName;
139
- nestedMapper = this.compile(`Discriminator:${targetName}:${key}`, groups, {
140
- mapper: () => this.createDiscriminatorMapper(propertyStore, groups)
141
- });
142
- }
143
- else {
144
- nestedMapper = isGeneric ? { id: "" } : this.compile(type, groups);
145
- }
146
- return (writer) => writer.callMapper((0, core_1.nameOf)(propertyStore.collectionType), varKey(key), `id: '${nestedMapper.id}'`, formatOpts);
147
- }
148
- if (isGeneric) {
149
- return (writer) => writer.set(varKey(key), `compileAndMap(${varKey(key)}, options)`);
150
- }
151
- let nestedMapper;
152
- if (hasDiscriminator) {
153
- const targetName = propertyStore.parent.targetName;
154
- nestedMapper = this.compile(`Discriminator:${targetName}:${key}`, groups, {
155
- mapper: () => this.createDiscriminatorMapper(propertyStore, groups)
156
- });
157
- }
158
- else {
159
- nestedMapper = this.compile(propertyStore.getBestType(), groups);
160
- }
161
- return (writer) => writer.callMapper(nestedMapper.id, varKey(key), formatOpts);
162
- }
163
- createDiscriminatorMapper(propertyStore, groups) {
164
- const discriminator = propertyStore.itemSchema.discriminator();
165
- const writer = new Writer_js_1.Writer().arrow("input", "options");
166
- const sw = writer.switch(`nameOf(classOf(input))`);
167
- discriminator.values.forEach((value, kind) => {
168
- const nestedMapper = this.compile(value, groups);
169
- sw.case(`'${(0, core_1.nameOf)(value)}'`).returnCallMapper(nestedMapper.id, "input");
170
- });
171
- return writer.root().toString();
172
- }
173
- mapPrecondition(id) {
174
- const writer = new Writer_js_1.Writer();
175
- writer.if("input && isCollection(input)").return(Writer_js_1.Writer.mapperFrom("input", `{...options, id: '${id}'}`));
176
- writer.if("hasJsonMethod(input)").return(`mapJSON(input, {...options, id: '${id}'})`);
177
- return writer;
178
- }
179
- mapDiscriminatorKeyValue(entity) {
180
- if (entity.discriminatorAncestor) {
181
- const discriminator = entity.discriminatorAncestor.schema.discriminator();
182
- const type = discriminator.getDefaultValue(entity.target);
183
- if (type) {
184
- const writer = new Writer_js_1.Writer();
185
- writer.if(`!obj.${discriminator.propertyName}`).set(`obj.${discriminator.propertyName}`, `'${type}'`);
186
- return writer;
187
- }
188
- }
189
- }
190
- mapAdditionalProperties(entity, properties) {
191
- const additionalProperties = !!entity.schema.get("additionalProperties");
192
- if (additionalProperties) {
193
- const exclude = [...properties.values()].map((key) => `'${key}'`).join(", ");
194
- const writer = new Writer_js_1.Writer();
195
- writer.add("// add additional properties");
196
- writer.each("objectKeys(input)", ["key"]).if(`![${exclude}].includes(key)`).set("obj[key]", "input[key]");
197
- return writer;
198
- }
199
- }
200
- mapObject(input, { type, ...options }) {
201
- if ((input && (0, core_1.isPrimitive)(input)) || !input) {
202
- // prevent mongoose mapping error
203
- return input;
204
- }
205
- if (input && (0, core_1.isCollection)(input)) {
206
- return this.execMapper(getCollectionType(input), input, options);
207
- }
208
- if ((0, core_1.hasJsonMethod)(input)) {
209
- return this.mapJSON(input, options);
210
- }
211
- return (0, getObjectProperties_js_1.getObjectProperties)(input)
212
- .filter(([, value]) => value !== undefined)
213
- .reduce((obj, [key, value]) => {
214
- if ((0, core_1.isNil)(value)) {
215
- return {
216
- ...obj,
217
- [key]: value
218
- };
219
- }
220
- const mapper = this.compile((0, core_1.classOf)(value), options.groups);
221
- return {
222
- ...obj,
223
- [key]: mapper.fn(value, options)
224
- };
225
- }, {});
226
- }
227
- mapSet(input, options) {
228
- if ((0, core_1.isNil)(input)) {
229
- return input;
230
- }
231
- return [...input.values()].map((item) => {
232
- return this.mapItem(item, options);
233
- });
234
- }
235
- mapArray(input, options) {
236
- if ((0, core_1.isNil)(input)) {
237
- return input;
238
- }
239
- return [].concat(input).map((item) => {
240
- return this.mapItem(item, options);
241
- });
242
- }
243
- mapMap(input, options) {
244
- if ((0, core_1.isNil)(input)) {
245
- return input;
246
- }
247
- return [...input.entries()].reduce((obj, [key, item]) => {
248
- return {
249
- ...obj,
250
- [key]: this.mapItem(item, options)
251
- };
252
- }, {});
253
- }
254
- mapItem(input, { id, ...options }) {
255
- if (!id && input) {
256
- return this.compile((0, core_1.classOf)(input), options.groups).fn(input, options);
257
- }
258
- return id ? this.execMapper(id, input, options) : input;
259
- }
260
- mapJSON(input, { id, ...options }) {
261
- if ((0, core_1.isMongooseObject)(input)) {
262
- return input.toJSON({ ...options, id });
263
- }
264
- id = id || (0, core_1.nameOf)((0, core_1.classOf)(input));
265
- if (this.mappers[id] && ((0, core_1.isDate)(input) || (0, core_1.isMomentObject)(input))) {
266
- return this.execMapper(id, input, options);
267
- }
268
- input = input.toJSON();
269
- return (0, core_1.isObject)(input) ? this.execMapper(id, input, options) : input;
270
- }
271
- }
272
- exports.JsonSerializer = JsonSerializer;
273
- //# sourceMappingURL=JsonSerializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonSerializer.js","sourceRoot":"","sources":["../../../src/domain/JsonSerializer.ts"],"names":[],"mappings":";;;AAAA,qCAeoB;AACpB,yCAAqG;AACrG,sEAA8D;AAC9D,4EAAoE;AACpE,mEAA2D;AAC3D,mEAA2D;AAC3D,+EAAiE;AAEjE,2CAAmC;AAEnC,MAAM,iBAAiB,GAAG,CAAC,KAAU,EAAE,EAAE;IACvC,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5G,CAAC,CAAC;AAEF,SAAS,WAAW,CAAC,IAAe,EAAE,GAAQ;IAC5C,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,QAAQ,IAAI,CAAC,IAAA,oBAAa,EAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,mBAAY,EAAC,GAAG,CAAC,EAAE;QAC9D,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,IAAI,IAAI,MAAM,CAAC;AACxB,CAA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AO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,CAAC;IAEO,OAAO,CAAC,KAAU,EAAE,EAAC,EAAE,EAAE,GAAG,OAAO,EAAwB;QACjE,IAAI,IAAA,uBAAgB,EAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,KAAK,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,EAAE,EAAC,CAAC,CAAC;SACvC;QAED,EAAE,GAAG,EAAE,IAAI,IAAA,aAAM,EAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC;QAElC,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAA,aAAM,EAAC,KAAK,CAAC,IAAI,IAAA,qBAAc,EAAC,KAAK,CAAC,CAAC,EAAE;YAChE,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;SAC5C;QAED,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAEvB,OAAO,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvE,CAAC;CACF;AAtUD,wCAsUC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=JsonSerializerOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonSerializerOptions.js","sourceRoot":"","sources":["../../../src/domain/JsonSerializerOptions.ts"],"names":[],"mappings":""}
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Writer = void 0;
4
- class Writer {
5
- static { this.object = {
6
- assign(...args) {
7
- return `{ ${args.filter(Boolean).join(", ")} }`;
8
- }
9
- }; }
10
- constructor(root) {
11
- this.body = [];
12
- this._root = root;
13
- }
14
- static indent(lines) {
15
- return lines.map((p) => `\t${p}`);
16
- }
17
- static mapper(mapperId, key, options) {
18
- return `execMapper('${mapperId}', ${key}, ${options})`;
19
- }
20
- static mapperFrom(key, options) {
21
- return `execMapper(nameOf(classOf(${key})), ${key}, ${options})`;
22
- }
23
- static options(...args) {
24
- args = args.filter(Boolean);
25
- return !args.length ? "options" : Writer.object.assign("...options", ...args);
26
- }
27
- add(...lines) {
28
- lines = lines.filter((line) => line !== undefined);
29
- lines.length && this.body.push(...lines);
30
- return this;
31
- }
32
- arrow(...args) {
33
- this.add(`(${args}) => {`);
34
- const writer = this.new();
35
- this.add("}");
36
- return writer;
37
- }
38
- build() {
39
- const result = this.body.flatMap((line) => {
40
- return line instanceof Writer ? line.build() : line;
41
- });
42
- return this._indent ? result.map((item) => "\t" + item) : result;
43
- }
44
- callMapper(id, key, ...options) {
45
- return this.set(key, Writer.mapper(id, key, Writer.options(...options)));
46
- }
47
- returnCallMapper(id, key, ...options) {
48
- return this.return(Writer.mapper(id, key, Writer.options(...options)));
49
- }
50
- const(name, line) {
51
- this.add(`const ${name} = ${line};`);
52
- return this;
53
- }
54
- each(iterable, args = []) {
55
- const writer = this.add(iterable + ".forEach((" + args.join(", ") + ") => {").new();
56
- this.add("});");
57
- return writer;
58
- }
59
- if(condition) {
60
- const writer = new IfWriter(condition, this);
61
- this.add(writer);
62
- return writer;
63
- }
64
- switch(input) {
65
- const sw = new SwitchWriter(input);
66
- this.add(sw);
67
- return sw;
68
- }
69
- indent(indent) {
70
- this._indent = indent;
71
- return this;
72
- }
73
- new(indent = true) {
74
- const writer = new Writer(this.root());
75
- writer.indent(indent);
76
- this.add(writer);
77
- return writer;
78
- }
79
- return(line) {
80
- this.add(`return ${line};`);
81
- return this.root();
82
- }
83
- root() {
84
- return this._root || this;
85
- }
86
- set(left, right) {
87
- this.add(`${left} = ${right};`);
88
- return this;
89
- }
90
- toString() {
91
- return this.build().join("\n");
92
- }
93
- }
94
- exports.Writer = Writer;
95
- class IfWriter extends Writer {
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
- #map;
117
- constructor(input) {
118
- super();
119
- this.input = input;
120
- this.#map = new Map();
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