ts-serializable 2.0.52 → 2.0.58

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.
@@ -44,7 +44,7 @@ export declare class Serializable {
44
44
  * @returns {object}
45
45
  * @memberof Serializable
46
46
  */
47
- toJSON(): object;
47
+ toJSON(): Record<string, unknown>;
48
48
  /**
49
49
  * Process exceptions from wrong types.
50
50
  * By default just print warning in console, but can by override for drop exception or logging to backend.
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-invalid-void-type */
2
+ /* eslint-disable no-prototype-builtins */
3
3
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
4
4
  /* eslint-disable complexity */
5
5
  /* eslint-disable max-lines-per-function */
6
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
7
- /* eslint-disable @typescript-eslint/strict-boolean-expressions */
8
- /* eslint-disable @typescript-eslint/ban-types */
9
6
  /* eslint-disable max-statements */
10
- /* eslint-disable @typescript-eslint/no-unsafe-call, no-prototype-builtins */
7
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.Serializable = void 0;
13
10
  const SerializationSettings_1 = require("../models/SerializationSettings");
@@ -81,12 +78,10 @@ class Serializable {
81
78
  for (const prop in fromJson) {
82
79
  // Json.hasOwnProperty(prop) - preserve for deserialization for other classes with methods
83
80
  if (fromJson.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
84
- if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) || false) {
85
- // eslint-disable-next-line no-continue
86
- continue;
81
+ if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) !== true) {
82
+ const toProp = this.getJsonPropertyName(prop);
83
+ Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
87
84
  }
88
- const toProp = this.getJsonPropertyName(prop);
89
- Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
90
85
  }
91
86
  }
92
87
  return toJson;
@@ -180,12 +175,11 @@ class Serializable {
180
175
  acceptedType !== void 0 &&
181
176
  !Array.isArray(acceptedType) &&
182
177
  (acceptedType.prototype instanceof Serializable ||
183
- Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType)) &&
178
+ Boolean(Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType))) &&
184
179
  jsonValue !== null &&
185
180
  jsonValue !== void 0 &&
186
181
  typeof jsonValue === "object" && !Array.isArray(jsonValue)) {
187
182
  const TypeConstructor = acceptedType;
188
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
189
183
  return new TypeConstructor().fromJSON(jsonValue, settings);
190
184
  }
191
185
  else if ( // Instance any other class, not Serializable, for parse from other classes instance
@@ -1,12 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-invalid-void-type */
1
+ /* eslint-disable no-prototype-builtins */
2
2
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
3
3
  /* eslint-disable complexity */
4
4
  /* eslint-disable max-lines-per-function */
5
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
- /* eslint-disable @typescript-eslint/strict-boolean-expressions */
7
- /* eslint-disable @typescript-eslint/ban-types */
8
5
  /* eslint-disable max-statements */
9
- /* eslint-disable @typescript-eslint/no-unsafe-call, no-prototype-builtins */
6
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
10
7
  import { SerializationSettings } from "../models/SerializationSettings";
11
8
  /**
12
9
  * Class how help you deserialize object to classes.
@@ -78,12 +75,10 @@ export class Serializable {
78
75
  for (const prop in fromJson) {
79
76
  // Json.hasOwnProperty(prop) - preserve for deserialization for other classes with methods
80
77
  if (fromJson.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
81
- if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) || false) {
82
- // eslint-disable-next-line no-continue
83
- continue;
78
+ if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) !== true) {
79
+ const toProp = this.getJsonPropertyName(prop);
80
+ Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
84
81
  }
85
- const toProp = this.getJsonPropertyName(prop);
86
- Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
87
82
  }
88
83
  }
89
84
  return toJson;
@@ -177,12 +172,11 @@ export class Serializable {
177
172
  acceptedType !== void 0 &&
178
173
  !Array.isArray(acceptedType) &&
179
174
  (acceptedType.prototype instanceof Serializable ||
180
- Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType)) &&
175
+ Boolean(Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType))) &&
181
176
  jsonValue !== null &&
182
177
  jsonValue !== void 0 &&
183
178
  typeof jsonValue === "object" && !Array.isArray(jsonValue)) {
184
179
  const TypeConstructor = acceptedType;
185
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
186
180
  return new TypeConstructor().fromJSON(jsonValue, settings);
187
181
  }
188
182
  else if ( // Instance any other class, not Serializable, for parse from other classes instance
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.jsonIgnore = void 0;
5
4
  const jsonIgnore = () => (target, propertyKey) => {
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
1
  export const jsonIgnore = () => (target, propertyKey) => {
3
2
  Reflect.defineMetadata("ts-serializable:jsonIgnore", true, target, propertyKey);
4
3
  };
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.jsonName = void 0;
5
4
  const jsonName = (jsonPropertyName) => (target, propertyKey) => {
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
1
  export const jsonName = (jsonPropertyName) => (target, propertyKey) => {
3
2
  Reflect.defineMetadata("ts-serializable:jsonName", jsonPropertyName, target, propertyKey);
4
3
  };
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
- /* eslint-disable @typescript-eslint/ban-types */
4
- /* eslint-disable max-statements */
5
- /* eslint-disable @typescript-eslint/unbound-method */
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
- /* eslint-disable @typescript-eslint/no-unsafe-call */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.jsonObject = void 0;
11
4
  const Serializable_1 = require("../classes/Serializable");
@@ -1,10 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
- /* eslint-disable @typescript-eslint/ban-types */
3
- /* eslint-disable max-statements */
4
- /* eslint-disable @typescript-eslint/unbound-method */
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
7
- /* eslint-disable @typescript-eslint/no-unsafe-call */
8
1
  import { Serializable } from "../classes/Serializable";
9
2
  export const jsonObject = (settings, extend) => (target) => {
10
3
  if (extend === true) {
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.jsonProperty = void 0;
5
4
  const jsonProperty = (...args) => (target, propertyKey) => {
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
1
  export const jsonProperty = (...args) => (target, propertyKey) => {
3
2
  Reflect.defineMetadata("ts-serializable:jsonTypes", args, target, propertyKey);
4
3
  };
@@ -1,4 +1,4 @@
1
- export declare type AcceptedType = null | void | BooleanConstructor | NumberConstructor | StringConstructor | ObjectConstructor | (new (...args: (Object | null | void)[]) => object) | DateConstructor | SymbolConstructor;
1
+ export declare type AcceptedType = null | void | BooleanConstructor | NumberConstructor | StringConstructor | ObjectConstructor | (new (...args: unknown[]) => object) | DateConstructor | SymbolConstructor;
2
2
  interface IRecursiveArray<T> extends Array<IRecursiveArray<T> | T> {
3
3
  }
4
4
  export declare type AcceptedTypes = AcceptedType | IRecursiveArray<AcceptedType>;
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/sort-type-union-intersection-members */
3
+ /* eslint-disable @typescript-eslint/no-invalid-void-type */
4
+ /* eslint-disable @typescript-eslint/no-type-alias */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/sort-type-union-intersection-members */
2
+ /* eslint-disable @typescript-eslint/no-invalid-void-type */
3
+ /* eslint-disable @typescript-eslint/no-type-alias */
1
4
  export {};
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "ts-serializable",
3
- "version": "2.0.52",
3
+ "version": "2.0.58",
4
4
  "description": "Serialization and deserializtion for classes",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "typings": "./dist/index.d.ts",
8
8
  "dependencies": {},
9
9
  "devDependencies": {
10
- "@labeg/code-style": "^2.0.31",
11
- "@types/chai": "^4.3.0",
12
- "@types/mocha": "^9.1.0",
10
+ "@labeg/code-style": "^2.0.34",
11
+ "@types/chai": "^4.3.1",
12
+ "@types/mocha": "^9.1.1",
13
13
  "chai": "^4.3.6",
14
- "mocha": "^9.2.2",
14
+ "mocha": "^10.0.0",
15
15
  "reflect-metadata": "^0.1.13",
16
16
  "ts-node": "^10.7.0",
17
- "typescript": "^4.6.2"
17
+ "typescript": "^4.6.4"
18
18
  },
19
19
  "scripts": {
20
20
  "cs:eslint": "eslint --fix -c .eslintrc.js --ext .tsx,.ts,.jsx,.js ./src/ ./tests/",
@@ -1,12 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-invalid-void-type */
1
+ /* eslint-disable no-prototype-builtins */
2
2
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
3
3
  /* eslint-disable complexity */
4
4
  /* eslint-disable max-lines-per-function */
5
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
- /* eslint-disable @typescript-eslint/strict-boolean-expressions */
7
- /* eslint-disable @typescript-eslint/ban-types */
8
5
  /* eslint-disable max-statements */
9
- /* eslint-disable @typescript-eslint/no-unsafe-call, no-prototype-builtins */
6
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
10
7
 
11
8
  import type {AcceptedTypes} from "../models/AcceptedType";
12
9
  import {SerializationSettings} from "../models/SerializationSettings";
@@ -104,21 +101,17 @@ export class Serializable {
104
101
  * @returns {object}
105
102
  * @memberof Serializable
106
103
  */
107
- public toJSON (): object {
108
- const fromJson: object = {...this};
109
- const toJson: object = {};
104
+ public toJSON (): Record<string, unknown> {
105
+ const fromJson: this = {...this};
106
+ const toJson: Record<string, unknown> = {};
110
107
 
111
108
  for (const prop in fromJson) {
112
109
  // Json.hasOwnProperty(prop) - preserve for deserialization for other classes with methods
113
110
  if (fromJson.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
114
- if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) || false) {
115
- // eslint-disable-next-line no-continue
116
- continue;
111
+ if (Reflect.getMetadata("ts-serializable:jsonIgnore", this.constructor.prototype, prop) !== true) {
112
+ const toProp = this.getJsonPropertyName(prop);
113
+ Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
117
114
  }
118
-
119
- const toProp = this.getJsonPropertyName(prop);
120
-
121
- Reflect.set(toJson, toProp, Reflect.get(fromJson, prop));
122
115
  }
123
116
  }
124
117
 
@@ -187,7 +180,7 @@ export class Serializable {
187
180
  acceptedType === Object &&
188
181
  (typeof jsonValue === "object")
189
182
  ) {
190
- return Object(jsonValue) as Object;
183
+ return Object(jsonValue);
191
184
  } else if (// Date
192
185
  acceptedType === Date &&
193
186
  (typeof jsonValue === "string" || jsonValue instanceof String || jsonValue instanceof Date)
@@ -227,7 +220,7 @@ export class Serializable {
227
220
  !Array.isArray(acceptedType) &&
228
221
  (
229
222
  acceptedType.prototype instanceof Serializable ||
230
- Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType)
223
+ Boolean(Reflect.getMetadata("ts-serializable:jsonObjectExtended", acceptedType))
231
224
  ) &&
232
225
  jsonValue !== null &&
233
226
  jsonValue !== void 0 &&
@@ -235,7 +228,6 @@ export class Serializable {
235
228
  ) {
236
229
  const TypeConstructor: new () => Serializable = acceptedType as new () => Serializable;
237
230
 
238
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
231
  return new TypeConstructor().fromJSON(jsonValue, settings);
240
232
  } else if (// Instance any other class, not Serializable, for parse from other classes instance
241
233
  acceptedType instanceof Function &&
@@ -248,7 +240,7 @@ export class Serializable {
248
240
  // Process wrong type and return default value
249
241
  this.onWrongType(prop, "is invalid", jsonValue);
250
242
 
251
- return Reflect.get(this, prop) as Object | null | void;
243
+ return Reflect.get(this, prop);
252
244
  }
253
245
 
254
246
  protected getJsonPropertyName (thisProperty: string, settings?: Partial<SerializationSettings>): string {
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
-
3
1
  export const jsonIgnore = (): PropertyDecorator => (
4
2
  target: object,
5
3
  propertyKey: string | symbol
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
-
3
-
4
1
  export const jsonName = (jsonPropertyName: string): PropertyDecorator => (
5
2
  target: object,
6
3
  propertyKey: string | symbol
@@ -1,11 +1,8 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
- /* eslint-disable @typescript-eslint/ban-types */
3
- /* eslint-disable max-statements */
4
- /* eslint-disable @typescript-eslint/unbound-method */
5
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
3
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
7
- /* eslint-disable @typescript-eslint/no-unsafe-call */
8
-
4
+ /* eslint-disable @typescript-eslint/unbound-method */
5
+ /* eslint-disable max-statements */
9
6
  import type {SerializationSettings} from "../models/SerializationSettings";
10
7
  import {Serializable} from "../classes/Serializable";
11
8
 
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
-
3
1
  import type {AcceptedTypes} from "./../models/AcceptedType";
4
2
 
5
3
  export const jsonProperty = (...args: AcceptedTypes[]): PropertyDecorator => (
@@ -1,14 +1,14 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
1
  /* eslint-disable @typescript-eslint/sort-type-union-intersection-members */
3
2
  /* eslint-disable @typescript-eslint/no-invalid-void-type */
4
3
  /* eslint-disable @typescript-eslint/no-type-alias */
4
+
5
5
  export type AcceptedType = null |
6
6
  void |
7
7
  BooleanConstructor |
8
8
  NumberConstructor |
9
9
  StringConstructor |
10
10
  ObjectConstructor |
11
- (new (...args: (Object | null | void)[]) => object) |
11
+ (new (...args: unknown[]) => object) |
12
12
  // Extended deserialization
13
13
  DateConstructor |
14
14
  SymbolConstructor; // Add ArrayBufferConstructor, MapConstructor, RegExpConstructor and many others...