@adviser/cement 0.3.19 → 0.4.0

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