seroval 0.7.0 → 0.8.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/dist/cjs/development/index.cjs +1109 -1039
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1109 -1039
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/assert.d.ts +1 -1
- package/dist/types/context.d.ts +2 -2
- package/dist/types/index.d.ts +3 -4
- package/dist/types/string.d.ts +1 -1
- package/dist/types/tree/UnsupportedTypeError.d.ts +3 -0
- package/dist/types/tree/async.d.ts +3 -3
- package/dist/types/tree/constants.d.ts +11 -0
- package/dist/types/tree/deserialize.d.ts +2 -2
- package/dist/types/tree/primitives.d.ts +9 -15
- package/dist/types/tree/serialize.d.ts +2 -2
- package/dist/types/tree/shared.d.ts +10 -8
- package/dist/types/tree/sync.d.ts +3 -3
- package/dist/types/tree/types.d.ts +64 -71
- package/dist/types/tree/web-api.d.ts +2 -2
- package/dist/types/types.d.ts +4 -4
- package/package.json +10 -8
- package/src/assert.ts +2 -2
- package/src/compat.ts +0 -1
- package/src/context.ts +10 -7
- package/src/get-identifier.ts +1 -1
- package/src/index.ts +35 -26
- package/src/string.ts +2 -2
- package/src/tree/UnsupportedTypeError.ts +8 -0
- package/src/tree/async.ts +245 -233
- package/src/tree/constants.ts +72 -0
- package/src/tree/deserialize.ts +96 -93
- package/src/tree/primitives.ts +81 -134
- package/src/tree/reference.ts +4 -3
- package/src/tree/serialize.ts +251 -197
- package/src/tree/shared.ts +31 -22
- package/src/tree/symbols.ts +13 -13
- package/src/tree/sync.ts +226 -198
- package/src/tree/types.ts +74 -93
- package/src/tree/web-api.ts +10 -7
- package/src/types.ts +7 -3
package/src/tree/types.ts
CHANGED
|
@@ -1,40 +1,45 @@
|
|
|
1
|
-
import { Symbols } from './symbols';
|
|
1
|
+
import type { Symbols } from './symbols';
|
|
2
|
+
|
|
3
|
+
export const enum SerovalConstant {
|
|
4
|
+
Null = 0,
|
|
5
|
+
Undefined = 1,
|
|
6
|
+
True = 2,
|
|
7
|
+
False = 3,
|
|
8
|
+
NegativeZero = 4,
|
|
9
|
+
Infinity = 5,
|
|
10
|
+
NegativeInfinity = 6,
|
|
11
|
+
NaN = 7,
|
|
12
|
+
}
|
|
2
13
|
|
|
3
14
|
export const enum SerovalNodeType {
|
|
4
|
-
Number,
|
|
5
|
-
String,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
ArrayBuffer,
|
|
33
|
-
DataView,
|
|
34
|
-
Blob,
|
|
35
|
-
File,
|
|
36
|
-
Headers,
|
|
37
|
-
FormData,
|
|
15
|
+
Number = 0,
|
|
16
|
+
String = 1,
|
|
17
|
+
Constant = 2,
|
|
18
|
+
BigInt = 3,
|
|
19
|
+
IndexedValue = 4,
|
|
20
|
+
Date = 5,
|
|
21
|
+
RegExp = 6,
|
|
22
|
+
Set = 7,
|
|
23
|
+
Map = 8,
|
|
24
|
+
Array = 9,
|
|
25
|
+
Object = 10,
|
|
26
|
+
NullConstructor = 11,
|
|
27
|
+
Promise = 12,
|
|
28
|
+
Error = 13,
|
|
29
|
+
AggregateError = 14,
|
|
30
|
+
TypedArray = 15,
|
|
31
|
+
BigIntTypedArray = 16,
|
|
32
|
+
WKSymbol = 17,
|
|
33
|
+
URL = 18,
|
|
34
|
+
URLSearchParams = 19,
|
|
35
|
+
Reference = 20,
|
|
36
|
+
ArrayBuffer = 21,
|
|
37
|
+
DataView = 22,
|
|
38
|
+
Blob = 23,
|
|
39
|
+
File = 24,
|
|
40
|
+
Headers = 25,
|
|
41
|
+
FormData = 26,
|
|
42
|
+
Boxed = 27,
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export interface SerovalBaseNode {
|
|
@@ -43,7 +48,7 @@ export interface SerovalBaseNode {
|
|
|
43
48
|
// Reference ID
|
|
44
49
|
i: number | undefined;
|
|
45
50
|
// Serialized value
|
|
46
|
-
s:
|
|
51
|
+
s: unknown;
|
|
47
52
|
// size/length
|
|
48
53
|
l: number | undefined;
|
|
49
54
|
// Constructor name / RegExp source
|
|
@@ -51,31 +56,41 @@ export interface SerovalBaseNode {
|
|
|
51
56
|
// message/flags
|
|
52
57
|
m: string | undefined;
|
|
53
58
|
// dictionary
|
|
54
|
-
d:
|
|
59
|
+
d: SerovalObjectRecordNode | SerovalMapRecordNode | undefined;
|
|
55
60
|
// array of nodes
|
|
56
|
-
a: SerovalNode[] | undefined;
|
|
61
|
+
a: (SerovalNode | undefined)[] | undefined;
|
|
57
62
|
// fulfilled node
|
|
58
63
|
f: SerovalNode | undefined;
|
|
59
64
|
// byte offset
|
|
60
65
|
b: number | undefined;
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
export
|
|
68
|
+
export const enum SerovalObjectRecordSpecialKey {
|
|
69
|
+
SymbolIterator = 0,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type SerovalObjectRecordKey =
|
|
73
|
+
| string
|
|
74
|
+
| SerovalObjectRecordSpecialKey;
|
|
75
|
+
|
|
76
|
+
export interface SerovalPlainRecordNode {
|
|
64
77
|
k: string[];
|
|
65
78
|
v: SerovalNode[];
|
|
66
79
|
s: number;
|
|
67
80
|
}
|
|
68
81
|
|
|
82
|
+
export interface SerovalObjectRecordNode {
|
|
83
|
+
k: SerovalObjectRecordKey[];
|
|
84
|
+
v: SerovalNode[];
|
|
85
|
+
s: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
export interface SerovalMapRecordNode {
|
|
70
89
|
k: SerovalNode[];
|
|
71
90
|
v: SerovalNode[];
|
|
72
91
|
s: number;
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
export type SerovalDictionaryNode =
|
|
76
|
-
| SerovalObjectRecordNode
|
|
77
|
-
| SerovalMapRecordNode;
|
|
78
|
-
|
|
79
94
|
export interface SerovalNumberNode extends SerovalBaseNode {
|
|
80
95
|
t: SerovalNodeType.Number;
|
|
81
96
|
s: number;
|
|
@@ -86,45 +101,15 @@ export interface SerovalStringNode extends SerovalBaseNode {
|
|
|
86
101
|
s: string;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
export interface
|
|
90
|
-
t: SerovalNodeType.
|
|
91
|
-
s:
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface SerovalNullNode extends SerovalBaseNode {
|
|
95
|
-
t: SerovalNodeType.Null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface SerovalUndefinedNode extends SerovalBaseNode {
|
|
99
|
-
t: SerovalNodeType.Undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface SerovalNegativeZeroNode extends SerovalBaseNode {
|
|
103
|
-
t: SerovalNodeType.NegativeZero;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface SerovalInfinityNode extends SerovalBaseNode {
|
|
107
|
-
t: SerovalNodeType.Infinity;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface SerovalNegativeInfinityNode extends SerovalBaseNode {
|
|
111
|
-
t: SerovalNodeType.NegativeInfinity;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface SerovalNaNNode extends SerovalBaseNode {
|
|
115
|
-
t: SerovalNodeType.NaN;
|
|
104
|
+
export interface SerovalConstantNode extends SerovalBaseNode {
|
|
105
|
+
t: SerovalNodeType.Constant;
|
|
106
|
+
s: SerovalConstant;
|
|
116
107
|
}
|
|
117
108
|
|
|
118
109
|
export type SerovalPrimitiveNode =
|
|
119
110
|
| SerovalNumberNode
|
|
120
111
|
| SerovalStringNode
|
|
121
|
-
|
|
|
122
|
-
| SerovalNullNode
|
|
123
|
-
| SerovalUndefinedNode
|
|
124
|
-
| SerovalNegativeZeroNode
|
|
125
|
-
| SerovalNegativeInfinityNode
|
|
126
|
-
| SerovalInfinityNode
|
|
127
|
-
| SerovalNaNNode;
|
|
112
|
+
| SerovalConstantNode;
|
|
128
113
|
|
|
129
114
|
export interface SerovalIndexedValueNode extends SerovalBaseNode {
|
|
130
115
|
t: SerovalNodeType.IndexedValue;
|
|
@@ -220,7 +205,7 @@ export interface SerovalArrayNode extends SerovalBaseNode {
|
|
|
220
205
|
// size of array
|
|
221
206
|
l: number;
|
|
222
207
|
// items
|
|
223
|
-
a: SerovalNode[];
|
|
208
|
+
a: (SerovalNode | undefined)[];
|
|
224
209
|
i: number;
|
|
225
210
|
}
|
|
226
211
|
|
|
@@ -265,19 +250,9 @@ export interface SerovalAggregateErrorNode extends SerovalBaseNode {
|
|
|
265
250
|
d: SerovalObjectRecordNode | undefined;
|
|
266
251
|
}
|
|
267
252
|
|
|
268
|
-
export interface SerovalIterableNode extends SerovalBaseNode {
|
|
269
|
-
t: SerovalNodeType.Iterable;
|
|
270
|
-
// other properties
|
|
271
|
-
d: SerovalObjectRecordNode | undefined;
|
|
272
|
-
// number of emitted items
|
|
273
|
-
l: number;
|
|
274
|
-
// array of items
|
|
275
|
-
a: SerovalNode[];
|
|
276
|
-
i: number;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
253
|
export interface SerovalWKSymbolNode extends SerovalBaseNode {
|
|
280
254
|
t: SerovalNodeType.WKSymbol;
|
|
255
|
+
i: number;
|
|
281
256
|
s: Symbols;
|
|
282
257
|
}
|
|
283
258
|
|
|
@@ -338,13 +313,19 @@ export interface SerovalFileNode extends SerovalBaseNode {
|
|
|
338
313
|
export interface SerovalHeadersNode extends SerovalBaseNode {
|
|
339
314
|
t: SerovalNodeType.Headers;
|
|
340
315
|
i: number;
|
|
341
|
-
d:
|
|
316
|
+
d: SerovalPlainRecordNode;
|
|
342
317
|
}
|
|
343
318
|
|
|
344
319
|
export interface SerovalFormDataNode extends SerovalBaseNode {
|
|
345
320
|
t: SerovalNodeType.FormData;
|
|
346
321
|
i: number;
|
|
347
|
-
d:
|
|
322
|
+
d: SerovalPlainRecordNode;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface SerovalBoxedNode extends SerovalBaseNode {
|
|
326
|
+
t: SerovalNodeType.Boxed;
|
|
327
|
+
i: number;
|
|
328
|
+
f: SerovalNode;
|
|
348
329
|
}
|
|
349
330
|
|
|
350
331
|
export type SerovalNode =
|
|
@@ -359,7 +340,6 @@ export type SerovalNode =
|
|
|
359
340
|
| SerovalPromiseNode
|
|
360
341
|
| SerovalErrorNode
|
|
361
342
|
| SerovalAggregateErrorNode
|
|
362
|
-
| SerovalIterableNode
|
|
363
343
|
| SerovalWKSymbolNode
|
|
364
344
|
| SerovalURLNode
|
|
365
345
|
| SerovalURLSearchParamsNode
|
|
@@ -369,4 +349,5 @@ export type SerovalNode =
|
|
|
369
349
|
| SerovalBlobNode
|
|
370
350
|
| SerovalFileNode
|
|
371
351
|
| SerovalHeadersNode
|
|
372
|
-
| SerovalFormDataNode
|
|
352
|
+
| SerovalFormDataNode
|
|
353
|
+
| SerovalBoxedNode;
|
package/src/tree/web-api.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import assert from '../assert';
|
|
2
2
|
import { Feature } from '../compat';
|
|
3
|
-
import { ParserContext } from '../context';
|
|
3
|
+
import type { ParserContext } from '../context';
|
|
4
4
|
import { serializeString } from '../string';
|
|
5
|
+
import UnsupportedTypeError from './UnsupportedTypeError';
|
|
5
6
|
import { serializeArrayBuffer } from './primitives';
|
|
6
|
-
import {
|
|
7
|
+
import type {
|
|
7
8
|
SerovalBlobNode,
|
|
8
9
|
SerovalFileNode,
|
|
9
|
-
SerovalNodeType,
|
|
10
10
|
SerovalURLNode,
|
|
11
11
|
SerovalURLSearchParamsNode,
|
|
12
12
|
} from './types';
|
|
13
|
+
import {
|
|
14
|
+
SerovalNodeType,
|
|
15
|
+
} from './types';
|
|
13
16
|
|
|
14
17
|
export function createURLNode(
|
|
15
18
|
ctx: ParserContext,
|
|
16
19
|
id: number,
|
|
17
20
|
current: URL,
|
|
18
21
|
): SerovalURLNode {
|
|
19
|
-
assert(ctx.features & Feature.WebAPI,
|
|
22
|
+
assert(ctx.features & Feature.WebAPI, new UnsupportedTypeError(current));
|
|
20
23
|
return {
|
|
21
24
|
t: SerovalNodeType.URL,
|
|
22
25
|
i: id,
|
|
@@ -36,7 +39,7 @@ export function createURLSearchParamsNode(
|
|
|
36
39
|
id: number,
|
|
37
40
|
current: URLSearchParams,
|
|
38
41
|
): SerovalURLSearchParamsNode {
|
|
39
|
-
assert(ctx.features & Feature.WebAPI,
|
|
42
|
+
assert(ctx.features & Feature.WebAPI, new UnsupportedTypeError(current));
|
|
40
43
|
return {
|
|
41
44
|
t: SerovalNodeType.URLSearchParams,
|
|
42
45
|
i: id,
|
|
@@ -56,7 +59,7 @@ export async function createBlobNode(
|
|
|
56
59
|
id: number,
|
|
57
60
|
current: Blob,
|
|
58
61
|
): Promise<SerovalBlobNode> {
|
|
59
|
-
assert(ctx.features & Feature.WebAPI,
|
|
62
|
+
assert(ctx.features & Feature.WebAPI, new UnsupportedTypeError(current));
|
|
60
63
|
return {
|
|
61
64
|
t: SerovalNodeType.Blob,
|
|
62
65
|
i: id,
|
|
@@ -76,7 +79,7 @@ export async function createFileNode(
|
|
|
76
79
|
id: number,
|
|
77
80
|
current: File,
|
|
78
81
|
): Promise<SerovalFileNode> {
|
|
79
|
-
assert(ctx.features & Feature.WebAPI,
|
|
82
|
+
assert(ctx.features & Feature.WebAPI, new UnsupportedTypeError(current));
|
|
80
83
|
return {
|
|
81
84
|
t: SerovalNodeType.File,
|
|
82
85
|
i: id,
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WellKnownSymbols } from './tree/symbols';
|
|
1
|
+
import type { WellKnownSymbols } from './tree/symbols';
|
|
2
2
|
|
|
3
3
|
// Values that are non-recursive
|
|
4
4
|
export type PrimitiveValue =
|
|
@@ -36,11 +36,15 @@ export type BigIntTypedArrayValue =
|
|
|
36
36
|
|
|
37
37
|
export type WebAPIValue =
|
|
38
38
|
| URL
|
|
39
|
-
| URLSearchParams
|
|
39
|
+
| URLSearchParams
|
|
40
|
+
| Blob
|
|
41
|
+
| File;
|
|
40
42
|
|
|
41
43
|
export type SemiPrimitiveValue =
|
|
42
44
|
| RegExp
|
|
43
45
|
| Date
|
|
46
|
+
| ArrayBuffer
|
|
47
|
+
| DataView
|
|
44
48
|
| TypedArrayValue
|
|
45
49
|
| BigIntTypedArrayValue
|
|
46
50
|
| bigint
|
|
@@ -70,7 +74,7 @@ export type AsyncServerValue =
|
|
|
70
74
|
| { readonly [key: string | number]: AsyncServerValue }
|
|
71
75
|
| Set<AsyncServerValue>
|
|
72
76
|
| Map<AsyncServerValue, AsyncServerValue>
|
|
73
|
-
|
|
|
77
|
+
| Promise<AsyncServerValue>;
|
|
74
78
|
|
|
75
79
|
export type NonPrimitiveServerValue<T> =
|
|
76
80
|
T extends PrimitiveValue
|