node-modules-tools 1.4.2 → 2.0.0-beta.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.
@@ -1,118 +1,947 @@
1
- import require$$0 from 'stream';
2
- import require$$1 from 'string_decoder';
3
- import require$$0$1 from 'events';
1
+ import { createRequire } from 'node:module';
2
+ import require$$0 from 'string_decoder';
4
3
 
5
4
  function getDefaultExportFromCjs (x) {
6
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
6
  }
8
7
 
9
- var Utf8Stream_1;
10
- var hasRequiredUtf8Stream;
8
+ var src$1 = {exports: {}};
11
9
 
12
- function requireUtf8Stream () {
13
- if (hasRequiredUtf8Stream) return Utf8Stream_1;
14
- hasRequiredUtf8Stream = 1;
10
+ var parser = {exports: {}};
15
11
 
16
- const {Transform} = require$$0;
17
- const {StringDecoder} = require$$1;
12
+ var src = {exports: {}};
18
13
 
19
- class Utf8Stream extends Transform {
20
- constructor(options) {
21
- super(Object.assign({}, options, {writableObjectMode: false}));
22
- this._buffer = '';
14
+ const require$2 = createRequire(import.meta.url);
15
+ function __require$1() { return require$2("node:stream"); }
16
+
17
+ var defs = {};
18
+
19
+ var hasRequiredDefs;
20
+
21
+ function requireDefs () {
22
+ if (hasRequiredDefs) return defs;
23
+ hasRequiredDefs = 1;
24
+
25
+ const none = Symbol.for('object-stream.none');
26
+ const stop = Symbol.for('object-stream.stop');
27
+
28
+ const finalSymbol = Symbol.for('object-stream.final');
29
+ const manySymbol = Symbol.for('object-stream.many');
30
+ const flushSymbol = Symbol.for('object-stream.flush');
31
+ const fListSymbol = Symbol.for('object-stream.fList');
32
+
33
+ const finalValue = value => ({[finalSymbol]: 1, value});
34
+ const many = values => ({[manySymbol]: 1, values});
35
+
36
+ const isFinalValue = o => o && o[finalSymbol] === 1;
37
+ const isMany = o => o && o[manySymbol] === 1;
38
+ const isFlushable = o => o && o[flushSymbol] === 1;
39
+ const isFunctionList = o => o && o[fListSymbol] === 1;
40
+
41
+ const getFinalValue = o => o.value;
42
+ const getManyValues = o => o.values;
43
+ const getFunctionList = o => o.fList;
44
+
45
+ const flushable = (write, final = null) => {
46
+ const fn = final ? value => (value === none ? final() : write(value)) : write;
47
+ fn[flushSymbol] = 1;
48
+ return fn;
49
+ };
50
+
51
+ const setFunctionList = (o, fns) => {
52
+ o.fList = fns;
53
+ o[fListSymbol] = 1;
54
+ return o;
55
+ };
56
+
57
+ const clearFunctionList = o => {
58
+ delete o.fList;
59
+ delete o[fListSymbol];
60
+ return o;
61
+ };
62
+
63
+ class Stop extends Error {}
64
+
65
+ const toMany = value =>
66
+ value === none ? many([]) : value && value[manySymbol] === 1 ? value : many([value]);
67
+
68
+ const normalizeMany = o => {
69
+ if (o?.[manySymbol] === 1) {
70
+ switch (o.values.length) {
71
+ case 0:
72
+ return none;
73
+ case 1:
74
+ return o.values[0];
75
+ }
23
76
  }
77
+ return o;
78
+ };
24
79
 
25
- _transform(chunk, encoding, callback) {
26
- if (typeof chunk == 'string') {
27
- this._transform = this._transformString;
80
+ const combineMany = (...args) => {
81
+ const values = [];
82
+ for (let i = 0; i < args.length; ++i) {
83
+ const a = args[i];
84
+ if (a === none) continue;
85
+ if (a?.[manySymbol] === 1) {
86
+ values.push(...a.values);
28
87
  } else {
29
- this._stringDecoder = new StringDecoder();
30
- this._transform = this._transformBuffer;
88
+ values.push(a);
31
89
  }
32
- this._transform(chunk, encoding, callback);
33
90
  }
91
+ return many(values);
92
+ };
34
93
 
35
- _transformBuffer(chunk, _, callback) {
36
- this._buffer += this._stringDecoder.write(chunk);
37
- this._processBuffer(callback);
94
+ const combineManyMut = (a, ...args) => {
95
+ const values = a === none ? [] : a?.[manySymbol] === 1 ? a.values : [a];
96
+ for (let i = 0; i < args.length; ++i) {
97
+ const b = args[i];
98
+ if (b === none) continue;
99
+ if (b?.[manySymbol] === 1) {
100
+ values.push(...b.values);
101
+ } else {
102
+ values.push(b);
103
+ }
38
104
  }
105
+ return many(values);
106
+ };
39
107
 
40
- _transformString(chunk, _, callback) {
41
- this._buffer += chunk.toString();
42
- this._processBuffer(callback);
43
- }
108
+ // old aliases
109
+ const final = finalValue;
110
+
111
+ defs.none = none;
112
+ defs.stop = stop;
113
+ defs.Stop = Stop;
114
+
115
+ defs.finalSymbol = finalSymbol;
116
+ defs.finalValue = finalValue;
117
+ defs.final = final;
118
+ defs.isFinalValue = isFinalValue;
119
+ defs.getFinalValue = getFinalValue;
120
+
121
+ defs.manySymbol = manySymbol;
122
+ defs.many = many;
123
+ defs.isMany = isMany;
124
+ defs.getManyValues = getManyValues;
125
+
126
+ defs.flushSymbol = flushSymbol;
127
+ defs.flushable = flushable;
128
+ defs.isFlushable = isFlushable;
44
129
 
45
- _processBuffer(callback) {
46
- if (this._buffer) {
47
- this.push(this._buffer, 'utf8');
48
- this._buffer = '';
130
+ defs.fListSymbol = fListSymbol;
131
+ defs.isFunctionList = isFunctionList;
132
+ defs.getFunctionList = getFunctionList;
133
+ defs.setFunctionList = setFunctionList;
134
+ defs.clearFunctionList = clearFunctionList;
135
+
136
+ defs.toMany = toMany;
137
+ defs.normalizeMany = normalizeMany;
138
+ defs.combineMany = combineMany;
139
+ defs.combineManyMut = combineManyMut;
140
+ return defs;
141
+ }
142
+
143
+ var gen = {exports: {}};
144
+
145
+ var hasRequiredGen;
146
+
147
+ function requireGen () {
148
+ if (hasRequiredGen) return gen.exports;
149
+ hasRequiredGen = 1;
150
+
151
+ const defs = requireDefs();
152
+
153
+ const next = async function* (value, fns, index) {
154
+ for (let i = index; i <= fns.length; ++i) {
155
+ if (value && typeof value.then == 'function') {
156
+ // thenable
157
+ value = await value;
158
+ }
159
+ if (value === defs.none) break;
160
+ if (value === defs.stop) throw new defs.Stop();
161
+ if (defs.isFinalValue(value)) {
162
+ yield defs.getFinalValue(value);
163
+ break;
164
+ }
165
+ if (defs.isMany(value)) {
166
+ const values = defs.getManyValues(value);
167
+ if (i == fns.length) {
168
+ yield* values;
169
+ } else {
170
+ for (let j = 0; j < values.length; ++j) {
171
+ yield* next(values[j], fns, i);
172
+ }
173
+ }
174
+ break;
175
+ }
176
+ if (value && typeof value.next == 'function') {
177
+ // generator
178
+ for (;;) {
179
+ let data = value.next();
180
+ if (data && typeof data.then == 'function') {
181
+ data = await data;
182
+ }
183
+ if (data.done) break;
184
+ if (i == fns.length) {
185
+ yield data.value;
186
+ } else {
187
+ yield* next(data.value, fns, i);
188
+ }
189
+ }
190
+ break;
191
+ }
192
+ if (i == fns.length) {
193
+ yield value;
194
+ break;
49
195
  }
50
- callback(null);
196
+ const f = fns[i];
197
+ value = f(value);
51
198
  }
199
+ };
52
200
 
53
- _flushInput() {
54
- // meant to be called from _flush()
55
- if (this._stringDecoder) {
56
- this._buffer += this._stringDecoder.end();
201
+ const gen$1 = (...fns) => {
202
+ fns = fns
203
+ .filter(fn => fn)
204
+ .flat(Infinity)
205
+ .map(fn => (defs.isFunctionList(fn) ? defs.getFunctionList(fn) : fn))
206
+ .flat(Infinity);
207
+ if (!fns.length) {
208
+ fns = [x => x];
209
+ }
210
+ let flushed = false;
211
+ let g = async function* (value) {
212
+ if (flushed) throw Error('Call to a flushed pipe.');
213
+ if (value !== defs.none) {
214
+ for (let i = 0; i <= fns.length; ++i) {
215
+ if (value && typeof value.then == 'function') {
216
+ yield* next(value, fns, i);
217
+ return;
218
+ }
219
+ if (value === defs.none) return;
220
+ if (value === defs.stop) throw new defs.Stop();
221
+ if (defs.isFinalValue(value)) {
222
+ yield defs.getFinalValue(value);
223
+ return;
224
+ }
225
+ if (defs.isMany(value) || (value && typeof value.next == 'function')) {
226
+ yield* next(value, fns, i);
227
+ return;
228
+ }
229
+ if (i == fns.length) {
230
+ yield value;
231
+ return;
232
+ }
233
+ value = fns[i](value);
234
+ }
235
+ } else {
236
+ flushed = true;
237
+ for (let i = 0; i < fns.length; ++i) {
238
+ const f = fns[i];
239
+ if (defs.isFlushable(f)) {
240
+ yield* next(f(defs.none), fns, i + 1);
241
+ }
242
+ }
57
243
  }
244
+ };
245
+ const needToFlush = fns.some(fn => defs.isFlushable(fn));
246
+ if (needToFlush) g = defs.flushable(g);
247
+ return defs.setFunctionList(g, fns);
248
+ };
249
+
250
+ gen.exports = gen$1;
251
+
252
+ gen.exports.next = next;
253
+ return gen.exports;
254
+ }
255
+
256
+ var asStream_1;
257
+ var hasRequiredAsStream;
258
+
259
+ function requireAsStream () {
260
+ if (hasRequiredAsStream) return asStream_1;
261
+ hasRequiredAsStream = 1;
262
+
263
+ const {Duplex} = __require$1();
264
+ const defs = requireDefs();
265
+
266
+ const asStream = (fn, options) => {
267
+ if (typeof fn != 'function') throw TypeError('Only a function is accepted as the first argument');
268
+
269
+ // pump variables
270
+ let paused = Promise.resolve(),
271
+ resolvePaused = null;
272
+ const queue = [];
273
+
274
+ // pause/resume
275
+ const resume = () => {
276
+ if (!resolvePaused) return;
277
+ resolvePaused();
278
+ resolvePaused = null;
279
+ paused = Promise.resolve();
280
+ };
281
+ const pause = () => {
282
+ if (resolvePaused) return;
283
+ paused = new Promise(resolve => (resolvePaused = resolve));
284
+ };
285
+
286
+ const innerFns = defs.isFunctionList(fn) ? fn.fList : null;
287
+
288
+ const applyFns = innerFns
289
+ ? function apply(value, i, push) {
290
+ for (;;) {
291
+ if (value && typeof value.then == 'function') return value.then(v => apply(v, i, push));
292
+ if (value === undefined || value === null || value === defs.none) return;
293
+ if (value === defs.stop) throw new defs.Stop();
294
+ if (defs.isFinalValue(value)) {
295
+ push(defs.getFinalValue(value));
296
+ return;
297
+ }
298
+ if (defs.isMany(value)) {
299
+ const values = defs.getManyValues(value);
300
+ if (i >= innerFns.length) {
301
+ for (let j = 0; j < values.length; ++j) push(values[j]);
302
+ return;
303
+ }
304
+ let pending;
305
+ for (let j = 0; j < values.length; ++j) {
306
+ if (pending) {
307
+ const jj = j;
308
+ pending = pending.then(() => apply(values[jj], i, push));
309
+ } else {
310
+ const result = apply(values[j], i, push);
311
+ if (result) pending = result;
312
+ }
313
+ }
314
+ return pending;
315
+ }
316
+ if (value && typeof value.next == 'function') {
317
+ return (async () => {
318
+ for (;;) {
319
+ let data = value.next();
320
+ if (data && typeof data.then == 'function') data = await data;
321
+ if (data.done) break;
322
+ const result = apply(data.value, i, push);
323
+ if (result) await result;
324
+ }
325
+ })();
326
+ }
327
+ if (i >= innerFns.length) {
328
+ push(value);
329
+ return;
330
+ }
331
+ value = innerFns[i++](value);
332
+ }
333
+ }
334
+ : null;
335
+
336
+ let stopped = false;
337
+ let stream = null; // will be assigned later
338
+
339
+ // data processing
340
+ const pushResults = values => {
341
+ if (values && typeof values.next == 'function') {
342
+ // generator
343
+ queue.push(values);
344
+ return;
345
+ }
346
+ // array
347
+ queue.push(values[Symbol.iterator]());
348
+ };
349
+ const pump = async () => {
350
+ while (queue.length) {
351
+ await paused;
352
+ const gen = queue[queue.length - 1];
353
+ let result = gen.next();
354
+ if (result && typeof result.then == 'function') {
355
+ result = await result;
356
+ }
357
+ if (result.done) {
358
+ queue.pop();
359
+ continue;
360
+ }
361
+ let value = result.value;
362
+ if (value && typeof value.then == 'function') {
363
+ value = await value;
364
+ }
365
+ await sanitize(value);
366
+ }
367
+ };
368
+ const sanitize = async value => {
369
+ if (value === undefined || value === null || value === defs.none) return;
370
+ if (value === defs.stop) throw new defs.Stop();
371
+
372
+ if (defs.isMany(value)) {
373
+ pushResults(defs.getManyValues(value));
374
+ return pump();
375
+ }
376
+
377
+ if (defs.isFinalValue(value)) {
378
+ // a final value is not supported, it is treated as a regular value
379
+ value = defs.getFinalValue(value);
380
+ return processValue(value);
381
+ }
382
+
383
+ if (!stream.push(value)) {
384
+ pause();
385
+ }
386
+ };
387
+ const processChunk = async (chunk, encoding) => {
388
+ try {
389
+ const value = fn(chunk, encoding);
390
+ await processValue(value);
391
+ } catch (error) {
392
+ if (error instanceof defs.Stop) {
393
+ stream.push(null);
394
+ stopped = true;
395
+ return;
396
+ }
397
+ throw error;
398
+ }
399
+ };
400
+ const processValue = async value => {
401
+ if (value && typeof value.then == 'function') {
402
+ // thenable
403
+ return value.then(value => processValue(value));
404
+ }
405
+ if (value && typeof value.next == 'function') {
406
+ // generator
407
+ pushResults(value);
408
+ return pump();
409
+ }
410
+ return sanitize(value);
411
+ };
412
+
413
+ stream = new Duplex({
414
+ writableObjectMode: true,
415
+ readableObjectMode: true,
416
+ ...options,
417
+ write(chunk, encoding, callback) {
418
+ if (stopped) {
419
+ callback(null);
420
+ return;
421
+ }
422
+ // fast path for gen() compositions: process inner functions directly
423
+ if (applyFns) {
424
+ let backpressure = false;
425
+ let asyncResult;
426
+ try {
427
+ asyncResult = applyFns(chunk, 0, value => {
428
+ if (!stream.push(value)) backpressure = true;
429
+ });
430
+ } catch (error) {
431
+ if (error instanceof defs.Stop) {
432
+ stream.push(null);
433
+ stopped = true;
434
+ callback(null);
435
+ return;
436
+ }
437
+ callback(error);
438
+ return;
439
+ }
440
+ if (asyncResult) {
441
+ asyncResult.then(
442
+ () => callback(null),
443
+ error => {
444
+ if (error instanceof defs.Stop) {
445
+ stream.push(null);
446
+ stopped = true;
447
+ callback(null);
448
+ return;
449
+ }
450
+ callback(error);
451
+ }
452
+ );
453
+ return;
454
+ }
455
+ if (backpressure) {
456
+ pause();
457
+ paused.then(() => callback(null));
458
+ } else {
459
+ callback(null);
460
+ }
461
+ return;
462
+ }
463
+ let value;
464
+ try {
465
+ value = fn(chunk, encoding);
466
+ } catch (error) {
467
+ if (error instanceof defs.Stop) {
468
+ stream.push(null);
469
+ stopped = true;
470
+ callback(null);
471
+ return;
472
+ }
473
+ callback(error);
474
+ return;
475
+ }
476
+ // sync fast path: plain value (not a promise, generator, or special)
477
+ if (
478
+ !(value && (typeof value.then == 'function' || typeof value.next == 'function')) &&
479
+ value !== defs.stop &&
480
+ !defs.isMany(value) &&
481
+ !defs.isFinalValue(value)
482
+ ) {
483
+ if (value !== undefined && value !== null && value !== defs.none) {
484
+ if (!stream.push(value)) {
485
+ pause();
486
+ paused.then(() => callback(null));
487
+ return;
488
+ }
489
+ }
490
+ callback(null);
491
+ return;
492
+ }
493
+ // async slow path: promises, generators, many, finalValue, stop
494
+ processValue(value).then(
495
+ () => callback(null),
496
+ error => {
497
+ if (error instanceof defs.Stop) {
498
+ stream.push(null);
499
+ stopped = true;
500
+ callback(null);
501
+ return;
502
+ }
503
+ callback(error);
504
+ }
505
+ );
506
+ },
507
+ final(callback) {
508
+ // fast path for gen() compositions: flush inner functions directly
509
+ if (applyFns) {
510
+ let backpressure = false;
511
+ let asyncChain;
512
+ try {
513
+ const pushFn = value => {
514
+ if (!stream.push(value)) backpressure = true;
515
+ };
516
+ for (let i = 0; i < innerFns.length; ++i) {
517
+ if (defs.isFlushable(innerFns[i])) {
518
+ if (asyncChain) {
519
+ const ii = i;
520
+ asyncChain = asyncChain.then(() =>
521
+ applyFns(innerFns[ii](defs.none), ii + 1, pushFn)
522
+ );
523
+ } else {
524
+ const result = applyFns(innerFns[i](defs.none), i + 1, pushFn);
525
+ if (result) asyncChain = result;
526
+ }
527
+ }
528
+ }
529
+ } catch (error) {
530
+ if (error instanceof defs.Stop) {
531
+ stream.push(null);
532
+ stopped = true;
533
+ callback(null);
534
+ return;
535
+ }
536
+ callback(error);
537
+ return;
538
+ }
539
+ if (asyncChain) {
540
+ asyncChain.then(
541
+ () => (stream.push(null), callback(null)),
542
+ error => {
543
+ if (error instanceof defs.Stop) {
544
+ stopped = true;
545
+ stream.push(null);
546
+ callback(null);
547
+ return;
548
+ }
549
+ callback(error);
550
+ }
551
+ );
552
+ return;
553
+ }
554
+ stream.push(null);
555
+ if (backpressure) {
556
+ pause();
557
+ paused.then(() => callback(null));
558
+ } else {
559
+ callback(null);
560
+ }
561
+ return;
562
+ }
563
+ if (!defs.isFlushable(fn)) {
564
+ stream.push(null);
565
+ callback(null);
566
+ return;
567
+ }
568
+ processChunk(defs.none, null).then(
569
+ () => {
570
+ if (!stopped) stream.push(null);
571
+ callback(null);
572
+ },
573
+ error => callback(error)
574
+ );
575
+ },
576
+ read() {
577
+ resume();
578
+ }
579
+ });
580
+
581
+ return stream;
582
+ };
583
+
584
+ asStream_1 = asStream;
585
+ return asStream_1;
586
+ }
587
+
588
+ var hasRequiredSrc$1;
589
+
590
+ function requireSrc$1 () {
591
+ if (hasRequiredSrc$1) return src.exports;
592
+ hasRequiredSrc$1 = 1;
593
+
594
+ const {Readable, Writable, Duplex} = __require$1();
595
+ const defs = requireDefs();
596
+ const gen = requireGen();
597
+ const asStream = requireAsStream();
598
+
599
+ // is*NodeStream functions taken from https://github.com/nodejs/node/blob/master/lib/internal/streams/utils.js
600
+ const isReadableNodeStream = obj =>
601
+ obj &&
602
+ typeof obj.pipe === 'function' &&
603
+ typeof obj.on === 'function' &&
604
+ (!obj._writableState ||
605
+ (typeof obj._readableState === 'object' ? obj._readableState.readable : null) !== false) && // Duplex
606
+ (!obj._writableState || obj._readableState); // Writable has .pipe.
607
+
608
+ const isWritableNodeStream = obj =>
609
+ obj &&
610
+ typeof obj.write === 'function' &&
611
+ typeof obj.on === 'function' &&
612
+ (!obj._readableState ||
613
+ (typeof obj._writableState === 'object' ? obj._writableState.writable : null) !== false); // Duplex
614
+
615
+ const isDuplexNodeStream = obj =>
616
+ obj &&
617
+ typeof obj.pipe === 'function' &&
618
+ obj._readableState &&
619
+ typeof obj.on === 'function' &&
620
+ typeof obj.write === 'function';
621
+
622
+ const isNodeStream = obj => {
623
+ return (
624
+ obj &&
625
+ (obj._readableState ||
626
+ obj._writableState ||
627
+ (typeof obj.write === 'function' && typeof obj.on === 'function') ||
628
+ (typeof obj.pipe === 'function' && typeof obj.on === 'function'))
629
+ );
630
+ };
631
+
632
+ const isReadableWebStream = obj =>
633
+ !!(
634
+ obj &&
635
+ !isNodeStream(obj) &&
636
+ typeof obj.pipeThrough === 'function' &&
637
+ typeof obj.getReader === 'function' &&
638
+ typeof obj.cancel === 'function'
639
+ );
640
+
641
+ const isWritableWebStream = obj =>
642
+ !!(
643
+ obj &&
644
+ !isNodeStream(obj) &&
645
+ typeof obj.getWriter === 'function' &&
646
+ typeof obj.abort === 'function'
647
+ );
648
+
649
+ const isDuplexWebStream = obj =>
650
+ !!(
651
+ obj &&
652
+ !isNodeStream(obj) &&
653
+ typeof obj.readable === 'object' &&
654
+ typeof obj.writable === 'object'
655
+ );
656
+
657
+ const groupFunctions = (output, fn, index, fns) => {
658
+ if (
659
+ isDuplexNodeStream(fn) ||
660
+ (!index && isReadableNodeStream(fn)) ||
661
+ (index === fns.length - 1 && isWritableNodeStream(fn))
662
+ ) {
663
+ output.push(fn);
664
+ return output;
665
+ }
666
+ if (isDuplexWebStream(fn)) {
667
+ output.push(Duplex.fromWeb(fn, {objectMode: true}));
668
+ return output;
669
+ }
670
+ if (!index && isReadableWebStream(fn)) {
671
+ output.push(Readable.fromWeb(fn, {objectMode: true}));
672
+ return output;
58
673
  }
674
+ if (index === fns.length - 1 && isWritableWebStream(fn)) {
675
+ output.push(Writable.fromWeb(fn, {objectMode: true}));
676
+ return output;
677
+ }
678
+ if (typeof fn != 'function')
679
+ throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');
680
+ if (!output.length) output.push([]);
681
+ const last = output[output.length - 1];
682
+ if (Array.isArray(last)) {
683
+ last.push(fn);
684
+ } else {
685
+ output.push([fn]);
686
+ }
687
+ return output;
688
+ };
59
689
 
60
- _flush(callback) {
61
- this._flushInput();
62
- this._processBuffer(callback);
690
+ const produceStreams = item => {
691
+ if (Array.isArray(item)) {
692
+ if (!item.length) return null;
693
+ if (item.length == 1) return item[0] && chain.asStream(item[0]);
694
+ return chain.asStream(chain.gen(...item));
63
695
  }
64
- }
696
+ return item;
697
+ };
698
+
699
+ const wrapFunctions = (fn, index, fns) => {
700
+ if (
701
+ isDuplexNodeStream(fn) ||
702
+ (!index && isReadableNodeStream(fn)) ||
703
+ (index === fns.length - 1 && isWritableNodeStream(fn))
704
+ ) {
705
+ return fn; // an acceptable stream
706
+ }
707
+ if (isDuplexWebStream(fn)) {
708
+ return Duplex.fromWeb(fn, {objectMode: true});
709
+ }
710
+ if (!index && isReadableWebStream(fn)) {
711
+ return Readable.fromWeb(fn, {objectMode: true});
712
+ }
713
+ if (index === fns.length - 1 && isWritableWebStream(fn)) {
714
+ return Writable.fromWeb(fn, {objectMode: true});
715
+ }
716
+ if (typeof fn == 'function') return chain.asStream(fn); // a function
717
+ throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');
718
+ };
719
+
720
+ // default implementation of required stream methods
721
+
722
+ const write = (input, chunk, encoding, callback) => {
723
+ let error = null;
724
+ try {
725
+ input.write(chunk, encoding, e => callback(e || error));
726
+ } catch (e) {
727
+ error = e;
728
+ }
729
+ };
730
+
731
+ const final = (input, callback) => {
732
+ let error = null;
733
+ try {
734
+ input.end(null, null, e => callback(e || error));
735
+ } catch (e) {
736
+ error = e;
737
+ }
738
+ };
739
+
740
+ const read = output => {
741
+ output.resume();
742
+ };
743
+
744
+ // the chain creator
745
+
746
+ const chain = (fns, options) => {
747
+ if (!Array.isArray(fns) || !fns.length) {
748
+ throw TypeError("Chain's first argument should be a non-empty array.");
749
+ }
750
+
751
+ fns = fns.flat(Infinity).filter(fn => fn);
752
+
753
+ const streams = (
754
+ options && options.noGrouping
755
+ ? fns.map(wrapFunctions)
756
+ : fns
757
+ .map(fn => (defs.isFunctionList(fn) ? defs.getFunctionList(fn) : fn))
758
+ .flat(Infinity)
759
+ .reduce(groupFunctions, [])
760
+ .map(produceStreams)
761
+ ).filter(s => s),
762
+ input = streams[0],
763
+ output = streams.reduce((output, item) => (output && output.pipe(item)) || item);
764
+
765
+ let stream = null; // will be assigned later
766
+
767
+ let writeMethod = (chunk, encoding, callback) => write(input, chunk, encoding, callback),
768
+ finalMethod = callback => final(input, callback),
769
+ readMethod = () => read(output);
770
+
771
+ if (!isWritableNodeStream(input)) {
772
+ writeMethod = (_1, _2, callback) => callback(null);
773
+ finalMethod = callback => callback(null);
774
+ input.on('end', () => stream.end());
775
+ }
776
+
777
+ if (isReadableNodeStream(output)) {
778
+ output.on('data', chunk => !stream.push(chunk) && output.pause());
779
+ output.on('end', () => stream.push(null));
780
+ } else {
781
+ readMethod = () => {}; // nop
782
+ output.on('finish', () => stream.push(null));
783
+ }
784
+
785
+ stream = new Duplex({
786
+ writableObjectMode: true,
787
+ readableObjectMode: true,
788
+ ...options,
789
+ readable: isReadableNodeStream(output),
790
+ writable: isWritableNodeStream(input),
791
+ write: writeMethod,
792
+ final: finalMethod,
793
+ read: readMethod
794
+ });
795
+ stream.streams = streams;
796
+ stream.input = input;
797
+ stream.output = output;
798
+
799
+ if (!isReadableNodeStream(output)) {
800
+ stream.resume();
801
+ }
802
+
803
+ // connect events
804
+ if (!options || !options.skipEvents) {
805
+ streams.forEach(item => item.on('error', error => stream.emit('error', error)));
806
+ }
807
+
808
+ return stream;
809
+ };
810
+
811
+ const dataSource = fn => {
812
+ if (typeof fn == 'function') return fn;
813
+ if (fn) {
814
+ if (typeof fn[Symbol.asyncIterator] == 'function') return fn[Symbol.asyncIterator].bind(fn);
815
+ if (typeof fn[Symbol.iterator] == 'function') return fn[Symbol.iterator].bind(fn);
816
+ }
817
+ throw new TypeError('The argument should be a function or an iterable object.');
818
+ };
819
+
820
+ src.exports = chain;
65
821
 
66
- Utf8Stream_1 = Utf8Stream;
67
- return Utf8Stream_1;
822
+ // from defs.js
823
+ src.exports.none = defs.none;
824
+ src.exports.stop = defs.stop;
825
+ src.exports.Stop = defs.Stop;
826
+
827
+ src.exports.finalSymbol = defs.finalSymbol;
828
+ src.exports.finalValue = defs.finalValue;
829
+ src.exports.final = defs.final;
830
+ src.exports.isFinalValue = defs.isFinalValue;
831
+ src.exports.getFinalValue = defs.getFinalValue;
832
+
833
+ src.exports.manySymbol = defs.manySymbol;
834
+ src.exports.many = defs.many;
835
+ src.exports.isMany = defs.isMany;
836
+ src.exports.getManyValues = defs.getManyValues;
837
+
838
+ src.exports.flushSymbol = defs.flushSymbol;
839
+ src.exports.flushable = defs.flushable;
840
+ src.exports.isFlushable = defs.isFlushable;
841
+
842
+ src.exports.fListSymbol = defs.fListSymbol;
843
+ src.exports.isFunctionList = defs.isFunctionList;
844
+ src.exports.getFunctionList = defs.getFunctionList;
845
+ src.exports.setFunctionList = defs.setFunctionList;
846
+ src.exports.clearFunctionList = defs.clearFunctionList;
847
+
848
+ src.exports.toMany = defs.toMany;
849
+ src.exports.normalizeMany = defs.normalizeMany;
850
+ src.exports.combineMany = defs.combineMany;
851
+ src.exports.combineManyMut = defs.combineManyMut;
852
+
853
+ src.exports.chain = chain; // for compatibility with 2.x
854
+ src.exports.chainUnchecked = chain; // for TypeScript to bypass type checks
855
+ src.exports.gen = gen;
856
+ src.exports.asStream = asStream;
857
+
858
+ src.exports.dataSource = dataSource;
859
+ return src.exports;
860
+ }
861
+
862
+ var fixUtf8Stream_1;
863
+ var hasRequiredFixUtf8Stream;
864
+
865
+ function requireFixUtf8Stream () {
866
+ if (hasRequiredFixUtf8Stream) return fixUtf8Stream_1;
867
+ hasRequiredFixUtf8Stream = 1;
868
+
869
+ const {StringDecoder} = require$$0;
870
+
871
+ const {none, flushable} = requireDefs();
872
+
873
+ const fixUtf8Stream = () => {
874
+ const stringDecoder = new StringDecoder();
875
+ let input = '';
876
+ return flushable(chunk => {
877
+ if (chunk === none) {
878
+ const result = input + stringDecoder.end();
879
+ input = '';
880
+ return result;
881
+ }
882
+ if (typeof chunk == 'string') {
883
+ if (!input) return chunk;
884
+ const result = input + chunk;
885
+ input = '';
886
+ return result;
887
+ }
888
+ if (chunk instanceof Buffer) {
889
+ const result = input + stringDecoder.write(chunk);
890
+ input = '';
891
+ return result;
892
+ }
893
+ throw new TypeError('Expected a string or a Buffer');
894
+ });
895
+ };
896
+
897
+ fixUtf8Stream_1 = fixUtf8Stream;
898
+ return fixUtf8Stream_1;
68
899
  }
69
900
 
70
- var Parser_1;
71
901
  var hasRequiredParser;
72
902
 
73
903
  function requireParser () {
74
- if (hasRequiredParser) return Parser_1;
904
+ if (hasRequiredParser) return parser.exports;
75
905
  hasRequiredParser = 1;
76
906
 
77
- const Utf8Stream = requireUtf8Stream();
907
+ const {asStream, flushable, gen, many, none} = requireSrc$1();
908
+ const fixUtf8Stream = requireFixUtf8Stream();
78
909
 
79
910
  const patterns = {
80
- value1: /^(?:[\"\{\[\]\-\d]|true\b|false\b|null\b|\s{1,256})/,
81
- string: /^(?:[^\x00-\x1f\"\\]{1,256}|\\[bfnrt\"\\\/]|\\u[\da-fA-F]{4}|\")/,
82
- key1: /^(?:[\"\}]|\s{1,256})/,
83
- colon: /^(?:\:|\s{1,256})/,
84
- comma: /^(?:[\,\]\}]|\s{1,256})/,
85
- ws: /^\s{1,256}/,
86
- numberStart: /^\d/,
87
- numberDigit: /^\d{0,256}/,
88
- numberFraction: /^[\.eE]/,
89
- numberExponent: /^[eE]/,
90
- numberExpSign: /^[-+]/
911
+ value1: /[\"\{\[\]\-\d]|true\b|false\b|null\b|\s{1,256}/y,
912
+ string: /[^\x00-\x1f\"\\]{1,256}|\\[bfnrt\"\\\/]|\\u[\da-fA-F]{4}|\"/y,
913
+ key1: /[\"\}]|\s{1,256}/y,
914
+ colon: /\:|\s{1,256}/y,
915
+ comma: /[\,\]\}]|\s{1,256}/y,
916
+ ws: /\s{1,256}/y,
917
+ numberStart: /\d/y,
918
+ numberDigit: /\d{0,256}/y,
919
+ numberFraction: /[\.eE]/y,
920
+ numberExponent: /[eE]/y,
921
+ numberExpSign: /[-+]/y
91
922
  };
92
923
  const MAX_PATTERN_SIZE = 16;
93
924
 
94
- let noSticky = true;
95
- try {
96
- new RegExp('.', 'y');
97
- noSticky = false;
98
- } catch (e) {
99
- // suppress
100
- }
101
-
102
- !noSticky &&
103
- Object.keys(patterns).forEach(key => {
104
- let src = patterns[key].source.slice(1); // lop off ^
105
- if (src.slice(0, 3) === '(?:' && src.slice(-1) === ')') {
106
- src = src.slice(3, -1);
107
- }
108
- patterns[key] = new RegExp(src, 'y');
109
- });
110
-
111
925
  patterns.numberFracStart = patterns.numberExpStart = patterns.numberStart;
112
926
  patterns.numberFracDigit = patterns.numberExpDigit = patterns.numberDigit;
113
927
 
114
- const values = {true: true, false: false, null: null},
115
- expected = {object: 'objectStop', array: 'arrayStop', '': 'done'};
928
+ const expected = {object: 'objectStop', array: 'arrayStop', '': 'done'};
929
+
930
+ const tokenStartObject = {name: 'startObject'},
931
+ tokenEndObject = {name: 'endObject'},
932
+ tokenStartArray = {name: 'startArray'},
933
+ tokenEndArray = {name: 'endArray'},
934
+ tokenStartString = {name: 'startString'},
935
+ tokenEndString = {name: 'endString'},
936
+ tokenStartNumber = {name: 'startNumber'},
937
+ tokenEndNumber = {name: 'endNumber'},
938
+ tokenStartKey = {name: 'startKey'},
939
+ tokenEndKey = {name: 'endKey'},
940
+ literalTokens = {
941
+ true: {name: 'trueValue', value: true},
942
+ false: {name: 'falseValue', value: false},
943
+ null: {name: 'nullValue', value: null}
944
+ };
116
945
 
117
946
  // long hexadecimal codes: \uXXXX
118
947
  const fromHex = s => String.fromCharCode(parseInt(s.slice(2), 16));
@@ -120,122 +949,113 @@ function requireParser () {
120
949
  // short codes: \b \f \n \r \t \" \\ \/
121
950
  const codes = {b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', '"': '"', '\\': '\\', '/': '/'};
122
951
 
123
- class Parser extends Utf8Stream {
124
- static make(options) {
125
- return new Parser(options);
952
+ const jsonParser = options => {
953
+ let packKeys = true,
954
+ packStrings = true,
955
+ packNumbers = true,
956
+ streamKeys = true,
957
+ streamStrings = true,
958
+ streamNumbers = true,
959
+ jsonStreaming = false;
960
+
961
+ if (options) {
962
+ 'packValues' in options && (packKeys = packStrings = packNumbers = options.packValues);
963
+ 'packKeys' in options && (packKeys = options.packKeys);
964
+ 'packStrings' in options && (packStrings = options.packStrings);
965
+ 'packNumbers' in options && (packNumbers = options.packNumbers);
966
+ 'streamValues' in options && (streamKeys = streamStrings = streamNumbers = options.streamValues);
967
+ 'streamKeys' in options && (streamKeys = options.streamKeys);
968
+ 'streamStrings' in options && (streamStrings = options.streamStrings);
969
+ 'streamNumbers' in options && (streamNumbers = options.streamNumbers);
970
+ jsonStreaming = options.jsonStreaming;
126
971
  }
127
972
 
128
- constructor(options) {
129
- super(Object.assign({}, options, {readableObjectMode: true}));
973
+ !packKeys && (streamKeys = true);
974
+ !packStrings && (streamStrings = true);
975
+ !packNumbers && (streamNumbers = true);
130
976
 
131
- this._packKeys = this._packStrings = this._packNumbers = this._streamKeys = this._streamStrings = this._streamNumbers = true;
132
- if (options) {
133
- 'packValues' in options && (this._packKeys = this._packStrings = this._packNumbers = options.packValues);
134
- 'packKeys' in options && (this._packKeys = options.packKeys);
135
- 'packStrings' in options && (this._packStrings = options.packStrings);
136
- 'packNumbers' in options && (this._packNumbers = options.packNumbers);
137
- 'streamValues' in options && (this._streamKeys = this._streamStrings = this._streamNumbers = options.streamValues);
138
- 'streamKeys' in options && (this._streamKeys = options.streamKeys);
139
- 'streamStrings' in options && (this._streamStrings = options.streamStrings);
140
- 'streamNumbers' in options && (this._streamNumbers = options.streamNumbers);
141
- this._jsonStreaming = options.jsonStreaming;
142
- }
143
- !this._packKeys && (this._streamKeys = true);
144
- !this._packStrings && (this._streamStrings = true);
145
- !this._packNumbers && (this._streamNumbers = true);
146
-
147
- this._done = false;
148
- this._expect = this._jsonStreaming ? 'done' : 'value';
149
- this._stack = [];
150
- this._parent = '';
151
- this._open_number = false;
152
- this._accumulator = '';
153
- }
154
-
155
- _flush(callback) {
156
- this._done = true;
157
- super._flush(error => {
158
- if (error) return callback(error);
159
- if (this._open_number) {
160
- if (this._streamNumbers) {
161
- this.push({name: 'endNumber'});
162
- }
163
- this._open_number = false;
164
- if (this._packNumbers) {
165
- this.push({name: 'numberValue', value: this._accumulator});
166
- this._accumulator = '';
167
- }
168
- }
169
- callback(null);
170
- });
171
- }
977
+ let done = false,
978
+ expect = jsonStreaming ? 'done' : 'value',
979
+ parent = '',
980
+ openNumber = false,
981
+ accumulator = '',
982
+ buffer = '';
983
+
984
+ const stack = [];
985
+
986
+ return flushable(buf => {
987
+ const tokens = [];
988
+
989
+ if (buf === none) {
990
+ done = true;
991
+ } else {
992
+ buffer += buf;
993
+ }
172
994
 
173
- _processBuffer(callback) {
174
995
  let match,
175
996
  value,
176
997
  index = 0;
998
+
177
999
  main: for (;;) {
178
- switch (this._expect) {
1000
+ switch (expect) {
179
1001
  case 'value1':
180
1002
  case 'value':
181
1003
  patterns.value1.lastIndex = index;
182
- match = patterns.value1.exec(this._buffer);
1004
+ match = patterns.value1.exec(buffer);
183
1005
  if (!match) {
184
- if (this._done || index + MAX_PATTERN_SIZE < this._buffer.length) {
185
- if (index < this._buffer.length) return callback(new Error('Parser cannot parse input: expected a value'));
186
- return callback(new Error('Parser has expected a value'));
1006
+ if (done || index + MAX_PATTERN_SIZE < buffer.length) {
1007
+ if (index < buffer.length) throw new Error('Parser cannot parse input: expected a value');
1008
+ throw new Error('Parser has expected a value');
187
1009
  }
188
1010
  break main; // wait for more input
189
1011
  }
190
1012
  value = match[0];
191
1013
  switch (value) {
192
1014
  case '"':
193
- this._streamStrings && this.push({name: 'startString'});
194
- this._expect = 'string';
1015
+ if (streamStrings) tokens.push(tokenStartString);
1016
+ expect = 'string';
195
1017
  break;
196
1018
  case '{':
197
- this.push({name: 'startObject'});
198
- this._stack.push(this._parent);
199
- this._parent = 'object';
200
- this._expect = 'key1';
1019
+ tokens.push(tokenStartObject);
1020
+ stack.push(parent);
1021
+ parent = 'object';
1022
+ expect = 'key1';
201
1023
  break;
202
1024
  case '[':
203
- this.push({name: 'startArray'});
204
- this._stack.push(this._parent);
205
- this._parent = 'array';
206
- this._expect = 'value1';
1025
+ tokens.push(tokenStartArray);
1026
+ stack.push(parent);
1027
+ parent = 'array';
1028
+ expect = 'value1';
207
1029
  break;
208
1030
  case ']':
209
- if (this._expect !== 'value1') return callback(new Error("Parser cannot parse input: unexpected token ']'"));
210
- if (this._open_number) {
211
- this._streamNumbers && this.push({name: 'endNumber'});
212
- this._open_number = false;
213
- if (this._packNumbers) {
214
- this.push({name: 'numberValue', value: this._accumulator});
215
- this._accumulator = '';
1031
+ if (expect !== 'value1') throw new Error("Parser cannot parse input: unexpected token ']'");
1032
+ if (openNumber) {
1033
+ if (streamNumbers) tokens.push(tokenEndNumber);
1034
+ openNumber = false;
1035
+ if (packNumbers) {
1036
+ tokens.push({name: 'numberValue', value: accumulator});
1037
+ accumulator = '';
216
1038
  }
217
1039
  }
218
- this.push({name: 'endArray'});
219
- this._parent = this._stack.pop();
220
- this._expect = expected[this._parent];
1040
+ tokens.push(tokenEndArray);
1041
+ parent = stack.pop();
1042
+ expect = expected[parent];
221
1043
  break;
222
1044
  case '-':
223
- this._open_number = true;
224
- if (this._streamNumbers) {
225
- this.push({name: 'startNumber'});
226
- this.push({name: 'numberChunk', value: '-'});
1045
+ openNumber = true;
1046
+ if (streamNumbers) {
1047
+ tokens.push(tokenStartNumber, {name: 'numberChunk', value: '-'});
227
1048
  }
228
- this._packNumbers && (this._accumulator = '-');
229
- this._expect = 'numberStart';
1049
+ packNumbers && (accumulator = '-');
1050
+ expect = 'numberStart';
230
1051
  break;
231
1052
  case '0':
232
- this._open_number = true;
233
- if (this._streamNumbers) {
234
- this.push({name: 'startNumber'});
235
- this.push({name: 'numberChunk', value: '0'});
1053
+ openNumber = true;
1054
+ if (streamNumbers) {
1055
+ tokens.push(tokenStartNumber, {name: 'numberChunk', value: '0'});
236
1056
  }
237
- this._packNumbers && (this._accumulator = '0');
238
- this._expect = 'numberFraction';
1057
+ packNumbers && (accumulator = '0');
1058
+ expect = 'numberFraction';
239
1059
  break;
240
1060
  case '1':
241
1061
  case '2':
@@ -246,191 +1066,161 @@ function requireParser () {
246
1066
  case '7':
247
1067
  case '8':
248
1068
  case '9':
249
- this._open_number = true;
250
- if (this._streamNumbers) {
251
- this.push({name: 'startNumber'});
252
- this.push({name: 'numberChunk', value: value});
1069
+ openNumber = true;
1070
+ if (streamNumbers) {
1071
+ tokens.push(tokenStartNumber, {name: 'numberChunk', value});
253
1072
  }
254
- this._packNumbers && (this._accumulator = value);
255
- this._expect = 'numberDigit';
1073
+ packNumbers && (accumulator = value);
1074
+ expect = 'numberDigit';
256
1075
  break;
257
1076
  case 'true':
258
1077
  case 'false':
259
1078
  case 'null':
260
- if (this._buffer.length - index === value.length && !this._done) break main; // wait for more input
261
- this.push({name: value + 'Value', value: values[value]});
262
- this._expect = expected[this._parent];
1079
+ if (buffer.length - index === value.length && !done) break main; // wait for more input
1080
+ tokens.push(literalTokens[value]);
1081
+ expect = expected[parent];
263
1082
  break;
264
1083
  // default: // ws
265
1084
  }
266
- if (noSticky) {
267
- this._buffer = this._buffer.slice(value.length);
268
- } else {
269
- index += value.length;
270
- }
1085
+ index += value.length;
271
1086
  break;
272
1087
  case 'keyVal':
273
1088
  case 'string':
274
1089
  patterns.string.lastIndex = index;
275
- match = patterns.string.exec(this._buffer);
1090
+ match = patterns.string.exec(buffer);
276
1091
  if (!match) {
277
- if (index < this._buffer.length && (this._done || this._buffer.length - index >= 6))
278
- return callback(new Error('Parser cannot parse input: escaped characters'));
279
- if (this._done) return callback(new Error('Parser has expected a string value'));
1092
+ if (index < buffer.length && (done || buffer.length - index >= 6)) throw new Error('Parser cannot parse input: escaped characters');
1093
+ if (done) throw new Error('Parser has expected a string value');
280
1094
  break main; // wait for more input
281
1095
  }
282
1096
  value = match[0];
283
1097
  if (value === '"') {
284
- if (this._expect === 'keyVal') {
285
- this._streamKeys && this.push({name: 'endKey'});
286
- if (this._packKeys) {
287
- this.push({name: 'keyValue', value: this._accumulator});
288
- this._accumulator = '';
1098
+ if (expect === 'keyVal') {
1099
+ if (streamKeys) tokens.push(tokenEndKey);
1100
+ if (packKeys) {
1101
+ tokens.push({name: 'keyValue', value: accumulator});
1102
+ accumulator = '';
289
1103
  }
290
- this._expect = 'colon';
1104
+ expect = 'colon';
291
1105
  } else {
292
- this._streamStrings && this.push({name: 'endString'});
293
- if (this._packStrings) {
294
- this.push({name: 'stringValue', value: this._accumulator});
295
- this._accumulator = '';
1106
+ if (streamStrings) tokens.push(tokenEndString);
1107
+ if (packStrings) {
1108
+ tokens.push({name: 'stringValue', value: accumulator});
1109
+ accumulator = '';
296
1110
  }
297
- this._expect = expected[this._parent];
1111
+ expect = expected[parent];
298
1112
  }
299
1113
  } else if (value.length > 1 && value.charAt(0) === '\\') {
300
1114
  const t = value.length == 2 ? codes[value.charAt(1)] : fromHex(value);
301
- if (this._expect === 'keyVal' ? this._streamKeys : this._streamStrings) {
302
- this.push({name: 'stringChunk', value: t});
1115
+ if (expect === 'keyVal' ? streamKeys : streamStrings) {
1116
+ tokens.push({name: 'stringChunk', value: t});
303
1117
  }
304
- if (this._expect === 'keyVal' ? this._packKeys : this._packStrings) {
305
- this._accumulator += t;
1118
+ if (expect === 'keyVal' ? packKeys : packStrings) {
1119
+ accumulator += t;
306
1120
  }
307
1121
  } else {
308
- if (this._expect === 'keyVal' ? this._streamKeys : this._streamStrings) {
309
- this.push({name: 'stringChunk', value: value});
1122
+ if (expect === 'keyVal' ? streamKeys : streamStrings) {
1123
+ tokens.push({name: 'stringChunk', value});
310
1124
  }
311
- if (this._expect === 'keyVal' ? this._packKeys : this._packStrings) {
312
- this._accumulator += value;
1125
+ if (expect === 'keyVal' ? packKeys : packStrings) {
1126
+ accumulator += value;
313
1127
  }
314
1128
  }
315
- if (noSticky) {
316
- this._buffer = this._buffer.slice(value.length);
317
- } else {
318
- index += value.length;
319
- }
1129
+ index += value.length;
320
1130
  break;
321
1131
  case 'key1':
322
1132
  case 'key':
323
1133
  patterns.key1.lastIndex = index;
324
- match = patterns.key1.exec(this._buffer);
1134
+ match = patterns.key1.exec(buffer);
325
1135
  if (!match) {
326
- if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected an object key'));
1136
+ if (index < buffer.length || done) throw new Error('Parser cannot parse input: expected an object key');
327
1137
  break main; // wait for more input
328
1138
  }
329
1139
  value = match[0];
330
1140
  if (value === '"') {
331
- this._streamKeys && this.push({name: 'startKey'});
332
- this._expect = 'keyVal';
1141
+ if (streamKeys) tokens.push(tokenStartKey);
1142
+ expect = 'keyVal';
333
1143
  } else if (value === '}') {
334
- if (this._expect !== 'key1') return callback(new Error("Parser cannot parse input: unexpected token '}'"));
335
- this.push({name: 'endObject'});
336
- this._parent = this._stack.pop();
337
- this._expect = expected[this._parent];
338
- }
339
- if (noSticky) {
340
- this._buffer = this._buffer.slice(value.length);
341
- } else {
342
- index += value.length;
1144
+ if (expect !== 'key1') throw new Error("Parser cannot parse input: unexpected token '}'");
1145
+ tokens.push(tokenEndObject);
1146
+ parent = stack.pop();
1147
+ expect = expected[parent];
343
1148
  }
1149
+ index += value.length;
344
1150
  break;
345
1151
  case 'colon':
346
1152
  patterns.colon.lastIndex = index;
347
- match = patterns.colon.exec(this._buffer);
1153
+ match = patterns.colon.exec(buffer);
348
1154
  if (!match) {
349
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ':'"));
1155
+ if (index < buffer.length || done) throw new Error("Parser cannot parse input: expected ':'");
350
1156
  break main; // wait for more input
351
1157
  }
352
1158
  value = match[0];
353
- value === ':' && (this._expect = 'value');
354
- if (noSticky) {
355
- this._buffer = this._buffer.slice(value.length);
356
- } else {
357
- index += value.length;
358
- }
1159
+ value === ':' && (expect = 'value');
1160
+ index += value.length;
359
1161
  break;
360
1162
  case 'arrayStop':
361
1163
  case 'objectStop':
362
1164
  patterns.comma.lastIndex = index;
363
- match = patterns.comma.exec(this._buffer);
1165
+ match = patterns.comma.exec(buffer);
364
1166
  if (!match) {
365
- if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ','"));
1167
+ if (index < buffer.length || done) throw new Error("Parser cannot parse input: expected ','");
366
1168
  break main; // wait for more input
367
1169
  }
368
- if (this._open_number) {
369
- this._streamNumbers && this.push({name: 'endNumber'});
370
- this._open_number = false;
371
- if (this._packNumbers) {
372
- this.push({name: 'numberValue', value: this._accumulator});
373
- this._accumulator = '';
1170
+ if (openNumber) {
1171
+ if (streamNumbers) tokens.push(tokenEndNumber);
1172
+ openNumber = false;
1173
+ if (packNumbers) {
1174
+ tokens.push({name: 'numberValue', value: accumulator});
1175
+ accumulator = '';
374
1176
  }
375
1177
  }
376
1178
  value = match[0];
377
1179
  if (value === ',') {
378
- this._expect = this._expect === 'arrayStop' ? 'value' : 'key';
1180
+ expect = expect === 'arrayStop' ? 'value' : 'key';
379
1181
  } else if (value === '}' || value === ']') {
380
- if (value === '}' ? this._expect === 'arrayStop' : this._expect !== 'arrayStop') {
381
- return callback(new Error("Parser cannot parse input: expected '" + (this._expect === 'arrayStop' ? ']' : '}') + "'"));
1182
+ if (value === '}' ? expect === 'arrayStop' : expect !== 'arrayStop') {
1183
+ throw new Error("Parser cannot parse input: expected '" + (expect === 'arrayStop' ? ']' : '}') + "'");
382
1184
  }
383
- this.push({name: value === '}' ? 'endObject' : 'endArray'});
384
- this._parent = this._stack.pop();
385
- this._expect = expected[this._parent];
386
- }
387
- if (noSticky) {
388
- this._buffer = this._buffer.slice(value.length);
389
- } else {
390
- index += value.length;
1185
+ tokens.push(value === '}' ? tokenEndObject : tokenEndArray);
1186
+ parent = stack.pop();
1187
+ expect = expected[parent];
391
1188
  }
1189
+ index += value.length;
392
1190
  break;
393
1191
  // number chunks
394
1192
  case 'numberStart': // [0-9]
395
1193
  patterns.numberStart.lastIndex = index;
396
- match = patterns.numberStart.exec(this._buffer);
1194
+ match = patterns.numberStart.exec(buffer);
397
1195
  if (!match) {
398
- if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a starting digit'));
1196
+ if (index < buffer.length || done) throw new Error('Parser cannot parse input: expected a starting digit');
399
1197
  break main; // wait for more input
400
1198
  }
401
1199
  value = match[0];
402
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
403
- this._packNumbers && (this._accumulator += value);
404
- this._expect = value === '0' ? 'numberFraction' : 'numberDigit';
405
- if (noSticky) {
406
- this._buffer = this._buffer.slice(value.length);
407
- } else {
408
- index += value.length;
409
- }
1200
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1201
+ packNumbers && (accumulator += value);
1202
+ expect = value === '0' ? 'numberFraction' : 'numberDigit';
1203
+ index += value.length;
410
1204
  break;
411
1205
  case 'numberDigit': // [0-9]*
412
1206
  patterns.numberDigit.lastIndex = index;
413
- match = patterns.numberDigit.exec(this._buffer);
1207
+ match = patterns.numberDigit.exec(buffer);
414
1208
  if (!match) {
415
- if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a digit'));
1209
+ if (index < buffer.length || done) throw new Error('Parser cannot parse input: expected a digit');
416
1210
  break main; // wait for more input
417
1211
  }
418
1212
  value = match[0];
419
1213
  if (value) {
420
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
421
- this._packNumbers && (this._accumulator += value);
422
- if (noSticky) {
423
- this._buffer = this._buffer.slice(value.length);
424
- } else {
425
- index += value.length;
426
- }
1214
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1215
+ packNumbers && (accumulator += value);
1216
+ index += value.length;
427
1217
  } else {
428
- if (index < this._buffer.length) {
429
- this._expect = 'numberFraction';
1218
+ if (index < buffer.length) {
1219
+ expect = 'numberFraction';
430
1220
  break;
431
1221
  }
432
- if (this._done) {
433
- this._expect = expected[this._parent];
1222
+ if (done) {
1223
+ expect = expected[parent];
434
1224
  break;
435
1225
  }
436
1226
  break main; // wait for more input
@@ -438,60 +1228,48 @@ function requireParser () {
438
1228
  break;
439
1229
  case 'numberFraction': // [\.eE]?
440
1230
  patterns.numberFraction.lastIndex = index;
441
- match = patterns.numberFraction.exec(this._buffer);
1231
+ match = patterns.numberFraction.exec(buffer);
442
1232
  if (!match) {
443
- if (index < this._buffer.length || this._done) {
444
- this._expect = expected[this._parent];
1233
+ if (index < buffer.length || done) {
1234
+ expect = expected[parent];
445
1235
  break;
446
1236
  }
447
1237
  break main; // wait for more input
448
1238
  }
449
1239
  value = match[0];
450
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
451
- this._packNumbers && (this._accumulator += value);
452
- this._expect = value === '.' ? 'numberFracStart' : 'numberExpSign';
453
- if (noSticky) {
454
- this._buffer = this._buffer.slice(value.length);
455
- } else {
456
- index += value.length;
457
- }
1240
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1241
+ packNumbers && (accumulator += value);
1242
+ expect = value === '.' ? 'numberFracStart' : 'numberExpSign';
1243
+ index += value.length;
458
1244
  break;
459
1245
  case 'numberFracStart': // [0-9]
460
1246
  patterns.numberFracStart.lastIndex = index;
461
- match = patterns.numberFracStart.exec(this._buffer);
1247
+ match = patterns.numberFracStart.exec(buffer);
462
1248
  if (!match) {
463
- if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a fractional part of a number'));
1249
+ if (index < buffer.length || done) throw new Error('Parser cannot parse input: expected a fractional part of a number');
464
1250
  break main; // wait for more input
465
1251
  }
466
1252
  value = match[0];
467
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
468
- this._packNumbers && (this._accumulator += value);
469
- this._expect = 'numberFracDigit';
470
- if (noSticky) {
471
- this._buffer = this._buffer.slice(value.length);
472
- } else {
473
- index += value.length;
474
- }
1253
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1254
+ packNumbers && (accumulator += value);
1255
+ expect = 'numberFracDigit';
1256
+ index += value.length;
475
1257
  break;
476
1258
  case 'numberFracDigit': // [0-9]*
477
1259
  patterns.numberFracDigit.lastIndex = index;
478
- match = patterns.numberFracDigit.exec(this._buffer);
1260
+ match = patterns.numberFracDigit.exec(buffer);
479
1261
  value = match[0];
480
1262
  if (value) {
481
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
482
- this._packNumbers && (this._accumulator += value);
483
- if (noSticky) {
484
- this._buffer = this._buffer.slice(value.length);
485
- } else {
486
- index += value.length;
487
- }
1263
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1264
+ packNumbers && (accumulator += value);
1265
+ index += value.length;
488
1266
  } else {
489
- if (index < this._buffer.length) {
490
- this._expect = 'numberExponent';
1267
+ if (index < buffer.length) {
1268
+ expect = 'numberExponent';
491
1269
  break;
492
1270
  }
493
- if (this._done) {
494
- this._expect = expected[this._parent];
1271
+ if (done) {
1272
+ expect = expected[parent];
495
1273
  break;
496
1274
  }
497
1275
  break main; // wait for more input
@@ -499,81 +1277,65 @@ function requireParser () {
499
1277
  break;
500
1278
  case 'numberExponent': // [eE]?
501
1279
  patterns.numberExponent.lastIndex = index;
502
- match = patterns.numberExponent.exec(this._buffer);
1280
+ match = patterns.numberExponent.exec(buffer);
503
1281
  if (!match) {
504
- if (index < this._buffer.length) {
505
- this._expect = expected[this._parent];
1282
+ if (index < buffer.length) {
1283
+ expect = expected[parent];
506
1284
  break;
507
1285
  }
508
- if (this._done) {
509
- this._expect = 'done';
1286
+ if (done) {
1287
+ expect = expected[parent];
510
1288
  break;
511
1289
  }
512
1290
  break main; // wait for more input
513
1291
  }
514
1292
  value = match[0];
515
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
516
- this._packNumbers && (this._accumulator += value);
517
- this._expect = 'numberExpSign';
518
- if (noSticky) {
519
- this._buffer = this._buffer.slice(value.length);
520
- } else {
521
- index += value.length;
522
- }
1293
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1294
+ packNumbers && (accumulator += value);
1295
+ expect = 'numberExpSign';
1296
+ index += value.length;
523
1297
  break;
524
1298
  case 'numberExpSign': // [-+]?
525
1299
  patterns.numberExpSign.lastIndex = index;
526
- match = patterns.numberExpSign.exec(this._buffer);
1300
+ match = patterns.numberExpSign.exec(buffer);
527
1301
  if (!match) {
528
- if (index < this._buffer.length) {
529
- this._expect = 'numberExpStart';
1302
+ if (index < buffer.length) {
1303
+ expect = 'numberExpStart';
530
1304
  break;
531
1305
  }
532
- if (this._done) return callback(new Error('Parser has expected an exponent value of a number'));
1306
+ if (done) throw new Error('Parser has expected an exponent value of a number');
533
1307
  break main; // wait for more input
534
1308
  }
535
1309
  value = match[0];
536
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
537
- this._packNumbers && (this._accumulator += value);
538
- this._expect = 'numberExpStart';
539
- if (noSticky) {
540
- this._buffer = this._buffer.slice(value.length);
541
- } else {
542
- index += value.length;
543
- }
1310
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1311
+ packNumbers && (accumulator += value);
1312
+ expect = 'numberExpStart';
1313
+ index += value.length;
544
1314
  break;
545
1315
  case 'numberExpStart': // [0-9]
546
1316
  patterns.numberExpStart.lastIndex = index;
547
- match = patterns.numberExpStart.exec(this._buffer);
1317
+ match = patterns.numberExpStart.exec(buffer);
548
1318
  if (!match) {
549
- if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected an exponent part of a number'));
1319
+ if (index < buffer.length || done) throw new Error('Parser cannot parse input: expected an exponent part of a number');
550
1320
  break main; // wait for more input
551
1321
  }
552
1322
  value = match[0];
553
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
554
- this._packNumbers && (this._accumulator += value);
555
- this._expect = 'numberExpDigit';
556
- if (noSticky) {
557
- this._buffer = this._buffer.slice(value.length);
558
- } else {
559
- index += value.length;
560
- }
1323
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1324
+ packNumbers && (accumulator += value);
1325
+ expect = 'numberExpDigit';
1326
+ index += value.length;
561
1327
  break;
562
1328
  case 'numberExpDigit': // [0-9]*
563
1329
  patterns.numberExpDigit.lastIndex = index;
564
- match = patterns.numberExpDigit.exec(this._buffer);
1330
+ match = patterns.numberExpDigit.exec(buffer);
565
1331
  value = match[0];
566
1332
  if (value) {
567
- this._streamNumbers && this.push({name: 'numberChunk', value: value});
568
- this._packNumbers && (this._accumulator += value);
569
- if (noSticky) {
570
- this._buffer = this._buffer.slice(value.length);
571
- } else {
572
- index += value.length;
573
- }
1333
+ if (streamNumbers) tokens.push({name: 'numberChunk', value});
1334
+ packNumbers && (accumulator += value);
1335
+ index += value.length;
574
1336
  } else {
575
- if (index < this._buffer.length || this._done) {
576
- this._expect = expected[this._parent];
1337
+ if (index < buffer.length || done) {
1338
+ expect = expected[parent];
577
1339
  break;
578
1340
  }
579
1341
  break main; // wait for more input
@@ -581,43 +1343,58 @@ function requireParser () {
581
1343
  break;
582
1344
  case 'done':
583
1345
  patterns.ws.lastIndex = index;
584
- match = patterns.ws.exec(this._buffer);
1346
+ match = patterns.ws.exec(buffer);
585
1347
  if (!match) {
586
- if (index < this._buffer.length) {
587
- if (this._jsonStreaming) {
588
- this._expect = 'value';
1348
+ if (index < buffer.length) {
1349
+ if (jsonStreaming) {
1350
+ if (openNumber) {
1351
+ if (streamNumbers) tokens.push(tokenEndNumber);
1352
+ openNumber = false;
1353
+ if (packNumbers) {
1354
+ tokens.push({name: 'numberValue', value: accumulator});
1355
+ accumulator = '';
1356
+ }
1357
+ }
1358
+ expect = 'value';
589
1359
  break;
590
1360
  }
591
- return callback(new Error('Parser cannot parse input: unexpected characters'));
1361
+ throw new Error('Parser cannot parse input: unexpected characters');
592
1362
  }
593
1363
  break main; // wait for more input
594
1364
  }
595
1365
  value = match[0];
596
- if (this._open_number) {
597
- this._streamNumbers && this.push({name: 'endNumber'});
598
- this._open_number = false;
599
- if (this._packNumbers) {
600
- this.push({name: 'numberValue', value: this._accumulator});
601
- this._accumulator = '';
1366
+ if (openNumber) {
1367
+ if (streamNumbers) tokens.push(tokenEndNumber);
1368
+ openNumber = false;
1369
+ if (packNumbers) {
1370
+ tokens.push({name: 'numberValue', value: accumulator});
1371
+ accumulator = '';
602
1372
  }
603
1373
  }
604
- if (noSticky) {
605
- this._buffer = this._buffer.slice(value.length);
606
- } else {
607
- index += value.length;
608
- }
1374
+ index += value.length;
609
1375
  break;
610
1376
  }
611
1377
  }
612
- !noSticky && (this._buffer = this._buffer.slice(index));
613
- callback(null);
614
- }
615
- }
616
- Parser.parser = Parser.make;
617
- Parser.make.Constructor = Parser;
1378
+ if (done && openNumber) {
1379
+ if (streamNumbers) tokens.push(tokenEndNumber);
1380
+ openNumber = false;
1381
+ if (packNumbers) {
1382
+ tokens.push({name: 'numberValue', value: accumulator});
1383
+ accumulator = '';
1384
+ }
1385
+ }
1386
+ buffer = buffer.slice(index);
1387
+ return tokens.length ? many(tokens) : none;
1388
+ });
1389
+ };
1390
+
1391
+ const parser$1 = options => gen(fixUtf8Stream(), jsonParser(options));
618
1392
 
619
- Parser_1 = Parser;
620
- return Parser_1;
1393
+ parser$1.asStream = options => asStream(parser$1(options), options);
1394
+
1395
+ parser.exports = parser$1;
1396
+ parser.exports.parser = parser$1; // for backward compatibility with 1.x
1397
+ return parser.exports;
621
1398
  }
622
1399
 
623
1400
  var emit_1;
@@ -633,36 +1410,38 @@ function requireEmit () {
633
1410
  return emit_1;
634
1411
  }
635
1412
 
636
- var streamJson;
637
- var hasRequiredStreamJson;
1413
+ var hasRequiredSrc;
638
1414
 
639
- function requireStreamJson () {
640
- if (hasRequiredStreamJson) return streamJson;
641
- hasRequiredStreamJson = 1;
1415
+ function requireSrc () {
1416
+ if (hasRequiredSrc) return src$1.exports;
1417
+ hasRequiredSrc = 1;
642
1418
 
643
- const Parser = requireParser();
1419
+ const parser = requireParser();
644
1420
  const emit = requireEmit();
645
1421
 
646
- const make = options => emit(new Parser(options));
647
-
648
- make.Parser = Parser;
649
- make.parser = Parser.parser;
1422
+ const make = options => emit(parser.asStream(options));
650
1423
 
651
- streamJson = make;
652
- return streamJson;
1424
+ src$1.exports = make;
1425
+ src$1.exports.parser = parser;
1426
+ return src$1.exports;
653
1427
  }
654
1428
 
655
- var streamJsonExports = requireStreamJson();
656
- const StreamJSON = /*@__PURE__*/getDefaultExportFromCjs(streamJsonExports);
1429
+ var srcExports = requireSrc();
1430
+ const StreamJSON = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
1431
+
1432
+ var assembler = {exports: {}};
1433
+
1434
+ const require$1 = createRequire(import.meta.url);
1435
+ function __require() { return require$1("node:events"); }
657
1436
 
658
- var Assembler_1;
659
1437
  var hasRequiredAssembler;
660
1438
 
661
1439
  function requireAssembler () {
662
- if (hasRequiredAssembler) return Assembler_1;
1440
+ if (hasRequiredAssembler) return assembler.exports;
663
1441
  hasRequiredAssembler = 1;
664
1442
 
665
- const EventEmitter = require$$0$1;
1443
+ const EventEmitter = __require();
1444
+ const {none} = requireSrc$1();
666
1445
 
667
1446
  const startObject = Ctr =>
668
1447
  function () {
@@ -694,6 +1473,14 @@ function requireAssembler () {
694
1473
  this.numberValue = this.stringValue;
695
1474
  }
696
1475
  }
1476
+
1477
+ this.tapChain = chunk => {
1478
+ if (this[chunk.name]) {
1479
+ this[chunk.name](chunk.value);
1480
+ if (this.done) return this.current;
1481
+ }
1482
+ return none;
1483
+ };
697
1484
  }
698
1485
 
699
1486
  connectTo(stream) {
@@ -721,7 +1508,7 @@ function requireAssembler () {
721
1508
 
722
1509
  dropToLevel(level) {
723
1510
  if (level < this.depth) {
724
- if (level) {
1511
+ if (level > 0) {
725
1512
  const index = (level - 1) << 1;
726
1513
  this.current = this.stack[index];
727
1514
  this.key = this.stack[index + 1];
@@ -768,6 +1555,9 @@ function requireAssembler () {
768
1555
  this.current = this.stack.pop();
769
1556
  this._saveValue(value);
770
1557
  } else {
1558
+ if (this.reviver) {
1559
+ this.current = this.reviver.call({'': this.current}, '', this.current);
1560
+ }
771
1561
  this.done = true;
772
1562
  }
773
1563
  }
@@ -778,32 +1568,34 @@ function requireAssembler () {
778
1568
  _saveValue(value) {
779
1569
  if (this.done) {
780
1570
  this.current = value;
1571
+ return;
1572
+ }
1573
+ if (this.current instanceof Array) {
1574
+ this.current.push(value);
781
1575
  } else {
782
- if (this.current instanceof Array) {
783
- this.current.push(value);
784
- } else {
785
- this.current[this.key] = value;
786
- this.key = null;
787
- }
1576
+ this.current[this.key] = value;
1577
+ this.key = null;
788
1578
  }
789
1579
  }
790
1580
  _saveValueWithReviver(value) {
791
1581
  if (this.done) {
792
- this.current = this.reviver('', value);
793
- } else {
794
- if (this.current instanceof Array) {
795
- value = this.reviver('' + this.current.length, value);
796
- this.current.push(value);
797
- if (value === undefined) {
798
- delete this.current[this.current.length - 1];
799
- }
1582
+ this.current = this.reviver.call({'': value}, '', value);
1583
+ return;
1584
+ }
1585
+ if (this.current instanceof Array) {
1586
+ this.current.push(value);
1587
+ value = this.reviver.call(this.current, String(this.current.length - 1), value);
1588
+ if (value === undefined) {
1589
+ delete this.current[this.current.length - 1];
800
1590
  } else {
801
- value = this.reviver(this.key, value);
802
- if (value !== undefined) {
803
- this.current[this.key] = value;
804
- }
805
- this.key = null;
1591
+ this.current[this.current.length - 1] = value;
1592
+ }
1593
+ } else {
1594
+ value = this.reviver.call(this.current, this.key, value);
1595
+ if (value !== undefined) {
1596
+ this.current[this.key] = value;
806
1597
  }
1598
+ this.key = null;
807
1599
  }
808
1600
  }
809
1601
  }
@@ -813,22 +1605,24 @@ function requireAssembler () {
813
1605
  Assembler.prototype.startArray = startObject(Array);
814
1606
  Assembler.prototype.endArray = Assembler.prototype.endObject;
815
1607
 
816
- Assembler_1 = Assembler;
817
- return Assembler_1;
1608
+ assembler.exports = Assembler;
1609
+ assembler.exports.assembler = options => new Assembler(options);
1610
+ return assembler.exports;
818
1611
  }
819
1612
 
820
- var AssemblerExports = requireAssembler();
821
- const Assembler = /*@__PURE__*/getDefaultExportFromCjs(AssemblerExports);
1613
+ var assemblerExports = requireAssembler();
1614
+ const Assembler = /*@__PURE__*/getDefaultExportFromCjs(assemblerExports);
822
1615
 
823
1616
  class JsonParseStreamError extends Error {
824
1617
  constructor(message, data) {
825
1618
  super(message);
826
1619
  this.data = data;
827
1620
  }
1621
+ data;
828
1622
  }
829
1623
  function parseJsonStream(stream) {
830
1624
  const assembler = new Assembler();
831
- const parser = StreamJSON.parser();
1625
+ const parser = StreamJSON.parser.asStream();
832
1626
  return new Promise((resolve) => {
833
1627
  parser.on("data", (chunk) => {
834
1628
  assembler[chunk.name]?.(chunk.value);
@@ -841,7 +1635,7 @@ function parseJsonStream(stream) {
841
1635
  }
842
1636
  function parseJsonStreamWithConcatArrays(stream, sourceName) {
843
1637
  const assembler = new Assembler();
844
- const parser = StreamJSON.parser({
1638
+ const parser = StreamJSON.parser.asStream({
845
1639
  jsonStreaming: true
846
1640
  });
847
1641
  const values = [];