@adviser/cement 0.3.20 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/base-sys-abstraction-DgTynXGV.d.cts +95 -0
  2. package/base-sys-abstraction-h0dB3nZ5.d.ts +95 -0
  3. package/cf/index.cjs +232 -283
  4. package/cf/index.cjs.map +1 -1
  5. package/cf/index.d.cts +10 -8
  6. package/cf/index.d.ts +10 -8
  7. package/cf/index.js +6 -41
  8. package/cf/index.js.map +1 -1
  9. package/{chunk-PHS255C5.js → chunk-FOALXQST.js} +1 -68
  10. package/chunk-FOALXQST.js.map +1 -0
  11. package/{chunk-UEER5ZC2.js → chunk-NPMIRK4R.js} +8 -22
  12. package/chunk-NPMIRK4R.js.map +1 -0
  13. package/{chunk-23MCJYE6.js → chunk-X3IV2RYT.js} +422 -602
  14. package/chunk-X3IV2RYT.js.map +1 -0
  15. package/chunk-YKGCONBX.js +677 -0
  16. package/chunk-YKGCONBX.js.map +1 -0
  17. package/{chunk-55W4AK2Z.js → chunk-YVACAIUX.js} +5 -5
  18. package/deno/index.cjs +257 -241
  19. package/deno/index.cjs.map +1 -1
  20. package/deno/index.d.cts +3 -5
  21. package/deno/index.d.ts +3 -5
  22. package/deno/index.js +14 -16
  23. package/deno/index.js.map +1 -1
  24. package/{index-BhmvYS_t.d.ts → index-N0bkrgSt.d.ts} +2 -2
  25. package/{index-DoK1OTgQ.d.cts → index-TtYD7HhB.d.cts} +2 -2
  26. package/index.cjs +1935 -1806
  27. package/index.cjs.map +1 -1
  28. package/index.d.cts +15 -8
  29. package/index.d.ts +15 -8
  30. package/index.js +58 -16
  31. package/index.js.map +1 -1
  32. package/metafile-cjs.json +1 -1
  33. package/metafile-esm.json +1 -1
  34. package/node/index.cjs +499 -474
  35. package/node/index.cjs.map +1 -1
  36. package/node/index.d.cts +3 -5
  37. package/node/index.d.ts +3 -5
  38. package/node/index.js +14 -16
  39. package/node/index.js.map +1 -1
  40. package/package.json +5 -5
  41. package/src/base-sys-abstraction.ts +106 -116
  42. package/src/cf/cf-basic-sys-abstraction.ts +79 -0
  43. package/src/cf/index.ts +1 -1
  44. package/src/cf-test-main.ts +10 -1
  45. package/src/coerce-binary.ts +39 -0
  46. package/src/deno/deno-basic-sys-abstraction.ts +39 -0
  47. package/src/deno/deno-file-service.ts +1 -1
  48. package/src/deno/deno-sys-abstraction.ts +19 -22
  49. package/src/index.ts +1 -0
  50. package/src/jsr.json +1 -1
  51. package/src/log-writer-impl.ts +6 -0
  52. package/src/logger-impl.ts +18 -20
  53. package/src/node/node-basic-sys-abstraction.ts +59 -0
  54. package/src/node/node-sys-abstraction.ts +19 -22
  55. package/src/sys-abstraction.ts +12 -6
  56. package/src/test/mock-logger.ts +2 -2
  57. package/src/txt-en-decoder.ts +3 -3
  58. package/src/web/index.ts +1 -1
  59. package/src/web/web-basic-sys-abstraction.ts +105 -0
  60. package/{sys-abstraction-B0x6IE7r.d.ts → sys-abstraction-CeAxxg9H.d.ts} +11 -7
  61. package/{sys-abstraction-BTs3Vzy4.d.cts → sys-abstraction-DDAwGTnk.d.cts} +11 -7
  62. package/test/index.cjs +1146 -1085
  63. package/test/index.cjs.map +1 -1
  64. package/test/index.d.cts +2 -2
  65. package/test/index.d.ts +2 -2
  66. package/test/index.js +4 -5
  67. package/ts/smoke/smoke.js +7 -8
  68. package/ts/smoke/smoke.js.map +1 -1
  69. package/ts/src/base-basic-sys-abstraction.test.d.ts +2 -0
  70. package/ts/src/base-basic-sys-abstraction.test.d.ts.map +1 -0
  71. package/ts/src/{base-sys-abstraction.test.js → base-basic-sys-abstraction.test.js} +9 -9
  72. package/ts/src/base-basic-sys-abstraction.test.js.map +1 -0
  73. package/ts/src/base-sys-abstraction.d.ts +33 -21
  74. package/ts/src/base-sys-abstraction.d.ts.map +1 -1
  75. package/ts/src/base-sys-abstraction.js +54 -67
  76. package/ts/src/base-sys-abstraction.js.map +1 -1
  77. package/ts/src/cf/cf-basic-sys-abstraction.d.ts +14 -0
  78. package/ts/src/cf/cf-basic-sys-abstraction.d.ts.map +1 -0
  79. package/ts/src/cf/cf-basic-sys-abstraction.js +67 -0
  80. package/ts/src/cf/cf-basic-sys-abstraction.js.map +1 -0
  81. package/ts/src/cf/index.d.ts +1 -1
  82. package/ts/src/cf/index.d.ts.map +1 -1
  83. package/ts/src/cf/index.js +1 -1
  84. package/ts/src/cf/index.js.map +1 -1
  85. package/ts/src/cf-test-main.d.ts.map +1 -1
  86. package/ts/src/cf-test-main.js +7 -1
  87. package/ts/src/cf-test-main.js.map +1 -1
  88. package/ts/src/coerce-binary.d.ts +6 -0
  89. package/ts/src/coerce-binary.d.ts.map +1 -0
  90. package/ts/src/coerce-binary.js +32 -0
  91. package/ts/src/coerce-binary.js.map +1 -0
  92. package/ts/src/coerce-binary.test.d.ts +2 -0
  93. package/ts/src/coerce-binary.test.d.ts.map +1 -0
  94. package/ts/src/coerce-binary.test.js +39 -0
  95. package/ts/src/coerce-binary.test.js.map +1 -0
  96. package/ts/src/deno/deno-basic-sys-abstraction.d.ts +14 -0
  97. package/ts/src/deno/deno-basic-sys-abstraction.d.ts.map +1 -0
  98. package/ts/src/deno/deno-basic-sys-abstraction.js +35 -0
  99. package/ts/src/deno/deno-basic-sys-abstraction.js.map +1 -0
  100. package/ts/src/deno/deno-file-service.d.ts +1 -1
  101. package/ts/src/deno/deno-file-service.d.ts.map +1 -1
  102. package/ts/src/deno/deno-sys-abstraction.d.ts +3 -6
  103. package/ts/src/deno/deno-sys-abstraction.d.ts.map +1 -1
  104. package/ts/src/deno/deno-sys-abstraction.js +13 -17
  105. package/ts/src/deno/deno-sys-abstraction.js.map +1 -1
  106. package/ts/src/index.d.ts +1 -0
  107. package/ts/src/index.d.ts.map +1 -1
  108. package/ts/src/index.js +1 -0
  109. package/ts/src/index.js.map +1 -1
  110. package/ts/src/log-writer-impl.d.ts +1 -0
  111. package/ts/src/log-writer-impl.d.ts.map +1 -1
  112. package/ts/src/log-writer-impl.js +1 -0
  113. package/ts/src/log-writer-impl.js.map +1 -1
  114. package/ts/src/logger-impl.d.ts +4 -4
  115. package/ts/src/logger-impl.d.ts.map +1 -1
  116. package/ts/src/logger-impl.js +4 -19
  117. package/ts/src/logger-impl.js.map +1 -1
  118. package/ts/src/logger.test.js +3 -4
  119. package/ts/src/logger.test.js.map +1 -1
  120. package/ts/src/node/node-basic-sys-abstraction.d.ts +25 -0
  121. package/ts/src/node/node-basic-sys-abstraction.d.ts.map +1 -0
  122. package/ts/src/node/node-basic-sys-abstraction.js +44 -0
  123. package/ts/src/node/node-basic-sys-abstraction.js.map +1 -0
  124. package/ts/src/node/node-sys-abstraction.d.ts +3 -6
  125. package/ts/src/node/node-sys-abstraction.d.ts.map +1 -1
  126. package/ts/src/node/node-sys-abstraction.js +13 -17
  127. package/ts/src/node/node-sys-abstraction.js.map +1 -1
  128. package/ts/src/node/node-sys-abstraction.test.js +1 -1
  129. package/ts/src/node/node-sys-abstraction.test.js.map +1 -1
  130. package/ts/src/sys-abstraction.d.ts +10 -6
  131. package/ts/src/sys-abstraction.d.ts.map +1 -1
  132. package/ts/src/test/mock-logger.d.ts +2 -2
  133. package/ts/src/test/mock-logger.d.ts.map +1 -1
  134. package/ts/src/test/mock-logger.js.map +1 -1
  135. package/ts/src/tracer.test.js +5 -8
  136. package/ts/src/tracer.test.js.map +1 -1
  137. package/ts/src/txt-en-decoder.d.ts.map +1 -1
  138. package/ts/src/txt-en-decoder.js +3 -3
  139. package/ts/src/txt-en-decoder.js.map +1 -1
  140. package/ts/src/web/index.d.ts +1 -1
  141. package/ts/src/web/index.d.ts.map +1 -1
  142. package/ts/src/web/index.js +1 -1
  143. package/ts/src/web/index.js.map +1 -1
  144. package/ts/src/web/web-basic-sys-abstraction.d.ts +4 -0
  145. package/ts/src/web/web-basic-sys-abstraction.d.ts.map +1 -0
  146. package/ts/src/web/web-basic-sys-abstraction.js +45 -0
  147. package/ts/src/web/web-basic-sys-abstraction.js.map +1 -0
  148. package/utils/index.cjs +132 -3
  149. package/utils/index.cjs.map +1 -1
  150. package/utils/index.js +5 -5
  151. package/web/index.cjs +277 -281
  152. package/web/index.cjs.map +1 -1
  153. package/web/index.d.cts +4 -17
  154. package/web/index.d.ts +4 -17
  155. package/web/index.js +4 -7
  156. package/base-sys-abstraction-BnBZ6zd0.d.ts +0 -84
  157. package/base-sys-abstraction-DAZ8tx5F.d.cts +0 -84
  158. package/chunk-23MCJYE6.js.map +0 -1
  159. package/chunk-H6MLKWIZ.js +0 -88
  160. package/chunk-H6MLKWIZ.js.map +0 -1
  161. package/chunk-LXTKPZ6M.js +0 -255
  162. package/chunk-LXTKPZ6M.js.map +0 -1
  163. package/chunk-PHS255C5.js.map +0 -1
  164. package/chunk-UEER5ZC2.js.map +0 -1
  165. package/src/cf/cf-sys-abstraction.ts +0 -34
  166. package/src/web/web-sys-abstraction.ts +0 -80
  167. package/ts/src/base-sys-abstraction.test.d.ts +0 -2
  168. package/ts/src/base-sys-abstraction.test.d.ts.map +0 -1
  169. package/ts/src/base-sys-abstraction.test.js.map +0 -1
  170. package/ts/src/cf/cf-sys-abstraction.d.ts +0 -11
  171. package/ts/src/cf/cf-sys-abstraction.d.ts.map +0 -1
  172. package/ts/src/cf/cf-sys-abstraction.js +0 -30
  173. package/ts/src/cf/cf-sys-abstraction.js.map +0 -1
  174. package/ts/src/web/web-sys-abstraction.d.ts +0 -18
  175. package/ts/src/web/web-sys-abstraction.d.ts.map +0 -1
  176. package/ts/src/web/web-sys-abstraction.js +0 -64
  177. package/ts/src/web/web-sys-abstraction.js.map +0 -1
  178. /package/{chunk-55W4AK2Z.js.map → chunk-YVACAIUX.js.map} +0 -0
package/index.cjs CHANGED
@@ -38,7 +38,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
38
38
  // src/index.ts
39
39
  var index_exports = {};
40
40
  __export(index_exports, {
41
+ BaseBasicSysAbstraction: () => BaseBasicSysAbstraction,
41
42
  BaseSysAbstraction: () => BaseSysAbstraction,
43
+ BasicSysAbstractionFactory: () => BasicSysAbstractionFactory,
42
44
  BuildURI: () => BuildURI,
43
45
  ConstTime: () => ConstTime,
44
46
  EnvImpl: () => EnvImpl,
@@ -87,7 +89,8 @@ __export(index_exports, {
87
89
  TxtEnDecoderSingleton: () => TxtEnDecoderSingleton,
88
90
  URI: () => URI,
89
91
  VERSION: () => VERSION,
90
- WrapperSysAbstraction: () => WrapperSysAbstraction,
92
+ WrapperBasicSysAbstraction: () => WrapperBasicSysAbstraction,
93
+ WrapperRuntimeSysAbstraction: () => WrapperRuntimeSysAbstraction,
91
94
  YAMLFormatter: () => YAMLFormatter,
92
95
  asyncLogValue: () => asyncLogValue,
93
96
  bin2string: () => bin2string,
@@ -103,6 +106,10 @@ __export(index_exports, {
103
106
  registerEnvAction: () => registerEnvAction,
104
107
  runtimeFn: () => runtimeFn,
105
108
  toCryptoRuntime: () => toCryptoRuntime,
109
+ to_arraybuf: () => to_arraybuf,
110
+ to_blob: () => to_blob,
111
+ to_uint8: () => to_uint8,
112
+ top_uint8: () => top_uint8,
106
113
  utils: () => utils_exports
107
114
  });
108
115
  module.exports = __toCommonJS(index_exports);
@@ -299,1964 +306,2195 @@ function IsLogger(obj) {
299
306
  ].map((fn) => typeof obj[fn] === "function").reduce((a, b) => a && b, true);
300
307
  }
301
308
 
302
- // src/sys-abstraction.ts
303
- var TimeMode = {
304
- REAL: "real",
305
- CONST: "const",
306
- STEP: "step"
307
- };
308
- var RandomMode = {
309
- CONST: "const",
310
- STEP: "step",
311
- RANDOM: "random"
312
- };
313
- var IDMode = {
314
- UUID: "uuid",
315
- CONST: "const",
316
- STEP: "step"
317
- };
318
- function String2TimeMode(s) {
319
- switch (s == null ? void 0 : s.toLowerCase()) {
320
- case "real":
321
- return TimeMode.REAL;
322
- case "const":
323
- return TimeMode.CONST;
324
- case "step":
325
- return TimeMode.STEP;
326
- default:
327
- return TimeMode.REAL;
309
+ // src/result.ts
310
+ var Result = class _Result {
311
+ static Ok(t) {
312
+ return new ResultOK(t);
328
313
  }
329
- }
330
-
331
- // src/time.ts
332
- var Time = class {
333
- TimeSince(start) {
334
- const now = this.Now();
335
- return now.getTime() - start.getTime();
314
+ static Err(t) {
315
+ if (typeof t === "string") {
316
+ return new ResultError(new Error(t));
317
+ }
318
+ if (_Result.Is(t)) {
319
+ if (t.is_ok()) {
320
+ return new ResultError(new Error("Result Error is Ok"));
321
+ }
322
+ return t;
323
+ }
324
+ return new ResultError(t);
336
325
  }
337
- };
338
- var TimeUnits = {
339
- Microsecond: 1,
340
- Second: 1e3 * 1,
341
- //Microsecond,
342
- Minute: 60 * 1e3 * 1,
343
- //Second,
344
- Hour: 60 * 60 * 1e3 * 1
345
- // Minute,
346
- };
347
-
348
- // src/base-sys-abstraction.ts
349
- var SysTime = class extends Time {
350
- Now() {
351
- return /* @__PURE__ */ new Date();
326
+ static Is(t) {
327
+ if (!t) {
328
+ return false;
329
+ }
330
+ if (t instanceof _Result) {
331
+ return true;
332
+ }
333
+ const rt = t;
334
+ if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
335
+ return true;
336
+ }
337
+ return false;
352
338
  }
353
- Sleep(duration) {
354
- return new Promise((resolve) => {
355
- setTimeout(() => {
356
- resolve();
357
- }, duration);
358
- });
339
+ isOk() {
340
+ return this.is_ok();
359
341
  }
360
- };
361
- var ConstTime = class extends Time {
362
- Now() {
363
- return new Date(2021, 1, 1, 0, 0, 0, 0);
342
+ isErr() {
343
+ return this.is_err();
364
344
  }
365
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
366
- Sleep(duration) {
367
- return Promise.resolve();
345
+ Ok() {
346
+ return this.unwrap();
347
+ }
348
+ Err() {
349
+ return this.unwrap_err();
368
350
  }
369
351
  };
370
- var StepTime = class extends Time {
371
- constructor() {
352
+ var ResultOK = class extends Result {
353
+ constructor(t) {
372
354
  super();
373
- this._step = new ConstTime().Now();
374
- this._start = this._step;
355
+ this._t = t;
375
356
  }
376
- Now(steps = 1) {
377
- for (let i = 0; steps > 0 && i < steps; i++) {
378
- this._step = new Date(this._step.getTime() + 1e3);
379
- }
380
- if (steps < 1) {
381
- this._step = new Date(this._start.getTime() + steps * -1e3);
382
- }
383
- return this._step;
357
+ is_ok() {
358
+ return true;
384
359
  }
385
- Sleep(duration) {
386
- this._step = new Date(this._step.getTime() + duration);
387
- return Promise.resolve();
360
+ is_err() {
361
+ return false;
362
+ }
363
+ unwrap_err() {
364
+ throw new Error("Result is Ok");
365
+ }
366
+ unwrap() {
367
+ return this._t;
388
368
  }
389
369
  };
390
- function TimeFactory(timeMode) {
391
- switch (timeMode) {
392
- case TimeMode.REAL:
393
- return new SysTime();
394
- case TimeMode.CONST:
395
- return new ConstTime();
396
- case TimeMode.STEP:
397
- return new StepTime();
370
+ var ResultError = class extends Result {
371
+ constructor(t) {
372
+ super();
373
+ this._error = t;
398
374
  }
399
- return new SysTime();
400
- }
401
- var RandomService = class {
402
- constructor(mode) {
403
- this._step = 0;
404
- this._mode = mode;
375
+ is_ok() {
376
+ return false;
405
377
  }
406
- Random0ToValue(value) {
407
- switch (this._mode) {
408
- case RandomMode.CONST:
409
- return 0.5 * value;
410
- case RandomMode.STEP:
411
- this._step += 1e-4;
412
- return this._step * value;
413
- case RandomMode.RANDOM:
414
- return Math.random() * value;
415
- default:
416
- throw new Error("Unknown RandomMode");
417
- }
378
+ is_err() {
379
+ return true;
418
380
  }
419
- };
420
- var IdService = class {
421
- constructor(mode) {
422
- this._step = 0;
423
- if (!mode) {
424
- mode = IDMode.UUID;
425
- }
426
- this._mode = mode;
381
+ unwrap() {
382
+ throw new Error(`Result is Err: ${this._error}`);
427
383
  }
428
- NextId() {
429
- switch (this._mode) {
430
- case IDMode.UUID:
431
- return crypto.randomUUID();
432
- case IDMode.CONST:
433
- return "VeryUniqueID";
434
- case IDMode.STEP:
435
- return `STEPId-${this._step++}`;
436
- default:
437
- throw new Error("Unknown IDMode");
438
- }
384
+ unwrap_err() {
385
+ return this._error;
439
386
  }
440
387
  };
441
- function consumeReadableStream(reader, writeFn) {
442
- reader.read().then(({ done, value }) => {
443
- if (done) {
444
- return;
388
+ function exception2Result(fn) {
389
+ try {
390
+ const res = fn();
391
+ if (res instanceof Promise) {
392
+ return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
445
393
  }
446
- writeFn(value).then(() => {
447
- consumeReadableStream(reader, writeFn);
448
- }).catch((e) => {
449
- console.error("consumeReadableStream:writeFn", e);
450
- });
451
- }).catch((e) => {
452
- console.error("consumeReadableStream:read", e);
453
- });
454
- }
455
- function CFWriteableStream(writeFn) {
456
- const ts = new TransformStream();
457
- consumeReadableStream(ts.readable.getReader(), writeFn);
458
- return ts.writable;
394
+ return Result.Ok(res);
395
+ } catch (e) {
396
+ return Result.Err(e);
397
+ }
459
398
  }
460
- var BaseSysAbstraction = class {
461
- constructor(params) {
462
- this._time = new SysTime();
463
- this._idService = new IdService();
464
- this._randomService = new RandomService(RandomMode.RANDOM);
465
- this._fileSystem = params.FileSystem;
466
- this._systemService = params.SystemService;
467
- this._txtEnDe = params.TxtEnDecoder;
468
- const decoder = this._txtEnDe;
469
- this._stdout = CFWriteableStream((chunk) => {
470
- const decoded = decoder.decode(chunk);
471
- console.log(decoded.trimEnd());
472
- return Promise.resolve();
473
- });
474
- this._stderr = CFWriteableStream((chunk) => {
475
- const decoded = decoder.decode(chunk);
476
- console.error(decoded.trimEnd());
477
- return Promise.resolve();
478
- });
399
+
400
+ // src/types.ts
401
+ var _Required = class {
402
+ constructor() {
403
+ this.type = "REQUIRED";
479
404
  }
480
405
  };
481
- var WrapperSysAbstraction = class {
482
- constructor(base, params) {
483
- this._time = base._time;
484
- this._stdout = base._stdout;
485
- this._stderr = base._stderr;
486
- this._idService = base._idService;
487
- this._randomService = base._randomService;
488
- this._fileSystem = base._fileSystem;
489
- this._systemService = base._systemService;
490
- if (params) {
491
- if (params.TimeMode) {
492
- this._time = TimeFactory(params.TimeMode);
493
- }
494
- if (params.Stdout) {
495
- this._stdout = params.Stdout;
496
- }
497
- if (params.Stderr) {
498
- this._stderr = params.Stderr;
499
- }
500
- if (params.IdMode) {
501
- this._idService = new IdService(params.IdMode);
502
- }
503
- if (params.RandomMode) {
504
- this._randomService = new RandomService(params.RandomMode);
505
- }
506
- if (params.FileSystem) {
507
- this._fileSystem = params.FileSystem;
508
- }
509
- if (params.SystemService) {
510
- this._systemService = params.SystemService;
511
- }
512
- }
513
- }
514
- Time() {
515
- return this._time;
516
- }
517
- NextId() {
518
- return this._idService.NextId();
519
- }
520
- Random0ToValue(value) {
521
- return this._randomService.Random0ToValue(value);
522
- }
523
- Stdout() {
524
- return this._stdout;
525
- }
526
- Stderr() {
527
- return this._stderr;
528
- }
529
- System() {
530
- return this._systemService;
531
- }
532
- FileSystem() {
533
- return this._fileSystem;
406
+ var _Optional = class {
407
+ constructor() {
408
+ this.type = "OPTIONAL";
534
409
  }
535
410
  };
536
-
537
- // src/future.ts
538
- var _promise, _resolveFn, _rejectFn;
539
- var Future = class {
540
- constructor() {
541
- __privateAdd(this, _promise);
542
- __privateAdd(this, _resolveFn, () => {
543
- throw new Error("This Promise is not working as expected.");
544
- });
545
- __privateAdd(this, _rejectFn, () => {
546
- throw new Error("This Promise is not working as expected.");
547
- });
548
- __privateSet(this, _promise, new Promise((resolve, reject) => {
549
- __privateSet(this, _resolveFn, resolve);
550
- __privateSet(this, _rejectFn, reject);
551
- }));
552
- }
553
- async asPromise() {
554
- return __privateGet(this, _promise);
555
- }
556
- resolve(value) {
557
- __privateGet(this, _resolveFn).call(this, value);
558
- }
559
- reject(reason) {
560
- __privateGet(this, _rejectFn).call(this, reason);
561
- }
411
+ var param = {
412
+ REQUIRED: new _Required(),
413
+ OPTIONAL: new _Optional()
562
414
  };
563
- _promise = new WeakMap();
564
- _resolveFn = new WeakMap();
565
- _rejectFn = new WeakMap();
566
415
 
567
- // src/lru-map-set.ts
568
- var LRUSet = class {
569
- constructor(param2 = {}) {
570
- this._lruMap = new LRUMap(param2);
571
- }
572
- setParam(param2 = {}) {
573
- this._lruMap.setParam(param2);
574
- }
575
- get size() {
576
- return this._lruMap.size;
577
- }
578
- has(key) {
579
- return this._lruMap.has(key);
580
- }
581
- add(key) {
582
- this._lruMap.set(key, key);
583
- }
584
- delete(key) {
585
- this._lruMap.delete(key);
586
- }
587
- clear() {
588
- this._lruMap.clear();
589
- }
590
- forEach(callbackfn) {
591
- this._lruMap.forEach((value) => callbackfn(value, value));
416
+ // src/utils/get-params-result.ts
417
+ function getParamsResult(keys, getParam) {
418
+ const keyDef = keys.flat().reduce(
419
+ (acc, i) => {
420
+ if (typeof i === "string") {
421
+ acc.push({ key: i, def: void 0, isOptional: false });
422
+ } else if (typeof i === "object") {
423
+ acc.push(
424
+ ...Object.keys(i).map((k) => ({
425
+ key: k,
426
+ def: typeof i[k] === "string" ? i[k] : void 0,
427
+ isOptional: i[k] === param.OPTIONAL
428
+ }))
429
+ );
430
+ }
431
+ return acc;
432
+ },
433
+ []
434
+ );
435
+ const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
436
+ const msg = keys2.join(",");
437
+ return `missing parameters: ${msg}`;
438
+ });
439
+ const errors = [];
440
+ const result = {};
441
+ for (const kd of keyDef) {
442
+ const val = getParam.getParam(kd.key);
443
+ if (val === void 0) {
444
+ if (typeof kd.def === "string") {
445
+ result[kd.key] = kd.def;
446
+ } else {
447
+ if (!kd.isOptional) {
448
+ errors.push(kd.key);
449
+ }
450
+ }
451
+ } else {
452
+ result[kd.key] = val;
453
+ }
592
454
  }
593
- entries() {
594
- return this._lruMap.entries();
455
+ if (errors.length) {
456
+ return Result.Err(msgFn(...errors));
595
457
  }
458
+ return Result.Ok(result);
459
+ }
460
+
461
+ // src/utils/relative-path.ts
462
+ var PartType = {
463
+ Slash: 1,
464
+ Root: 3,
465
+ Up: 4,
466
+ Noop: 8
467
+ // RootUp = 0x8 /* ../ */,
596
468
  };
597
- var LRUMap = class {
598
- constructor(c = {}) {
599
- this._map = /* @__PURE__ */ new Map();
600
- this.param = {
601
- maxEntries: c.maxEntries || 100,
602
- maxAge: c.maxAge || 0
603
- };
604
- }
605
- touch(key) {
606
- if (!this._map.has(key)) {
607
- throw new Error(`key not found in cache: ${key}`);
608
- }
609
- const value = this._map.get(key);
610
- this._map.delete(key);
611
- this._map.set(key, value);
612
- return value;
469
+ var Path = class {
470
+ constructor(parts = []) {
471
+ this.parts = parts;
613
472
  }
614
- setParam(param2 = {}) {
615
- if (typeof param2.maxEntries === "number") {
616
- this.param.maxEntries = param2.maxEntries;
617
- if (param2.maxEntries > 0 && this._map.size > param2.maxEntries) {
618
- const toDelete = [];
619
- let cacheSize = this._map.size;
620
- for (const key of this._map.keys()) {
621
- if (cacheSize > param2.maxEntries) {
622
- toDelete.push(key);
623
- cacheSize--;
624
- } else {
625
- break;
626
- }
627
- }
628
- for (const key of toDelete) {
629
- this._map.delete(key);
473
+ toString() {
474
+ return this.parts.map((part) => {
475
+ if (typeof part === "string") {
476
+ return part;
477
+ } else {
478
+ switch (part) {
479
+ case PartType.Slash:
480
+ case PartType.Root:
481
+ return "/";
482
+ case PartType.Up:
483
+ return "..";
484
+ default:
485
+ return part;
630
486
  }
631
487
  }
632
- }
488
+ }).join("");
633
489
  }
634
- has(key) {
635
- return this._map.has(key);
490
+ add(part) {
491
+ if (this.parts.includes(PartType.Root) && part === PartType.Root) {
492
+ throw new Error("Cannot add absolute part to absolute path");
493
+ }
494
+ const last = this.parts[this.parts.length - 1];
495
+ if (last & PartType.Slash && part === PartType.Slash) {
496
+ return;
497
+ }
498
+ switch (part) {
499
+ case ".":
500
+ this.parts.push(PartType.Noop);
501
+ return;
502
+ case "..":
503
+ part = PartType.Up;
504
+ }
505
+ if (last === PartType.Noop && part === PartType.Slash) {
506
+ if (last === PartType.Noop) {
507
+ this.parts.pop();
508
+ }
509
+ return;
510
+ }
511
+ this.parts.push(part);
636
512
  }
637
- get size() {
638
- return this._map.size;
513
+ };
514
+ function splitPath(path) {
515
+ const p = new Path();
516
+ if (path === "") {
517
+ return p;
639
518
  }
640
- async getSet(key, createFN) {
641
- const val = this.get(key);
642
- if (val) {
643
- return val;
519
+ for (let count = 0; path.length; count++) {
520
+ if (path.match(/^\/+/)) {
521
+ if (count === 0) {
522
+ p.add(PartType.Root);
523
+ } else {
524
+ p.add(PartType.Slash);
525
+ }
526
+ path = path.replace(/^\/+/, "");
644
527
  } else {
645
- const val2 = await createFN(key);
646
- this.set(key, val2);
647
- return val2;
528
+ const part = path.replace(/\/.*$/, "");
529
+ p.add(part);
530
+ path = path.replace(/^[^/]+/, "");
648
531
  }
649
532
  }
650
- get(key) {
651
- if (this._map.has(key)) {
652
- return this.touch(key);
533
+ return p;
534
+ }
535
+ function pathJoin(...paths) {
536
+ let prev = "";
537
+ const res = [];
538
+ for (let i = 0; i < paths.length; i++) {
539
+ const path = paths[i];
540
+ if (path === "") {
541
+ continue;
653
542
  }
654
- return this._map.get(key);
655
- }
656
- set(key, value) {
657
- this._map.delete(key);
658
- if (this.param.maxEntries > 0 && this._map.size >= this.param.maxEntries) {
659
- this._map.delete(this._map.keys().next().value);
660
- this._map.set(key, value);
543
+ if (!(prev.endsWith("/") || path.startsWith("/"))) {
544
+ if (prev !== "") {
545
+ res.push("/");
546
+ }
547
+ res.push(path);
661
548
  } else {
662
- this._map.set(key, value);
549
+ res.push(path);
663
550
  }
551
+ prev = path;
664
552
  }
665
- delete(key) {
666
- this._map.delete(key);
667
- }
668
- clear() {
669
- this._map.clear();
553
+ return res.join("");
554
+ }
555
+ function relativePath(path, relative) {
556
+ const relativeParts = splitPath(relative);
557
+ let result;
558
+ if (relativeParts.parts[0] === PartType.Root) {
559
+ result = relative;
560
+ } else {
561
+ result = pathJoin(path, relative);
670
562
  }
671
- forEach(callbackfn) {
672
- this._map.forEach(callbackfn);
673
- }
674
- entries() {
675
- return this._map.entries();
563
+ const unoptPath = splitPath(result);
564
+ const out = [];
565
+ let topUp = false;
566
+ for (const part of unoptPath.parts) {
567
+ switch (part) {
568
+ case PartType.Root:
569
+ out.push(PartType.Root);
570
+ break;
571
+ case PartType.Up:
572
+ if (out.length && !topUp) {
573
+ const last = out.length - 1;
574
+ if (typeof out[last] === "string" && out[last - 1] == PartType.Root) {
575
+ out.pop();
576
+ } else {
577
+ out.pop();
578
+ out.pop();
579
+ }
580
+ if (out.length === 0) {
581
+ topUp = !topUp ? true : topUp;
582
+ out.push(PartType.Up);
583
+ }
584
+ } else {
585
+ out.push(PartType.Up);
586
+ }
587
+ break;
588
+ case PartType.Slash:
589
+ if (!(out[out.length - 1] & PartType.Slash)) {
590
+ out.push(PartType.Slash);
591
+ }
592
+ break;
593
+ default:
594
+ out.push(part);
595
+ break;
596
+ }
676
597
  }
677
- // *entries(): IterableIterator<[T, K]> {
678
- // for (const x of this._cache.entries()) {
679
- // yield x;
680
- // }
681
- // }
682
- // getLeastRecent(): K {
683
- // return Array.from(this.cache)[0];
684
- // }
685
- // getMostRecent(): K {
686
- // return Array.from(this.cache)[this.cache.size - 1];
687
- // }
688
- };
598
+ return new Path(out).toString();
599
+ }
689
600
 
690
- // src/result.ts
691
- var Result = class _Result {
692
- static Ok(t) {
693
- return new ResultOK(t);
601
+ // src/utils/stripper.ts
602
+ function stripper(strip, obj) {
603
+ const strips = Array.isArray(strip) ? strip : [strip];
604
+ const restrips = strips.map((s) => {
605
+ if (typeof s === "string") {
606
+ const escaped = s.replace(/[-\\[\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g, "\\$&");
607
+ return new RegExp(`^${escaped}$`);
608
+ }
609
+ return s;
610
+ });
611
+ return localStripper(void 0, restrips, obj);
612
+ }
613
+ function localStripper(path, restrips, obj) {
614
+ if (typeof obj !== "object" || obj === null) {
615
+ return obj;
694
616
  }
695
- static Err(t) {
696
- if (typeof t === "string") {
697
- return new ResultError(new Error(t));
617
+ if (Array.isArray(obj)) {
618
+ return obj.map((i) => localStripper(path, restrips, i));
619
+ }
620
+ const ret = { ...obj };
621
+ const matcher = (key, nextPath) => {
622
+ for (const re of restrips) {
623
+ if (re.test(key) || re.test(nextPath)) {
624
+ return true;
625
+ }
698
626
  }
699
- if (_Result.Is(t)) {
700
- if (t.is_ok()) {
701
- return new ResultError(new Error("Result Error is Ok"));
627
+ return false;
628
+ };
629
+ for (const key in ret) {
630
+ if (Object.prototype.hasOwnProperty.call(ret, key)) {
631
+ let nextPath;
632
+ if (path) {
633
+ nextPath = [path, key].join(".");
634
+ } else {
635
+ nextPath = key;
636
+ }
637
+ if (matcher(key, nextPath)) {
638
+ delete ret[key];
639
+ continue;
640
+ }
641
+ if (typeof ret[key] === "object") {
642
+ if (Array.isArray(ret[key])) {
643
+ ret[key] = ret[key].reduce((acc, v, i) => {
644
+ const toDelete = matcher(key, `${nextPath}[${i}]`);
645
+ if (!toDelete) {
646
+ acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
647
+ }
648
+ return acc;
649
+ }, []);
650
+ } else {
651
+ ret[key] = localStripper(nextPath, restrips, ret[key]);
652
+ }
702
653
  }
703
- return t;
704
654
  }
705
- return new ResultError(t);
706
655
  }
707
- static Is(t) {
708
- if (!t) {
709
- return false;
710
- }
711
- if (t instanceof _Result) {
712
- return true;
656
+ return ret;
657
+ }
658
+
659
+ // src/uri.ts
660
+ function match(iref, ioth) {
661
+ const mr = {
662
+ score: 0,
663
+ protocol: false,
664
+ hostname: false,
665
+ port: false,
666
+ pathname: false,
667
+ pathParts: [],
668
+ params: {}
669
+ };
670
+ const ref = URI.from(iref);
671
+ const oth = URI.from(ioth);
672
+ if (ref.protocol === oth.protocol) {
673
+ mr.score += 1;
674
+ mr.protocol = true;
675
+ }
676
+ try {
677
+ const refH = ref.hostname;
678
+ const refP = ref.port;
679
+ if (refH === oth.hostname) {
680
+ mr.score += 1;
681
+ mr.hostname = true;
713
682
  }
714
- const rt = t;
715
- if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
716
- return true;
683
+ if (refP.length && refP === oth.port) {
684
+ mr.score += 1;
685
+ mr.port = true;
717
686
  }
718
- return false;
687
+ } catch (e) {
719
688
  }
720
- isOk() {
721
- return this.is_ok();
689
+ if (ref.pathname.length && ref.pathname !== "/") {
690
+ const pref = ref.pathname.split("/").filter((p) => p.length);
691
+ const poth = oth.pathname.split("/").filter((p) => p.length);
692
+ for (let i = 0; i < pref.length && i < poth.length; i++) {
693
+ if (poth[i] === pref[i]) {
694
+ mr.score += 1;
695
+ mr.pathname = true;
696
+ mr.pathParts.push(pref[i]);
697
+ }
698
+ }
722
699
  }
723
- isErr() {
724
- return this.is_err();
700
+ for (const [key, value] of ref.getParams) {
701
+ if (oth.getParam(key) === value) {
702
+ mr.score += 1;
703
+ mr.params[key] = value;
704
+ }
725
705
  }
726
- Ok() {
727
- return this.unwrap();
706
+ return mr;
707
+ }
708
+ function coerceKey(key, def) {
709
+ if (typeof key === "object") {
710
+ const keys = Object.keys(key);
711
+ if (keys.length !== 1) {
712
+ throw new Error(`Invalid key: ${JSON.stringify(key)}`);
713
+ }
714
+ return { key: keys[0], def: key[keys[0]] };
728
715
  }
729
- Err() {
730
- return this.unwrap_err();
716
+ return { key, def };
717
+ }
718
+ function falsy2undef(value) {
719
+ return value === void 0 || value === null ? void 0 : value;
720
+ }
721
+ function ensureURLWithDefaultProto(url, defaultProtocol) {
722
+ if (!url) {
723
+ return new MutableURL(`${defaultProtocol}//`);
731
724
  }
732
- };
733
- var ResultOK = class extends Result {
734
- constructor(t) {
735
- super();
736
- this._t = t;
725
+ if (typeof url === "string") {
726
+ try {
727
+ return new MutableURL(url);
728
+ } catch (e) {
729
+ return new MutableURL(`${defaultProtocol}//${url}`);
730
+ }
731
+ } else {
732
+ return new MutableURL(url.toString());
737
733
  }
738
- is_ok() {
739
- return true;
734
+ }
735
+ function isURL(value) {
736
+ return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
737
+ }
738
+ var MutableURL = class _MutableURL extends URL {
739
+ constructor(urlStr) {
740
+ super("defect://does.not.exist");
741
+ const partedURL = urlStr.split(":");
742
+ this._hasHostpart = hasHostPartProtocols.has(partedURL[0]);
743
+ let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
744
+ if (!this._hasHostpart) {
745
+ const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
746
+ hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
747
+ }
748
+ try {
749
+ this._sysURL = new URL(hostPartUrl);
750
+ } catch (ie) {
751
+ const e = ie;
752
+ e.message = `${e.message} for URL: ${urlStr}`;
753
+ throw e;
754
+ }
755
+ this._protocol = `${partedURL[0]}:`;
756
+ if (this._hasHostpart) {
757
+ this._pathname = this._sysURL.pathname;
758
+ } else {
759
+ this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
760
+ }
761
+ this.hash = this._sysURL.hash;
740
762
  }
741
- is_err() {
742
- return false;
763
+ clone() {
764
+ return new _MutableURL(this.toString());
743
765
  }
744
- unwrap_err() {
745
- throw new Error("Result is Ok");
766
+ get host() {
767
+ if (!this._hasHostpart) {
768
+ throw new Error(
769
+ `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
770
+ );
771
+ }
772
+ return this._sysURL.host;
746
773
  }
747
- unwrap() {
748
- return this._t;
774
+ get port() {
775
+ if (!this._hasHostpart) {
776
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
777
+ }
778
+ return this._sysURL.port;
749
779
  }
750
- };
751
- var ResultError = class extends Result {
752
- constructor(t) {
753
- super();
754
- this._error = t;
755
- }
756
- is_ok() {
757
- return false;
758
- }
759
- is_err() {
760
- return true;
761
- }
762
- unwrap() {
763
- throw new Error(`Result is Err: ${this._error}`);
764
- }
765
- unwrap_err() {
766
- return this._error;
767
- }
768
- };
769
- function exception2Result(fn) {
770
- try {
771
- const res = fn();
772
- if (res instanceof Promise) {
773
- return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
780
+ set port(p) {
781
+ if (!this._hasHostpart) {
782
+ throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
774
783
  }
775
- return Result.Ok(res);
776
- } catch (e) {
777
- return Result.Err(e);
778
- }
779
- }
780
-
781
- // src/resolve-once.ts
782
- var ResolveSeq = class {
783
- constructor(ctx) {
784
- this._flushWaiting = [];
785
- this._seqFutures = [];
786
- this.ctx = ctx;
787
- }
788
- reset() {
784
+ this._sysURL.port = p;
789
785
  }
790
- flush() {
791
- var _a;
792
- if (this._seqFutures.length > 0) {
793
- const waitForFlush = new Future();
794
- (_a = this._flushWaiting) == null ? void 0 : _a.push(waitForFlush);
795
- return waitForFlush.asPromise();
786
+ get hostname() {
787
+ if (!this._hasHostpart) {
788
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
796
789
  }
797
- return Promise.resolve();
790
+ return this._sysURL.hostname;
798
791
  }
799
- _step(item) {
800
- var _a;
801
- if (!item) {
802
- this._flushWaiting.forEach((f) => f.resolve());
803
- (_a = this._flushWaiting) == null ? void 0 : _a.splice(0, this._flushWaiting.length);
804
- return Promise.resolve();
792
+ set hostname(h) {
793
+ if (!this._hasHostpart) {
794
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
805
795
  }
806
- item.fn(this.ctx).then((value) => item.future.resolve(value)).catch((e) => item.future.reject(e)).finally(() => {
807
- this._seqFutures.shift();
808
- void this._step(this._seqFutures[0]);
809
- });
810
- return Promise.resolve();
796
+ this._sysURL.hostname = h;
811
797
  }
812
- async add(fn, id) {
813
- const future = new Future();
814
- this._seqFutures.push({ future, fn, id });
815
- if (this._seqFutures.length === 1) {
816
- void this._step(this._seqFutures[0]);
817
- }
818
- return future.asPromise();
798
+ set pathname(p) {
799
+ this._pathname = p;
819
800
  }
820
- };
821
- var ResolveOnce = class {
822
- constructor(ctx) {
823
- this._onceDone = false;
824
- this._onceFutures = [];
825
- this._onceOk = false;
826
- this._isPromise = false;
827
- this.ctx = ctx;
801
+ get pathname() {
802
+ return this._pathname;
828
803
  }
829
- get ready() {
830
- return this._onceDone;
804
+ get protocol() {
805
+ return this._protocol;
831
806
  }
832
- reset() {
833
- this._onceDone = false;
834
- this._onceOk = false;
835
- this._onceValue = void 0;
836
- this._onceError = void 0;
837
- if (this._inProgress) {
838
- const idx = this._onceFutures.findIndex((f) => f === this._inProgress);
839
- if (idx >= 0) {
840
- this._onceFutures.push(...this._onceFutures.splice(2).slice(1));
841
- }
842
- } else {
843
- this._onceFutures.length = 0;
807
+ set protocol(p) {
808
+ if (!p.endsWith(":")) {
809
+ p = `${p}:`;
844
810
  }
811
+ this._protocol = p;
845
812
  }
846
- // T extends Option<infer U> ? U : T
847
- once(fn) {
848
- if (this._onceDone) {
849
- if (this._onceError) {
850
- if (this._isPromise) {
851
- return Promise.reject(this._onceError);
852
- } else {
853
- throw this._onceError;
854
- }
855
- }
856
- if (this._onceOk) {
857
- if (this._isPromise) {
858
- return Promise.resolve(this._onceValue);
859
- } else {
860
- return this._onceValue;
861
- }
813
+ get searchParams() {
814
+ return this._sysURL.searchParams;
815
+ }
816
+ toString() {
817
+ let search = "";
818
+ if (this._sysURL.searchParams.size) {
819
+ for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
820
+ search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
862
821
  }
863
- throw new Error("ResolveOnce.once impossible");
864
822
  }
865
- const future = new Future();
866
- this._onceFutures.push(future);
867
- if (this._onceFutures.length === 1) {
868
- const okFn = (value) => {
869
- this._onceValue = value;
870
- this._onceOk = true;
871
- this._onceDone = true;
872
- if (this._isPromise) {
873
- this._onceFutures.forEach((f) => f.resolve(this._onceValue));
874
- }
875
- this._onceFutures.length = 0;
876
- };
877
- const catchFn = (e) => {
878
- this._onceError = e;
879
- this._onceOk = false;
880
- this._onceValue = void 0;
881
- this._onceDone = true;
882
- if (this._isPromise) {
883
- this._onceFutures.forEach((f) => f.reject(this._onceError));
884
- }
885
- this._onceFutures.length = 0;
886
- };
887
- this._inProgress = future;
888
- try {
889
- const ret = fn(this.ctx);
890
- if (typeof ret.then === "function") {
891
- this._isPromise = true;
892
- ret.then(okFn).catch(catchFn).finally(() => {
893
- this._inProgress = void 0;
894
- });
895
- } else {
896
- okFn(ret);
897
- }
898
- } catch (e) {
899
- catchFn(e);
823
+ let hostpart = "";
824
+ if (this._hasHostpart) {
825
+ hostpart = this._sysURL.hostname;
826
+ if (this._sysURL.port) {
827
+ hostpart += `:${this._sysURL.port}`;
900
828
  }
901
- if (!this._isPromise) {
902
- this._inProgress = void 0;
829
+ if (!this._pathname.startsWith("/")) {
830
+ hostpart += "/";
903
831
  }
904
832
  }
905
- if (this._isPromise) {
906
- return future.asPromise();
907
- } else {
908
- return this.once(fn);
909
- }
833
+ return `${this._protocol}//${hostpart}${this._pathname}${search}`;
910
834
  }
911
835
  };
912
- var Keyed = class {
913
- constructor(factory, params) {
914
- var _a;
915
- this.factory = factory;
916
- this._map = new LRUMap((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
836
+ function from(fac, strURLUri, defaultProtocol) {
837
+ switch (typeof falsy2undef(strURLUri)) {
838
+ case "undefined":
839
+ return fac(new MutableURL(`${defaultProtocol}///`));
840
+ case "string":
841
+ return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
842
+ case "object":
843
+ if (BuildURI.is(strURLUri)) {
844
+ return fac(new MutableURL(strURLUri._url.toString()));
845
+ } else if (URI.is(strURLUri)) {
846
+ return fac(new MutableURL(strURLUri._url.toString()));
847
+ } else if (isURL(strURLUri)) {
848
+ return fac(new MutableURL(strURLUri.toString()));
849
+ }
850
+ throw new Error(`unknown object type: ${strURLUri}`);
851
+ default:
852
+ throw new Error(`Invalid argument: ${typeof strURLUri}`);
917
853
  }
918
- setParam(params) {
919
- this._map.setParam(params.lru);
854
+ }
855
+ function getParamResult(key, val, msgFn = (key2) => {
856
+ return `missing parameter: ${key2}`;
857
+ }) {
858
+ if (val === void 0) {
859
+ return Result.Err(msgFn(key));
920
860
  }
921
- async asyncGet(key) {
922
- return this.get(await key());
861
+ return Result.Ok(val);
862
+ }
863
+ var BuildURI = class _BuildURI {
864
+ // pathname needs this
865
+ constructor(url) {
866
+ this._url = url;
923
867
  }
924
- get(key) {
925
- if (typeof key === "function") {
926
- key = key();
927
- }
928
- let keyed = this._map.get(key);
929
- if (!keyed) {
930
- keyed = this.factory(key);
931
- this._map.set(key, keyed);
932
- }
933
- return keyed;
868
+ static is(value) {
869
+ return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
934
870
  }
935
- unget(key) {
936
- const keyed = this._map.get(key);
937
- keyed == null ? void 0 : keyed.reset();
938
- this._map.delete(key);
871
+ static from(strURLUri, defaultProtocol = "file:") {
872
+ return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
939
873
  }
940
- reset() {
941
- this._map.forEach((keyed) => keyed.reset());
942
- this._map.clear();
874
+ match(other) {
875
+ return match(this.URI(), URI.from(other));
943
876
  }
944
- };
945
- var KeyedResolvOnce = class extends Keyed {
946
- constructor(kp = {}) {
947
- super((key) => new ResolveOnce(key), kp);
877
+ port(p) {
878
+ this._url.port = p;
879
+ return this;
948
880
  }
949
- /**
950
- *
951
- * @returns The values of the resolved keys
952
- */
953
- values() {
954
- return Array.from(this._map.entries()).filter(([_, v]) => v._onceDone).map(([k, v]) => {
955
- if (v._onceDone) {
956
- if (v._onceError) {
957
- return {
958
- key: k,
959
- value: Result.Err(v._onceError)
960
- };
961
- }
962
- return {
963
- key: k,
964
- value: Result.Ok(v._onceValue)
965
- };
966
- }
967
- throw new Error("KeyedResolvOnce.values impossible");
968
- });
969
- }
970
- };
971
- var KeyedResolvSeq = class extends Keyed {
972
- constructor(kp = {}) {
973
- super((key) => new ResolveSeq(key), kp);
881
+ hostname(h) {
882
+ this._url.hostname = h;
883
+ return this;
974
884
  }
975
- };
976
-
977
- // src/runtime.ts
978
- function isSet(value, ref = globalThis) {
979
- const [head, ...tail] = value.split(".");
980
- if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
981
- if (tail.length <= 1) {
982
- return true;
885
+ protocol(p) {
886
+ if (!p.endsWith(":")) {
887
+ p = `${p}:`;
983
888
  }
984
- return isSet(tail.join("."), ref[head]);
985
- }
986
- return false;
987
- }
988
- function runtimeFn() {
989
- const gt = globalThis;
990
- let isReactNative = (
991
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
992
- isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative"
993
- );
994
- let isNodeIsh = false;
995
- if (!isSet("Deno")) {
996
- isNodeIsh = isSet("process.versions.node") && !isReactNative;
997
- }
998
- let isDeno = isSet("Deno");
999
- const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
1000
- if (isCFWorker) {
1001
- isDeno = false;
1002
- isNodeIsh = false;
1003
- isReactNative = false;
1004
- }
1005
- return {
1006
- isNodeIsh,
1007
- isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1008
- isDeno,
1009
- isReactNative,
1010
- isCFWorker
1011
- };
1012
- }
1013
-
1014
- // src/deno/deno-env-actions.ts
1015
- var once = new ResolveOnce();
1016
- var _deno;
1017
- var _DenoEnvActions = class _DenoEnvActions {
1018
- constructor(opts) {
1019
- __privateAdd(this, _deno, globalThis);
1020
- this.opts = opts;
1021
- }
1022
- static new(opts) {
1023
- return once.once(() => new _DenoEnvActions(opts));
889
+ this._url.protocol = p;
890
+ return this;
1024
891
  }
1025
- get _env() {
1026
- return __privateGet(this, _deno).Deno.env;
892
+ pathname(p) {
893
+ this._url.pathname = p;
894
+ return this;
1027
895
  }
1028
- register(env) {
1029
- for (const key of env.keys()) {
1030
- this._env.set(key, env.get(key) || "");
896
+ // could pass a relative path or a full URL
897
+ // if relative path, it will be appended to the current path
898
+ resolve(p) {
899
+ if (!p) {
900
+ return this;
1031
901
  }
1032
- return env;
902
+ if (typeof p === "string") {
903
+ if (!p.match(/^[a-zA-Z0-9]+:/)) {
904
+ if (p.startsWith("/")) {
905
+ this.pathname(p);
906
+ return this;
907
+ }
908
+ return this.appendRelative(p);
909
+ }
910
+ }
911
+ this._url = new MutableURL(p.toString());
912
+ return this;
1033
913
  }
1034
- active() {
1035
- return runtimeFn().isDeno;
914
+ appendRelative(p) {
915
+ const appendUrl = URI.from(p);
916
+ const pathname = "./" + appendUrl.pathname;
917
+ const basePath = this._url.pathname;
918
+ this.pathname(relativePath(basePath, pathname));
919
+ for (const [key, value] of appendUrl.getParams) {
920
+ this.setParam(key, value);
921
+ }
922
+ return this;
1036
923
  }
1037
- keys() {
1038
- return Object.keys(this._env.toObject());
924
+ cleanParams() {
925
+ for (const key of Array.from(this._url.searchParams.keys())) {
926
+ this._url.searchParams.delete(key);
927
+ }
928
+ return this;
1039
929
  }
1040
- get(key) {
1041
- return this._env.get(key);
930
+ delParam(key) {
931
+ this._url.searchParams.delete(key);
932
+ return this;
1042
933
  }
1043
- set(key, value) {
1044
- if (value) {
1045
- this._env.set(key, value);
934
+ defParam(key, str) {
935
+ if (!this._url.searchParams.has(key)) {
936
+ this._url.searchParams.set(key, str);
1046
937
  }
938
+ return this;
1047
939
  }
1048
- delete(key) {
1049
- this._env.delete(key);
940
+ setParam(key, str) {
941
+ this._url.searchParams.set(key, str);
942
+ return this;
1050
943
  }
1051
- };
1052
- _deno = new WeakMap();
1053
- var DenoEnvActions = _DenoEnvActions;
1054
-
1055
- // src/node/node-env-actions.ts
1056
- var once2 = new ResolveOnce();
1057
- var _node;
1058
- var _NodeEnvActions = class _NodeEnvActions {
1059
- constructor(opts) {
1060
- __privateAdd(this, _node, globalThis);
1061
- this._env = this.active() ? __privateGet(this, _node).process.env : {};
1062
- this.opts = opts;
944
+ hasParam(key) {
945
+ return this._url.searchParams.has(key);
1063
946
  }
1064
- static new(opts) {
1065
- return once2.once(() => new _NodeEnvActions(opts));
947
+ get getParams() {
948
+ return this._url.searchParams.entries();
1066
949
  }
1067
- register(env) {
1068
- for (const key of env.keys()) {
1069
- this._env[key] = env.get(key) || "";
950
+ getParam(key, def) {
951
+ const { key: k, def: d } = coerceKey(key, def);
952
+ let val = this._url.searchParams.get(k);
953
+ if (!falsy2undef(val) && d) {
954
+ val = d;
1070
955
  }
1071
- return env;
956
+ return falsy2undef(val);
1072
957
  }
1073
- active() {
1074
- return runtimeFn().isNodeIsh;
958
+ getParamResult(key, msgFn) {
959
+ return getParamResult(key, this.getParam(key), msgFn);
1075
960
  }
1076
- keys() {
1077
- return Object.keys(this._env);
961
+ getParamsResult(...keys) {
962
+ return getParamsResult(keys, this);
1078
963
  }
1079
- get(key) {
1080
- return this._env[key];
964
+ toString() {
965
+ this._url.searchParams.sort();
966
+ return this._url.toString();
1081
967
  }
1082
- set(key, value) {
1083
- if (value) {
1084
- this._env[key] = value;
1085
- }
968
+ toJSON() {
969
+ return this.toString();
1086
970
  }
1087
- delete(key) {
1088
- delete this._env[key];
971
+ asURL() {
972
+ return this.URI().asURL();
1089
973
  }
1090
- };
1091
- _node = new WeakMap();
1092
- var NodeEnvActions = _NodeEnvActions;
1093
-
1094
- // src/web/web-env-actions.ts
1095
- var once3 = new ResolveOnce();
1096
- var BrowserEnvActions = class _BrowserEnvActions {
1097
- constructor(opts) {
1098
- this.env = /* @__PURE__ */ new Map();
1099
- this.opts = opts;
974
+ asObj(...strips) {
975
+ return this.URI().asObj(...strips);
1100
976
  }
1101
- static new(opts) {
1102
- return once3.once(() => new _BrowserEnvActions(opts));
977
+ clone() {
978
+ return _BuildURI.from(this.toString());
1103
979
  }
1104
- get(key) {
1105
- return this.env.get(key);
980
+ URI() {
981
+ return URI.from(this._url);
1106
982
  }
1107
- set(key, value) {
1108
- if (value) {
1109
- this.env.set(key, value);
1110
- }
983
+ };
984
+ function isCoerceURI(value) {
985
+ if (!value) {
986
+ return false;
1111
987
  }
1112
- delete(key) {
1113
- this.env.delete(key);
988
+ if (isURL(value)) {
989
+ return true;
1114
990
  }
1115
- keys() {
1116
- return Array.from(this.env.keys());
991
+ if (URI.is(value)) {
992
+ return true;
1117
993
  }
1118
- active() {
994
+ if (BuildURI.is(value)) {
1119
995
  return true;
1120
996
  }
1121
- register(env) {
1122
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1123
- const browser = globalThis;
1124
- browser[sym] = env;
1125
- return env;
997
+ if (typeof value === "string") {
998
+ return true;
1126
999
  }
1127
- };
1128
-
1129
- // src/cf/cf-env-actions.ts
1130
- var once4 = new ResolveOnce();
1131
- var CFEnvActions = class _CFEnvActions {
1132
- constructor(env) {
1133
- this.injectOnRegister = {};
1134
- this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
1000
+ return false;
1001
+ }
1002
+ var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
1003
+ var URI = class _URI {
1004
+ static protocolHasHostpart(protocol) {
1005
+ protocol = protocol.replace(/:$/, "");
1006
+ hasHostPartProtocols.add(protocol);
1007
+ return () => {
1008
+ hasHostPartProtocols.delete(protocol);
1009
+ };
1135
1010
  }
1136
- static new(opts) {
1137
- return once4.once(() => new _CFEnvActions(opts));
1011
+ match(other) {
1012
+ return match(this, other);
1138
1013
  }
1139
- static inject(o) {
1140
- const env = _CFEnvActions.new({});
1141
- for (const key in o) {
1142
- const value = o[key];
1143
- if (typeof value === "string") {
1144
- if (env.env) {
1145
- env.env.set(key, value);
1146
- } else {
1147
- env.injectOnRegister[key] = value;
1148
- }
1149
- }
1014
+ // if no protocol is provided, default to file:
1015
+ static merge(into, from2, defaultProtocol = "file:") {
1016
+ const intoUrl = BuildURI.from(into, defaultProtocol);
1017
+ const fromUrl = _URI.from(from2, defaultProtocol);
1018
+ intoUrl.protocol(fromUrl.protocol);
1019
+ const fPath = fromUrl.pathname;
1020
+ if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
1021
+ intoUrl.pathname(fromUrl.pathname);
1150
1022
  }
1023
+ for (const [key, value] of fromUrl.getParams) {
1024
+ intoUrl.setParam(key, value);
1025
+ }
1026
+ return intoUrl.URI();
1151
1027
  }
1152
- active() {
1153
- return runtimeFn().isCFWorker;
1028
+ static is(value) {
1029
+ return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
1154
1030
  }
1155
- register(env) {
1156
- this.env = env;
1157
- for (const key in this.injectOnRegister) {
1158
- env.set(key, this.injectOnRegister[key]);
1159
- }
1160
- return env;
1031
+ // if no protocol is provided, default to file:
1032
+ static from(strURLUri, defaultProtocol = "file:") {
1033
+ return from((url) => new _URI(url), strURLUri, defaultProtocol);
1161
1034
  }
1162
- get(key) {
1163
- return this.cfEnv.get(key);
1035
+ static fromResult(strURLUri, defaultProtocol = "file:") {
1036
+ return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
1164
1037
  }
1165
- set(key, value) {
1166
- if (value) {
1167
- this.cfEnv.set(key, value);
1038
+ constructor(url) {
1039
+ this._url = url.clone();
1040
+ }
1041
+ build() {
1042
+ return BuildURI.from(this._url);
1043
+ }
1044
+ get hostname() {
1045
+ return this._url.hostname;
1046
+ }
1047
+ // get password(): string {
1048
+ // return this._url.password;
1049
+ // }
1050
+ get port() {
1051
+ return this._url.port;
1052
+ }
1053
+ get host() {
1054
+ return this._url.host;
1055
+ }
1056
+ // get username(): string {
1057
+ // return this._url.username;
1058
+ // }
1059
+ // get search(): string {
1060
+ // return this._url.search;
1061
+ // }
1062
+ get protocol() {
1063
+ return this._url.protocol;
1064
+ }
1065
+ get pathname() {
1066
+ return this._url.pathname;
1067
+ }
1068
+ // get hash(): string {
1069
+ // return this._url.hash;
1070
+ // }
1071
+ // get host(): string {
1072
+ // return this._url.host;
1073
+ // }
1074
+ get getParams() {
1075
+ return this._url.searchParams.entries();
1076
+ }
1077
+ hasParam(key) {
1078
+ return this._url.searchParams.has(key);
1079
+ }
1080
+ getParam(key, def) {
1081
+ const { key: k, def: d } = coerceKey(key, def);
1082
+ let val = this._url.searchParams.get(k);
1083
+ if (!falsy2undef(val) && d) {
1084
+ val = d;
1168
1085
  }
1086
+ return falsy2undef(val);
1169
1087
  }
1170
- delete(key) {
1171
- this.cfEnv.delete(key);
1088
+ getParamResult(key, msgFn) {
1089
+ return getParamResult(key, this.getParam(key), msgFn);
1172
1090
  }
1173
- keys() {
1174
- return Array.from(this.cfEnv.keys());
1091
+ getParamsResult(...keys) {
1092
+ return getParamsResult(keys, this);
1093
+ }
1094
+ clone() {
1095
+ return new _URI(this._url);
1096
+ }
1097
+ asURL() {
1098
+ return this._url.clone();
1099
+ }
1100
+ toString() {
1101
+ return this._url.toString();
1102
+ }
1103
+ toJSON() {
1104
+ return this.toString();
1105
+ }
1106
+ asObj(...strips) {
1107
+ const pathURI = {
1108
+ style: "path",
1109
+ protocol: this.protocol,
1110
+ pathname: this.pathname,
1111
+ searchParams: Object.fromEntries(this.getParams)
1112
+ };
1113
+ if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
1114
+ return stripper(strips, {
1115
+ ...pathURI,
1116
+ style: "host",
1117
+ hostname: this.hostname,
1118
+ port: this.port
1119
+ });
1120
+ }
1121
+ return stripper(strips, pathURI);
1175
1122
  }
1176
1123
  };
1177
1124
 
1178
- // src/types.ts
1179
- var _Required = class {
1125
+ // src/future.ts
1126
+ var _promise, _resolveFn, _rejectFn;
1127
+ var Future = class {
1180
1128
  constructor() {
1181
- this.type = "REQUIRED";
1129
+ __privateAdd(this, _promise);
1130
+ __privateAdd(this, _resolveFn, () => {
1131
+ throw new Error("This Promise is not working as expected.");
1132
+ });
1133
+ __privateAdd(this, _rejectFn, () => {
1134
+ throw new Error("This Promise is not working as expected.");
1135
+ });
1136
+ __privateSet(this, _promise, new Promise((resolve, reject) => {
1137
+ __privateSet(this, _resolveFn, resolve);
1138
+ __privateSet(this, _rejectFn, reject);
1139
+ }));
1182
1140
  }
1183
- };
1184
- var _Optional = class {
1185
- constructor() {
1186
- this.type = "OPTIONAL";
1141
+ async asPromise() {
1142
+ return __privateGet(this, _promise);
1143
+ }
1144
+ resolve(value) {
1145
+ __privateGet(this, _resolveFn).call(this, value);
1146
+ }
1147
+ reject(reason) {
1148
+ __privateGet(this, _rejectFn).call(this, reason);
1187
1149
  }
1188
1150
  };
1189
- var param = {
1190
- REQUIRED: new _Required(),
1191
- OPTIONAL: new _Optional()
1192
- };
1151
+ _promise = new WeakMap();
1152
+ _resolveFn = new WeakMap();
1153
+ _rejectFn = new WeakMap();
1193
1154
 
1194
- // src/utils/get-params-result.ts
1195
- function getParamsResult(keys, getParam) {
1196
- const keyDef = keys.flat().reduce(
1197
- (acc, i) => {
1198
- if (typeof i === "string") {
1199
- acc.push({ key: i, def: void 0, isOptional: false });
1200
- } else if (typeof i === "object") {
1201
- acc.push(
1202
- ...Object.keys(i).map((k) => ({
1203
- key: k,
1204
- def: typeof i[k] === "string" ? i[k] : void 0,
1205
- isOptional: i[k] === param.OPTIONAL
1206
- }))
1207
- );
1208
- }
1209
- return acc;
1210
- },
1211
- []
1212
- );
1213
- const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
1214
- const msg = keys2.join(",");
1215
- return `missing parameters: ${msg}`;
1216
- });
1217
- const errors = [];
1218
- const result = {};
1219
- for (const kd of keyDef) {
1220
- const val = getParam.getParam(kd.key);
1221
- if (val === void 0) {
1222
- if (typeof kd.def === "string") {
1223
- result[kd.key] = kd.def;
1224
- } else {
1225
- if (!kd.isOptional) {
1226
- errors.push(kd.key);
1227
- }
1228
- }
1229
- } else {
1230
- result[kd.key] = val;
1231
- }
1155
+ // src/lru-map-set.ts
1156
+ var LRUSet = class {
1157
+ constructor(param2 = {}) {
1158
+ this._lruMap = new LRUMap(param2);
1232
1159
  }
1233
- if (errors.length) {
1234
- return Result.Err(msgFn(...errors));
1160
+ setParam(param2 = {}) {
1161
+ this._lruMap.setParam(param2);
1235
1162
  }
1236
- return Result.Ok(result);
1237
- }
1238
-
1239
- // src/sys-env.ts
1240
- var envActions = [
1241
- { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1242
- { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1243
- { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1244
- { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
1245
- ];
1246
- function registerEnvAction(fn) {
1247
- const id = `id-${Math.random()}`;
1248
- envActions.unshift({ id, fn });
1249
- _envFactories.unget(id);
1250
- return () => {
1251
- const index = envActions.findIndex((i) => i.id === id);
1252
- if (index >= 0) {
1253
- envActions.splice(index, 1);
1254
- }
1255
- };
1256
- }
1257
- var _envFactories = new KeyedResolvOnce();
1258
- function envFactory(opts = {}) {
1259
- const found = envActions.find((fi) => fi.fn(opts).active());
1260
- if (!found) {
1261
- throw new Error("SysContainer:envFactory: no env available");
1163
+ get size() {
1164
+ return this._lruMap.size;
1262
1165
  }
1263
- return _envFactories.get(found.id).once(() => {
1264
- const action = found.fn(opts);
1265
- const ret = new EnvImpl(action, opts);
1266
- action.register(ret);
1267
- return ret;
1268
- });
1269
- }
1270
- function isIterable(obj) {
1271
- if (obj == null) {
1272
- return false;
1166
+ has(key) {
1167
+ return this._lruMap.has(key);
1273
1168
  }
1274
- return typeof obj[Symbol.iterator] === "function";
1275
- }
1276
- var EnvImpl = class {
1277
- constructor(map, opts = {}) {
1278
- this._onSet = [];
1279
- this._map = map;
1280
- this._updatePresets(opts.presetEnv);
1169
+ add(key) {
1170
+ this._lruMap.set(key, key);
1281
1171
  }
1282
- gets(...kparams) {
1283
- return getParamsResult(kparams, {
1284
- getParam: (k) => this.get(k)
1285
- });
1172
+ delete(key) {
1173
+ this._lruMap.delete(key);
1286
1174
  }
1287
- sets(...keys) {
1288
- keys.forEach((key) => {
1289
- if (Array.isArray(key)) {
1290
- if (key.length === 2) {
1291
- const [k, v] = key;
1292
- if (typeof k === "string" && typeof v === "string") {
1293
- this.set(k, v);
1294
- return;
1295
- }
1296
- }
1297
- for (const item of key) {
1298
- if (Array.isArray(item)) {
1299
- if (item.length === 2) {
1300
- const [k, v] = item;
1301
- if (typeof k === "string" && typeof v === "string") {
1302
- this.set(k, v);
1303
- }
1304
- }
1175
+ clear() {
1176
+ this._lruMap.clear();
1177
+ }
1178
+ forEach(callbackfn) {
1179
+ this._lruMap.forEach((value) => callbackfn(value, value));
1180
+ }
1181
+ entries() {
1182
+ return this._lruMap.entries();
1183
+ }
1184
+ };
1185
+ var LRUMap = class {
1186
+ constructor(c = {}) {
1187
+ this._map = /* @__PURE__ */ new Map();
1188
+ this.param = {
1189
+ maxEntries: c.maxEntries || 100,
1190
+ maxAge: c.maxAge || 0
1191
+ };
1192
+ }
1193
+ touch(key) {
1194
+ if (!this._map.has(key)) {
1195
+ throw new Error(`key not found in cache: ${key}`);
1196
+ }
1197
+ const value = this._map.get(key);
1198
+ this._map.delete(key);
1199
+ this._map.set(key, value);
1200
+ return value;
1201
+ }
1202
+ setParam(param2 = {}) {
1203
+ if (typeof param2.maxEntries === "number") {
1204
+ this.param.maxEntries = param2.maxEntries;
1205
+ if (param2.maxEntries > 0 && this._map.size > param2.maxEntries) {
1206
+ const toDelete = [];
1207
+ let cacheSize = this._map.size;
1208
+ for (const key of this._map.keys()) {
1209
+ if (cacheSize > param2.maxEntries) {
1210
+ toDelete.push(key);
1211
+ cacheSize--;
1212
+ } else {
1213
+ break;
1305
1214
  }
1306
1215
  }
1307
- } else {
1308
- if (isIterable(key)) {
1309
- for (const [k, v] of key) {
1310
- if (typeof k === "string" && typeof v === "string") {
1311
- this.set(k, v);
1312
- }
1313
- }
1314
- } else {
1315
- const rKey = key;
1316
- for (const k in rKey) {
1317
- const v = rKey[k];
1318
- if (typeof k === "string" && typeof v === "string") {
1319
- this.set(k, v);
1320
- }
1321
- }
1216
+ for (const key of toDelete) {
1217
+ this._map.delete(key);
1322
1218
  }
1323
1219
  }
1324
- });
1325
- }
1326
- _updatePresets(presetEnv) {
1327
- if (!presetEnv) {
1328
- return;
1329
- }
1330
- for (const [key, value] of presetEnv) {
1331
- this._map.set(key, value);
1332
1220
  }
1333
1221
  }
1334
- _applyOnSet(onSet, key, value) {
1335
- onSet.forEach((item) => {
1336
- let keys = [];
1337
- if (key) {
1338
- keys = [key];
1339
- } else {
1340
- keys = this._map.keys();
1341
- }
1342
- keys.filter((k) => {
1343
- if (item.filter.size === 0) {
1344
- return true;
1345
- }
1346
- if (item.filter.has(k)) {
1347
- return true;
1348
- }
1349
- return false;
1350
- }).forEach((k) => {
1351
- let v;
1352
- if (!key && !value) {
1353
- v = this._map.get(k);
1354
- } else if (key && !value) {
1355
- v = void 0;
1356
- } else {
1357
- v = value;
1358
- }
1359
- item.fn(k, v);
1360
- });
1361
- });
1222
+ has(key) {
1223
+ return this._map.has(key);
1362
1224
  }
1363
- keys() {
1364
- return this._map.keys();
1225
+ get size() {
1226
+ return this._map.size;
1365
1227
  }
1366
- // filter is not set all sets passed
1367
- onSet(fn, ...filter) {
1368
- const item = { filter: new Set(filter), fn };
1369
- this._onSet.push(item);
1370
- this._applyOnSet([item]);
1228
+ async getSet(key, createFN) {
1229
+ const val = this.get(key);
1230
+ if (val) {
1231
+ return val;
1232
+ } else {
1233
+ const val2 = await createFN(key);
1234
+ this.set(key, val2);
1235
+ return val2;
1236
+ }
1371
1237
  }
1372
1238
  get(key) {
1239
+ if (this._map.has(key)) {
1240
+ return this.touch(key);
1241
+ }
1373
1242
  return this._map.get(key);
1374
1243
  }
1375
1244
  set(key, value) {
1376
- if (!value) {
1377
- return;
1245
+ this._map.delete(key);
1246
+ if (this.param.maxEntries > 0 && this._map.size >= this.param.maxEntries) {
1247
+ this._map.delete(this._map.keys().next().value);
1248
+ this._map.set(key, value);
1249
+ } else {
1250
+ this._map.set(key, value);
1378
1251
  }
1379
- this._map.set(key, value);
1380
- this._applyOnSet(this._onSet, key, value);
1381
1252
  }
1382
1253
  delete(key) {
1383
1254
  this._map.delete(key);
1384
- this._applyOnSet(this._onSet, key);
1385
- }
1386
- };
1387
-
1388
- // src/utils/coerce-uint8.ts
1389
- var globalBuffer = globalThis;
1390
- function coerceIntoUint8(raw) {
1391
- if (raw instanceof ArrayBuffer) {
1392
- return Result.Ok(new Uint8Array(raw));
1393
- }
1394
- if (ArrayBuffer.isView(raw)) {
1395
- return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
1396
- }
1397
- if (raw instanceof Blob) {
1398
- return Result.Err("Blob not supported");
1399
1255
  }
1400
- if (globalBuffer.Buffer && globalBuffer.Buffer.isBuffer(raw)) {
1401
- return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
1402
- }
1403
- if (raw instanceof Uint8Array) {
1404
- return Result.Ok(raw);
1256
+ clear() {
1257
+ this._map.clear();
1405
1258
  }
1406
- if (Result.Is(raw)) {
1407
- if (raw.isErr()) {
1408
- return Result.Err(raw);
1409
- }
1410
- return coerceIntoUint8(raw.unwrap());
1259
+ forEach(callbackfn) {
1260
+ this._map.forEach(callbackfn);
1411
1261
  }
1412
- return Result.Err("Not a Uint8Array");
1413
- }
1414
- async function asyncCoerceIntoUint8(raw) {
1415
- let resolved = await raw;
1416
- if (resolved instanceof Blob) {
1417
- resolved = await resolved.arrayBuffer();
1262
+ entries() {
1263
+ return this._map.entries();
1418
1264
  }
1419
- return coerceIntoUint8(resolved);
1420
- }
1265
+ // *entries(): IterableIterator<[T, K]> {
1266
+ // for (const x of this._cache.entries()) {
1267
+ // yield x;
1268
+ // }
1269
+ // }
1270
+ // getLeastRecent(): K {
1271
+ // return Array.from(this.cache)[0];
1272
+ // }
1273
+ // getMostRecent(): K {
1274
+ // return Array.from(this.cache)[this.cache.size - 1];
1275
+ // }
1276
+ };
1421
1277
 
1422
- // src/txt-en-decoder.ts
1423
- var TxtOps = class {
1424
- constructor() {
1425
- this.encoder = new TextEncoder();
1426
- this.decoder = new TextDecoder();
1278
+ // src/resolve-once.ts
1279
+ var ResolveSeq = class {
1280
+ constructor(ctx) {
1281
+ this._flushWaiting = [];
1282
+ this._seqFutures = [];
1283
+ this.ctx = ctx;
1427
1284
  }
1428
- encode(str) {
1429
- return this.encoder.encode(str);
1285
+ reset() {
1430
1286
  }
1431
- decode(data) {
1432
- if (Result.Is(data)) {
1433
- if (data.isErr()) {
1434
- throw data.Err();
1435
- }
1436
- const unwrapped = data.unwrap();
1437
- if (typeof unwrapped === "string") {
1438
- return this.decode(unwrapped);
1439
- }
1287
+ flush() {
1288
+ var _a;
1289
+ if (this._seqFutures.length > 0) {
1290
+ const waitForFlush = new Future();
1291
+ (_a = this._flushWaiting) == null ? void 0 : _a.push(waitForFlush);
1292
+ return waitForFlush.asPromise();
1440
1293
  }
1441
- if (typeof data === "string") {
1442
- return data;
1294
+ return Promise.resolve();
1295
+ }
1296
+ _step(item) {
1297
+ var _a;
1298
+ if (!item) {
1299
+ this._flushWaiting.forEach((f) => f.resolve());
1300
+ (_a = this._flushWaiting) == null ? void 0 : _a.splice(0, this._flushWaiting.length);
1301
+ return Promise.resolve();
1443
1302
  }
1444
- return this.decoder.decode(coerceIntoUint8(data).Ok());
1303
+ item.fn(this.ctx).then((value) => item.future.resolve(value)).catch((e) => item.future.reject(e)).finally(() => {
1304
+ this._seqFutures.shift();
1305
+ void this._step(this._seqFutures[0]);
1306
+ });
1307
+ return Promise.resolve();
1445
1308
  }
1446
- async asyncDecode(data) {
1447
- let resolved = await data;
1448
- if (resolved instanceof Blob) {
1449
- resolved = await resolved.arrayBuffer();
1309
+ async add(fn, id) {
1310
+ const future = new Future();
1311
+ this._seqFutures.push({ future, fn, id });
1312
+ if (this._seqFutures.length === 1) {
1313
+ void this._step(this._seqFutures[0]);
1450
1314
  }
1451
- return this.decode(resolved);
1315
+ return future.asPromise();
1452
1316
  }
1453
1317
  };
1454
- var txtEnDecoder;
1455
- function TxtEnDecoderSingleton() {
1456
- txtEnDecoder = txtEnDecoder != null ? txtEnDecoder : new TxtOps();
1457
- return txtEnDecoder;
1458
- }
1459
-
1460
- // src/web/web-sys-abstraction.ts
1461
- var WebFileService = class {
1462
- get baseDir() {
1463
- throw new Error("basedir-Method not implemented.");
1464
- }
1465
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1466
- create(fname) {
1467
- throw new Error("create-Method not implemented.");
1318
+ var ResolveOnce = class {
1319
+ constructor(ctx) {
1320
+ this._onceDone = false;
1321
+ this._onceFutures = [];
1322
+ this._onceOk = false;
1323
+ this._isPromise = false;
1324
+ this.ctx = ctx;
1468
1325
  }
1469
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1470
- readFileString(fname) {
1471
- throw new Error("readFileString-Method not implemented.");
1326
+ get ready() {
1327
+ return this._onceDone;
1472
1328
  }
1473
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1474
- writeFileString(fname, content) {
1475
- throw new Error("writeFileString-Method not implemented.");
1329
+ reset() {
1330
+ this._onceDone = false;
1331
+ this._onceOk = false;
1332
+ this._onceValue = void 0;
1333
+ this._onceError = void 0;
1334
+ if (this._inProgress) {
1335
+ const idx = this._onceFutures.findIndex((f) => f === this._inProgress);
1336
+ if (idx >= 0) {
1337
+ this._onceFutures.push(...this._onceFutures.splice(2).slice(1));
1338
+ }
1339
+ } else {
1340
+ this._onceFutures.length = 0;
1341
+ }
1476
1342
  }
1477
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1478
- abs(fname) {
1479
- throw new Error("abs-Method not implemented.");
1343
+ // T extends Option<infer U> ? U : T
1344
+ once(fn) {
1345
+ if (this._onceDone) {
1346
+ if (this._onceError) {
1347
+ if (this._isPromise) {
1348
+ return Promise.reject(this._onceError);
1349
+ } else {
1350
+ throw this._onceError;
1351
+ }
1352
+ }
1353
+ if (this._onceOk) {
1354
+ if (this._isPromise) {
1355
+ return Promise.resolve(this._onceValue);
1356
+ } else {
1357
+ return this._onceValue;
1358
+ }
1359
+ }
1360
+ throw new Error("ResolveOnce.once impossible");
1361
+ }
1362
+ const future = new Future();
1363
+ this._onceFutures.push(future);
1364
+ if (this._onceFutures.length === 1) {
1365
+ const okFn = (value) => {
1366
+ this._onceValue = value;
1367
+ this._onceOk = true;
1368
+ this._onceDone = true;
1369
+ if (this._isPromise) {
1370
+ this._onceFutures.forEach((f) => f.resolve(this._onceValue));
1371
+ }
1372
+ this._onceFutures.length = 0;
1373
+ };
1374
+ const catchFn = (e) => {
1375
+ this._onceError = e;
1376
+ this._onceOk = false;
1377
+ this._onceValue = void 0;
1378
+ this._onceDone = true;
1379
+ if (this._isPromise) {
1380
+ this._onceFutures.forEach((f) => f.reject(this._onceError));
1381
+ }
1382
+ this._onceFutures.length = 0;
1383
+ };
1384
+ this._inProgress = future;
1385
+ try {
1386
+ const ret = fn(this.ctx);
1387
+ if (typeof ret.then === "function") {
1388
+ this._isPromise = true;
1389
+ ret.then(okFn).catch(catchFn).finally(() => {
1390
+ this._inProgress = void 0;
1391
+ });
1392
+ } else {
1393
+ okFn(ret);
1394
+ }
1395
+ } catch (e) {
1396
+ catchFn(e);
1397
+ }
1398
+ if (!this._isPromise) {
1399
+ this._inProgress = void 0;
1400
+ }
1401
+ }
1402
+ if (this._isPromise) {
1403
+ return future.asPromise();
1404
+ } else {
1405
+ return this.once(fn);
1406
+ }
1480
1407
  }
1481
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1482
- join(...paths) {
1483
- throw new Error("join-Method not implemented.");
1408
+ };
1409
+ var Keyed = class {
1410
+ constructor(factory, params) {
1411
+ var _a;
1412
+ this.factory = factory;
1413
+ this._map = new LRUMap((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
1484
1414
  }
1485
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1486
- relative(from2, to) {
1487
- throw new Error("relative-Method not implemented.");
1415
+ setParam(params) {
1416
+ this._map.setParam(params.lru);
1488
1417
  }
1489
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1490
- dirname(fname) {
1491
- throw new Error("dirname-Method not implemented.");
1418
+ async asyncGet(key) {
1419
+ return this.get(await key());
1492
1420
  }
1493
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1494
- basename(fname) {
1495
- throw new Error("basename-Method not implemented.");
1421
+ get(key) {
1422
+ if (typeof key === "function") {
1423
+ key = key();
1424
+ }
1425
+ let keyed = this._map.get(key);
1426
+ if (!keyed) {
1427
+ keyed = this.factory(key);
1428
+ this._map.set(key, keyed);
1429
+ }
1430
+ return keyed;
1496
1431
  }
1497
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1498
- nodeImport(fname) {
1499
- throw new Error("nodeImport-Method not implemented.");
1432
+ unget(key) {
1433
+ const keyed = this._map.get(key);
1434
+ keyed == null ? void 0 : keyed.reset();
1435
+ this._map.delete(key);
1500
1436
  }
1501
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1502
- isAbsolute(fname) {
1503
- throw new Error("isAbsolute-Method not implemented.");
1437
+ reset() {
1438
+ this._map.forEach((keyed) => keyed.reset());
1439
+ this._map.clear();
1504
1440
  }
1505
1441
  };
1506
- var WebSystemService = class {
1507
- Env() {
1508
- return envFactory();
1509
- }
1510
- Args() {
1511
- throw new Error("Args-Method not implemented.");
1512
- }
1513
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1514
- OnExit(hdl) {
1515
- throw new Error("OnExit-Method not implemented.");
1442
+ var KeyedResolvOnce = class extends Keyed {
1443
+ constructor(kp = {}) {
1444
+ super((key) => new ResolveOnce(key), kp);
1516
1445
  }
1517
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1518
- Exit(code) {
1519
- throw new Error("Exit-Method not implemented.");
1446
+ /**
1447
+ *
1448
+ * @returns The values of the resolved keys
1449
+ */
1450
+ values() {
1451
+ return Array.from(this._map.entries()).filter(([_, v]) => v._onceDone).map(([k, v]) => {
1452
+ if (v._onceDone) {
1453
+ if (v._onceError) {
1454
+ return {
1455
+ key: k,
1456
+ value: Result.Err(v._onceError)
1457
+ };
1458
+ }
1459
+ return {
1460
+ key: k,
1461
+ value: Result.Ok(v._onceValue)
1462
+ };
1463
+ }
1464
+ throw new Error("KeyedResolvOnce.values impossible");
1465
+ });
1520
1466
  }
1521
1467
  };
1522
- var my = void 0;
1523
- function WebSysAbstraction(param2) {
1524
- if (!my) {
1525
- my = new BaseSysAbstraction({
1526
- TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton(),
1527
- FileSystem: new WebFileService(),
1528
- SystemService: new WebSystemService()
1529
- });
1468
+ var KeyedResolvSeq = class extends Keyed {
1469
+ constructor(kp = {}) {
1470
+ super((key) => new ResolveSeq(key), kp);
1530
1471
  }
1531
- return new WrapperSysAbstraction(my, param2);
1532
- }
1533
-
1534
- // src/utils/relative-path.ts
1535
- var PartType = {
1536
- Slash: 1,
1537
- Root: 3,
1538
- Up: 4,
1539
- Noop: 8
1540
- // RootUp = 0x8 /* ../ */,
1541
1472
  };
1542
- var Path = class {
1543
- constructor(parts = []) {
1544
- this.parts = parts;
1473
+
1474
+ // src/utils/coerce-uint8.ts
1475
+ var globalBuffer = globalThis;
1476
+ function coerceIntoUint8(raw) {
1477
+ if (raw instanceof ArrayBuffer) {
1478
+ return Result.Ok(new Uint8Array(raw));
1545
1479
  }
1546
- toString() {
1547
- return this.parts.map((part) => {
1548
- if (typeof part === "string") {
1549
- return part;
1550
- } else {
1551
- switch (part) {
1552
- case PartType.Slash:
1553
- case PartType.Root:
1554
- return "/";
1555
- case PartType.Up:
1556
- return "..";
1557
- default:
1558
- return part;
1559
- }
1560
- }
1561
- }).join("");
1480
+ if (ArrayBuffer.isView(raw)) {
1481
+ return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
1562
1482
  }
1563
- add(part) {
1564
- if (this.parts.includes(PartType.Root) && part === PartType.Root) {
1565
- throw new Error("Cannot add absolute part to absolute path");
1566
- }
1567
- const last = this.parts[this.parts.length - 1];
1568
- if (last & PartType.Slash && part === PartType.Slash) {
1569
- return;
1570
- }
1571
- switch (part) {
1572
- case ".":
1573
- this.parts.push(PartType.Noop);
1574
- return;
1575
- case "..":
1576
- part = PartType.Up;
1577
- }
1578
- if (last === PartType.Noop && part === PartType.Slash) {
1579
- if (last === PartType.Noop) {
1580
- this.parts.pop();
1581
- }
1582
- return;
1583
- }
1584
- this.parts.push(part);
1483
+ if (raw instanceof Blob) {
1484
+ return Result.Err("Blob not supported");
1585
1485
  }
1586
- };
1587
- function splitPath(path) {
1588
- const p = new Path();
1589
- if (path === "") {
1590
- return p;
1486
+ if (globalBuffer.Buffer && globalBuffer.Buffer.isBuffer(raw)) {
1487
+ return Result.Ok(new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength));
1591
1488
  }
1592
- for (let count = 0; path.length; count++) {
1593
- if (path.match(/^\/+/)) {
1594
- if (count === 0) {
1595
- p.add(PartType.Root);
1596
- } else {
1597
- p.add(PartType.Slash);
1598
- }
1599
- path = path.replace(/^\/+/, "");
1600
- } else {
1601
- const part = path.replace(/\/.*$/, "");
1602
- p.add(part);
1603
- path = path.replace(/^[^/]+/, "");
1489
+ if (raw instanceof Uint8Array) {
1490
+ return Result.Ok(raw);
1491
+ }
1492
+ if (Result.Is(raw)) {
1493
+ if (raw.isErr()) {
1494
+ return Result.Err(raw);
1604
1495
  }
1496
+ return coerceIntoUint8(raw.unwrap());
1605
1497
  }
1606
- return p;
1498
+ return Result.Err("Not a Uint8Array");
1607
1499
  }
1608
- function pathJoin(...paths) {
1609
- let prev = "";
1610
- const res = [];
1611
- for (let i = 0; i < paths.length; i++) {
1612
- const path = paths[i];
1613
- if (path === "") {
1614
- continue;
1615
- }
1616
- if (!(prev.endsWith("/") || path.startsWith("/"))) {
1617
- if (prev !== "") {
1618
- res.push("/");
1500
+ async function asyncCoerceIntoUint8(raw) {
1501
+ let resolved = await raw;
1502
+ if (resolved instanceof Blob) {
1503
+ resolved = await resolved.arrayBuffer();
1504
+ }
1505
+ return coerceIntoUint8(resolved);
1506
+ }
1507
+
1508
+ // src/txt-en-decoder.ts
1509
+ var TxtOps = class {
1510
+ constructor() {
1511
+ this.encoder = new TextEncoder();
1512
+ this.decoder = new TextDecoder();
1513
+ }
1514
+ encode(str) {
1515
+ return this.encoder.encode(str);
1516
+ }
1517
+ decode(data) {
1518
+ if (Result.Is(data)) {
1519
+ if (data.isErr()) {
1520
+ throw data.Err();
1521
+ }
1522
+ const unwrapped = data.unwrap();
1523
+ if (typeof unwrapped === "string") {
1524
+ return this.decode(unwrapped);
1619
1525
  }
1620
- res.push(path);
1621
- } else {
1622
- res.push(path);
1623
1526
  }
1624
- prev = path;
1527
+ if (typeof data === "string") {
1528
+ return data;
1529
+ }
1530
+ return this.decoder.decode(coerceIntoUint8(data).Ok());
1625
1531
  }
1626
- return res.join("");
1532
+ async asyncDecode(data) {
1533
+ let resolved = await data;
1534
+ if (resolved instanceof Blob) {
1535
+ resolved = await resolved.arrayBuffer();
1536
+ }
1537
+ return this.decode(resolved);
1538
+ }
1539
+ };
1540
+ var txtEnDecoder = new ResolveOnce();
1541
+ function TxtEnDecoderSingleton() {
1542
+ return txtEnDecoder.once(() => new TxtOps());
1627
1543
  }
1628
- function relativePath(path, relative) {
1629
- const relativeParts = splitPath(relative);
1630
- let result;
1631
- if (relativeParts.parts[0] === PartType.Root) {
1632
- result = relative;
1633
- } else {
1634
- result = pathJoin(path, relative);
1544
+
1545
+ // src/option.ts
1546
+ var Option = class _Option {
1547
+ static Some(t) {
1548
+ return new Some(t);
1635
1549
  }
1636
- const unoptPath = splitPath(result);
1637
- const out = [];
1638
- let topUp = false;
1639
- for (const part of unoptPath.parts) {
1640
- switch (part) {
1641
- case PartType.Root:
1642
- out.push(PartType.Root);
1643
- break;
1644
- case PartType.Up:
1645
- if (out.length && !topUp) {
1646
- const last = out.length - 1;
1647
- if (typeof out[last] === "string" && out[last - 1] == PartType.Root) {
1648
- out.pop();
1649
- } else {
1650
- out.pop();
1651
- out.pop();
1652
- }
1653
- if (out.length === 0) {
1654
- topUp = !topUp ? true : topUp;
1655
- out.push(PartType.Up);
1656
- }
1657
- } else {
1658
- out.push(PartType.Up);
1659
- }
1660
- break;
1661
- case PartType.Slash:
1662
- if (!(out[out.length - 1] & PartType.Slash)) {
1663
- out.push(PartType.Slash);
1664
- }
1665
- break;
1666
- default:
1667
- out.push(part);
1668
- break;
1550
+ static None() {
1551
+ return new None();
1552
+ }
1553
+ static Is(t) {
1554
+ return t instanceof _Option;
1555
+ }
1556
+ static From(t) {
1557
+ if (!t) {
1558
+ return new None();
1669
1559
  }
1560
+ return new Some(t);
1670
1561
  }
1671
- return new Path(out).toString();
1672
- }
1562
+ IsNone() {
1563
+ return this.is_none();
1564
+ }
1565
+ IsSome() {
1566
+ return this.is_some();
1567
+ }
1568
+ Unwrap() {
1569
+ return this.unwrap();
1570
+ }
1571
+ };
1572
+ var Some = class extends Option {
1573
+ constructor(_t) {
1574
+ super();
1575
+ this._t = _t;
1576
+ }
1577
+ is_none() {
1578
+ return false;
1579
+ }
1580
+ is_some() {
1581
+ return true;
1582
+ }
1583
+ unwrap() {
1584
+ return this._t;
1585
+ }
1586
+ };
1587
+ var None = class extends Option {
1588
+ is_none() {
1589
+ return true;
1590
+ }
1591
+ is_some() {
1592
+ return false;
1593
+ }
1594
+ unwrap() {
1595
+ throw new Error("None.unwrap");
1596
+ }
1597
+ };
1673
1598
 
1674
- // src/utils/stripper.ts
1675
- function stripper(strip, obj) {
1676
- const strips = Array.isArray(strip) ? strip : [strip];
1677
- const restrips = strips.map((s) => {
1678
- if (typeof s === "string") {
1679
- const escaped = s.replace(/[-\\[\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g, "\\$&");
1680
- return new RegExp(`^${escaped}$`);
1599
+ // src/log-level-impl.ts
1600
+ var LevelHandlerImpl = class {
1601
+ constructor() {
1602
+ this._globalLevels = /* @__PURE__ */ new Set([Level.INFO, Level.ERROR, Level.WARN]);
1603
+ this._modules = /* @__PURE__ */ new Map();
1604
+ this.ignoreAttr = Option.Some(/^_/);
1605
+ this.isStackExposed = false;
1606
+ }
1607
+ enableLevel(level, ...modules) {
1608
+ if (modules.length == 0) {
1609
+ this._globalLevels.add(level);
1610
+ return;
1681
1611
  }
1682
- return s;
1683
- });
1684
- return localStripper(void 0, restrips, obj);
1685
- }
1686
- function localStripper(path, restrips, obj) {
1687
- if (typeof obj !== "object" || obj === null) {
1688
- return obj;
1612
+ this.forModules(
1613
+ level,
1614
+ (p) => {
1615
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, level]));
1616
+ },
1617
+ ...modules
1618
+ );
1689
1619
  }
1690
- if (Array.isArray(obj)) {
1691
- return obj.map((i) => localStripper(path, restrips, i));
1620
+ disableLevel(level, ...modules) {
1621
+ if (modules.length == 0) {
1622
+ this._globalLevels.delete(level);
1623
+ return;
1624
+ }
1625
+ this.forModules(
1626
+ level,
1627
+ (p) => {
1628
+ this._modules.delete(p);
1629
+ },
1630
+ ...modules
1631
+ );
1692
1632
  }
1693
- const ret = { ...obj };
1694
- const matcher = (key, nextPath) => {
1695
- for (const re of restrips) {
1696
- if (re.test(key) || re.test(nextPath)) {
1697
- return true;
1633
+ setExposeStack(enable) {
1634
+ this.isStackExposed = !!enable;
1635
+ }
1636
+ setIgnoreAttr(re) {
1637
+ this.ignoreAttr = Option.From(re);
1638
+ }
1639
+ forModules(level, fnAction, ...modules) {
1640
+ for (const m of modules.flat()) {
1641
+ if (typeof m !== "string") {
1642
+ continue;
1698
1643
  }
1699
- }
1700
- return false;
1701
- };
1702
- for (const key in ret) {
1703
- if (Object.prototype.hasOwnProperty.call(ret, key)) {
1704
- let nextPath;
1705
- if (path) {
1706
- nextPath = [path, key].join(".");
1707
- } else {
1708
- nextPath = key;
1644
+ const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
1645
+ for (const p of parts) {
1646
+ fnAction(p);
1709
1647
  }
1710
- if (matcher(key, nextPath)) {
1711
- delete ret[key];
1712
- continue;
1648
+ }
1649
+ }
1650
+ setDebug(...modules) {
1651
+ this.forModules(
1652
+ Level.DEBUG,
1653
+ (p) => {
1654
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, Level.DEBUG]));
1655
+ },
1656
+ ...modules
1657
+ );
1658
+ }
1659
+ isEnabled(ilevel, module2) {
1660
+ const level = ilevel;
1661
+ if (typeof module2 === "string") {
1662
+ const levels = this._modules.get(module2);
1663
+ if (levels && levels.has(level)) {
1664
+ return true;
1713
1665
  }
1714
- if (typeof ret[key] === "object") {
1715
- if (Array.isArray(ret[key])) {
1716
- ret[key] = ret[key].reduce((acc, v, i) => {
1717
- const toDelete = matcher(key, `${nextPath}[${i}]`);
1718
- if (!toDelete) {
1719
- acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
1720
- }
1721
- return acc;
1722
- }, []);
1723
- } else {
1724
- ret[key] = localStripper(nextPath, restrips, ret[key]);
1725
- }
1666
+ }
1667
+ const wlevel = this._modules.get("*");
1668
+ if (wlevel && typeof level === "string") {
1669
+ if (wlevel.has(level)) {
1670
+ return true;
1726
1671
  }
1727
1672
  }
1673
+ if (typeof level !== "string") {
1674
+ return true;
1675
+ }
1676
+ return this._globalLevels.has(level);
1728
1677
  }
1729
- return ret;
1678
+ };
1679
+ var levelSingleton = new LevelHandlerImpl();
1680
+ function LevelHandlerSingleton() {
1681
+ return levelSingleton;
1730
1682
  }
1731
1683
 
1732
- // src/uri.ts
1733
- function match(iref, ioth) {
1734
- const mr = {
1735
- score: 0,
1736
- protocol: false,
1737
- hostname: false,
1738
- port: false,
1739
- pathname: false,
1740
- pathParts: [],
1741
- params: {}
1684
+ // src/runtime.ts
1685
+ function isSet(value, ref = globalThis) {
1686
+ const [head, ...tail] = value.split(".");
1687
+ if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
1688
+ if (tail.length <= 1) {
1689
+ return true;
1690
+ }
1691
+ return isSet(tail.join("."), ref[head]);
1692
+ }
1693
+ return false;
1694
+ }
1695
+ function runtimeFn() {
1696
+ const gt = globalThis;
1697
+ let isReactNative = (
1698
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1699
+ isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative"
1700
+ );
1701
+ let isNodeIsh = false;
1702
+ if (!isSet("Deno")) {
1703
+ isNodeIsh = isSet("process.versions.node") && !isReactNative;
1704
+ }
1705
+ let isDeno = isSet("Deno");
1706
+ const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
1707
+ if (isCFWorker) {
1708
+ isDeno = false;
1709
+ isNodeIsh = false;
1710
+ isReactNative = false;
1711
+ }
1712
+ return {
1713
+ isNodeIsh,
1714
+ isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1715
+ isDeno,
1716
+ isReactNative,
1717
+ isCFWorker
1742
1718
  };
1743
- const ref = URI.from(iref);
1744
- const oth = URI.from(ioth);
1745
- if (ref.protocol === oth.protocol) {
1746
- mr.score += 1;
1747
- mr.protocol = true;
1719
+ }
1720
+
1721
+ // src/sys-abstraction.ts
1722
+ var TimeMode = {
1723
+ REAL: "real",
1724
+ CONST: "const",
1725
+ STEP: "step"
1726
+ };
1727
+ var RandomMode = {
1728
+ CONST: "const",
1729
+ STEP: "step",
1730
+ RANDOM: "random"
1731
+ };
1732
+ var IDMode = {
1733
+ UUID: "uuid",
1734
+ CONST: "const",
1735
+ STEP: "step"
1736
+ };
1737
+ function String2TimeMode(s) {
1738
+ switch (s == null ? void 0 : s.toLowerCase()) {
1739
+ case "real":
1740
+ return TimeMode.REAL;
1741
+ case "const":
1742
+ return TimeMode.CONST;
1743
+ case "step":
1744
+ return TimeMode.STEP;
1745
+ default:
1746
+ return TimeMode.REAL;
1748
1747
  }
1749
- try {
1750
- const refH = ref.hostname;
1751
- const refP = ref.port;
1752
- if (refH === oth.hostname) {
1753
- mr.score += 1;
1754
- mr.hostname = true;
1748
+ }
1749
+
1750
+ // src/time.ts
1751
+ var Time = class {
1752
+ TimeSince(start) {
1753
+ const now = this.Now();
1754
+ return now.getTime() - start.getTime();
1755
+ }
1756
+ };
1757
+ var TimeUnits = {
1758
+ Microsecond: 1,
1759
+ Second: 1e3 * 1,
1760
+ //Microsecond,
1761
+ Minute: 60 * 1e3 * 1,
1762
+ //Second,
1763
+ Hour: 60 * 60 * 1e3 * 1
1764
+ // Minute,
1765
+ };
1766
+
1767
+ // src/deno/deno-env-actions.ts
1768
+ var once = new ResolveOnce();
1769
+ var _deno;
1770
+ var _DenoEnvActions = class _DenoEnvActions {
1771
+ constructor(opts) {
1772
+ __privateAdd(this, _deno, globalThis);
1773
+ this.opts = opts;
1774
+ }
1775
+ static new(opts) {
1776
+ return once.once(() => new _DenoEnvActions(opts));
1777
+ }
1778
+ get _env() {
1779
+ return __privateGet(this, _deno).Deno.env;
1780
+ }
1781
+ register(env) {
1782
+ for (const key of env.keys()) {
1783
+ this._env.set(key, env.get(key) || "");
1755
1784
  }
1756
- if (refP.length && refP === oth.port) {
1757
- mr.score += 1;
1758
- mr.port = true;
1785
+ return env;
1786
+ }
1787
+ active() {
1788
+ return runtimeFn().isDeno;
1789
+ }
1790
+ keys() {
1791
+ return Object.keys(this._env.toObject());
1792
+ }
1793
+ get(key) {
1794
+ return this._env.get(key);
1795
+ }
1796
+ set(key, value) {
1797
+ if (value) {
1798
+ this._env.set(key, value);
1759
1799
  }
1760
- } catch (e) {
1761
1800
  }
1762
- if (ref.pathname.length && ref.pathname !== "/") {
1763
- const pref = ref.pathname.split("/").filter((p) => p.length);
1764
- const poth = oth.pathname.split("/").filter((p) => p.length);
1765
- for (let i = 0; i < pref.length && i < poth.length; i++) {
1766
- if (poth[i] === pref[i]) {
1767
- mr.score += 1;
1768
- mr.pathname = true;
1769
- mr.pathParts.push(pref[i]);
1770
- }
1801
+ delete(key) {
1802
+ this._env.delete(key);
1803
+ }
1804
+ };
1805
+ _deno = new WeakMap();
1806
+ var DenoEnvActions = _DenoEnvActions;
1807
+
1808
+ // src/node/node-env-actions.ts
1809
+ var once2 = new ResolveOnce();
1810
+ var _node;
1811
+ var _NodeEnvActions = class _NodeEnvActions {
1812
+ constructor(opts) {
1813
+ __privateAdd(this, _node, globalThis);
1814
+ this._env = this.active() ? __privateGet(this, _node).process.env : {};
1815
+ this.opts = opts;
1816
+ }
1817
+ static new(opts) {
1818
+ return once2.once(() => new _NodeEnvActions(opts));
1819
+ }
1820
+ register(env) {
1821
+ for (const key of env.keys()) {
1822
+ this._env[key] = env.get(key) || "";
1771
1823
  }
1824
+ return env;
1772
1825
  }
1773
- for (const [key, value] of ref.getParams) {
1774
- if (oth.getParam(key) === value) {
1775
- mr.score += 1;
1776
- mr.params[key] = value;
1777
- }
1826
+ active() {
1827
+ return runtimeFn().isNodeIsh;
1778
1828
  }
1779
- return mr;
1780
- }
1781
- function coerceKey(key, def) {
1782
- if (typeof key === "object") {
1783
- const keys = Object.keys(key);
1784
- if (keys.length !== 1) {
1785
- throw new Error(`Invalid key: ${JSON.stringify(key)}`);
1786
- }
1787
- return { key: keys[0], def: key[keys[0]] };
1829
+ keys() {
1830
+ return Object.keys(this._env);
1788
1831
  }
1789
- return { key, def };
1790
- }
1791
- function falsy2undef(value) {
1792
- return value === void 0 || value === null ? void 0 : value;
1793
- }
1794
- function ensureURLWithDefaultProto(url, defaultProtocol) {
1795
- if (!url) {
1796
- return new MutableURL(`${defaultProtocol}//`);
1832
+ get(key) {
1833
+ return this._env[key];
1797
1834
  }
1798
- if (typeof url === "string") {
1799
- try {
1800
- return new MutableURL(url);
1801
- } catch (e) {
1802
- return new MutableURL(`${defaultProtocol}//${url}`);
1835
+ set(key, value) {
1836
+ if (value) {
1837
+ this._env[key] = value;
1803
1838
  }
1804
- } else {
1805
- return new MutableURL(url.toString());
1806
1839
  }
1807
- }
1808
- function isURL(value) {
1809
- return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
1810
- }
1811
- var MutableURL = class _MutableURL extends URL {
1812
- constructor(urlStr) {
1813
- super("defect://does.not.exist");
1814
- const partedURL = urlStr.split(":");
1815
- this._hasHostpart = hasHostPartProtocols.has(partedURL[0]);
1816
- let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
1817
- if (!this._hasHostpart) {
1818
- const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
1819
- hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
1820
- }
1821
- try {
1822
- this._sysURL = new URL(hostPartUrl);
1823
- } catch (ie) {
1824
- const e = ie;
1825
- e.message = `${e.message} for URL: ${urlStr}`;
1826
- throw e;
1827
- }
1828
- this._protocol = `${partedURL[0]}:`;
1829
- if (this._hasHostpart) {
1830
- this._pathname = this._sysURL.pathname;
1831
- } else {
1832
- this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
1833
- }
1834
- this.hash = this._sysURL.hash;
1840
+ delete(key) {
1841
+ delete this._env[key];
1835
1842
  }
1836
- clone() {
1837
- return new _MutableURL(this.toString());
1843
+ };
1844
+ _node = new WeakMap();
1845
+ var NodeEnvActions = _NodeEnvActions;
1846
+
1847
+ // src/web/web-env-actions.ts
1848
+ var once3 = new ResolveOnce();
1849
+ var BrowserEnvActions = class _BrowserEnvActions {
1850
+ constructor(opts) {
1851
+ this.env = /* @__PURE__ */ new Map();
1852
+ this.opts = opts;
1838
1853
  }
1839
- get host() {
1840
- if (!this._hasHostpart) {
1841
- throw new Error(
1842
- `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
1843
- );
1844
- }
1845
- return this._sysURL.host;
1854
+ static new(opts) {
1855
+ return once3.once(() => new _BrowserEnvActions(opts));
1846
1856
  }
1847
- get port() {
1848
- if (!this._hasHostpart) {
1849
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1850
- }
1851
- return this._sysURL.port;
1857
+ get(key) {
1858
+ return this.env.get(key);
1852
1859
  }
1853
- set port(p) {
1854
- if (!this._hasHostpart) {
1855
- throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1860
+ set(key, value) {
1861
+ if (value) {
1862
+ this.env.set(key, value);
1856
1863
  }
1857
- this._sysURL.port = p;
1858
1864
  }
1859
- get hostname() {
1860
- if (!this._hasHostpart) {
1861
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1865
+ delete(key) {
1866
+ this.env.delete(key);
1867
+ }
1868
+ keys() {
1869
+ return Array.from(this.env.keys());
1870
+ }
1871
+ active() {
1872
+ return true;
1873
+ }
1874
+ register(env) {
1875
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1876
+ const browser = globalThis;
1877
+ browser[sym] = env;
1878
+ return env;
1879
+ }
1880
+ };
1881
+
1882
+ // src/cf/cf-env-actions.ts
1883
+ var once4 = new ResolveOnce();
1884
+ var CFEnvActions = class _CFEnvActions {
1885
+ constructor(env) {
1886
+ this.injectOnRegister = {};
1887
+ this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
1888
+ }
1889
+ static new(opts) {
1890
+ return once4.once(() => new _CFEnvActions(opts));
1891
+ }
1892
+ static inject(o) {
1893
+ const env = _CFEnvActions.new({});
1894
+ for (const key in o) {
1895
+ const value = o[key];
1896
+ if (typeof value === "string") {
1897
+ if (env.env) {
1898
+ env.env.set(key, value);
1899
+ } else {
1900
+ env.injectOnRegister[key] = value;
1901
+ }
1902
+ }
1862
1903
  }
1863
- return this._sysURL.hostname;
1864
1904
  }
1865
- set hostname(h) {
1866
- if (!this._hasHostpart) {
1867
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1905
+ active() {
1906
+ return runtimeFn().isCFWorker;
1907
+ }
1908
+ register(env) {
1909
+ this.env = env;
1910
+ for (const key in this.injectOnRegister) {
1911
+ env.set(key, this.injectOnRegister[key]);
1868
1912
  }
1869
- this._sysURL.hostname = h;
1913
+ return env;
1870
1914
  }
1871
- set pathname(p) {
1872
- this._pathname = p;
1915
+ get(key) {
1916
+ return this.cfEnv.get(key);
1873
1917
  }
1874
- get pathname() {
1875
- return this._pathname;
1918
+ set(key, value) {
1919
+ if (value) {
1920
+ this.cfEnv.set(key, value);
1921
+ }
1876
1922
  }
1877
- get protocol() {
1878
- return this._protocol;
1923
+ delete(key) {
1924
+ this.cfEnv.delete(key);
1879
1925
  }
1880
- set protocol(p) {
1881
- if (!p.endsWith(":")) {
1882
- p = `${p}:`;
1926
+ keys() {
1927
+ return Array.from(this.cfEnv.keys());
1928
+ }
1929
+ };
1930
+
1931
+ // src/sys-env.ts
1932
+ var envActions = [
1933
+ { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1934
+ { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1935
+ { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1936
+ { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
1937
+ ];
1938
+ function registerEnvAction(fn) {
1939
+ const id = `id-${Math.random()}`;
1940
+ envActions.unshift({ id, fn });
1941
+ _envFactories.unget(id);
1942
+ return () => {
1943
+ const index = envActions.findIndex((i) => i.id === id);
1944
+ if (index >= 0) {
1945
+ envActions.splice(index, 1);
1883
1946
  }
1884
- this._protocol = p;
1947
+ };
1948
+ }
1949
+ var _envFactories = new KeyedResolvOnce();
1950
+ function envFactory(opts = {}) {
1951
+ const found = envActions.find((fi) => fi.fn(opts).active());
1952
+ if (!found) {
1953
+ throw new Error("SysContainer:envFactory: no env available");
1885
1954
  }
1886
- get searchParams() {
1887
- return this._sysURL.searchParams;
1955
+ return _envFactories.get(found.id).once(() => {
1956
+ const action = found.fn(opts);
1957
+ const ret = new EnvImpl(action, opts);
1958
+ action.register(ret);
1959
+ return ret;
1960
+ });
1961
+ }
1962
+ function isIterable(obj) {
1963
+ if (obj == null) {
1964
+ return false;
1888
1965
  }
1889
- toString() {
1890
- let search = "";
1891
- if (this._sysURL.searchParams.size) {
1892
- for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
1893
- search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
1966
+ return typeof obj[Symbol.iterator] === "function";
1967
+ }
1968
+ var EnvImpl = class {
1969
+ constructor(map, opts = {}) {
1970
+ this._onSet = [];
1971
+ this._map = map;
1972
+ this._updatePresets(opts.presetEnv);
1973
+ }
1974
+ gets(...kparams) {
1975
+ return getParamsResult(kparams, {
1976
+ getParam: (k) => this.get(k)
1977
+ });
1978
+ }
1979
+ sets(...keys) {
1980
+ keys.forEach((key) => {
1981
+ if (Array.isArray(key)) {
1982
+ if (key.length === 2) {
1983
+ const [k, v] = key;
1984
+ if (typeof k === "string" && typeof v === "string") {
1985
+ this.set(k, v);
1986
+ return;
1987
+ }
1988
+ }
1989
+ for (const item of key) {
1990
+ if (Array.isArray(item)) {
1991
+ if (item.length === 2) {
1992
+ const [k, v] = item;
1993
+ if (typeof k === "string" && typeof v === "string") {
1994
+ this.set(k, v);
1995
+ }
1996
+ }
1997
+ }
1998
+ }
1999
+ } else {
2000
+ if (isIterable(key)) {
2001
+ for (const [k, v] of key) {
2002
+ if (typeof k === "string" && typeof v === "string") {
2003
+ this.set(k, v);
2004
+ }
2005
+ }
2006
+ } else {
2007
+ const rKey = key;
2008
+ for (const k in rKey) {
2009
+ const v = rKey[k];
2010
+ if (typeof k === "string" && typeof v === "string") {
2011
+ this.set(k, v);
2012
+ }
2013
+ }
2014
+ }
1894
2015
  }
2016
+ });
2017
+ }
2018
+ _updatePresets(presetEnv) {
2019
+ if (!presetEnv) {
2020
+ return;
1895
2021
  }
1896
- let hostpart = "";
1897
- if (this._hasHostpart) {
1898
- hostpart = this._sysURL.hostname;
1899
- if (this._sysURL.port) {
1900
- hostpart += `:${this._sysURL.port}`;
1901
- }
1902
- if (!this._pathname.startsWith("/")) {
1903
- hostpart += "/";
1904
- }
2022
+ for (const [key, value] of presetEnv) {
2023
+ this._map.set(key, value);
1905
2024
  }
1906
- return `${this._protocol}//${hostpart}${this._pathname}${search}`;
1907
2025
  }
1908
- };
1909
- function from(fac, strURLUri, defaultProtocol) {
1910
- switch (typeof falsy2undef(strURLUri)) {
1911
- case "undefined":
1912
- return fac(new MutableURL(`${defaultProtocol}///`));
1913
- case "string":
1914
- return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
1915
- case "object":
1916
- if (BuildURI.is(strURLUri)) {
1917
- return fac(new MutableURL(strURLUri._url.toString()));
1918
- } else if (URI.is(strURLUri)) {
1919
- return fac(new MutableURL(strURLUri._url.toString()));
1920
- } else if (isURL(strURLUri)) {
1921
- return fac(new MutableURL(strURLUri.toString()));
2026
+ _applyOnSet(onSet, key, value) {
2027
+ onSet.forEach((item) => {
2028
+ let keys = [];
2029
+ if (key) {
2030
+ keys = [key];
2031
+ } else {
2032
+ keys = this._map.keys();
1922
2033
  }
1923
- throw new Error(`unknown object type: ${strURLUri}`);
1924
- default:
1925
- throw new Error(`Invalid argument: ${typeof strURLUri}`);
2034
+ keys.filter((k) => {
2035
+ if (item.filter.size === 0) {
2036
+ return true;
2037
+ }
2038
+ if (item.filter.has(k)) {
2039
+ return true;
2040
+ }
2041
+ return false;
2042
+ }).forEach((k) => {
2043
+ let v;
2044
+ if (!key && !value) {
2045
+ v = this._map.get(k);
2046
+ } else if (key && !value) {
2047
+ v = void 0;
2048
+ } else {
2049
+ v = value;
2050
+ }
2051
+ item.fn(k, v);
2052
+ });
2053
+ });
1926
2054
  }
1927
- }
1928
- function getParamResult(key, val, msgFn = (key2) => {
1929
- return `missing parameter: ${key2}`;
1930
- }) {
1931
- if (val === void 0) {
1932
- return Result.Err(msgFn(key));
2055
+ keys() {
2056
+ return this._map.keys();
1933
2057
  }
1934
- return Result.Ok(val);
1935
- }
1936
- var BuildURI = class _BuildURI {
1937
- // pathname needs this
1938
- constructor(url) {
1939
- this._url = url;
2058
+ // filter is not set all sets passed
2059
+ onSet(fn, ...filter) {
2060
+ const item = { filter: new Set(filter), fn };
2061
+ this._onSet.push(item);
2062
+ this._applyOnSet([item]);
1940
2063
  }
1941
- static is(value) {
1942
- return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
2064
+ get(key) {
2065
+ return this._map.get(key);
1943
2066
  }
1944
- static from(strURLUri, defaultProtocol = "file:") {
1945
- return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
2067
+ set(key, value) {
2068
+ if (!value) {
2069
+ return;
2070
+ }
2071
+ this._map.set(key, value);
2072
+ this._applyOnSet(this._onSet, key, value);
1946
2073
  }
1947
- match(other) {
1948
- return match(this.URI(), URI.from(other));
2074
+ delete(key) {
2075
+ this._map.delete(key);
2076
+ this._applyOnSet(this._onSet, key);
1949
2077
  }
1950
- port(p) {
1951
- this._url.port = p;
1952
- return this;
2078
+ };
2079
+
2080
+ // src/utils/console-write-stream.ts
2081
+ var ConsoleWriterStreamDefaultWriter = class {
2082
+ constructor(stream) {
2083
+ this.stream = stream;
2084
+ this.desiredSize = null;
2085
+ this.decoder = new TextDecoder();
2086
+ this._stream = stream;
2087
+ this.ready = Promise.resolve(void 0);
2088
+ this.closed = Promise.resolve(void 0);
1953
2089
  }
1954
- hostname(h) {
1955
- this._url.hostname = h;
1956
- return this;
2090
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
2091
+ abort(reason) {
2092
+ throw new Error("Method not implemented.");
1957
2093
  }
1958
- protocol(p) {
1959
- if (!p.endsWith(":")) {
1960
- p = `${p}:`;
1961
- }
1962
- this._url.protocol = p;
1963
- return this;
2094
+ async close() {
1964
2095
  }
1965
- pathname(p) {
1966
- this._url.pathname = p;
1967
- return this;
2096
+ releaseLock() {
2097
+ this._stream.locked = false;
2098
+ this.ready = Promise.resolve(void 0);
2099
+ this.closed = Promise.resolve(void 0);
1968
2100
  }
1969
- // could pass a relative path or a full URL
1970
- // if relative path, it will be appended to the current path
1971
- resolve(p) {
1972
- if (!p) {
1973
- return this;
2101
+ write(chunk) {
2102
+ let strObj = this.decoder.decode(chunk).trimEnd();
2103
+ let output = "log";
2104
+ try {
2105
+ strObj = JSON.parse(strObj);
2106
+ output = strObj.level;
2107
+ } catch (e) {
1974
2108
  }
1975
- if (typeof p === "string") {
1976
- if (!p.match(/^[a-zA-Z0-9]+:/)) {
1977
- if (p.startsWith("/")) {
1978
- this.pathname(p);
1979
- return this;
1980
- }
1981
- return this.appendRelative(p);
1982
- }
2109
+ switch (output) {
2110
+ case "error":
2111
+ console.error(strObj);
2112
+ break;
2113
+ case "warn":
2114
+ console.warn(strObj);
2115
+ break;
2116
+ default:
2117
+ console.log(strObj);
1983
2118
  }
1984
- this._url = new MutableURL(p.toString());
1985
- return this;
2119
+ return Promise.resolve();
1986
2120
  }
1987
- appendRelative(p) {
1988
- const appendUrl = URI.from(p);
1989
- const pathname = "./" + appendUrl.pathname;
1990
- const basePath = this._url.pathname;
1991
- this.pathname(relativePath(basePath, pathname));
1992
- for (const [key, value] of appendUrl.getParams) {
1993
- this.setParam(key, value);
1994
- }
1995
- return this;
2121
+ };
2122
+ var ConsoleWriterStream = class {
2123
+ constructor() {
2124
+ this.locked = false;
1996
2125
  }
1997
- cleanParams() {
1998
- for (const key of Array.from(this._url.searchParams.keys())) {
1999
- this._url.searchParams.delete(key);
2000
- }
2001
- return this;
2126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
2127
+ abort(reason) {
2128
+ throw new Error("Method not implemented.");
2002
2129
  }
2003
- delParam(key) {
2004
- this._url.searchParams.delete(key);
2005
- return this;
2130
+ close() {
2131
+ return Promise.resolve();
2006
2132
  }
2007
- defParam(key, str) {
2008
- if (!this._url.searchParams.has(key)) {
2009
- this._url.searchParams.set(key, str);
2133
+ getWriter() {
2134
+ if (this.locked) {
2135
+ throw new Error("Stream is locked");
2010
2136
  }
2011
- return this;
2012
- }
2013
- setParam(key, str) {
2014
- this._url.searchParams.set(key, str);
2015
- return this;
2016
- }
2017
- hasParam(key) {
2018
- return this._url.searchParams.has(key);
2019
- }
2020
- get getParams() {
2021
- return this._url.searchParams.entries();
2022
- }
2023
- getParam(key, def) {
2024
- const { key: k, def: d } = coerceKey(key, def);
2025
- let val = this._url.searchParams.get(k);
2026
- if (!falsy2undef(val) && d) {
2027
- val = d;
2137
+ this.locked = true;
2138
+ if (!this._writer) {
2139
+ this._writer = new ConsoleWriterStreamDefaultWriter(this);
2028
2140
  }
2029
- return falsy2undef(val);
2030
- }
2031
- getParamResult(key, msgFn) {
2032
- return getParamResult(key, this.getParam(key), msgFn);
2033
- }
2034
- getParamsResult(...keys) {
2035
- return getParamsResult(keys, this);
2036
- }
2037
- toString() {
2038
- this._url.searchParams.sort();
2039
- return this._url.toString();
2040
- }
2041
- toJSON() {
2042
- return this.toString();
2141
+ return this._writer;
2043
2142
  }
2044
- asURL() {
2045
- return this.URI().asURL();
2143
+ };
2144
+
2145
+ // src/web/web-basic-sys-abstraction.ts
2146
+ var WebSystemService = class {
2147
+ constructor(ende) {
2148
+ this._txtEnDe = ende;
2046
2149
  }
2047
- asObj(...strips) {
2048
- return this.URI().asObj(...strips);
2150
+ Env() {
2151
+ return envFactory();
2049
2152
  }
2050
- clone() {
2051
- return _BuildURI.from(this.toString());
2153
+ Args() {
2154
+ throw new Error("Args-Method not implemented.");
2052
2155
  }
2053
- URI() {
2054
- return URI.from(this._url);
2156
+ Stdout() {
2157
+ return new ConsoleWriterStream();
2158
+ }
2159
+ Stderr() {
2160
+ const decoder = this._txtEnDe;
2161
+ return new WritableStream({
2162
+ write(chunk) {
2163
+ return new Promise((resolve) => {
2164
+ const decoded = decoder.decode(chunk);
2165
+ console.error(decoded.trimEnd());
2166
+ resolve();
2167
+ });
2168
+ }
2169
+ });
2055
2170
  }
2056
2171
  };
2057
- function isCoerceURI(value) {
2058
- if (!value) {
2059
- return false;
2172
+ var baseSysAbstraction = new ResolveOnce();
2173
+ function WebBasicSysAbstraction(param2) {
2174
+ var _a;
2175
+ const my = baseSysAbstraction.once(() => {
2176
+ return new BaseBasicSysAbstraction({
2177
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2178
+ });
2179
+ });
2180
+ return new WrapperBasicSysAbstraction(my, {
2181
+ basicRuntimeService: new WebSystemService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2182
+ ...param2
2183
+ });
2184
+ }
2185
+
2186
+ // src/cf/cf-basic-sys-abstraction.ts
2187
+ var CFRuntimeService = class {
2188
+ constructor(ende) {
2189
+ this._txtEnDe = ende;
2060
2190
  }
2061
- if (isURL(value)) {
2062
- return true;
2191
+ Env() {
2192
+ return envFactory();
2063
2193
  }
2064
- if (URI.is(value)) {
2065
- return true;
2194
+ Args() {
2195
+ throw new Error("Args-Method not implemented.");
2066
2196
  }
2067
- if (BuildURI.is(value)) {
2068
- return true;
2197
+ Stdout() {
2198
+ return CFWriteableStream((chunk) => {
2199
+ const decoded = this._txtEnDe.decode(chunk);
2200
+ console.log(decoded.trimEnd());
2201
+ return Promise.resolve();
2202
+ });
2069
2203
  }
2070
- if (typeof value === "string") {
2071
- return true;
2204
+ Stderr() {
2205
+ return CFWriteableStream((chunk) => {
2206
+ const decoded = this._txtEnDe.decode(chunk);
2207
+ console.error(decoded.trimEnd());
2208
+ return Promise.resolve();
2209
+ });
2072
2210
  }
2073
- return false;
2211
+ };
2212
+ function consumeReadableStream(reader, writeFn) {
2213
+ reader.read().then(({ done, value }) => {
2214
+ if (done) {
2215
+ return;
2216
+ }
2217
+ writeFn(value).then(() => {
2218
+ consumeReadableStream(reader, writeFn);
2219
+ }).catch((e) => {
2220
+ console.error("consumeReadableStream:writeFn", e);
2221
+ });
2222
+ }).catch((e) => {
2223
+ console.error("consumeReadableStream:read", e);
2224
+ });
2074
2225
  }
2075
- var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
2076
- var URI = class _URI {
2077
- static protocolHasHostpart(protocol) {
2078
- protocol = protocol.replace(/:$/, "");
2079
- hasHostPartProtocols.add(protocol);
2080
- return () => {
2081
- hasHostPartProtocols.delete(protocol);
2082
- };
2226
+ function CFWriteableStream(writeFn) {
2227
+ const ts = new TransformStream();
2228
+ consumeReadableStream(ts.readable.getReader(), writeFn);
2229
+ return ts.writable;
2230
+ }
2231
+ var baseSysAbstraction2 = new ResolveOnce();
2232
+ function CFBasicSysAbstraction(param2) {
2233
+ var _a;
2234
+ const my = baseSysAbstraction2.once(() => {
2235
+ return new BaseBasicSysAbstraction({
2236
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2237
+ });
2238
+ });
2239
+ return new WrapperBasicSysAbstraction(my, {
2240
+ basicRuntimeService: new CFRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2241
+ ...param2
2242
+ });
2243
+ }
2244
+
2245
+ // src/deno/deno-basic-sys-abstraction.ts
2246
+ var DenoRuntimeService = class {
2247
+ constructor(ende) {
2248
+ this._txtEnDe = ende;
2083
2249
  }
2084
- match(other) {
2085
- return match(this, other);
2250
+ Env() {
2251
+ return envFactory();
2086
2252
  }
2087
- // if no protocol is provided, default to file:
2088
- static merge(into, from2, defaultProtocol = "file:") {
2089
- const intoUrl = BuildURI.from(into, defaultProtocol);
2090
- const fromUrl = _URI.from(from2, defaultProtocol);
2091
- intoUrl.protocol(fromUrl.protocol);
2092
- const fPath = fromUrl.pathname;
2093
- if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
2094
- intoUrl.pathname(fromUrl.pathname);
2095
- }
2096
- for (const [key, value] of fromUrl.getParams) {
2097
- intoUrl.setParam(key, value);
2098
- }
2099
- return intoUrl.URI();
2253
+ Args() {
2254
+ return globalThis.Deno.args;
2100
2255
  }
2101
- static is(value) {
2102
- return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
2256
+ Stdout() {
2257
+ return globalThis.Deno.stdout.writable;
2103
2258
  }
2104
- // if no protocol is provided, default to file:
2105
- static from(strURLUri, defaultProtocol = "file:") {
2106
- return from((url) => new _URI(url), strURLUri, defaultProtocol);
2259
+ Stderr() {
2260
+ return globalThis.Deno.stderr.writable;
2107
2261
  }
2108
- static fromResult(strURLUri, defaultProtocol = "file:") {
2109
- return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
2262
+ };
2263
+ var baseSysAbstraction3 = new ResolveOnce();
2264
+ function DenoBasicSysAbstraction(param2) {
2265
+ var _a;
2266
+ const my = baseSysAbstraction3.once(() => {
2267
+ return new BaseBasicSysAbstraction({
2268
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2269
+ });
2270
+ });
2271
+ return new WrapperBasicSysAbstraction(my, {
2272
+ basicRuntimeService: new DenoRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2273
+ ...param2
2274
+ });
2275
+ }
2276
+
2277
+ // src/node/node-basic-sys-abstraction.ts
2278
+ var NodeRuntimeService = class {
2279
+ constructor(ende) {
2280
+ this._txtEnDe = ende;
2281
+ this._gthis = globalThis;
2110
2282
  }
2111
- constructor(url) {
2112
- this._url = url.clone();
2283
+ Env() {
2284
+ return envFactory();
2113
2285
  }
2114
- build() {
2115
- return BuildURI.from(this._url);
2286
+ Args() {
2287
+ return this._gthis.process.argv;
2116
2288
  }
2117
- get hostname() {
2118
- return this._url.hostname;
2289
+ Stdout() {
2290
+ return new WritableStream({
2291
+ write: (chunk) => {
2292
+ this._gthis.process.stdout.write(chunk);
2293
+ }
2294
+ });
2119
2295
  }
2120
- // get password(): string {
2121
- // return this._url.password;
2122
- // }
2123
- get port() {
2124
- return this._url.port;
2296
+ Stderr() {
2297
+ return new WritableStream({
2298
+ write: (chunk) => {
2299
+ this._gthis.process.stderr.write(chunk);
2300
+ }
2301
+ });
2125
2302
  }
2126
- get host() {
2127
- return this._url.host;
2303
+ };
2304
+ var baseSysAbstraction4 = new ResolveOnce();
2305
+ function NodeBasicSysAbstraction(param2) {
2306
+ var _a;
2307
+ const my = baseSysAbstraction4.once(() => {
2308
+ return new BaseBasicSysAbstraction({
2309
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2310
+ });
2311
+ });
2312
+ return new WrapperBasicSysAbstraction(my, {
2313
+ basicRuntimeService: new NodeRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2314
+ ...param2
2315
+ });
2316
+ }
2317
+
2318
+ // src/base-sys-abstraction.ts
2319
+ var SysTime = class extends Time {
2320
+ Now() {
2321
+ return /* @__PURE__ */ new Date();
2128
2322
  }
2129
- // get username(): string {
2130
- // return this._url.username;
2131
- // }
2132
- // get search(): string {
2133
- // return this._url.search;
2134
- // }
2135
- get protocol() {
2136
- return this._url.protocol;
2323
+ Sleep(duration) {
2324
+ return new Promise((resolve) => {
2325
+ setTimeout(() => {
2326
+ resolve();
2327
+ }, duration);
2328
+ });
2137
2329
  }
2138
- get pathname() {
2139
- return this._url.pathname;
2330
+ };
2331
+ var ConstTime = class extends Time {
2332
+ Now() {
2333
+ return new Date(2021, 1, 1, 0, 0, 0, 0);
2140
2334
  }
2141
- // get hash(): string {
2142
- // return this._url.hash;
2143
- // }
2144
- // get host(): string {
2145
- // return this._url.host;
2146
- // }
2147
- get getParams() {
2148
- return this._url.searchParams.entries();
2335
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2336
+ Sleep(duration) {
2337
+ return Promise.resolve();
2149
2338
  }
2150
- hasParam(key) {
2151
- return this._url.searchParams.has(key);
2339
+ };
2340
+ var StepTime = class extends Time {
2341
+ constructor() {
2342
+ super();
2343
+ this._step = new ConstTime().Now();
2344
+ this._start = this._step;
2152
2345
  }
2153
- getParam(key, def) {
2154
- const { key: k, def: d } = coerceKey(key, def);
2155
- let val = this._url.searchParams.get(k);
2156
- if (!falsy2undef(val) && d) {
2157
- val = d;
2346
+ Now(steps = 1) {
2347
+ for (let i = 0; steps > 0 && i < steps; i++) {
2348
+ this._step = new Date(this._step.getTime() + 1e3);
2158
2349
  }
2159
- return falsy2undef(val);
2160
- }
2161
- getParamResult(key, msgFn) {
2162
- return getParamResult(key, this.getParam(key), msgFn);
2350
+ if (steps < 1) {
2351
+ this._step = new Date(this._start.getTime() + steps * -1e3);
2352
+ }
2353
+ return this._step;
2163
2354
  }
2164
- getParamsResult(...keys) {
2165
- return getParamsResult(keys, this);
2355
+ Sleep(duration) {
2356
+ this._step = new Date(this._step.getTime() + duration);
2357
+ return Promise.resolve();
2166
2358
  }
2167
- clone() {
2168
- return new _URI(this._url);
2359
+ };
2360
+ function TimeFactory(timeMode) {
2361
+ switch (timeMode) {
2362
+ case TimeMode.REAL:
2363
+ return new SysTime();
2364
+ case TimeMode.CONST:
2365
+ return new ConstTime();
2366
+ case TimeMode.STEP:
2367
+ return new StepTime();
2169
2368
  }
2170
- asURL() {
2171
- return this._url.clone();
2369
+ return new SysTime();
2370
+ }
2371
+ var RandomService = class {
2372
+ constructor(mode) {
2373
+ this._step = 0;
2374
+ this._mode = mode;
2172
2375
  }
2173
- toString() {
2174
- return this._url.toString();
2376
+ Random0ToValue(value) {
2377
+ switch (this._mode) {
2378
+ case RandomMode.CONST:
2379
+ return 0.5 * value;
2380
+ case RandomMode.STEP:
2381
+ this._step += 1e-4;
2382
+ return this._step * value;
2383
+ case RandomMode.RANDOM:
2384
+ return Math.random() * value;
2385
+ default:
2386
+ throw new Error("Unknown RandomMode");
2387
+ }
2175
2388
  }
2176
- toJSON() {
2177
- return this.toString();
2389
+ };
2390
+ var IdService = class {
2391
+ constructor(mode) {
2392
+ this._step = 0;
2393
+ if (!mode) {
2394
+ mode = IDMode.UUID;
2395
+ }
2396
+ this._mode = mode;
2178
2397
  }
2179
- asObj(...strips) {
2180
- const pathURI = {
2181
- style: "path",
2182
- protocol: this.protocol,
2183
- pathname: this.pathname,
2184
- searchParams: Object.fromEntries(this.getParams)
2185
- };
2186
- if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
2187
- return stripper(strips, {
2188
- ...pathURI,
2189
- style: "host",
2190
- hostname: this.hostname,
2191
- port: this.port
2192
- });
2398
+ NextId() {
2399
+ switch (this._mode) {
2400
+ case IDMode.UUID:
2401
+ return crypto.randomUUID();
2402
+ case IDMode.CONST:
2403
+ return "VeryUniqueID";
2404
+ case IDMode.STEP:
2405
+ return `STEPId-${this._step++}`;
2406
+ default:
2407
+ throw new Error("Unknown IDMode");
2193
2408
  }
2194
- return stripper(strips, pathURI);
2195
2409
  }
2196
2410
  };
2197
-
2198
- // src/utils/console-write-stream.ts
2199
- var ConsoleWriterStreamDefaultWriter = class {
2200
- constructor(stream) {
2201
- this.stream = stream;
2202
- this.desiredSize = null;
2203
- this.decoder = new TextDecoder();
2204
- this._stream = stream;
2205
- this.ready = Promise.resolve(void 0);
2206
- this.closed = Promise.resolve(void 0);
2207
- }
2208
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
2209
- abort(reason) {
2210
- throw new Error("Method not implemented.");
2411
+ var BaseBasicSysAbstraction = class {
2412
+ constructor(params) {
2413
+ this._time = new SysTime();
2414
+ // system independent services
2415
+ this._idService = new IdService();
2416
+ this._randomService = new RandomService(RandomMode.RANDOM);
2417
+ this._txtEnDe = params.TxtEnDecoder;
2211
2418
  }
2212
- async close() {
2419
+ };
2420
+ var BaseSysAbstraction = class extends BaseBasicSysAbstraction {
2421
+ constructor(params) {
2422
+ super(params);
2423
+ this._fileSystem = params.FileSystem;
2424
+ this._systemService = params.SystemService;
2213
2425
  }
2214
- releaseLock() {
2215
- this._stream.locked = false;
2216
- this.ready = Promise.resolve(void 0);
2217
- this.closed = Promise.resolve(void 0);
2426
+ };
2427
+ function BasicSysAbstractionFactory(params) {
2428
+ const fn = runtimeFn();
2429
+ switch (true) {
2430
+ case fn.isBrowser:
2431
+ return WebBasicSysAbstraction(params);
2432
+ case fn.isDeno:
2433
+ return DenoBasicSysAbstraction(params);
2434
+ case fn.isCFWorker:
2435
+ return CFBasicSysAbstraction(params);
2436
+ case fn.isNodeIsh:
2437
+ return NodeBasicSysAbstraction(params);
2438
+ default:
2439
+ throw new Error("Unknown runtime");
2218
2440
  }
2219
- write(chunk) {
2220
- let strObj = this.decoder.decode(chunk).trimEnd();
2221
- let output = "log";
2222
- try {
2223
- strObj = JSON.parse(strObj);
2224
- output = strObj.level;
2225
- } catch (e) {
2441
+ }
2442
+ var WrapperBasicSysAbstraction = class {
2443
+ constructor(base, params) {
2444
+ this._time = base._time;
2445
+ this._basicRuntimeService = params.basicRuntimeService;
2446
+ this._idService = base._idService;
2447
+ this._randomService = base._randomService;
2448
+ if (params.TimeMode) {
2449
+ this._time = TimeFactory(params.TimeMode);
2226
2450
  }
2227
- switch (output) {
2228
- case "error":
2229
- console.error(strObj);
2230
- break;
2231
- case "warn":
2232
- console.warn(strObj);
2233
- break;
2234
- default:
2235
- console.log(strObj);
2451
+ if (params.IdMode) {
2452
+ this._idService = new IdService(params.IdMode);
2453
+ }
2454
+ if (params.RandomMode) {
2455
+ this._randomService = new RandomService(params.RandomMode);
2236
2456
  }
2237
- return Promise.resolve();
2238
2457
  }
2239
- };
2240
- var ConsoleWriterStream = class {
2241
- constructor() {
2242
- this.locked = false;
2458
+ Time() {
2459
+ return this._time;
2243
2460
  }
2244
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
2245
- abort(reason) {
2246
- throw new Error("Method not implemented.");
2461
+ NextId() {
2462
+ return this._idService.NextId();
2247
2463
  }
2248
- close() {
2249
- return Promise.resolve();
2464
+ Random0ToValue(value) {
2465
+ return this._randomService.Random0ToValue(value);
2250
2466
  }
2251
- getWriter() {
2252
- if (this.locked) {
2253
- throw new Error("Stream is locked");
2254
- }
2255
- this.locked = true;
2256
- if (!this._writer) {
2257
- this._writer = new ConsoleWriterStreamDefaultWriter(this);
2258
- }
2259
- return this._writer;
2467
+ Stdout() {
2468
+ return this._basicRuntimeService.Stdout();
2469
+ }
2470
+ Stderr() {
2471
+ return this._basicRuntimeService.Stderr();
2472
+ }
2473
+ Env() {
2474
+ return this._basicRuntimeService.Env();
2475
+ }
2476
+ Args() {
2477
+ return this._basicRuntimeService.Args();
2478
+ }
2479
+ // System(): SystemService {
2480
+ // return this._systemService;
2481
+ // }
2482
+ // FileSystem(): FileService {
2483
+ // return this._fileSystem;
2484
+ // }
2485
+ };
2486
+ var WrapperRuntimeSysAbstraction = class extends WrapperBasicSysAbstraction {
2487
+ constructor(base, params) {
2488
+ var _a, _b;
2489
+ super(base, params);
2490
+ this._systemService = (_a = params.systemService) != null ? _a : base._systemService;
2491
+ this._fileSystem = (_b = params.fileSystem) != null ? _b : base._fileSystem;
2492
+ }
2493
+ System() {
2494
+ return this._systemService;
2495
+ }
2496
+ FileSystem() {
2497
+ return this._fileSystem;
2260
2498
  }
2261
2499
  };
2262
2500
 
@@ -2267,9 +2505,10 @@ var LogWriterStream = class {
2267
2505
  this._flushIsRunning = false;
2268
2506
  this._flushDoneFns = [];
2269
2507
  this._out = out;
2508
+ this._id = Math.random();
2270
2509
  }
2271
2510
  write(encoded) {
2272
- const my2 = async () => {
2511
+ const my = async () => {
2273
2512
  try {
2274
2513
  const writer = this._out.getWriter();
2275
2514
  await writer.ready;
@@ -2279,7 +2518,7 @@ var LogWriterStream = class {
2279
2518
  console.error("Chunk error:", err);
2280
2519
  }
2281
2520
  };
2282
- this._toFlush.push(my2);
2521
+ this._toFlush.push(my);
2283
2522
  this._flush();
2284
2523
  }
2285
2524
  _flush(toFlush = void 0, done) {
@@ -2297,8 +2536,8 @@ var LogWriterStream = class {
2297
2536
  } else if (!toFlush) {
2298
2537
  return;
2299
2538
  }
2300
- const my2 = this._toFlush.shift();
2301
- my2 == null ? void 0 : my2().catch((e) => {
2539
+ const my = this._toFlush.shift();
2540
+ my == null ? void 0 : my().catch((e) => {
2302
2541
  console.error("Flush error:", e);
2303
2542
  }).finally(() => {
2304
2543
  this._flush(this._toFlush);
@@ -2306,145 +2545,6 @@ var LogWriterStream = class {
2306
2545
  }
2307
2546
  };
2308
2547
 
2309
- // src/option.ts
2310
- var Option = class _Option {
2311
- static Some(t) {
2312
- return new Some(t);
2313
- }
2314
- static None() {
2315
- return new None();
2316
- }
2317
- static Is(t) {
2318
- return t instanceof _Option;
2319
- }
2320
- static From(t) {
2321
- if (!t) {
2322
- return new None();
2323
- }
2324
- return new Some(t);
2325
- }
2326
- IsNone() {
2327
- return this.is_none();
2328
- }
2329
- IsSome() {
2330
- return this.is_some();
2331
- }
2332
- Unwrap() {
2333
- return this.unwrap();
2334
- }
2335
- };
2336
- var Some = class extends Option {
2337
- constructor(_t) {
2338
- super();
2339
- this._t = _t;
2340
- }
2341
- is_none() {
2342
- return false;
2343
- }
2344
- is_some() {
2345
- return true;
2346
- }
2347
- unwrap() {
2348
- return this._t;
2349
- }
2350
- };
2351
- var None = class extends Option {
2352
- is_none() {
2353
- return true;
2354
- }
2355
- is_some() {
2356
- return false;
2357
- }
2358
- unwrap() {
2359
- throw new Error("None.unwrap");
2360
- }
2361
- };
2362
-
2363
- // src/log-level-impl.ts
2364
- var LevelHandlerImpl = class {
2365
- constructor() {
2366
- this._globalLevels = /* @__PURE__ */ new Set([Level.INFO, Level.ERROR, Level.WARN]);
2367
- this._modules = /* @__PURE__ */ new Map();
2368
- this.ignoreAttr = Option.Some(/^_/);
2369
- this.isStackExposed = false;
2370
- }
2371
- enableLevel(level, ...modules) {
2372
- if (modules.length == 0) {
2373
- this._globalLevels.add(level);
2374
- return;
2375
- }
2376
- this.forModules(
2377
- level,
2378
- (p) => {
2379
- this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, level]));
2380
- },
2381
- ...modules
2382
- );
2383
- }
2384
- disableLevel(level, ...modules) {
2385
- if (modules.length == 0) {
2386
- this._globalLevels.delete(level);
2387
- return;
2388
- }
2389
- this.forModules(
2390
- level,
2391
- (p) => {
2392
- this._modules.delete(p);
2393
- },
2394
- ...modules
2395
- );
2396
- }
2397
- setExposeStack(enable) {
2398
- this.isStackExposed = !!enable;
2399
- }
2400
- setIgnoreAttr(re) {
2401
- this.ignoreAttr = Option.From(re);
2402
- }
2403
- forModules(level, fnAction, ...modules) {
2404
- for (const m of modules.flat()) {
2405
- if (typeof m !== "string") {
2406
- continue;
2407
- }
2408
- const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
2409
- for (const p of parts) {
2410
- fnAction(p);
2411
- }
2412
- }
2413
- }
2414
- setDebug(...modules) {
2415
- this.forModules(
2416
- Level.DEBUG,
2417
- (p) => {
2418
- this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, Level.DEBUG]));
2419
- },
2420
- ...modules
2421
- );
2422
- }
2423
- isEnabled(ilevel, module2) {
2424
- const level = ilevel;
2425
- if (typeof module2 === "string") {
2426
- const levels = this._modules.get(module2);
2427
- if (levels && levels.has(level)) {
2428
- return true;
2429
- }
2430
- }
2431
- const wlevel = this._modules.get("*");
2432
- if (wlevel && typeof level === "string") {
2433
- if (wlevel.has(level)) {
2434
- return true;
2435
- }
2436
- }
2437
- if (typeof level !== "string") {
2438
- return true;
2439
- }
2440
- return this._globalLevels.has(level);
2441
- }
2442
- };
2443
- var levelSingleton = new LevelHandlerImpl();
2444
- function LevelHandlerSingleton() {
2445
- return levelSingleton;
2446
- }
2447
-
2448
2548
  // src/logger-impl.ts
2449
2549
  function getLen(value, lvs) {
2450
2550
  if (Array.isArray(value)) {
@@ -2504,7 +2604,7 @@ var LoggerImpl = class _LoggerImpl {
2504
2604
  params = {};
2505
2605
  }
2506
2606
  if (!params.sys) {
2507
- this._sys = WebSysAbstraction();
2607
+ this._sys = BasicSysAbstractionFactory();
2508
2608
  } else {
2509
2609
  this._sys = params.sys;
2510
2610
  }
@@ -2522,18 +2622,7 @@ var LoggerImpl = class _LoggerImpl {
2522
2622
  this._logWriter = params.logWriter;
2523
2623
  } else {
2524
2624
  if (!params.out) {
2525
- const rt = runtimeFn();
2526
- let stream;
2527
- if (rt.isBrowser) {
2528
- stream = new ConsoleWriterStream();
2529
- } else {
2530
- if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
2531
- stream = this._sys.Stdout();
2532
- } else {
2533
- throw new Error("No output defined for runtime");
2534
- }
2535
- }
2536
- this._logWriter = new LogWriterStream(stream);
2625
+ this._logWriter = new LogWriterStream(this._sys.Stdout());
2537
2626
  } else {
2538
2627
  this._logWriter = new LogWriterStream(params.out);
2539
2628
  }
@@ -3475,6 +3564,39 @@ function JSONEnDecoderSingleton(txtEnde) {
3475
3564
  return jsonEnDecoder;
3476
3565
  }
3477
3566
 
3567
+ // src/coerce-binary.ts
3568
+ async function top_uint8(input) {
3569
+ if (input instanceof Blob) {
3570
+ return new Uint8Array(await input.arrayBuffer());
3571
+ }
3572
+ return to_uint8(input);
3573
+ }
3574
+ function to_uint8(input, encoder) {
3575
+ if (typeof input === "string") {
3576
+ return (encoder != null ? encoder : new TextEncoder()).encode(input);
3577
+ }
3578
+ if (input instanceof ArrayBuffer) {
3579
+ return new Uint8Array(input);
3580
+ }
3581
+ if (input instanceof Uint8Array) {
3582
+ return input;
3583
+ }
3584
+ return new Uint8Array(input);
3585
+ }
3586
+ function to_blob(input, encoder) {
3587
+ if (input instanceof Blob) {
3588
+ return input;
3589
+ }
3590
+ return new Blob([to_uint8(input, encoder)]);
3591
+ }
3592
+ function to_arraybuf(input, encoder) {
3593
+ if (input instanceof ArrayBuffer) {
3594
+ return input;
3595
+ }
3596
+ const u8 = to_uint8(input, encoder);
3597
+ return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
3598
+ }
3599
+
3478
3600
  // src/utils/index.ts
3479
3601
  var utils_exports = {};
3480
3602
  __export(utils_exports, {
@@ -3713,7 +3835,9 @@ function UInt8ArrayEqual(a, b) {
3713
3835
  }
3714
3836
  // Annotate the CommonJS export names for ESM import in node:
3715
3837
  0 && (module.exports = {
3838
+ BaseBasicSysAbstraction,
3716
3839
  BaseSysAbstraction,
3840
+ BasicSysAbstractionFactory,
3717
3841
  BuildURI,
3718
3842
  ConstTime,
3719
3843
  EnvImpl,
@@ -3762,7 +3886,8 @@ function UInt8ArrayEqual(a, b) {
3762
3886
  TxtEnDecoderSingleton,
3763
3887
  URI,
3764
3888
  VERSION,
3765
- WrapperSysAbstraction,
3889
+ WrapperBasicSysAbstraction,
3890
+ WrapperRuntimeSysAbstraction,
3766
3891
  YAMLFormatter,
3767
3892
  asyncLogValue,
3768
3893
  bin2string,
@@ -3778,6 +3903,10 @@ function UInt8ArrayEqual(a, b) {
3778
3903
  registerEnvAction,
3779
3904
  runtimeFn,
3780
3905
  toCryptoRuntime,
3906
+ to_arraybuf,
3907
+ to_blob,
3908
+ to_uint8,
3909
+ top_uint8,
3781
3910
  utils
3782
3911
  });
3783
3912
  //# sourceMappingURL=index.cjs.map