kiss-for-react 1.0.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/LICENSE +21 -0
- package/README.md +555 -0
- package/lib/cjs/ClassPersistor.js +112 -0
- package/lib/cjs/Esserializer/DeserializationOptions.js +4 -0
- package/lib/cjs/Esserializer/SerializeOptions.js +4 -0
- package/lib/cjs/Esserializer/constant.js +131 -0
- package/lib/cjs/Esserializer/deserializer.js +313 -0
- package/lib/cjs/Esserializer/general.js +39 -0
- package/lib/cjs/Esserializer/index.js +43 -0
- package/lib/cjs/Esserializer/serializer.js +133 -0
- package/lib/cjs/Hooks.js +969 -0
- package/lib/cjs/KissAction.js +1268 -0
- package/lib/cjs/Persistor.js +120 -0
- package/lib/cjs/ProcessPersistence.js +262 -0
- package/lib/cjs/Store.js +1534 -0
- package/lib/cjs/StoreException.js +75 -0
- package/lib/cjs/UnmodifiableSetView.js +53 -0
- package/lib/cjs/UserException.js +218 -0
- package/lib/cjs/Wait.js +309 -0
- package/lib/cjs/index.js +42 -0
- package/lib/cjs/types/ClassPersistor.d.ts +113 -0
- package/lib/cjs/types/ClassPersistor.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts +7 -0
- package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/SerializeOptions.d.ts +6 -0
- package/lib/cjs/types/Esserializer/SerializeOptions.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/constant.d.ts +50 -0
- package/lib/cjs/types/Esserializer/constant.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/deserializer.d.ts +18 -0
- package/lib/cjs/types/Esserializer/deserializer.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/general.d.ts +5 -0
- package/lib/cjs/types/Esserializer/general.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/index.d.ts +30 -0
- package/lib/cjs/types/Esserializer/index.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/serializer.d.ts +4 -0
- package/lib/cjs/types/Esserializer/serializer.d.ts.map +1 -0
- package/lib/cjs/types/Hooks.d.ts +838 -0
- package/lib/cjs/types/Hooks.d.ts.map +1 -0
- package/lib/cjs/types/KissAction.d.ts +1324 -0
- package/lib/cjs/types/KissAction.d.ts.map +1 -0
- package/lib/cjs/types/Persistor.d.ts +119 -0
- package/lib/cjs/types/Persistor.d.ts.map +1 -0
- package/lib/cjs/types/ProcessPersistence.d.ts +100 -0
- package/lib/cjs/types/ProcessPersistence.d.ts.map +1 -0
- package/lib/cjs/types/Store.d.ts +1043 -0
- package/lib/cjs/types/Store.d.ts.map +1 -0
- package/lib/cjs/types/StoreException.d.ts +29 -0
- package/lib/cjs/types/StoreException.d.ts.map +1 -0
- package/lib/cjs/types/UnmodifiableSetView.d.ts +24 -0
- package/lib/cjs/types/UnmodifiableSetView.d.ts.map +1 -0
- package/lib/cjs/types/UserException.d.ts +170 -0
- package/lib/cjs/types/UserException.d.ts.map +1 -0
- package/lib/cjs/types/Wait.d.ts +1 -0
- package/lib/cjs/types/Wait.d.ts.map +1 -0
- package/lib/cjs/types/index.d.ts +10 -0
- package/lib/cjs/types/index.d.ts.map +1 -0
- package/lib/cjs/types/utils.d.ts +2 -0
- package/lib/cjs/types/utils.d.ts.map +1 -0
- package/lib/cjs/utils.js +7 -0
- package/lib/esm/ClassPersistor.js +112 -0
- package/lib/esm/Esserializer/DeserializationOptions.js +3 -0
- package/lib/esm/Esserializer/SerializeOptions.js +3 -0
- package/lib/esm/Esserializer/constant.js +81 -0
- package/lib/esm/Esserializer/deserializer.js +307 -0
- package/lib/esm/Esserializer/general.js +34 -0
- package/lib/esm/Esserializer/index.js +39 -0
- package/lib/esm/Esserializer/serializer.js +130 -0
- package/lib/esm/Hooks.js +955 -0
- package/lib/esm/KissAction.js +1368 -0
- package/lib/esm/Persistor.js +113 -0
- package/lib/esm/ProcessPersistence.js +262 -0
- package/lib/esm/Store.js +1606 -0
- package/lib/esm/StoreException.js +69 -0
- package/lib/esm/UnmodifiableSetView.js +50 -0
- package/lib/esm/UserException.js +246 -0
- package/lib/esm/Wait.js +309 -0
- package/lib/esm/index.mjs +9 -0
- package/lib/esm/types/ClassPersistor.d.ts +113 -0
- package/lib/esm/types/ClassPersistor.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/DeserializationOptions.d.ts +7 -0
- package/lib/esm/types/Esserializer/DeserializationOptions.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/SerializeOptions.d.ts +6 -0
- package/lib/esm/types/Esserializer/SerializeOptions.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/constant.d.ts +50 -0
- package/lib/esm/types/Esserializer/constant.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/deserializer.d.ts +18 -0
- package/lib/esm/types/Esserializer/deserializer.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/general.d.ts +5 -0
- package/lib/esm/types/Esserializer/general.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/index.d.ts +30 -0
- package/lib/esm/types/Esserializer/index.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/serializer.d.ts +4 -0
- package/lib/esm/types/Esserializer/serializer.d.ts.map +1 -0
- package/lib/esm/types/Hooks.d.ts +838 -0
- package/lib/esm/types/Hooks.d.ts.map +1 -0
- package/lib/esm/types/KissAction.d.ts +1324 -0
- package/lib/esm/types/KissAction.d.ts.map +1 -0
- package/lib/esm/types/Persistor.d.ts +119 -0
- package/lib/esm/types/Persistor.d.ts.map +1 -0
- package/lib/esm/types/ProcessPersistence.d.ts +100 -0
- package/lib/esm/types/ProcessPersistence.d.ts.map +1 -0
- package/lib/esm/types/Store.d.ts +1043 -0
- package/lib/esm/types/Store.d.ts.map +1 -0
- package/lib/esm/types/StoreException.d.ts +29 -0
- package/lib/esm/types/StoreException.d.ts.map +1 -0
- package/lib/esm/types/UnmodifiableSetView.d.ts +24 -0
- package/lib/esm/types/UnmodifiableSetView.d.ts.map +1 -0
- package/lib/esm/types/UserException.d.ts +170 -0
- package/lib/esm/types/UserException.d.ts.map +1 -0
- package/lib/esm/types/Wait.d.ts +1 -0
- package/lib/esm/types/Wait.d.ts.map +1 -0
- package/lib/esm/types/index.d.ts +10 -0
- package/lib/esm/types/index.d.ts.map +1 -0
- package/lib/esm/types/utils.d.ts +2 -0
- package/lib/esm/types/utils.d.ts.map +1 -0
- package/lib/esm/utils.js +3 -0
- package/package.json +87 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Esserializer code was copied and adapted from the original copyrighted work, MIT licensed, by cshao.
|
|
3
|
+
// All credit goes to him. See: https://www.npmjs.com/package/esserializer
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.TO_STRING_FIELD = exports.TIMESTAMP_FIELD = exports.OPTIONS_FIELD = exports.CLASS_NAME_FIELD = exports.BOOLEAN_FIELD = exports.ARRAY_FIELD = exports.BUILTIN_TYPE_UNDEFINED = exports.BUILTIN_TYPE_NOT_FINITE = exports.BUILTIN_TYPE_BIG_INT = exports.BUILTIN_CLASS_AGGREGATE_ERROR = exports.BUILTIN_CLASS_URI_ERROR = exports.BUILTIN_CLASS_TYPE_ERROR = exports.BUILTIN_CLASS_SYNTAX_ERROR = exports.BUILTIN_CLASS_REFERENCE_ERROR = exports.BUILTIN_CLASS_RANGE_ERROR = exports.BUILTIN_CLASS_EVAL_ERROR = exports.BUILTIN_CLASS_ERROR = exports.BUILTIN_CLASS_STRING = exports.BUILTIN_CLASS_SET = exports.BUILTIN_CLASS_REGEXP = exports.BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT = exports.BUILTIN_CLASS_INTL_PLURALRULES = exports.BUILTIN_CLASS_INTL_NUMBERFORMAT = exports.BUILTIN_CLASS_INTL_LOCALE = exports.BUILTIN_CLASS_INTL_LISTFORMAT = exports.BUILTIN_CLASS_INTL_DATETIMEFORMAT = exports.BUILTIN_CLASS_INTL_COLLATOR = exports.BUILTIN_CLASS_DATE = exports.BUILTIN_CLASS_DATAVIEW = exports.BUILTIN_CLASS_BOOLEAN = exports.BUILTIN_CLASS_SHAREDARRAYBUFFER = exports.BUILTIN_CLASS_ARRAYBUFFER = exports.BUILTIN_CLASS_BIGUINT64ARRAY = exports.BUILTIN_CLASS_BIGINT64ARRAY = exports.BUILTIN_CLASS_FLOAT64ARRAY = exports.BUILTIN_CLASS_FLOAT32ARRAY = exports.BUILTIN_CLASS_UINT32ARRAY = exports.BUILTIN_CLASS_INT32ARRAY = exports.BUILTIN_CLASS_UINT16ARRAY = exports.BUILTIN_CLASS_INT16ARRAY = exports.BUILTIN_CLASS_UINT8CLAMPEDARRAY = exports.BUILTIN_CLASS_UINT8ARRAY = exports.BUILTIN_CLASS_INT8ARRAY = exports.CLASSNAMES_WHOSE_ENUMERABLE_PROPERTIES_SHOULD_BE_IGNORED = exports.ALL_BUILTIN_INTLS = exports.ALL_BUILTIN_ERRORS = exports.ALL_BUILTIN_ARRAYS = exports.ESSERIALIZER_NULL = void 0;
|
|
6
|
+
const ESSERIALIZER_NULL = '__ESSERIALIZER_NULL__';
|
|
7
|
+
exports.ESSERIALIZER_NULL = ESSERIALIZER_NULL;
|
|
8
|
+
const ARRAY_FIELD = 'ess_arr';
|
|
9
|
+
exports.ARRAY_FIELD = ARRAY_FIELD;
|
|
10
|
+
const BOOLEAN_FIELD = 'ess_bool';
|
|
11
|
+
exports.BOOLEAN_FIELD = BOOLEAN_FIELD;
|
|
12
|
+
const CLASS_NAME_FIELD = '*type';
|
|
13
|
+
exports.CLASS_NAME_FIELD = CLASS_NAME_FIELD;
|
|
14
|
+
const OPTIONS_FIELD = 'ess_opt';
|
|
15
|
+
exports.OPTIONS_FIELD = OPTIONS_FIELD;
|
|
16
|
+
const TIMESTAMP_FIELD = 'ess_ts';
|
|
17
|
+
exports.TIMESTAMP_FIELD = TIMESTAMP_FIELD;
|
|
18
|
+
const TO_STRING_FIELD = 'ess_str';
|
|
19
|
+
exports.TO_STRING_FIELD = TO_STRING_FIELD;
|
|
20
|
+
const BUILTIN_CLASS_INT8ARRAY = 'Int8Array';
|
|
21
|
+
exports.BUILTIN_CLASS_INT8ARRAY = BUILTIN_CLASS_INT8ARRAY;
|
|
22
|
+
const BUILTIN_CLASS_UINT8ARRAY = 'Uint8Array';
|
|
23
|
+
exports.BUILTIN_CLASS_UINT8ARRAY = BUILTIN_CLASS_UINT8ARRAY;
|
|
24
|
+
const BUILTIN_CLASS_UINT8CLAMPEDARRAY = 'Uint8ClampedArray';
|
|
25
|
+
exports.BUILTIN_CLASS_UINT8CLAMPEDARRAY = BUILTIN_CLASS_UINT8CLAMPEDARRAY;
|
|
26
|
+
const BUILTIN_CLASS_INT16ARRAY = 'Int16Array';
|
|
27
|
+
exports.BUILTIN_CLASS_INT16ARRAY = BUILTIN_CLASS_INT16ARRAY;
|
|
28
|
+
const BUILTIN_CLASS_UINT16ARRAY = 'Uint16Array';
|
|
29
|
+
exports.BUILTIN_CLASS_UINT16ARRAY = BUILTIN_CLASS_UINT16ARRAY;
|
|
30
|
+
const BUILTIN_CLASS_INT32ARRAY = 'Int32Array';
|
|
31
|
+
exports.BUILTIN_CLASS_INT32ARRAY = BUILTIN_CLASS_INT32ARRAY;
|
|
32
|
+
const BUILTIN_CLASS_UINT32ARRAY = 'Uint32Array';
|
|
33
|
+
exports.BUILTIN_CLASS_UINT32ARRAY = BUILTIN_CLASS_UINT32ARRAY;
|
|
34
|
+
const BUILTIN_CLASS_FLOAT32ARRAY = 'Float32Array';
|
|
35
|
+
exports.BUILTIN_CLASS_FLOAT32ARRAY = BUILTIN_CLASS_FLOAT32ARRAY;
|
|
36
|
+
const BUILTIN_CLASS_FLOAT64ARRAY = 'Float64Array';
|
|
37
|
+
exports.BUILTIN_CLASS_FLOAT64ARRAY = BUILTIN_CLASS_FLOAT64ARRAY;
|
|
38
|
+
const BUILTIN_CLASS_BIGINT64ARRAY = 'BigInt64Array';
|
|
39
|
+
exports.BUILTIN_CLASS_BIGINT64ARRAY = BUILTIN_CLASS_BIGINT64ARRAY;
|
|
40
|
+
const BUILTIN_CLASS_BIGUINT64ARRAY = 'BigUint64Array';
|
|
41
|
+
exports.BUILTIN_CLASS_BIGUINT64ARRAY = BUILTIN_CLASS_BIGUINT64ARRAY;
|
|
42
|
+
const BUILTIN_CLASS_ARRAYBUFFER = 'ArrayBuffer';
|
|
43
|
+
exports.BUILTIN_CLASS_ARRAYBUFFER = BUILTIN_CLASS_ARRAYBUFFER;
|
|
44
|
+
const BUILTIN_CLASS_SHAREDARRAYBUFFER = 'SharedArrayBuffer';
|
|
45
|
+
exports.BUILTIN_CLASS_SHAREDARRAYBUFFER = BUILTIN_CLASS_SHAREDARRAYBUFFER;
|
|
46
|
+
const BUILTIN_CLASS_BOOLEAN = 'Boolean';
|
|
47
|
+
exports.BUILTIN_CLASS_BOOLEAN = BUILTIN_CLASS_BOOLEAN;
|
|
48
|
+
const BUILTIN_CLASS_DATAVIEW = 'DataView';
|
|
49
|
+
exports.BUILTIN_CLASS_DATAVIEW = BUILTIN_CLASS_DATAVIEW;
|
|
50
|
+
const BUILTIN_CLASS_DATE = 'Date';
|
|
51
|
+
exports.BUILTIN_CLASS_DATE = BUILTIN_CLASS_DATE;
|
|
52
|
+
const BUILTIN_CLASS_INTL_COLLATOR = 'Collator';
|
|
53
|
+
exports.BUILTIN_CLASS_INTL_COLLATOR = BUILTIN_CLASS_INTL_COLLATOR;
|
|
54
|
+
const BUILTIN_CLASS_INTL_DATETIMEFORMAT = 'DateTimeFormat';
|
|
55
|
+
exports.BUILTIN_CLASS_INTL_DATETIMEFORMAT = BUILTIN_CLASS_INTL_DATETIMEFORMAT;
|
|
56
|
+
const BUILTIN_CLASS_INTL_LISTFORMAT = 'ListFormat';
|
|
57
|
+
exports.BUILTIN_CLASS_INTL_LISTFORMAT = BUILTIN_CLASS_INTL_LISTFORMAT;
|
|
58
|
+
const BUILTIN_CLASS_INTL_LOCALE = 'Locale';
|
|
59
|
+
exports.BUILTIN_CLASS_INTL_LOCALE = BUILTIN_CLASS_INTL_LOCALE;
|
|
60
|
+
const BUILTIN_CLASS_INTL_NUMBERFORMAT = 'NumberFormat';
|
|
61
|
+
exports.BUILTIN_CLASS_INTL_NUMBERFORMAT = BUILTIN_CLASS_INTL_NUMBERFORMAT;
|
|
62
|
+
const BUILTIN_CLASS_INTL_PLURALRULES = 'PluralRules';
|
|
63
|
+
exports.BUILTIN_CLASS_INTL_PLURALRULES = BUILTIN_CLASS_INTL_PLURALRULES;
|
|
64
|
+
const BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT = 'RelativeTimeFormat';
|
|
65
|
+
exports.BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT = BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT;
|
|
66
|
+
const BUILTIN_CLASS_REGEXP = 'RegExp';
|
|
67
|
+
exports.BUILTIN_CLASS_REGEXP = BUILTIN_CLASS_REGEXP;
|
|
68
|
+
const BUILTIN_CLASS_SET = 'Set';
|
|
69
|
+
exports.BUILTIN_CLASS_SET = BUILTIN_CLASS_SET;
|
|
70
|
+
const BUILTIN_CLASS_STRING = 'String';
|
|
71
|
+
exports.BUILTIN_CLASS_STRING = BUILTIN_CLASS_STRING;
|
|
72
|
+
const BUILTIN_CLASS_ERROR = 'Error';
|
|
73
|
+
exports.BUILTIN_CLASS_ERROR = BUILTIN_CLASS_ERROR;
|
|
74
|
+
const BUILTIN_CLASS_EVAL_ERROR = 'EvalError';
|
|
75
|
+
exports.BUILTIN_CLASS_EVAL_ERROR = BUILTIN_CLASS_EVAL_ERROR;
|
|
76
|
+
const BUILTIN_CLASS_RANGE_ERROR = 'RangeError';
|
|
77
|
+
exports.BUILTIN_CLASS_RANGE_ERROR = BUILTIN_CLASS_RANGE_ERROR;
|
|
78
|
+
const BUILTIN_CLASS_REFERENCE_ERROR = 'ReferenceError';
|
|
79
|
+
exports.BUILTIN_CLASS_REFERENCE_ERROR = BUILTIN_CLASS_REFERENCE_ERROR;
|
|
80
|
+
const BUILTIN_CLASS_SYNTAX_ERROR = 'SyntaxError';
|
|
81
|
+
exports.BUILTIN_CLASS_SYNTAX_ERROR = BUILTIN_CLASS_SYNTAX_ERROR;
|
|
82
|
+
const BUILTIN_CLASS_TYPE_ERROR = 'TypeError';
|
|
83
|
+
exports.BUILTIN_CLASS_TYPE_ERROR = BUILTIN_CLASS_TYPE_ERROR;
|
|
84
|
+
const BUILTIN_CLASS_URI_ERROR = 'URIError';
|
|
85
|
+
exports.BUILTIN_CLASS_URI_ERROR = BUILTIN_CLASS_URI_ERROR;
|
|
86
|
+
const BUILTIN_CLASS_AGGREGATE_ERROR = 'AggregateError';
|
|
87
|
+
exports.BUILTIN_CLASS_AGGREGATE_ERROR = BUILTIN_CLASS_AGGREGATE_ERROR;
|
|
88
|
+
const BUILTIN_TYPE_BIG_INT = 'BI';
|
|
89
|
+
exports.BUILTIN_TYPE_BIG_INT = BUILTIN_TYPE_BIG_INT;
|
|
90
|
+
const BUILTIN_TYPE_NOT_FINITE = 'NF';
|
|
91
|
+
exports.BUILTIN_TYPE_NOT_FINITE = BUILTIN_TYPE_NOT_FINITE;
|
|
92
|
+
const BUILTIN_TYPE_UNDEFINED = 'UD';
|
|
93
|
+
exports.BUILTIN_TYPE_UNDEFINED = BUILTIN_TYPE_UNDEFINED;
|
|
94
|
+
const ALL_BUILTIN_ARRAYS = [
|
|
95
|
+
BUILTIN_CLASS_INT8ARRAY,
|
|
96
|
+
BUILTIN_CLASS_UINT8ARRAY,
|
|
97
|
+
BUILTIN_CLASS_UINT8CLAMPEDARRAY,
|
|
98
|
+
BUILTIN_CLASS_INT16ARRAY,
|
|
99
|
+
BUILTIN_CLASS_UINT16ARRAY,
|
|
100
|
+
BUILTIN_CLASS_INT32ARRAY,
|
|
101
|
+
BUILTIN_CLASS_UINT32ARRAY,
|
|
102
|
+
BUILTIN_CLASS_FLOAT32ARRAY,
|
|
103
|
+
BUILTIN_CLASS_FLOAT64ARRAY,
|
|
104
|
+
BUILTIN_CLASS_BIGINT64ARRAY,
|
|
105
|
+
BUILTIN_CLASS_BIGUINT64ARRAY
|
|
106
|
+
];
|
|
107
|
+
exports.ALL_BUILTIN_ARRAYS = ALL_BUILTIN_ARRAYS;
|
|
108
|
+
const ALL_BUILTIN_ERRORS = [
|
|
109
|
+
BUILTIN_CLASS_ERROR,
|
|
110
|
+
BUILTIN_CLASS_EVAL_ERROR,
|
|
111
|
+
BUILTIN_CLASS_RANGE_ERROR,
|
|
112
|
+
BUILTIN_CLASS_REFERENCE_ERROR,
|
|
113
|
+
BUILTIN_CLASS_SYNTAX_ERROR,
|
|
114
|
+
BUILTIN_CLASS_TYPE_ERROR,
|
|
115
|
+
BUILTIN_CLASS_URI_ERROR,
|
|
116
|
+
BUILTIN_CLASS_AGGREGATE_ERROR
|
|
117
|
+
];
|
|
118
|
+
exports.ALL_BUILTIN_ERRORS = ALL_BUILTIN_ERRORS;
|
|
119
|
+
const ALL_BUILTIN_INTLS = [
|
|
120
|
+
BUILTIN_CLASS_INTL_COLLATOR,
|
|
121
|
+
BUILTIN_CLASS_INTL_DATETIMEFORMAT,
|
|
122
|
+
BUILTIN_CLASS_INTL_LISTFORMAT,
|
|
123
|
+
BUILTIN_CLASS_INTL_NUMBERFORMAT,
|
|
124
|
+
BUILTIN_CLASS_INTL_PLURALRULES,
|
|
125
|
+
BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT
|
|
126
|
+
];
|
|
127
|
+
exports.ALL_BUILTIN_INTLS = ALL_BUILTIN_INTLS;
|
|
128
|
+
const CLASSNAMES_WHOSE_ENUMERABLE_PROPERTIES_SHOULD_BE_IGNORED = [
|
|
129
|
+
BUILTIN_CLASS_STRING, ...ALL_BUILTIN_ARRAYS
|
|
130
|
+
];
|
|
131
|
+
exports.CLASSNAMES_WHOSE_ENUMERABLE_PROPERTIES_SHOULD_BE_IGNORED = CLASSNAMES_WHOSE_ENUMERABLE_PROPERTIES_SHOULD_BE_IGNORED;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Esserializer code was copied and adapted from the original copyrighted work, MIT licensed, by cshao.
|
|
3
|
+
// All credit goes to him. See: https://www.npmjs.com/package/esserializer
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getParentClassName = exports.getClassMappingFromClassArray = exports.deserializeFromParsedObjWithClassMapping = exports.deserializeFromParsedObj = void 0;
|
|
6
|
+
const general_1 = require("./general");
|
|
7
|
+
const constant_1 = require("./constant");
|
|
8
|
+
const REGEXP_BEGIN_WITH_CLASS = /^\s*class\s+/;
|
|
9
|
+
function deserializeFromParsedObj(parsedObj, classes, options) {
|
|
10
|
+
//
|
|
11
|
+
return deserializeFromParsedObjWithClassMapping(parsedObj, getClassMappingFromClassArray(classes), options);
|
|
12
|
+
}
|
|
13
|
+
exports.deserializeFromParsedObj = deserializeFromParsedObj;
|
|
14
|
+
function deserializeFromParsedObjWithClassMapping(parsedObj, classMapping, options = {}) {
|
|
15
|
+
if ((0, general_1.notObject)(parsedObj)) {
|
|
16
|
+
return parsedObj;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(parsedObj)) {
|
|
19
|
+
return _deserializeArray(parsedObj, classMapping);
|
|
20
|
+
}
|
|
21
|
+
const classNameInParsedObj = parsedObj[constant_1.CLASS_NAME_FIELD];
|
|
22
|
+
const deserializedValueForBuiltinType = _deserializeBuiltinTypes(classNameInParsedObj, parsedObj, classMapping);
|
|
23
|
+
if (deserializedValueForBuiltinType !== constant_1.ESSERIALIZER_NULL) {
|
|
24
|
+
return deserializedValueForBuiltinType;
|
|
25
|
+
}
|
|
26
|
+
if (classNameInParsedObj && !classMapping[classNameInParsedObj]) {
|
|
27
|
+
throw new Error(`Class "${classNameInParsedObj}" not found during deserialization. You must register it with: "ESSerializer.registerClass(${classNameInParsedObj});"`);
|
|
28
|
+
}
|
|
29
|
+
let constructorParameters = [];
|
|
30
|
+
if (options.fieldsForConstructorParameters) {
|
|
31
|
+
constructorParameters = options.fieldsForConstructorParameters.map((field) => {
|
|
32
|
+
if (field in parsedObj) {
|
|
33
|
+
return parsedObj[field];
|
|
34
|
+
}
|
|
35
|
+
return {}; // Prevent passing undefined to constructor
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const deserializedObj = deserializeClassProperty(classMapping[classNameInParsedObj], constructorParameters);
|
|
39
|
+
return deserializeValuesWithClassMapping(deserializedObj, parsedObj, classMapping, options);
|
|
40
|
+
}
|
|
41
|
+
exports.deserializeFromParsedObjWithClassMapping = deserializeFromParsedObjWithClassMapping;
|
|
42
|
+
function _deserializeArray(parsedObj, classMapping) {
|
|
43
|
+
return parsedObj.map((item) => {
|
|
44
|
+
return deserializeFromParsedObjWithClassMapping(item, classMapping);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function _deserializeBuiltinTypes(classNameInParsedObj, parsedObj, classMapping) {
|
|
48
|
+
switch (classNameInParsedObj) {
|
|
49
|
+
case constant_1.BUILTIN_CLASS_INT8ARRAY:
|
|
50
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Int8Array);
|
|
51
|
+
case constant_1.BUILTIN_CLASS_UINT8ARRAY:
|
|
52
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Uint8Array);
|
|
53
|
+
case constant_1.BUILTIN_CLASS_UINT8CLAMPEDARRAY:
|
|
54
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Uint8ClampedArray);
|
|
55
|
+
case constant_1.BUILTIN_CLASS_INT16ARRAY:
|
|
56
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Int16Array);
|
|
57
|
+
case constant_1.BUILTIN_CLASS_UINT16ARRAY:
|
|
58
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Uint16Array);
|
|
59
|
+
case constant_1.BUILTIN_CLASS_INT32ARRAY:
|
|
60
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Int32Array);
|
|
61
|
+
case constant_1.BUILTIN_CLASS_UINT32ARRAY:
|
|
62
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Uint32Array);
|
|
63
|
+
case constant_1.BUILTIN_CLASS_FLOAT32ARRAY:
|
|
64
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Float32Array);
|
|
65
|
+
case constant_1.BUILTIN_CLASS_FLOAT64ARRAY:
|
|
66
|
+
return _deserializeArrayInstance(parsedObj[constant_1.ARRAY_FIELD], Float64Array);
|
|
67
|
+
case constant_1.BUILTIN_CLASS_BIGINT64ARRAY:
|
|
68
|
+
return _deserializeBigIntArrayInstance(parsedObj[constant_1.ARRAY_FIELD], BigInt64Array);
|
|
69
|
+
case constant_1.BUILTIN_CLASS_BIGUINT64ARRAY:
|
|
70
|
+
return _deserializeBigIntArrayInstance(parsedObj[constant_1.ARRAY_FIELD], BigUint64Array);
|
|
71
|
+
case constant_1.BUILTIN_TYPE_BIG_INT:
|
|
72
|
+
return deserializeBigInt(parsedObj[constant_1.TO_STRING_FIELD]);
|
|
73
|
+
case constant_1.BUILTIN_TYPE_UNDEFINED:
|
|
74
|
+
return undefined;
|
|
75
|
+
case constant_1.BUILTIN_TYPE_NOT_FINITE:
|
|
76
|
+
return (0, general_1.getValueFromToStringResult)(parsedObj[constant_1.TO_STRING_FIELD]);
|
|
77
|
+
case constant_1.BUILTIN_CLASS_ARRAYBUFFER:
|
|
78
|
+
return _deserializeArrayBuffer(parsedObj[constant_1.ARRAY_FIELD]);
|
|
79
|
+
case constant_1.BUILTIN_CLASS_SHAREDARRAYBUFFER:
|
|
80
|
+
return _deserializeSharedArrayBuffer(parsedObj[constant_1.ARRAY_FIELD]);
|
|
81
|
+
case constant_1.BUILTIN_CLASS_BOOLEAN:
|
|
82
|
+
return deserializeBoolean(parsedObj);
|
|
83
|
+
case constant_1.BUILTIN_CLASS_DATAVIEW:
|
|
84
|
+
return _deserializeDataView(parsedObj[constant_1.ARRAY_FIELD]);
|
|
85
|
+
case constant_1.BUILTIN_CLASS_DATE:
|
|
86
|
+
return deserializeDate(parsedObj);
|
|
87
|
+
case constant_1.BUILTIN_CLASS_INTL_COLLATOR:
|
|
88
|
+
return _deserializeIntlInstance(parsedObj, Intl.Collator);
|
|
89
|
+
case constant_1.BUILTIN_CLASS_INTL_DATETIMEFORMAT:
|
|
90
|
+
return _deserializeIntlInstance(parsedObj, Intl.DateTimeFormat);
|
|
91
|
+
case constant_1.BUILTIN_CLASS_INTL_LISTFORMAT:
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
return _deserializeIntlInstance(parsedObj, Intl.ListFormat);
|
|
94
|
+
case constant_1.BUILTIN_CLASS_INTL_LOCALE:
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
return new Intl.Locale(parsedObj[constant_1.TO_STRING_FIELD]);
|
|
97
|
+
case constant_1.BUILTIN_CLASS_INTL_NUMBERFORMAT:
|
|
98
|
+
return _deserializeIntlInstance(parsedObj, Intl.NumberFormat);
|
|
99
|
+
case constant_1.BUILTIN_CLASS_INTL_PLURALRULES:
|
|
100
|
+
return _deserializeIntlInstance(parsedObj, Intl.PluralRules);
|
|
101
|
+
case constant_1.BUILTIN_CLASS_INTL_RELATIVETIMEFORMAT:
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
return _deserializeIntlInstance(parsedObj, Intl.RelativeTimeFormat);
|
|
104
|
+
case constant_1.BUILTIN_CLASS_REGEXP:
|
|
105
|
+
return deserializeRegExp(parsedObj);
|
|
106
|
+
case constant_1.BUILTIN_CLASS_SET:
|
|
107
|
+
return _deserializeSet(parsedObj, classMapping);
|
|
108
|
+
case constant_1.BUILTIN_CLASS_STRING:
|
|
109
|
+
return deserializeString(parsedObj);
|
|
110
|
+
case constant_1.BUILTIN_CLASS_ERROR:
|
|
111
|
+
return deserializeError(parsedObj, Error);
|
|
112
|
+
case constant_1.BUILTIN_CLASS_EVAL_ERROR:
|
|
113
|
+
return deserializeError(parsedObj, EvalError);
|
|
114
|
+
case constant_1.BUILTIN_CLASS_RANGE_ERROR:
|
|
115
|
+
return deserializeError(parsedObj, RangeError);
|
|
116
|
+
case constant_1.BUILTIN_CLASS_REFERENCE_ERROR:
|
|
117
|
+
return deserializeError(parsedObj, ReferenceError);
|
|
118
|
+
case constant_1.BUILTIN_CLASS_SYNTAX_ERROR:
|
|
119
|
+
return deserializeError(parsedObj, SyntaxError);
|
|
120
|
+
case constant_1.BUILTIN_CLASS_TYPE_ERROR:
|
|
121
|
+
return deserializeError(parsedObj, TypeError);
|
|
122
|
+
case constant_1.BUILTIN_CLASS_URI_ERROR:
|
|
123
|
+
return deserializeError(parsedObj, URIError);
|
|
124
|
+
case constant_1.BUILTIN_CLASS_AGGREGATE_ERROR:
|
|
125
|
+
return deserializeError(parsedObj, AggregateError);
|
|
126
|
+
default:
|
|
127
|
+
return constant_1.ESSERIALIZER_NULL;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function _deserializeArrayBuffer(byteArray) {
|
|
131
|
+
return new Uint8Array(byteArray).buffer;
|
|
132
|
+
}
|
|
133
|
+
function _deserializeSharedArrayBuffer(byteArray) {
|
|
134
|
+
const sab = new SharedArrayBuffer(byteArray.length);
|
|
135
|
+
const sabViewArray = new Uint8Array(sab);
|
|
136
|
+
byteArray.forEach((byte, index) => {
|
|
137
|
+
sabViewArray[index] = byte;
|
|
138
|
+
});
|
|
139
|
+
return sab;
|
|
140
|
+
}
|
|
141
|
+
function _deserializeDataView(byteArray) {
|
|
142
|
+
return new DataView(new Uint8Array(byteArray).buffer);
|
|
143
|
+
}
|
|
144
|
+
function _deserializeArrayInstance(arr, ArrayClass) {
|
|
145
|
+
return new ArrayClass(arr);
|
|
146
|
+
}
|
|
147
|
+
function _deserializeBigIntArrayInstance(arr, ArrayClass) {
|
|
148
|
+
return new ArrayClass(arr.map((biObj) => {
|
|
149
|
+
return deserializeBigInt(biObj[constant_1.TO_STRING_FIELD]);
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
function deserializeBigInt(str) {
|
|
153
|
+
return BigInt(str);
|
|
154
|
+
}
|
|
155
|
+
function deserializeBoolean(parsedObj) {
|
|
156
|
+
// noinspection JSPrimitiveTypeWrapperUsage
|
|
157
|
+
return new Boolean(parsedObj[constant_1.BOOLEAN_FIELD]);
|
|
158
|
+
}
|
|
159
|
+
function deserializeDate(parsedObj) {
|
|
160
|
+
return typeof parsedObj[constant_1.TIMESTAMP_FIELD] === 'number' ? new Date(parsedObj[constant_1.TIMESTAMP_FIELD]) : null;
|
|
161
|
+
}
|
|
162
|
+
function _deserializeIntlInstance(parsedObj, IntlClass) {
|
|
163
|
+
const options = parsedObj[constant_1.OPTIONS_FIELD];
|
|
164
|
+
const locale = options.locale;
|
|
165
|
+
delete options.locale;
|
|
166
|
+
return new IntlClass(locale, options);
|
|
167
|
+
}
|
|
168
|
+
function deserializeRegExp(parsedObj) {
|
|
169
|
+
const regExpStr = parsedObj[constant_1.TO_STRING_FIELD];
|
|
170
|
+
const lastIndexOfSlash = regExpStr.lastIndexOf('/');
|
|
171
|
+
return new RegExp(regExpStr.substring(1, lastIndexOfSlash), regExpStr.substring(lastIndexOfSlash + 1));
|
|
172
|
+
}
|
|
173
|
+
function _deserializeSet(parsedObj, classMapping) {
|
|
174
|
+
return new Set(_deserializeArray(parsedObj[constant_1.ARRAY_FIELD], classMapping));
|
|
175
|
+
}
|
|
176
|
+
function deserializeString(parsedObj) {
|
|
177
|
+
// noinspection JSPrimitiveTypeWrapperUsage
|
|
178
|
+
return new String(parsedObj[constant_1.TO_STRING_FIELD]);
|
|
179
|
+
}
|
|
180
|
+
function deserializeError(parsedObj, ErrorClass) {
|
|
181
|
+
let error;
|
|
182
|
+
if (parsedObj.message) {
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
error = new ErrorClass(parsedObj.message);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
error = new ErrorClass();
|
|
189
|
+
}
|
|
190
|
+
delete error.stack;
|
|
191
|
+
if (parsedObj.name) {
|
|
192
|
+
error.name = parsedObj.name;
|
|
193
|
+
}
|
|
194
|
+
if (parsedObj.stack) {
|
|
195
|
+
error.stack = parsedObj.stack;
|
|
196
|
+
}
|
|
197
|
+
if (ErrorClass === AggregateError) {
|
|
198
|
+
error.errors = deserializeFromParsedObjWithClassMapping(parsedObj.errors, {});
|
|
199
|
+
}
|
|
200
|
+
return error;
|
|
201
|
+
}
|
|
202
|
+
function deserializeClassProperty(classObj, constructorParameters) {
|
|
203
|
+
if (!classObj) {
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
const additionalParameterNumber = Math.max(classObj.length - constructorParameters.length, 0);
|
|
207
|
+
const FALLBACK_PARAMETERS = [{}, 0, '', null];
|
|
208
|
+
let fallbackParam = FALLBACK_PARAMETERS.shift();
|
|
209
|
+
let deserializedObj;
|
|
210
|
+
while (!deserializedObj && fallbackParam !== undefined) {
|
|
211
|
+
deserializedObj = createDeserializedObj(classObj, constructorParameters.concat(Array.from(Array(additionalParameterNumber), () => (fallbackParam))));
|
|
212
|
+
if (additionalParameterNumber === 0) {
|
|
213
|
+
fallbackParam = undefined;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
fallbackParam = FALLBACK_PARAMETERS.shift();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!deserializedObj) {
|
|
220
|
+
deserializedObj = {};
|
|
221
|
+
Object.setPrototypeOf(deserializedObj, classObj ? classObj.prototype : Object.prototype);
|
|
222
|
+
}
|
|
223
|
+
return deserializedObj;
|
|
224
|
+
}
|
|
225
|
+
function createDeserializedObj(classObj, allConstructorParameters) {
|
|
226
|
+
let deserializedObj;
|
|
227
|
+
try {
|
|
228
|
+
if (REGEXP_BEGIN_WITH_CLASS.test(classObj.toString())) {
|
|
229
|
+
deserializedObj = new classObj(...allConstructorParameters);
|
|
230
|
+
}
|
|
231
|
+
else { // It's class in function style.
|
|
232
|
+
let objectConstructor = classObj.prototype.constructor;
|
|
233
|
+
if (objectConstructor.name === 'Object') {
|
|
234
|
+
objectConstructor = classObj; // In case object's constructor is not in its prototype, such as Big in big.js
|
|
235
|
+
}
|
|
236
|
+
deserializedObj = Object.create(objectConstructor.prototype);
|
|
237
|
+
objectConstructor.call(deserializedObj, allConstructorParameters);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
deserializedObj = null;
|
|
242
|
+
}
|
|
243
|
+
return deserializedObj;
|
|
244
|
+
}
|
|
245
|
+
function deserializeValuesWithClassMapping(deserializedObj, parsedObj, classMapping, options) {
|
|
246
|
+
for (const k in parsedObj) {
|
|
247
|
+
const v = parsedObj[k];
|
|
248
|
+
if (options.ignoreProperties && options.ignoreProperties.includes(k)) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (options.rawProperties && options.rawProperties.includes(k)) {
|
|
252
|
+
deserializedObj[k] = JSON.stringify(v);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const descriptor = Object.getOwnPropertyDescriptor(deserializedObj, k);
|
|
256
|
+
if (canSkipCopyingValue(k, v, descriptor)) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (descriptor && descriptor.writable === false && typeof v === 'object') {
|
|
260
|
+
assignWritableField(deserializedObj[k], v, classMapping);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
deserializedObj[k] = deserializeFromParsedObjWithClassMapping(v, classMapping);
|
|
264
|
+
}
|
|
265
|
+
return deserializedObj;
|
|
266
|
+
}
|
|
267
|
+
function canSkipCopyingValue(keyOfParsedObj, valueOfParsedObj, descriptorOfDeserializedObjProperty) {
|
|
268
|
+
if (keyOfParsedObj === constant_1.CLASS_NAME_FIELD) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
return descriptorOfDeserializedObjProperty && (typeof descriptorOfDeserializedObjProperty.set === 'function' ||
|
|
272
|
+
(descriptorOfDeserializedObjProperty.writable === false && typeof valueOfParsedObj !== 'object'));
|
|
273
|
+
}
|
|
274
|
+
function assignWritableField(targetObj, sourceObj, classMapping) {
|
|
275
|
+
for (const field in sourceObj) {
|
|
276
|
+
const descriptor = Object.getOwnPropertyDescriptor(targetObj, field);
|
|
277
|
+
if (descriptor && !(descriptor.writable === true || typeof descriptor.set === 'function')) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
targetObj[field] = deserializeFromParsedObjWithClassMapping(sourceObj[field], classMapping);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
*
|
|
285
|
+
* @param classes It's an array of Class definition. "any" is used in code only
|
|
286
|
+
* because there is no TypeScript type definition for Class.
|
|
287
|
+
*/
|
|
288
|
+
function getClassMappingFromClassArray(classes = []) {
|
|
289
|
+
const classMapping = {};
|
|
290
|
+
classes.forEach((c) => {
|
|
291
|
+
if (!(0, general_1.isClass)(c)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const className = c.name;
|
|
295
|
+
const previousClass = classMapping[className];
|
|
296
|
+
if (previousClass && previousClass !== c) {
|
|
297
|
+
console.warn('WARNING: Found class definition with the same name: ' + className);
|
|
298
|
+
}
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
classMapping[className] = c;
|
|
301
|
+
});
|
|
302
|
+
return classMapping;
|
|
303
|
+
}
|
|
304
|
+
exports.getClassMappingFromClassArray = getClassMappingFromClassArray;
|
|
305
|
+
/**
|
|
306
|
+
*
|
|
307
|
+
* @param classObj It's a Class definition. "any" is used in code only
|
|
308
|
+
* because there is no TypeScript type definition for Class.
|
|
309
|
+
*/
|
|
310
|
+
function getParentClassName(classObj) {
|
|
311
|
+
return classObj.prototype.__proto__.constructor.name;
|
|
312
|
+
}
|
|
313
|
+
exports.getParentClassName = getParentClassName;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Esserializer code was copied and adapted from the original copyrighted work, MIT licensed, by cshao.
|
|
3
|
+
// All credit goes to him. See: https://www.npmjs.com/package/esserializer
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.isClass = exports.notObject = exports.getValueFromToStringResult = void 0;
|
|
6
|
+
function notObject(target) {
|
|
7
|
+
return target === null || typeof target !== 'object';
|
|
8
|
+
}
|
|
9
|
+
exports.notObject = notObject;
|
|
10
|
+
function getValueFromToStringResult(result) {
|
|
11
|
+
switch (result) {
|
|
12
|
+
case 'Infinity':
|
|
13
|
+
return Infinity;
|
|
14
|
+
case '-Infinity':
|
|
15
|
+
return -Infinity;
|
|
16
|
+
case 'NaN':
|
|
17
|
+
return NaN;
|
|
18
|
+
default:
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.getValueFromToStringResult = getValueFromToStringResult;
|
|
23
|
+
function isSupportedBuiltinClass(target) {
|
|
24
|
+
return [Date].indexOf(target) >= 0;
|
|
25
|
+
}
|
|
26
|
+
function isClass(target) {
|
|
27
|
+
if (isSupportedBuiltinClass(target)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// Adopt solution from https://stackoverflow.com/a/46759625/707451
|
|
31
|
+
try {
|
|
32
|
+
Reflect.construct(String, [], target);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
exports.isClass = isClass;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Esserializer code was copied and adapted from the original copyrighted work, MIT licensed, by cshao.
|
|
3
|
+
// All credit goes to him. See: https://www.npmjs.com/package/esserializer
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ESSerializer = void 0;
|
|
6
|
+
const serializer_1 = require("./serializer");
|
|
7
|
+
const deserializer_1 = require("./deserializer");
|
|
8
|
+
class ESSerializer {
|
|
9
|
+
/**
|
|
10
|
+
* Globally register classes or enums.
|
|
11
|
+
*/
|
|
12
|
+
static registerClasses(classesOrEnums) {
|
|
13
|
+
this.registeredClasses = this.registeredClasses.concat(classesOrEnums);
|
|
14
|
+
}
|
|
15
|
+
static registerClass(classOrEnum) {
|
|
16
|
+
this.registeredClasses.push(classOrEnum);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Clear all registered classes.
|
|
20
|
+
*/
|
|
21
|
+
static clearRegisteredClasses() {
|
|
22
|
+
this.registeredClasses = [];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @param target
|
|
26
|
+
* @param options Serialization options
|
|
27
|
+
*/
|
|
28
|
+
static serialize(target, options = {}) {
|
|
29
|
+
return JSON.stringify((0, serializer_1.getSerializeValueWithClassName)(target, options));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param serializedText
|
|
33
|
+
* @param classes
|
|
34
|
+
* because there is no TypeScript type definition for Class.
|
|
35
|
+
* @param options Deserialization options
|
|
36
|
+
*/
|
|
37
|
+
static deserialize(serializedText, classes = [], options = {}) {
|
|
38
|
+
//
|
|
39
|
+
return (0, deserializer_1.deserializeFromParsedObj)(JSON.parse(serializedText), Object.values(this.registeredClasses).concat(classes), options);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ESSerializer = ESSerializer;
|
|
43
|
+
ESSerializer.registeredClasses = [];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The Esserializer code was copied and adapted from the original copyrighted work, MIT licensed, by cshao.
|
|
3
|
+
// All credit goes to him. See: https://www.npmjs.com/package/esserializer
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getSerializeValueWithClassName = void 0;
|
|
6
|
+
const constant_1 = require("./constant");
|
|
7
|
+
const general_1 = require("./general");
|
|
8
|
+
function getSerializeValueWithClassName(target, options = {}) {
|
|
9
|
+
const serializeValueForBuiltinTypes = _getSerializeValueForBuiltinTypes(target);
|
|
10
|
+
if (serializeValueForBuiltinTypes !== constant_1.ESSERIALIZER_NULL) {
|
|
11
|
+
return serializeValueForBuiltinTypes;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(target)) {
|
|
14
|
+
return _serializeArray(target);
|
|
15
|
+
}
|
|
16
|
+
const serializedObj = {};
|
|
17
|
+
if (!_shouldIgnoreEnumerableProperties(target)) {
|
|
18
|
+
if (options.ignoreProperties) {
|
|
19
|
+
options.ignoreProperties.forEach((ignored) => {
|
|
20
|
+
delete target[ignored];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (options.interceptProperties) {
|
|
24
|
+
for (const intercepted in options.interceptProperties) {
|
|
25
|
+
target[intercepted] = options.interceptProperties[intercepted].call(target, target[intercepted]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
copySerializedProperties(target, serializedObj);
|
|
29
|
+
}
|
|
30
|
+
return appendClassInfoAndAssignDataForBuiltinType(target, serializedObj);
|
|
31
|
+
}
|
|
32
|
+
exports.getSerializeValueWithClassName = getSerializeValueWithClassName;
|
|
33
|
+
function copySerializedProperties(source, dest) {
|
|
34
|
+
for (const k in source) {
|
|
35
|
+
const v = source[k];
|
|
36
|
+
if (typeof v === 'function') {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
dest[k] = getSerializeValueWithClassName(source[k]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function appendClassInfoAndAssignDataForBuiltinType(target, serializedObj) {
|
|
44
|
+
let className = target.__proto__.constructor.name;
|
|
45
|
+
if (className === 'Object') {
|
|
46
|
+
className = target.constructor.name; // In case object's constructor is not in its prototype, such as Big in big.js
|
|
47
|
+
}
|
|
48
|
+
if (className !== 'Object') {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
serializedObj[constant_1.CLASS_NAME_FIELD] = className;
|
|
51
|
+
if (className === constant_1.BUILTIN_CLASS_ARRAYBUFFER || className === constant_1.BUILTIN_CLASS_SHAREDARRAYBUFFER) {
|
|
52
|
+
serializedObj[constant_1.ARRAY_FIELD] = _serializeArray(Array.from(new Uint8Array(target)));
|
|
53
|
+
}
|
|
54
|
+
else if (className === constant_1.BUILTIN_CLASS_BOOLEAN) {
|
|
55
|
+
serializedObj[constant_1.BOOLEAN_FIELD] = target.valueOf();
|
|
56
|
+
}
|
|
57
|
+
else if (className === constant_1.BUILTIN_CLASS_DATAVIEW) {
|
|
58
|
+
serializedObj[constant_1.ARRAY_FIELD] = _serializeArray(Array.from(new Uint8Array(target.buffer)));
|
|
59
|
+
}
|
|
60
|
+
else if (className === constant_1.BUILTIN_CLASS_DATE) {
|
|
61
|
+
serializedObj[constant_1.TIMESTAMP_FIELD] = target.getTime();
|
|
62
|
+
}
|
|
63
|
+
else if (className === constant_1.BUILTIN_CLASS_INTL_LOCALE) {
|
|
64
|
+
serializedObj[constant_1.TO_STRING_FIELD] = target.toString();
|
|
65
|
+
}
|
|
66
|
+
else if (className === constant_1.BUILTIN_CLASS_REGEXP) {
|
|
67
|
+
serializedObj[constant_1.TO_STRING_FIELD] = target.toString();
|
|
68
|
+
}
|
|
69
|
+
else if (className === constant_1.BUILTIN_CLASS_SET) {
|
|
70
|
+
serializedObj[constant_1.ARRAY_FIELD] = _serializeArray(Array.from(target));
|
|
71
|
+
}
|
|
72
|
+
else if (className === constant_1.BUILTIN_CLASS_STRING) {
|
|
73
|
+
serializedObj[constant_1.TO_STRING_FIELD] = target.toString();
|
|
74
|
+
}
|
|
75
|
+
else if (constant_1.ALL_BUILTIN_ARRAYS.includes(className)) {
|
|
76
|
+
serializedObj[constant_1.ARRAY_FIELD] = _serializeArray(Array.from(target));
|
|
77
|
+
}
|
|
78
|
+
else if (constant_1.ALL_BUILTIN_ERRORS.includes(className)) {
|
|
79
|
+
_assignDataForErrorType(target, serializedObj, className);
|
|
80
|
+
}
|
|
81
|
+
else if (constant_1.ALL_BUILTIN_INTLS.includes(className)) {
|
|
82
|
+
serializedObj[constant_1.OPTIONS_FIELD] = target.resolvedOptions();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return serializedObj;
|
|
86
|
+
}
|
|
87
|
+
function _assignDataForErrorType(target, serializedObj, className) {
|
|
88
|
+
if (target.name !== 'Error') {
|
|
89
|
+
serializedObj.name = target.name;
|
|
90
|
+
}
|
|
91
|
+
if (target.message) {
|
|
92
|
+
serializedObj.message = target.message;
|
|
93
|
+
}
|
|
94
|
+
if (target.stack) {
|
|
95
|
+
serializedObj.stack = target.stack;
|
|
96
|
+
}
|
|
97
|
+
if (className === constant_1.BUILTIN_CLASS_AGGREGATE_ERROR) {
|
|
98
|
+
serializedObj.errors = getSerializeValueWithClassName(target.errors);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function _getSerializeValueForBuiltinTypes(target) {
|
|
102
|
+
if (target === undefined) {
|
|
103
|
+
return {
|
|
104
|
+
[constant_1.CLASS_NAME_FIELD]: constant_1.BUILTIN_TYPE_UNDEFINED
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Infinity, -Infinity, NaN
|
|
108
|
+
if (typeof target === 'number' && !isFinite(target)) {
|
|
109
|
+
return {
|
|
110
|
+
[constant_1.CLASS_NAME_FIELD]: constant_1.BUILTIN_TYPE_NOT_FINITE,
|
|
111
|
+
[constant_1.TO_STRING_FIELD]: target.toString()
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (typeof target === 'bigint') {
|
|
115
|
+
return {
|
|
116
|
+
[constant_1.CLASS_NAME_FIELD]: constant_1.BUILTIN_TYPE_BIG_INT,
|
|
117
|
+
[constant_1.TO_STRING_FIELD]: target.toString()
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if ((0, general_1.notObject)(target)) {
|
|
121
|
+
return target;
|
|
122
|
+
}
|
|
123
|
+
return constant_1.ESSERIALIZER_NULL;
|
|
124
|
+
}
|
|
125
|
+
function _serializeArray(arr) {
|
|
126
|
+
return arr.map((elem) => {
|
|
127
|
+
return getSerializeValueWithClassName(elem);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function _shouldIgnoreEnumerableProperties(target) {
|
|
131
|
+
const className = target.__proto__.constructor.name;
|
|
132
|
+
return constant_1.CLASSNAMES_WHOSE_ENUMERABLE_PROPERTIES_SHOULD_BE_IGNORED.includes(className);
|
|
133
|
+
}
|