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