seroval 1.7.10 → 1.8.0

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