@cratis/fundamentals 5.3.8 → 5.4.0

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/JsonSerializer.ts CHANGED
@@ -17,7 +17,15 @@ const typeSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, t
17
17
  [Guid, (value: any) => Guid.parse(value.toString())],
18
18
  ]);
19
19
 
20
- const deserializeValue = (field: Field, value: any) => {
20
+ const deserializeValueFromType = (type: Constructor, value: any) => {
21
+ if (typeSerializers.has(type)) {
22
+ return typeSerializers.get(type)!(value);
23
+ } else {
24
+ return JsonSerializer.deserialize(type, JSON.stringify(value));
25
+ }
26
+ };
27
+
28
+ const deserializeValueFromField = (field: Field, value: any) => {
21
29
  if (typeSerializers.has(field.type)) {
22
30
  return typeSerializers.get(field.type)!(value);
23
31
  } else {
@@ -67,14 +75,19 @@ export class JsonSerializer {
67
75
  */
68
76
  static deserializeFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instance: any): TResult {
69
77
  const fields = Fields.getFieldsForType(targetType as Constructor);
78
+
79
+ if( typeSerializers.has(targetType) ) {
80
+ return deserializeValueFromType(targetType, instance);
81
+ }
82
+
70
83
  const deserialized = new targetType();
71
84
  for (const field of fields) {
72
85
  let value = instance[field.name];
73
86
  if (value) {
74
87
  if (field.enumerable) {
75
- value = value.map(_ => deserializeValue(field, _));
88
+ value = value.map(_ => deserializeValueFromField(field, _));
76
89
  } else {
77
- value = deserializeValue(field, value);
90
+ value = deserializeValueFromField(field, value);
78
91
  }
79
92
  }
80
93
 
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSerializer.d.ts","sourceRoot":"","sources":["../../JsonSerializer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAiC5C,qBAAa,cAAc;IACvB,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAoB;IAQjE,MAAM,CAAC,WAAW,CAAC,OAAO,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AO,EAAE;CASvH"}
@@ -11,7 +11,15 @@ const typeSerializers = new Map([
11
11
  [Date, (value) => new Date(value)],
12
12
  [Guid.Guid, (value) => Guid.Guid.parse(value.toString())],
13
13
  ]);
14
- const deserializeValue = (field, value) => {
14
+ const deserializeValueFromType = (type, value) => {
15
+ if (typeSerializers.has(type)) {
16
+ return typeSerializers.get(type)(value);
17
+ }
18
+ else {
19
+ return JsonSerializer.deserialize(type, JSON.stringify(value));
20
+ }
21
+ };
22
+ const deserializeValueFromField = (field, value) => {
15
23
  if (typeSerializers.has(field.type)) {
16
24
  return typeSerializers.get(field.type)(value);
17
25
  }
@@ -35,15 +43,18 @@ class JsonSerializer {
35
43
  }
36
44
  static deserializeFromInstance(targetType, instance) {
37
45
  const fields = Fields.Fields.getFieldsForType(targetType);
46
+ if (typeSerializers.has(targetType)) {
47
+ return deserializeValueFromType(targetType, instance);
48
+ }
38
49
  const deserialized = new targetType();
39
50
  for (const field of fields) {
40
51
  let value = instance[field.name];
41
52
  if (value) {
42
53
  if (field.enumerable) {
43
- value = value.map(_ => deserializeValue(field, _));
54
+ value = value.map(_ => deserializeValueFromField(field, _));
44
55
  }
45
56
  else {
46
- value = deserializeValue(field, value);
57
+ value = deserializeValueFromField(field, value);
47
58
  }
48
59
  }
49
60
  deserialized[field.name] = value;
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { DerivedType } from './DerivedType';\nimport { Guid } from './Guid';\n\ntype typeSerializer = (value: any) => any;\n\nconst typeSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value],\n [Date, (value: any) => new Date(value)],\n [Guid, (value: any) => Guid.parse(value.toString())],\n]);\n\nconst deserializeValue = (field: Field, value: any) => {\n if (typeSerializers.has(field.type)) {\n return typeSerializers.get(field.type)!(value);\n } else {\n let type = field.type;\n if (field.derivatives.length > 0 && value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n type = field.derivatives.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValue(field, _));\n } else {\n value = deserializeValue(field, value);\n }\n }\n\n deserialized[field.name] = value;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value, index, arr) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":["Guid","DerivedType","Fields"],"mappings":";;;;;;AAWA,MAAM,eAAe,GAAqC,IAAI,GAAG,CAA8B;IAC3F,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,OAAO,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;AAChC,IAAA,CAAC,IAAI,EAAE,CAAC,KAAU,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACvC,IAAA,CAACA,SAAI,EAAE,CAAC,KAAU,KAAKA,SAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAA,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,CAAC,KAAY,EAAE,KAAU,KAAI;IAClD,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACjC,OAAO,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAE,CAAC,KAAK,CAAC,CAAC;KAClD;SAAM;AACH,QAAA,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;AACtB,QAAA,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,qBAAqB,CAAC,EAAE;YAC7E,MAAM,aAAa,GAAG,KAAK,CAAC,cAAc,CAAC,qBAAqB,CAAC,C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E,KAAK,CAAC,CAAC;iBAC1C;aACJ;AAED,YAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;SACpC;AAED,QAAA,IAAK,UAA0B,IAAI,MAAM,EAAE;AACvC,YAAA,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,KAAI;AACpE,gBAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;AAC9C,aAAC,CAAC,CAAC;AAEH,YAAA,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;gBAC9B,YAAY,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;aACzC;SACJ;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;AAQD,IAAA,OAAO,4BAA4B,CAAqB,UAAgC,EAAE,SAAc,EAAA;QACpG,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;SAClF;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;;AAzEe,cAAqB,CAAA,qBAAA,GAAW,gBAAgB;;;;"}
1
+ {"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { DerivedType } from './DerivedType';\nimport { Guid } from './Guid';\n\ntype typeSerializer = (value: any) => any;\n\nconst typeSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value],\n [Date, (value: any) => new Date(value)],\n [Guid, (value: any) => Guid.parse(value.toString())],\n]);\n\nconst deserializeValueFromType = (type: Constructor, value: any) => {\n if (typeSerializers.has(type)) {\n return typeSerializers.get(type)!(value);\n } else {\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\nconst deserializeValueFromField = (field: Field, value: any) => {\n if (typeSerializers.has(field.type)) {\n return typeSerializers.get(field.type)!(value);\n } else {\n let type = field.type;\n if (field.derivatives.length > 0 && value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n type = field.derivatives.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n\n if( typeSerializers.has(targetType) ) {\n return deserializeValueFromType(targetType, instance);\n }\n\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValueFromField(field, _));\n } else {\n value = deserializeValueFromField(field, value);\n }\n }\n\n deserialized[field.name] = value;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value, index, arr) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":["Guid","DerivedType","Fields"],"mappings":";;;;;;AAWA,MAAM,eAAe,GAAqC,IAAI,GAAG,CAA8B;IAC3F,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,OAAO,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;AAChC,IAAA,CAAC,IAAI,EAAE,CAAC,KAAU,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACvC,IAAA,CAACA,SAAI,EAAE,CAAC,KAAU,KAAKA,SAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvD,CAAA,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,IAAiB,EAAE,KAAU,KAAI;AAC/D,IAAA,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAC3B,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC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CAAC,KAAK,CAAC,CAAC;aACzC;SACJ;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;AAQD,IAAA,OAAO,4BAA4B,CAAqB,UAAgC,EAAE,SAAc,EAAA;QACpG,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;SAClF;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;;AA9Ee,cAAqB,CAAA,qBAAA,GAAW,gBAAgB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSerializer.d.ts","sourceRoot":"","sources":["../../JsonSerializer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAiC5C,qBAAa,cAAc;IACvB,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAoB;IAQjE,MAAM,CAAC,WAAW,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAW/F,MAAM,CAAC,gBAAgB,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE;IAWtG,MAAM,CAAC,uBAAuB,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO;IAmC5G,MAAM,CAAC,4BAA4B,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,EAAE;CASvH"}
1
+ {"version":3,"file":"JsonSerializer.d.ts","sourceRoot":"","sources":["../../JsonSerializer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAyC5C,qBAAa,cAAc;IACvB,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAoB;IAQjE,MAAM,CAAC,WAAW,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAW/F,MAAM,CAAC,gBAAgB,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE;IAWtG,MAAM,CAAC,uBAAuB,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO;IAwC5G,MAAM,CAAC,4BAA4B,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,EAAE;CASvH"}
@@ -9,7 +9,15 @@ const typeSerializers = new Map([
9
9
  [Date, (value) => new Date(value)],
10
10
  [Guid, (value) => Guid.parse(value.toString())],
11
11
  ]);
12
- const deserializeValue = (field, value) => {
12
+ const deserializeValueFromType = (type, value) => {
13
+ if (typeSerializers.has(type)) {
14
+ return typeSerializers.get(type)(value);
15
+ }
16
+ else {
17
+ return JsonSerializer.deserialize(type, JSON.stringify(value));
18
+ }
19
+ };
20
+ const deserializeValueFromField = (field, value) => {
13
21
  if (typeSerializers.has(field.type)) {
14
22
  return typeSerializers.get(field.type)(value);
15
23
  }
@@ -33,15 +41,18 @@ class JsonSerializer {
33
41
  }
34
42
  static deserializeFromInstance(targetType, instance) {
35
43
  const fields = Fields.getFieldsForType(targetType);
44
+ if (typeSerializers.has(targetType)) {
45
+ return deserializeValueFromType(targetType, instance);
46
+ }
36
47
  const deserialized = new targetType();
37
48
  for (const field of fields) {
38
49
  let value = instance[field.name];
39
50
  if (value) {
40
51
  if (field.enumerable) {
41
- value = value.map(_ => deserializeValue(field, _));
52
+ value = value.map(_ => deserializeValueFromField(field, _));
42
53
  }
43
54
  else {
44
- value = deserializeValue(field, value);
55
+ value = deserializeValueFromField(field, value);
45
56
  }
46
57
  }
47
58
  deserialized[field.name] = value;
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { DerivedType } from './DerivedType';\nimport { Guid } from './Guid';\n\ntype typeSerializer = (value: any) => any;\n\nconst typeSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value],\n [Date, (value: any) => new Date(value)],\n [Guid, (value: any) => Guid.parse(value.toString())],\n]);\n\nconst deserializeValue = (field: Field, value: any) => {\n if (typeSerializers.has(field.type)) {\n return typeSerializers.get(field.type)!(value);\n } else {\n let type = field.type;\n if (field.derivatives.length > 0 && value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n type = field.derivatives.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValue(field, _));\n } else {\n value = deserializeValue(field, value);\n }\n }\n\n deserialized[field.name] = value;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value, index, arr) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":[],"mappings":";;;;AAWA,MAAM,eAAe,GAAqC,IAAI,GAAG,CAA8B;IAC3F,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,MAAM,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;IAC/B,CAAC,OAAO,EAAE,CAAC,KAAU,KAAK,KAAK,CAAC;AAChC,IAAA,CAAC,IAAI,EAAE,CA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UAAgC,EAAE,SAAc,EAAA;QACpG,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;SAClF;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;;AAzEe,cAAqB,CAAA,qBAAA,GAAW,gBAAgB;;;;"}
1
+ {"version":3,"file":"JsonSerializer.js","sources":["../../JsonSerializer.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from './Constructor';\nimport { Field } from './Field';\nimport { Fields } from './Fields';\nimport { DerivedType } from './DerivedType';\nimport { Guid } from './Guid';\n\ntype typeSerializer = (value: any) => any;\n\nconst typeSerializers: Map<Constructor, typeSerializer> = new Map<Constructor, typeSerializer>([\n [Number, (value: any) => value],\n [String, (value: any) => value],\n [Boolean, (value: any) => value],\n [Date, (value: any) => new Date(value)],\n [Guid, (value: any) => Guid.parse(value.toString())],\n]);\n\nconst deserializeValueFromType = (type: Constructor, value: any) => {\n if (typeSerializers.has(type)) {\n return typeSerializers.get(type)!(value);\n } else {\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\nconst deserializeValueFromField = (field: Field, value: any) => {\n if (typeSerializers.has(field.type)) {\n return typeSerializers.get(field.type)!(value);\n } else {\n let type = field.type;\n if (field.derivatives.length > 0 && value[JsonSerializer.DerivedTypeIdProperty]) {\n const derivedTypeId = value[JsonSerializer.DerivedTypeIdProperty];\n type = field.derivatives.find(_ => DerivedType.get(_) == derivedTypeId) || type;\n }\n\n return JsonSerializer.deserialize(type, JSON.stringify(value));\n }\n};\n\n/**\n * Represents a serializer for JSON.\n */\nexport class JsonSerializer {\n static readonly DerivedTypeIdProperty: string = \"_derivedTypeId\";\n\n /**\n * Deserialize a JSON string to the specific type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An instance of the target type.\n */\n static deserialize<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult {\n const parsed = JSON.parse(json);\n return this.deserializeFromInstance<TResult>(targetType, parsed);\n }\n\n /**\n * Deserialize a array JSON string to an array of the specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {string} json Actual JSON to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArray<TResult extends {}>(targetType: Constructor<TResult>, json: string): TResult[] {\n const parsed = JSON.parse(json);\n return this.deserializeArrayFromInstance(targetType, parsed);\n }\n\n /**\n * Deserialize an any instance to a specific instance type.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {*} instance Actual instance to deserialize.\n * @returns An instance of the target type.\n */\n static deserializeFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instance: any): TResult {\n const fields = Fields.getFieldsForType(targetType as Constructor);\n\n if( typeSerializers.has(targetType) ) {\n return deserializeValueFromType(targetType, instance);\n }\n\n const deserialized = new targetType();\n for (const field of fields) {\n let value = instance[field.name];\n if (value) {\n if (field.enumerable) {\n value = value.map(_ => deserializeValueFromField(field, _));\n } else {\n value = deserializeValueFromField(field, value);\n }\n }\n\n deserialized[field.name] = value;\n }\n\n if ((targetType as Constructor) == Object) {\n const objectFields = Object.keys(instance).filter((value, index, arr) => {\n return !fields.some(_ => _.name == value);\n });\n\n for (const field of objectFields) {\n deserialized[field] = instance[field];\n }\n }\n\n return deserialized;\n }\n\n /**\n * Deserialize an array of any instances to an array of specific instance types.\n * @param {Constructor} targetType Type to deserialize to.\n * @param {instances} instances Actual instances to deserialize.\n * @returns An array of instances of the target type.\n */\n static deserializeArrayFromInstance<TResult extends {}>(targetType: Constructor<TResult>, instances: any): TResult[] {\n const deserialized: TResult[] = [];\n\n for (const instance of instances) {\n deserialized.push(this.deserializeFromInstance<TResult>(targetType, instance));\n }\n\n return deserialized;\n }\n}\n"],"names":[],"mapp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B,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;iBAC/D;qBAAM;AACH,oBAAA,KAAK,GAAG,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;iBACnD;aACJ;AAED,YAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;SACpC;AAED,QAAA,IAAK,UAA0B,IAAI,MAAM,EAAE;AACvC,YAAA,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,KAAI;AACpE,gBAAA,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;AAC9C,aAAC,CAAC,CAAC;AAEH,YAAA,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;gBAC9B,YAAY,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;aACzC;SACJ;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;AAQD,IAAA,OAAO,4BAA4B,CAAqB,UAAgC,EAAE,SAAc,EAAA;QACpG,MAAM,YAAY,GAAc,EAAE,CAAC;AAEnC,QAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;AAC9B,YAAA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAU,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;SAClF;AAED,QAAA,OAAO,YAAY,CAAC;KACvB;;AA9Ee,cAAqB,CAAA,qBAAA,GAAW,gBAAgB;;;;"}
@@ -4,7 +4,6 @@
4
4
  import { field } from '../fieldDecorator';
5
5
  import { JsonSerializer } from '../JsonSerializer';
6
6
  import { derivedType } from '../derivedTypeDecorator';
7
- import { Constructor } from '../Constructor';
8
7
 
9
8
  class OtherType {
10
9
  @field(Number)
@@ -96,7 +95,7 @@ describe('when deserializing complex nested object with multiple wellknown types
96
95
 
97
96
  it('should hold correct number for first level number', () => result.someNumber.should.equal(42));
98
97
  it('should hold correct string for first level string', () => result.someString.should.equal('forty two'));
99
- it('should hold correct bool fvalue for first level boolean', () => result.someBoolean.should.be.true);
98
+ it('should hold correct bool value for first level boolean', () => result.someBoolean.should.be.true);
100
99
  it('should hold correct type for first level date', () => result.someDate.constructor.should.equal(Date));
101
100
  it('should hold correct value for first level date', () => result.someDate.toString().should.equal(new Date('2022-10-07 15:51').toString()));
102
101
 
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { Guid } from '../Guid';
5
+ import { JsonSerializer } from '../JsonSerializer';
6
+
7
+ describe('when deserializing guid', () => {
8
+ const guidString = 'd2c7b1f3-5d5f-4d0a-8e3b-1b3f2c7e4d4d';
9
+ const json = `"${guidString}"`;
10
+ const result = JsonSerializer.deserialize(Guid, json);
11
+
12
+ it('should be a guid', () => result.should.be.instanceof(Guid));
13
+ it('should have the correct value', () => result.toString().should.equal(guidString));
14
+ });
@@ -1,9 +1,6 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
- // Copyright (c) Cratis. All rights reserved.
5
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
6
-
7
4
  import { field } from '../fieldDecorator';
8
5
  import { JsonSerializer } from '../JsonSerializer';
9
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/fundamentals",
3
- "version": "5.3.8",
3
+ "version": "5.4.0",
4
4
  "description": "",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",