seroval 0.4.0-alpha.12 → 0.4.0-alpha.13
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/dist/cjs/development/index.cjs +298 -329
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +298 -329
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/context.d.ts +11 -11
- package/dist/types/tree/primitives.d.ts +1 -10
- package/dist/types/tree/types.d.ts +57 -38
- package/package.json +2 -2
- package/src/context.ts +37 -39
- package/src/index.ts +8 -9
- package/src/tree/async.ts +48 -111
- package/src/tree/primitives.ts +7 -143
- package/src/tree/sync.ts +45 -94
- package/src/tree/types.ts +202 -53
package/src/tree/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { BigIntTypedArrayValue, PrimitiveValue, TypedArrayValue } from '../types';
|
|
2
3
|
|
|
3
4
|
export const enum SerovalNodeType {
|
|
4
5
|
Primitive,
|
|
@@ -21,81 +22,156 @@ export const enum SerovalNodeType {
|
|
|
21
22
|
|
|
22
23
|
export interface SerovalBaseNode {
|
|
23
24
|
// Type of the node
|
|
24
|
-
t
|
|
25
|
+
t?: SerovalNodeType;
|
|
25
26
|
// Serialized value
|
|
26
|
-
s
|
|
27
|
+
s?: PrimitiveValue;
|
|
27
28
|
// Reference ID
|
|
28
|
-
i
|
|
29
|
+
i?: number;
|
|
29
30
|
// Size/Byte offset
|
|
30
|
-
l
|
|
31
|
+
l?: number;
|
|
31
32
|
// Constructor name
|
|
32
|
-
c
|
|
33
|
+
c?: string;
|
|
33
34
|
// dictionary
|
|
34
|
-
d
|
|
35
|
+
d?: SerovalDictionaryNode;
|
|
35
36
|
// message
|
|
36
|
-
m
|
|
37
|
+
m?: string;
|
|
37
38
|
// next node
|
|
38
|
-
n
|
|
39
|
+
n?: SerovalNode;
|
|
39
40
|
// array of nodes
|
|
40
|
-
a
|
|
41
|
+
a?: SerovalNode[];
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export
|
|
44
|
+
export class SerovalObjectRecordNode {
|
|
44
45
|
k: string[];
|
|
46
|
+
|
|
45
47
|
v: SerovalNode[];
|
|
48
|
+
|
|
46
49
|
s: number;
|
|
50
|
+
|
|
51
|
+
constructor(k: string[], v: SerovalNode[], s: number) {
|
|
52
|
+
this.k = k;
|
|
53
|
+
this.v = v;
|
|
54
|
+
this.s = s;
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
export
|
|
58
|
+
export class SerovalMapRecordNode {
|
|
50
59
|
k: SerovalNode[];
|
|
60
|
+
|
|
51
61
|
v: SerovalNode[];
|
|
62
|
+
|
|
52
63
|
s: number;
|
|
64
|
+
|
|
65
|
+
constructor(k: SerovalNode[], v: SerovalNode[], s: number) {
|
|
66
|
+
this.k = k;
|
|
67
|
+
this.v = v;
|
|
68
|
+
this.s = s;
|
|
69
|
+
}
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
export type SerovalDictionaryNode =
|
|
56
73
|
| SerovalObjectRecordNode
|
|
57
74
|
| SerovalMapRecordNode;
|
|
58
75
|
|
|
59
|
-
export
|
|
60
|
-
t: SerovalNodeType.Primitive;
|
|
76
|
+
export class SerovalPrimitiveNode implements SerovalBaseNode {
|
|
77
|
+
t: SerovalNodeType.Primitive = SerovalNodeType.Primitive;
|
|
78
|
+
|
|
79
|
+
s: string | number | null;
|
|
80
|
+
|
|
81
|
+
constructor(current: string | number | null) {
|
|
82
|
+
this.s = current;
|
|
83
|
+
}
|
|
61
84
|
}
|
|
62
85
|
|
|
63
|
-
export
|
|
64
|
-
t: SerovalNodeType.Reference;
|
|
86
|
+
export class SerovalReferenceNode implements SerovalBaseNode {
|
|
87
|
+
t: SerovalNodeType.Reference = SerovalNodeType.Reference;
|
|
88
|
+
|
|
65
89
|
i: number;
|
|
90
|
+
|
|
91
|
+
constructor(id: number) {
|
|
92
|
+
this.i = id;
|
|
93
|
+
}
|
|
66
94
|
}
|
|
67
95
|
|
|
68
|
-
export
|
|
69
|
-
t: SerovalNodeType.BigInt;
|
|
96
|
+
export class SerovalBigIntNode implements SerovalBaseNode {
|
|
97
|
+
t: SerovalNodeType.BigInt = SerovalNodeType.BigInt;
|
|
98
|
+
|
|
70
99
|
s: string;
|
|
100
|
+
|
|
101
|
+
constructor(current: bigint) {
|
|
102
|
+
this.s = `${current}n`;
|
|
103
|
+
}
|
|
71
104
|
}
|
|
72
105
|
|
|
73
|
-
export
|
|
74
|
-
t: SerovalNodeType.Date;
|
|
106
|
+
export class SerovalDateNode implements SerovalBaseNode {
|
|
107
|
+
t: SerovalNodeType.Date = SerovalNodeType.Date;
|
|
108
|
+
|
|
75
109
|
i: number;
|
|
110
|
+
|
|
76
111
|
s: string;
|
|
112
|
+
|
|
113
|
+
constructor(id: number, current: Date) {
|
|
114
|
+
this.i = id;
|
|
115
|
+
this.s = current.toISOString();
|
|
116
|
+
}
|
|
77
117
|
}
|
|
78
118
|
|
|
79
|
-
export
|
|
80
|
-
t: SerovalNodeType.RegExp;
|
|
119
|
+
export class SerovalRegExpNode implements SerovalBaseNode {
|
|
120
|
+
t: SerovalNodeType.RegExp = SerovalNodeType.RegExp;
|
|
121
|
+
|
|
81
122
|
i: number;
|
|
123
|
+
|
|
82
124
|
s: string;
|
|
125
|
+
|
|
126
|
+
constructor(id: number, current: RegExp) {
|
|
127
|
+
this.i = id;
|
|
128
|
+
this.s = String(current);
|
|
129
|
+
}
|
|
83
130
|
}
|
|
84
131
|
|
|
85
|
-
export
|
|
86
|
-
t: SerovalNodeType.TypedArray;
|
|
132
|
+
export class SerovalTypedArrayNode implements SerovalBaseNode {
|
|
133
|
+
t: SerovalNodeType.TypedArray = SerovalNodeType.TypedArray;
|
|
134
|
+
|
|
87
135
|
i: number;
|
|
136
|
+
|
|
88
137
|
s: string;
|
|
138
|
+
|
|
89
139
|
l: number;
|
|
140
|
+
|
|
90
141
|
c: string;
|
|
142
|
+
|
|
143
|
+
constructor(id: number, current: TypedArrayValue) {
|
|
144
|
+
this.i = id;
|
|
145
|
+
this.s = current.toString();
|
|
146
|
+
this.l = current.byteOffset;
|
|
147
|
+
this.c = current.constructor.name;
|
|
148
|
+
}
|
|
91
149
|
}
|
|
92
150
|
|
|
93
|
-
export
|
|
94
|
-
t: SerovalNodeType.BigIntTypedArray;
|
|
151
|
+
export class SerovalBigIntTypedArrayNode implements SerovalBaseNode {
|
|
152
|
+
t: SerovalNodeType.BigIntTypedArray = SerovalNodeType.BigIntTypedArray;
|
|
153
|
+
|
|
95
154
|
i: number;
|
|
155
|
+
|
|
96
156
|
s: string;
|
|
157
|
+
|
|
97
158
|
l: number;
|
|
159
|
+
|
|
98
160
|
c: string;
|
|
161
|
+
|
|
162
|
+
constructor(id: number, current: BigIntTypedArrayValue) {
|
|
163
|
+
let result = '';
|
|
164
|
+
const cap = current.length - 1;
|
|
165
|
+
for (let i = 0; i < cap; i++) {
|
|
166
|
+
result += `${current[i]}n,`;
|
|
167
|
+
}
|
|
168
|
+
result += `"${current[cap]}"`;
|
|
169
|
+
|
|
170
|
+
this.i = id;
|
|
171
|
+
this.s = result;
|
|
172
|
+
this.l = current.byteOffset;
|
|
173
|
+
this.c = current.constructor.name;
|
|
174
|
+
}
|
|
99
175
|
}
|
|
100
176
|
|
|
101
177
|
export type SerovalSemiPrimitiveNode =
|
|
@@ -105,63 +181,136 @@ export type SerovalSemiPrimitiveNode =
|
|
|
105
181
|
| SerovalTypedArrayNode
|
|
106
182
|
| SerovalBigIntTypedArrayNode;
|
|
107
183
|
|
|
108
|
-
export
|
|
109
|
-
t: SerovalNodeType.Set;
|
|
110
|
-
|
|
184
|
+
export class SerovalSetNode implements SerovalBaseNode {
|
|
185
|
+
t: SerovalNodeType.Set = SerovalNodeType.Set;
|
|
186
|
+
|
|
111
187
|
i: number;
|
|
188
|
+
|
|
189
|
+
a: SerovalNode[];
|
|
190
|
+
|
|
191
|
+
constructor(id: number, a: SerovalNode[]) {
|
|
192
|
+
this.i = id;
|
|
193
|
+
this.a = a;
|
|
194
|
+
}
|
|
112
195
|
}
|
|
113
196
|
|
|
114
|
-
export
|
|
115
|
-
t: SerovalNodeType.Map;
|
|
116
|
-
|
|
197
|
+
export class SerovalMapNode implements SerovalBaseNode {
|
|
198
|
+
t: SerovalNodeType.Map = SerovalNodeType.Map;
|
|
199
|
+
|
|
117
200
|
i: number;
|
|
201
|
+
|
|
202
|
+
d: SerovalMapRecordNode;
|
|
203
|
+
|
|
204
|
+
constructor(id: number, d: SerovalMapRecordNode) {
|
|
205
|
+
this.i = id;
|
|
206
|
+
this.d = d;
|
|
207
|
+
}
|
|
118
208
|
}
|
|
119
209
|
|
|
120
|
-
export
|
|
121
|
-
t: SerovalNodeType.Array;
|
|
122
|
-
|
|
210
|
+
export class SerovalArrayNode implements SerovalBaseNode {
|
|
211
|
+
t: SerovalNodeType.Array = SerovalNodeType.Array;
|
|
212
|
+
|
|
123
213
|
i: number;
|
|
214
|
+
|
|
215
|
+
a: SerovalNode[];
|
|
216
|
+
|
|
217
|
+
constructor(id: number, a: SerovalNode[]) {
|
|
218
|
+
this.i = id;
|
|
219
|
+
this.a = a;
|
|
220
|
+
}
|
|
124
221
|
}
|
|
125
222
|
|
|
126
|
-
export
|
|
127
|
-
t: SerovalNodeType.Object;
|
|
128
|
-
|
|
223
|
+
export class SerovalObjectNode implements SerovalBaseNode {
|
|
224
|
+
t: SerovalNodeType.Object = SerovalNodeType.Object;
|
|
225
|
+
|
|
129
226
|
i: number;
|
|
130
|
-
}
|
|
131
227
|
|
|
132
|
-
export interface SerovalNullConstructorNode extends SerovalBaseNode {
|
|
133
|
-
t: SerovalNodeType.NullConstructor;
|
|
134
228
|
d: SerovalObjectRecordNode;
|
|
229
|
+
|
|
230
|
+
constructor(id: number, d: SerovalObjectRecordNode) {
|
|
231
|
+
this.i = id;
|
|
232
|
+
this.d = d;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export class SerovalNullConstructorNode implements SerovalBaseNode {
|
|
237
|
+
t: SerovalNodeType.NullConstructor = SerovalNodeType.NullConstructor;
|
|
238
|
+
|
|
135
239
|
i: number;
|
|
240
|
+
|
|
241
|
+
d: SerovalObjectRecordNode;
|
|
242
|
+
|
|
243
|
+
constructor(id: number, d: SerovalObjectRecordNode) {
|
|
244
|
+
this.i = id;
|
|
245
|
+
this.d = d;
|
|
246
|
+
}
|
|
136
247
|
}
|
|
137
248
|
|
|
138
|
-
export
|
|
139
|
-
t: SerovalNodeType.Promise;
|
|
140
|
-
|
|
249
|
+
export class SerovalPromiseNode implements SerovalBaseNode {
|
|
250
|
+
t: SerovalNodeType.Promise = SerovalNodeType.Promise;
|
|
251
|
+
|
|
141
252
|
i: number;
|
|
253
|
+
|
|
254
|
+
n: SerovalNode;
|
|
255
|
+
|
|
256
|
+
constructor(id: number, n: SerovalNode) {
|
|
257
|
+
this.i = id;
|
|
258
|
+
this.n = n;
|
|
259
|
+
}
|
|
142
260
|
}
|
|
143
261
|
|
|
144
|
-
export
|
|
145
|
-
t: SerovalNodeType.Error;
|
|
262
|
+
export class SerovalErrorNode implements SerovalBaseNode {
|
|
263
|
+
t: SerovalNodeType.Error = SerovalNodeType.Error;
|
|
264
|
+
|
|
265
|
+
i: number;
|
|
266
|
+
|
|
146
267
|
c: string;
|
|
268
|
+
|
|
147
269
|
m: string;
|
|
270
|
+
|
|
148
271
|
d: SerovalObjectRecordNode | undefined;
|
|
149
|
-
|
|
272
|
+
|
|
273
|
+
constructor(id: number, c: string, m: string, d: SerovalObjectRecordNode | undefined) {
|
|
274
|
+
this.i = id;
|
|
275
|
+
this.c = c;
|
|
276
|
+
this.m = m;
|
|
277
|
+
this.d = d;
|
|
278
|
+
}
|
|
150
279
|
}
|
|
151
280
|
|
|
152
|
-
export
|
|
153
|
-
t: SerovalNodeType.AggregateError;
|
|
281
|
+
export class SerovalAggregateErrorNode implements SerovalBaseNode {
|
|
282
|
+
t: SerovalNodeType.AggregateError = SerovalNodeType.AggregateError;
|
|
283
|
+
|
|
284
|
+
i: number;
|
|
285
|
+
|
|
154
286
|
m: string;
|
|
287
|
+
|
|
155
288
|
d: SerovalObjectRecordNode | undefined;
|
|
289
|
+
|
|
156
290
|
n: SerovalNode;
|
|
157
|
-
|
|
291
|
+
|
|
292
|
+
constructor(id: number, m: string, d: SerovalObjectRecordNode | undefined, n: SerovalNode) {
|
|
293
|
+
this.i = id;
|
|
294
|
+
this.m = m;
|
|
295
|
+
this.d = d;
|
|
296
|
+
this.n = n;
|
|
297
|
+
}
|
|
158
298
|
}
|
|
159
299
|
|
|
160
|
-
export
|
|
161
|
-
t: SerovalNodeType.Iterable;
|
|
300
|
+
export class SerovalIterableNode implements SerovalBaseNode {
|
|
301
|
+
t: SerovalNodeType.Iterable = SerovalNodeType.Iterable;
|
|
302
|
+
|
|
303
|
+
i: number;
|
|
304
|
+
|
|
162
305
|
d: SerovalObjectRecordNode | undefined;
|
|
306
|
+
|
|
163
307
|
a: SerovalNode[];
|
|
164
|
-
|
|
308
|
+
|
|
309
|
+
constructor(id: number, d: SerovalObjectRecordNode | undefined, a: SerovalNode[]) {
|
|
310
|
+
this.i = id;
|
|
311
|
+
this.d = d;
|
|
312
|
+
this.a = a;
|
|
313
|
+
}
|
|
165
314
|
}
|
|
166
315
|
|
|
167
316
|
export type SerovalNode =
|