@jsenv/server 16.1.1 → 16.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
+ import require$$0 from "node:domain";
2
+ import { EventEmitter } from "node:events";
3
+ import fsPromises from "node:fs/promises";
1
4
  import os from "node:os";
2
5
  import path from "node:path";
3
- import fsPromises from "node:fs/promises";
4
- import { EventEmitter } from "node:events";
5
6
  import { StringDecoder } from "node:string_decoder";
6
- import require$$0 from "node:domain";
7
- import { PassThrough, Transform, Stream } from "node:stream";
8
7
  import fs from "node:fs";
9
8
  import require$$1, { createHash } from "node:crypto";
9
+ import { Transform, PassThrough, Stream } from "node:stream";
10
10
 
11
11
  /* eslint-disable no-underscore-dangle */
12
12
 
@@ -169,127 +169,870 @@ class VolatileFile extends EventEmitter {
169
169
  }
170
170
  }
171
171
 
172
- for(var r=256,n=[];r--;)n[r]=(r+256).toString(16).substring(1);function hexoid(r){r=r||16;var t="",o=0;return function(){if(!t||256===o){for(t="",o=(1+r)/2|0;o--;)t+=n[256*Math.random()|0];t=t.substring(o=0,r-2);}return t+n[o++]}}
172
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
173
173
 
174
- function getDefaultExportFromCjs$1 (x) {
175
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
174
+ var cuid2 = {};
175
+
176
+ var src = {};
177
+
178
+ var sha3 = {};
179
+
180
+ var _u64 = {};
181
+
182
+ var hasRequired_u64;
183
+
184
+ function require_u64 () {
185
+ if (hasRequired_u64) return _u64;
186
+ hasRequired_u64 = 1;
187
+ Object.defineProperty(_u64, "__esModule", { value: true });
188
+ _u64.toBig = _u64.shrSL = _u64.shrSH = _u64.rotrSL = _u64.rotrSH = _u64.rotrBL = _u64.rotrBH = _u64.rotr32L = _u64.rotr32H = _u64.rotlSL = _u64.rotlSH = _u64.rotlBL = _u64.rotlBH = _u64.add5L = _u64.add5H = _u64.add4L = _u64.add4H = _u64.add3L = _u64.add3H = void 0;
189
+ _u64.add = add;
190
+ _u64.fromBig = fromBig;
191
+ _u64.split = split;
192
+ /**
193
+ * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
194
+ * @todo re-check https://issues.chromium.org/issues/42212588
195
+ * @module
196
+ */
197
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
198
+ const _32n = /* @__PURE__ */ BigInt(32);
199
+ function fromBig(n, le = false) {
200
+ if (le)
201
+ return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
202
+ return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
203
+ }
204
+ function split(lst, le = false) {
205
+ const len = lst.length;
206
+ let Ah = new Uint32Array(len);
207
+ let Al = new Uint32Array(len);
208
+ for (let i = 0; i < len; i++) {
209
+ const { h, l } = fromBig(lst[i], le);
210
+ [Ah[i], Al[i]] = [h, l];
211
+ }
212
+ return [Ah, Al];
213
+ }
214
+ const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
215
+ _u64.toBig = toBig;
216
+ // for Shift in [0, 32)
217
+ const shrSH = (h, _l, s) => h >>> s;
218
+ _u64.shrSH = shrSH;
219
+ const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
220
+ _u64.shrSL = shrSL;
221
+ // Right rotate for Shift in [1, 32)
222
+ const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
223
+ _u64.rotrSH = rotrSH;
224
+ const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
225
+ _u64.rotrSL = rotrSL;
226
+ // Right rotate for Shift in (32, 64), NOTE: 32 is special case.
227
+ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
228
+ _u64.rotrBH = rotrBH;
229
+ const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
230
+ _u64.rotrBL = rotrBL;
231
+ // Right rotate for shift===32 (just swaps l&h)
232
+ const rotr32H = (_h, l) => l;
233
+ _u64.rotr32H = rotr32H;
234
+ const rotr32L = (h, _l) => h;
235
+ _u64.rotr32L = rotr32L;
236
+ // Left rotate for Shift in [1, 32)
237
+ const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
238
+ _u64.rotlSH = rotlSH;
239
+ const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
240
+ _u64.rotlSL = rotlSL;
241
+ // Left rotate for Shift in (32, 64), NOTE: 32 is special case.
242
+ const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
243
+ _u64.rotlBH = rotlBH;
244
+ const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
245
+ _u64.rotlBL = rotlBL;
246
+ // JS uses 32-bit signed integers for bitwise operations which means we cannot
247
+ // simple take carry out of low bit sum by shift, we need to use division.
248
+ function add(Ah, Al, Bh, Bl) {
249
+ const l = (Al >>> 0) + (Bl >>> 0);
250
+ return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
251
+ }
252
+ // Addition with more than 2 elements
253
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
254
+ _u64.add3L = add3L;
255
+ const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
256
+ _u64.add3H = add3H;
257
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
258
+ _u64.add4L = add4L;
259
+ const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
260
+ _u64.add4H = add4H;
261
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
262
+ _u64.add5L = add5L;
263
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
264
+ _u64.add5H = add5H;
265
+ // prettier-ignore
266
+ const u64 = {
267
+ fromBig, split, toBig,
268
+ shrSH, shrSL,
269
+ rotrSH, rotrSL, rotrBH, rotrBL,
270
+ rotr32H, rotr32L,
271
+ rotlSH, rotlSL, rotlBH, rotlBL,
272
+ add, add3L, add3H, add4L, add4H, add5H, add5L,
273
+ };
274
+ _u64.default = u64;
275
+
276
+ return _u64;
176
277
  }
177
278
 
178
- var once = {exports: {}};
279
+ var utils = {};
179
280
 
180
- var wrappy_1$1;
181
- var hasRequiredWrappy$1;
281
+ var crypto = {};
182
282
 
183
- function requireWrappy$1 () {
184
- if (hasRequiredWrappy$1) return wrappy_1$1;
185
- hasRequiredWrappy$1 = 1;
186
- // Returns a wrapper function that returns a wrapped callback
187
- // The wrapper function should do some stuff, and return a
188
- // presumably different callback function.
189
- // This makes sure that own properties are retained, so that
190
- // decorations and such are not lost along the way.
191
- wrappy_1$1 = wrappy;
192
- function wrappy (fn, cb) {
193
- if (fn && cb) return wrappy(fn)(cb)
283
+ var hasRequiredCrypto;
194
284
 
195
- if (typeof fn !== 'function')
196
- throw new TypeError('need wrapper function')
285
+ function requireCrypto () {
286
+ if (hasRequiredCrypto) return crypto;
287
+ hasRequiredCrypto = 1;
288
+ Object.defineProperty(crypto, "__esModule", { value: true });
289
+ crypto.crypto = void 0;
290
+ crypto.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
291
+
292
+ return crypto;
293
+ }
197
294
 
198
- Object.keys(fn).forEach(function (k) {
199
- wrapper[k] = fn[k];
200
- });
295
+ var hasRequiredUtils;
296
+
297
+ function requireUtils () {
298
+ if (hasRequiredUtils) return utils;
299
+ hasRequiredUtils = 1;
300
+ (function (exports) {
301
+ /**
302
+ * Utilities for hex, bytes, CSPRNG.
303
+ * @module
304
+ */
305
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
306
+ Object.defineProperty(exports, "__esModule", { value: true });
307
+ exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
308
+ exports.isBytes = isBytes;
309
+ exports.anumber = anumber;
310
+ exports.abytes = abytes;
311
+ exports.ahash = ahash;
312
+ exports.aexists = aexists;
313
+ exports.aoutput = aoutput;
314
+ exports.u8 = u8;
315
+ exports.u32 = u32;
316
+ exports.clean = clean;
317
+ exports.createView = createView;
318
+ exports.rotr = rotr;
319
+ exports.rotl = rotl;
320
+ exports.byteSwap = byteSwap;
321
+ exports.byteSwap32 = byteSwap32;
322
+ exports.bytesToHex = bytesToHex;
323
+ exports.hexToBytes = hexToBytes;
324
+ exports.asyncLoop = asyncLoop;
325
+ exports.utf8ToBytes = utf8ToBytes;
326
+ exports.bytesToUtf8 = bytesToUtf8;
327
+ exports.toBytes = toBytes;
328
+ exports.kdfInputToBytes = kdfInputToBytes;
329
+ exports.concatBytes = concatBytes;
330
+ exports.checkOpts = checkOpts;
331
+ exports.createHasher = createHasher;
332
+ exports.createOptHasher = createOptHasher;
333
+ exports.createXOFer = createXOFer;
334
+ exports.randomBytes = randomBytes;
335
+ // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
336
+ // node.js versions earlier than v19 don't declare it in global scope.
337
+ // For node.js, package.json#exports field mapping rewrites import
338
+ // from `crypto` to `cryptoNode`, which imports native module.
339
+ // Makes the utils un-importable in browsers without a bundler.
340
+ // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
341
+ const crypto_1 = requireCrypto();
342
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
343
+ function isBytes(a) {
344
+ return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
345
+ }
346
+ /** Asserts something is positive integer. */
347
+ function anumber(n) {
348
+ if (!Number.isSafeInteger(n) || n < 0)
349
+ throw new Error('positive integer expected, got ' + n);
350
+ }
351
+ /** Asserts something is Uint8Array. */
352
+ function abytes(b, ...lengths) {
353
+ if (!isBytes(b))
354
+ throw new Error('Uint8Array expected');
355
+ if (lengths.length > 0 && !lengths.includes(b.length))
356
+ throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
357
+ }
358
+ /** Asserts something is hash */
359
+ function ahash(h) {
360
+ if (typeof h !== 'function' || typeof h.create !== 'function')
361
+ throw new Error('Hash should be wrapped by utils.createHasher');
362
+ anumber(h.outputLen);
363
+ anumber(h.blockLen);
364
+ }
365
+ /** Asserts a hash instance has not been destroyed / finished */
366
+ function aexists(instance, checkFinished = true) {
367
+ if (instance.destroyed)
368
+ throw new Error('Hash instance has been destroyed');
369
+ if (checkFinished && instance.finished)
370
+ throw new Error('Hash#digest() has already been called');
371
+ }
372
+ /** Asserts output is properly-sized byte array */
373
+ function aoutput(out, instance) {
374
+ abytes(out);
375
+ const min = instance.outputLen;
376
+ if (out.length < min) {
377
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
378
+ }
379
+ }
380
+ /** Cast u8 / u16 / u32 to u8. */
381
+ function u8(arr) {
382
+ return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
383
+ }
384
+ /** Cast u8 / u16 / u32 to u32. */
385
+ function u32(arr) {
386
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
387
+ }
388
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
389
+ function clean(...arrays) {
390
+ for (let i = 0; i < arrays.length; i++) {
391
+ arrays[i].fill(0);
392
+ }
393
+ }
394
+ /** Create DataView of an array for easy byte-level manipulation. */
395
+ function createView(arr) {
396
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
397
+ }
398
+ /** The rotate right (circular right shift) operation for uint32 */
399
+ function rotr(word, shift) {
400
+ return (word << (32 - shift)) | (word >>> shift);
401
+ }
402
+ /** The rotate left (circular left shift) operation for uint32 */
403
+ function rotl(word, shift) {
404
+ return (word << shift) | ((word >>> (32 - shift)) >>> 0);
405
+ }
406
+ /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
407
+ exports.isLE = (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
408
+ /** The byte swap operation for uint32 */
409
+ function byteSwap(word) {
410
+ return (((word << 24) & 0xff000000) |
411
+ ((word << 8) & 0xff0000) |
412
+ ((word >>> 8) & 0xff00) |
413
+ ((word >>> 24) & 0xff));
414
+ }
415
+ /** Conditionally byte swap if on a big-endian platform */
416
+ exports.swap8IfBE = exports.isLE
417
+ ? (n) => n
418
+ : (n) => byteSwap(n);
419
+ /** @deprecated */
420
+ exports.byteSwapIfBE = exports.swap8IfBE;
421
+ /** In place byte swap for Uint32Array */
422
+ function byteSwap32(arr) {
423
+ for (let i = 0; i < arr.length; i++) {
424
+ arr[i] = byteSwap(arr[i]);
425
+ }
426
+ return arr;
427
+ }
428
+ exports.swap32IfBE = exports.isLE
429
+ ? (u) => u
430
+ : byteSwap32;
431
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
432
+ const hasHexBuiltin = /* @__PURE__ */ (() =>
433
+ // @ts-ignore
434
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
435
+ // Array where index 0xf0 (240) is mapped to string 'f0'
436
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
437
+ /**
438
+ * Convert byte array to hex string. Uses built-in function, when available.
439
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
440
+ */
441
+ function bytesToHex(bytes) {
442
+ abytes(bytes);
443
+ // @ts-ignore
444
+ if (hasHexBuiltin)
445
+ return bytes.toHex();
446
+ // pre-caching improves the speed 6x
447
+ let hex = '';
448
+ for (let i = 0; i < bytes.length; i++) {
449
+ hex += hexes[bytes[i]];
450
+ }
451
+ return hex;
452
+ }
453
+ // We use optimized technique to convert hex string to byte array
454
+ const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
455
+ function asciiToBase16(ch) {
456
+ if (ch >= asciis._0 && ch <= asciis._9)
457
+ return ch - asciis._0; // '2' => 50-48
458
+ if (ch >= asciis.A && ch <= asciis.F)
459
+ return ch - (asciis.A - 10); // 'B' => 66-(65-10)
460
+ if (ch >= asciis.a && ch <= asciis.f)
461
+ return ch - (asciis.a - 10); // 'b' => 98-(97-10)
462
+ return;
463
+ }
464
+ /**
465
+ * Convert hex string to byte array. Uses built-in function, when available.
466
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
467
+ */
468
+ function hexToBytes(hex) {
469
+ if (typeof hex !== 'string')
470
+ throw new Error('hex string expected, got ' + typeof hex);
471
+ // @ts-ignore
472
+ if (hasHexBuiltin)
473
+ return Uint8Array.fromHex(hex);
474
+ const hl = hex.length;
475
+ const al = hl / 2;
476
+ if (hl % 2)
477
+ throw new Error('hex string expected, got unpadded hex of length ' + hl);
478
+ const array = new Uint8Array(al);
479
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
480
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
481
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
482
+ if (n1 === undefined || n2 === undefined) {
483
+ const char = hex[hi] + hex[hi + 1];
484
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
485
+ }
486
+ array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
487
+ }
488
+ return array;
489
+ }
490
+ /**
491
+ * There is no setImmediate in browser and setTimeout is slow.
492
+ * Call of async fn will return Promise, which will be fullfiled only on
493
+ * next scheduler queue processing step and this is exactly what we need.
494
+ */
495
+ const nextTick = async () => { };
496
+ exports.nextTick = nextTick;
497
+ /** Returns control to thread each 'tick' ms to avoid blocking. */
498
+ async function asyncLoop(iters, tick, cb) {
499
+ let ts = Date.now();
500
+ for (let i = 0; i < iters; i++) {
501
+ cb(i);
502
+ // Date.now() is not monotonic, so in case if clock goes backwards we return return control too
503
+ const diff = Date.now() - ts;
504
+ if (diff >= 0 && diff < tick)
505
+ continue;
506
+ await (0, exports.nextTick)();
507
+ ts += diff;
508
+ }
509
+ }
510
+ /**
511
+ * Converts string to bytes using UTF8 encoding.
512
+ * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
513
+ */
514
+ function utf8ToBytes(str) {
515
+ if (typeof str !== 'string')
516
+ throw new Error('string expected');
517
+ return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
518
+ }
519
+ /**
520
+ * Converts bytes to string using UTF8 encoding.
521
+ * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
522
+ */
523
+ function bytesToUtf8(bytes) {
524
+ return new TextDecoder().decode(bytes);
525
+ }
526
+ /**
527
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
528
+ * Warning: when Uint8Array is passed, it would NOT get copied.
529
+ * Keep in mind for future mutable operations.
530
+ */
531
+ function toBytes(data) {
532
+ if (typeof data === 'string')
533
+ data = utf8ToBytes(data);
534
+ abytes(data);
535
+ return data;
536
+ }
537
+ /**
538
+ * Helper for KDFs: consumes uint8array or string.
539
+ * When string is passed, does utf8 decoding, using TextDecoder.
540
+ */
541
+ function kdfInputToBytes(data) {
542
+ if (typeof data === 'string')
543
+ data = utf8ToBytes(data);
544
+ abytes(data);
545
+ return data;
546
+ }
547
+ /** Copies several Uint8Arrays into one. */
548
+ function concatBytes(...arrays) {
549
+ let sum = 0;
550
+ for (let i = 0; i < arrays.length; i++) {
551
+ const a = arrays[i];
552
+ abytes(a);
553
+ sum += a.length;
554
+ }
555
+ const res = new Uint8Array(sum);
556
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
557
+ const a = arrays[i];
558
+ res.set(a, pad);
559
+ pad += a.length;
560
+ }
561
+ return res;
562
+ }
563
+ function checkOpts(defaults, opts) {
564
+ if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')
565
+ throw new Error('options should be object or undefined');
566
+ const merged = Object.assign(defaults, opts);
567
+ return merged;
568
+ }
569
+ /** For runtime check if class implements interface */
570
+ class Hash {
571
+ }
572
+ exports.Hash = Hash;
573
+ /** Wraps hash function, creating an interface on top of it */
574
+ function createHasher(hashCons) {
575
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
576
+ const tmp = hashCons();
577
+ hashC.outputLen = tmp.outputLen;
578
+ hashC.blockLen = tmp.blockLen;
579
+ hashC.create = () => hashCons();
580
+ return hashC;
581
+ }
582
+ function createOptHasher(hashCons) {
583
+ const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
584
+ const tmp = hashCons({});
585
+ hashC.outputLen = tmp.outputLen;
586
+ hashC.blockLen = tmp.blockLen;
587
+ hashC.create = (opts) => hashCons(opts);
588
+ return hashC;
589
+ }
590
+ function createXOFer(hashCons) {
591
+ const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
592
+ const tmp = hashCons({});
593
+ hashC.outputLen = tmp.outputLen;
594
+ hashC.blockLen = tmp.blockLen;
595
+ hashC.create = (opts) => hashCons(opts);
596
+ return hashC;
597
+ }
598
+ exports.wrapConstructor = createHasher;
599
+ exports.wrapConstructorWithOpts = createOptHasher;
600
+ exports.wrapXOFConstructorWithOpts = createXOFer;
601
+ /** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
602
+ function randomBytes(bytesLength = 32) {
603
+ if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') {
604
+ return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
605
+ }
606
+ // Legacy Node.js compatibility
607
+ if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === 'function') {
608
+ return Uint8Array.from(crypto_1.crypto.randomBytes(bytesLength));
609
+ }
610
+ throw new Error('crypto.getRandomValues must be defined');
611
+ }
612
+
613
+ } (utils));
614
+ return utils;
615
+ }
201
616
 
202
- return wrapper
617
+ var hasRequiredSha3;
203
618
 
204
- function wrapper() {
205
- var args = new Array(arguments.length);
206
- for (var i = 0; i < args.length; i++) {
207
- args[i] = arguments[i];
619
+ function requireSha3 () {
620
+ if (hasRequiredSha3) return sha3;
621
+ hasRequiredSha3 = 1;
622
+ Object.defineProperty(sha3, "__esModule", { value: true });
623
+ sha3.shake256 = sha3.shake128 = sha3.keccak_512 = sha3.keccak_384 = sha3.keccak_256 = sha3.keccak_224 = sha3.sha3_512 = sha3.sha3_384 = sha3.sha3_256 = sha3.sha3_224 = sha3.Keccak = void 0;
624
+ sha3.keccakP = keccakP;
625
+ /**
626
+ * SHA3 (keccak) hash function, based on a new "Sponge function" design.
627
+ * Different from older hashes, the internal state is bigger than output size.
628
+ *
629
+ * Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
630
+ * [Website](https://keccak.team/keccak.html),
631
+ * [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
632
+ *
633
+ * Check out `sha3-addons` module for cSHAKE, k12, and others.
634
+ * @module
635
+ */
636
+ const _u64_ts_1 = /*@__PURE__*/ require_u64();
637
+ // prettier-ignore
638
+ const utils_ts_1 = /*@__PURE__*/ requireUtils();
639
+ // No __PURE__ annotations in sha3 header:
640
+ // EVERYTHING is in fact used on every export.
641
+ // Various per round constants calculations
642
+ const _0n = BigInt(0);
643
+ const _1n = BigInt(1);
644
+ const _2n = BigInt(2);
645
+ const _7n = BigInt(7);
646
+ const _256n = BigInt(256);
647
+ const _0x71n = BigInt(0x71);
648
+ const SHA3_PI = [];
649
+ const SHA3_ROTL = [];
650
+ const _SHA3_IOTA = [];
651
+ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
652
+ // Pi
653
+ [x, y] = [y, (2 * x + 3 * y) % 5];
654
+ SHA3_PI.push(2 * (5 * y + x));
655
+ // Rotational
656
+ SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
657
+ // Iota
658
+ let t = _0n;
659
+ for (let j = 0; j < 7; j++) {
660
+ R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
661
+ if (R & _2n)
662
+ t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
208
663
  }
209
- var ret = fn.apply(this, args);
210
- var cb = args[args.length-1];
211
- if (typeof ret === 'function' && ret !== cb) {
212
- Object.keys(cb).forEach(function (k) {
213
- ret[k] = cb[k];
214
- });
664
+ _SHA3_IOTA.push(t);
665
+ }
666
+ const IOTAS = (0, _u64_ts_1.split)(_SHA3_IOTA, true);
667
+ const SHA3_IOTA_H = IOTAS[0];
668
+ const SHA3_IOTA_L = IOTAS[1];
669
+ // Left rotation (without 0, 32, 64)
670
+ const rotlH = (h, l, s) => (s > 32 ? (0, _u64_ts_1.rotlBH)(h, l, s) : (0, _u64_ts_1.rotlSH)(h, l, s));
671
+ const rotlL = (h, l, s) => (s > 32 ? (0, _u64_ts_1.rotlBL)(h, l, s) : (0, _u64_ts_1.rotlSL)(h, l, s));
672
+ /** `keccakf1600` internal function, additionally allows to adjust round count. */
673
+ function keccakP(s, rounds = 24) {
674
+ const B = new Uint32Array(5 * 2);
675
+ // NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
676
+ for (let round = 24 - rounds; round < 24; round++) {
677
+ // Theta θ
678
+ for (let x = 0; x < 10; x++)
679
+ B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
680
+ for (let x = 0; x < 10; x += 2) {
681
+ const idx1 = (x + 8) % 10;
682
+ const idx0 = (x + 2) % 10;
683
+ const B0 = B[idx0];
684
+ const B1 = B[idx0 + 1];
685
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
686
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
687
+ for (let y = 0; y < 50; y += 10) {
688
+ s[x + y] ^= Th;
689
+ s[x + y + 1] ^= Tl;
690
+ }
691
+ }
692
+ // Rho (ρ) and Pi (π)
693
+ let curH = s[2];
694
+ let curL = s[3];
695
+ for (let t = 0; t < 24; t++) {
696
+ const shift = SHA3_ROTL[t];
697
+ const Th = rotlH(curH, curL, shift);
698
+ const Tl = rotlL(curH, curL, shift);
699
+ const PI = SHA3_PI[t];
700
+ curH = s[PI];
701
+ curL = s[PI + 1];
702
+ s[PI] = Th;
703
+ s[PI + 1] = Tl;
704
+ }
705
+ // Chi (χ)
706
+ for (let y = 0; y < 50; y += 10) {
707
+ for (let x = 0; x < 10; x++)
708
+ B[x] = s[y + x];
709
+ for (let x = 0; x < 10; x++)
710
+ s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
711
+ }
712
+ // Iota (ι)
713
+ s[0] ^= SHA3_IOTA_H[round];
714
+ s[1] ^= SHA3_IOTA_L[round];
215
715
  }
216
- return ret
217
- }
716
+ (0, utils_ts_1.clean)(B);
218
717
  }
219
- return wrappy_1$1;
718
+ /** Keccak sponge function. */
719
+ class Keccak extends utils_ts_1.Hash {
720
+ // NOTE: we accept arguments in bytes instead of bits here.
721
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
722
+ super();
723
+ this.pos = 0;
724
+ this.posOut = 0;
725
+ this.finished = false;
726
+ this.destroyed = false;
727
+ this.enableXOF = false;
728
+ this.blockLen = blockLen;
729
+ this.suffix = suffix;
730
+ this.outputLen = outputLen;
731
+ this.enableXOF = enableXOF;
732
+ this.rounds = rounds;
733
+ // Can be passed from user as dkLen
734
+ (0, utils_ts_1.anumber)(outputLen);
735
+ // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
736
+ // 0 < blockLen < 200
737
+ if (!(0 < blockLen && blockLen < 200))
738
+ throw new Error('only keccak-f1600 function is supported');
739
+ this.state = new Uint8Array(200);
740
+ this.state32 = (0, utils_ts_1.u32)(this.state);
741
+ }
742
+ clone() {
743
+ return this._cloneInto();
744
+ }
745
+ keccak() {
746
+ (0, utils_ts_1.swap32IfBE)(this.state32);
747
+ keccakP(this.state32, this.rounds);
748
+ (0, utils_ts_1.swap32IfBE)(this.state32);
749
+ this.posOut = 0;
750
+ this.pos = 0;
751
+ }
752
+ update(data) {
753
+ (0, utils_ts_1.aexists)(this);
754
+ data = (0, utils_ts_1.toBytes)(data);
755
+ (0, utils_ts_1.abytes)(data);
756
+ const { blockLen, state } = this;
757
+ const len = data.length;
758
+ for (let pos = 0; pos < len;) {
759
+ const take = Math.min(blockLen - this.pos, len - pos);
760
+ for (let i = 0; i < take; i++)
761
+ state[this.pos++] ^= data[pos++];
762
+ if (this.pos === blockLen)
763
+ this.keccak();
764
+ }
765
+ return this;
766
+ }
767
+ finish() {
768
+ if (this.finished)
769
+ return;
770
+ this.finished = true;
771
+ const { state, suffix, pos, blockLen } = this;
772
+ // Do the padding
773
+ state[pos] ^= suffix;
774
+ if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
775
+ this.keccak();
776
+ state[blockLen - 1] ^= 0x80;
777
+ this.keccak();
778
+ }
779
+ writeInto(out) {
780
+ (0, utils_ts_1.aexists)(this, false);
781
+ (0, utils_ts_1.abytes)(out);
782
+ this.finish();
783
+ const bufferOut = this.state;
784
+ const { blockLen } = this;
785
+ for (let pos = 0, len = out.length; pos < len;) {
786
+ if (this.posOut >= blockLen)
787
+ this.keccak();
788
+ const take = Math.min(blockLen - this.posOut, len - pos);
789
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
790
+ this.posOut += take;
791
+ pos += take;
792
+ }
793
+ return out;
794
+ }
795
+ xofInto(out) {
796
+ // Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
797
+ if (!this.enableXOF)
798
+ throw new Error('XOF is not possible for this instance');
799
+ return this.writeInto(out);
800
+ }
801
+ xof(bytes) {
802
+ (0, utils_ts_1.anumber)(bytes);
803
+ return this.xofInto(new Uint8Array(bytes));
804
+ }
805
+ digestInto(out) {
806
+ (0, utils_ts_1.aoutput)(out, this);
807
+ if (this.finished)
808
+ throw new Error('digest() was already called');
809
+ this.writeInto(out);
810
+ this.destroy();
811
+ return out;
812
+ }
813
+ digest() {
814
+ return this.digestInto(new Uint8Array(this.outputLen));
815
+ }
816
+ destroy() {
817
+ this.destroyed = true;
818
+ (0, utils_ts_1.clean)(this.state);
819
+ }
820
+ _cloneInto(to) {
821
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
822
+ to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
823
+ to.state32.set(this.state32);
824
+ to.pos = this.pos;
825
+ to.posOut = this.posOut;
826
+ to.finished = this.finished;
827
+ to.rounds = rounds;
828
+ // Suffix can change in cSHAKE
829
+ to.suffix = suffix;
830
+ to.outputLen = outputLen;
831
+ to.enableXOF = enableXOF;
832
+ to.destroyed = this.destroyed;
833
+ return to;
834
+ }
835
+ }
836
+ sha3.Keccak = Keccak;
837
+ const gen = (suffix, blockLen, outputLen) => (0, utils_ts_1.createHasher)(() => new Keccak(blockLen, suffix, outputLen));
838
+ /** SHA3-224 hash function. */
839
+ sha3.sha3_224 = (() => gen(0x06, 144, 224 / 8))();
840
+ /** SHA3-256 hash function. Different from keccak-256. */
841
+ sha3.sha3_256 = (() => gen(0x06, 136, 256 / 8))();
842
+ /** SHA3-384 hash function. */
843
+ sha3.sha3_384 = (() => gen(0x06, 104, 384 / 8))();
844
+ /** SHA3-512 hash function. */
845
+ sha3.sha3_512 = (() => gen(0x06, 72, 512 / 8))();
846
+ /** keccak-224 hash function. */
847
+ sha3.keccak_224 = (() => gen(0x01, 144, 224 / 8))();
848
+ /** keccak-256 hash function. Different from SHA3-256. */
849
+ sha3.keccak_256 = (() => gen(0x01, 136, 256 / 8))();
850
+ /** keccak-384 hash function. */
851
+ sha3.keccak_384 = (() => gen(0x01, 104, 384 / 8))();
852
+ /** keccak-512 hash function. */
853
+ sha3.keccak_512 = (() => gen(0x01, 72, 512 / 8))();
854
+ const genShake = (suffix, blockLen, outputLen) => (0, utils_ts_1.createXOFer)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
855
+ /** SHAKE128 XOF with 128-bit security. */
856
+ sha3.shake128 = (() => genShake(0x1f, 168, 128 / 8))();
857
+ /** SHAKE256 XOF with 256-bit security. */
858
+ sha3.shake256 = (() => genShake(0x1f, 136, 256 / 8))();
859
+
860
+ return sha3;
220
861
  }
221
862
 
222
- var hasRequiredOnce;
863
+ /* global global, window, module */
223
864
 
224
- function requireOnce () {
225
- if (hasRequiredOnce) return once.exports;
226
- hasRequiredOnce = 1;
227
- var wrappy = requireWrappy$1();
228
- once.exports = wrappy(once$1);
229
- once.exports.strict = wrappy(onceStrict);
865
+ var hasRequiredSrc;
230
866
 
231
- once$1.proto = once$1(function () {
232
- Object.defineProperty(Function.prototype, 'once', {
233
- value: function () {
234
- return once$1(this)
235
- },
236
- configurable: true
237
- });
867
+ function requireSrc () {
868
+ if (hasRequiredSrc) return src;
869
+ hasRequiredSrc = 1;
870
+ const { sha3_512: sha3 } = /*@__PURE__*/ requireSha3();
238
871
 
239
- Object.defineProperty(Function.prototype, 'onceStrict', {
240
- value: function () {
241
- return onceStrict(this)
242
- },
243
- configurable: true
244
- });
245
- });
872
+ const defaultLength = 24;
873
+ const bigLength = 32;
246
874
 
247
- function once$1 (fn) {
248
- var f = function () {
249
- if (f.called) return f.value
250
- f.called = true;
251
- return f.value = fn.apply(this, arguments)
252
- };
253
- f.called = false;
254
- return f
875
+ const createEntropy = (length = 4, random = Math.random) => {
876
+ let entropy = "";
877
+
878
+ while (entropy.length < length) {
879
+ entropy = entropy + Math.floor(random() * 36).toString(36);
880
+ }
881
+ return entropy;
882
+ };
883
+
884
+ /*
885
+ * Adapted from https://github.com/juanelas/bigint-conversion
886
+ * MIT License Copyright (c) 2018 Juan Hernández Serrano
887
+ */
888
+ function bufToBigInt(buf) {
889
+ let bits = 8n;
890
+
891
+ let value = 0n;
892
+ for (const i of buf.values()) {
893
+ const bi = BigInt(i);
894
+ value = (value << bits) + bi;
895
+ }
896
+ return value;
255
897
  }
256
898
 
257
- function onceStrict (fn) {
258
- var f = function () {
259
- if (f.called)
260
- throw new Error(f.onceError)
261
- f.called = true;
262
- return f.value = fn.apply(this, arguments)
899
+ const hash = (input = "") => {
900
+ // Drop the first character because it will bias the histogram
901
+ // to the left.
902
+ return bufToBigInt(sha3(input)).toString(36).slice(1);
903
+ };
904
+
905
+ const alphabet = Array.from({ length: 26 }, (x, i) =>
906
+ String.fromCharCode(i + 97)
907
+ );
908
+
909
+ const randomLetter = (random) =>
910
+ alphabet[Math.floor(random() * alphabet.length)];
911
+
912
+ /*
913
+ This is a fingerprint of the host environment. It is used to help
914
+ prevent collisions when generating ids in a distributed system.
915
+ If no global object is available, you can pass in your own, or fall back
916
+ on a random string.
917
+ */
918
+ const createFingerprint = ({
919
+ globalObj = typeof commonjsGlobal !== "undefined"
920
+ ? commonjsGlobal
921
+ : typeof window !== "undefined"
922
+ ? window
923
+ : {},
924
+ random = Math.random,
925
+ } = {}) => {
926
+ const globals = Object.keys(globalObj).toString();
927
+ const sourceString = globals.length
928
+ ? globals + createEntropy(bigLength, random)
929
+ : createEntropy(bigLength, random);
930
+
931
+ return hash(sourceString).substring(0, bigLength);
932
+ };
933
+
934
+ const createCounter = (count) => () => {
935
+ return count++;
936
+ };
937
+
938
+ // ~22k hosts before 50% chance of initial counter collision
939
+ // with a remaining counter range of 9.0e+15 in JavaScript.
940
+ const initialCountMax = 476782367;
941
+
942
+ const init = ({
943
+ // Fallback if the user does not pass in a CSPRNG. This should be OK
944
+ // because we don't rely solely on the random number generator for entropy.
945
+ // We also use the host fingerprint, current time, and a session counter.
946
+ random = Math.random,
947
+ counter = createCounter(Math.floor(random() * initialCountMax)),
948
+ length = defaultLength,
949
+ fingerprint = createFingerprint({ random }),
950
+ } = {}) => {
951
+ return function cuid2() {
952
+ const firstLetter = randomLetter(random);
953
+
954
+ // If we're lucky, the `.toString(36)` calls may reduce hashing rounds
955
+ // by shortening the input to the hash function a little.
956
+ const time = Date.now().toString(36);
957
+ const count = counter().toString(36);
958
+
959
+ // The salt should be long enough to be globally unique across the full
960
+ // length of the hash. For simplicity, we use the same length as the
961
+ // intended id output.
962
+ const salt = createEntropy(length, random);
963
+ const hashInput = `${time + salt + count + fingerprint}`;
964
+
965
+ return `${firstLetter + hash(hashInput).substring(1, length)}`;
263
966
  };
264
- var name = fn.name || 'Function wrapped with `once`';
265
- f.onceError = name + " shouldn't be called more than once";
266
- f.called = false;
267
- return f
268
- }
269
- return once.exports;
967
+ };
968
+
969
+ const createId = init();
970
+
971
+ const isCuid = (id, { minLength = 2, maxLength = bigLength } = {}) => {
972
+ const length = id.length;
973
+ const regex = /^[0-9a-z]+$/;
974
+
975
+ try {
976
+ if (
977
+ typeof id === "string" &&
978
+ length >= minLength &&
979
+ length <= maxLength &&
980
+ regex.test(id)
981
+ )
982
+ return true;
983
+ } finally {
984
+ }
985
+
986
+ return false;
987
+ };
988
+
989
+ src.getConstants = () => ({ defaultLength, bigLength });
990
+ src.init = init;
991
+ src.createId = createId;
992
+ src.bufToBigInt = bufToBigInt;
993
+ src.createCounter = createCounter;
994
+ src.createFingerprint = createFingerprint;
995
+ src.isCuid = isCuid;
996
+ return src;
270
997
  }
271
998
 
272
- var onceExports = requireOnce();
273
- var __jsenv_default_import__$1 = /*@__PURE__*/getDefaultExportFromCjs$1(onceExports);
999
+ var hasRequiredCuid2;
274
1000
 
275
- onceExports.strict;
1001
+ function requireCuid2 () {
1002
+ if (hasRequiredCuid2) return cuid2;
1003
+ hasRequiredCuid2 = 1;
1004
+ const { createId, init, getConstants, isCuid } = requireSrc();
276
1005
 
277
- function getDefaultExportFromCjs (x) {
1006
+ cuid2.createId = createId;
1007
+ cuid2.init = init;
1008
+ cuid2.getConstants = getConstants;
1009
+ cuid2.isCuid = isCuid;
1010
+ return cuid2;
1011
+ }
1012
+
1013
+ var cuid2Exports = requireCuid2();
1014
+
1015
+ cuid2Exports.createId;
1016
+ cuid2Exports.getConstants;
1017
+ var init$3 = cuid2Exports.init;
1018
+ cuid2Exports.isCuid;
1019
+
1020
+ function getDefaultExportFromCjs$1 (x) {
278
1021
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
279
1022
  }
280
1023
 
281
- var wrappy_1;
282
- var hasRequiredWrappy;
1024
+ var wrappy_1$1;
1025
+ var hasRequiredWrappy$1;
283
1026
 
284
- function requireWrappy () {
285
- if (hasRequiredWrappy) return wrappy_1;
286
- hasRequiredWrappy = 1;
1027
+ function requireWrappy$1 () {
1028
+ if (hasRequiredWrappy$1) return wrappy_1$1;
1029
+ hasRequiredWrappy$1 = 1;
287
1030
  // Returns a wrapper function that returns a wrapped callback
288
1031
  // The wrapper function should do some stuff, and return a
289
1032
  // presumably different callback function.
290
1033
  // This makes sure that own properties are retained, so that
291
1034
  // decorations and such are not lost along the way.
292
- wrappy_1 = wrappy;
1035
+ wrappy_1$1 = wrappy;
293
1036
  function wrappy (fn, cb) {
294
1037
  if (fn && cb) return wrappy(fn)(cb)
295
1038
 
@@ -317,7 +1060,7 @@ function requireWrappy () {
317
1060
  return ret
318
1061
  }
319
1062
  }
320
- return wrappy_1;
1063
+ return wrappy_1$1;
321
1064
  }
322
1065
 
323
1066
  var raw;
@@ -507,7 +1250,7 @@ var hasRequiredDezalgo;
507
1250
  function requireDezalgo () {
508
1251
  if (hasRequiredDezalgo) return dezalgo_1;
509
1252
  hasRequiredDezalgo = 1;
510
- var wrappy = requireWrappy();
1253
+ var wrappy = requireWrappy$1();
511
1254
  dezalgo_1 = wrappy(dezalgo);
512
1255
 
513
1256
  var asap = requireAsap();
@@ -533,169 +1276,111 @@ function requireDezalgo () {
533
1276
  }
534
1277
 
535
1278
  var dezalgoExports = requireDezalgo();
536
- var __jsenv_default_import__ = /*@__PURE__*/getDefaultExportFromCjs(dezalgoExports);
537
-
538
- class OctetStreamParser extends PassThrough {
539
- constructor(options = {}) {
540
- super();
541
- this.globalOptions = { ...options };
542
- }
543
- }
544
-
545
- /* eslint-disable no-underscore-dangle */
546
-
547
-
548
- const octetStreamType = 'octet-stream';
549
- // the `options` is also available through the `options` / `formidable.options`
550
- async function plugin$3(formidable, options) {
551
- // the `this` context is always formidable, as the first argument of a plugin
552
- // but this allows us to customize/test each plugin
553
-
554
- /* istanbul ignore next */
555
- const self = this || formidable;
556
-
557
- if (/octet-stream/i.test(self.headers['content-type'])) {
558
- await init$2.call(self, self, options);
559
- }
560
- return self;
561
- }
562
-
563
- // Note that it's a good practice (but it's up to you) to use the `this.options` instead
564
- // of the passed `options` (second) param, because when you decide
565
- // to test the plugin you can pass custom `this` context to it (and so `this.options`)
566
- async function init$2(_self, _opts) {
567
- this.type = octetStreamType;
568
- const originalFilename = this.headers['x-file-name'];
569
- const mimetype = this.headers['content-type'];
570
-
571
- const thisPart = {
572
- originalFilename,
573
- mimetype,
574
- };
575
- const newFilename = this._getNewName(thisPart);
576
- const filepath = this._joinDirectoryName(newFilename);
577
- const file = await this._newFile({
578
- newFilename,
579
- filepath,
580
- originalFilename,
581
- mimetype,
582
- });
583
-
584
- this.emit('fileBegin', originalFilename, file);
585
- file.open();
586
- this.openedFiles.push(file);
587
- this._flushing += 1;
588
-
589
- this._parser = new OctetStreamParser(this.options);
590
-
591
- // Keep track of writes that haven't finished so we don't emit the file before it's done being written
592
- let outstandingWrites = 0;
593
-
594
- this._parser.on('data', (buffer) => {
595
- this.pause();
596
- outstandingWrites += 1;
597
-
598
- file.write(buffer, () => {
599
- outstandingWrites -= 1;
600
- this.resume();
601
-
602
- if (this.ended) {
603
- this._parser.emit('doneWritingFile');
604
- }
605
- });
606
- });
607
-
608
- this._parser.on('end', () => {
609
- this._flushing -= 1;
610
- this.ended = true;
1279
+ var __jsenv_default_import__$1 = /*@__PURE__*/getDefaultExportFromCjs$1(dezalgoExports);
611
1280
 
612
- const done = () => {
613
- file.end(() => {
614
- this.emit('file', 'file', file);
615
- this._maybeEnd();
616
- });
617
- };
618
-
619
- if (outstandingWrites === 0) {
620
- done();
621
- } else {
622
- this._parser.once('doneWritingFile', done);
623
- }
624
- });
625
-
626
- return this;
1281
+ function getDefaultExportFromCjs (x) {
1282
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
627
1283
  }
628
1284
 
629
- /* eslint-disable no-underscore-dangle */
630
-
631
-
632
- // This is a buffering parser, have a look at StreamingQuerystring.js for a streaming parser
633
- class QuerystringParser extends Transform {
634
- constructor(options = {}) {
635
- super({ readableObjectMode: true });
636
- this.globalOptions = { ...options };
637
- this.buffer = '';
638
- this.bufferLength = 0;
639
- }
640
-
641
- _transform(buffer, encoding, callback) {
642
- this.buffer += buffer.toString('ascii');
643
- this.bufferLength = this.buffer.length;
644
- callback();
645
- }
1285
+ var once = {exports: {}};
646
1286
 
647
- _flush(callback) {
648
- const fields = new URLSearchParams(this.buffer);
649
- for (const [key, value] of fields) {
650
- this.push({
651
- key,
652
- value,
653
- });
654
- }
655
- this.buffer = '';
656
- callback();
657
- }
658
- }
1287
+ var wrappy_1;
1288
+ var hasRequiredWrappy;
659
1289
 
660
- /* eslint-disable no-underscore-dangle */
1290
+ function requireWrappy () {
1291
+ if (hasRequiredWrappy) return wrappy_1;
1292
+ hasRequiredWrappy = 1;
1293
+ // Returns a wrapper function that returns a wrapped callback
1294
+ // The wrapper function should do some stuff, and return a
1295
+ // presumably different callback function.
1296
+ // This makes sure that own properties are retained, so that
1297
+ // decorations and such are not lost along the way.
1298
+ wrappy_1 = wrappy;
1299
+ function wrappy (fn, cb) {
1300
+ if (fn && cb) return wrappy(fn)(cb)
661
1301
 
1302
+ if (typeof fn !== 'function')
1303
+ throw new TypeError('need wrapper function')
662
1304
 
663
- const querystringType = 'urlencoded';
664
- // the `options` is also available through the `this.options` / `formidable.options`
665
- function plugin$2(formidable, options) {
666
- // the `this` context is always formidable, as the first argument of a plugin
667
- // but this allows us to customize/test each plugin
1305
+ Object.keys(fn).forEach(function (k) {
1306
+ wrapper[k] = fn[k];
1307
+ });
668
1308
 
669
- /* istanbul ignore next */
670
- const self = this || formidable;
1309
+ return wrapper
671
1310
 
672
- if (/urlencoded/i.test(self.headers['content-type'])) {
673
- init$1.call(self, self, options);
674
- }
675
- return self;
676
- }
677
- // Note that it's a good practice (but it's up to you) to use the `this.options` instead
678
- // of the passed `options` (second) param, because when you decide
679
- // to test the plugin you can pass custom `this` context to it (and so `this.options`)
680
- function init$1(_self, _opts) {
681
- this.type = querystringType;
1311
+ function wrapper() {
1312
+ var args = new Array(arguments.length);
1313
+ for (var i = 0; i < args.length; i++) {
1314
+ args[i] = arguments[i];
1315
+ }
1316
+ var ret = fn.apply(this, args);
1317
+ var cb = args[args.length-1];
1318
+ if (typeof ret === 'function' && ret !== cb) {
1319
+ Object.keys(cb).forEach(function (k) {
1320
+ ret[k] = cb[k];
1321
+ });
1322
+ }
1323
+ return ret
1324
+ }
1325
+ }
1326
+ return wrappy_1;
1327
+ }
682
1328
 
683
- const parser = new QuerystringParser(this.options);
1329
+ var hasRequiredOnce;
684
1330
 
685
- parser.on('data', ({ key, value }) => {
686
- this.emit('field', key, value);
687
- });
1331
+ function requireOnce () {
1332
+ if (hasRequiredOnce) return once.exports;
1333
+ hasRequiredOnce = 1;
1334
+ var wrappy = requireWrappy();
1335
+ once.exports = wrappy(once$1);
1336
+ once.exports.strict = wrappy(onceStrict);
688
1337
 
689
- parser.once('end', () => {
690
- this.ended = true;
691
- this._maybeEnd();
692
- });
1338
+ once$1.proto = once$1(function () {
1339
+ Object.defineProperty(Function.prototype, 'once', {
1340
+ value: function () {
1341
+ return once$1(this)
1342
+ },
1343
+ configurable: true
1344
+ });
693
1345
 
694
- this._parser = parser;
1346
+ Object.defineProperty(Function.prototype, 'onceStrict', {
1347
+ value: function () {
1348
+ return onceStrict(this)
1349
+ },
1350
+ configurable: true
1351
+ });
1352
+ });
695
1353
 
696
- return this;
1354
+ function once$1 (fn) {
1355
+ var f = function () {
1356
+ if (f.called) return f.value
1357
+ f.called = true;
1358
+ return f.value = fn.apply(this, arguments)
1359
+ };
1360
+ f.called = false;
1361
+ return f
1362
+ }
1363
+
1364
+ function onceStrict (fn) {
1365
+ var f = function () {
1366
+ if (f.called)
1367
+ throw new Error(f.onceError)
1368
+ f.called = true;
1369
+ return f.value = fn.apply(this, arguments)
1370
+ };
1371
+ var name = fn.name || 'Function wrapped with `once`';
1372
+ f.onceError = name + " shouldn't be called more than once";
1373
+ f.called = false;
1374
+ return f
1375
+ }
1376
+ return once.exports;
697
1377
  }
698
1378
 
1379
+ var onceExports = requireOnce();
1380
+ var __jsenv_default_import__ = /*@__PURE__*/getDefaultExportFromCjs(onceExports);
1381
+
1382
+ onceExports.strict;
1383
+
699
1384
  const missingPlugin = 1000;
700
1385
  const pluginFunction = 1001;
701
1386
  const aborted = 1002;
@@ -724,6 +1409,23 @@ const FormidableError = class extends Error {
724
1409
  }
725
1410
  };
726
1411
 
1412
+ /* eslint-disable no-underscore-dangle */
1413
+
1414
+
1415
+ class DummyParser extends Transform {
1416
+ constructor(incomingForm, options = {}) {
1417
+ super();
1418
+ this.globalOptions = { ...options };
1419
+ this.incomingForm = incomingForm;
1420
+ }
1421
+
1422
+ _flush(callback) {
1423
+ this.incomingForm.ended = true;
1424
+ this.incomingForm._maybeEnd();
1425
+ callback();
1426
+ }
1427
+ }
1428
+
727
1429
  /* eslint-disable no-fallthrough */
728
1430
  /* eslint-disable no-bitwise */
729
1431
  /* eslint-disable no-plusplus */
@@ -1078,6 +1780,167 @@ MultipartParser.stateToString = (stateNumber) => {
1078
1780
 
1079
1781
  const MultipartParser$1 = Object.assign(MultipartParser, { STATES });
1080
1782
 
1783
+ class OctetStreamParser extends PassThrough {
1784
+ constructor(options = {}) {
1785
+ super();
1786
+ this.globalOptions = { ...options };
1787
+ }
1788
+ }
1789
+
1790
+ /* eslint-disable no-underscore-dangle */
1791
+
1792
+
1793
+ const octetStreamType = 'octet-stream';
1794
+ // the `options` is also available through the `options` / `formidable.options`
1795
+ async function plugin$3(formidable, options) {
1796
+ // the `this` context is always formidable, as the first argument of a plugin
1797
+ // but this allows us to customize/test each plugin
1798
+
1799
+ /* istanbul ignore next */
1800
+ const self = this || formidable;
1801
+
1802
+ if (/octet-stream/i.test(self.headers['content-type'])) {
1803
+ await init$2.call(self, self, options);
1804
+ }
1805
+ return self;
1806
+ }
1807
+
1808
+ // Note that it's a good practice (but it's up to you) to use the `this.options` instead
1809
+ // of the passed `options` (second) param, because when you decide
1810
+ // to test the plugin you can pass custom `this` context to it (and so `this.options`)
1811
+ async function init$2(_self, _opts) {
1812
+ this.type = octetStreamType;
1813
+ const originalFilename = this.headers['x-file-name'];
1814
+ const mimetype = this.headers['content-type'];
1815
+
1816
+ const thisPart = {
1817
+ originalFilename,
1818
+ mimetype,
1819
+ };
1820
+ const newFilename = this._getNewName(thisPart);
1821
+ const filepath = this._joinDirectoryName(newFilename);
1822
+ const file = await this._newFile({
1823
+ newFilename,
1824
+ filepath,
1825
+ originalFilename,
1826
+ mimetype,
1827
+ });
1828
+
1829
+ this.emit('fileBegin', originalFilename, file);
1830
+ file.open();
1831
+ this.openedFiles.push(file);
1832
+ this._flushing += 1;
1833
+
1834
+ this._parser = new OctetStreamParser(this.options);
1835
+
1836
+ // Keep track of writes that haven't finished so we don't emit the file before it's done being written
1837
+ let outstandingWrites = 0;
1838
+
1839
+ this._parser.on('data', (buffer) => {
1840
+ this.pause();
1841
+ outstandingWrites += 1;
1842
+
1843
+ file.write(buffer, () => {
1844
+ outstandingWrites -= 1;
1845
+ this.resume();
1846
+
1847
+ if (this.ended) {
1848
+ this._parser.emit('doneWritingFile');
1849
+ }
1850
+ });
1851
+ });
1852
+
1853
+ this._parser.on('end', () => {
1854
+ this._flushing -= 1;
1855
+ this.ended = true;
1856
+
1857
+ const done = () => {
1858
+ file.end(() => {
1859
+ this.emit('file', 'file', file);
1860
+ this._maybeEnd();
1861
+ });
1862
+ };
1863
+
1864
+ if (outstandingWrites === 0) {
1865
+ done();
1866
+ } else {
1867
+ this._parser.once('doneWritingFile', done);
1868
+ }
1869
+ });
1870
+
1871
+ return this;
1872
+ }
1873
+
1874
+ /* eslint-disable no-underscore-dangle */
1875
+
1876
+
1877
+ // This is a buffering parser, have a look at StreamingQuerystring.js for a streaming parser
1878
+ class QuerystringParser extends Transform {
1879
+ constructor(options = {}) {
1880
+ super({ readableObjectMode: true });
1881
+ this.globalOptions = { ...options };
1882
+ this.buffer = '';
1883
+ this.bufferLength = 0;
1884
+ }
1885
+
1886
+ _transform(buffer, encoding, callback) {
1887
+ this.buffer += buffer.toString('ascii');
1888
+ this.bufferLength = this.buffer.length;
1889
+ callback();
1890
+ }
1891
+
1892
+ _flush(callback) {
1893
+ const fields = new URLSearchParams(this.buffer);
1894
+ for (const [key, value] of fields) {
1895
+ this.push({
1896
+ key,
1897
+ value,
1898
+ });
1899
+ }
1900
+ this.buffer = '';
1901
+ callback();
1902
+ }
1903
+ }
1904
+
1905
+ /* eslint-disable no-underscore-dangle */
1906
+
1907
+
1908
+ const querystringType = 'urlencoded';
1909
+ // the `options` is also available through the `this.options` / `formidable.options`
1910
+ function plugin$2(formidable, options) {
1911
+ // the `this` context is always formidable, as the first argument of a plugin
1912
+ // but this allows us to customize/test each plugin
1913
+
1914
+ /* istanbul ignore next */
1915
+ const self = this || formidable;
1916
+
1917
+ if (/urlencoded/i.test(self.headers['content-type'])) {
1918
+ init$1.call(self, self, options);
1919
+ }
1920
+ return self;
1921
+ }
1922
+ // Note that it's a good practice (but it's up to you) to use the `this.options` instead
1923
+ // of the passed `options` (second) param, because when you decide
1924
+ // to test the plugin you can pass custom `this` context to it (and so `this.options`)
1925
+ function init$1(_self, _opts) {
1926
+ this.type = querystringType;
1927
+
1928
+ const parser = new QuerystringParser(this.options);
1929
+
1930
+ parser.on('data', ({ key, value }) => {
1931
+ this.emit('field', key, value);
1932
+ });
1933
+
1934
+ parser.once('end', () => {
1935
+ this.ended = true;
1936
+ this._maybeEnd();
1937
+ });
1938
+
1939
+ this._parser = parser;
1940
+
1941
+ return this;
1942
+ }
1943
+
1081
1944
  /* eslint-disable no-underscore-dangle */
1082
1945
 
1083
1946
 
@@ -1314,28 +2177,13 @@ function init(_self, _opts) {
1314
2177
  this._parser = parser;
1315
2178
  }
1316
2179
 
1317
- /* eslint-disable no-underscore-dangle */
1318
-
1319
-
1320
- class DummyParser extends Transform {
1321
- constructor(incomingForm, options = {}) {
1322
- super();
1323
- this.globalOptions = { ...options };
1324
- this.incomingForm = incomingForm;
1325
- }
1326
-
1327
- _flush(callback) {
1328
- this.incomingForm.ended = true;
1329
- this.incomingForm._maybeEnd();
1330
- callback();
1331
- }
1332
- }
1333
-
1334
2180
  /* eslint-disable class-methods-use-this */
1335
2181
  /* eslint-disable no-underscore-dangle */
1336
2182
 
1337
2183
 
1338
- const toHexoId = hexoid(25);
2184
+ const CUID2_FINGERPRINT = `${("production")}-${os.platform()}-${os.hostname()}`;
2185
+ const createId = init$3({ length: 25, fingerprint: CUID2_FINGERPRINT.toLowerCase() });
2186
+
1339
2187
  const DEFAULT_OPTIONS = {
1340
2188
  maxFields: 1000,
1341
2189
  maxFieldsSize: 20 * 1024 * 1024,
@@ -1517,7 +2365,7 @@ class IncomingForm extends EventEmitter {
1517
2365
  }
1518
2366
  };
1519
2367
  }
1520
- const callback = __jsenv_default_import__$1(__jsenv_default_import__(cb));
2368
+ const callback = __jsenv_default_import__(__jsenv_default_import__$1(cb));
1521
2369
  this.fields = {};
1522
2370
  const files = {};
1523
2371
 
@@ -1940,7 +2788,7 @@ class IncomingForm extends EventEmitter {
1940
2788
  };
1941
2789
  } else {
1942
2790
  this._getNewName = (part) => {
1943
- const name = toHexoId();
2791
+ const name = createId();
1944
2792
 
1945
2793
  if (part && this.options.keepExtensions) {
1946
2794
  const originalFilename =