seroval 0.15.1 → 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/README.md +3 -3
- package/dist/cjs/development/index.cjs +1221 -1867
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1222 -1868
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/Serializer.d.ts +2 -1
- package/dist/types/core/Serializer.d.ts.map +1 -1
- package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
- package/dist/types/core/base-primitives.d.ts +6 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +5 -13
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +17 -29
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +6 -16
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +2 -11
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +10 -10
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +5 -7
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +19 -4
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +11 -25
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/async.d.ts.map +1 -1
- package/dist/types/core/cross/deserializer.d.ts.map +1 -1
- package/dist/types/core/cross/index.d.ts.map +1 -1
- package/dist/types/core/cross/parser.d.ts.map +1 -1
- package/dist/types/core/cross/serializer.d.ts +1 -1
- package/dist/types/core/cross/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/stream.d.ts.map +1 -1
- package/dist/types/core/cross/sync.d.ts.map +1 -1
- package/dist/types/core/keys.d.ts.map +1 -1
- package/dist/types/core/literals.d.ts.map +1 -1
- package/dist/types/core/plugin.d.ts +21 -0
- package/dist/types/core/plugin.d.ts.map +1 -1
- package/dist/types/core/reference.d.ts.map +1 -1
- package/dist/types/core/special-reference.d.ts +4 -9
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/stream.d.ts +18 -0
- package/dist/types/core/stream.d.ts.map +1 -0
- package/dist/types/core/string.d.ts.map +1 -1
- package/dist/types/core/tree/async.d.ts.map +1 -1
- package/dist/types/core/tree/deserializer.d.ts.map +1 -1
- package/dist/types/core/tree/index.d.ts +1 -1
- package/dist/types/core/tree/index.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +3 -11
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +28 -122
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/utils/deferred.d.ts +0 -7
- package/dist/types/core/utils/deferred.d.ts.map +1 -1
- package/dist/types/core/utils/error.d.ts +2 -1
- package/dist/types/core/utils/error.d.ts.map +1 -1
- package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
- package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
- package/dist/types/core/utils/typed-array.d.ts +2 -0
- package/dist/types/core/utils/typed-array.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/core/Serializer.ts +44 -28
- package/src/core/UnsupportedTypeError.ts +2 -3
- package/src/core/base-primitives.ts +124 -38
- package/src/core/compat.ts +5 -14
- package/src/core/constants.ts +28 -39
- package/src/core/context/deserializer.ts +122 -308
- package/src/core/context/parser/async.ts +163 -375
- package/src/core/context/parser/stream.ts +109 -367
- package/src/core/context/parser/sync.ts +139 -266
- package/src/core/context/parser.ts +93 -68
- package/src/core/context/serializer.ts +370 -439
- package/src/core/cross/async.ts +1 -1
- package/src/core/cross/deserializer.ts +1 -4
- package/src/core/cross/index.ts +26 -20
- package/src/core/cross/parser.ts +1 -1
- package/src/core/cross/serializer.ts +30 -20
- package/src/core/cross/stream.ts +1 -1
- package/src/core/cross/sync.ts +1 -1
- package/src/core/keys.ts +3 -1
- package/src/core/literals.ts +22 -8
- package/src/core/plugin.ts +48 -10
- package/src/core/reference.ts +4 -5
- package/src/core/special-reference.ts +5 -15
- package/src/core/stream.ts +205 -0
- package/src/core/string.ts +53 -22
- package/src/core/tree/async.ts +1 -1
- package/src/core/tree/deserializer.ts +4 -9
- package/src/core/tree/index.ts +15 -10
- package/src/core/tree/serializer.ts +6 -50
- package/src/core/types.ts +39 -179
- package/src/core/utils/deferred.ts +0 -27
- package/src/core/utils/error.ts +26 -15
- package/src/core/utils/get-identifier.ts +5 -4
- package/src/core/utils/is-valid-identifier.ts +6 -5
- package/src/core/utils/iterator-to-sequence.ts +0 -174
- package/src/core/utils/typed-array.ts +35 -11
- package/src/index.ts +3 -12
- package/dist/types/core/utils/constructors.d.ts +0 -5
- package/dist/types/core/utils/constructors.d.ts.map +0 -1
- package/dist/types/core/web-api.d.ts +0 -8
- package/dist/types/core/web-api.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -21
- package/dist/types/types.d.ts.map +0 -1
- package/src/core/utils/constructors.ts +0 -49
- package/src/core/web-api.ts +0 -138
- package/src/example.ts +0 -25
- package/src/types.ts +0 -84
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import type { BigIntTypedArrayValue, TypedArrayValue } from '../../../types';
|
|
2
|
-
import UnsupportedTypeError from '../../UnsupportedTypeError';
|
|
3
1
|
import {
|
|
4
|
-
createArrayBufferNode,
|
|
5
2
|
createAsyncIteratorFactoryInstanceNode,
|
|
6
|
-
createDateNode,
|
|
7
3
|
createIteratorFactoryInstanceNode,
|
|
8
4
|
createPluginNode,
|
|
9
|
-
|
|
5
|
+
createStreamConstructorNode,
|
|
6
|
+
createStreamNextNode,
|
|
7
|
+
createStreamReturnNode,
|
|
8
|
+
createStreamThrowNode,
|
|
10
9
|
createStringNode,
|
|
11
10
|
} from '../../base-primitives';
|
|
12
11
|
import type { BaseSyncParserContextOptions } from './sync';
|
|
13
12
|
import BaseSyncParserContext from './sync';
|
|
14
|
-
import { BIGINT_FLAG, Feature } from '../../compat';
|
|
15
13
|
import { SerovalNodeType } from '../../constants';
|
|
16
|
-
import {
|
|
17
|
-
import { FALSE_NODE, NULL_NODE, TRUE_NODE } from '../../literals';
|
|
14
|
+
import { FALSE_NODE, TRUE_NODE } from '../../literals';
|
|
18
15
|
import { serializeString } from '../../string';
|
|
19
16
|
import type {
|
|
20
17
|
SerovalNode,
|
|
@@ -22,15 +19,14 @@ import type {
|
|
|
22
19
|
SerovalObjectRecordNode,
|
|
23
20
|
SerovalPluginNode,
|
|
24
21
|
SerovalPromiseConstructorNode,
|
|
25
|
-
SerovalReadableStreamConstructorNode,
|
|
26
|
-
SerovalRequestNode,
|
|
27
|
-
SerovalResponseNode,
|
|
28
22
|
} from '../../types';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
23
|
+
import { iteratorToSequence } from '../../utils/iterator-to-sequence';
|
|
24
|
+
import { SpecialReference } from '../../special-reference';
|
|
25
|
+
import type { Stream } from '../../stream';
|
|
26
|
+
import { createStreamFromAsyncIterable } from '../../stream';
|
|
32
27
|
|
|
33
|
-
export interface BaseStreamParserContextOptions
|
|
28
|
+
export interface BaseStreamParserContextOptions
|
|
29
|
+
extends BaseSyncParserContextOptions {
|
|
34
30
|
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
35
31
|
onError?: (error: unknown) => void;
|
|
36
32
|
onDone?: () => void;
|
|
@@ -56,7 +52,11 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
56
52
|
this.onDoneCallback = options.onDone;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
private
|
|
55
|
+
private initial = true;
|
|
56
|
+
|
|
57
|
+
private buffer: SerovalNode[] = [];
|
|
58
|
+
|
|
59
|
+
private onParseInternal(node: SerovalNode, initial: boolean): void {
|
|
60
60
|
try {
|
|
61
61
|
this.onParseCallback(node, initial);
|
|
62
62
|
} catch (error) {
|
|
@@ -64,6 +64,20 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
private flush(): void {
|
|
68
|
+
for (let i = 0, len = this.buffer.length; i < len; i++) {
|
|
69
|
+
this.onParseInternal(this.buffer[i], false);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private onParse(node: SerovalNode): void {
|
|
74
|
+
if (this.initial) {
|
|
75
|
+
this.buffer.push(node);
|
|
76
|
+
} else {
|
|
77
|
+
this.onParseInternal(node, false);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
private onError(error: unknown): void {
|
|
68
82
|
if (this.onErrorCallback) {
|
|
69
83
|
this.onErrorCallback(error);
|
|
@@ -78,18 +92,11 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
|
|
82
|
-
this.onParse(
|
|
83
|
-
this.parse(value),
|
|
84
|
-
false,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
pushPendingState(): void {
|
|
95
|
+
private pushPendingState(): void {
|
|
89
96
|
this.pending++;
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
popPendingState(): void {
|
|
99
|
+
private popPendingState(): void {
|
|
93
100
|
if (--this.pending <= 0) {
|
|
94
101
|
this.onDone();
|
|
95
102
|
}
|
|
@@ -101,57 +108,46 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
101
108
|
const entries = Object.entries(properties);
|
|
102
109
|
const keyNodes: SerovalObjectRecordKey[] = [];
|
|
103
110
|
const valueNodes: SerovalNode[] = [];
|
|
104
|
-
for (
|
|
105
|
-
let i = 0, len = entries.length;
|
|
106
|
-
i < len;
|
|
107
|
-
i++
|
|
108
|
-
) {
|
|
111
|
+
for (let i = 0, len = entries.length; i < len; i++) {
|
|
109
112
|
keyNodes.push(serializeString(entries[i][0]));
|
|
110
113
|
valueNodes.push(this.parse(entries[i][1]));
|
|
111
114
|
}
|
|
112
115
|
// Check special properties, symbols in this case
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.parseIteratorFactory(),
|
|
122
|
-
this.parse(
|
|
123
|
-
iteratorToSequence(properties as unknown as Iterable<unknown>),
|
|
124
|
-
),
|
|
116
|
+
let symbol = Symbol.iterator;
|
|
117
|
+
if (symbol in properties) {
|
|
118
|
+
keyNodes.push(this.parseWellKnownSymbol(symbol));
|
|
119
|
+
valueNodes.push(
|
|
120
|
+
createIteratorFactoryInstanceNode(
|
|
121
|
+
this.parseIteratorFactory(),
|
|
122
|
+
this.parse(
|
|
123
|
+
iteratorToSequence(properties as unknown as Iterable<unknown>),
|
|
125
124
|
),
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
properties as unknown as AsyncIterable<unknown>,
|
|
139
|
-
this,
|
|
140
|
-
),
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
symbol = Symbol.asyncIterator;
|
|
129
|
+
if (symbol in properties) {
|
|
130
|
+
keyNodes.push(this.parseWellKnownSymbol(symbol));
|
|
131
|
+
valueNodes.push(
|
|
132
|
+
createAsyncIteratorFactoryInstanceNode(
|
|
133
|
+
this.parseAsyncIteratorFactory(),
|
|
134
|
+
this.parse(
|
|
135
|
+
createStreamFromAsyncIterable(
|
|
136
|
+
properties as unknown as AsyncIterable<unknown>,
|
|
141
137
|
),
|
|
142
138
|
),
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
symbol = Symbol.toStringTag;
|
|
143
|
+
if (symbol in properties) {
|
|
144
|
+
keyNodes.push(this.parseWellKnownSymbol(symbol));
|
|
145
|
+
valueNodes.push(createStringNode(properties[symbol] as string));
|
|
146
|
+
}
|
|
147
|
+
symbol = Symbol.isConcatSpreadable;
|
|
148
|
+
if (symbol in properties) {
|
|
149
|
+
keyNodes.push(this.parseWellKnownSymbol(symbol));
|
|
150
|
+
valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
|
|
155
151
|
}
|
|
156
152
|
return {
|
|
157
153
|
k: keyNodes,
|
|
@@ -160,159 +156,12 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
160
156
|
};
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
id: number,
|
|
165
|
-
reader: ReadableStreamDefaultReader,
|
|
166
|
-
): void {
|
|
167
|
-
reader.read().then(
|
|
168
|
-
(data) => {
|
|
169
|
-
if (this.alive) {
|
|
170
|
-
if (data.done) {
|
|
171
|
-
this.onParse({
|
|
172
|
-
t: SerovalNodeType.ReadableStreamClose,
|
|
173
|
-
i: id,
|
|
174
|
-
s: undefined,
|
|
175
|
-
l: undefined,
|
|
176
|
-
c: undefined,
|
|
177
|
-
m: undefined,
|
|
178
|
-
p: undefined,
|
|
179
|
-
e: undefined,
|
|
180
|
-
a: undefined,
|
|
181
|
-
f: this.parseSpecialReference(SpecialReference.ReadableStreamClose),
|
|
182
|
-
b: undefined,
|
|
183
|
-
o: undefined,
|
|
184
|
-
}, false);
|
|
185
|
-
this.popPendingState();
|
|
186
|
-
} else {
|
|
187
|
-
const parsed = this.parseWithError(data.value);
|
|
188
|
-
if (parsed) {
|
|
189
|
-
this.onParse({
|
|
190
|
-
t: SerovalNodeType.ReadableStreamEnqueue,
|
|
191
|
-
i: id,
|
|
192
|
-
s: undefined,
|
|
193
|
-
l: undefined,
|
|
194
|
-
c: undefined,
|
|
195
|
-
m: undefined,
|
|
196
|
-
p: undefined,
|
|
197
|
-
e: undefined,
|
|
198
|
-
a: [
|
|
199
|
-
this.parseSpecialReference(SpecialReference.ReadableStreamEnqueue),
|
|
200
|
-
parsed,
|
|
201
|
-
],
|
|
202
|
-
f: undefined,
|
|
203
|
-
b: undefined,
|
|
204
|
-
o: undefined,
|
|
205
|
-
}, false);
|
|
206
|
-
this.pushReadableStreamReader(id, reader);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
(value) => {
|
|
212
|
-
if (this.alive) {
|
|
213
|
-
const parsed = this.parseWithError(value);
|
|
214
|
-
if (parsed) {
|
|
215
|
-
this.onParse({
|
|
216
|
-
t: SerovalNodeType.ReadableStreamError,
|
|
217
|
-
i: id,
|
|
218
|
-
s: undefined,
|
|
219
|
-
l: undefined,
|
|
220
|
-
c: undefined,
|
|
221
|
-
m: undefined,
|
|
222
|
-
p: undefined,
|
|
223
|
-
e: undefined,
|
|
224
|
-
a: [
|
|
225
|
-
this.parseSpecialReference(SpecialReference.ReadableStreamError),
|
|
226
|
-
parsed,
|
|
227
|
-
],
|
|
228
|
-
f: undefined,
|
|
229
|
-
b: undefined,
|
|
230
|
-
o: undefined,
|
|
231
|
-
}, false);
|
|
232
|
-
}
|
|
233
|
-
this.popPendingState();
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
private parseReadableStream(
|
|
240
|
-
id: number,
|
|
241
|
-
current: ReadableStream<unknown>,
|
|
242
|
-
): SerovalReadableStreamConstructorNode {
|
|
243
|
-
const reader = current.getReader();
|
|
244
|
-
this.pushPendingState();
|
|
245
|
-
this.pushReadableStreamReader(id, reader);
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
t: SerovalNodeType.ReadableStreamConstructor,
|
|
249
|
-
i: id,
|
|
250
|
-
s: undefined,
|
|
251
|
-
l: undefined,
|
|
252
|
-
c: undefined,
|
|
253
|
-
m: undefined,
|
|
254
|
-
p: undefined,
|
|
255
|
-
e: undefined,
|
|
256
|
-
a: undefined,
|
|
257
|
-
f: this.parseSpecialReference(SpecialReference.ReadableStreamConstructor),
|
|
258
|
-
b: undefined,
|
|
259
|
-
o: undefined,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private parseRequest(
|
|
264
|
-
id: number,
|
|
265
|
-
current: Request,
|
|
266
|
-
): SerovalRequestNode {
|
|
267
|
-
return {
|
|
268
|
-
t: SerovalNodeType.Request,
|
|
269
|
-
i: id,
|
|
270
|
-
s: serializeString(current.url),
|
|
271
|
-
l: undefined,
|
|
272
|
-
c: undefined,
|
|
273
|
-
m: undefined,
|
|
274
|
-
p: undefined,
|
|
275
|
-
e: undefined,
|
|
276
|
-
f: this.parse(
|
|
277
|
-
createRequestOptions(current, current.clone().body),
|
|
278
|
-
),
|
|
279
|
-
a: undefined,
|
|
280
|
-
b: undefined,
|
|
281
|
-
o: undefined,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private parseResponse(
|
|
286
|
-
id: number,
|
|
287
|
-
current: Response,
|
|
288
|
-
): SerovalResponseNode {
|
|
289
|
-
return {
|
|
290
|
-
t: SerovalNodeType.Response,
|
|
291
|
-
i: id,
|
|
292
|
-
s: undefined,
|
|
293
|
-
l: undefined,
|
|
294
|
-
c: undefined,
|
|
295
|
-
m: undefined,
|
|
296
|
-
p: undefined,
|
|
297
|
-
e: undefined,
|
|
298
|
-
f: undefined,
|
|
299
|
-
a: [
|
|
300
|
-
current.body
|
|
301
|
-
? this.parse(current.clone().body)
|
|
302
|
-
: NULL_NODE,
|
|
303
|
-
this.parse(createResponseOptions(current)),
|
|
304
|
-
],
|
|
305
|
-
b: undefined,
|
|
306
|
-
o: undefined,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
private parsePromise(
|
|
159
|
+
protected parsePromise(
|
|
311
160
|
id: number,
|
|
312
161
|
current: Promise<unknown>,
|
|
313
162
|
): SerovalPromiseConstructorNode {
|
|
314
163
|
current.then(
|
|
315
|
-
|
|
164
|
+
data => {
|
|
316
165
|
const parsed = this.parseWithError(data);
|
|
317
166
|
if (parsed) {
|
|
318
167
|
this.onParse({
|
|
@@ -331,11 +180,11 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
331
180
|
f: undefined,
|
|
332
181
|
b: undefined,
|
|
333
182
|
o: undefined,
|
|
334
|
-
}
|
|
183
|
+
});
|
|
335
184
|
}
|
|
336
185
|
this.popPendingState();
|
|
337
186
|
},
|
|
338
|
-
|
|
187
|
+
data => {
|
|
339
188
|
if (this.alive) {
|
|
340
189
|
const parsed = this.parseWithError(data);
|
|
341
190
|
if (parsed) {
|
|
@@ -355,7 +204,7 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
355
204
|
f: undefined,
|
|
356
205
|
b: undefined,
|
|
357
206
|
o: undefined,
|
|
358
|
-
}
|
|
207
|
+
});
|
|
359
208
|
}
|
|
360
209
|
}
|
|
361
210
|
this.popPendingState();
|
|
@@ -400,151 +249,42 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
400
249
|
return undefined;
|
|
401
250
|
}
|
|
402
251
|
|
|
403
|
-
protected
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
case BigInt:
|
|
440
|
-
return this.parseBoxed(id, current);
|
|
441
|
-
default:
|
|
442
|
-
break;
|
|
443
|
-
}
|
|
444
|
-
const currentFeatures = this.features;
|
|
445
|
-
// Promises
|
|
446
|
-
if (
|
|
447
|
-
(currentFeatures & Feature.Promise)
|
|
448
|
-
&& (currentClass === Promise || current instanceof Promise)
|
|
449
|
-
) {
|
|
450
|
-
return this.parsePromise(id, current as unknown as Promise<unknown>);
|
|
451
|
-
}
|
|
452
|
-
// Typed Arrays
|
|
453
|
-
if (currentFeatures & Feature.TypedArray) {
|
|
454
|
-
switch (currentClass) {
|
|
455
|
-
case ArrayBuffer:
|
|
456
|
-
return createArrayBufferNode(id, current as unknown as ArrayBuffer);
|
|
457
|
-
case Int8Array:
|
|
458
|
-
case Int16Array:
|
|
459
|
-
case Int32Array:
|
|
460
|
-
case Uint8Array:
|
|
461
|
-
case Uint16Array:
|
|
462
|
-
case Uint32Array:
|
|
463
|
-
case Uint8ClampedArray:
|
|
464
|
-
case Float32Array:
|
|
465
|
-
case Float64Array:
|
|
466
|
-
return this.parseTypedArray(id, current as unknown as TypedArrayValue);
|
|
467
|
-
case DataView:
|
|
468
|
-
return this.parseDataView(id, current as unknown as DataView);
|
|
469
|
-
default:
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
// BigInt Typed Arrays
|
|
474
|
-
if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
|
|
475
|
-
switch (currentClass) {
|
|
476
|
-
case BigInt64Array:
|
|
477
|
-
case BigUint64Array:
|
|
478
|
-
return this.parseBigIntTypedArray(id, current as unknown as BigIntTypedArrayValue);
|
|
479
|
-
default:
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
// ES Collection
|
|
484
|
-
if (currentFeatures & Feature.Map && currentClass === Map) {
|
|
485
|
-
return this.parseMap(
|
|
486
|
-
id,
|
|
487
|
-
current as unknown as Map<unknown, unknown>,
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
if (currentFeatures & Feature.Set && currentClass === Set) {
|
|
491
|
-
return this.parseSet(
|
|
492
|
-
id,
|
|
493
|
-
current as unknown as Set<unknown>,
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
// Web APIs
|
|
497
|
-
if (currentFeatures & Feature.WebAPI) {
|
|
498
|
-
switch (currentClass) {
|
|
499
|
-
case (typeof URL !== 'undefined' ? URL : UNIVERSAL_SENTINEL):
|
|
500
|
-
return createURLNode(id, current as unknown as URL);
|
|
501
|
-
case (typeof URLSearchParams !== 'undefined' ? URLSearchParams : UNIVERSAL_SENTINEL):
|
|
502
|
-
return createURLSearchParamsNode(id, current as unknown as URLSearchParams);
|
|
503
|
-
case (typeof Headers !== 'undefined' ? Headers : UNIVERSAL_SENTINEL):
|
|
504
|
-
return this.parseHeaders(id, current as unknown as Headers);
|
|
505
|
-
case (typeof FormData !== 'undefined' ? FormData : UNIVERSAL_SENTINEL):
|
|
506
|
-
return this.parseFormData(id, current as unknown as FormData);
|
|
507
|
-
case (typeof ReadableStream !== 'undefined' ? ReadableStream : UNIVERSAL_SENTINEL):
|
|
508
|
-
return this.parseReadableStream(id, current as unknown as ReadableStream);
|
|
509
|
-
case (typeof Request !== 'undefined' ? Request : UNIVERSAL_SENTINEL):
|
|
510
|
-
return this.parseRequest(id, current as unknown as Request);
|
|
511
|
-
case (typeof Response !== 'undefined' ? Response : UNIVERSAL_SENTINEL):
|
|
512
|
-
return this.parseResponse(id, current as unknown as Response);
|
|
513
|
-
case (typeof Event !== 'undefined' ? Event : UNIVERSAL_SENTINEL):
|
|
514
|
-
return this.parseEvent(id, current as unknown as Event);
|
|
515
|
-
case (typeof CustomEvent !== 'undefined' ? CustomEvent : UNIVERSAL_SENTINEL):
|
|
516
|
-
return this.parseCustomEvent(id, current as unknown as CustomEvent);
|
|
517
|
-
case (typeof DOMException !== 'undefined' ? DOMException : UNIVERSAL_SENTINEL):
|
|
518
|
-
return createDOMExceptionNode(id, current as unknown as DOMException);
|
|
519
|
-
default:
|
|
520
|
-
break;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
const parsed = this.parsePlugin(id, current);
|
|
524
|
-
if (parsed) {
|
|
525
|
-
return parsed;
|
|
526
|
-
}
|
|
527
|
-
if (
|
|
528
|
-
(currentFeatures & Feature.AggregateError)
|
|
529
|
-
&& typeof AggregateError !== 'undefined'
|
|
530
|
-
&& (currentClass === AggregateError || current instanceof AggregateError)
|
|
531
|
-
) {
|
|
532
|
-
return this.parseAggregateError(id, current as unknown as AggregateError);
|
|
533
|
-
}
|
|
534
|
-
// Slow path. We only need to handle Errors and Iterators
|
|
535
|
-
// since they have very broad implementations.
|
|
536
|
-
if (current instanceof Error) {
|
|
537
|
-
return this.parseError(id, current);
|
|
538
|
-
}
|
|
539
|
-
// Generator functions don't have a global constructor
|
|
540
|
-
// despite existing
|
|
541
|
-
if (
|
|
542
|
-
currentFeatures & Feature.Symbol
|
|
543
|
-
&& (Symbol.iterator in current || Symbol.asyncIterator in current)
|
|
544
|
-
) {
|
|
545
|
-
return this.parsePlainObject(id, current, !!currentClass);
|
|
546
|
-
}
|
|
547
|
-
throw new UnsupportedTypeError(current);
|
|
252
|
+
protected parseStream(id: number, current: Stream<unknown>): SerovalNode {
|
|
253
|
+
const result = createStreamConstructorNode(
|
|
254
|
+
id,
|
|
255
|
+
this.parseSpecialReference(SpecialReference.StreamConstructor),
|
|
256
|
+
[],
|
|
257
|
+
);
|
|
258
|
+
this.pushPendingState();
|
|
259
|
+
current.on({
|
|
260
|
+
next: value => {
|
|
261
|
+
if (this.alive) {
|
|
262
|
+
const parsed = this.parseWithError(value);
|
|
263
|
+
if (parsed) {
|
|
264
|
+
this.onParse(createStreamNextNode(id, parsed));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
throw: value => {
|
|
269
|
+
if (this.alive) {
|
|
270
|
+
const parsed = this.parseWithError(value);
|
|
271
|
+
if (parsed) {
|
|
272
|
+
this.onParse(createStreamThrowNode(id, parsed));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
this.popPendingState();
|
|
276
|
+
},
|
|
277
|
+
return: value => {
|
|
278
|
+
if (this.alive) {
|
|
279
|
+
const parsed = this.parseWithError(value);
|
|
280
|
+
if (parsed) {
|
|
281
|
+
this.onParse(createStreamReturnNode(id, parsed));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
this.popPendingState();
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
return result;
|
|
548
288
|
}
|
|
549
289
|
|
|
550
290
|
private parseWithError<T>(current: T): SerovalNode | undefined {
|
|
@@ -562,7 +302,9 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
|
|
|
562
302
|
start<T>(current: T): void {
|
|
563
303
|
const parsed = this.parseWithError(current);
|
|
564
304
|
if (parsed) {
|
|
565
|
-
this.
|
|
305
|
+
this.onParseInternal(parsed, true);
|
|
306
|
+
this.initial = false;
|
|
307
|
+
this.flush();
|
|
566
308
|
|
|
567
309
|
// Check if there's any pending pushes
|
|
568
310
|
if (this.pending <= 0) {
|