@hg-ts/serialize 0.1.53 → 0.1.55
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/package.json +7 -7
- package/.eslintcache +0 -1
- package/.turbo/turbo-build.log +0 -2
- package/.turbo/turbo-lint$colon$ts.log +0 -2
- package/.turbo/turbo-test.log +0 -19
- package/src/additional-classes.ts +0 -5
- package/src/deserialize.ts +0 -69
- package/src/exceptions/deserialize-unknown-prototype.exception.ts +0 -7
- package/src/exceptions/deserialize.exception.ts +0 -9
- package/src/exceptions/index.ts +0 -3
- package/src/exceptions/serialize.exception.ts +0 -7
- package/src/index.ts +0 -7
- package/src/serialize.ts +0 -114
- package/src/tests/serialization.test.ts +0 -74
- package/src/types.ts +0 -70
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hg-ts/serialize",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js"
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"test:dev": "yarn build:dev --onSuccess \"yarn test\""
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@hg-ts-config/typescript": "0.1.
|
|
20
|
-
"@hg-ts/exception": "0.1.
|
|
21
|
-
"@hg-ts/linter": "0.1.
|
|
22
|
-
"@hg-ts/tests": "0.1.
|
|
23
|
-
"@hg-ts/types": "0.1.
|
|
19
|
+
"@hg-ts-config/typescript": "0.1.55",
|
|
20
|
+
"@hg-ts/exception": "0.1.55",
|
|
21
|
+
"@hg-ts/linter": "0.1.55",
|
|
22
|
+
"@hg-ts/tests": "0.1.55",
|
|
23
|
+
"@hg-ts/types": "0.1.55",
|
|
24
24
|
"@types/node": "22.10.6",
|
|
25
25
|
"eslint": "9.18.0",
|
|
26
26
|
"reflect-metadata": "0.2.2",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"typescript": "5.7.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@hg-ts/exception": "0.1.
|
|
32
|
+
"@hg-ts/exception": "0.1.55",
|
|
33
33
|
"reflect-metadata": "*",
|
|
34
34
|
"tslib": "*"
|
|
35
35
|
}
|
package/.eslintcache
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/additional-classes.js":"1","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/deserialize.js":"2","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/deserialize-unknown-prototype.exception.js":"3","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/deserialize.exception.js":"4","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/index.js":"5","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/serialize.exception.js":"6","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/index.js":"7","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/serialize.js":"8","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/tests/serialization.test.js":"9","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/types.js":"10","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/eslint.config.mjs":"11","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/additional-classes.ts":"12","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/deserialize.ts":"13","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/deserialize-unknown-prototype.exception.ts":"14","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/deserialize.exception.ts":"15","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/index.ts":"16","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/serialize.exception.ts":"17","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/index.ts":"18","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/serialize.ts":"19","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/tests/serialization.test.ts":"20","/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/types.ts":"21"},{"size":343,"mtime":1746294715486,"results":"22","hashOfConfig":"23"},{"size":1984,"mtime":1746294715497,"results":"24","hashOfConfig":"23"},{"size":529,"mtime":1746294715489,"results":"25","hashOfConfig":"23"},{"size":435,"mtime":1746294715492,"results":"26","hashOfConfig":"23"},{"size":361,"mtime":1746294715494,"results":"27","hashOfConfig":"23"},{"size":414,"mtime":1746294715493,"results":"28","hashOfConfig":"23"},{"size":606,"mtime":1746294715502,"results":"29","hashOfConfig":"23"},{"size":2776,"mtime":1746294715500,"results":"30","hashOfConfig":"23"},{"size":3923,"mtime":1746294715507,"results":"31","hashOfConfig":"23"},{"size":110,"mtime":1746294715490,"results":"32","hashOfConfig":"23"},{"size":59,"mtime":1736896000117,"results":"33","hashOfConfig":"23"},{"size":175,"mtime":1736876770678,"results":"34","hashOfConfig":"35"},{"size":1736,"mtime":1736876770678,"results":"36","hashOfConfig":"35"},{"size":245,"mtime":1736876770678,"results":"37","hashOfConfig":"35"},{"size":276,"mtime":1736876770678,"results":"38","hashOfConfig":"35"},{"size":139,"mtime":1736876770678,"results":"39","hashOfConfig":"35"},{"size":204,"mtime":1736876770678,"results":"40","hashOfConfig":"35"},{"size":176,"mtime":1736876770678,"results":"41","hashOfConfig":"35"},{"size":2365,"mtime":1736876770678,"results":"42","hashOfConfig":"35"},{"size":1511,"mtime":1739852908160,"results":"43","hashOfConfig":"35"},{"size":1103,"mtime":1736876770678,"results":"44","hashOfConfig":"35"},{"filePath":"45","messages":"46","suppressedMessages":"47","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1gtnk1i",{"filePath":"48","messages":"49","suppressedMessages":"50","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"51","messages":"52","suppressedMessages":"53","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","suppressedMessages":"56","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"57","messages":"58","suppressedMessages":"59","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","suppressedMessages":"62","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"63","messages":"64","suppressedMessages":"65","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","suppressedMessages":"68","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"69","messages":"70","suppressedMessages":"71","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"72","messages":"73","suppressedMessages":"74","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"75","messages":"76","suppressedMessages":"77","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"78","messages":"79","suppressedMessages":"80","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"i5df87",{"filePath":"81","messages":"82","suppressedMessages":"83","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"84","messages":"85","suppressedMessages":"86","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"87","messages":"88","suppressedMessages":"89","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"90","messages":"91","suppressedMessages":"92","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"93","messages":"94","suppressedMessages":"95","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"96","messages":"97","suppressedMessages":"98","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"99","messages":"100","suppressedMessages":"101","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"102","messages":"103","suppressedMessages":"104","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"105","messages":"106","suppressedMessages":"107","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/additional-classes.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/deserialize.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/deserialize-unknown-prototype.exception.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/deserialize.exception.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/index.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/exceptions/serialize.exception.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/index.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/serialize.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/tests/serialization.test.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/dist/types.js",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/eslint.config.mjs",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/additional-classes.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/deserialize.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/deserialize-unknown-prototype.exception.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/deserialize.exception.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/index.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/exceptions/serialize.exception.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/index.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/serialize.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/tests/serialization.test.ts",[],[],"/Users/atsapko/WebstormProjects/personnal/framework/packages/serialize/src/types.ts",[],[]]
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-test.log
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
▶ SerializationTestSuite
|
|
3
|
-
[32m✔ serializeNull [90m(1.095375ms)[39m[39m
|
|
4
|
-
[32m✔ serializeNumber [90m(0.317167ms)[39m[39m
|
|
5
|
-
[32m✔ serializeString [90m(0.412167ms)[39m[39m
|
|
6
|
-
[32m✔ serializeSet [90m(0.398083ms)[39m[39m
|
|
7
|
-
[32m✔ serializeMap [90m(0.635458ms)[39m[39m
|
|
8
|
-
[32m✔ serializeDate [90m(0.660084ms)[39m[39m
|
|
9
|
-
[32m✔ serializeBigint [90m(0.868875ms)[39m[39m
|
|
10
|
-
[32m✔ serializeBuffer [90m(0.263625ms)[39m[39m
|
|
11
|
-
[32m✔ SerializationTestSuite [90m(5.371125ms)[39m[39m
|
|
12
|
-
[34mℹ tests 8[39m
|
|
13
|
-
[34mℹ suites 1[39m
|
|
14
|
-
[34mℹ pass 8[39m
|
|
15
|
-
[34mℹ fail 0[39m
|
|
16
|
-
[34mℹ cancelled 0[39m
|
|
17
|
-
[34mℹ skipped 0[39m
|
|
18
|
-
[34mℹ todo 0[39m
|
|
19
|
-
[34mℹ duration_ms 242.58725[39m
|
package/src/deserialize.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { DeserializeException, DeserializeUnknownPrototypeException } from './exceptions';
|
|
2
|
-
import type {
|
|
3
|
-
SerializedObject,
|
|
4
|
-
SerializedValue,
|
|
5
|
-
} from './types';
|
|
6
|
-
import { classes } from './additional-classes';
|
|
7
|
-
|
|
8
|
-
function deserializeObject(
|
|
9
|
-
{ value, prototypeNameList }: SerializedObject,
|
|
10
|
-
): unknown {
|
|
11
|
-
let targetClass: Class = Object;
|
|
12
|
-
const [preferredClassName = null] = prototypeNameList.filter(name => name !== Object.name);
|
|
13
|
-
|
|
14
|
-
if (preferredClassName) {
|
|
15
|
-
const foundCtor = classes.get(preferredClassName);
|
|
16
|
-
|
|
17
|
-
if (!foundCtor) {
|
|
18
|
-
throw new DeserializeUnknownPrototypeException(preferredClassName);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
targetClass = foundCtor;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const result: Record<string, unknown> = Object.create(targetClass.prototype);
|
|
25
|
-
|
|
26
|
-
return Object.keys(value)
|
|
27
|
-
.reduce<Record<string, unknown>>((result, key) => {
|
|
28
|
-
result[key] = deserializeValue(value[key]!);
|
|
29
|
-
|
|
30
|
-
return result;
|
|
31
|
-
}, result);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function deserializeValue(value: SerializedValue): unknown {
|
|
35
|
-
switch (value.type) {
|
|
36
|
-
case 'boolean':
|
|
37
|
-
case 'string':
|
|
38
|
-
case 'number':
|
|
39
|
-
return value.value;
|
|
40
|
-
case 'buffer':
|
|
41
|
-
return Buffer.from(value.value, 'hex');
|
|
42
|
-
case 'bigint':
|
|
43
|
-
return BigInt(value.value);
|
|
44
|
-
case 'null':
|
|
45
|
-
return null;
|
|
46
|
-
case 'date':
|
|
47
|
-
return new Date(value.value);
|
|
48
|
-
case 'array':
|
|
49
|
-
return value.value.map(item => deserializeValue(item));
|
|
50
|
-
case 'set':
|
|
51
|
-
return new Set(value.value.map(item => deserializeValue(item)));
|
|
52
|
-
case 'map':
|
|
53
|
-
return new Map(value.value.map(item => [
|
|
54
|
-
deserializeValue(item.key),
|
|
55
|
-
deserializeValue(item.value),
|
|
56
|
-
]));
|
|
57
|
-
case 'object':
|
|
58
|
-
return deserializeObject(value);
|
|
59
|
-
|
|
60
|
-
default: {
|
|
61
|
-
const error: never = value;
|
|
62
|
-
throw new DeserializeException(error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function deserialize(value: SerializedValue): unknown {
|
|
68
|
-
return deserializeValue(value);
|
|
69
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BaseException } from '@hg-ts/exception';
|
|
2
|
-
|
|
3
|
-
import type { SerializedValue } from '../types';
|
|
4
|
-
|
|
5
|
-
export class DeserializeException extends BaseException {
|
|
6
|
-
public constructor(value: SerializedValue) {
|
|
7
|
-
super(`Error for deserialize value: ${JSON.stringify(value)}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
package/src/exceptions/index.ts
DELETED
package/src/index.ts
DELETED
package/src/serialize.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SerializedArray,
|
|
3
|
-
SerializedObject,
|
|
4
|
-
SerializedValue,
|
|
5
|
-
} from './types';
|
|
6
|
-
import { SerializeException } from './exceptions';
|
|
7
|
-
|
|
8
|
-
export function getPrototypeListNames(value: Record<string | symbol, unknown>): string[] {
|
|
9
|
-
const result: string[] = [];
|
|
10
|
-
let nextPrototype = Object.getPrototypeOf(value);
|
|
11
|
-
|
|
12
|
-
while (nextPrototype !== null) {
|
|
13
|
-
result.push(nextPrototype.constructor.name);
|
|
14
|
-
|
|
15
|
-
nextPrototype = Object.getPrototypeOf(nextPrototype);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function serializeArray(value: unknown[]): SerializedArray {
|
|
22
|
-
return {
|
|
23
|
-
type: 'array',
|
|
24
|
-
value: value.map(item => serializeValue(item)),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function serializeRecord(value: Record<string | symbol, unknown>): SerializedObject {
|
|
29
|
-
const fields = Object.keys(value)
|
|
30
|
-
.reduce<Record<string, SerializedValue>>((result, key) => {
|
|
31
|
-
if (typeof key === 'symbol') {
|
|
32
|
-
throw new SerializeException('symbol key');
|
|
33
|
-
}
|
|
34
|
-
result[key] = serializeValue(value[key]);
|
|
35
|
-
return result;
|
|
36
|
-
}, {});
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
type: 'object',
|
|
40
|
-
prototypeNameList: getPrototypeListNames(value),
|
|
41
|
-
value: fields,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function serializeObject(value: object | null): SerializedValue {
|
|
46
|
-
if (value === null) {
|
|
47
|
-
return { type: 'null' };
|
|
48
|
-
}
|
|
49
|
-
if (value instanceof Date) {
|
|
50
|
-
return {
|
|
51
|
-
type: 'date',
|
|
52
|
-
value: value.getTime(),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (value instanceof Buffer) {
|
|
56
|
-
return {
|
|
57
|
-
type: 'buffer',
|
|
58
|
-
value: value.toString('hex'),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (value instanceof Map) {
|
|
62
|
-
return {
|
|
63
|
-
type: 'map',
|
|
64
|
-
value: [...value.entries()].map(([key, value]) => ({
|
|
65
|
-
key: serializeValue(key),
|
|
66
|
-
value: serializeValue(value),
|
|
67
|
-
})),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (value instanceof Set) {
|
|
71
|
-
return {
|
|
72
|
-
type: 'set',
|
|
73
|
-
value: [...value.values()].map(item => serializeValue(item)),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(value)) {
|
|
77
|
-
return serializeArray(value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return serializeRecord(value as any);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function serializeValue(value: unknown): SerializedValue {
|
|
84
|
-
switch (typeof value) {
|
|
85
|
-
case 'boolean':
|
|
86
|
-
return {
|
|
87
|
-
value,
|
|
88
|
-
type: 'boolean',
|
|
89
|
-
};
|
|
90
|
-
case 'bigint':
|
|
91
|
-
return {
|
|
92
|
-
type: 'bigint',
|
|
93
|
-
value: String(value),
|
|
94
|
-
};
|
|
95
|
-
case 'string':
|
|
96
|
-
return {
|
|
97
|
-
value,
|
|
98
|
-
type: 'string',
|
|
99
|
-
};
|
|
100
|
-
case 'number':
|
|
101
|
-
return {
|
|
102
|
-
value,
|
|
103
|
-
type: 'number',
|
|
104
|
-
};
|
|
105
|
-
case 'object':
|
|
106
|
-
return serializeObject(value as any);
|
|
107
|
-
default:
|
|
108
|
-
throw new SerializeException(typeof value);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function serialize(value: unknown): SerializedValue {
|
|
113
|
-
return serializeValue(value);
|
|
114
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import '@hg-ts/types';
|
|
2
|
-
import {
|
|
3
|
-
Test,
|
|
4
|
-
Describe,
|
|
5
|
-
Suite,
|
|
6
|
-
expect,
|
|
7
|
-
} from '@hg-ts/tests';
|
|
8
|
-
import { serialize } from '../serialize';
|
|
9
|
-
import { deserialize } from '../deserialize';
|
|
10
|
-
|
|
11
|
-
@Describe()
|
|
12
|
-
export class SerializationTestSuite extends Suite {
|
|
13
|
-
@Test()
|
|
14
|
-
public async serializeNull(): Promise<void> {
|
|
15
|
-
this.test(null);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@Test()
|
|
19
|
-
public async serializeNumber(): Promise<void> {
|
|
20
|
-
this.test(123);
|
|
21
|
-
this.test(12.35);
|
|
22
|
-
this.test(0);
|
|
23
|
-
this.test(-12.35);
|
|
24
|
-
this.test(-123);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@Test()
|
|
28
|
-
public async serializeString(): Promise<void> {
|
|
29
|
-
this.test('random string');
|
|
30
|
-
this.test('');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Test()
|
|
34
|
-
public async serializeSet(): Promise<void> {
|
|
35
|
-
this.test(new Set(['foo', 'bar']));
|
|
36
|
-
this.test(new Set());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@Test()
|
|
40
|
-
public async serializeMap(): Promise<void> {
|
|
41
|
-
this.test(new Map<unknown, unknown>([
|
|
42
|
-
['foo', 'bar'],
|
|
43
|
-
[1, 'string'],
|
|
44
|
-
['string', Buffer.from('some string')],
|
|
45
|
-
]));
|
|
46
|
-
this.test(new Map());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Test()
|
|
50
|
-
public async serializeDate(): Promise<void> {
|
|
51
|
-
this.test(new Date());
|
|
52
|
-
this.test(new Date('2024-01-01'));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Test()
|
|
56
|
-
public async serializeBigint(): Promise<void> {
|
|
57
|
-
this.test(1235n * 1_000_000_000_000_000_000_000_000n);
|
|
58
|
-
this.test(123n);
|
|
59
|
-
this.test(0n);
|
|
60
|
-
this.test(-123n);
|
|
61
|
-
this.test(-1235n * 1_000_000_000_000_000_000_000_000n);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Test()
|
|
65
|
-
public async serializeBuffer(): Promise<void> {
|
|
66
|
-
this.test(Buffer.from('sdfsdgdfgdfg'));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
protected test(expected: unknown): void {
|
|
70
|
-
const value = deserialize(serialize(expected));
|
|
71
|
-
|
|
72
|
-
expect(value).toEqual(expected);
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export type SerializedNumber = {
|
|
2
|
-
type: 'number';
|
|
3
|
-
value: number;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type SerializedString = {
|
|
7
|
-
type: 'string';
|
|
8
|
-
value: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type SerializedBoolean = {
|
|
12
|
-
type: 'boolean';
|
|
13
|
-
value: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type SerializedBigint = {
|
|
17
|
-
type: 'bigint';
|
|
18
|
-
value: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type SerializedDate = {
|
|
22
|
-
type: 'date';
|
|
23
|
-
value: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type SerializedArray = {
|
|
27
|
-
type: 'array';
|
|
28
|
-
value: SerializedValue[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type SerializedBuffer = {
|
|
32
|
-
type: 'buffer';
|
|
33
|
-
value: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type SerializedObject = {
|
|
37
|
-
type: 'object';
|
|
38
|
-
prototypeNameList: string[];
|
|
39
|
-
value: Record<string, SerializedValue>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type SerializedMap = {
|
|
43
|
-
type: 'map';
|
|
44
|
-
value: {
|
|
45
|
-
key: SerializedValue;
|
|
46
|
-
value: SerializedValue;
|
|
47
|
-
}[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type SerializedSet = {
|
|
51
|
-
type: 'set';
|
|
52
|
-
value: SerializedValue[];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type SerializedNull = {
|
|
56
|
-
type: 'null';
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type SerializedValue =
|
|
60
|
-
| SerializedArray
|
|
61
|
-
| SerializedBigint
|
|
62
|
-
| SerializedBoolean
|
|
63
|
-
| SerializedDate
|
|
64
|
-
| SerializedMap
|
|
65
|
-
| SerializedNull
|
|
66
|
-
| SerializedBuffer
|
|
67
|
-
| SerializedNumber
|
|
68
|
-
| SerializedObject
|
|
69
|
-
| SerializedSet
|
|
70
|
-
| SerializedString;
|