@getcronit/pylon 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3428 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __require = (id) => {
20
+ return import.meta.require(id);
21
+ };
22
+
23
+ // /Users/schettn/Documents/pylon/node_modules/safe-buffer/index.js
24
+ var require_safe_buffer = __commonJS((exports, module) => {
25
+ var copyProps = function(src, dst) {
26
+ for (var key in src) {
27
+ dst[key] = src[key];
28
+ }
29
+ };
30
+ var SafeBuffer = function(arg, encodingOrOffset, length) {
31
+ return Buffer(arg, encodingOrOffset, length);
32
+ };
33
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
34
+ var buffer = import.meta.require("buffer");
35
+ var Buffer = buffer.Buffer;
36
+ if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
37
+ module.exports = buffer;
38
+ } else {
39
+ copyProps(buffer, exports);
40
+ exports.Buffer = SafeBuffer;
41
+ }
42
+ SafeBuffer.prototype = Object.create(Buffer.prototype);
43
+ copyProps(Buffer, SafeBuffer);
44
+ SafeBuffer.from = function(arg, encodingOrOffset, length) {
45
+ if (typeof arg === "number") {
46
+ throw new TypeError("Argument must not be a number");
47
+ }
48
+ return Buffer(arg, encodingOrOffset, length);
49
+ };
50
+ SafeBuffer.alloc = function(size, fill, encoding) {
51
+ if (typeof size !== "number") {
52
+ throw new TypeError("Argument must be a number");
53
+ }
54
+ var buf = Buffer(size);
55
+ if (fill !== undefined) {
56
+ if (typeof encoding === "string") {
57
+ buf.fill(fill, encoding);
58
+ } else {
59
+ buf.fill(fill);
60
+ }
61
+ } else {
62
+ buf.fill(0);
63
+ }
64
+ return buf;
65
+ };
66
+ SafeBuffer.allocUnsafe = function(size) {
67
+ if (typeof size !== "number") {
68
+ throw new TypeError("Argument must be a number");
69
+ }
70
+ return Buffer(size);
71
+ };
72
+ SafeBuffer.allocUnsafeSlow = function(size) {
73
+ if (typeof size !== "number") {
74
+ throw new TypeError("Argument must be a number");
75
+ }
76
+ return buffer.SlowBuffer(size);
77
+ };
78
+ });
79
+
80
+ // /Users/schettn/Documents/pylon/node_modules/string_decoder/lib/string_decoder.js
81
+ var require_string_decoder = __commonJS((exports) => {
82
+ var _normalizeEncoding = function(enc) {
83
+ if (!enc)
84
+ return "utf8";
85
+ var retried;
86
+ while (true) {
87
+ switch (enc) {
88
+ case "utf8":
89
+ case "utf-8":
90
+ return "utf8";
91
+ case "ucs2":
92
+ case "ucs-2":
93
+ case "utf16le":
94
+ case "utf-16le":
95
+ return "utf16le";
96
+ case "latin1":
97
+ case "binary":
98
+ return "latin1";
99
+ case "base64":
100
+ case "ascii":
101
+ case "hex":
102
+ return enc;
103
+ default:
104
+ if (retried)
105
+ return;
106
+ enc = ("" + enc).toLowerCase();
107
+ retried = true;
108
+ }
109
+ }
110
+ };
111
+ var normalizeEncoding = function(enc) {
112
+ var nenc = _normalizeEncoding(enc);
113
+ if (typeof nenc !== "string" && (Buffer.isEncoding === isEncoding || !isEncoding(enc)))
114
+ throw new Error("Unknown encoding: " + enc);
115
+ return nenc || enc;
116
+ };
117
+ var StringDecoder = function(encoding) {
118
+ this.encoding = normalizeEncoding(encoding);
119
+ var nb;
120
+ switch (this.encoding) {
121
+ case "utf16le":
122
+ this.text = utf16Text;
123
+ this.end = utf16End;
124
+ nb = 4;
125
+ break;
126
+ case "utf8":
127
+ this.fillLast = utf8FillLast;
128
+ nb = 4;
129
+ break;
130
+ case "base64":
131
+ this.text = base64Text;
132
+ this.end = base64End;
133
+ nb = 3;
134
+ break;
135
+ default:
136
+ this.write = simpleWrite;
137
+ this.end = simpleEnd;
138
+ return;
139
+ }
140
+ this.lastNeed = 0;
141
+ this.lastTotal = 0;
142
+ this.lastChar = Buffer.allocUnsafe(nb);
143
+ };
144
+ var utf8CheckByte = function(byte) {
145
+ if (byte <= 127)
146
+ return 0;
147
+ else if (byte >> 5 === 6)
148
+ return 2;
149
+ else if (byte >> 4 === 14)
150
+ return 3;
151
+ else if (byte >> 3 === 30)
152
+ return 4;
153
+ return byte >> 6 === 2 ? -1 : -2;
154
+ };
155
+ var utf8CheckIncomplete = function(self2, buf, i) {
156
+ var j = buf.length - 1;
157
+ if (j < i)
158
+ return 0;
159
+ var nb = utf8CheckByte(buf[j]);
160
+ if (nb >= 0) {
161
+ if (nb > 0)
162
+ self2.lastNeed = nb - 1;
163
+ return nb;
164
+ }
165
+ if (--j < i || nb === -2)
166
+ return 0;
167
+ nb = utf8CheckByte(buf[j]);
168
+ if (nb >= 0) {
169
+ if (nb > 0)
170
+ self2.lastNeed = nb - 2;
171
+ return nb;
172
+ }
173
+ if (--j < i || nb === -2)
174
+ return 0;
175
+ nb = utf8CheckByte(buf[j]);
176
+ if (nb >= 0) {
177
+ if (nb > 0) {
178
+ if (nb === 2)
179
+ nb = 0;
180
+ else
181
+ self2.lastNeed = nb - 3;
182
+ }
183
+ return nb;
184
+ }
185
+ return 0;
186
+ };
187
+ var utf8CheckExtraBytes = function(self2, buf, p) {
188
+ if ((buf[0] & 192) !== 128) {
189
+ self2.lastNeed = 0;
190
+ return "\uFFFD";
191
+ }
192
+ if (self2.lastNeed > 1 && buf.length > 1) {
193
+ if ((buf[1] & 192) !== 128) {
194
+ self2.lastNeed = 1;
195
+ return "\uFFFD";
196
+ }
197
+ if (self2.lastNeed > 2 && buf.length > 2) {
198
+ if ((buf[2] & 192) !== 128) {
199
+ self2.lastNeed = 2;
200
+ return "\uFFFD";
201
+ }
202
+ }
203
+ }
204
+ };
205
+ var utf8FillLast = function(buf) {
206
+ var p = this.lastTotal - this.lastNeed;
207
+ var r = utf8CheckExtraBytes(this, buf, p);
208
+ if (r !== undefined)
209
+ return r;
210
+ if (this.lastNeed <= buf.length) {
211
+ buf.copy(this.lastChar, p, 0, this.lastNeed);
212
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
213
+ }
214
+ buf.copy(this.lastChar, p, 0, buf.length);
215
+ this.lastNeed -= buf.length;
216
+ };
217
+ var utf8Text = function(buf, i) {
218
+ var total = utf8CheckIncomplete(this, buf, i);
219
+ if (!this.lastNeed)
220
+ return buf.toString("utf8", i);
221
+ this.lastTotal = total;
222
+ var end = buf.length - (total - this.lastNeed);
223
+ buf.copy(this.lastChar, 0, end);
224
+ return buf.toString("utf8", i, end);
225
+ };
226
+ var utf8End = function(buf) {
227
+ var r = buf && buf.length ? this.write(buf) : "";
228
+ if (this.lastNeed)
229
+ return r + "\uFFFD";
230
+ return r;
231
+ };
232
+ var utf16Text = function(buf, i) {
233
+ if ((buf.length - i) % 2 === 0) {
234
+ var r = buf.toString("utf16le", i);
235
+ if (r) {
236
+ var c = r.charCodeAt(r.length - 1);
237
+ if (c >= 55296 && c <= 56319) {
238
+ this.lastNeed = 2;
239
+ this.lastTotal = 4;
240
+ this.lastChar[0] = buf[buf.length - 2];
241
+ this.lastChar[1] = buf[buf.length - 1];
242
+ return r.slice(0, -1);
243
+ }
244
+ }
245
+ return r;
246
+ }
247
+ this.lastNeed = 1;
248
+ this.lastTotal = 2;
249
+ this.lastChar[0] = buf[buf.length - 1];
250
+ return buf.toString("utf16le", i, buf.length - 1);
251
+ };
252
+ var utf16End = function(buf) {
253
+ var r = buf && buf.length ? this.write(buf) : "";
254
+ if (this.lastNeed) {
255
+ var end = this.lastTotal - this.lastNeed;
256
+ return r + this.lastChar.toString("utf16le", 0, end);
257
+ }
258
+ return r;
259
+ };
260
+ var base64Text = function(buf, i) {
261
+ var n = (buf.length - i) % 3;
262
+ if (n === 0)
263
+ return buf.toString("base64", i);
264
+ this.lastNeed = 3 - n;
265
+ this.lastTotal = 3;
266
+ if (n === 1) {
267
+ this.lastChar[0] = buf[buf.length - 1];
268
+ } else {
269
+ this.lastChar[0] = buf[buf.length - 2];
270
+ this.lastChar[1] = buf[buf.length - 1];
271
+ }
272
+ return buf.toString("base64", i, buf.length - n);
273
+ };
274
+ var base64End = function(buf) {
275
+ var r = buf && buf.length ? this.write(buf) : "";
276
+ if (this.lastNeed)
277
+ return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
278
+ return r;
279
+ };
280
+ var simpleWrite = function(buf) {
281
+ return buf.toString(this.encoding);
282
+ };
283
+ var simpleEnd = function(buf) {
284
+ return buf && buf.length ? this.write(buf) : "";
285
+ };
286
+ var Buffer = require_safe_buffer().Buffer;
287
+ var isEncoding = Buffer.isEncoding || function(encoding) {
288
+ encoding = "" + encoding;
289
+ switch (encoding && encoding.toLowerCase()) {
290
+ case "hex":
291
+ case "utf8":
292
+ case "utf-8":
293
+ case "ascii":
294
+ case "binary":
295
+ case "base64":
296
+ case "ucs2":
297
+ case "ucs-2":
298
+ case "utf16le":
299
+ case "utf-16le":
300
+ case "raw":
301
+ return true;
302
+ default:
303
+ return false;
304
+ }
305
+ };
306
+ exports.StringDecoder = StringDecoder;
307
+ StringDecoder.prototype.write = function(buf) {
308
+ if (buf.length === 0)
309
+ return "";
310
+ var r;
311
+ var i;
312
+ if (this.lastNeed) {
313
+ r = this.fillLast(buf);
314
+ if (r === undefined)
315
+ return "";
316
+ i = this.lastNeed;
317
+ this.lastNeed = 0;
318
+ } else {
319
+ i = 0;
320
+ }
321
+ if (i < buf.length)
322
+ return r ? r + this.text(buf, i) : this.text(buf, i);
323
+ return r || "";
324
+ };
325
+ StringDecoder.prototype.end = utf8End;
326
+ StringDecoder.prototype.text = utf8Text;
327
+ StringDecoder.prototype.fillLast = function(buf) {
328
+ if (this.lastNeed <= buf.length) {
329
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
330
+ return this.lastChar.toString(this.encoding, 0, this.lastTotal);
331
+ }
332
+ buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
333
+ this.lastNeed -= buf.length;
334
+ };
335
+ });
336
+
337
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/buffer_list.js
338
+ var require_buffer_list = __commonJS((exports, module) => {
339
+ var ownKeys = function(object, enumerableOnly) {
340
+ var keys = Object.keys(object);
341
+ if (Object.getOwnPropertySymbols) {
342
+ var symbols = Object.getOwnPropertySymbols(object);
343
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
344
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
345
+ })), keys.push.apply(keys, symbols);
346
+ }
347
+ return keys;
348
+ };
349
+ var _objectSpread = function(target) {
350
+ for (var i = 1;i < arguments.length; i++) {
351
+ var source = arguments[i] != null ? arguments[i] : {};
352
+ i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
353
+ _defineProperty(target, key, source[key]);
354
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
355
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
356
+ });
357
+ }
358
+ return target;
359
+ };
360
+ var _defineProperty = function(obj, key, value) {
361
+ key = _toPropertyKey(key);
362
+ if (key in obj) {
363
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
364
+ } else {
365
+ obj[key] = value;
366
+ }
367
+ return obj;
368
+ };
369
+ var _classCallCheck = function(instance, Constructor) {
370
+ if (!(instance instanceof Constructor)) {
371
+ throw new TypeError("Cannot call a class as a function");
372
+ }
373
+ };
374
+ var _defineProperties = function(target, props) {
375
+ for (var i = 0;i < props.length; i++) {
376
+ var descriptor = props[i];
377
+ descriptor.enumerable = descriptor.enumerable || false;
378
+ descriptor.configurable = true;
379
+ if ("value" in descriptor)
380
+ descriptor.writable = true;
381
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
382
+ }
383
+ };
384
+ var _createClass = function(Constructor, protoProps, staticProps) {
385
+ if (protoProps)
386
+ _defineProperties(Constructor.prototype, protoProps);
387
+ if (staticProps)
388
+ _defineProperties(Constructor, staticProps);
389
+ Object.defineProperty(Constructor, "prototype", { writable: false });
390
+ return Constructor;
391
+ };
392
+ var _toPropertyKey = function(arg) {
393
+ var key = _toPrimitive(arg, "string");
394
+ return typeof key === "symbol" ? key : String(key);
395
+ };
396
+ var _toPrimitive = function(input, hint) {
397
+ if (typeof input !== "object" || input === null)
398
+ return input;
399
+ var prim = input[Symbol.toPrimitive];
400
+ if (prim !== undefined) {
401
+ var res = prim.call(input, hint || "default");
402
+ if (typeof res !== "object")
403
+ return res;
404
+ throw new TypeError("@@toPrimitive must return a primitive value.");
405
+ }
406
+ return (hint === "string" ? String : Number)(input);
407
+ };
408
+ var copyBuffer = function(src, target, offset) {
409
+ Buffer.prototype.copy.call(src, target, offset);
410
+ };
411
+ var _require = import.meta.require("buffer");
412
+ var Buffer = _require.Buffer;
413
+ var _require2 = import.meta.require("util");
414
+ var inspect = _require2.inspect;
415
+ var custom = inspect && inspect.custom || "inspect";
416
+ module.exports = function() {
417
+ function BufferList() {
418
+ _classCallCheck(this, BufferList);
419
+ this.head = null;
420
+ this.tail = null;
421
+ this.length = 0;
422
+ }
423
+ _createClass(BufferList, [{
424
+ key: "push",
425
+ value: function push(v) {
426
+ var entry = {
427
+ data: v,
428
+ next: null
429
+ };
430
+ if (this.length > 0)
431
+ this.tail.next = entry;
432
+ else
433
+ this.head = entry;
434
+ this.tail = entry;
435
+ ++this.length;
436
+ }
437
+ }, {
438
+ key: "unshift",
439
+ value: function unshift(v) {
440
+ var entry = {
441
+ data: v,
442
+ next: this.head
443
+ };
444
+ if (this.length === 0)
445
+ this.tail = entry;
446
+ this.head = entry;
447
+ ++this.length;
448
+ }
449
+ }, {
450
+ key: "shift",
451
+ value: function shift() {
452
+ if (this.length === 0)
453
+ return;
454
+ var ret = this.head.data;
455
+ if (this.length === 1)
456
+ this.head = this.tail = null;
457
+ else
458
+ this.head = this.head.next;
459
+ --this.length;
460
+ return ret;
461
+ }
462
+ }, {
463
+ key: "clear",
464
+ value: function clear() {
465
+ this.head = this.tail = null;
466
+ this.length = 0;
467
+ }
468
+ }, {
469
+ key: "join",
470
+ value: function join(s) {
471
+ if (this.length === 0)
472
+ return "";
473
+ var p = this.head;
474
+ var ret = "" + p.data;
475
+ while (p = p.next)
476
+ ret += s + p.data;
477
+ return ret;
478
+ }
479
+ }, {
480
+ key: "concat",
481
+ value: function concat(n) {
482
+ if (this.length === 0)
483
+ return Buffer.alloc(0);
484
+ var ret = Buffer.allocUnsafe(n >>> 0);
485
+ var p = this.head;
486
+ var i = 0;
487
+ while (p) {
488
+ copyBuffer(p.data, ret, i);
489
+ i += p.data.length;
490
+ p = p.next;
491
+ }
492
+ return ret;
493
+ }
494
+ }, {
495
+ key: "consume",
496
+ value: function consume(n, hasStrings) {
497
+ var ret;
498
+ if (n < this.head.data.length) {
499
+ ret = this.head.data.slice(0, n);
500
+ this.head.data = this.head.data.slice(n);
501
+ } else if (n === this.head.data.length) {
502
+ ret = this.shift();
503
+ } else {
504
+ ret = hasStrings ? this._getString(n) : this._getBuffer(n);
505
+ }
506
+ return ret;
507
+ }
508
+ }, {
509
+ key: "first",
510
+ value: function first() {
511
+ return this.head.data;
512
+ }
513
+ }, {
514
+ key: "_getString",
515
+ value: function _getString(n) {
516
+ var p = this.head;
517
+ var c = 1;
518
+ var ret = p.data;
519
+ n -= ret.length;
520
+ while (p = p.next) {
521
+ var str = p.data;
522
+ var nb = n > str.length ? str.length : n;
523
+ if (nb === str.length)
524
+ ret += str;
525
+ else
526
+ ret += str.slice(0, n);
527
+ n -= nb;
528
+ if (n === 0) {
529
+ if (nb === str.length) {
530
+ ++c;
531
+ if (p.next)
532
+ this.head = p.next;
533
+ else
534
+ this.head = this.tail = null;
535
+ } else {
536
+ this.head = p;
537
+ p.data = str.slice(nb);
538
+ }
539
+ break;
540
+ }
541
+ ++c;
542
+ }
543
+ this.length -= c;
544
+ return ret;
545
+ }
546
+ }, {
547
+ key: "_getBuffer",
548
+ value: function _getBuffer(n) {
549
+ var ret = Buffer.allocUnsafe(n);
550
+ var p = this.head;
551
+ var c = 1;
552
+ p.data.copy(ret);
553
+ n -= p.data.length;
554
+ while (p = p.next) {
555
+ var buf = p.data;
556
+ var nb = n > buf.length ? buf.length : n;
557
+ buf.copy(ret, ret.length - n, 0, nb);
558
+ n -= nb;
559
+ if (n === 0) {
560
+ if (nb === buf.length) {
561
+ ++c;
562
+ if (p.next)
563
+ this.head = p.next;
564
+ else
565
+ this.head = this.tail = null;
566
+ } else {
567
+ this.head = p;
568
+ p.data = buf.slice(nb);
569
+ }
570
+ break;
571
+ }
572
+ ++c;
573
+ }
574
+ this.length -= c;
575
+ return ret;
576
+ }
577
+ }, {
578
+ key: custom,
579
+ value: function value(_, options) {
580
+ return inspect(this, _objectSpread(_objectSpread({}, options), {}, {
581
+ depth: 0,
582
+ customInspect: false
583
+ }));
584
+ }
585
+ }]);
586
+ return BufferList;
587
+ }();
588
+ });
589
+
590
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/destroy.js
591
+ var require_destroy = __commonJS((exports, module) => {
592
+ var destroy = function(err, cb) {
593
+ var _this = this;
594
+ var readableDestroyed = this._readableState && this._readableState.destroyed;
595
+ var writableDestroyed = this._writableState && this._writableState.destroyed;
596
+ if (readableDestroyed || writableDestroyed) {
597
+ if (cb) {
598
+ cb(err);
599
+ } else if (err) {
600
+ if (!this._writableState) {
601
+ process.nextTick(emitErrorNT, this, err);
602
+ } else if (!this._writableState.errorEmitted) {
603
+ this._writableState.errorEmitted = true;
604
+ process.nextTick(emitErrorNT, this, err);
605
+ }
606
+ }
607
+ return this;
608
+ }
609
+ if (this._readableState) {
610
+ this._readableState.destroyed = true;
611
+ }
612
+ if (this._writableState) {
613
+ this._writableState.destroyed = true;
614
+ }
615
+ this._destroy(err || null, function(err2) {
616
+ if (!cb && err2) {
617
+ if (!_this._writableState) {
618
+ process.nextTick(emitErrorAndCloseNT, _this, err2);
619
+ } else if (!_this._writableState.errorEmitted) {
620
+ _this._writableState.errorEmitted = true;
621
+ process.nextTick(emitErrorAndCloseNT, _this, err2);
622
+ } else {
623
+ process.nextTick(emitCloseNT, _this);
624
+ }
625
+ } else if (cb) {
626
+ process.nextTick(emitCloseNT, _this);
627
+ cb(err2);
628
+ } else {
629
+ process.nextTick(emitCloseNT, _this);
630
+ }
631
+ });
632
+ return this;
633
+ };
634
+ var emitErrorAndCloseNT = function(self2, err) {
635
+ emitErrorNT(self2, err);
636
+ emitCloseNT(self2);
637
+ };
638
+ var emitCloseNT = function(self2) {
639
+ if (self2._writableState && !self2._writableState.emitClose)
640
+ return;
641
+ if (self2._readableState && !self2._readableState.emitClose)
642
+ return;
643
+ self2.emit("close");
644
+ };
645
+ var undestroy = function() {
646
+ if (this._readableState) {
647
+ this._readableState.destroyed = false;
648
+ this._readableState.reading = false;
649
+ this._readableState.ended = false;
650
+ this._readableState.endEmitted = false;
651
+ }
652
+ if (this._writableState) {
653
+ this._writableState.destroyed = false;
654
+ this._writableState.ended = false;
655
+ this._writableState.ending = false;
656
+ this._writableState.finalCalled = false;
657
+ this._writableState.prefinished = false;
658
+ this._writableState.finished = false;
659
+ this._writableState.errorEmitted = false;
660
+ }
661
+ };
662
+ var emitErrorNT = function(self2, err) {
663
+ self2.emit("error", err);
664
+ };
665
+ var errorOrDestroy = function(stream, err) {
666
+ var rState = stream._readableState;
667
+ var wState = stream._writableState;
668
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy)
669
+ stream.destroy(err);
670
+ else
671
+ stream.emit("error", err);
672
+ };
673
+ module.exports = {
674
+ destroy,
675
+ undestroy,
676
+ errorOrDestroy
677
+ };
678
+ });
679
+
680
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/errors.js
681
+ var require_errors = __commonJS((exports, module) => {
682
+ var createErrorType = function(code, message, Base) {
683
+ if (!Base) {
684
+ Base = Error;
685
+ }
686
+ function getMessage(arg1, arg2, arg3) {
687
+ if (typeof message === "string") {
688
+ return message;
689
+ } else {
690
+ return message(arg1, arg2, arg3);
691
+ }
692
+ }
693
+
694
+ class NodeError extends Base {
695
+ constructor(arg1, arg2, arg3) {
696
+ super(getMessage(arg1, arg2, arg3));
697
+ }
698
+ }
699
+ NodeError.prototype.name = Base.name;
700
+ NodeError.prototype.code = code;
701
+ codes[code] = NodeError;
702
+ };
703
+ var oneOf = function(expected, thing) {
704
+ if (Array.isArray(expected)) {
705
+ const len = expected.length;
706
+ expected = expected.map((i) => String(i));
707
+ if (len > 2) {
708
+ return `one of ${thing} ${expected.slice(0, len - 1).join(", ")}, or ` + expected[len - 1];
709
+ } else if (len === 2) {
710
+ return `one of ${thing} ${expected[0]} or ${expected[1]}`;
711
+ } else {
712
+ return `of ${thing} ${expected[0]}`;
713
+ }
714
+ } else {
715
+ return `of ${thing} ${String(expected)}`;
716
+ }
717
+ };
718
+ var startsWith = function(str, search, pos) {
719
+ return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
720
+ };
721
+ var endsWith = function(str, search, this_len) {
722
+ if (this_len === undefined || this_len > str.length) {
723
+ this_len = str.length;
724
+ }
725
+ return str.substring(this_len - search.length, this_len) === search;
726
+ };
727
+ var includes = function(str, search, start) {
728
+ if (typeof start !== "number") {
729
+ start = 0;
730
+ }
731
+ if (start + search.length > str.length) {
732
+ return false;
733
+ } else {
734
+ return str.indexOf(search, start) !== -1;
735
+ }
736
+ };
737
+ var codes = {};
738
+ createErrorType("ERR_INVALID_OPT_VALUE", function(name, value) {
739
+ return 'The value "' + value + '" is invalid for option "' + name + '"';
740
+ }, TypeError);
741
+ createErrorType("ERR_INVALID_ARG_TYPE", function(name, expected, actual) {
742
+ let determiner;
743
+ if (typeof expected === "string" && startsWith(expected, "not ")) {
744
+ determiner = "must not be";
745
+ expected = expected.replace(/^not /, "");
746
+ } else {
747
+ determiner = "must be";
748
+ }
749
+ let msg;
750
+ if (endsWith(name, " argument")) {
751
+ msg = `The ${name} ${determiner} ${oneOf(expected, "type")}`;
752
+ } else {
753
+ const type = includes(name, ".") ? "property" : "argument";
754
+ msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, "type")}`;
755
+ }
756
+ msg += `. Received type ${typeof actual}`;
757
+ return msg;
758
+ }, TypeError);
759
+ createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF");
760
+ createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function(name) {
761
+ return "The " + name + " method is not implemented";
762
+ });
763
+ createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close");
764
+ createErrorType("ERR_STREAM_DESTROYED", function(name) {
765
+ return "Cannot call " + name + " after a stream was destroyed";
766
+ });
767
+ createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times");
768
+ createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable");
769
+ createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end");
770
+ createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError);
771
+ createErrorType("ERR_UNKNOWN_ENCODING", function(arg) {
772
+ return "Unknown encoding: " + arg;
773
+ }, TypeError);
774
+ createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event");
775
+ exports.codes = codes;
776
+ });
777
+
778
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/state.js
779
+ var require_state = __commonJS((exports, module) => {
780
+ var highWaterMarkFrom = function(options, isDuplex, duplexKey) {
781
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
782
+ };
783
+ var getHighWaterMark = function(state, options, duplexKey, isDuplex) {
784
+ var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
785
+ if (hwm != null) {
786
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
787
+ var name = isDuplex ? duplexKey : "highWaterMark";
788
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
789
+ }
790
+ return Math.floor(hwm);
791
+ }
792
+ return state.objectMode ? 16 : 16 * 1024;
793
+ };
794
+ var ERR_INVALID_OPT_VALUE = require_errors().codes.ERR_INVALID_OPT_VALUE;
795
+ module.exports = {
796
+ getHighWaterMark
797
+ };
798
+ });
799
+
800
+ // /Users/schettn/Documents/pylon/node_modules/inherits/inherits_browser.js
801
+ var require_inherits_browser = __commonJS((exports, module) => {
802
+ if (typeof Object.create === "function") {
803
+ module.exports = function inherits(ctor, superCtor) {
804
+ if (superCtor) {
805
+ ctor.super_ = superCtor;
806
+ ctor.prototype = Object.create(superCtor.prototype, {
807
+ constructor: {
808
+ value: ctor,
809
+ enumerable: false,
810
+ writable: true,
811
+ configurable: true
812
+ }
813
+ });
814
+ }
815
+ };
816
+ } else {
817
+ module.exports = function inherits(ctor, superCtor) {
818
+ if (superCtor) {
819
+ ctor.super_ = superCtor;
820
+ var TempCtor = function() {
821
+ };
822
+ TempCtor.prototype = superCtor.prototype;
823
+ ctor.prototype = new TempCtor;
824
+ ctor.prototype.constructor = ctor;
825
+ }
826
+ };
827
+ }
828
+ });
829
+
830
+ // /Users/schettn/Documents/pylon/node_modules/inherits/inherits.js
831
+ var require_inherits = __commonJS((exports, module) => {
832
+ try {
833
+ util = import.meta.require("util");
834
+ if (typeof util.inherits !== "function")
835
+ throw "";
836
+ module.exports = util.inherits;
837
+ } catch (e) {
838
+ module.exports = require_inherits_browser();
839
+ }
840
+ var util;
841
+ });
842
+
843
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/end-of-stream.js
844
+ var require_end_of_stream = __commonJS((exports, module) => {
845
+ var once = function(callback) {
846
+ var called = false;
847
+ return function() {
848
+ if (called)
849
+ return;
850
+ called = true;
851
+ for (var _len = arguments.length, args = new Array(_len), _key = 0;_key < _len; _key++) {
852
+ args[_key] = arguments[_key];
853
+ }
854
+ callback.apply(this, args);
855
+ };
856
+ };
857
+ var noop = function() {
858
+ };
859
+ var isRequest = function(stream) {
860
+ return stream.setHeader && typeof stream.abort === "function";
861
+ };
862
+ var eos = function(stream, opts, callback) {
863
+ if (typeof opts === "function")
864
+ return eos(stream, null, opts);
865
+ if (!opts)
866
+ opts = {};
867
+ callback = once(callback || noop);
868
+ var readable = opts.readable || opts.readable !== false && stream.readable;
869
+ var writable = opts.writable || opts.writable !== false && stream.writable;
870
+ var onlegacyfinish = function onlegacyfinish() {
871
+ if (!stream.writable)
872
+ onfinish();
873
+ };
874
+ var writableEnded = stream._writableState && stream._writableState.finished;
875
+ var onfinish = function onfinish() {
876
+ writable = false;
877
+ writableEnded = true;
878
+ if (!readable)
879
+ callback.call(stream);
880
+ };
881
+ var readableEnded = stream._readableState && stream._readableState.endEmitted;
882
+ var onend = function onend() {
883
+ readable = false;
884
+ readableEnded = true;
885
+ if (!writable)
886
+ callback.call(stream);
887
+ };
888
+ var onerror = function onerror(err) {
889
+ callback.call(stream, err);
890
+ };
891
+ var onclose = function onclose() {
892
+ var err;
893
+ if (readable && !readableEnded) {
894
+ if (!stream._readableState || !stream._readableState.ended)
895
+ err = new ERR_STREAM_PREMATURE_CLOSE;
896
+ return callback.call(stream, err);
897
+ }
898
+ if (writable && !writableEnded) {
899
+ if (!stream._writableState || !stream._writableState.ended)
900
+ err = new ERR_STREAM_PREMATURE_CLOSE;
901
+ return callback.call(stream, err);
902
+ }
903
+ };
904
+ var onrequest = function onrequest() {
905
+ stream.req.on("finish", onfinish);
906
+ };
907
+ if (isRequest(stream)) {
908
+ stream.on("complete", onfinish);
909
+ stream.on("abort", onclose);
910
+ if (stream.req)
911
+ onrequest();
912
+ else
913
+ stream.on("request", onrequest);
914
+ } else if (writable && !stream._writableState) {
915
+ stream.on("end", onlegacyfinish);
916
+ stream.on("close", onlegacyfinish);
917
+ }
918
+ stream.on("end", onend);
919
+ stream.on("finish", onfinish);
920
+ if (opts.error !== false)
921
+ stream.on("error", onerror);
922
+ stream.on("close", onclose);
923
+ return function() {
924
+ stream.removeListener("complete", onfinish);
925
+ stream.removeListener("abort", onclose);
926
+ stream.removeListener("request", onrequest);
927
+ if (stream.req)
928
+ stream.req.removeListener("finish", onfinish);
929
+ stream.removeListener("end", onlegacyfinish);
930
+ stream.removeListener("close", onlegacyfinish);
931
+ stream.removeListener("finish", onfinish);
932
+ stream.removeListener("end", onend);
933
+ stream.removeListener("error", onerror);
934
+ stream.removeListener("close", onclose);
935
+ };
936
+ };
937
+ var ERR_STREAM_PREMATURE_CLOSE = require_errors().codes.ERR_STREAM_PREMATURE_CLOSE;
938
+ module.exports = eos;
939
+ });
940
+
941
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/async_iterator.js
942
+ var require_async_iterator = __commonJS((exports, module) => {
943
+ var _defineProperty = function(obj, key, value) {
944
+ key = _toPropertyKey(key);
945
+ if (key in obj) {
946
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
947
+ } else {
948
+ obj[key] = value;
949
+ }
950
+ return obj;
951
+ };
952
+ var _toPropertyKey = function(arg) {
953
+ var key = _toPrimitive(arg, "string");
954
+ return typeof key === "symbol" ? key : String(key);
955
+ };
956
+ var _toPrimitive = function(input, hint) {
957
+ if (typeof input !== "object" || input === null)
958
+ return input;
959
+ var prim = input[Symbol.toPrimitive];
960
+ if (prim !== undefined) {
961
+ var res = prim.call(input, hint || "default");
962
+ if (typeof res !== "object")
963
+ return res;
964
+ throw new TypeError("@@toPrimitive must return a primitive value.");
965
+ }
966
+ return (hint === "string" ? String : Number)(input);
967
+ };
968
+ var createIterResult = function(value, done) {
969
+ return {
970
+ value,
971
+ done
972
+ };
973
+ };
974
+ var readAndResolve = function(iter) {
975
+ var resolve = iter[kLastResolve];
976
+ if (resolve !== null) {
977
+ var data = iter[kStream].read();
978
+ if (data !== null) {
979
+ iter[kLastPromise] = null;
980
+ iter[kLastResolve] = null;
981
+ iter[kLastReject] = null;
982
+ resolve(createIterResult(data, false));
983
+ }
984
+ }
985
+ };
986
+ var onReadable = function(iter) {
987
+ process.nextTick(readAndResolve, iter);
988
+ };
989
+ var wrapForNext = function(lastPromise, iter) {
990
+ return function(resolve, reject) {
991
+ lastPromise.then(function() {
992
+ if (iter[kEnded]) {
993
+ resolve(createIterResult(undefined, true));
994
+ return;
995
+ }
996
+ iter[kHandlePromise](resolve, reject);
997
+ }, reject);
998
+ };
999
+ };
1000
+ var _Object$setPrototypeO;
1001
+ var finished = require_end_of_stream();
1002
+ var kLastResolve = Symbol("lastResolve");
1003
+ var kLastReject = Symbol("lastReject");
1004
+ var kError = Symbol("error");
1005
+ var kEnded = Symbol("ended");
1006
+ var kLastPromise = Symbol("lastPromise");
1007
+ var kHandlePromise = Symbol("handlePromise");
1008
+ var kStream = Symbol("stream");
1009
+ var AsyncIteratorPrototype = Object.getPrototypeOf(function() {
1010
+ });
1011
+ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
1012
+ get stream() {
1013
+ return this[kStream];
1014
+ },
1015
+ next: function next() {
1016
+ var _this = this;
1017
+ var error = this[kError];
1018
+ if (error !== null) {
1019
+ return Promise.reject(error);
1020
+ }
1021
+ if (this[kEnded]) {
1022
+ return Promise.resolve(createIterResult(undefined, true));
1023
+ }
1024
+ if (this[kStream].destroyed) {
1025
+ return new Promise(function(resolve, reject) {
1026
+ process.nextTick(function() {
1027
+ if (_this[kError]) {
1028
+ reject(_this[kError]);
1029
+ } else {
1030
+ resolve(createIterResult(undefined, true));
1031
+ }
1032
+ });
1033
+ });
1034
+ }
1035
+ var lastPromise = this[kLastPromise];
1036
+ var promise;
1037
+ if (lastPromise) {
1038
+ promise = new Promise(wrapForNext(lastPromise, this));
1039
+ } else {
1040
+ var data = this[kStream].read();
1041
+ if (data !== null) {
1042
+ return Promise.resolve(createIterResult(data, false));
1043
+ }
1044
+ promise = new Promise(this[kHandlePromise]);
1045
+ }
1046
+ this[kLastPromise] = promise;
1047
+ return promise;
1048
+ }
1049
+ }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function() {
1050
+ return this;
1051
+ }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
1052
+ var _this2 = this;
1053
+ return new Promise(function(resolve, reject) {
1054
+ _this2[kStream].destroy(null, function(err) {
1055
+ if (err) {
1056
+ reject(err);
1057
+ return;
1058
+ }
1059
+ resolve(createIterResult(undefined, true));
1060
+ });
1061
+ });
1062
+ }), _Object$setPrototypeO), AsyncIteratorPrototype);
1063
+ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
1064
+ var _Object$create;
1065
+ var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
1066
+ value: stream,
1067
+ writable: true
1068
+ }), _defineProperty(_Object$create, kLastResolve, {
1069
+ value: null,
1070
+ writable: true
1071
+ }), _defineProperty(_Object$create, kLastReject, {
1072
+ value: null,
1073
+ writable: true
1074
+ }), _defineProperty(_Object$create, kError, {
1075
+ value: null,
1076
+ writable: true
1077
+ }), _defineProperty(_Object$create, kEnded, {
1078
+ value: stream._readableState.endEmitted,
1079
+ writable: true
1080
+ }), _defineProperty(_Object$create, kHandlePromise, {
1081
+ value: function value(resolve, reject) {
1082
+ var data = iterator[kStream].read();
1083
+ if (data) {
1084
+ iterator[kLastPromise] = null;
1085
+ iterator[kLastResolve] = null;
1086
+ iterator[kLastReject] = null;
1087
+ resolve(createIterResult(data, false));
1088
+ } else {
1089
+ iterator[kLastResolve] = resolve;
1090
+ iterator[kLastReject] = reject;
1091
+ }
1092
+ },
1093
+ writable: true
1094
+ }), _Object$create));
1095
+ iterator[kLastPromise] = null;
1096
+ finished(stream, function(err) {
1097
+ if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
1098
+ var reject = iterator[kLastReject];
1099
+ if (reject !== null) {
1100
+ iterator[kLastPromise] = null;
1101
+ iterator[kLastResolve] = null;
1102
+ iterator[kLastReject] = null;
1103
+ reject(err);
1104
+ }
1105
+ iterator[kError] = err;
1106
+ return;
1107
+ }
1108
+ var resolve = iterator[kLastResolve];
1109
+ if (resolve !== null) {
1110
+ iterator[kLastPromise] = null;
1111
+ iterator[kLastResolve] = null;
1112
+ iterator[kLastReject] = null;
1113
+ resolve(createIterResult(undefined, true));
1114
+ }
1115
+ iterator[kEnded] = true;
1116
+ });
1117
+ stream.on("readable", onReadable.bind(null, iterator));
1118
+ return iterator;
1119
+ };
1120
+ module.exports = createReadableStreamAsyncIterator;
1121
+ });
1122
+
1123
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/internal/streams/from.js
1124
+ var require_from = __commonJS((exports, module) => {
1125
+ var asyncGeneratorStep = function(gen, resolve, reject, _next, _throw, key, arg) {
1126
+ try {
1127
+ var info = gen[key](arg);
1128
+ var value = info.value;
1129
+ } catch (error) {
1130
+ reject(error);
1131
+ return;
1132
+ }
1133
+ if (info.done) {
1134
+ resolve(value);
1135
+ } else {
1136
+ Promise.resolve(value).then(_next, _throw);
1137
+ }
1138
+ };
1139
+ var _asyncToGenerator = function(fn) {
1140
+ return function() {
1141
+ var self2 = this, args = arguments;
1142
+ return new Promise(function(resolve, reject) {
1143
+ var gen = fn.apply(self2, args);
1144
+ function _next(value) {
1145
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1146
+ }
1147
+ function _throw(err) {
1148
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1149
+ }
1150
+ _next(undefined);
1151
+ });
1152
+ };
1153
+ };
1154
+ var ownKeys = function(object, enumerableOnly) {
1155
+ var keys = Object.keys(object);
1156
+ if (Object.getOwnPropertySymbols) {
1157
+ var symbols = Object.getOwnPropertySymbols(object);
1158
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
1159
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
1160
+ })), keys.push.apply(keys, symbols);
1161
+ }
1162
+ return keys;
1163
+ };
1164
+ var _objectSpread = function(target) {
1165
+ for (var i = 1;i < arguments.length; i++) {
1166
+ var source = arguments[i] != null ? arguments[i] : {};
1167
+ i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
1168
+ _defineProperty(target, key, source[key]);
1169
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
1170
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1171
+ });
1172
+ }
1173
+ return target;
1174
+ };
1175
+ var _defineProperty = function(obj, key, value) {
1176
+ key = _toPropertyKey(key);
1177
+ if (key in obj) {
1178
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
1179
+ } else {
1180
+ obj[key] = value;
1181
+ }
1182
+ return obj;
1183
+ };
1184
+ var _toPropertyKey = function(arg) {
1185
+ var key = _toPrimitive(arg, "string");
1186
+ return typeof key === "symbol" ? key : String(key);
1187
+ };
1188
+ var _toPrimitive = function(input, hint) {
1189
+ if (typeof input !== "object" || input === null)
1190
+ return input;
1191
+ var prim = input[Symbol.toPrimitive];
1192
+ if (prim !== undefined) {
1193
+ var res = prim.call(input, hint || "default");
1194
+ if (typeof res !== "object")
1195
+ return res;
1196
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1197
+ }
1198
+ return (hint === "string" ? String : Number)(input);
1199
+ };
1200
+ var from = function(Readable, iterable, opts) {
1201
+ var iterator;
1202
+ if (iterable && typeof iterable.next === "function") {
1203
+ iterator = iterable;
1204
+ } else if (iterable && iterable[Symbol.asyncIterator])
1205
+ iterator = iterable[Symbol.asyncIterator]();
1206
+ else if (iterable && iterable[Symbol.iterator])
1207
+ iterator = iterable[Symbol.iterator]();
1208
+ else
1209
+ throw new ERR_INVALID_ARG_TYPE("iterable", ["Iterable"], iterable);
1210
+ var readable = new Readable(_objectSpread({
1211
+ objectMode: true
1212
+ }, opts));
1213
+ var reading = false;
1214
+ readable._read = function() {
1215
+ if (!reading) {
1216
+ reading = true;
1217
+ next();
1218
+ }
1219
+ };
1220
+ function next() {
1221
+ return _next2.apply(this, arguments);
1222
+ }
1223
+ function _next2() {
1224
+ _next2 = _asyncToGenerator(function* () {
1225
+ try {
1226
+ var _yield$iterator$next = yield iterator.next(), value = _yield$iterator$next.value, done = _yield$iterator$next.done;
1227
+ if (done) {
1228
+ readable.push(null);
1229
+ } else if (readable.push(yield value)) {
1230
+ next();
1231
+ } else {
1232
+ reading = false;
1233
+ }
1234
+ } catch (err) {
1235
+ readable.destroy(err);
1236
+ }
1237
+ });
1238
+ return _next2.apply(this, arguments);
1239
+ }
1240
+ return readable;
1241
+ };
1242
+ var ERR_INVALID_ARG_TYPE = require_errors().codes.ERR_INVALID_ARG_TYPE;
1243
+ module.exports = from;
1244
+ });
1245
+
1246
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/_stream_readable.js
1247
+ var require__stream_readable = __commonJS((exports, module) => {
1248
+ var _uint8ArrayToBuffer = function(chunk) {
1249
+ return Buffer.from(chunk);
1250
+ };
1251
+ var _isUint8Array = function(obj) {
1252
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
1253
+ };
1254
+ var prependListener = function(emitter, event, fn) {
1255
+ if (typeof emitter.prependListener === "function")
1256
+ return emitter.prependListener(event, fn);
1257
+ if (!emitter._events || !emitter._events[event])
1258
+ emitter.on(event, fn);
1259
+ else if (Array.isArray(emitter._events[event]))
1260
+ emitter._events[event].unshift(fn);
1261
+ else
1262
+ emitter._events[event] = [fn, emitter._events[event]];
1263
+ };
1264
+ var ReadableState = function(options, stream, isDuplex) {
1265
+ Duplex = Duplex || require__stream_duplex();
1266
+ options = options || {};
1267
+ if (typeof isDuplex !== "boolean")
1268
+ isDuplex = stream instanceof Duplex;
1269
+ this.objectMode = !!options.objectMode;
1270
+ if (isDuplex)
1271
+ this.objectMode = this.objectMode || !!options.readableObjectMode;
1272
+ this.highWaterMark = getHighWaterMark(this, options, "readableHighWaterMark", isDuplex);
1273
+ this.buffer = new BufferList;
1274
+ this.length = 0;
1275
+ this.pipes = null;
1276
+ this.pipesCount = 0;
1277
+ this.flowing = null;
1278
+ this.ended = false;
1279
+ this.endEmitted = false;
1280
+ this.reading = false;
1281
+ this.sync = true;
1282
+ this.needReadable = false;
1283
+ this.emittedReadable = false;
1284
+ this.readableListening = false;
1285
+ this.resumeScheduled = false;
1286
+ this.paused = true;
1287
+ this.emitClose = options.emitClose !== false;
1288
+ this.autoDestroy = !!options.autoDestroy;
1289
+ this.destroyed = false;
1290
+ this.defaultEncoding = options.defaultEncoding || "utf8";
1291
+ this.awaitDrain = 0;
1292
+ this.readingMore = false;
1293
+ this.decoder = null;
1294
+ this.encoding = null;
1295
+ if (options.encoding) {
1296
+ if (!StringDecoder)
1297
+ StringDecoder = require_string_decoder().StringDecoder;
1298
+ this.decoder = new StringDecoder(options.encoding);
1299
+ this.encoding = options.encoding;
1300
+ }
1301
+ };
1302
+ var Readable = function(options) {
1303
+ Duplex = Duplex || require__stream_duplex();
1304
+ if (!(this instanceof Readable))
1305
+ return new Readable(options);
1306
+ var isDuplex = this instanceof Duplex;
1307
+ this._readableState = new ReadableState(options, this, isDuplex);
1308
+ this.readable = true;
1309
+ if (options) {
1310
+ if (typeof options.read === "function")
1311
+ this._read = options.read;
1312
+ if (typeof options.destroy === "function")
1313
+ this._destroy = options.destroy;
1314
+ }
1315
+ Stream.call(this);
1316
+ };
1317
+ var readableAddChunk = function(stream, chunk, encoding, addToFront, skipChunkCheck) {
1318
+ debug("readableAddChunk", chunk);
1319
+ var state = stream._readableState;
1320
+ if (chunk === null) {
1321
+ state.reading = false;
1322
+ onEofChunk(stream, state);
1323
+ } else {
1324
+ var er;
1325
+ if (!skipChunkCheck)
1326
+ er = chunkInvalid(state, chunk);
1327
+ if (er) {
1328
+ errorOrDestroy(stream, er);
1329
+ } else if (state.objectMode || chunk && chunk.length > 0) {
1330
+ if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
1331
+ chunk = _uint8ArrayToBuffer(chunk);
1332
+ }
1333
+ if (addToFront) {
1334
+ if (state.endEmitted)
1335
+ errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT);
1336
+ else
1337
+ addChunk(stream, state, chunk, true);
1338
+ } else if (state.ended) {
1339
+ errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF);
1340
+ } else if (state.destroyed) {
1341
+ return false;
1342
+ } else {
1343
+ state.reading = false;
1344
+ if (state.decoder && !encoding) {
1345
+ chunk = state.decoder.write(chunk);
1346
+ if (state.objectMode || chunk.length !== 0)
1347
+ addChunk(stream, state, chunk, false);
1348
+ else
1349
+ maybeReadMore(stream, state);
1350
+ } else {
1351
+ addChunk(stream, state, chunk, false);
1352
+ }
1353
+ }
1354
+ } else if (!addToFront) {
1355
+ state.reading = false;
1356
+ maybeReadMore(stream, state);
1357
+ }
1358
+ }
1359
+ return !state.ended && (state.length < state.highWaterMark || state.length === 0);
1360
+ };
1361
+ var addChunk = function(stream, state, chunk, addToFront) {
1362
+ if (state.flowing && state.length === 0 && !state.sync) {
1363
+ state.awaitDrain = 0;
1364
+ stream.emit("data", chunk);
1365
+ } else {
1366
+ state.length += state.objectMode ? 1 : chunk.length;
1367
+ if (addToFront)
1368
+ state.buffer.unshift(chunk);
1369
+ else
1370
+ state.buffer.push(chunk);
1371
+ if (state.needReadable)
1372
+ emitReadable(stream);
1373
+ }
1374
+ maybeReadMore(stream, state);
1375
+ };
1376
+ var chunkInvalid = function(state, chunk) {
1377
+ var er;
1378
+ if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== undefined && !state.objectMode) {
1379
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk);
1380
+ }
1381
+ return er;
1382
+ };
1383
+ var computeNewHighWaterMark = function(n) {
1384
+ if (n >= MAX_HWM) {
1385
+ n = MAX_HWM;
1386
+ } else {
1387
+ n--;
1388
+ n |= n >>> 1;
1389
+ n |= n >>> 2;
1390
+ n |= n >>> 4;
1391
+ n |= n >>> 8;
1392
+ n |= n >>> 16;
1393
+ n++;
1394
+ }
1395
+ return n;
1396
+ };
1397
+ var howMuchToRead = function(n, state) {
1398
+ if (n <= 0 || state.length === 0 && state.ended)
1399
+ return 0;
1400
+ if (state.objectMode)
1401
+ return 1;
1402
+ if (n !== n) {
1403
+ if (state.flowing && state.length)
1404
+ return state.buffer.head.data.length;
1405
+ else
1406
+ return state.length;
1407
+ }
1408
+ if (n > state.highWaterMark)
1409
+ state.highWaterMark = computeNewHighWaterMark(n);
1410
+ if (n <= state.length)
1411
+ return n;
1412
+ if (!state.ended) {
1413
+ state.needReadable = true;
1414
+ return 0;
1415
+ }
1416
+ return state.length;
1417
+ };
1418
+ var onEofChunk = function(stream, state) {
1419
+ debug("onEofChunk");
1420
+ if (state.ended)
1421
+ return;
1422
+ if (state.decoder) {
1423
+ var chunk = state.decoder.end();
1424
+ if (chunk && chunk.length) {
1425
+ state.buffer.push(chunk);
1426
+ state.length += state.objectMode ? 1 : chunk.length;
1427
+ }
1428
+ }
1429
+ state.ended = true;
1430
+ if (state.sync) {
1431
+ emitReadable(stream);
1432
+ } else {
1433
+ state.needReadable = false;
1434
+ if (!state.emittedReadable) {
1435
+ state.emittedReadable = true;
1436
+ emitReadable_(stream);
1437
+ }
1438
+ }
1439
+ };
1440
+ var emitReadable = function(stream) {
1441
+ var state = stream._readableState;
1442
+ debug("emitReadable", state.needReadable, state.emittedReadable);
1443
+ state.needReadable = false;
1444
+ if (!state.emittedReadable) {
1445
+ debug("emitReadable", state.flowing);
1446
+ state.emittedReadable = true;
1447
+ process.nextTick(emitReadable_, stream);
1448
+ }
1449
+ };
1450
+ var emitReadable_ = function(stream) {
1451
+ var state = stream._readableState;
1452
+ debug("emitReadable_", state.destroyed, state.length, state.ended);
1453
+ if (!state.destroyed && (state.length || state.ended)) {
1454
+ stream.emit("readable");
1455
+ state.emittedReadable = false;
1456
+ }
1457
+ state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
1458
+ flow(stream);
1459
+ };
1460
+ var maybeReadMore = function(stream, state) {
1461
+ if (!state.readingMore) {
1462
+ state.readingMore = true;
1463
+ process.nextTick(maybeReadMore_, stream, state);
1464
+ }
1465
+ };
1466
+ var maybeReadMore_ = function(stream, state) {
1467
+ while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
1468
+ var len = state.length;
1469
+ debug("maybeReadMore read 0");
1470
+ stream.read(0);
1471
+ if (len === state.length)
1472
+ break;
1473
+ }
1474
+ state.readingMore = false;
1475
+ };
1476
+ var pipeOnDrain = function(src) {
1477
+ return function pipeOnDrainFunctionResult() {
1478
+ var state = src._readableState;
1479
+ debug("pipeOnDrain", state.awaitDrain);
1480
+ if (state.awaitDrain)
1481
+ state.awaitDrain--;
1482
+ if (state.awaitDrain === 0 && EElistenerCount(src, "data")) {
1483
+ state.flowing = true;
1484
+ flow(src);
1485
+ }
1486
+ };
1487
+ };
1488
+ var updateReadableListening = function(self2) {
1489
+ var state = self2._readableState;
1490
+ state.readableListening = self2.listenerCount("readable") > 0;
1491
+ if (state.resumeScheduled && !state.paused) {
1492
+ state.flowing = true;
1493
+ } else if (self2.listenerCount("data") > 0) {
1494
+ self2.resume();
1495
+ }
1496
+ };
1497
+ var nReadingNextTick = function(self2) {
1498
+ debug("readable nexttick read 0");
1499
+ self2.read(0);
1500
+ };
1501
+ var resume = function(stream, state) {
1502
+ if (!state.resumeScheduled) {
1503
+ state.resumeScheduled = true;
1504
+ process.nextTick(resume_, stream, state);
1505
+ }
1506
+ };
1507
+ var resume_ = function(stream, state) {
1508
+ debug("resume", state.reading);
1509
+ if (!state.reading) {
1510
+ stream.read(0);
1511
+ }
1512
+ state.resumeScheduled = false;
1513
+ stream.emit("resume");
1514
+ flow(stream);
1515
+ if (state.flowing && !state.reading)
1516
+ stream.read(0);
1517
+ };
1518
+ var flow = function(stream) {
1519
+ var state = stream._readableState;
1520
+ debug("flow", state.flowing);
1521
+ while (state.flowing && stream.read() !== null)
1522
+ ;
1523
+ };
1524
+ var fromList = function(n, state) {
1525
+ if (state.length === 0)
1526
+ return null;
1527
+ var ret;
1528
+ if (state.objectMode)
1529
+ ret = state.buffer.shift();
1530
+ else if (!n || n >= state.length) {
1531
+ if (state.decoder)
1532
+ ret = state.buffer.join("");
1533
+ else if (state.buffer.length === 1)
1534
+ ret = state.buffer.first();
1535
+ else
1536
+ ret = state.buffer.concat(state.length);
1537
+ state.buffer.clear();
1538
+ } else {
1539
+ ret = state.buffer.consume(n, state.decoder);
1540
+ }
1541
+ return ret;
1542
+ };
1543
+ var endReadable = function(stream) {
1544
+ var state = stream._readableState;
1545
+ debug("endReadable", state.endEmitted);
1546
+ if (!state.endEmitted) {
1547
+ state.ended = true;
1548
+ process.nextTick(endReadableNT, state, stream);
1549
+ }
1550
+ };
1551
+ var endReadableNT = function(state, stream) {
1552
+ debug("endReadableNT", state.endEmitted, state.length);
1553
+ if (!state.endEmitted && state.length === 0) {
1554
+ state.endEmitted = true;
1555
+ stream.readable = false;
1556
+ stream.emit("end");
1557
+ if (state.autoDestroy) {
1558
+ var wState = stream._writableState;
1559
+ if (!wState || wState.autoDestroy && wState.finished) {
1560
+ stream.destroy();
1561
+ }
1562
+ }
1563
+ }
1564
+ };
1565
+ var indexOf = function(xs, x) {
1566
+ for (var i = 0, l = xs.length;i < l; i++) {
1567
+ if (xs[i] === x)
1568
+ return i;
1569
+ }
1570
+ return -1;
1571
+ };
1572
+ module.exports = Readable;
1573
+ var Duplex;
1574
+ Readable.ReadableState = ReadableState;
1575
+ var EE = import.meta.require("events").EventEmitter;
1576
+ var EElistenerCount = function EElistenerCount(emitter, type) {
1577
+ return emitter.listeners(type).length;
1578
+ };
1579
+ var Stream = import.meta.require("stream");
1580
+ var Buffer = import.meta.require("buffer").Buffer;
1581
+ var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
1582
+ };
1583
+ var debugUtil = import.meta.require("util");
1584
+ var debug;
1585
+ if (debugUtil && debugUtil.debuglog) {
1586
+ debug = debugUtil.debuglog("stream");
1587
+ } else {
1588
+ debug = function debug() {
1589
+ };
1590
+ }
1591
+ var BufferList = require_buffer_list();
1592
+ var destroyImpl = require_destroy();
1593
+ var _require = require_state();
1594
+ var getHighWaterMark = _require.getHighWaterMark;
1595
+ var _require$codes = require_errors().codes;
1596
+ var ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE;
1597
+ var ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF;
1598
+ var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
1599
+ var ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
1600
+ var StringDecoder;
1601
+ var createReadableStreamAsyncIterator;
1602
+ var from;
1603
+ require_inherits()(Readable, Stream);
1604
+ var errorOrDestroy = destroyImpl.errorOrDestroy;
1605
+ var kProxyEvents = ["error", "close", "destroy", "pause", "resume"];
1606
+ Object.defineProperty(Readable.prototype, "destroyed", {
1607
+ enumerable: false,
1608
+ get: function get() {
1609
+ if (this._readableState === undefined) {
1610
+ return false;
1611
+ }
1612
+ return this._readableState.destroyed;
1613
+ },
1614
+ set: function set(value) {
1615
+ if (!this._readableState) {
1616
+ return;
1617
+ }
1618
+ this._readableState.destroyed = value;
1619
+ }
1620
+ });
1621
+ Readable.prototype.destroy = destroyImpl.destroy;
1622
+ Readable.prototype._undestroy = destroyImpl.undestroy;
1623
+ Readable.prototype._destroy = function(err, cb) {
1624
+ cb(err);
1625
+ };
1626
+ Readable.prototype.push = function(chunk, encoding) {
1627
+ var state = this._readableState;
1628
+ var skipChunkCheck;
1629
+ if (!state.objectMode) {
1630
+ if (typeof chunk === "string") {
1631
+ encoding = encoding || state.defaultEncoding;
1632
+ if (encoding !== state.encoding) {
1633
+ chunk = Buffer.from(chunk, encoding);
1634
+ encoding = "";
1635
+ }
1636
+ skipChunkCheck = true;
1637
+ }
1638
+ } else {
1639
+ skipChunkCheck = true;
1640
+ }
1641
+ return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
1642
+ };
1643
+ Readable.prototype.unshift = function(chunk) {
1644
+ return readableAddChunk(this, chunk, null, true, false);
1645
+ };
1646
+ Readable.prototype.isPaused = function() {
1647
+ return this._readableState.flowing === false;
1648
+ };
1649
+ Readable.prototype.setEncoding = function(enc) {
1650
+ if (!StringDecoder)
1651
+ StringDecoder = require_string_decoder().StringDecoder;
1652
+ var decoder = new StringDecoder(enc);
1653
+ this._readableState.decoder = decoder;
1654
+ this._readableState.encoding = this._readableState.decoder.encoding;
1655
+ var p = this._readableState.buffer.head;
1656
+ var content = "";
1657
+ while (p !== null) {
1658
+ content += decoder.write(p.data);
1659
+ p = p.next;
1660
+ }
1661
+ this._readableState.buffer.clear();
1662
+ if (content !== "")
1663
+ this._readableState.buffer.push(content);
1664
+ this._readableState.length = content.length;
1665
+ return this;
1666
+ };
1667
+ var MAX_HWM = 1073741824;
1668
+ Readable.prototype.read = function(n) {
1669
+ debug("read", n);
1670
+ n = parseInt(n, 10);
1671
+ var state = this._readableState;
1672
+ var nOrig = n;
1673
+ if (n !== 0)
1674
+ state.emittedReadable = false;
1675
+ if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
1676
+ debug("read: emitReadable", state.length, state.ended);
1677
+ if (state.length === 0 && state.ended)
1678
+ endReadable(this);
1679
+ else
1680
+ emitReadable(this);
1681
+ return null;
1682
+ }
1683
+ n = howMuchToRead(n, state);
1684
+ if (n === 0 && state.ended) {
1685
+ if (state.length === 0)
1686
+ endReadable(this);
1687
+ return null;
1688
+ }
1689
+ var doRead = state.needReadable;
1690
+ debug("need readable", doRead);
1691
+ if (state.length === 0 || state.length - n < state.highWaterMark) {
1692
+ doRead = true;
1693
+ debug("length less than watermark", doRead);
1694
+ }
1695
+ if (state.ended || state.reading) {
1696
+ doRead = false;
1697
+ debug("reading or ended", doRead);
1698
+ } else if (doRead) {
1699
+ debug("do read");
1700
+ state.reading = true;
1701
+ state.sync = true;
1702
+ if (state.length === 0)
1703
+ state.needReadable = true;
1704
+ this._read(state.highWaterMark);
1705
+ state.sync = false;
1706
+ if (!state.reading)
1707
+ n = howMuchToRead(nOrig, state);
1708
+ }
1709
+ var ret;
1710
+ if (n > 0)
1711
+ ret = fromList(n, state);
1712
+ else
1713
+ ret = null;
1714
+ if (ret === null) {
1715
+ state.needReadable = state.length <= state.highWaterMark;
1716
+ n = 0;
1717
+ } else {
1718
+ state.length -= n;
1719
+ state.awaitDrain = 0;
1720
+ }
1721
+ if (state.length === 0) {
1722
+ if (!state.ended)
1723
+ state.needReadable = true;
1724
+ if (nOrig !== n && state.ended)
1725
+ endReadable(this);
1726
+ }
1727
+ if (ret !== null)
1728
+ this.emit("data", ret);
1729
+ return ret;
1730
+ };
1731
+ Readable.prototype._read = function(n) {
1732
+ errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED("_read()"));
1733
+ };
1734
+ Readable.prototype.pipe = function(dest, pipeOpts) {
1735
+ var src = this;
1736
+ var state = this._readableState;
1737
+ switch (state.pipesCount) {
1738
+ case 0:
1739
+ state.pipes = dest;
1740
+ break;
1741
+ case 1:
1742
+ state.pipes = [state.pipes, dest];
1743
+ break;
1744
+ default:
1745
+ state.pipes.push(dest);
1746
+ break;
1747
+ }
1748
+ state.pipesCount += 1;
1749
+ debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts);
1750
+ var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
1751
+ var endFn = doEnd ? onend : unpipe;
1752
+ if (state.endEmitted)
1753
+ process.nextTick(endFn);
1754
+ else
1755
+ src.once("end", endFn);
1756
+ dest.on("unpipe", onunpipe);
1757
+ function onunpipe(readable, unpipeInfo) {
1758
+ debug("onunpipe");
1759
+ if (readable === src) {
1760
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
1761
+ unpipeInfo.hasUnpiped = true;
1762
+ cleanup();
1763
+ }
1764
+ }
1765
+ }
1766
+ function onend() {
1767
+ debug("onend");
1768
+ dest.end();
1769
+ }
1770
+ var ondrain = pipeOnDrain(src);
1771
+ dest.on("drain", ondrain);
1772
+ var cleanedUp = false;
1773
+ function cleanup() {
1774
+ debug("cleanup");
1775
+ dest.removeListener("close", onclose);
1776
+ dest.removeListener("finish", onfinish);
1777
+ dest.removeListener("drain", ondrain);
1778
+ dest.removeListener("error", onerror);
1779
+ dest.removeListener("unpipe", onunpipe);
1780
+ src.removeListener("end", onend);
1781
+ src.removeListener("end", unpipe);
1782
+ src.removeListener("data", ondata);
1783
+ cleanedUp = true;
1784
+ if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain))
1785
+ ondrain();
1786
+ }
1787
+ src.on("data", ondata);
1788
+ function ondata(chunk) {
1789
+ debug("ondata");
1790
+ var ret = dest.write(chunk);
1791
+ debug("dest.write", ret);
1792
+ if (ret === false) {
1793
+ if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
1794
+ debug("false write response, pause", state.awaitDrain);
1795
+ state.awaitDrain++;
1796
+ }
1797
+ src.pause();
1798
+ }
1799
+ }
1800
+ function onerror(er) {
1801
+ debug("onerror", er);
1802
+ unpipe();
1803
+ dest.removeListener("error", onerror);
1804
+ if (EElistenerCount(dest, "error") === 0)
1805
+ errorOrDestroy(dest, er);
1806
+ }
1807
+ prependListener(dest, "error", onerror);
1808
+ function onclose() {
1809
+ dest.removeListener("finish", onfinish);
1810
+ unpipe();
1811
+ }
1812
+ dest.once("close", onclose);
1813
+ function onfinish() {
1814
+ debug("onfinish");
1815
+ dest.removeListener("close", onclose);
1816
+ unpipe();
1817
+ }
1818
+ dest.once("finish", onfinish);
1819
+ function unpipe() {
1820
+ debug("unpipe");
1821
+ src.unpipe(dest);
1822
+ }
1823
+ dest.emit("pipe", src);
1824
+ if (!state.flowing) {
1825
+ debug("pipe resume");
1826
+ src.resume();
1827
+ }
1828
+ return dest;
1829
+ };
1830
+ Readable.prototype.unpipe = function(dest) {
1831
+ var state = this._readableState;
1832
+ var unpipeInfo = {
1833
+ hasUnpiped: false
1834
+ };
1835
+ if (state.pipesCount === 0)
1836
+ return this;
1837
+ if (state.pipesCount === 1) {
1838
+ if (dest && dest !== state.pipes)
1839
+ return this;
1840
+ if (!dest)
1841
+ dest = state.pipes;
1842
+ state.pipes = null;
1843
+ state.pipesCount = 0;
1844
+ state.flowing = false;
1845
+ if (dest)
1846
+ dest.emit("unpipe", this, unpipeInfo);
1847
+ return this;
1848
+ }
1849
+ if (!dest) {
1850
+ var dests = state.pipes;
1851
+ var len = state.pipesCount;
1852
+ state.pipes = null;
1853
+ state.pipesCount = 0;
1854
+ state.flowing = false;
1855
+ for (var i = 0;i < len; i++)
1856
+ dests[i].emit("unpipe", this, {
1857
+ hasUnpiped: false
1858
+ });
1859
+ return this;
1860
+ }
1861
+ var index = indexOf(state.pipes, dest);
1862
+ if (index === -1)
1863
+ return this;
1864
+ state.pipes.splice(index, 1);
1865
+ state.pipesCount -= 1;
1866
+ if (state.pipesCount === 1)
1867
+ state.pipes = state.pipes[0];
1868
+ dest.emit("unpipe", this, unpipeInfo);
1869
+ return this;
1870
+ };
1871
+ Readable.prototype.on = function(ev, fn) {
1872
+ var res = Stream.prototype.on.call(this, ev, fn);
1873
+ var state = this._readableState;
1874
+ if (ev === "data") {
1875
+ state.readableListening = this.listenerCount("readable") > 0;
1876
+ if (state.flowing !== false)
1877
+ this.resume();
1878
+ } else if (ev === "readable") {
1879
+ if (!state.endEmitted && !state.readableListening) {
1880
+ state.readableListening = state.needReadable = true;
1881
+ state.flowing = false;
1882
+ state.emittedReadable = false;
1883
+ debug("on readable", state.length, state.reading);
1884
+ if (state.length) {
1885
+ emitReadable(this);
1886
+ } else if (!state.reading) {
1887
+ process.nextTick(nReadingNextTick, this);
1888
+ }
1889
+ }
1890
+ }
1891
+ return res;
1892
+ };
1893
+ Readable.prototype.addListener = Readable.prototype.on;
1894
+ Readable.prototype.removeListener = function(ev, fn) {
1895
+ var res = Stream.prototype.removeListener.call(this, ev, fn);
1896
+ if (ev === "readable") {
1897
+ process.nextTick(updateReadableListening, this);
1898
+ }
1899
+ return res;
1900
+ };
1901
+ Readable.prototype.removeAllListeners = function(ev) {
1902
+ var res = Stream.prototype.removeAllListeners.apply(this, arguments);
1903
+ if (ev === "readable" || ev === undefined) {
1904
+ process.nextTick(updateReadableListening, this);
1905
+ }
1906
+ return res;
1907
+ };
1908
+ Readable.prototype.resume = function() {
1909
+ var state = this._readableState;
1910
+ if (!state.flowing) {
1911
+ debug("resume");
1912
+ state.flowing = !state.readableListening;
1913
+ resume(this, state);
1914
+ }
1915
+ state.paused = false;
1916
+ return this;
1917
+ };
1918
+ Readable.prototype.pause = function() {
1919
+ debug("call pause flowing=%j", this._readableState.flowing);
1920
+ if (this._readableState.flowing !== false) {
1921
+ debug("pause");
1922
+ this._readableState.flowing = false;
1923
+ this.emit("pause");
1924
+ }
1925
+ this._readableState.paused = true;
1926
+ return this;
1927
+ };
1928
+ Readable.prototype.wrap = function(stream) {
1929
+ var _this = this;
1930
+ var state = this._readableState;
1931
+ var paused = false;
1932
+ stream.on("end", function() {
1933
+ debug("wrapped end");
1934
+ if (state.decoder && !state.ended) {
1935
+ var chunk = state.decoder.end();
1936
+ if (chunk && chunk.length)
1937
+ _this.push(chunk);
1938
+ }
1939
+ _this.push(null);
1940
+ });
1941
+ stream.on("data", function(chunk) {
1942
+ debug("wrapped data");
1943
+ if (state.decoder)
1944
+ chunk = state.decoder.write(chunk);
1945
+ if (state.objectMode && (chunk === null || chunk === undefined))
1946
+ return;
1947
+ else if (!state.objectMode && (!chunk || !chunk.length))
1948
+ return;
1949
+ var ret = _this.push(chunk);
1950
+ if (!ret) {
1951
+ paused = true;
1952
+ stream.pause();
1953
+ }
1954
+ });
1955
+ for (var i in stream) {
1956
+ if (this[i] === undefined && typeof stream[i] === "function") {
1957
+ this[i] = function methodWrap(method) {
1958
+ return function methodWrapReturnFunction() {
1959
+ return stream[method].apply(stream, arguments);
1960
+ };
1961
+ }(i);
1962
+ }
1963
+ }
1964
+ for (var n = 0;n < kProxyEvents.length; n++) {
1965
+ stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
1966
+ }
1967
+ this._read = function(n2) {
1968
+ debug("wrapped _read", n2);
1969
+ if (paused) {
1970
+ paused = false;
1971
+ stream.resume();
1972
+ }
1973
+ };
1974
+ return this;
1975
+ };
1976
+ if (typeof Symbol === "function") {
1977
+ Readable.prototype[Symbol.asyncIterator] = function() {
1978
+ if (createReadableStreamAsyncIterator === undefined) {
1979
+ createReadableStreamAsyncIterator = require_async_iterator();
1980
+ }
1981
+ return createReadableStreamAsyncIterator(this);
1982
+ };
1983
+ }
1984
+ Object.defineProperty(Readable.prototype, "readableHighWaterMark", {
1985
+ enumerable: false,
1986
+ get: function get() {
1987
+ return this._readableState.highWaterMark;
1988
+ }
1989
+ });
1990
+ Object.defineProperty(Readable.prototype, "readableBuffer", {
1991
+ enumerable: false,
1992
+ get: function get() {
1993
+ return this._readableState && this._readableState.buffer;
1994
+ }
1995
+ });
1996
+ Object.defineProperty(Readable.prototype, "readableFlowing", {
1997
+ enumerable: false,
1998
+ get: function get() {
1999
+ return this._readableState.flowing;
2000
+ },
2001
+ set: function set(state) {
2002
+ if (this._readableState) {
2003
+ this._readableState.flowing = state;
2004
+ }
2005
+ }
2006
+ });
2007
+ Readable._fromList = fromList;
2008
+ Object.defineProperty(Readable.prototype, "readableLength", {
2009
+ enumerable: false,
2010
+ get: function get() {
2011
+ return this._readableState.length;
2012
+ }
2013
+ });
2014
+ if (typeof Symbol === "function") {
2015
+ Readable.from = function(iterable, opts) {
2016
+ if (from === undefined) {
2017
+ from = require_from();
2018
+ }
2019
+ return from(Readable, iterable, opts);
2020
+ };
2021
+ }
2022
+ });
2023
+
2024
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/_stream_duplex.js
2025
+ var require__stream_duplex = __commonJS((exports, module) => {
2026
+ var Duplex = function(options) {
2027
+ if (!(this instanceof Duplex))
2028
+ return new Duplex(options);
2029
+ Readable.call(this, options);
2030
+ Writable.call(this, options);
2031
+ this.allowHalfOpen = true;
2032
+ if (options) {
2033
+ if (options.readable === false)
2034
+ this.readable = false;
2035
+ if (options.writable === false)
2036
+ this.writable = false;
2037
+ if (options.allowHalfOpen === false) {
2038
+ this.allowHalfOpen = false;
2039
+ this.once("end", onend);
2040
+ }
2041
+ }
2042
+ };
2043
+ var onend = function() {
2044
+ if (this._writableState.ended)
2045
+ return;
2046
+ process.nextTick(onEndNT, this);
2047
+ };
2048
+ var onEndNT = function(self2) {
2049
+ self2.end();
2050
+ };
2051
+ var objectKeys = Object.keys || function(obj) {
2052
+ var keys2 = [];
2053
+ for (var key in obj)
2054
+ keys2.push(key);
2055
+ return keys2;
2056
+ };
2057
+ module.exports = Duplex;
2058
+ var Readable = require__stream_readable();
2059
+ var Writable = require__stream_writable();
2060
+ require_inherits()(Duplex, Readable);
2061
+ {
2062
+ keys = objectKeys(Writable.prototype);
2063
+ for (v = 0;v < keys.length; v++) {
2064
+ method = keys[v];
2065
+ if (!Duplex.prototype[method])
2066
+ Duplex.prototype[method] = Writable.prototype[method];
2067
+ }
2068
+ }
2069
+ var keys;
2070
+ var method;
2071
+ var v;
2072
+ Object.defineProperty(Duplex.prototype, "writableHighWaterMark", {
2073
+ enumerable: false,
2074
+ get: function get() {
2075
+ return this._writableState.highWaterMark;
2076
+ }
2077
+ });
2078
+ Object.defineProperty(Duplex.prototype, "writableBuffer", {
2079
+ enumerable: false,
2080
+ get: function get() {
2081
+ return this._writableState && this._writableState.getBuffer();
2082
+ }
2083
+ });
2084
+ Object.defineProperty(Duplex.prototype, "writableLength", {
2085
+ enumerable: false,
2086
+ get: function get() {
2087
+ return this._writableState.length;
2088
+ }
2089
+ });
2090
+ Object.defineProperty(Duplex.prototype, "destroyed", {
2091
+ enumerable: false,
2092
+ get: function get() {
2093
+ if (this._readableState === undefined || this._writableState === undefined) {
2094
+ return false;
2095
+ }
2096
+ return this._readableState.destroyed && this._writableState.destroyed;
2097
+ },
2098
+ set: function set(value) {
2099
+ if (this._readableState === undefined || this._writableState === undefined) {
2100
+ return;
2101
+ }
2102
+ this._readableState.destroyed = value;
2103
+ this._writableState.destroyed = value;
2104
+ }
2105
+ });
2106
+ });
2107
+
2108
+ // /Users/schettn/Documents/pylon/node_modules/util-deprecate/node.js
2109
+ var require_node = __commonJS((exports, module) => {
2110
+ module.exports = import.meta.require("util").deprecate;
2111
+ });
2112
+
2113
+ // /Users/schettn/Documents/pylon/node_modules/readable-stream/lib/_stream_writable.js
2114
+ var require__stream_writable = __commonJS((exports, module) => {
2115
+ var CorkedRequest = function(state) {
2116
+ var _this = this;
2117
+ this.next = null;
2118
+ this.entry = null;
2119
+ this.finish = function() {
2120
+ onCorkedFinish(_this, state);
2121
+ };
2122
+ };
2123
+ var _uint8ArrayToBuffer = function(chunk) {
2124
+ return Buffer.from(chunk);
2125
+ };
2126
+ var _isUint8Array = function(obj) {
2127
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
2128
+ };
2129
+ var nop = function() {
2130
+ };
2131
+ var WritableState = function(options, stream, isDuplex) {
2132
+ Duplex = Duplex || require__stream_duplex();
2133
+ options = options || {};
2134
+ if (typeof isDuplex !== "boolean")
2135
+ isDuplex = stream instanceof Duplex;
2136
+ this.objectMode = !!options.objectMode;
2137
+ if (isDuplex)
2138
+ this.objectMode = this.objectMode || !!options.writableObjectMode;
2139
+ this.highWaterMark = getHighWaterMark(this, options, "writableHighWaterMark", isDuplex);
2140
+ this.finalCalled = false;
2141
+ this.needDrain = false;
2142
+ this.ending = false;
2143
+ this.ended = false;
2144
+ this.finished = false;
2145
+ this.destroyed = false;
2146
+ var noDecode = options.decodeStrings === false;
2147
+ this.decodeStrings = !noDecode;
2148
+ this.defaultEncoding = options.defaultEncoding || "utf8";
2149
+ this.length = 0;
2150
+ this.writing = false;
2151
+ this.corked = 0;
2152
+ this.sync = true;
2153
+ this.bufferProcessing = false;
2154
+ this.onwrite = function(er) {
2155
+ onwrite(stream, er);
2156
+ };
2157
+ this.writecb = null;
2158
+ this.writelen = 0;
2159
+ this.bufferedRequest = null;
2160
+ this.lastBufferedRequest = null;
2161
+ this.pendingcb = 0;
2162
+ this.prefinished = false;
2163
+ this.errorEmitted = false;
2164
+ this.emitClose = options.emitClose !== false;
2165
+ this.autoDestroy = !!options.autoDestroy;
2166
+ this.bufferedRequestCount = 0;
2167
+ this.corkedRequestsFree = new CorkedRequest(this);
2168
+ };
2169
+ var Writable = function(options) {
2170
+ Duplex = Duplex || require__stream_duplex();
2171
+ var isDuplex = this instanceof Duplex;
2172
+ if (!isDuplex && !realHasInstance.call(Writable, this))
2173
+ return new Writable(options);
2174
+ this._writableState = new WritableState(options, this, isDuplex);
2175
+ this.writable = true;
2176
+ if (options) {
2177
+ if (typeof options.write === "function")
2178
+ this._write = options.write;
2179
+ if (typeof options.writev === "function")
2180
+ this._writev = options.writev;
2181
+ if (typeof options.destroy === "function")
2182
+ this._destroy = options.destroy;
2183
+ if (typeof options.final === "function")
2184
+ this._final = options.final;
2185
+ }
2186
+ Stream.call(this);
2187
+ };
2188
+ var writeAfterEnd = function(stream, cb) {
2189
+ var er = new ERR_STREAM_WRITE_AFTER_END;
2190
+ errorOrDestroy(stream, er);
2191
+ process.nextTick(cb, er);
2192
+ };
2193
+ var validChunk = function(stream, state, chunk, cb) {
2194
+ var er;
2195
+ if (chunk === null) {
2196
+ er = new ERR_STREAM_NULL_VALUES;
2197
+ } else if (typeof chunk !== "string" && !state.objectMode) {
2198
+ er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk);
2199
+ }
2200
+ if (er) {
2201
+ errorOrDestroy(stream, er);
2202
+ process.nextTick(cb, er);
2203
+ return false;
2204
+ }
2205
+ return true;
2206
+ };
2207
+ var decodeChunk = function(state, chunk, encoding) {
2208
+ if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") {
2209
+ chunk = Buffer.from(chunk, encoding);
2210
+ }
2211
+ return chunk;
2212
+ };
2213
+ var writeOrBuffer = function(stream, state, isBuf, chunk, encoding, cb) {
2214
+ if (!isBuf) {
2215
+ var newChunk = decodeChunk(state, chunk, encoding);
2216
+ if (chunk !== newChunk) {
2217
+ isBuf = true;
2218
+ encoding = "buffer";
2219
+ chunk = newChunk;
2220
+ }
2221
+ }
2222
+ var len = state.objectMode ? 1 : chunk.length;
2223
+ state.length += len;
2224
+ var ret = state.length < state.highWaterMark;
2225
+ if (!ret)
2226
+ state.needDrain = true;
2227
+ if (state.writing || state.corked) {
2228
+ var last = state.lastBufferedRequest;
2229
+ state.lastBufferedRequest = {
2230
+ chunk,
2231
+ encoding,
2232
+ isBuf,
2233
+ callback: cb,
2234
+ next: null
2235
+ };
2236
+ if (last) {
2237
+ last.next = state.lastBufferedRequest;
2238
+ } else {
2239
+ state.bufferedRequest = state.lastBufferedRequest;
2240
+ }
2241
+ state.bufferedRequestCount += 1;
2242
+ } else {
2243
+ doWrite(stream, state, false, len, chunk, encoding, cb);
2244
+ }
2245
+ return ret;
2246
+ };
2247
+ var doWrite = function(stream, state, writev, len, chunk, encoding, cb) {
2248
+ state.writelen = len;
2249
+ state.writecb = cb;
2250
+ state.writing = true;
2251
+ state.sync = true;
2252
+ if (state.destroyed)
2253
+ state.onwrite(new ERR_STREAM_DESTROYED("write"));
2254
+ else if (writev)
2255
+ stream._writev(chunk, state.onwrite);
2256
+ else
2257
+ stream._write(chunk, encoding, state.onwrite);
2258
+ state.sync = false;
2259
+ };
2260
+ var onwriteError = function(stream, state, sync, er, cb) {
2261
+ --state.pendingcb;
2262
+ if (sync) {
2263
+ process.nextTick(cb, er);
2264
+ process.nextTick(finishMaybe, stream, state);
2265
+ stream._writableState.errorEmitted = true;
2266
+ errorOrDestroy(stream, er);
2267
+ } else {
2268
+ cb(er);
2269
+ stream._writableState.errorEmitted = true;
2270
+ errorOrDestroy(stream, er);
2271
+ finishMaybe(stream, state);
2272
+ }
2273
+ };
2274
+ var onwriteStateUpdate = function(state) {
2275
+ state.writing = false;
2276
+ state.writecb = null;
2277
+ state.length -= state.writelen;
2278
+ state.writelen = 0;
2279
+ };
2280
+ var onwrite = function(stream, er) {
2281
+ var state = stream._writableState;
2282
+ var sync = state.sync;
2283
+ var cb = state.writecb;
2284
+ if (typeof cb !== "function")
2285
+ throw new ERR_MULTIPLE_CALLBACK;
2286
+ onwriteStateUpdate(state);
2287
+ if (er)
2288
+ onwriteError(stream, state, sync, er, cb);
2289
+ else {
2290
+ var finished = needFinish(state) || stream.destroyed;
2291
+ if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
2292
+ clearBuffer(stream, state);
2293
+ }
2294
+ if (sync) {
2295
+ process.nextTick(afterWrite, stream, state, finished, cb);
2296
+ } else {
2297
+ afterWrite(stream, state, finished, cb);
2298
+ }
2299
+ }
2300
+ };
2301
+ var afterWrite = function(stream, state, finished, cb) {
2302
+ if (!finished)
2303
+ onwriteDrain(stream, state);
2304
+ state.pendingcb--;
2305
+ cb();
2306
+ finishMaybe(stream, state);
2307
+ };
2308
+ var onwriteDrain = function(stream, state) {
2309
+ if (state.length === 0 && state.needDrain) {
2310
+ state.needDrain = false;
2311
+ stream.emit("drain");
2312
+ }
2313
+ };
2314
+ var clearBuffer = function(stream, state) {
2315
+ state.bufferProcessing = true;
2316
+ var entry = state.bufferedRequest;
2317
+ if (stream._writev && entry && entry.next) {
2318
+ var l = state.bufferedRequestCount;
2319
+ var buffer = new Array(l);
2320
+ var holder = state.corkedRequestsFree;
2321
+ holder.entry = entry;
2322
+ var count = 0;
2323
+ var allBuffers = true;
2324
+ while (entry) {
2325
+ buffer[count] = entry;
2326
+ if (!entry.isBuf)
2327
+ allBuffers = false;
2328
+ entry = entry.next;
2329
+ count += 1;
2330
+ }
2331
+ buffer.allBuffers = allBuffers;
2332
+ doWrite(stream, state, true, state.length, buffer, "", holder.finish);
2333
+ state.pendingcb++;
2334
+ state.lastBufferedRequest = null;
2335
+ if (holder.next) {
2336
+ state.corkedRequestsFree = holder.next;
2337
+ holder.next = null;
2338
+ } else {
2339
+ state.corkedRequestsFree = new CorkedRequest(state);
2340
+ }
2341
+ state.bufferedRequestCount = 0;
2342
+ } else {
2343
+ while (entry) {
2344
+ var chunk = entry.chunk;
2345
+ var encoding = entry.encoding;
2346
+ var cb = entry.callback;
2347
+ var len = state.objectMode ? 1 : chunk.length;
2348
+ doWrite(stream, state, false, len, chunk, encoding, cb);
2349
+ entry = entry.next;
2350
+ state.bufferedRequestCount--;
2351
+ if (state.writing) {
2352
+ break;
2353
+ }
2354
+ }
2355
+ if (entry === null)
2356
+ state.lastBufferedRequest = null;
2357
+ }
2358
+ state.bufferedRequest = entry;
2359
+ state.bufferProcessing = false;
2360
+ };
2361
+ var needFinish = function(state) {
2362
+ return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
2363
+ };
2364
+ var callFinal = function(stream, state) {
2365
+ stream._final(function(err) {
2366
+ state.pendingcb--;
2367
+ if (err) {
2368
+ errorOrDestroy(stream, err);
2369
+ }
2370
+ state.prefinished = true;
2371
+ stream.emit("prefinish");
2372
+ finishMaybe(stream, state);
2373
+ });
2374
+ };
2375
+ var prefinish = function(stream, state) {
2376
+ if (!state.prefinished && !state.finalCalled) {
2377
+ if (typeof stream._final === "function" && !state.destroyed) {
2378
+ state.pendingcb++;
2379
+ state.finalCalled = true;
2380
+ process.nextTick(callFinal, stream, state);
2381
+ } else {
2382
+ state.prefinished = true;
2383
+ stream.emit("prefinish");
2384
+ }
2385
+ }
2386
+ };
2387
+ var finishMaybe = function(stream, state) {
2388
+ var need = needFinish(state);
2389
+ if (need) {
2390
+ prefinish(stream, state);
2391
+ if (state.pendingcb === 0) {
2392
+ state.finished = true;
2393
+ stream.emit("finish");
2394
+ if (state.autoDestroy) {
2395
+ var rState = stream._readableState;
2396
+ if (!rState || rState.autoDestroy && rState.endEmitted) {
2397
+ stream.destroy();
2398
+ }
2399
+ }
2400
+ }
2401
+ }
2402
+ return need;
2403
+ };
2404
+ var endWritable = function(stream, state, cb) {
2405
+ state.ending = true;
2406
+ finishMaybe(stream, state);
2407
+ if (cb) {
2408
+ if (state.finished)
2409
+ process.nextTick(cb);
2410
+ else
2411
+ stream.once("finish", cb);
2412
+ }
2413
+ state.ended = true;
2414
+ stream.writable = false;
2415
+ };
2416
+ var onCorkedFinish = function(corkReq, state, err) {
2417
+ var entry = corkReq.entry;
2418
+ corkReq.entry = null;
2419
+ while (entry) {
2420
+ var cb = entry.callback;
2421
+ state.pendingcb--;
2422
+ cb(err);
2423
+ entry = entry.next;
2424
+ }
2425
+ state.corkedRequestsFree.next = corkReq;
2426
+ };
2427
+ module.exports = Writable;
2428
+ var Duplex;
2429
+ Writable.WritableState = WritableState;
2430
+ var internalUtil = {
2431
+ deprecate: require_node()
2432
+ };
2433
+ var Stream = import.meta.require("stream");
2434
+ var Buffer = import.meta.require("buffer").Buffer;
2435
+ var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
2436
+ };
2437
+ var destroyImpl = require_destroy();
2438
+ var _require = require_state();
2439
+ var getHighWaterMark = _require.getHighWaterMark;
2440
+ var _require$codes = require_errors().codes;
2441
+ var ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE;
2442
+ var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
2443
+ var ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK;
2444
+ var ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE;
2445
+ var ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
2446
+ var ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES;
2447
+ var ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END;
2448
+ var ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
2449
+ var errorOrDestroy = destroyImpl.errorOrDestroy;
2450
+ require_inherits()(Writable, Stream);
2451
+ WritableState.prototype.getBuffer = function getBuffer() {
2452
+ var current = this.bufferedRequest;
2453
+ var out = [];
2454
+ while (current) {
2455
+ out.push(current);
2456
+ current = current.next;
2457
+ }
2458
+ return out;
2459
+ };
2460
+ (function() {
2461
+ try {
2462
+ Object.defineProperty(WritableState.prototype, "buffer", {
2463
+ get: internalUtil.deprecate(function writableStateBufferGetter() {
2464
+ return this.getBuffer();
2465
+ }, "_writableState.buffer is deprecated. Use _writableState.getBuffer instead.", "DEP0003")
2466
+ });
2467
+ } catch (_) {
2468
+ }
2469
+ })();
2470
+ var realHasInstance;
2471
+ if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") {
2472
+ realHasInstance = Function.prototype[Symbol.hasInstance];
2473
+ Object.defineProperty(Writable, Symbol.hasInstance, {
2474
+ value: function value(object) {
2475
+ if (realHasInstance.call(this, object))
2476
+ return true;
2477
+ if (this !== Writable)
2478
+ return false;
2479
+ return object && object._writableState instanceof WritableState;
2480
+ }
2481
+ });
2482
+ } else {
2483
+ realHasInstance = function realHasInstance(object) {
2484
+ return object instanceof this;
2485
+ };
2486
+ }
2487
+ Writable.prototype.pipe = function() {
2488
+ errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE);
2489
+ };
2490
+ Writable.prototype.write = function(chunk, encoding, cb) {
2491
+ var state = this._writableState;
2492
+ var ret = false;
2493
+ var isBuf = !state.objectMode && _isUint8Array(chunk);
2494
+ if (isBuf && !Buffer.isBuffer(chunk)) {
2495
+ chunk = _uint8ArrayToBuffer(chunk);
2496
+ }
2497
+ if (typeof encoding === "function") {
2498
+ cb = encoding;
2499
+ encoding = null;
2500
+ }
2501
+ if (isBuf)
2502
+ encoding = "buffer";
2503
+ else if (!encoding)
2504
+ encoding = state.defaultEncoding;
2505
+ if (typeof cb !== "function")
2506
+ cb = nop;
2507
+ if (state.ending)
2508
+ writeAfterEnd(this, cb);
2509
+ else if (isBuf || validChunk(this, state, chunk, cb)) {
2510
+ state.pendingcb++;
2511
+ ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
2512
+ }
2513
+ return ret;
2514
+ };
2515
+ Writable.prototype.cork = function() {
2516
+ this._writableState.corked++;
2517
+ };
2518
+ Writable.prototype.uncork = function() {
2519
+ var state = this._writableState;
2520
+ if (state.corked) {
2521
+ state.corked--;
2522
+ if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest)
2523
+ clearBuffer(this, state);
2524
+ }
2525
+ };
2526
+ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
2527
+ if (typeof encoding === "string")
2528
+ encoding = encoding.toLowerCase();
2529
+ if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1))
2530
+ throw new ERR_UNKNOWN_ENCODING(encoding);
2531
+ this._writableState.defaultEncoding = encoding;
2532
+ return this;
2533
+ };
2534
+ Object.defineProperty(Writable.prototype, "writableBuffer", {
2535
+ enumerable: false,
2536
+ get: function get() {
2537
+ return this._writableState && this._writableState.getBuffer();
2538
+ }
2539
+ });
2540
+ Object.defineProperty(Writable.prototype, "writableHighWaterMark", {
2541
+ enumerable: false,
2542
+ get: function get() {
2543
+ return this._writableState.highWaterMark;
2544
+ }
2545
+ });
2546
+ Writable.prototype._write = function(chunk, encoding, cb) {
2547
+ cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()"));
2548
+ };
2549
+ Writable.prototype._writev = null;
2550
+ Writable.prototype.end = function(chunk, encoding, cb) {
2551
+ var state = this._writableState;
2552
+ if (typeof chunk === "function") {
2553
+ cb = chunk;
2554
+ chunk = null;
2555
+ encoding = null;
2556
+ } else if (typeof encoding === "function") {
2557
+ cb = encoding;
2558
+ encoding = null;
2559
+ }
2560
+ if (chunk !== null && chunk !== undefined)
2561
+ this.write(chunk, encoding);
2562
+ if (state.corked) {
2563
+ state.corked = 1;
2564
+ this.uncork();
2565
+ }
2566
+ if (!state.ending)
2567
+ endWritable(this, state, cb);
2568
+ return this;
2569
+ };
2570
+ Object.defineProperty(Writable.prototype, "writableLength", {
2571
+ enumerable: false,
2572
+ get: function get() {
2573
+ return this._writableState.length;
2574
+ }
2575
+ });
2576
+ Object.defineProperty(Writable.prototype, "destroyed", {
2577
+ enumerable: false,
2578
+ get: function get() {
2579
+ if (this._writableState === undefined) {
2580
+ return false;
2581
+ }
2582
+ return this._writableState.destroyed;
2583
+ },
2584
+ set: function set(value) {
2585
+ if (!this._writableState) {
2586
+ return;
2587
+ }
2588
+ this._writableState.destroyed = value;
2589
+ }
2590
+ });
2591
+ Writable.prototype.destroy = destroyImpl.destroy;
2592
+ Writable.prototype._undestroy = destroyImpl.undestroy;
2593
+ Writable.prototype._destroy = function(err, cb) {
2594
+ cb(err);
2595
+ };
2596
+ });
2597
+
2598
+ // /Users/schettn/Documents/pylon/node_modules/triple-beam/config/cli.js
2599
+ var require_cli = __commonJS((exports) => {
2600
+ exports.levels = {
2601
+ error: 0,
2602
+ warn: 1,
2603
+ help: 2,
2604
+ data: 3,
2605
+ info: 4,
2606
+ debug: 5,
2607
+ prompt: 6,
2608
+ verbose: 7,
2609
+ input: 8,
2610
+ silly: 9
2611
+ };
2612
+ exports.colors = {
2613
+ error: "red",
2614
+ warn: "yellow",
2615
+ help: "cyan",
2616
+ data: "grey",
2617
+ info: "green",
2618
+ debug: "blue",
2619
+ prompt: "grey",
2620
+ verbose: "cyan",
2621
+ input: "grey",
2622
+ silly: "magenta"
2623
+ };
2624
+ });
2625
+
2626
+ // /Users/schettn/Documents/pylon/node_modules/triple-beam/config/npm.js
2627
+ var require_npm = __commonJS((exports) => {
2628
+ exports.levels = {
2629
+ error: 0,
2630
+ warn: 1,
2631
+ info: 2,
2632
+ http: 3,
2633
+ verbose: 4,
2634
+ debug: 5,
2635
+ silly: 6
2636
+ };
2637
+ exports.colors = {
2638
+ error: "red",
2639
+ warn: "yellow",
2640
+ info: "green",
2641
+ http: "green",
2642
+ verbose: "cyan",
2643
+ debug: "blue",
2644
+ silly: "magenta"
2645
+ };
2646
+ });
2647
+
2648
+ // /Users/schettn/Documents/pylon/node_modules/triple-beam/config/syslog.js
2649
+ var require_syslog = __commonJS((exports) => {
2650
+ exports.levels = {
2651
+ emerg: 0,
2652
+ alert: 1,
2653
+ crit: 2,
2654
+ error: 3,
2655
+ warning: 4,
2656
+ notice: 5,
2657
+ info: 6,
2658
+ debug: 7
2659
+ };
2660
+ exports.colors = {
2661
+ emerg: "red",
2662
+ alert: "yellow",
2663
+ crit: "red",
2664
+ error: "red",
2665
+ warning: "red",
2666
+ notice: "yellow",
2667
+ info: "green",
2668
+ debug: "blue"
2669
+ };
2670
+ });
2671
+
2672
+ // /Users/schettn/Documents/pylon/node_modules/triple-beam/config/index.js
2673
+ var require_config = __commonJS((exports) => {
2674
+ Object.defineProperty(exports, "cli", {
2675
+ value: require_cli()
2676
+ });
2677
+ Object.defineProperty(exports, "npm", {
2678
+ value: require_npm()
2679
+ });
2680
+ Object.defineProperty(exports, "syslog", {
2681
+ value: require_syslog()
2682
+ });
2683
+ });
2684
+
2685
+ // /Users/schettn/Documents/pylon/node_modules/triple-beam/index.js
2686
+ var require_triple_beam = __commonJS((exports) => {
2687
+ Object.defineProperty(exports, "LEVEL", {
2688
+ value: Symbol.for("level")
2689
+ });
2690
+ Object.defineProperty(exports, "MESSAGE", {
2691
+ value: Symbol.for("message")
2692
+ });
2693
+ Object.defineProperty(exports, "SPLAT", {
2694
+ value: Symbol.for("splat")
2695
+ });
2696
+ Object.defineProperty(exports, "configs", {
2697
+ value: require_config()
2698
+ });
2699
+ });
2700
+
2701
+ // /Users/schettn/Documents/pylon/node_modules/winston-transport/modern.js
2702
+ var require_modern = __commonJS((exports, module) => {
2703
+ var util = import.meta.require("util");
2704
+ var Writable = require__stream_writable();
2705
+ var { LEVEL } = require_triple_beam();
2706
+ var TransportStream = module.exports = function TransportStream(options = {}) {
2707
+ Writable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
2708
+ this.format = options.format;
2709
+ this.level = options.level;
2710
+ this.handleExceptions = options.handleExceptions;
2711
+ this.handleRejections = options.handleRejections;
2712
+ this.silent = options.silent;
2713
+ if (options.log)
2714
+ this.log = options.log;
2715
+ if (options.logv)
2716
+ this.logv = options.logv;
2717
+ if (options.close)
2718
+ this.close = options.close;
2719
+ this.once("pipe", (logger) => {
2720
+ this.levels = logger.levels;
2721
+ this.parent = logger;
2722
+ });
2723
+ this.once("unpipe", (src) => {
2724
+ if (src === this.parent) {
2725
+ this.parent = null;
2726
+ if (this.close) {
2727
+ this.close();
2728
+ }
2729
+ }
2730
+ });
2731
+ };
2732
+ util.inherits(TransportStream, Writable);
2733
+ TransportStream.prototype._write = function _write(info, enc, callback) {
2734
+ if (this.silent || info.exception === true && !this.handleExceptions) {
2735
+ return callback(null);
2736
+ }
2737
+ const level = this.level || this.parent && this.parent.level;
2738
+ if (!level || this.levels[level] >= this.levels[info[LEVEL]]) {
2739
+ if (info && !this.format) {
2740
+ return this.log(info, callback);
2741
+ }
2742
+ let errState;
2743
+ let transformed;
2744
+ try {
2745
+ transformed = this.format.transform(Object.assign({}, info), this.format.options);
2746
+ } catch (err) {
2747
+ errState = err;
2748
+ }
2749
+ if (errState || !transformed) {
2750
+ callback();
2751
+ if (errState)
2752
+ throw errState;
2753
+ return;
2754
+ }
2755
+ return this.log(transformed, callback);
2756
+ }
2757
+ this._writableState.sync = false;
2758
+ return callback(null);
2759
+ };
2760
+ TransportStream.prototype._writev = function _writev(chunks, callback) {
2761
+ if (this.logv) {
2762
+ const infos = chunks.filter(this._accept, this);
2763
+ if (!infos.length) {
2764
+ return callback(null);
2765
+ }
2766
+ return this.logv(infos, callback);
2767
+ }
2768
+ for (let i = 0;i < chunks.length; i++) {
2769
+ if (!this._accept(chunks[i]))
2770
+ continue;
2771
+ if (chunks[i].chunk && !this.format) {
2772
+ this.log(chunks[i].chunk, chunks[i].callback);
2773
+ continue;
2774
+ }
2775
+ let errState;
2776
+ let transformed;
2777
+ try {
2778
+ transformed = this.format.transform(Object.assign({}, chunks[i].chunk), this.format.options);
2779
+ } catch (err) {
2780
+ errState = err;
2781
+ }
2782
+ if (errState || !transformed) {
2783
+ chunks[i].callback();
2784
+ if (errState) {
2785
+ callback(null);
2786
+ throw errState;
2787
+ }
2788
+ } else {
2789
+ this.log(transformed, chunks[i].callback);
2790
+ }
2791
+ }
2792
+ return callback(null);
2793
+ };
2794
+ TransportStream.prototype._accept = function _accept(write) {
2795
+ const info = write.chunk;
2796
+ if (this.silent) {
2797
+ return false;
2798
+ }
2799
+ const level = this.level || this.parent && this.parent.level;
2800
+ if (info.exception === true || !level || this.levels[level] >= this.levels[info[LEVEL]]) {
2801
+ if (this.handleExceptions || info.exception !== true) {
2802
+ return true;
2803
+ }
2804
+ }
2805
+ return false;
2806
+ };
2807
+ TransportStream.prototype._nop = function _nop() {
2808
+ return;
2809
+ };
2810
+ });
2811
+
2812
+ // /Users/schettn/Documents/pylon/node_modules/winston-transport/legacy.js
2813
+ var require_legacy = __commonJS((exports, module) => {
2814
+ var util = import.meta.require("util");
2815
+ var { LEVEL } = require_triple_beam();
2816
+ var TransportStream = require_modern();
2817
+ var LegacyTransportStream = module.exports = function LegacyTransportStream(options = {}) {
2818
+ TransportStream.call(this, options);
2819
+ if (!options.transport || typeof options.transport.log !== "function") {
2820
+ throw new Error("Invalid transport, must be an object with a log method.");
2821
+ }
2822
+ this.transport = options.transport;
2823
+ this.level = this.level || options.transport.level;
2824
+ this.handleExceptions = this.handleExceptions || options.transport.handleExceptions;
2825
+ this._deprecated();
2826
+ function transportError(err) {
2827
+ this.emit("error", err, this.transport);
2828
+ }
2829
+ if (!this.transport.__winstonError) {
2830
+ this.transport.__winstonError = transportError.bind(this);
2831
+ this.transport.on("error", this.transport.__winstonError);
2832
+ }
2833
+ };
2834
+ util.inherits(LegacyTransportStream, TransportStream);
2835
+ LegacyTransportStream.prototype._write = function _write(info, enc, callback) {
2836
+ if (this.silent || info.exception === true && !this.handleExceptions) {
2837
+ return callback(null);
2838
+ }
2839
+ if (!this.level || this.levels[this.level] >= this.levels[info[LEVEL]]) {
2840
+ this.transport.log(info[LEVEL], info.message, info, this._nop);
2841
+ }
2842
+ callback(null);
2843
+ };
2844
+ LegacyTransportStream.prototype._writev = function _writev(chunks, callback) {
2845
+ for (let i = 0;i < chunks.length; i++) {
2846
+ if (this._accept(chunks[i])) {
2847
+ this.transport.log(chunks[i].chunk[LEVEL], chunks[i].chunk.message, chunks[i].chunk, this._nop);
2848
+ chunks[i].callback();
2849
+ }
2850
+ }
2851
+ return callback(null);
2852
+ };
2853
+ LegacyTransportStream.prototype._deprecated = function _deprecated() {
2854
+ console.error([
2855
+ `${this.transport.name} is a legacy winston transport. Consider upgrading: `,
2856
+ "- Upgrade docs: https://github.com/winstonjs/winston/blob/master/UPGRADE-3.0.md"
2857
+ ].join("\n"));
2858
+ };
2859
+ LegacyTransportStream.prototype.close = function close() {
2860
+ if (this.transport.close) {
2861
+ this.transport.close();
2862
+ }
2863
+ if (this.transport.__winstonError) {
2864
+ this.transport.removeListener("error", this.transport.__winstonError);
2865
+ this.transport.__winstonError = null;
2866
+ }
2867
+ };
2868
+ });
2869
+
2870
+ // /Users/schettn/Documents/pylon/node_modules/winston-transport/index.js
2871
+ var require_winston_transport = __commonJS((exports, module) => {
2872
+ module.exports = require_modern();
2873
+ module.exports.LegacyTransportStream = require_legacy();
2874
+ });
2875
+
2876
+ // src/define-pylon.ts
2877
+ import {
2878
+ GraphQLError
2879
+ } from "graphql";
2880
+ import * as Sentry from "@sentry/bun";
2881
+
2882
+ // src/context.ts
2883
+ import {AsyncLocalStorage} from "async_hooks";
2884
+ var asyncContext = new AsyncLocalStorage;
2885
+ var getContext = () => {
2886
+ const ctx = asyncContext.getStore();
2887
+ if (!ctx) {
2888
+ throw new Error("Context not defined");
2889
+ }
2890
+ return ctx;
2891
+ };
2892
+ var setContext = (context) => {
2893
+ return asyncContext.enterWith(context);
2894
+ };
2895
+
2896
+ // src/define-pylon.ts
2897
+ async function wrapFunctionsRecursively(obj, wrapper, that = null, selectionSet = []) {
2898
+ if (obj === null || obj instanceof Date) {
2899
+ return obj;
2900
+ }
2901
+ if (Array.isArray(obj)) {
2902
+ return await Promise.all(obj.map(async (item) => {
2903
+ return await wrapFunctionsRecursively(item, wrapper, that, selectionSet);
2904
+ }));
2905
+ } else if (typeof obj === "function") {
2906
+ return Sentry.startSpan({
2907
+ name: obj.name,
2908
+ op: "pylon.fn"
2909
+ }, async () => {
2910
+ return await wrapper.call(that, obj, selectionSet);
2911
+ });
2912
+ } else if (obj instanceof Promise) {
2913
+ return await wrapFunctionsRecursively(await obj, wrapper, that, selectionSet);
2914
+ } else if (typeof obj === "object") {
2915
+ const result = {};
2916
+ const fields = [];
2917
+ that = obj;
2918
+ for (const selection of selectionSet) {
2919
+ if (selection.kind === "Field") {
2920
+ selection.selectionSet;
2921
+ fields.push({
2922
+ key: selection.name.value,
2923
+ selectionSet: selection.selectionSet?.selections || []
2924
+ });
2925
+ }
2926
+ }
2927
+ for (const { key, selectionSet: selectionSet2 } of Object.values(fields)) {
2928
+ result[key] = await wrapFunctionsRecursively(obj[key], wrapper, that, selectionSet2);
2929
+ }
2930
+ if (Object.keys(result).length === 0) {
2931
+ return obj;
2932
+ }
2933
+ return result;
2934
+ } else {
2935
+ return await obj;
2936
+ }
2937
+ }
2938
+ var spreadFunctionArguments = function(fn) {
2939
+ return (otherArgs, c, info) => {
2940
+ const selections = arguments[1];
2941
+ let args = {};
2942
+ if (info) {
2943
+ const type = info.parentType;
2944
+ const field = type.getFields()[info.fieldName];
2945
+ const fieldArguments = field?.args;
2946
+ const preparedArguments = fieldArguments?.reduce((acc, arg) => {
2947
+ if (otherArgs[arg.name] !== undefined) {
2948
+ acc[arg.name] = otherArgs[arg.name];
2949
+ } else {
2950
+ acc[arg.name] = undefined;
2951
+ }
2952
+ return acc;
2953
+ }, {});
2954
+ if (preparedArguments) {
2955
+ args = preparedArguments;
2956
+ }
2957
+ } else {
2958
+ args = otherArgs;
2959
+ }
2960
+ const orderedArgs = Object.keys(args).map((key) => args[key]);
2961
+ const that = this || {};
2962
+ const result = wrapFunctionsRecursively(fn.call(that, ...orderedArgs), spreadFunctionArguments, this, selections);
2963
+ return result;
2964
+ };
2965
+ };
2966
+ var defineService = (plainResolvers, options) => {
2967
+ const typedPlainResolvers = plainResolvers;
2968
+ typedPlainResolvers.Query = {
2969
+ ...typedPlainResolvers.Query,
2970
+ version: "NOT_IMPLEMENTED_YET"
2971
+ };
2972
+ const graphqlResolvers = resolversToGraphQLResolvers(typedPlainResolvers, options?.context);
2973
+ return {
2974
+ graphqlResolvers,
2975
+ plainResolvers: typedPlainResolvers,
2976
+ getContext: () => {
2977
+ return getContext();
2978
+ }
2979
+ };
2980
+ };
2981
+ var resolversToGraphQLResolvers = (resolvers, configureContext) => {
2982
+ const rootGraphqlResolver = (fn) => async (_, args, ctx, info) => {
2983
+ return Sentry.withScope(async (scope) => {
2984
+ const ctx2 = asyncContext.getStore();
2985
+ if (!ctx2) {
2986
+ throw new Error("Internal error. Context not defined.");
2987
+ }
2988
+ const auth = ctx2.get("auth");
2989
+ if (auth?.active) {
2990
+ scope.setUser({
2991
+ id: auth.sub,
2992
+ username: auth.preferred_username,
2993
+ email: auth.email,
2994
+ details: auth
2995
+ });
2996
+ }
2997
+ if (configureContext) {
2998
+ const configuredCtx = await Sentry.startSpan({
2999
+ name: "Context",
3000
+ op: "pylon.context"
3001
+ }, () => configureContext(ctx2));
3002
+ asyncContext.enterWith(configuredCtx);
3003
+ }
3004
+ const path = info.path;
3005
+ const isQuery = info.operation.operation === "query";
3006
+ const isMutation = info.operation.operation === "mutation";
3007
+ if (!isQuery && !isMutation) {
3008
+ throw new Error("Only queries and mutations are supported.");
3009
+ }
3010
+ const type = isQuery ? info.schema.getQueryType() : info.schema.getMutationType();
3011
+ const field = type?.getFields()[path.key];
3012
+ const fieldArguments = field?.args || [];
3013
+ const preparedArguments = fieldArguments.reduce((acc, arg) => {
3014
+ if (args[arg.name] !== undefined) {
3015
+ acc[arg.name] = args[arg.name];
3016
+ } else {
3017
+ acc[arg.name] = undefined;
3018
+ }
3019
+ return acc;
3020
+ }, {});
3021
+ let inner = await fn;
3022
+ let baseSelectionSet = [];
3023
+ for (const selection of info.operation.selectionSet.selections) {
3024
+ if (selection.kind === "Field" && selection.name.value === path.key) {
3025
+ baseSelectionSet = selection.selectionSet?.selections || [];
3026
+ }
3027
+ }
3028
+ const wrappedFn = await wrapFunctionsRecursively(inner, spreadFunctionArguments, null, baseSelectionSet);
3029
+ if (typeof wrappedFn !== "function") {
3030
+ return wrappedFn;
3031
+ }
3032
+ return await wrappedFn(preparedArguments);
3033
+ });
3034
+ };
3035
+ const graphqlResolvers = {};
3036
+ if (resolvers.Query) {
3037
+ for (const [key, value] of Object.entries(resolvers.Query)) {
3038
+ if (!graphqlResolvers.Query) {
3039
+ graphqlResolvers.Query = {};
3040
+ }
3041
+ graphqlResolvers.Query[key] = rootGraphqlResolver(value);
3042
+ }
3043
+ }
3044
+ if (resolvers.Mutation) {
3045
+ if (!graphqlResolvers.Mutation) {
3046
+ graphqlResolvers.Mutation = {};
3047
+ }
3048
+ for (const [key, value] of Object.entries(resolvers.Mutation)) {
3049
+ graphqlResolvers.Mutation[key] = rootGraphqlResolver(value);
3050
+ }
3051
+ }
3052
+ return graphqlResolvers;
3053
+ };
3054
+
3055
+ class ServiceError extends GraphQLError {
3056
+ extensions;
3057
+ constructor(message, extensions) {
3058
+ super(message);
3059
+ this.extensions = extensions;
3060
+ }
3061
+ }
3062
+ // src/logger/index.ts
3063
+ import winston from "winston";
3064
+
3065
+ // src/logger/winston-sentry-transport.ts
3066
+ var import_winston_transport = __toESM(require_winston_transport(), 1);
3067
+ import _ from "lodash";
3068
+ import * as Sentry2 from "@sentry/bun";
3069
+ var errorHandler = (err) => {
3070
+ console.error(err);
3071
+ };
3072
+
3073
+ class WinstonSentryTransport extends import_winston_transport.default {
3074
+ name;
3075
+ tags;
3076
+ levelsMap;
3077
+ constructor(opts) {
3078
+ super(opts);
3079
+ this.name = "winston-sentry-log";
3080
+ this.tags = {};
3081
+ const options = opts;
3082
+ _.defaultsDeep(opts, {
3083
+ errorHandler,
3084
+ config: {
3085
+ dsn: process.env.SENTRY_DSN
3086
+ },
3087
+ level: "info",
3088
+ levelsMap: {
3089
+ silly: "debug",
3090
+ verbose: "debug",
3091
+ info: "info",
3092
+ debug: "debug",
3093
+ warn: "warning",
3094
+ error: "error"
3095
+ },
3096
+ name: "winston-sentry-log",
3097
+ silent: false
3098
+ });
3099
+ this.levelsMap = options.levelsMap;
3100
+ if (options.tags) {
3101
+ this.tags = options.tags;
3102
+ } else if (options.globalTags) {
3103
+ this.tags = options.globalTags;
3104
+ } else if (options.config.tags) {
3105
+ this.tags = options.config.tags;
3106
+ }
3107
+ if (options.extra) {
3108
+ options.config.extra = options.config.extra || {};
3109
+ options.config.extra = _.defaults(options.config.extra, options.extra);
3110
+ }
3111
+ Sentry2.configureScope((scope) => {
3112
+ if (!_.isEmpty(this.tags)) {
3113
+ Object.keys(this.tags).forEach((key) => {
3114
+ scope.setTag(key, this.tags[key]);
3115
+ });
3116
+ }
3117
+ });
3118
+ }
3119
+ log(info, callback) {
3120
+ const { message, fingerprint } = info;
3121
+ const level = Object.keys(this.levelsMap).find((key) => info.level.toString().includes(key));
3122
+ if (!level) {
3123
+ return callback(null, true);
3124
+ }
3125
+ const meta = Object.assign({}, _.omit(info, ["level", "message", "label"]));
3126
+ setImmediate(() => {
3127
+ this.emit("logged", level);
3128
+ });
3129
+ if (!!this.silent) {
3130
+ return callback(null, true);
3131
+ }
3132
+ const context2 = {};
3133
+ context2.level = this.levelsMap[level];
3134
+ context2.extra = _.omit(meta, ["user", "tags"]);
3135
+ context2.fingerprint = [fingerprint, "development"];
3136
+ Sentry2.withScope((scope) => {
3137
+ const user = _.get(meta, "user");
3138
+ if (_.has(context2, "extra")) {
3139
+ Object.keys(context2.extra).forEach((key) => {
3140
+ scope.setExtra(key, context2.extra[key]);
3141
+ });
3142
+ }
3143
+ if (!_.isEmpty(meta.tags) && _.isObject(meta.tags)) {
3144
+ Object.keys(meta.tags).forEach((key) => {
3145
+ scope.setTag(key, meta.tags[key]);
3146
+ });
3147
+ }
3148
+ if (!!user) {
3149
+ scope.setUser(user);
3150
+ }
3151
+ if (context2.level === "error" || context2.level === "fatal") {
3152
+ let err = null;
3153
+ if (_.isError(info)) {
3154
+ err = info;
3155
+ } else {
3156
+ err = new Error(message);
3157
+ if (info.stack) {
3158
+ err.stack = info.stack;
3159
+ }
3160
+ }
3161
+ Sentry2.captureException(err);
3162
+ return callback(null, true);
3163
+ }
3164
+ Sentry2.captureMessage(message, context2.level);
3165
+ return callback(null, true);
3166
+ });
3167
+ return;
3168
+ }
3169
+ }
3170
+ var winston_sentry_transport_default = WinstonSentryTransport;
3171
+
3172
+ // src/logger/index.ts
3173
+ var logger = winston.createLogger({
3174
+ transports: [
3175
+ new winston_sentry_transport_default({
3176
+ level: "info"
3177
+ })
3178
+ ]
3179
+ });
3180
+ if (true) {
3181
+ logger.add(new winston.transports.Console({
3182
+ format: winston.format.simple()
3183
+ }));
3184
+ }
3185
+ // src/auth/index.ts
3186
+ import jwt from "jsonwebtoken";
3187
+ import path from "path";
3188
+ import {HTTPException as HTTPException2} from "hono/http-exception";
3189
+ import * as Sentry3 from "@sentry/bun";
3190
+
3191
+ // src/auth/decorators/requireAuth.ts
3192
+ import {HTTPException} from "hono/http-exception";
3193
+ function requireAuth(checks) {
3194
+ const checkAuth = async (c) => {
3195
+ const ctx = await c;
3196
+ try {
3197
+ await auth.require(checks)(ctx, async () => {
3198
+ });
3199
+ } catch (e) {
3200
+ if (e instanceof HTTPException) {
3201
+ if (e.status === 401) {
3202
+ throw new ServiceError(e.message, {
3203
+ statusCode: 401,
3204
+ code: "AUTH_REQUIRED"
3205
+ });
3206
+ } else if (e.status === 403) {
3207
+ const res = e.getResponse();
3208
+ throw new ServiceError(res.statusText, {
3209
+ statusCode: res.status,
3210
+ code: "AUTHORIZATION_REQUIRED",
3211
+ details: {
3212
+ missingRoles: res.headers.get("Missing-Roles")?.split(","),
3213
+ obtainedRoles: res.headers.get("Obtained-Roles")?.split(",")
3214
+ }
3215
+ });
3216
+ } else {
3217
+ throw e;
3218
+ }
3219
+ }
3220
+ throw e;
3221
+ }
3222
+ };
3223
+ return function fn(...args) {
3224
+ const target = args[0];
3225
+ const propertyKey = args[1];
3226
+ const descriptor = args[2];
3227
+ if (descriptor) {
3228
+ const originalMethod = descriptor.value;
3229
+ descriptor.value = async function(...args2) {
3230
+ await checkAuth(getContext());
3231
+ return originalMethod.apply(this, args2);
3232
+ };
3233
+ } else {
3234
+ Object.defineProperty(target, propertyKey, {
3235
+ get: async function() {
3236
+ await checkAuth(getContext());
3237
+ return this._value;
3238
+ },
3239
+ set: function(newValue) {
3240
+ this._value = newValue;
3241
+ }
3242
+ });
3243
+ }
3244
+ };
3245
+ }
3246
+
3247
+ // src/auth/index.ts
3248
+ var AUTH_PROJECT_ID = process.env.AUTH_PROJECT_ID;
3249
+ var authInitialize = () => {
3250
+ const authKeyFilePath = path.join(process.cwd(), "key.json");
3251
+ const authKey = process.env.AUTH_KEY;
3252
+ const API_PRIVATE_KEY_FILE = authKey ? JSON.parse(authKey) : import.meta.require(authKeyFilePath);
3253
+ const AUTH_ISSUER = process.env.AUTH_ISSUER;
3254
+ if (!AUTH_ISSUER) {
3255
+ throw new Error("AUTH_ISSUER is not set");
3256
+ }
3257
+ logger.info(`AUTH_ISSUER: ${AUTH_ISSUER}`);
3258
+ logger.info(`AUTH_PROJECT_ID: ${AUTH_PROJECT_ID}`);
3259
+ const middleware = Sentry3.startSpan({
3260
+ name: "AuthMiddleware",
3261
+ op: "auth"
3262
+ }, () => async function(ctx, next) {
3263
+ const ZITADEL_INTROSPECTION_URL = `${AUTH_ISSUER}/oauth/v2/introspect`;
3264
+ async function getRolesFromToken(tokenString) {
3265
+ const response = await fetch(`${AUTH_ISSUER}/auth/v1/usergrants/me/_search`, {
3266
+ method: "POST",
3267
+ headers: {
3268
+ "Content-Type": "application/json",
3269
+ Authorization: `Bearer ${tokenString}`
3270
+ }
3271
+ });
3272
+ const data = await response.json();
3273
+ const userRoles = data.result?.map((grant) => {
3274
+ return (grant.roles || []).map((role) => {
3275
+ return `${grant.projectId}:${role}`;
3276
+ });
3277
+ }) || [];
3278
+ const projectScopedRoles = userRoles.flat();
3279
+ const rolesSet = new Set(projectScopedRoles);
3280
+ if (AUTH_PROJECT_ID) {
3281
+ for (const role of projectScopedRoles) {
3282
+ const [projectId, ...roleNameParts] = role.split(":");
3283
+ const roleName = roleNameParts.join(":");
3284
+ if (projectId === AUTH_PROJECT_ID) {
3285
+ rolesSet.add(roleName);
3286
+ }
3287
+ }
3288
+ }
3289
+ return Array.from(rolesSet);
3290
+ }
3291
+ async function introspectToken(tokenString) {
3292
+ const payload = {
3293
+ iss: API_PRIVATE_KEY_FILE.clientId,
3294
+ sub: API_PRIVATE_KEY_FILE.clientId,
3295
+ aud: AUTH_ISSUER,
3296
+ exp: Math.floor(Date.now() / 1000) + 3600,
3297
+ iat: Math.floor(Date.now() / 1000)
3298
+ };
3299
+ const headers = {
3300
+ alg: "RS256",
3301
+ kid: API_PRIVATE_KEY_FILE.keyId
3302
+ };
3303
+ const jwtToken = jwt.sign(payload, API_PRIVATE_KEY_FILE.key, {
3304
+ algorithm: "RS256",
3305
+ header: headers
3306
+ });
3307
+ const scopeSet = new Set;
3308
+ scopeSet.add("openid");
3309
+ scopeSet.add("profile");
3310
+ scopeSet.add("email");
3311
+ if (AUTH_PROJECT_ID) {
3312
+ scopeSet.add(`urn:zitadel:iam:org:project:id:${AUTH_PROJECT_ID}:aud`);
3313
+ }
3314
+ const scope = Array.from(scopeSet).join(" ");
3315
+ const body = new URLSearchParams({
3316
+ client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
3317
+ client_assertion: jwtToken,
3318
+ token: tokenString,
3319
+ scope
3320
+ }).toString();
3321
+ try {
3322
+ const response = await fetch(ZITADEL_INTROSPECTION_URL, {
3323
+ method: "POST",
3324
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
3325
+ body
3326
+ });
3327
+ if (!response.ok) {
3328
+ throw new Error("Network response was not ok");
3329
+ }
3330
+ const tokenData = await response.json();
3331
+ const roles = await getRolesFromToken(tokenString);
3332
+ const state = {
3333
+ ...tokenData,
3334
+ roles
3335
+ };
3336
+ return state;
3337
+ } catch (error) {
3338
+ console.error("Error while introspecting token", error);
3339
+ throw new Error("Token introspection failed");
3340
+ }
3341
+ }
3342
+ let token = undefined;
3343
+ if (ctx.req.header("Authorization")) {
3344
+ const authHeader = ctx.req.header("Authorization");
3345
+ if (authHeader) {
3346
+ const parts = authHeader.split(" ");
3347
+ if (parts.length === 2 && parts[0] === "Bearer") {
3348
+ token = parts[1];
3349
+ }
3350
+ }
3351
+ }
3352
+ if (!token) {
3353
+ const queryToken = ctx.req.query("token");
3354
+ if (queryToken) {
3355
+ token = queryToken;
3356
+ }
3357
+ }
3358
+ if (token) {
3359
+ const auth2 = await introspectToken(token);
3360
+ if (auth2.active) {
3361
+ ctx.set("auth", auth2);
3362
+ Sentry3.setUser({
3363
+ id: auth2.sub,
3364
+ username: auth2.preferred_username,
3365
+ email: auth2.email,
3366
+ details: auth2
3367
+ });
3368
+ }
3369
+ }
3370
+ return next();
3371
+ });
3372
+ return middleware;
3373
+ };
3374
+ var authRequire = (checks = {}) => {
3375
+ const middleware = async (ctx, next) => {
3376
+ const auth2 = ctx.get("auth");
3377
+ if (!auth2) {
3378
+ throw new HTTPException2(401, {
3379
+ message: "Authentication required"
3380
+ });
3381
+ }
3382
+ if (checks.roles) {
3383
+ const roles = auth2.roles;
3384
+ const hasRole = checks.roles.some((role) => {
3385
+ return roles.includes(role) || roles.includes(`${AUTH_PROJECT_ID}:${role}`);
3386
+ });
3387
+ if (!hasRole) {
3388
+ const resError = new Response("Forbidden", {
3389
+ status: 403,
3390
+ statusText: "Forbidden",
3391
+ headers: {
3392
+ "Missing-Roles": checks.roles.join(","),
3393
+ "Obtained-Roles": roles.join(",")
3394
+ }
3395
+ });
3396
+ throw new HTTPException2(resError.status, { res: resError });
3397
+ }
3398
+ }
3399
+ return next();
3400
+ };
3401
+ return middleware;
3402
+ };
3403
+ var auth = {
3404
+ initialize: authInitialize,
3405
+ require: authRequire
3406
+ };
3407
+
3408
+ // src/index.ts
3409
+ import * as Sentry4 from "@sentry/bun";
3410
+ Sentry4.init({
3411
+ dsn: process.env.SENTRY_DSN,
3412
+ environment: "development",
3413
+ integrations: [...Sentry4.autoDiscoverNodePerformanceMonitoringIntegrations()],
3414
+ normalizeDepth: 10,
3415
+ tracesSampleRate: 1
3416
+ });
3417
+ export {
3418
+ setContext,
3419
+ requireAuth,
3420
+ logger,
3421
+ getContext,
3422
+ defineService,
3423
+ auth,
3424
+ asyncContext,
3425
+ ServiceError
3426
+ };
3427
+
3428
+ //# debugId=0CE28FCAEDBED79B64756e2164756e21