@adviser/cement 0.3.20 → 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 (164) 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-UEER5ZC2.js → chunk-6F3ACVHD.js} +8 -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-BhmvYS_t.d.ts → index-N0bkrgSt.d.ts} +2 -2
  25. package/{index-DoK1OTgQ.d.cts → index-TtYD7HhB.d.cts} +2 -2
  26. package/index.cjs +1863 -1775
  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 +4 -4
  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/web/index.ts +1 -1
  57. package/src/web/web-basic-sys-abstraction.ts +105 -0
  58. package/{sys-abstraction-B0x6IE7r.d.ts → sys-abstraction-CeAxxg9H.d.ts} +11 -7
  59. package/{sys-abstraction-BTs3Vzy4.d.cts → sys-abstraction-DDAwGTnk.d.cts} +11 -7
  60. package/test/index.cjs +1546 -1485
  61. package/test/index.cjs.map +1 -1
  62. package/test/index.d.cts +2 -2
  63. package/test/index.d.ts +2 -2
  64. package/test/index.js +4 -5
  65. package/ts/smoke/smoke.js +7 -8
  66. package/ts/smoke/smoke.js.map +1 -1
  67. package/ts/src/base-basic-sys-abstraction.test.d.ts +2 -0
  68. package/ts/src/base-basic-sys-abstraction.test.d.ts.map +1 -0
  69. package/ts/src/{base-sys-abstraction.test.js → base-basic-sys-abstraction.test.js} +9 -9
  70. package/ts/src/base-basic-sys-abstraction.test.js.map +1 -0
  71. package/ts/src/base-sys-abstraction.d.ts +33 -21
  72. package/ts/src/base-sys-abstraction.d.ts.map +1 -1
  73. package/ts/src/base-sys-abstraction.js +54 -67
  74. package/ts/src/base-sys-abstraction.js.map +1 -1
  75. package/ts/src/cf/cf-basic-sys-abstraction.d.ts +14 -0
  76. package/ts/src/cf/cf-basic-sys-abstraction.d.ts.map +1 -0
  77. package/ts/src/cf/cf-basic-sys-abstraction.js +67 -0
  78. package/ts/src/cf/cf-basic-sys-abstraction.js.map +1 -0
  79. package/ts/src/cf/index.d.ts +1 -1
  80. package/ts/src/cf/index.d.ts.map +1 -1
  81. package/ts/src/cf/index.js +1 -1
  82. package/ts/src/cf/index.js.map +1 -1
  83. package/ts/src/cf-test-main.d.ts.map +1 -1
  84. package/ts/src/cf-test-main.js +7 -1
  85. package/ts/src/cf-test-main.js.map +1 -1
  86. package/ts/src/deno/deno-basic-sys-abstraction.d.ts +14 -0
  87. package/ts/src/deno/deno-basic-sys-abstraction.d.ts.map +1 -0
  88. package/ts/src/deno/deno-basic-sys-abstraction.js +35 -0
  89. package/ts/src/deno/deno-basic-sys-abstraction.js.map +1 -0
  90. package/ts/src/deno/deno-file-service.d.ts +1 -1
  91. package/ts/src/deno/deno-file-service.d.ts.map +1 -1
  92. package/ts/src/deno/deno-sys-abstraction.d.ts +3 -6
  93. package/ts/src/deno/deno-sys-abstraction.d.ts.map +1 -1
  94. package/ts/src/deno/deno-sys-abstraction.js +13 -17
  95. package/ts/src/deno/deno-sys-abstraction.js.map +1 -1
  96. package/ts/src/log-writer-impl.d.ts +1 -0
  97. package/ts/src/log-writer-impl.d.ts.map +1 -1
  98. package/ts/src/log-writer-impl.js +1 -0
  99. package/ts/src/log-writer-impl.js.map +1 -1
  100. package/ts/src/logger-impl.d.ts +3 -3
  101. package/ts/src/logger-impl.d.ts.map +1 -1
  102. package/ts/src/logger-impl.js +3 -18
  103. package/ts/src/logger-impl.js.map +1 -1
  104. package/ts/src/logger.test.js +3 -4
  105. package/ts/src/logger.test.js.map +1 -1
  106. package/ts/src/node/node-basic-sys-abstraction.d.ts +25 -0
  107. package/ts/src/node/node-basic-sys-abstraction.d.ts.map +1 -0
  108. package/ts/src/node/node-basic-sys-abstraction.js +44 -0
  109. package/ts/src/node/node-basic-sys-abstraction.js.map +1 -0
  110. package/ts/src/node/node-sys-abstraction.d.ts +3 -6
  111. package/ts/src/node/node-sys-abstraction.d.ts.map +1 -1
  112. package/ts/src/node/node-sys-abstraction.js +13 -17
  113. package/ts/src/node/node-sys-abstraction.js.map +1 -1
  114. package/ts/src/node/node-sys-abstraction.test.js +1 -1
  115. package/ts/src/node/node-sys-abstraction.test.js.map +1 -1
  116. package/ts/src/sys-abstraction.d.ts +10 -6
  117. package/ts/src/sys-abstraction.d.ts.map +1 -1
  118. package/ts/src/test/mock-logger.d.ts +2 -2
  119. package/ts/src/test/mock-logger.d.ts.map +1 -1
  120. package/ts/src/test/mock-logger.js.map +1 -1
  121. package/ts/src/tracer.test.js +5 -8
  122. package/ts/src/tracer.test.js.map +1 -1
  123. package/ts/src/txt-en-decoder.d.ts.map +1 -1
  124. package/ts/src/txt-en-decoder.js +3 -3
  125. package/ts/src/txt-en-decoder.js.map +1 -1
  126. package/ts/src/web/index.d.ts +1 -1
  127. package/ts/src/web/index.d.ts.map +1 -1
  128. package/ts/src/web/index.js +1 -1
  129. package/ts/src/web/index.js.map +1 -1
  130. package/ts/src/web/web-basic-sys-abstraction.d.ts +4 -0
  131. package/ts/src/web/web-basic-sys-abstraction.d.ts.map +1 -0
  132. package/ts/src/web/web-basic-sys-abstraction.js +45 -0
  133. package/ts/src/web/web-basic-sys-abstraction.js.map +1 -0
  134. package/utils/index.cjs +132 -3
  135. package/utils/index.cjs.map +1 -1
  136. package/utils/index.js +5 -5
  137. package/web/index.cjs +277 -281
  138. package/web/index.cjs.map +1 -1
  139. package/web/index.d.cts +4 -17
  140. package/web/index.d.ts +4 -17
  141. package/web/index.js +4 -7
  142. package/base-sys-abstraction-BnBZ6zd0.d.ts +0 -84
  143. package/base-sys-abstraction-DAZ8tx5F.d.cts +0 -84
  144. package/chunk-23MCJYE6.js.map +0 -1
  145. package/chunk-H6MLKWIZ.js +0 -88
  146. package/chunk-H6MLKWIZ.js.map +0 -1
  147. package/chunk-LXTKPZ6M.js +0 -255
  148. package/chunk-LXTKPZ6M.js.map +0 -1
  149. package/chunk-PHS255C5.js.map +0 -1
  150. package/chunk-UEER5ZC2.js.map +0 -1
  151. package/src/cf/cf-sys-abstraction.ts +0 -34
  152. package/src/web/web-sys-abstraction.ts +0 -80
  153. package/ts/src/base-sys-abstraction.test.d.ts +0 -2
  154. package/ts/src/base-sys-abstraction.test.d.ts.map +0 -1
  155. package/ts/src/base-sys-abstraction.test.js.map +0 -1
  156. package/ts/src/cf/cf-sys-abstraction.d.ts +0 -11
  157. package/ts/src/cf/cf-sys-abstraction.d.ts.map +0 -1
  158. package/ts/src/cf/cf-sys-abstraction.js +0 -30
  159. package/ts/src/cf/cf-sys-abstraction.js.map +0 -1
  160. package/ts/src/web/web-sys-abstraction.d.ts +0 -18
  161. package/ts/src/web/web-sys-abstraction.d.ts.map +0 -1
  162. package/ts/src/web/web-sys-abstraction.js +0 -64
  163. package/ts/src/web/web-sys-abstraction.js.map +0 -1
  164. /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,1704 +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();
945
+ if (errors.length) {
946
+ return Result.Err(msgFn(...errors));
719
947
  }
948
+ return Result.Ok(result);
949
+ }
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 /* ../ */,
720
958
  };
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();
959
+ var Path = class {
960
+ constructor(parts = []) {
961
+ this.parts = parts;
729
962
  }
730
- return new SysTime();
731
- }
732
- var RandomService = class {
733
- constructor(mode) {
734
- this._step = 0;
735
- this._mode = mode;
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("");
736
979
  }
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");
980
+ add(part) {
981
+ if (this.parts.includes(PartType.Root) && part === PartType.Root) {
982
+ throw new Error("Cannot add absolute part to absolute path");
748
983
  }
749
- }
750
- };
751
- var IdService = class {
752
- constructor(mode) {
753
- this._step = 0;
754
- if (!mode) {
755
- mode = IDMode.UUID;
984
+ const last = this.parts[this.parts.length - 1];
985
+ if (last & PartType.Slash && part === PartType.Slash) {
986
+ return;
756
987
  }
757
- this._mode = mode;
758
- }
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");
988
+ switch (part) {
989
+ case ".":
990
+ this.parts.push(PartType.Noop);
991
+ return;
992
+ case "..":
993
+ part = PartType.Up;
769
994
  }
770
- }
771
- };
772
- function consumeReadableStream(reader, writeFn) {
773
- reader.read().then(({ done, value }) => {
774
- if (done) {
995
+ if (last === PartType.Noop && part === PartType.Slash) {
996
+ if (last === PartType.Noop) {
997
+ this.parts.pop();
998
+ }
775
999
  return;
776
1000
  }
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
- });
1001
+ this.parts.push(part);
810
1002
  }
811
1003
  };
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;
1004
+ function splitPath(path) {
1005
+ const p = new Path();
1006
+ if (path === "") {
1007
+ return p;
1008
+ }
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);
842
1015
  }
1016
+ path = path.replace(/^\/+/, "");
1017
+ } else {
1018
+ const part = path.replace(/\/.*$/, "");
1019
+ p.add(part);
1020
+ path = path.replace(/^[^/]+/, "");
843
1021
  }
844
1022
  }
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;
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;
1032
+ }
1033
+ if (!(prev.endsWith("/") || path.startsWith("/"))) {
1034
+ if (prev !== "") {
1035
+ res.push("/");
1036
+ }
1037
+ res.push(path);
1038
+ } else {
1039
+ res.push(path);
1040
+ }
1041
+ prev = path;
859
1042
  }
860
- System() {
861
- return this._systemService;
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);
862
1052
  }
863
- FileSystem() {
864
- return this._fileSystem;
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
+ }
865
1087
  }
866
- };
1088
+ return new Path(out).toString();
1089
+ }
867
1090
 
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}`);
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}$`);
880
1098
  }
881
- const value = this._map.get(key);
882
- this._map.delete(key);
883
- this._map.set(key, value);
884
- return value;
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;
885
1106
  }
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);
1107
+ if (Array.isArray(obj)) {
1108
+ return obj.map((i) => localStripper(path, restrips, i));
1109
+ }
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;
1115
+ }
1116
+ }
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;
1126
+ }
1127
+ if (matcher(key, nextPath)) {
1128
+ delete ret[key];
1129
+ continue;
1130
+ }
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
+ }, []);
1140
+ } else {
1141
+ ret[key] = localStripper(nextPath, restrips, ret[key]);
902
1142
  }
903
1143
  }
904
1144
  }
905
1145
  }
906
- has(key) {
907
- return this._map.has(key);
908
- }
909
- get size() {
910
- return this._map.size;
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;
911
1165
  }
912
- async getSet(key, createFN) {
913
- const val = this.get(key);
914
- if (val) {
915
- return val;
916
- } else {
917
- const val2 = await createFN(key);
918
- this.set(key, val2);
919
- return val2;
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;
1172
+ }
1173
+ if (refP.length && refP === oth.port) {
1174
+ mr.score += 1;
1175
+ mr.port = true;
920
1176
  }
1177
+ } catch (e) {
921
1178
  }
922
- get(key) {
923
- if (this._map.has(key)) {
924
- return this.touch(key);
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]);
1187
+ }
925
1188
  }
926
- return this._map.get(key);
927
1189
  }
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);
933
- } else {
934
- this._map.set(key, value);
1190
+ for (const [key, value] of ref.getParams) {
1191
+ if (oth.getParam(key) === value) {
1192
+ mr.score += 1;
1193
+ mr.params[key] = value;
935
1194
  }
936
1195
  }
937
- delete(key) {
938
- this._map.delete(key);
1196
+ return mr;
1197
+ }
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]] };
939
1205
  }
940
- clear() {
941
- this._map.clear();
1206
+ return { key, def };
1207
+ }
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}//`);
942
1214
  }
943
- forEach(callbackfn) {
944
- this._map.forEach(callbackfn);
1215
+ if (typeof url === "string") {
1216
+ try {
1217
+ return new MutableURL(url);
1218
+ } catch (e) {
1219
+ return new MutableURL(`${defaultProtocol}//${url}`);
1220
+ }
1221
+ } else {
1222
+ return new MutableURL(url.toString());
945
1223
  }
946
- entries() {
947
- return this._map.entries();
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;
948
1252
  }
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
- };
961
-
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;
1253
+ clone() {
1254
+ return new _MutableURL(this.toString());
970
1255
  }
971
- get ready() {
972
- return this._onceDone;
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
+ );
1261
+ }
1262
+ return this._sysURL.host;
973
1263
  }
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));
983
- }
984
- } else {
985
- this._onceFutures.length = 0;
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()))}`);
986
1267
  }
1268
+ return this._sysURL.port;
987
1269
  }
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
- }
997
- }
998
- if (this._onceOk) {
999
- if (this._isPromise) {
1000
- return Promise.resolve(this._onceValue);
1001
- } else {
1002
- return this._onceValue;
1003
- }
1004
- }
1005
- throw new Error("ResolveOnce.once impossible");
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()))}`);
1006
1273
  }
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
- });
1037
- } else {
1038
- okFn(ret);
1039
- }
1040
- } catch (e) {
1041
- catchFn(e);
1042
- }
1043
- if (!this._isPromise) {
1044
- this._inProgress = void 0;
1045
- }
1274
+ this._sysURL.port = p;
1275
+ }
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()))}`);
1046
1279
  }
1047
- if (this._isPromise) {
1048
- return future.asPromise();
1049
- } else {
1050
- return this.once(fn);
1280
+ return this._sysURL.hostname;
1281
+ }
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()))}`);
1051
1285
  }
1286
+ this._sysURL.hostname = h;
1052
1287
  }
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 });
1288
+ set pathname(p) {
1289
+ this._pathname = p;
1059
1290
  }
1060
- setParam(params) {
1061
- this._map.setParam(params.lru);
1291
+ get pathname() {
1292
+ return this._pathname;
1062
1293
  }
1063
- async asyncGet(key) {
1064
- return this.get(await key());
1294
+ get protocol() {
1295
+ return this._protocol;
1065
1296
  }
1066
- get(key) {
1067
- if (typeof key === "function") {
1068
- key = key();
1069
- }
1070
- let keyed = this._map.get(key);
1071
- if (!keyed) {
1072
- keyed = this.factory(key);
1073
- this._map.set(key, keyed);
1297
+ set protocol(p) {
1298
+ if (!p.endsWith(":")) {
1299
+ p = `${p}:`;
1074
1300
  }
1075
- return keyed;
1301
+ this._protocol = p;
1076
1302
  }
1077
- unget(key) {
1078
- const keyed = this._map.get(key);
1079
- keyed == null ? void 0 : keyed.reset();
1080
- this._map.delete(key);
1303
+ get searchParams() {
1304
+ return this._sysURL.searchParams;
1081
1305
  }
1082
- reset() {
1083
- this._map.forEach((keyed) => keyed.reset());
1084
- this._map.clear();
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}`;
1085
1324
  }
1086
1325
  };
1087
- var KeyedResolvOnce = class extends Keyed {
1088
- constructor(kp = {}) {
1089
- super((key) => new ResolveOnce(key), kp);
1090
- }
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
- };
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()));
1108
1339
  }
1109
- throw new Error("KeyedResolvOnce.values impossible");
1110
- });
1340
+ throw new Error(`unknown object type: ${strURLUri}`);
1341
+ default:
1342
+ throw new Error(`Invalid argument: ${typeof strURLUri}`);
1111
1343
  }
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;
1120
- }
1121
- return isSet(tail.join("."), ref[head]);
1122
- }
1123
- return false;
1124
1344
  }
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;
1345
+ function getParamResult(key, val, msgFn = (key2) => {
1346
+ return `missing parameter: ${key2}`;
1347
+ }) {
1348
+ if (val === void 0) {
1349
+ return Result.Err(msgFn(key));
1141
1350
  }
1142
- return {
1143
- isNodeIsh,
1144
- isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1145
- isDeno,
1146
- isReactNative,
1147
- isCFWorker
1148
- };
1351
+ return Result.Ok(val);
1149
1352
  }
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;
1353
+ var BuildURI = class _BuildURI {
1354
+ // pathname needs this
1355
+ constructor(url) {
1356
+ this._url = url;
1158
1357
  }
1159
- static new(opts) {
1160
- return once.once(() => new _DenoEnvActions(opts));
1358
+ static is(value) {
1359
+ return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
1161
1360
  }
1162
- get _env() {
1163
- return __privateGet(this, _deno).Deno.env;
1361
+ static from(strURLUri, defaultProtocol = "file:") {
1362
+ return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
1164
1363
  }
1165
- register(env) {
1166
- for (const key of env.keys()) {
1167
- this._env.set(key, env.get(key) || "");
1168
- }
1169
- return env;
1364
+ match(other) {
1365
+ return match(this.URI(), URI.from(other));
1170
1366
  }
1171
- active() {
1172
- return runtimeFn().isDeno;
1367
+ port(p) {
1368
+ this._url.port = p;
1369
+ return this;
1173
1370
  }
1174
- keys() {
1175
- return Object.keys(this._env.toObject());
1371
+ hostname(h) {
1372
+ this._url.hostname = h;
1373
+ return this;
1176
1374
  }
1177
- get(key) {
1178
- return this._env.get(key);
1375
+ protocol(p) {
1376
+ if (!p.endsWith(":")) {
1377
+ p = `${p}:`;
1378
+ }
1379
+ this._url.protocol = p;
1380
+ return this;
1179
1381
  }
1180
- set(key, value) {
1181
- if (value) {
1182
- this._env.set(key, value);
1382
+ pathname(p) {
1383
+ this._url.pathname = p;
1384
+ return this;
1385
+ }
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;
1397
+ }
1398
+ return this.appendRelative(p);
1399
+ }
1183
1400
  }
1401
+ this._url = new MutableURL(p.toString());
1402
+ return this;
1184
1403
  }
1185
- delete(key) {
1186
- this._env.delete(key);
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;
1187
1413
  }
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;
1414
+ cleanParams() {
1415
+ for (const key of Array.from(this._url.searchParams.keys())) {
1416
+ this._url.searchParams.delete(key);
1417
+ }
1418
+ return this;
1200
1419
  }
1201
- static new(opts) {
1202
- return once2.once(() => new _NodeEnvActions(opts));
1420
+ delParam(key) {
1421
+ this._url.searchParams.delete(key);
1422
+ return this;
1203
1423
  }
1204
- register(env) {
1205
- for (const key of env.keys()) {
1206
- this._env[key] = env.get(key) || "";
1424
+ defParam(key, str) {
1425
+ if (!this._url.searchParams.has(key)) {
1426
+ this._url.searchParams.set(key, str);
1207
1427
  }
1208
- return env;
1428
+ return this;
1209
1429
  }
1210
- active() {
1211
- return runtimeFn().isNodeIsh;
1430
+ setParam(key, str) {
1431
+ this._url.searchParams.set(key, str);
1432
+ return this;
1212
1433
  }
1213
- keys() {
1214
- return Object.keys(this._env);
1434
+ hasParam(key) {
1435
+ return this._url.searchParams.has(key);
1215
1436
  }
1216
- get(key) {
1217
- return this._env[key];
1437
+ get getParams() {
1438
+ return this._url.searchParams.entries();
1218
1439
  }
1219
- set(key, value) {
1220
- if (value) {
1221
- this._env[key] = value;
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;
1222
1445
  }
1446
+ return falsy2undef(val);
1223
1447
  }
1224
- delete(key) {
1225
- delete this._env[key];
1226
- }
1227
- };
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;
1448
+ getParamResult(key, msgFn) {
1449
+ return getParamResult(key, this.getParam(key), msgFn);
1237
1450
  }
1238
- static new(opts) {
1239
- return once3.once(() => new _BrowserEnvActions(opts));
1451
+ getParamsResult(...keys) {
1452
+ return getParamsResult(keys, this);
1240
1453
  }
1241
- get(key) {
1242
- return this.env.get(key);
1454
+ toString() {
1455
+ this._url.searchParams.sort();
1456
+ return this._url.toString();
1243
1457
  }
1244
- set(key, value) {
1245
- if (value) {
1246
- this.env.set(key, value);
1247
- }
1458
+ toJSON() {
1459
+ return this.toString();
1248
1460
  }
1249
- delete(key) {
1250
- this.env.delete(key);
1461
+ asURL() {
1462
+ return this.URI().asURL();
1251
1463
  }
1252
- keys() {
1253
- return Array.from(this.env.keys());
1464
+ asObj(...strips) {
1465
+ return this.URI().asObj(...strips);
1254
1466
  }
1255
- active() {
1256
- return true;
1467
+ clone() {
1468
+ return _BuildURI.from(this.toString());
1257
1469
  }
1258
- register(env) {
1259
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1260
- const browser = globalThis;
1261
- browser[sym] = env;
1262
- return env;
1470
+ URI() {
1471
+ return URI.from(this._url);
1263
1472
  }
1264
1473
  };
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 || {}));
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
+ };
1272
1482
  }
1273
- static new(opts) {
1274
- return once4.once(() => new _CFEnvActions(opts));
1483
+ match(other) {
1484
+ return match(this, other);
1275
1485
  }
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;
1285
- }
1286
- }
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);
1287
1494
  }
1495
+ for (const [key, value] of fromUrl.getParams) {
1496
+ intoUrl.setParam(key, value);
1497
+ }
1498
+ return intoUrl.URI();
1288
1499
  }
1289
- active() {
1290
- return runtimeFn().isCFWorker;
1291
- }
1292
- register(env) {
1293
- this.env = env;
1294
- for (const key in this.injectOnRegister) {
1295
- env.set(key, this.injectOnRegister[key]);
1296
- }
1297
- return env;
1298
- }
1299
- get(key) {
1300
- return this.cfEnv.get(key);
1301
- }
1302
- set(key, value) {
1303
- if (value) {
1304
- this.cfEnv.set(key, value);
1305
- }
1500
+ static is(value) {
1501
+ return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
1306
1502
  }
1307
- delete(key) {
1308
- this.cfEnv.delete(key);
1503
+ // if no protocol is provided, default to file:
1504
+ static from(strURLUri, defaultProtocol = "file:") {
1505
+ return from((url) => new _URI(url), strURLUri, defaultProtocol);
1309
1506
  }
1310
- keys() {
1311
- return Array.from(this.cfEnv.keys());
1507
+ static fromResult(strURLUri, defaultProtocol = "file:") {
1508
+ return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
1312
1509
  }
1313
- };
1314
-
1315
- // src/types.ts
1316
- var _Required = class {
1317
- constructor() {
1318
- this.type = "REQUIRED";
1510
+ constructor(url) {
1511
+ this._url = url.clone();
1319
1512
  }
1320
- };
1321
- var _Optional = class {
1322
- constructor() {
1323
- this.type = "OPTIONAL";
1513
+ build() {
1514
+ return BuildURI.from(this._url);
1324
1515
  }
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;
1368
- }
1516
+ get hostname() {
1517
+ return this._url.hostname;
1369
1518
  }
1370
- if (errors.length) {
1371
- return Result.Err(msgFn(...errors));
1519
+ // get password(): string {
1520
+ // return this._url.password;
1521
+ // }
1522
+ get port() {
1523
+ return this._url.port;
1372
1524
  }
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");
1525
+ get host() {
1526
+ return this._url.host;
1388
1527
  }
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;
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;
1399
1536
  }
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);
1537
+ get pathname() {
1538
+ return this._url.pathname;
1407
1539
  }
1408
- gets(...kparams) {
1409
- return getParamsResult(kparams, {
1410
- getParam: (k) => this.get(k)
1411
- });
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();
1412
1548
  }
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
- });
1549
+ hasParam(key) {
1550
+ return this._url.searchParams.has(key);
1451
1551
  }
1452
- _updatePresets(presetEnv) {
1453
- if (!presetEnv) {
1454
- return;
1455
- }
1456
- for (const [key, value] of presetEnv) {
1457
- this._map.set(key, value);
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;
1458
1557
  }
1558
+ return falsy2undef(val);
1459
1559
  }
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
- });
1560
+ getParamResult(key, msgFn) {
1561
+ return getParamResult(key, this.getParam(key), msgFn);
1488
1562
  }
1489
- keys() {
1490
- return this._map.keys();
1563
+ getParamsResult(...keys) {
1564
+ return getParamsResult(keys, this);
1491
1565
  }
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]);
1566
+ clone() {
1567
+ return new _URI(this._url);
1497
1568
  }
1498
- get(key) {
1499
- return this._map.get(key);
1569
+ asURL() {
1570
+ return this._url.clone();
1500
1571
  }
1501
- set(key, value) {
1502
- if (!value) {
1503
- return;
1504
- }
1505
- this._map.set(key, value);
1506
- this._applyOnSet(this._onSet, key, value);
1572
+ toString() {
1573
+ return this._url.toString();
1507
1574
  }
1508
- delete(key) {
1509
- this._map.delete(key);
1510
- this._applyOnSet(this._onSet, key);
1511
- }
1512
- };
1513
-
1514
- // src/web/web-sys-abstraction.ts
1515
- var WebFileService = class {
1516
- get baseDir() {
1517
- throw new Error("basedir-Method not implemented.");
1518
- }
1519
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1520
- create(fname) {
1521
- throw new Error("create-Method not implemented.");
1522
- }
1523
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1524
- readFileString(fname) {
1525
- throw new Error("readFileString-Method not implemented.");
1526
- }
1527
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1528
- writeFileString(fname, content) {
1529
- throw new Error("writeFileString-Method not implemented.");
1530
- }
1531
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1532
- abs(fname) {
1533
- throw new Error("abs-Method not implemented.");
1534
- }
1535
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1536
- join(...paths) {
1537
- throw new Error("join-Method not implemented.");
1538
- }
1539
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1540
- relative(from2, to) {
1541
- throw new Error("relative-Method not implemented.");
1542
- }
1543
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1544
- dirname(fname) {
1545
- throw new Error("dirname-Method not implemented.");
1546
- }
1547
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1548
- basename(fname) {
1549
- throw new Error("basename-Method not implemented.");
1550
- }
1551
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1552
- nodeImport(fname) {
1553
- throw new Error("nodeImport-Method not implemented.");
1554
- }
1555
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1556
- isAbsolute(fname) {
1557
- throw new Error("isAbsolute-Method not implemented.");
1558
- }
1559
- };
1560
- var WebSystemService = class {
1561
- Env() {
1562
- return envFactory();
1563
- }
1564
- Args() {
1565
- throw new Error("Args-Method not implemented.");
1566
- }
1567
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1568
- OnExit(hdl) {
1569
- throw new Error("OnExit-Method not implemented.");
1570
- }
1571
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1572
- Exit(code) {
1573
- throw new Error("Exit-Method not implemented.");
1574
- }
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
- });
1584
- }
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;
1599
- }
1600
- 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("");
1575
+ toJSON() {
1576
+ return this.toString();
1616
1577
  }
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;
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
+ });
1637
1592
  }
1638
- this.parts.push(part);
1593
+ return stripper(strips, pathURI);
1639
1594
  }
1640
1595
  };
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;
1679
- }
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);
1689
- }
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;
1723
- }
1724
- }
1725
- return new Path(out).toString();
1726
- }
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));
1746
- }
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;
1752
- }
1753
- }
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
- }
1781
- }
1782
- }
1783
- return ret;
1784
- }
1785
-
1786
- // src/uri.ts
1787
- function match(iref, ioth) {
1788
- const mr = {
1789
- score: 0,
1790
- protocol: false,
1791
- hostname: false,
1792
- port: false,
1793
- pathname: false,
1794
- pathParts: [],
1795
- params: {}
1796
- };
1797
- const ref = URI.from(iref);
1798
- const oth = URI.from(ioth);
1799
- if (ref.protocol === oth.protocol) {
1800
- mr.score += 1;
1801
- mr.protocol = true;
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();
1802
1605
  }
1803
- try {
1804
- const refH = ref.hostname;
1805
- const refP = ref.port;
1806
- if (refH === oth.hostname) {
1807
- mr.score += 1;
1808
- mr.hostname = 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);
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);
1809
1623
  }
1810
- if (refP.length && refP === oth.port) {
1811
- mr.score += 1;
1812
- mr.port = true;
1624
+ if (this._toFlush.length == 0) {
1625
+ this._flushIsRunning = false;
1626
+ this._flushDoneFns.forEach((fn) => fn());
1627
+ this._flushDoneFns = [];
1628
+ return;
1813
1629
  }
1814
- } catch (e) {
1815
- }
1816
- if (ref.pathname.length && ref.pathname !== "/") {
1817
- const pref = ref.pathname.split("/").filter((p) => p.length);
1818
- const poth = oth.pathname.split("/").filter((p) => p.length);
1819
- for (let i = 0; i < pref.length && i < poth.length; i++) {
1820
- if (poth[i] === pref[i]) {
1821
- mr.score += 1;
1822
- mr.pathname = true;
1823
- mr.pathParts.push(pref[i]);
1824
- }
1630
+ if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
1631
+ this._flushIsRunning = true;
1632
+ } else if (!toFlush) {
1633
+ return;
1825
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
+ });
1826
1641
  }
1827
- for (const [key, value] of ref.getParams) {
1828
- if (oth.getParam(key) === value) {
1829
- mr.score += 1;
1830
- mr.params[key] = value;
1642
+ };
1643
+
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;
1831
1650
  }
1651
+ return isSet(tail.join("."), ref[head]);
1832
1652
  }
1833
- return mr;
1653
+ return false;
1834
1654
  }
1835
- function coerceKey(key, def) {
1836
- if (typeof key === "object") {
1837
- const keys = Object.keys(key);
1838
- if (keys.length !== 1) {
1839
- throw new Error(`Invalid key: ${JSON.stringify(key)}`);
1840
- }
1841
- return { key: keys[0], def: key[keys[0]] };
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;
1842
1664
  }
1843
- return { key, def };
1844
- }
1845
- function falsy2undef(value) {
1846
- return value === void 0 || value === null ? void 0 : value;
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;
1671
+ }
1672
+ return {
1673
+ isNodeIsh,
1674
+ isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1675
+ isDeno,
1676
+ isReactNative,
1677
+ isCFWorker
1678
+ };
1847
1679
  }
1848
- function ensureURLWithDefaultProto(url, defaultProtocol) {
1849
- if (!url) {
1850
- return new MutableURL(`${defaultProtocol}//`);
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();
1851
1703
  }
1852
- if (typeof url === "string") {
1853
- try {
1854
- return new MutableURL(url);
1855
- } catch (e) {
1856
- return new MutableURL(`${defaultProtocol}//${url}`);
1857
- }
1858
- } else {
1859
- return new MutableURL(url.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;
1860
1722
  }
1861
- }
1862
- function isURL(value) {
1863
- return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
1864
- }
1865
- var MutableURL = class _MutableURL extends URL {
1866
- constructor(urlStr) {
1867
- super("defect://does.not.exist");
1868
- const partedURL = urlStr.split(":");
1869
- this._hasHostpart = hasHostPartProtocols.has(partedURL[0]);
1870
- let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
1871
- if (!this._hasHostpart) {
1872
- const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
1873
- hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
1874
- }
1875
- try {
1876
- this._sysURL = new URL(hostPartUrl);
1877
- } catch (ie) {
1878
- const e = ie;
1879
- e.message = `${e.message} for URL: ${urlStr}`;
1880
- throw e;
1723
+ static new(opts) {
1724
+ return once.once(() => new _DenoEnvActions(opts));
1725
+ }
1726
+ get _env() {
1727
+ return __privateGet(this, _deno).Deno.env;
1728
+ }
1729
+ register(env) {
1730
+ for (const key of env.keys()) {
1731
+ this._env.set(key, env.get(key) || "");
1881
1732
  }
1882
- this._protocol = `${partedURL[0]}:`;
1883
- if (this._hasHostpart) {
1884
- this._pathname = this._sysURL.pathname;
1885
- } else {
1886
- this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
1733
+ return env;
1734
+ }
1735
+ active() {
1736
+ return runtimeFn().isDeno;
1737
+ }
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);
1887
1747
  }
1888
- this.hash = this._sysURL.hash;
1889
1748
  }
1890
- clone() {
1891
- return new _MutableURL(this.toString());
1749
+ delete(key) {
1750
+ this._env.delete(key);
1892
1751
  }
1893
- get host() {
1894
- if (!this._hasHostpart) {
1895
- throw new Error(
1896
- `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
1897
- );
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;
1764
+ }
1765
+ static new(opts) {
1766
+ return once2.once(() => new _NodeEnvActions(opts));
1767
+ }
1768
+ register(env) {
1769
+ for (const key of env.keys()) {
1770
+ this._env[key] = env.get(key) || "";
1898
1771
  }
1899
- return this._sysURL.host;
1772
+ return env;
1900
1773
  }
1901
- get port() {
1902
- if (!this._hasHostpart) {
1903
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1774
+ active() {
1775
+ return runtimeFn().isNodeIsh;
1776
+ }
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;
1904
1786
  }
1905
- return this._sysURL.port;
1906
1787
  }
1907
- set port(p) {
1908
- if (!this._hasHostpart) {
1909
- throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1910
- }
1911
- this._sysURL.port = p;
1788
+ delete(key) {
1789
+ delete this._env[key];
1790
+ }
1791
+ };
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;
1801
+ }
1802
+ static new(opts) {
1803
+ return once3.once(() => new _BrowserEnvActions(opts));
1912
1804
  }
1913
- get hostname() {
1914
- if (!this._hasHostpart) {
1915
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1916
- }
1917
- return this._sysURL.hostname;
1805
+ get(key) {
1806
+ return this.env.get(key);
1918
1807
  }
1919
- set hostname(h) {
1920
- if (!this._hasHostpart) {
1921
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1808
+ set(key, value) {
1809
+ if (value) {
1810
+ this.env.set(key, value);
1922
1811
  }
1923
- this._sysURL.hostname = h;
1924
1812
  }
1925
- set pathname(p) {
1926
- this._pathname = p;
1813
+ delete(key) {
1814
+ this.env.delete(key);
1927
1815
  }
1928
- get pathname() {
1929
- return this._pathname;
1816
+ keys() {
1817
+ return Array.from(this.env.keys());
1930
1818
  }
1931
- get protocol() {
1932
- return this._protocol;
1819
+ active() {
1820
+ return true;
1933
1821
  }
1934
- set protocol(p) {
1935
- if (!p.endsWith(":")) {
1936
- p = `${p}:`;
1937
- }
1938
- this._protocol = p;
1822
+ register(env) {
1823
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1824
+ const browser = globalThis;
1825
+ browser[sym] = env;
1826
+ return env;
1939
1827
  }
1940
- get searchParams() {
1941
- return this._sysURL.searchParams;
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 || {}));
1942
1836
  }
1943
- toString() {
1944
- let search = "";
1945
- if (this._sysURL.searchParams.size) {
1946
- for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
1947
- search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
1948
- }
1949
- }
1950
- let hostpart = "";
1951
- if (this._hasHostpart) {
1952
- hostpart = this._sysURL.hostname;
1953
- if (this._sysURL.port) {
1954
- hostpart += `:${this._sysURL.port}`;
1955
- }
1956
- if (!this._pathname.startsWith("/")) {
1957
- hostpart += "/";
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;
1849
+ }
1958
1850
  }
1959
1851
  }
1960
- return `${this._protocol}//${hostpart}${this._pathname}${search}`;
1961
1852
  }
1962
- };
1963
- function from(fac, strURLUri, defaultProtocol) {
1964
- switch (typeof falsy2undef(strURLUri)) {
1965
- case "undefined":
1966
- return fac(new MutableURL(`${defaultProtocol}///`));
1967
- case "string":
1968
- return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
1969
- case "object":
1970
- if (BuildURI.is(strURLUri)) {
1971
- return fac(new MutableURL(strURLUri._url.toString()));
1972
- } else if (URI.is(strURLUri)) {
1973
- return fac(new MutableURL(strURLUri._url.toString()));
1974
- } else if (isURL(strURLUri)) {
1975
- return fac(new MutableURL(strURLUri.toString()));
1976
- }
1977
- throw new Error(`unknown object type: ${strURLUri}`);
1978
- default:
1979
- throw new Error(`Invalid argument: ${typeof strURLUri}`);
1853
+ active() {
1854
+ return runtimeFn().isCFWorker;
1980
1855
  }
1981
- }
1982
- function getParamResult(key, val, msgFn = (key2) => {
1983
- return `missing parameter: ${key2}`;
1984
- }) {
1985
- if (val === void 0) {
1986
- return Result.Err(msgFn(key));
1856
+ register(env) {
1857
+ this.env = env;
1858
+ for (const key in this.injectOnRegister) {
1859
+ env.set(key, this.injectOnRegister[key]);
1860
+ }
1861
+ return env;
1987
1862
  }
1988
- return Result.Ok(val);
1989
- }
1990
- var BuildURI = class _BuildURI {
1991
- // pathname needs this
1992
- constructor(url) {
1993
- this._url = url;
1863
+ get(key) {
1864
+ return this.cfEnv.get(key);
1994
1865
  }
1995
- static is(value) {
1996
- return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
1866
+ set(key, value) {
1867
+ if (value) {
1868
+ this.cfEnv.set(key, value);
1869
+ }
1997
1870
  }
1998
- static from(strURLUri, defaultProtocol = "file:") {
1999
- return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
1871
+ delete(key) {
1872
+ this.cfEnv.delete(key);
2000
1873
  }
2001
- match(other) {
2002
- return match(this.URI(), URI.from(other));
1874
+ keys() {
1875
+ return Array.from(this.cfEnv.keys());
2003
1876
  }
2004
- port(p) {
2005
- this._url.port = p;
2006
- return this;
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");
2007
1891
  }
2008
- hostname(h) {
2009
- this._url.hostname = h;
2010
- return this;
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;
2011
1902
  }
2012
- protocol(p) {
2013
- if (!p.endsWith(":")) {
2014
- p = `${p}:`;
2015
- }
2016
- this._url.protocol = p;
2017
- return this;
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);
2018
1910
  }
2019
- pathname(p) {
2020
- this._url.pathname = p;
2021
- return this;
1911
+ gets(...kparams) {
1912
+ return getParamsResult(kparams, {
1913
+ getParam: (k) => this.get(k)
1914
+ });
2022
1915
  }
2023
- // could pass a relative path or a full URL
2024
- // if relative path, it will be appended to the current path
2025
- resolve(p) {
2026
- if (!p) {
2027
- return this;
2028
- }
2029
- if (typeof p === "string") {
2030
- if (!p.match(/^[a-zA-Z0-9]+:/)) {
2031
- if (p.startsWith("/")) {
2032
- this.pathname(p);
2033
- return this;
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
+ }
2034
1951
  }
2035
- return this.appendRelative(p);
2036
1952
  }
2037
- }
2038
- this._url = new MutableURL(p.toString());
2039
- return this;
1953
+ });
2040
1954
  }
2041
- appendRelative(p) {
2042
- const appendUrl = URI.from(p);
2043
- const pathname = "./" + appendUrl.pathname;
2044
- const basePath = this._url.pathname;
2045
- this.pathname(relativePath(basePath, pathname));
2046
- for (const [key, value] of appendUrl.getParams) {
2047
- this.setParam(key, value);
1955
+ _updatePresets(presetEnv) {
1956
+ if (!presetEnv) {
1957
+ return;
2048
1958
  }
2049
- return this;
2050
- }
2051
- cleanParams() {
2052
- for (const key of Array.from(this._url.searchParams.keys())) {
2053
- this._url.searchParams.delete(key);
1959
+ for (const [key, value] of presetEnv) {
1960
+ this._map.set(key, value);
2054
1961
  }
2055
- return this;
2056
- }
2057
- delParam(key) {
2058
- this._url.searchParams.delete(key);
2059
- return this;
2060
1962
  }
2061
- defParam(key, str) {
2062
- if (!this._url.searchParams.has(key)) {
2063
- this._url.searchParams.set(key, str);
2064
- }
2065
- 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
+ });
2066
1991
  }
2067
- setParam(key, str) {
2068
- this._url.searchParams.set(key, str);
2069
- return this;
1992
+ keys() {
1993
+ return this._map.keys();
2070
1994
  }
2071
- hasParam(key) {
2072
- return this._url.searchParams.has(key);
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]);
2073
2000
  }
2074
- get getParams() {
2075
- return this._url.searchParams.entries();
2001
+ get(key) {
2002
+ return this._map.get(key);
2076
2003
  }
2077
- getParam(key, def) {
2078
- const { key: k, def: d } = coerceKey(key, def);
2079
- let val = this._url.searchParams.get(k);
2080
- if (!falsy2undef(val) && d) {
2081
- val = d;
2004
+ set(key, value) {
2005
+ if (!value) {
2006
+ return;
2082
2007
  }
2083
- return falsy2undef(val);
2084
- }
2085
- getParamResult(key, msgFn) {
2086
- return getParamResult(key, this.getParam(key), msgFn);
2087
- }
2088
- getParamsResult(...keys) {
2089
- return getParamsResult(keys, this);
2008
+ this._map.set(key, value);
2009
+ this._applyOnSet(this._onSet, key, value);
2090
2010
  }
2091
- toString() {
2092
- this._url.searchParams.sort();
2093
- return this._url.toString();
2011
+ delete(key) {
2012
+ this._map.delete(key);
2013
+ this._applyOnSet(this._onSet, key);
2094
2014
  }
2095
- toJSON() {
2096
- return this.toString();
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);
2097
2026
  }
2098
- asURL() {
2099
- return this.URI().asURL();
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.");
2100
2030
  }
2101
- asObj(...strips) {
2102
- return this.URI().asObj(...strips);
2031
+ async close() {
2103
2032
  }
2104
- clone() {
2105
- return _BuildURI.from(this.toString());
2033
+ releaseLock() {
2034
+ this._stream.locked = false;
2035
+ this.ready = Promise.resolve(void 0);
2036
+ this.closed = Promise.resolve(void 0);
2106
2037
  }
2107
- URI() {
2108
- return URI.from(this._url);
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();
2109
2057
  }
2110
2058
  };
2111
- var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
2112
- var URI = class _URI {
2113
- static protocolHasHostpart(protocol) {
2114
- protocol = protocol.replace(/:$/, "");
2115
- hasHostPartProtocols.add(protocol);
2116
- return () => {
2117
- hasHostPartProtocols.delete(protocol);
2118
- };
2059
+ var ConsoleWriterStream = class {
2060
+ constructor() {
2061
+ this.locked = false;
2119
2062
  }
2120
- match(other) {
2121
- return match(this, other);
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.");
2122
2066
  }
2123
- // if no protocol is provided, default to file:
2124
- static merge(into, from2, defaultProtocol = "file:") {
2125
- const intoUrl = BuildURI.from(into, defaultProtocol);
2126
- const fromUrl = _URI.from(from2, defaultProtocol);
2127
- intoUrl.protocol(fromUrl.protocol);
2128
- const fPath = fromUrl.pathname;
2129
- if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
2130
- intoUrl.pathname(fromUrl.pathname);
2067
+ close() {
2068
+ return Promise.resolve();
2069
+ }
2070
+ getWriter() {
2071
+ if (this.locked) {
2072
+ throw new Error("Stream is locked");
2131
2073
  }
2132
- for (const [key, value] of fromUrl.getParams) {
2133
- intoUrl.setParam(key, value);
2074
+ this.locked = true;
2075
+ if (!this._writer) {
2076
+ this._writer = new ConsoleWriterStreamDefaultWriter(this);
2134
2077
  }
2135
- return intoUrl.URI();
2078
+ return this._writer;
2136
2079
  }
2137
- static is(value) {
2138
- 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;
2139
2086
  }
2140
- // if no protocol is provided, default to file:
2141
- static from(strURLUri, defaultProtocol = "file:") {
2142
- return from((url) => new _URI(url), strURLUri, defaultProtocol);
2087
+ Env() {
2088
+ return envFactory();
2143
2089
  }
2144
- static fromResult(strURLUri, defaultProtocol = "file:") {
2145
- return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
2090
+ Args() {
2091
+ throw new Error("Args-Method not implemented.");
2146
2092
  }
2147
- constructor(url) {
2148
- this._url = url.clone();
2093
+ Stdout() {
2094
+ return new ConsoleWriterStream();
2149
2095
  }
2150
- build() {
2151
- 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
+ });
2152
2107
  }
2153
- get hostname() {
2154
- 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;
2155
2127
  }
2156
- // get password(): string {
2157
- // return this._url.password;
2158
- // }
2159
- get port() {
2160
- return this._url.port;
2128
+ Env() {
2129
+ return envFactory();
2161
2130
  }
2162
- get host() {
2163
- return this._url.host;
2131
+ Args() {
2132
+ throw new Error("Args-Method not implemented.");
2164
2133
  }
2165
- // get username(): string {
2166
- // return this._url.username;
2167
- // }
2168
- // get search(): string {
2169
- // return this._url.search;
2170
- // }
2171
- get protocol() {
2172
- 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
+ });
2173
2140
  }
2174
- get pathname() {
2175
- 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
+ });
2176
2147
  }
2177
- // get hash(): string {
2178
- // return this._url.hash;
2179
- // }
2180
- // get host(): string {
2181
- // return this._url.host;
2182
- // }
2183
- get getParams() {
2184
- 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;
2185
2186
  }
2186
- hasParam(key) {
2187
- return this._url.searchParams.has(key);
2187
+ Env() {
2188
+ return envFactory();
2188
2189
  }
2189
- getParam(key, def) {
2190
- const { key: k, def: d } = coerceKey(key, def);
2191
- let val = this._url.searchParams.get(k);
2192
- if (!falsy2undef(val) && d) {
2193
- val = d;
2194
- }
2195
- return falsy2undef(val);
2190
+ Args() {
2191
+ return globalThis.Deno.args;
2196
2192
  }
2197
- getParamResult(key, msgFn) {
2198
- return getParamResult(key, this.getParam(key), msgFn);
2193
+ Stdout() {
2194
+ return globalThis.Deno.stdout.writable;
2199
2195
  }
2200
- getParamsResult(...keys) {
2201
- return getParamsResult(keys, this);
2196
+ Stderr() {
2197
+ return globalThis.Deno.stderr.writable;
2202
2198
  }
2203
- clone() {
2204
- 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;
2205
2219
  }
2206
- asURL() {
2207
- return this._url.clone();
2220
+ Env() {
2221
+ return envFactory();
2208
2222
  }
2209
- toString() {
2210
- return this._url.toString();
2223
+ Args() {
2224
+ return this._gthis.process.argv;
2211
2225
  }
2212
- toJSON() {
2213
- return this.toString();
2226
+ Stdout() {
2227
+ return new WritableStream({
2228
+ write: (chunk) => {
2229
+ this._gthis.process.stdout.write(chunk);
2230
+ }
2231
+ });
2214
2232
  }
2215
- asObj(...strips) {
2216
- const pathURI = {
2217
- style: "path",
2218
- protocol: this.protocol,
2219
- pathname: this.pathname,
2220
- searchParams: Object.fromEntries(this.getParams)
2221
- };
2222
- if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
2223
- return stripper(strips, {
2224
- ...pathURI,
2225
- style: "host",
2226
- hostname: this.hostname,
2227
- port: this.port
2228
- });
2229
- }
2230
- return stripper(strips, pathURI);
2233
+ Stderr() {
2234
+ return new WritableStream({
2235
+ write: (chunk) => {
2236
+ this._gthis.process.stderr.write(chunk);
2237
+ }
2238
+ });
2231
2239
  }
2232
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
+ }
2233
2254
 
2234
- // src/utils/console-write-stream.ts
2235
- var ConsoleWriterStreamDefaultWriter = class {
2236
- constructor(stream) {
2237
- this.stream = stream;
2238
- this.desiredSize = null;
2239
- this.decoder = new TextDecoder();
2240
- this._stream = stream;
2241
- this.ready = Promise.resolve(void 0);
2242
- 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();
2243
2259
  }
2244
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
2245
- abort(reason) {
2246
- throw new Error("Method not implemented.");
2260
+ Sleep(duration) {
2261
+ return new Promise((resolve) => {
2262
+ setTimeout(() => {
2263
+ resolve();
2264
+ }, duration);
2265
+ });
2247
2266
  }
2248
- async close() {
2267
+ };
2268
+ var ConstTime = class extends Time {
2269
+ Now() {
2270
+ return new Date(2021, 1, 1, 0, 0, 0, 0);
2249
2271
  }
2250
- releaseLock() {
2251
- this._stream.locked = false;
2252
- this.ready = Promise.resolve(void 0);
2253
- this.closed = Promise.resolve(void 0);
2272
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2273
+ Sleep(duration) {
2274
+ return Promise.resolve();
2254
2275
  }
2255
- write(chunk) {
2256
- let strObj = this.decoder.decode(chunk).trimEnd();
2257
- let output = "log";
2258
- try {
2259
- strObj = JSON.parse(strObj);
2260
- output = strObj.level;
2261
- } 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);
2262
2286
  }
2263
- switch (output) {
2264
- case "error":
2265
- console.error(strObj);
2266
- break;
2267
- case "warn":
2268
- console.warn(strObj);
2269
- break;
2270
- default:
2271
- console.log(strObj);
2287
+ if (steps < 1) {
2288
+ this._step = new Date(this._start.getTime() + steps * -1e3);
2272
2289
  }
2290
+ return this._step;
2291
+ }
2292
+ Sleep(duration) {
2293
+ this._step = new Date(this._step.getTime() + duration);
2273
2294
  return Promise.resolve();
2274
2295
  }
2275
2296
  };
2276
- var ConsoleWriterStream = class {
2277
- constructor() {
2278
- 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();
2279
2305
  }
2280
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
2281
- abort(reason) {
2282
- 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;
2283
2312
  }
2284
- close() {
2285
- 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
+ }
2286
2325
  }
2287
- getWriter() {
2288
- if (this.locked) {
2289
- 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;
2290
2332
  }
2291
- this.locked = true;
2292
- if (!this._writer) {
2293
- 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");
2294
2345
  }
2295
- return this._writer;
2296
2346
  }
2297
2347
  };
2298
-
2299
- // src/log-writer-impl.ts
2300
- var LogWriterStream = class {
2301
- constructor(out) {
2302
- this._toFlush = [];
2303
- this._flushIsRunning = false;
2304
- this._flushDoneFns = [];
2305
- 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;
2306
2355
  }
2307
- write(encoded) {
2308
- const my2 = async () => {
2309
- try {
2310
- const writer = this._out.getWriter();
2311
- await writer.ready;
2312
- await writer.write(encoded);
2313
- writer.releaseLock();
2314
- } catch (err) {
2315
- console.error("Chunk error:", err);
2316
- }
2317
- };
2318
- this._toFlush.push(my2);
2319
- 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");
2320
2370
  }
2321
- _flush(toFlush = void 0, done) {
2322
- if (done) {
2323
- 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);
2324
2380
  }
2325
- if (this._toFlush.length == 0) {
2326
- this._flushIsRunning = false;
2327
- this._flushDoneFns.forEach((fn) => fn());
2328
- this._flushDoneFns = [];
2329
- return;
2381
+ if (params.IdMode) {
2382
+ this._idService = new IdService(params.IdMode);
2330
2383
  }
2331
- if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
2332
- this._flushIsRunning = true;
2333
- } else if (!toFlush) {
2334
- return;
2384
+ if (params.RandomMode) {
2385
+ this._randomService = new RandomService(params.RandomMode);
2335
2386
  }
2336
- const my2 = this._toFlush.shift();
2337
- my2 == null ? void 0 : my2().catch((e) => {
2338
- console.error("Flush error:", e);
2339
- }).finally(() => {
2340
- this._flush(this._toFlush);
2341
- });
2342
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
+ // }
2343
2415
  };
2344
2416
 
2345
2417
  // src/logger-impl.ts
@@ -2392,7 +2464,7 @@ var LoggerImpl = class _LoggerImpl {
2392
2464
  params = {};
2393
2465
  }
2394
2466
  if (!params.sys) {
2395
- this._sys = WebSysAbstraction();
2467
+ this._sys = BasicSysAbstractionFactory();
2396
2468
  } else {
2397
2469
  this._sys = params.sys;
2398
2470
  }
@@ -2410,18 +2482,7 @@ var LoggerImpl = class _LoggerImpl {
2410
2482
  this._logWriter = params.logWriter;
2411
2483
  } else {
2412
2484
  if (!params.out) {
2413
- const rt = runtimeFn();
2414
- let stream;
2415
- if (rt.isBrowser) {
2416
- stream = new ConsoleWriterStream();
2417
- } else {
2418
- if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
2419
- stream = this._sys.Stdout();
2420
- } else {
2421
- throw new Error("No output defined for runtime");
2422
- }
2423
- }
2424
- this._logWriter = new LogWriterStream(stream);
2485
+ this._logWriter = new LogWriterStream(this._sys.Stdout());
2425
2486
  } else {
2426
2487
  this._logWriter = new LogWriterStream(params.out);
2427
2488
  }