seroval 1.7.10 → 1.8.1

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 (73) hide show
  1. package/dist/dev/index.cjs +58 -3893
  2. package/dist/dev/index.d.cts +5 -834
  3. package/dist/dev/index.d.ts +5 -834
  4. package/dist/dev/index.js +4 -3847
  5. package/dist/dev/read-BgToBbWd.js +455 -0
  6. package/dist/dev/read-Bn_ffmiS.d.ts +14 -0
  7. package/dist/dev/read-CgzYPh_Q.d.cts +14 -0
  8. package/dist/dev/read-D4n-bxUW.cjs +478 -0
  9. package/dist/dev/read.cjs +45 -0
  10. package/dist/dev/read.d.cts +17 -0
  11. package/dist/dev/read.d.ts +17 -0
  12. package/dist/dev/read.js +3 -0
  13. package/dist/dev/shared-Cf-Bmoy-.js +1010 -0
  14. package/dist/dev/shared-DTMVoS-y.d.ts +749 -0
  15. package/dist/dev/shared-DWx3Bwb6.cjs +1410 -0
  16. package/dist/dev/shared-Dju99SLx.d.cts +749 -0
  17. package/dist/dev/shared.cjs +40 -0
  18. package/dist/dev/shared.d.cts +2 -0
  19. package/dist/dev/shared.d.ts +2 -0
  20. package/dist/dev/shared.js +1 -0
  21. package/dist/dev/typed-array-C3haUQv_.js +72 -0
  22. package/dist/dev/typed-array-DUH_YsNc.cjs +101 -0
  23. package/dist/dev/validator-CxDhXc0k.d.cts +28 -0
  24. package/dist/dev/validator-CxDhXc0k.d.ts +28 -0
  25. package/dist/dev/validator.cjs +54 -0
  26. package/dist/dev/validator.d.cts +2 -0
  27. package/dist/dev/validator.d.ts +2 -0
  28. package/dist/dev/validator.js +45 -0
  29. package/dist/dev/write-BKJsV31u.js +2354 -0
  30. package/dist/dev/write-C0KqlAXN.d.ts +86 -0
  31. package/dist/dev/write-DGOp2jqo.cjs +2425 -0
  32. package/dist/dev/write-KxJKA4_p.d.cts +86 -0
  33. package/dist/dev/write.cjs +54 -0
  34. package/dist/dev/write.d.cts +4 -0
  35. package/dist/dev/write.d.ts +4 -0
  36. package/dist/dev/write.js +3 -0
  37. package/dist/index.cjs +58 -3877
  38. package/dist/index.d.cts +5 -834
  39. package/dist/index.d.ts +5 -834
  40. package/dist/index.js +4 -3831
  41. package/dist/read-B0hu4YND.cjs +478 -0
  42. package/dist/read-BSFu4fPn.js +455 -0
  43. package/dist/read-Bn_ffmiS.d.ts +14 -0
  44. package/dist/read-CgzYPh_Q.d.cts +14 -0
  45. package/dist/read.cjs +45 -0
  46. package/dist/read.d.cts +17 -0
  47. package/dist/read.d.ts +17 -0
  48. package/dist/read.js +3 -0
  49. package/dist/shared-DJIVyqa9.js +994 -0
  50. package/dist/shared-DTMVoS-y.d.ts +749 -0
  51. package/dist/shared-Dju99SLx.d.cts +749 -0
  52. package/dist/shared-u-KYXAax.cjs +1394 -0
  53. package/dist/shared.cjs +40 -0
  54. package/dist/shared.d.cts +2 -0
  55. package/dist/shared.d.ts +2 -0
  56. package/dist/shared.js +1 -0
  57. package/dist/typed-array-BWH0IKxT.js +72 -0
  58. package/dist/typed-array-BkSwWNFI.cjs +101 -0
  59. package/dist/validator-CxDhXc0k.d.cts +28 -0
  60. package/dist/validator-CxDhXc0k.d.ts +28 -0
  61. package/dist/validator.cjs +54 -0
  62. package/dist/validator.d.cts +2 -0
  63. package/dist/validator.d.ts +2 -0
  64. package/dist/validator.js +45 -0
  65. package/dist/write-B_hZaAwC.js +2354 -0
  66. package/dist/write-C0KqlAXN.d.ts +86 -0
  67. package/dist/write-CMi0CxOu.cjs +2425 -0
  68. package/dist/write-KxJKA4_p.d.cts +86 -0
  69. package/dist/write.cjs +54 -0
  70. package/dist/write.d.cts +4 -0
  71. package/dist/write.d.ts +4 -0
  72. package/dist/write.js +3 -0
  73. package/package.json +97 -1
package/dist/index.d.cts CHANGED
@@ -1,834 +1,5 @@
1
- //#region src/core/compat.d.ts
2
- /**
3
- * Public feature bits for `disabledFeatures`. Stays a runtime `enum` so the
4
- * published declaration is unchanged for consumers. Its values must match
5
- * the internal bits (checked by test/feature.test.ts).
6
- */
7
- export declare enum Feature {
8
- AggregateError = 1,
9
- /**
10
- * @deprecated Has no effect. Output follows the syntax of the build seroval
11
- * runs in: arrow functions, or `function` expressions in an ES5 build.
12
- */
13
- ArrowFunction = 2,
14
- ErrorPrototypeStack = 4,
15
- ObjectAssign = 8,
16
- BigIntTypedArray = 16,
17
- RegExp = 32,
18
- Temporal = 64
19
- }
20
- //#endregion
21
- //#region src/core/constants.d.ts
22
- declare const enum SerovalConstant {
23
- Null = 0,
24
- Undefined = 1,
25
- True = 2,
26
- False = 3,
27
- NegZero = 4,
28
- Inf = 5,
29
- NegInf = 6,
30
- Nan = 7
31
- }
32
- declare const enum SerovalNodeType {
33
- Number = 0,
34
- String = 1,
35
- Constant = 2,
36
- BigInt = 3,
37
- IndexedValue = 4,
38
- Date = 5,
39
- RegExp = 6,
40
- Set = 7,
41
- Map = 8,
42
- Array = 9,
43
- Object = 10,
44
- NullConstructor = 11,
45
- Promise = 12,
46
- Error = 13,
47
- AggregateError = 14,
48
- TypedArray = 15,
49
- BigIntTypedArray = 16,
50
- WKSymbol = 17,
51
- Reference = 18,
52
- ArrayBuffer = 19,
53
- DataView = 20,
54
- Boxed = 21,
55
- PromiseConstructor = 22,
56
- PromiseSuccess = 23,
57
- PromiseFailure = 24,
58
- Plugin = 25,
59
- SpecialReference = 26,
60
- IteratorFactory = 27,
61
- IteratorFactoryInstance = 28,
62
- AsyncIteratorFactory = 29,
63
- AsyncIteratorFactoryInstance = 30,
64
- StreamConstructor = 31,
65
- StreamNext = 32,
66
- StreamThrow = 33,
67
- StreamReturn = 34,
68
- Sequence = 35,
69
- Temporal = 36
70
- }
71
- declare const enum SerovalTemporalType {
72
- Instant = 0,
73
- Duration = 1,
74
- PlainDate = 2,
75
- PlainDateTime = 3,
76
- PlainMonthDay = 4,
77
- PlainTime = 5,
78
- PlainYearMonth = 6,
79
- ZonedDateTime = 7
80
- }
81
- declare const enum SerovalObjectFlags {
82
- None = 0,
83
- NonExtensible = 1,
84
- Sealed = 2,
85
- Frozen = 3
86
- }
87
- declare const enum Symbols {
88
- AsyncIterator = 0,
89
- HasInstance = 1,
90
- IsConcatSpreadable = 2,
91
- Iterator = 3,
92
- Match = 4,
93
- MatchAll = 5,
94
- Replace = 6,
95
- Search = 7,
96
- Species = 8,
97
- Split = 9,
98
- ToPrimitive = 10,
99
- ToStringTag = 11,
100
- Unscopables = 12
101
- }
102
- declare const enum ErrorConstructorTag {
103
- Error = 0,
104
- EvalError = 1,
105
- RangeError = 2,
106
- ReferenceError = 3,
107
- SyntaxError = 4,
108
- TypeError = 5,
109
- URIError = 6
110
- }
111
- //#endregion
112
- //#region src/core/special-reference.d.ts
113
- declare const enum SpecialReference {
114
- MapSentinel = 0,
115
- PromiseConstructor = 1,
116
- PromiseSuccess = 2,
117
- PromiseFailure = 3,
118
- StreamConstructor = 4,
119
- ArrayBufferConstructor = 5
120
- }
121
- //#endregion
122
- //#region src/core/types.d.ts
123
- interface SerovalBaseNode {
124
- t: SerovalNodeType;
125
- i: number | undefined;
126
- s: unknown;
127
- c: string | SerovalTemporalType | undefined;
128
- m: string | undefined;
129
- p: SerovalObjectRecordNode | undefined;
130
- e: SerovalMapRecordNode | undefined;
131
- a: (SerovalNode | 0)[] | undefined;
132
- f: SerovalNode | undefined;
133
- b: number | undefined;
134
- o: SerovalObjectFlags | undefined;
135
- l: number | undefined;
136
- }
137
- type SerovalObjectRecordKey = string | SerovalNode;
138
- interface SerovalObjectRecordNode {
139
- k: SerovalObjectRecordKey[];
140
- v: SerovalNode[];
141
- }
142
- interface SerovalMapRecordNode {
143
- k: SerovalNode[];
144
- v: SerovalNode[];
145
- }
146
- interface SerovalNumberNode extends SerovalBaseNode {
147
- t: SerovalNodeType.Number;
148
- s: number;
149
- }
150
- interface SerovalStringNode extends SerovalBaseNode {
151
- t: SerovalNodeType.String;
152
- s: string;
153
- }
154
- interface SerovalConstantNode extends SerovalBaseNode {
155
- t: SerovalNodeType.Constant;
156
- s: SerovalConstant;
157
- }
158
- type SerovalPrimitiveNode = SerovalNumberNode | SerovalStringNode | SerovalConstantNode;
159
- interface SerovalIndexedValueNode extends SerovalBaseNode {
160
- t: SerovalNodeType.IndexedValue;
161
- i: number;
162
- }
163
- interface SerovalBigIntNode extends SerovalBaseNode {
164
- t: SerovalNodeType.BigInt;
165
- s: string;
166
- }
167
- interface SerovalDateNode extends SerovalBaseNode {
168
- t: SerovalNodeType.Date;
169
- i: number;
170
- s: string;
171
- }
172
- interface SerovalRegExpNode extends SerovalBaseNode {
173
- t: SerovalNodeType.RegExp;
174
- i: number;
175
- c: string;
176
- m: string;
177
- }
178
- interface SerovalArrayBufferNode extends SerovalBaseNode {
179
- t: SerovalNodeType.ArrayBuffer;
180
- i: number;
181
- s: string;
182
- f: SerovalNodeWithID;
183
- }
184
- interface SerovalTypedArrayNode extends SerovalBaseNode {
185
- t: SerovalNodeType.TypedArray;
186
- i: number;
187
- c: string;
188
- f: SerovalNode;
189
- b: number;
190
- l: number;
191
- }
192
- interface SerovalBigIntTypedArrayNode extends SerovalBaseNode {
193
- t: SerovalNodeType.BigIntTypedArray;
194
- i: number;
195
- c: string;
196
- f: SerovalNode;
197
- b: number;
198
- l: number;
199
- }
200
- interface SerovalTemporalNode extends SerovalBaseNode {
201
- t: SerovalNodeType.Temporal;
202
- i: number;
203
- c: SerovalTemporalType;
204
- s: string;
205
- }
206
- type SerovalSemiPrimitiveNode = SerovalBigIntNode | SerovalDateNode | SerovalRegExpNode | SerovalTypedArrayNode | SerovalBigIntTypedArrayNode | SerovalTemporalNode;
207
- interface SerovalSetNode extends SerovalBaseNode {
208
- t: SerovalNodeType.Set;
209
- i: number;
210
- a: SerovalNode[];
211
- }
212
- interface SerovalMapNode extends SerovalBaseNode {
213
- t: SerovalNodeType.Map;
214
- i: number;
215
- e: SerovalMapRecordNode;
216
- f: SerovalNodeWithID;
217
- }
218
- interface SerovalArrayNode extends SerovalBaseNode {
219
- t: SerovalNodeType.Array;
220
- a: (SerovalNode | 0)[];
221
- i: number;
222
- o: SerovalObjectFlags;
223
- }
224
- interface SerovalObjectNode extends SerovalBaseNode {
225
- t: SerovalNodeType.Object;
226
- p: SerovalObjectRecordNode;
227
- i: number;
228
- o: SerovalObjectFlags;
229
- }
230
- interface SerovalNullConstructorNode extends SerovalBaseNode {
231
- t: SerovalNodeType.NullConstructor;
232
- p: SerovalObjectRecordNode;
233
- i: number;
234
- o: SerovalObjectFlags;
235
- }
236
- interface SerovalPromiseNode extends SerovalBaseNode {
237
- t: SerovalNodeType.Promise;
238
- s: 0 | 1;
239
- f: SerovalNode;
240
- i: number;
241
- }
242
- interface SerovalErrorNode extends SerovalBaseNode {
243
- t: SerovalNodeType.Error;
244
- s: ErrorConstructorTag;
245
- m: string;
246
- p: SerovalObjectRecordNode | undefined;
247
- i: number;
248
- }
249
- interface SerovalAggregateErrorNode extends SerovalBaseNode {
250
- t: SerovalNodeType.AggregateError;
251
- i: number;
252
- m: string;
253
- p: SerovalObjectRecordNode | undefined;
254
- }
255
- interface SerovalWKSymbolNode extends SerovalBaseNode {
256
- t: SerovalNodeType.WKSymbol;
257
- i: number;
258
- s: Symbols;
259
- }
260
- interface SerovalReferenceNode extends SerovalBaseNode {
261
- t: SerovalNodeType.Reference;
262
- i: number;
263
- s: string;
264
- }
265
- interface SerovalDataViewNode extends SerovalBaseNode {
266
- t: SerovalNodeType.DataView;
267
- i: number;
268
- f: SerovalNode;
269
- b: number;
270
- l: number;
271
- }
272
- interface SerovalBoxedNode extends SerovalBaseNode {
273
- t: SerovalNodeType.Boxed;
274
- i: number;
275
- f: SerovalNode;
276
- }
277
- interface SerovalPromiseConstructorNode extends SerovalBaseNode {
278
- t: SerovalNodeType.PromiseConstructor;
279
- i: number;
280
- s: number;
281
- f: SerovalNodeWithID;
282
- }
283
- interface SerovalPromiseResolveNode extends SerovalBaseNode {
284
- t: SerovalNodeType.PromiseSuccess;
285
- i: number;
286
- a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
287
- }
288
- interface SerovalPromiseRejectNode extends SerovalBaseNode {
289
- t: SerovalNodeType.PromiseFailure;
290
- i: number;
291
- a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
292
- }
293
- interface SerovalPluginNode extends SerovalBaseNode {
294
- t: SerovalNodeType.Plugin;
295
- i: number;
296
- s: Record<string, SerovalNode>;
297
- c: string;
298
- }
299
- /**
300
- * Represents special values as placeholders
301
- */
302
- interface SerovalSpecialReferenceNode extends SerovalBaseNode {
303
- t: SerovalNodeType.SpecialReference;
304
- i: number;
305
- s: SpecialReference;
306
- }
307
- interface SerovalIteratorFactoryNode extends SerovalBaseNode {
308
- t: SerovalNodeType.IteratorFactory;
309
- i: number;
310
- f: SerovalNodeWithID;
311
- }
312
- interface SerovalIteratorFactoryInstanceNode extends SerovalBaseNode {
313
- t: SerovalNodeType.IteratorFactoryInstance;
314
- a: [instance: SerovalNodeWithID, sequence: SerovalNodeWithID];
315
- }
316
- interface SerovalAsyncIteratorFactoryNode extends SerovalBaseNode {
317
- t: SerovalNodeType.AsyncIteratorFactory;
318
- i: number;
319
- a: [promise: SerovalNodeWithID, symbol: SerovalNodeWithID];
320
- }
321
- interface SerovalAsyncIteratorFactoryInstanceNode extends SerovalBaseNode {
322
- t: SerovalNodeType.AsyncIteratorFactoryInstance;
323
- a: [instance: SerovalNodeWithID, sequence: SerovalNodeWithID];
324
- }
325
- interface SerovalStreamConstructorNode extends SerovalBaseNode {
326
- t: SerovalNodeType.StreamConstructor;
327
- i: number;
328
- a: SerovalNode[];
329
- f: SerovalNodeWithID;
330
- l: 1 | undefined;
331
- }
332
- interface SerovalStreamNextNode extends SerovalBaseNode {
333
- t: SerovalNodeType.StreamNext;
334
- i: number;
335
- f: SerovalNode;
336
- }
337
- interface SerovalStreamThrowNode extends SerovalBaseNode {
338
- t: SerovalNodeType.StreamThrow;
339
- i: number;
340
- f: SerovalNode;
341
- }
342
- interface SerovalStreamReturnNode extends SerovalBaseNode {
343
- t: SerovalNodeType.StreamReturn;
344
- i: number;
345
- f: SerovalNode;
346
- }
347
- interface SerovalSequenceNode extends SerovalBaseNode {
348
- t: SerovalNodeType.Sequence;
349
- i: number;
350
- s: number;
351
- a: SerovalNode[];
352
- l: number;
353
- }
354
- type SerovalSyncNode = SerovalPrimitiveNode | SerovalIndexedValueNode | SerovalSemiPrimitiveNode | SerovalSetNode | SerovalMapNode | SerovalArrayNode | SerovalObjectNode | SerovalNullConstructorNode | SerovalPromiseNode | SerovalErrorNode | SerovalAggregateErrorNode | SerovalWKSymbolNode | SerovalReferenceNode | SerovalArrayBufferNode | SerovalDataViewNode | SerovalBoxedNode | SerovalPluginNode | SerovalSpecialReferenceNode | SerovalIteratorFactoryNode | SerovalIteratorFactoryInstanceNode | SerovalAsyncIteratorFactoryNode | SerovalAsyncIteratorFactoryInstanceNode | SerovalSequenceNode;
355
- type SerovalAsyncNode = SerovalPromiseNode | SerovalPromiseConstructorNode | SerovalPromiseResolveNode | SerovalPromiseRejectNode | SerovalStreamConstructorNode | SerovalStreamNextNode | SerovalStreamThrowNode | SerovalStreamReturnNode;
356
- type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
357
- type SerovalNodeWithID = Extract<SerovalNode, {
358
- i: number;
359
- }>;
360
- //#endregion
361
- //#region src/core/context/deserializer.d.ts
362
- interface BaseDeserializerContextOptions extends PluginAccessOptions {
363
- refs?: Map<number, unknown>;
364
- features?: number;
365
- disabledFeatures?: number;
366
- depthLimit?: number;
367
- /** Maximum encoded characters per ArrayBuffer. Defaults to 1,000,000. */
368
- maxBase64Length?: number;
369
- }
370
- interface VanillaDeserializerContextOptions extends Omit<BaseDeserializerContextOptions, 'refs'> {
371
- markedRefs: number[] | Set<number>;
372
- }
373
- type CrossDeserializerContextOptions = BaseDeserializerContextOptions;
374
- interface DeserializePluginContext {
375
- deserialize<T>(node: SerovalNode): T;
376
- }
377
- //#endregion
378
- //#region src/core/context/serializer.d.ts
379
- interface BaseSerializerContextOptions extends PluginAccessOptions {
380
- features: number;
381
- markedRefs: number[] | Set<number>;
382
- assignSharedRefsOnly?: boolean;
383
- }
384
- interface CrossContextOptions {
385
- scopeId?: string;
386
- }
387
- type VanillaSerializerContextOptions = BaseSerializerContextOptions;
388
- interface CrossSerializerContextOptions extends BaseSerializerContextOptions, CrossContextOptions {}
389
- interface SerializePluginContext {
390
- serialize(node: SerovalNode): string;
391
- }
392
- //#endregion
393
- //#region src/core/stream.d.ts
394
- interface StreamListener<T> {
395
- next(value: T): void;
396
- throw(value: unknown): void;
397
- return(value: T): void;
398
- }
399
- /**
400
- * An internal class rather than a tagged POJO: identity is checked with
401
- * `instanceof`, which untrusted input cannot forge. The class is exported
402
- * because bundlers cannot drop an unexported top-level class.
403
- *
404
- * The behavior is intentionally duplicated from `STREAM_CONSTRUCTOR`. That
405
- * constructor's source is embedded verbatim into the eval-based `deserialize`
406
- * output, which has no access to this class, so the two cannot be shared. A
407
- * stream read back through `deserialize` is therefore a plain POJO and, by
408
- * design, is not treated as a genuine Stream on re-serialization. Keep the two
409
- * implementations in sync.
410
- */
411
- export declare class Stream<T> {
412
- private buffer;
413
- private listeners;
414
- private alive;
415
- private success;
416
- private count;
417
- private live;
418
- constructor(live?: number);
419
- private flush;
420
- private replay;
421
- on(listener: StreamListener<T>): () => void;
422
- /**
423
- * Returns the events of a stream that has ended, without subscribing, so a
424
- * live receiver is not consumed. The last value is the `return` or `throw`
425
- * value. Returns `undefined` while the stream is open, or when a live
426
- * receiver was already consumed and has no events left.
427
- * @internal
428
- */
429
- endedEvents(): {
430
- values: unknown[];
431
- success: boolean;
432
- } | undefined;
433
- next(value: T): void;
434
- throw(value: unknown): void;
435
- return(value: T): void;
436
- }
437
- export declare function isStream<T>(value: unknown): value is Stream<T> | LiveStream<T>;
438
- export declare function createStream<T>(): Stream<T>;
439
- //#endregion
440
- //#region src/core/live-stream.d.ts
441
- type LiveStreamEvent<T> = {
442
- type: 'next';
443
- value: T;
444
- } | {
445
- type: 'return';
446
- value: T;
447
- } | {
448
- type: 'throw';
449
- error: unknown;
450
- };
451
- interface LiveStreamDelivery<T> {
452
- event: LiveStreamEvent<T>;
453
- /**
454
- * Release the event and resolve the producer operation that sent it.
455
- * Call it only after the serialized record for the event has been
456
- * accepted by its destination. Late or repeated calls are ignored.
457
- */
458
- accept(): void;
459
- }
460
- interface LiveStreamConsumer<T> {
461
- read(): Promise<LiveStreamDelivery<T>>;
462
- cancel(reason?: unknown): void;
463
- }
464
- interface LiveStreamProducer<T> {
465
- write(value: T): Promise<void>;
466
- close(value: T): Promise<void>;
467
- fail(error: unknown): Promise<void>;
468
- }
469
- /**
470
- * Receives events from `LiveStream.pump`. Each handler gets the event value
471
- * and the accept function for it, and returns `undefined` to keep going or
472
- * the error that stopped the sink. `error` runs if the stream is cancelled
473
- * while a read is pending.
474
- */
475
- interface LiveStreamSink<T> {
476
- next(value: T, accept: () => void): unknown;
477
- throw(value: unknown, accept: () => void): unknown;
478
- return(value: T, accept: () => void): unknown;
479
- /** Runs once after the terminal event, or after a handler failed. */
480
- done?(): void;
481
- /** Runs if the stream is cancelled while a read is pending. */
482
- error?(reason: unknown): void;
483
- }
484
- interface LiveStreamOptions {
485
- onCancel?: (reason: unknown) => void;
486
- }
487
- declare const BRAND: unique symbol;
488
- export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
489
- /**
490
- * A single-consumer stream for incremental serialization. Unlike
491
- * `createStream`, it keeps no history: at most one event is held, and the
492
- * producer operation that sent it settles only when the consumer accepts it.
493
- *
494
- * An internal class rather than a tagged POJO: identity is checked with
495
- * `isLiveStream`, which untrusted input cannot forge. The class is exported
496
- * because bundlers cannot drop an unexported top-level class.
497
- */
498
- export declare class LiveStream<T> {
499
- private readonly [BRAND];
500
- private pending;
501
- private waiting;
502
- private consumed;
503
- private closed;
504
- private cancelled;
505
- private cancelReason;
506
- private options;
507
- constructor(options?: LiveStreamOptions);
508
- private deliver;
509
- /** @internal */
510
- push(event: LiveStreamEvent<T>): Promise<void>;
511
- private cancel;
512
- private read;
513
- consume(): LiveStreamConsumer<T>;
514
- /**
515
- * Consumes the stream through a replay-style listener, accepting each
516
- * event as soon as it has been delivered. Use `consume` or `pump` when
517
- * acceptance must wait for processing.
518
- */
519
- on(listener: StreamListener<T>): () => void;
520
- /**
521
- * Consumes the stream into a sink that controls acceptance. Returns the
522
- * cancel function.
523
- * @internal
524
- */
525
- pump(sink: LiveStreamSink<T>): (reason?: unknown) => void;
526
- }
527
- /**
528
- * Creates a live stream and the producer that writes to it.
529
- */
530
- export declare function createLiveStream<T>(options?: LiveStreamOptions): {
531
- stream: LiveStream<T>;
532
- producer: LiveStreamProducer<T>;
533
- };
534
- //#endregion
535
- //#region src/core/context/sync-parser.d.ts
536
- type SyncParserContextOptions = BaseParserContextOptions;
537
- interface SyncParsePluginContext {
538
- parse<T>(current: T): SerovalNode;
539
- }
540
- interface StreamParserContextOptions extends SyncParserContextOptions {
541
- /**
542
- * Receives each parsed record. Returning a promise defers the next record,
543
- * and the acceptance of the source event that produced it, until the
544
- * promise settles.
545
- */
546
- onParse: (node: SerovalNode, initial: boolean) => void | PromiseLike<void>;
547
- onError?: (error: unknown) => void;
548
- onDone?: () => void;
549
- }
550
- //#endregion
551
- //#region src/core/context/stream-parser.d.ts
552
- interface StreamParsePluginContext {
553
- parse<T>(current: T): SerovalNode;
554
- parseStreamSource(current: AsyncIterable<unknown>): SerovalNode;
555
- parseWithError<T>(current: T): SerovalNode | undefined;
556
- isAlive(): boolean;
557
- pushPendingState(): void;
558
- popPendingState(): void;
559
- onParse(node: SerovalNode): void;
560
- onError(error: unknown): void;
561
- addCleanup(callback: () => void): void;
562
- }
563
- //#endregion
564
- //#region src/core/plugin.d.ts
565
- export declare const enum SerovalMode {
566
- Vanilla = 1,
567
- Cross = 2
568
- }
569
- export interface PluginData {
570
- id: number;
571
- }
572
- export type PluginInfo = {
573
- [key: string]: SerovalNode;
574
- };
575
- export interface Plugin<Value, Info extends PluginInfo> {
576
- /**
577
- * A unique string that helps idenfity the plugin
578
- */
579
- tag: string;
580
- /**
581
- * List of dependency plugins
582
- */
583
- extends?: Plugin<any, any>[];
584
- /**
585
- * Method to test if a value is an expected value of the plugin
586
- * @param value
587
- */
588
- test(value: unknown): boolean;
589
- /**
590
- * Set to `true` if `test` never returns `true` for a plain object, whose
591
- * prototype is `Object.prototype`, such as an object literal. The parsers
592
- * then skip this plugin for those objects. Leave it unset if unsure. A
593
- * plugin that sets it is never applied to such objects.
594
- */
595
- skipPlainObjects?: boolean;
596
- /**
597
- * Parsing modes
598
- */
599
- parse: {
600
- sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
601
- async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
602
- stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
603
- };
604
- /**
605
- * Convert the parsed node into a JS string
606
- */
607
- serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
608
- /**
609
- * Convert the parsed node into its runtime equivalent.
610
- */
611
- deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
612
- }
613
- export declare function createPlugin<Value, Info extends PluginInfo>(plugin: Plugin<Value, Info>): Plugin<Value, Info>;
614
- export interface PluginAccessOptions {
615
- plugins?: Plugin<any, any>[];
616
- }
617
- export declare function resolvePlugins(plugins?: Plugin<any, any>[]): Plugin<any, any>[] | undefined;
618
- /**
619
- * Returns the plugins that are tested for plain objects. It is the same array
620
- * when no plugin sets `skipPlainObjects`.
621
- */
622
- export declare function getPlainObjectPlugins(plugins: Plugin<any, any>[] | undefined): Plugin<any, any>[] | undefined;
623
- //#endregion
624
- //#region src/core/context/parser.d.ts
625
- interface BaseParserContextOptions extends PluginAccessOptions {
626
- disabledFeatures?: number;
627
- refs?: Map<unknown, number>;
628
- depthLimit?: number;
629
- /** Copy each typed array or DataView's visible bytes into its own buffer. */
630
- compactArrayBufferViews?: boolean;
631
- }
632
- //#endregion
633
- //#region src/core/context/async-parser.d.ts
634
- type AsyncParserContextOptions = BaseParserContextOptions;
635
- interface AsyncParsePluginContext {
636
- parse<T>(current: T): Promise<SerovalNode>;
637
- parseStreamSource(current: AsyncIterable<unknown>): Promise<SerovalNode>;
638
- }
639
- //#endregion
640
- //#region src/core/cross/index.d.ts
641
- export interface CrossAssignmentOptions {
642
- /**
643
- * Only assign `$R[n]` for values that the output reads more than once,
644
- * such as shared references and cycles. The output is shorter, but later
645
- * scripts cannot read the other values from `$R`. Only use it when no
646
- * later output that shares the same references refers back to this one.
647
- */
648
- assignSharedRefsOnly?: boolean;
649
- }
650
- export interface CrossSerializeOptions extends SyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {}
651
- export declare function crossSerialize<T>(source: T, options?: CrossSerializeOptions): string;
652
- export interface CrossSerializeAsyncOptions extends AsyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {}
653
- export declare function crossSerializeAsync<T>(source: T, options?: CrossSerializeAsyncOptions): Promise<string>;
654
- export type ToCrossJSONOptions = SyncParserContextOptions;
655
- export declare function toCrossJSON<T>(source: T, options?: ToCrossJSONOptions): SerovalNode;
656
- export type ToCrossJSONAsyncOptions = AsyncParserContextOptions;
657
- export declare function toCrossJSONAsync<T>(source: T, options?: ToCrossJSONAsyncOptions): Promise<SerovalNode>;
658
- export interface CrossSerializeStreamOptions extends Omit<StreamParserContextOptions, 'onParse'>, CrossContextOptions {
659
- /**
660
- * Receives each serialized record. Returning a promise defers the next
661
- * record, and the acceptance of the live stream event behind this one,
662
- * until the promise settles.
663
- */
664
- onSerialize: (data: string, initial: boolean) => void | PromiseLike<void>;
665
- }
666
- export declare function crossSerializeStream<T>(source: T, options: CrossSerializeStreamOptions): (reason?: unknown) => void;
667
- export type ToCrossJSONStreamOptions = StreamParserContextOptions;
668
- export declare function toCrossJSONStream<T>(source: T, options: ToCrossJSONStreamOptions): (reason?: unknown) => void;
669
- export type FromCrossJSONOptions = CrossDeserializerContextOptions;
670
- export declare function fromCrossJSON<T>(source: SerovalNode, options: FromCrossJSONOptions): T;
671
- export interface CrossDeserializer {
672
- /** Deserializes one streamed record. Records share references. */
673
- deserialize<T>(node: SerovalNode): T;
674
- /** Deferred values (promises, streams) created but not yet settled. */
675
- readonly pending: number;
676
- /** Rejects pending promises and throws into open streams; idempotent. */
677
- abort(reason: unknown): void;
678
- }
679
- export type CrossDeserializerOptions = FromCrossJSONOptions;
680
- export declare function createCrossDeserializer(options: CrossDeserializerOptions): CrossDeserializer;
681
- //#endregion
682
- //#region src/core/errors.d.ts
683
- export declare class SerovalError extends Error {
684
- cause: unknown;
685
- constructor(type: string, cause: unknown);
686
- }
687
- export declare class SerovalParserError extends SerovalError {
688
- constructor(cause: unknown);
689
- }
690
- export declare class SerovalSerializationError extends SerovalError {
691
- constructor(cause: unknown);
692
- }
693
- export declare class SerovalDeserializationError extends SerovalError {
694
- constructor(cause: unknown);
695
- }
696
- export declare class SerovalUnsupportedTypeError extends Error {
697
- value: unknown;
698
- constructor(value: unknown);
699
- }
700
- export declare class SerovalUnsupportedNodeError extends Error {
701
- constructor(node: SerovalNode);
702
- }
703
- export declare class SerovalMissingPluginError extends Error {
704
- constructor(tag: string);
705
- }
706
- export declare class SerovalMissingInstanceError extends Error {
707
- constructor(tag: string);
708
- }
709
- /**
710
- * @deprecated Not thrown by seroval. A missing `createReference` key throws
711
- * {@link SerovalMissingReferenceForIdError} instead.
712
- */
713
- export declare class SerovalMissingReferenceError extends Error {
714
- value: unknown;
715
- constructor(value: unknown);
716
- }
717
- export declare class SerovalMissingReferenceForIdError extends Error {
718
- constructor(id: string);
719
- }
720
- export declare class SerovalUnknownTypedArrayError extends Error {
721
- constructor(name: string);
722
- }
723
- export declare class SerovalMalformedNodeError extends Error {
724
- constructor(node: SerovalNode);
725
- }
726
- export declare class SerovalConflictedNodeIdError extends Error {
727
- constructor(node: SerovalNode);
728
- }
729
- export declare class SerovalDepthLimitError extends Error {
730
- constructor(limit: number);
731
- }
732
- export declare class SerovalAbortedError extends Error {
733
- constructor();
734
- }
735
- export type LiveStreamErrorReason = 'consumed' | 'pending' | 'reading' | 'closed';
736
- export declare class SerovalLiveStreamError extends Error {
737
- reason: LiveStreamErrorReason;
738
- constructor(reason: LiveStreamErrorReason);
739
- }
740
- //#endregion
741
- //#region src/core/keys.d.ts
742
- export declare function getCrossReferenceHeader(id?: string): string;
743
- //#endregion
744
- //#region src/core/opaque-reference.d.ts
745
- /**
746
- * An opaque reference allows hiding values from the serializer.
747
- */
748
- export declare class OpaqueReference<V, R = undefined> {
749
- readonly value: V;
750
- readonly replacement?: R | undefined;
751
- constructor(value: V, replacement?: R | undefined);
752
- }
753
- //#endregion
754
- //#region src/core/reference.d.ts
755
- export declare function createReference<T>(id: string, value: T): T;
756
- //#endregion
757
- //#region src/core/Serializer.d.ts
758
- interface SerializerOptions extends PluginAccessOptions {
759
- globalIdentifier: string;
760
- scopeId?: string;
761
- disabledFeatures?: number;
762
- compactArrayBufferViews?: boolean;
763
- depthLimit?: number;
764
- onData: (result: string) => void;
765
- onError: (error: unknown) => void;
766
- onDone?: () => void;
767
- }
768
- declare class Serializer {
769
- private alive;
770
- private flushed;
771
- private done;
772
- private pending;
773
- private cleanups;
774
- private readonly refs;
775
- private plugins?;
776
- private options;
777
- constructor(options: SerializerOptions);
778
- keys: Set<string>;
779
- write(key: string, value: unknown): void;
780
- private finishWrite;
781
- ids: number;
782
- private getNextID;
783
- push(value: unknown): string;
784
- flush(): void;
785
- close(): void;
786
- private finish;
787
- }
788
- //#endregion
789
- //#region src/core/sequence.d.ts
790
- /**
791
- * An internal class rather than a tagged POJO: identity is checked with
792
- * `instanceof`, which untrusted input cannot forge. The class is exported
793
- * because bundlers cannot drop an unexported top-level class.
794
- * The eval-based `deserialize` path still rebuilds a `{__SEROVAL_SEQUENCE__…}`
795
- * POJO from embedded source - it has no access to this class - so a value read
796
- * back through `deserialize` is not an instance and, by design, is not treated
797
- * as a genuine Sequence on re-serialization.
798
- */
799
- export declare class Sequence {
800
- v: unknown[];
801
- t: number;
802
- d: number;
803
- constructor(values: unknown[], throwAt: number, doneAt: number);
804
- }
805
- //#endregion
806
- //#region src/core/tree/index.d.ts
807
- /**
808
- * Options for `serialize`. The same as the parser options, without `refs`:
809
- * the output is self-contained, so there is nothing to share between calls.
810
- */
811
- export type SerializeOptions = Omit<BaseParserContextOptions, 'refs'>;
812
- /** Options for `serializeAsync`. */
813
- export type SerializeAsyncOptions = Omit<BaseParserContextOptions, 'refs'>;
814
- /** Options for `toJSON`. */
815
- export type ToJSONOptions = SerializeOptions;
816
- /** Options for `toJSONAsync`. */
817
- export type ToJSONAsyncOptions = SerializeAsyncOptions;
818
- export declare function serialize<T>(source: T, options?: SerializeOptions): string;
819
- export declare function serializeAsync<T>(source: T, options?: SerializeAsyncOptions): Promise<string>;
820
- export declare function deserialize<T>(source: string): T;
821
- export interface SerovalJSON {
822
- t: SerovalNode;
823
- f: number;
824
- m: number[];
825
- }
826
- export interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'depthLimit' | 'maxBase64Length'> {
827
- disabledFeatures?: number;
828
- }
829
- export declare function toJSON<T>(source: T, options?: ToJSONOptions): SerovalJSON;
830
- export declare function toJSONAsync<T>(source: T, options?: ToJSONAsyncOptions): Promise<SerovalJSON>;
831
- export declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
832
- export declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
833
- //#endregion
834
- export { type AsyncParsePluginContext, type AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, type CrossSerializerContextOptions, type DeserializePluginContext, type LiveStreamConsumer, type LiveStreamDelivery, type LiveStreamEvent, type LiveStreamOptions, type LiveStreamProducer, type SerializePluginContext, Serializer, type SerovalNode, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, type SyncParserContextOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions };
1
+ import { $ as BaseSerializerContextOptions, A as PluginAccessOptions, B as SyncParserContextOptions, C as SerovalUnsupportedTypeError, D as DeserializePluginContext, E as CrossDeserializerContextOptions, F as getPlainObjectPlugins, G as LiveStreamOptions, H as LiveStreamConsumer, I as resolvePlugins, J as isLiveStream, K as LiveStreamProducer, L as StreamParsePluginContext, M as PluginInfo, N as SerovalMode, O as VanillaDeserializerContextOptions, P as createPlugin, Q as isStream, R as StreamParserContextOptions, S as SerovalUnsupportedNodeError, T as BaseDeserializerContextOptions, U as LiveStreamDelivery, V as LiveStream, W as LiveStreamEvent, X as StreamListener, Y as Stream, Z as createStream, _ as SerovalMissingReferenceForIdError, a as OpaqueReference, at as AsyncParserContextOptions, b as SerovalSerializationError, c as SerovalConflictedNodeIdError, d as SerovalError, et as CrossContextOptions, f as SerovalLiveStreamError, g as SerovalMissingReferenceError, h as SerovalMissingPluginError, i as createReference, it as AsyncParsePluginContext, j as PluginData, k as Plugin, l as SerovalDepthLimitError, m as SerovalMissingInstanceError, n as v, nt as SerializePluginContext, o as LiveStreamErrorReason, ot as BaseParserContextOptions, p as SerovalMalformedNodeError, q as createLiveStream, r as Sequence, rt as VanillaSerializerContextOptions, s as SerovalAbortedError, st as SerovalNode, t as Validator, tt as CrossSerializerContextOptions, u as SerovalDeserializationError, v as SerovalParserError, w as Feature, x as SerovalUnknownTypedArrayError, y as SerovalPluginValidationError, z as SyncParsePluginContext } from "./shared-Dju99SLx.cjs";
2
+ import { i as fromJSON, n as SerovalJSON, r as deserialize, t as FromJSONOptions } from "./read-CgzYPh_Q.cjs";
3
+ import { CrossDeserializer, CrossDeserializerOptions, FromCrossJSONOptions, createCrossDeserializer, fromCrossJSON } from "./read.cjs";
4
+ import { C as toCrossJSONAsync, S as toCrossJSON, _ as ToCrossJSONOptions, a as compileJSON, b as crossSerializeAsync, c as toJSON, d as getCrossReferenceHeader, f as CrossAssignmentOptions, g as ToCrossJSONAsyncOptions, h as CrossSerializeStreamOptions, i as ToJSONOptions, l as toJSONAsync, m as CrossSerializeOptions, n as SerializeOptions, o as serialize, p as CrossSerializeAsyncOptions, r as ToJSONAsyncOptions, s as serializeAsync, t as SerializeAsyncOptions, u as Serializer, v as ToCrossJSONStreamOptions, w as toCrossJSONStream, x as crossSerializeStream, y as crossSerialize } from "./write-KxJKA4_p.cjs";
5
+ export { type AsyncParsePluginContext, type AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, CrossAssignmentOptions, type CrossContextOptions, CrossDeserializer, type CrossDeserializerContextOptions, CrossDeserializerOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, LiveStream, type LiveStreamConsumer, type LiveStreamDelivery, LiveStreamErrorReason, type LiveStreamEvent, type LiveStreamOptions, type LiveStreamProducer, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, Sequence, SerializeAsyncOptions, SerializeOptions, type SerializePluginContext, Serializer, SerovalAbortedError, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalLiveStreamError, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalPluginValidationError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, type SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, ToJSONAsyncOptions, ToJSONOptions, type Validator, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createCrossDeserializer, createLiveStream, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, getPlainObjectPlugins, isLiveStream, isStream, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync, v };