seroval 0.15.1 → 1.0.2

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.
Files changed (114) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/development/index.cjs +1287 -1945
  3. package/dist/cjs/development/index.cjs.map +3 -3
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +1288 -1946
  6. package/dist/esm/development/index.mjs.map +3 -3
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +2 -1
  9. package/dist/types/core/Serializer.d.ts.map +1 -1
  10. package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
  11. package/dist/types/core/base-primitives.d.ts +6 -2
  12. package/dist/types/core/base-primitives.d.ts.map +1 -1
  13. package/dist/types/core/compat.d.ts +5 -13
  14. package/dist/types/core/compat.d.ts.map +1 -1
  15. package/dist/types/core/constants.d.ts +17 -29
  16. package/dist/types/core/constants.d.ts.map +1 -1
  17. package/dist/types/core/context/deserializer.d.ts +6 -16
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser/async.d.ts +2 -11
  20. package/dist/types/core/context/parser/async.d.ts.map +1 -1
  21. package/dist/types/core/context/parser/stream.d.ts +10 -10
  22. package/dist/types/core/context/parser/stream.d.ts.map +1 -1
  23. package/dist/types/core/context/parser/sync.d.ts +5 -7
  24. package/dist/types/core/context/parser/sync.d.ts.map +1 -1
  25. package/dist/types/core/context/parser.d.ts +26 -5
  26. package/dist/types/core/context/parser.d.ts.map +1 -1
  27. package/dist/types/core/context/serializer.d.ts +21 -30
  28. package/dist/types/core/context/serializer.d.ts.map +1 -1
  29. package/dist/types/core/cross/async.d.ts.map +1 -1
  30. package/dist/types/core/cross/deserializer.d.ts.map +1 -1
  31. package/dist/types/core/cross/index.d.ts.map +1 -1
  32. package/dist/types/core/cross/parser.d.ts.map +1 -1
  33. package/dist/types/core/cross/serializer.d.ts +1 -1
  34. package/dist/types/core/cross/serializer.d.ts.map +1 -1
  35. package/dist/types/core/cross/stream.d.ts.map +1 -1
  36. package/dist/types/core/cross/sync.d.ts.map +1 -1
  37. package/dist/types/core/keys.d.ts.map +1 -1
  38. package/dist/types/core/literals.d.ts.map +1 -1
  39. package/dist/types/core/plugin.d.ts +21 -0
  40. package/dist/types/core/plugin.d.ts.map +1 -1
  41. package/dist/types/core/reference.d.ts.map +1 -1
  42. package/dist/types/core/special-reference.d.ts +4 -9
  43. package/dist/types/core/special-reference.d.ts.map +1 -1
  44. package/dist/types/core/stream.d.ts +18 -0
  45. package/dist/types/core/stream.d.ts.map +1 -0
  46. package/dist/types/core/string.d.ts.map +1 -1
  47. package/dist/types/core/tree/async.d.ts.map +1 -1
  48. package/dist/types/core/tree/deserializer.d.ts.map +1 -1
  49. package/dist/types/core/tree/index.d.ts +1 -1
  50. package/dist/types/core/tree/index.d.ts.map +1 -1
  51. package/dist/types/core/tree/serializer.d.ts +3 -11
  52. package/dist/types/core/tree/serializer.d.ts.map +1 -1
  53. package/dist/types/core/types.d.ts +28 -122
  54. package/dist/types/core/types.d.ts.map +1 -1
  55. package/dist/types/core/utils/deferred.d.ts +0 -7
  56. package/dist/types/core/utils/deferred.d.ts.map +1 -1
  57. package/dist/types/core/utils/error.d.ts +2 -1
  58. package/dist/types/core/utils/error.d.ts.map +1 -1
  59. package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
  60. package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
  61. package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
  62. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  63. package/dist/types/core/utils/typed-array.d.ts +2 -0
  64. package/dist/types/core/utils/typed-array.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +2 -3
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/package.json +7 -7
  68. package/src/core/Serializer.ts +44 -28
  69. package/src/core/UnsupportedTypeError.ts +2 -3
  70. package/src/core/base-primitives.ts +124 -38
  71. package/src/core/compat.ts +5 -14
  72. package/src/core/constants.ts +28 -39
  73. package/src/core/context/deserializer.ts +122 -308
  74. package/src/core/context/parser/async.ts +163 -375
  75. package/src/core/context/parser/stream.ts +110 -381
  76. package/src/core/context/parser/sync.ts +125 -266
  77. package/src/core/context/parser.ts +119 -68
  78. package/src/core/context/serializer.ts +396 -473
  79. package/src/core/cross/async.ts +1 -1
  80. package/src/core/cross/deserializer.ts +1 -4
  81. package/src/core/cross/index.ts +26 -20
  82. package/src/core/cross/parser.ts +1 -1
  83. package/src/core/cross/serializer.ts +30 -20
  84. package/src/core/cross/stream.ts +1 -1
  85. package/src/core/cross/sync.ts +1 -1
  86. package/src/core/keys.ts +3 -1
  87. package/src/core/literals.ts +22 -8
  88. package/src/core/plugin.ts +48 -10
  89. package/src/core/reference.ts +4 -5
  90. package/src/core/special-reference.ts +5 -15
  91. package/src/core/stream.ts +205 -0
  92. package/src/core/string.ts +53 -22
  93. package/src/core/tree/async.ts +1 -1
  94. package/src/core/tree/deserializer.ts +4 -9
  95. package/src/core/tree/index.ts +15 -10
  96. package/src/core/tree/serializer.ts +6 -50
  97. package/src/core/types.ts +39 -179
  98. package/src/core/utils/deferred.ts +0 -27
  99. package/src/core/utils/error.ts +26 -15
  100. package/src/core/utils/get-identifier.ts +5 -4
  101. package/src/core/utils/is-valid-identifier.ts +6 -5
  102. package/src/core/utils/iterator-to-sequence.ts +0 -174
  103. package/src/core/utils/typed-array.ts +35 -11
  104. package/src/index.ts +3 -12
  105. package/dist/types/core/utils/constructors.d.ts +0 -5
  106. package/dist/types/core/utils/constructors.d.ts.map +0 -1
  107. package/dist/types/core/web-api.d.ts +0 -8
  108. package/dist/types/core/web-api.d.ts.map +0 -1
  109. package/dist/types/types.d.ts +0 -21
  110. package/dist/types/types.d.ts.map +0 -1
  111. package/src/core/utils/constructors.ts +0 -49
  112. package/src/core/web-api.ts +0 -138
  113. package/src/example.ts +0 -25
  114. package/src/types.ts +0 -84
@@ -1,8 +1,4 @@
1
- /* eslint-disable prefer-destructuring */
2
- /* eslint-disable no-await-in-loop */
3
- import type { BigIntTypedArrayValue, TypedArrayValue } from '../../../types';
4
1
  import UnsupportedTypeError from '../../UnsupportedTypeError';
5
- import assert from '../../utils/assert';
6
2
  import {
7
3
  createPluginNode,
8
4
  createDateNode,
@@ -21,24 +17,20 @@ import {
21
17
  createAggregateErrorNode,
22
18
  createIteratorFactoryInstanceNode,
23
19
  createAsyncIteratorFactoryInstanceNode,
20
+ createStreamConstructorNode,
21
+ createStreamNextNode,
22
+ createStreamThrowNode,
23
+ createStreamReturnNode,
24
24
  } from '../../base-primitives';
25
- import { BIGINT_FLAG, Feature } from '../../compat';
26
- import {
27
- SerovalNodeType,
28
- } from '../../constants';
29
- import {
30
- createRequestOptions,
31
- createResponseOptions,
32
- createEventOptions,
33
- createCustomEventOptions,
34
- } from '../../utils/constructors';
25
+ import { Feature } from '../../compat';
26
+ import { SerovalNodeType } from '../../constants';
35
27
  import {
36
28
  NULL_NODE,
37
29
  TRUE_NODE,
38
30
  FALSE_NODE,
39
31
  UNDEFINED_NODE,
40
32
  } from '../../literals';
41
- import { asyncIteratorToSequence, iteratorToSequence, readableStreamToSequence } from '../../utils/iterator-to-sequence';
33
+ import { iteratorToSequence } from '../../utils/iterator-to-sequence';
42
34
  import { BaseParserContext } from '../parser';
43
35
  import promiseToResult from '../../utils/promise-to-result';
44
36
  import { getErrorOptions } from '../../utils/error';
@@ -56,30 +48,19 @@ import type {
56
48
  SerovalPromiseNode,
57
49
  SerovalTypedArrayNode,
58
50
  SerovalAggregateErrorNode,
59
- SerovalBlobNode,
60
- SerovalCustomEventNode,
61
- SerovalEventNode,
62
- SerovalFileNode,
63
- SerovalFormDataNode,
64
- SerovalHeadersNode,
65
51
  SerovalMapNode,
66
- SerovalPlainRecordNode,
67
52
  SerovalPluginNode,
68
- SerovalRequestNode,
69
- SerovalResponseNode,
70
53
  SerovalSetNode,
71
54
  SerovalDataViewNode,
72
- SerovalReadableStreamNode,
55
+ SerovalStreamConstructorNode,
73
56
  } from '../../types';
74
- import {
75
- createURLNode,
76
- createURLSearchParamsNode,
77
- createDOMExceptionNode,
78
- createEventNode,
79
- createCustomEventNode,
80
- createReadableStreamNode,
81
- } from '../../web-api';
82
- import { SpecialReference, UNIVERSAL_SENTINEL } from '../../special-reference';
57
+ import { SpecialReference } from '../../special-reference';
58
+ import type { Stream } from '../../stream';
59
+ import { createStreamFromAsyncIterable, isStream } from '../../stream';
60
+ import type {
61
+ BigIntTypedArrayValue,
62
+ TypedArrayValue,
63
+ } from '../../utils/typed-array';
83
64
 
84
65
  type ObjectLikeNode =
85
66
  | SerovalObjectNode
@@ -87,11 +68,10 @@ type ObjectLikeNode =
87
68
  | SerovalPromiseNode;
88
69
 
89
70
  export default abstract class BaseAsyncParserContext extends BaseParserContext {
90
- private async parseItems(
91
- current: unknown[],
92
- ): Promise<SerovalNode[]> {
71
+ private async parseItems(current: unknown[]): Promise<SerovalNode[]> {
93
72
  const nodes = [];
94
73
  for (let i = 0, len = current.length; i < len; i++) {
74
+ // For consistency in holes
95
75
  if (i in current) {
96
76
  nodes[i] = await this.parse(current[i]);
97
77
  }
@@ -103,11 +83,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
103
83
  id: number,
104
84
  current: unknown[],
105
85
  ): Promise<SerovalArrayNode> {
106
- return createArrayNode(
107
- id,
108
- current,
109
- await this.parseItems(current),
110
- );
86
+ return createArrayNode(id, current, await this.parseItems(current));
111
87
  }
112
88
 
113
89
  private async parseProperties(
@@ -116,54 +92,46 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
116
92
  const entries = Object.entries(properties);
117
93
  const keyNodes: SerovalObjectRecordKey[] = [];
118
94
  const valueNodes: SerovalNode[] = [];
119
- for (
120
- let i = 0, len = entries.length;
121
- i < len;
122
- i++
123
- ) {
95
+ for (let i = 0, len = entries.length; i < len; i++) {
124
96
  keyNodes.push(serializeString(entries[i][0]));
125
97
  valueNodes.push(await this.parse(entries[i][1]));
126
98
  }
127
99
  // Check special properties
128
- if (this.features & Feature.Symbol) {
129
- let symbol = Symbol.iterator;
130
- if (symbol in properties) {
131
- keyNodes.push(
132
- this.parseWKSymbol(symbol),
133
- );
134
- valueNodes.push(
135
- createIteratorFactoryInstanceNode(
136
- this.parseIteratorFactory(),
137
- await this.parse(
138
- iteratorToSequence(properties as unknown as Iterable<unknown>),
139
- ),
100
+ let symbol = Symbol.iterator;
101
+ if (symbol in properties) {
102
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
103
+ valueNodes.push(
104
+ createIteratorFactoryInstanceNode(
105
+ this.parseIteratorFactory(),
106
+ await this.parse(
107
+ iteratorToSequence(properties as unknown as Iterable<unknown>),
140
108
  ),
141
- );
142
- }
143
- symbol = Symbol.asyncIterator;
144
- if (symbol in properties) {
145
- keyNodes.push(
146
- this.parseWKSymbol(symbol),
147
- );
148
- valueNodes.push(
149
- createAsyncIteratorFactoryInstanceNode(
150
- this.parseAsyncIteratorFactory(0),
151
- await this.parse(
152
- await asyncIteratorToSequence(properties as unknown as AsyncIterable<unknown>),
109
+ ),
110
+ );
111
+ }
112
+ symbol = Symbol.asyncIterator;
113
+ if (symbol in properties) {
114
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
115
+ valueNodes.push(
116
+ createAsyncIteratorFactoryInstanceNode(
117
+ this.parseAsyncIteratorFactory(),
118
+ await this.parse(
119
+ createStreamFromAsyncIterable(
120
+ properties as unknown as AsyncIterable<unknown>,
153
121
  ),
154
122
  ),
155
- );
156
- }
157
- symbol = Symbol.toStringTag;
158
- if (symbol in properties) {
159
- keyNodes.push(this.parseWKSymbol(symbol));
160
- valueNodes.push(createStringNode(properties[symbol] as string));
161
- }
162
- symbol = Symbol.isConcatSpreadable;
163
- if (symbol in properties) {
164
- keyNodes.push(this.parseWKSymbol(symbol));
165
- valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
166
- }
123
+ ),
124
+ );
125
+ }
126
+ symbol = Symbol.toStringTag;
127
+ if (symbol in properties) {
128
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
129
+ valueNodes.push(createStringNode(properties[symbol] as string));
130
+ }
131
+ symbol = Symbol.isConcatSpreadable;
132
+ if (symbol in properties) {
133
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
134
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
167
135
  }
168
136
  return {
169
137
  k: keyNodes,
@@ -203,7 +171,11 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
203
171
  id: number,
204
172
  current: BigIntTypedArrayValue,
205
173
  ): Promise<SerovalBigIntTypedArrayNode> {
206
- return createBigIntTypedArrayNode(id, current, await this.parse(current.buffer));
174
+ return createBigIntTypedArrayNode(
175
+ id,
176
+ current,
177
+ await this.parse(current.buffer),
178
+ );
207
179
  }
208
180
 
209
181
  private async parseDataView(
@@ -221,9 +193,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
221
193
  return createErrorNode(
222
194
  id,
223
195
  current,
224
- options
225
- ? await this.parseProperties(options)
226
- : undefined,
196
+ options ? await this.parseProperties(options) : undefined,
227
197
  );
228
198
  }
229
199
 
@@ -235,9 +205,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
235
205
  return createAggregateErrorNode(
236
206
  id,
237
207
  current,
238
- options
239
- ? await this.parseProperties(options)
240
- : undefined,
208
+ options ? await this.parseProperties(options) : undefined,
241
209
  );
242
210
  }
243
211
 
@@ -251,12 +219,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
251
219
  keyNodes.push(await this.parse(key));
252
220
  valueNodes.push(await this.parse(value));
253
221
  }
254
- return this.createMapNode(
255
- id,
256
- keyNodes,
257
- valueNodes,
258
- current.size,
259
- );
222
+ return this.createMapNode(id, keyNodes, valueNodes, current.size);
260
223
  }
261
224
 
262
225
  private async parseSet(
@@ -270,176 +233,6 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
270
233
  return createSetNode(id, current.size, items);
271
234
  }
272
235
 
273
- private async parseBlob(
274
- id: number,
275
- current: Blob,
276
- ): Promise<SerovalBlobNode> {
277
- return {
278
- t: SerovalNodeType.Blob,
279
- i: id,
280
- s: undefined,
281
- l: undefined,
282
- c: serializeString(current.type),
283
- m: undefined,
284
- p: undefined,
285
- e: undefined,
286
- f: await this.parse(await current.arrayBuffer()),
287
- a: undefined,
288
- b: undefined,
289
- o: undefined,
290
- };
291
- }
292
-
293
- private async parseFile(
294
- id: number,
295
- current: File,
296
- ): Promise<SerovalFileNode> {
297
- return {
298
- t: SerovalNodeType.File,
299
- i: id,
300
- s: undefined,
301
- l: undefined,
302
- c: serializeString(current.type),
303
- m: serializeString(current.name),
304
- p: undefined,
305
- e: undefined,
306
- f: await this.parse(await current.arrayBuffer()),
307
- a: undefined,
308
- b: current.lastModified,
309
- o: undefined,
310
- };
311
- }
312
-
313
- protected async parsePlainProperties(
314
- entries: [key: string, value: unknown][],
315
- ): Promise<SerovalPlainRecordNode> {
316
- const size = entries.length;
317
- const keyNodes: string[] = [];
318
- const valueNodes: SerovalNode[] = [];
319
- for (let i = 0; i < size; i++) {
320
- keyNodes.push(serializeString(entries[i][0]));
321
- valueNodes.push(await this.parse(entries[i][1]));
322
- }
323
- return {
324
- k: keyNodes,
325
- v: valueNodes,
326
- s: size,
327
- };
328
- }
329
-
330
- private async parseHeaders(
331
- id: number,
332
- current: Headers,
333
- ): Promise<SerovalHeadersNode> {
334
- const items: [key: string, value: unknown][] = [];
335
- current.forEach((value, key) => {
336
- items.push([key, value]);
337
- });
338
- return {
339
- t: SerovalNodeType.Headers,
340
- i: id,
341
- s: undefined,
342
- l: undefined,
343
- c: undefined,
344
- m: undefined,
345
- p: undefined,
346
- e: await this.parsePlainProperties(items),
347
- a: undefined,
348
- f: undefined,
349
- b: undefined,
350
- o: undefined,
351
- };
352
- }
353
-
354
- private async parseFormData(
355
- id: number,
356
- current: FormData,
357
- ): Promise<SerovalFormDataNode> {
358
- const items: [key: string, value: FormDataEntryValue][] = [];
359
- current.forEach((value, key) => {
360
- items.push([key, value]);
361
- });
362
- return {
363
- t: SerovalNodeType.FormData,
364
- i: id,
365
- s: undefined,
366
- l: undefined,
367
- c: undefined,
368
- m: undefined,
369
- p: undefined,
370
- e: await this.parsePlainProperties(items),
371
- a: undefined,
372
- f: undefined,
373
- b: undefined,
374
- o: undefined,
375
- };
376
- }
377
-
378
- private async parseRequest(
379
- id: number,
380
- current: Request,
381
- ): Promise<SerovalRequestNode> {
382
- return {
383
- t: SerovalNodeType.Request,
384
- i: id,
385
- s: serializeString(current.url),
386
- l: undefined,
387
- c: undefined,
388
- m: undefined,
389
- p: undefined,
390
- e: undefined,
391
- f: await this.parse(
392
- createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null),
393
- ),
394
- a: undefined,
395
- b: undefined,
396
- o: undefined,
397
- };
398
- }
399
-
400
- private async parseResponse(
401
- id: number,
402
- current: Response,
403
- ): Promise<SerovalResponseNode> {
404
- return {
405
- t: SerovalNodeType.Response,
406
- i: id,
407
- s: undefined,
408
- l: undefined,
409
- c: undefined,
410
- m: undefined,
411
- p: undefined,
412
- e: undefined,
413
- f: undefined,
414
- a: [
415
- current.body
416
- ? await this.parse(await current.clone().arrayBuffer())
417
- : NULL_NODE,
418
- await this.parse(createResponseOptions(current)),
419
- ],
420
- b: undefined,
421
- o: undefined,
422
- };
423
- }
424
-
425
- private async parseEvent(
426
- id: number,
427
- current: Event,
428
- ): Promise<SerovalEventNode> {
429
- return createEventNode(id, current.type, await this.parse(createEventOptions(current)));
430
- }
431
-
432
- private async parseCustomEvent(
433
- id: number,
434
- current: CustomEvent,
435
- ): Promise<SerovalCustomEventNode> {
436
- return createCustomEventNode(
437
- id,
438
- current.type,
439
- await this.parse(createCustomEventOptions(current)),
440
- );
441
- }
442
-
443
236
  private async parsePromise(
444
237
  id: number,
445
238
  current: Promise<unknown>,
@@ -483,26 +276,72 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
483
276
  return undefined;
484
277
  }
485
278
 
486
- private async parseReadableStream(
279
+ private async parseStream(
487
280
  id: number,
488
- current: ReadableStream,
489
- ): Promise<SerovalReadableStreamNode> {
490
- return createReadableStreamNode(
281
+ current: Stream<unknown>,
282
+ ): Promise<SerovalStreamConstructorNode> {
283
+ return createStreamConstructorNode(
491
284
  id,
492
- this.parseSpecialReference(SpecialReference.ReadableStream),
493
- await this.parse(
494
- await readableStreamToSequence(current),
495
- ),
285
+ this.parseSpecialReference(SpecialReference.StreamConstructor),
286
+ await new Promise<SerovalNode[]>((resolve, reject) => {
287
+ const sequence: SerovalNode[] = [];
288
+ const cleanup = current.on({
289
+ next: value => {
290
+ this.markRef(id);
291
+ this.parse(value).then(
292
+ data => {
293
+ sequence.push(createStreamNextNode(id, data));
294
+ },
295
+ data => {
296
+ reject(data);
297
+ cleanup();
298
+ },
299
+ );
300
+ },
301
+ throw: value => {
302
+ this.markRef(id);
303
+ this.parse(value).then(
304
+ data => {
305
+ sequence.push(createStreamThrowNode(id, data));
306
+ resolve(sequence);
307
+ cleanup();
308
+ },
309
+ data => {
310
+ reject(data);
311
+ cleanup();
312
+ },
313
+ );
314
+ },
315
+ return: value => {
316
+ this.markRef(id);
317
+ this.parse(value).then(
318
+ data => {
319
+ sequence.push(createStreamReturnNode(id, data));
320
+ resolve(sequence);
321
+ cleanup();
322
+ },
323
+ data => {
324
+ reject(data);
325
+ cleanup();
326
+ },
327
+ );
328
+ },
329
+ });
330
+ }),
496
331
  );
497
332
  }
498
333
 
499
- private async parseObject(
500
- id: number,
501
- current: object,
502
- ): Promise<SerovalNode> {
334
+ private async parseObject(id: number, current: object): Promise<SerovalNode> {
503
335
  if (Array.isArray(current)) {
504
336
  return this.parseArray(id, current);
505
337
  }
338
+ if (isStream(current)) {
339
+ return this.parseStream(id, current);
340
+ }
341
+ const parsed = await this.parsePlugin(id, current);
342
+ if (parsed) {
343
+ return parsed;
344
+ }
506
345
  const currentClass = current.constructor;
507
346
  switch (currentClass) {
508
347
  case Object:
@@ -534,100 +373,49 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
534
373
  case String:
535
374
  case BigInt:
536
375
  return this.parseBoxed(id, current);
376
+ case ArrayBuffer:
377
+ return createArrayBufferNode(id, current as unknown as ArrayBuffer);
378
+ case Int8Array:
379
+ case Int16Array:
380
+ case Int32Array:
381
+ case Uint8Array:
382
+ case Uint16Array:
383
+ case Uint32Array:
384
+ case Uint8ClampedArray:
385
+ case Float32Array:
386
+ case Float64Array:
387
+ return this.parseTypedArray(id, current as unknown as TypedArrayValue);
388
+ case DataView:
389
+ return this.parseDataView(id, current as unknown as DataView);
390
+ case Map:
391
+ return this.parseMap(id, current as unknown as Map<unknown, unknown>);
392
+ case Set:
393
+ return this.parseSet(id, current as unknown as Set<unknown>);
537
394
  default:
538
395
  break;
539
396
  }
540
- const currentFeatures = this.features;
541
397
  // Promises
542
- if (
543
- (currentFeatures & Feature.Promise)
544
- && (currentClass === Promise || current instanceof Promise)
545
- ) {
398
+ if (currentClass === Promise || current instanceof Promise) {
546
399
  return this.parsePromise(id, current as unknown as Promise<unknown>);
547
400
  }
548
- // Typed Arrays
549
- if (currentFeatures & Feature.TypedArray) {
550
- switch (currentClass) {
551
- case ArrayBuffer:
552
- return createArrayBufferNode(id, current as unknown as ArrayBuffer);
553
- case Int8Array:
554
- case Int16Array:
555
- case Int32Array:
556
- case Uint8Array:
557
- case Uint16Array:
558
- case Uint32Array:
559
- case Uint8ClampedArray:
560
- case Float32Array:
561
- case Float64Array:
562
- return this.parseTypedArray(id, current as unknown as TypedArrayValue);
563
- case DataView:
564
- return this.parseDataView(id, current as unknown as DataView);
565
- default:
566
- break;
567
- }
568
- }
401
+ const currentFeatures = this.features;
569
402
  // BigInt Typed Arrays
570
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
403
+ if (currentFeatures & Feature.BigIntTypedArray) {
571
404
  switch (currentClass) {
572
405
  case BigInt64Array:
573
406
  case BigUint64Array:
574
- return this.parseBigIntTypedArray(id, current as unknown as BigIntTypedArrayValue);
575
- default:
576
- break;
577
- }
578
- }
579
- // ES Collection
580
- if (currentFeatures & Feature.Map && currentClass === Map) {
581
- return this.parseMap(
582
- id,
583
- current as unknown as Map<unknown, unknown>,
584
- );
585
- }
586
- if (currentFeatures & Feature.Set && currentClass === Set) {
587
- return this.parseSet(
588
- id,
589
- current as unknown as Set<unknown>,
590
- );
591
- }
592
- // Web APIs
593
- if (currentFeatures & Feature.WebAPI) {
594
- switch (currentClass) {
595
- case (typeof URL !== 'undefined' ? URL : UNIVERSAL_SENTINEL):
596
- return createURLNode(id, current as unknown as URL);
597
- case (typeof URLSearchParams !== 'undefined' ? URLSearchParams : UNIVERSAL_SENTINEL):
598
- return createURLSearchParamsNode(id, current as unknown as URLSearchParams);
599
- case (typeof Blob !== 'undefined' ? Blob : UNIVERSAL_SENTINEL):
600
- return this.parseBlob(id, current as unknown as Blob);
601
- case (typeof File !== 'undefined' ? File : UNIVERSAL_SENTINEL):
602
- return this.parseFile(id, current as unknown as File);
603
- case (typeof Headers !== 'undefined' ? Headers : UNIVERSAL_SENTINEL):
604
- return this.parseHeaders(id, current as unknown as Headers);
605
- case (typeof FormData !== 'undefined' ? FormData : UNIVERSAL_SENTINEL):
606
- return this.parseFormData(id, current as unknown as FormData);
607
- case (typeof Request !== 'undefined' ? Request : UNIVERSAL_SENTINEL):
608
- return this.parseRequest(id, current as unknown as Request);
609
- case (typeof Response !== 'undefined' ? Response : UNIVERSAL_SENTINEL):
610
- return this.parseResponse(id, current as unknown as Response);
611
- case (typeof Event !== 'undefined' ? Event : UNIVERSAL_SENTINEL):
612
- return this.parseEvent(id, current as unknown as Event);
613
- case (typeof CustomEvent !== 'undefined' ? CustomEvent : UNIVERSAL_SENTINEL):
614
- return this.parseCustomEvent(id, current as unknown as CustomEvent);
615
- case (typeof DOMException !== 'undefined' ? DOMException : UNIVERSAL_SENTINEL):
616
- return createDOMExceptionNode(id, current as unknown as DOMException);
617
- case (typeof ReadableStream !== 'undefined' ? ReadableStream : UNIVERSAL_SENTINEL):
618
- return this.parseReadableStream(id, current as unknown as ReadableStream);
407
+ return this.parseBigIntTypedArray(
408
+ id,
409
+ current as unknown as BigIntTypedArrayValue,
410
+ );
619
411
  default:
620
412
  break;
621
413
  }
622
414
  }
623
- const parsed = await this.parsePlugin(id, current);
624
- if (parsed) {
625
- return parsed;
626
- }
627
415
  if (
628
- (currentFeatures & Feature.AggregateError)
629
- && typeof AggregateError !== 'undefined'
630
- && (currentClass === AggregateError || current instanceof AggregateError)
416
+ currentFeatures & Feature.AggregateError &&
417
+ typeof AggregateError !== 'undefined' &&
418
+ (currentClass === AggregateError || current instanceof AggregateError)
631
419
  ) {
632
420
  return this.parseAggregateError(id, current as unknown as AggregateError);
633
421
  }
@@ -638,37 +426,37 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
638
426
  }
639
427
  // Generator functions don't have a global constructor
640
428
  // despite existing
641
- if (
642
- currentFeatures & Feature.Symbol
643
- && (Symbol.iterator in current || Symbol.asyncIterator in current)
644
- ) {
429
+ if (Symbol.iterator in current || Symbol.asyncIterator in current) {
645
430
  return this.parsePlainObject(id, current, !!currentClass);
646
431
  }
647
432
  throw new UnsupportedTypeError(current);
648
433
  }
649
434
 
650
435
  async parse<T>(current: T): Promise<SerovalNode> {
651
- switch (current) {
652
- case true: return TRUE_NODE;
653
- case false: return FALSE_NODE;
654
- case undefined: return UNDEFINED_NODE;
655
- case null: return NULL_NODE;
656
- default: break;
657
- }
658
436
  switch (typeof current) {
659
- case 'string': return createStringNode(current as string);
660
- case 'number': return createNumberNode(current as number);
437
+ case 'boolean':
438
+ return current ? TRUE_NODE : FALSE_NODE;
439
+ case 'undefined':
440
+ return UNDEFINED_NODE;
441
+ case 'string':
442
+ return createStringNode(current as string);
443
+ case 'number':
444
+ return createNumberNode(current as number);
661
445
  case 'bigint':
662
- assert(this.features & Feature.BigInt, new UnsupportedTypeError(current));
663
446
  return createBigIntNode(current as bigint);
664
447
  case 'object': {
665
- const id = this.getReference(current);
666
- return typeof id === 'number' ? this.parseObject(id, current as object) : id;
448
+ if (current) {
449
+ const ref = this.getReference(current);
450
+ return ref.type === 0
451
+ ? await this.parseObject(ref.value, current as object)
452
+ : ref.value;
453
+ }
454
+ return NULL_NODE;
667
455
  }
668
456
  case 'symbol':
669
- return this.parseWKSymbol(current);
457
+ return this.parseWellKnownSymbol(current);
670
458
  case 'function':
671
- return this.parseFunction(current);
459
+ return this.parseFunction(current as (...args: unknown[]) => unknown);
672
460
  default:
673
461
  throw new UnsupportedTypeError(current);
674
462
  }