@adviser/cement 0.3.20 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/base-sys-abstraction-DgTynXGV.d.cts +95 -0
  2. package/base-sys-abstraction-h0dB3nZ5.d.ts +95 -0
  3. package/cf/index.cjs +232 -283
  4. package/cf/index.cjs.map +1 -1
  5. package/cf/index.d.cts +10 -8
  6. package/cf/index.d.ts +10 -8
  7. package/cf/index.js +6 -41
  8. package/cf/index.js.map +1 -1
  9. package/{chunk-PHS255C5.js → chunk-FOALXQST.js} +1 -68
  10. package/chunk-FOALXQST.js.map +1 -0
  11. package/{chunk-UEER5ZC2.js → chunk-NPMIRK4R.js} +8 -22
  12. package/chunk-NPMIRK4R.js.map +1 -0
  13. package/{chunk-23MCJYE6.js → chunk-X3IV2RYT.js} +422 -602
  14. package/chunk-X3IV2RYT.js.map +1 -0
  15. package/chunk-YKGCONBX.js +677 -0
  16. package/chunk-YKGCONBX.js.map +1 -0
  17. package/{chunk-55W4AK2Z.js → chunk-YVACAIUX.js} +5 -5
  18. package/deno/index.cjs +257 -241
  19. package/deno/index.cjs.map +1 -1
  20. package/deno/index.d.cts +3 -5
  21. package/deno/index.d.ts +3 -5
  22. package/deno/index.js +14 -16
  23. package/deno/index.js.map +1 -1
  24. package/{index-BhmvYS_t.d.ts → index-N0bkrgSt.d.ts} +2 -2
  25. package/{index-DoK1OTgQ.d.cts → index-TtYD7HhB.d.cts} +2 -2
  26. package/index.cjs +1935 -1806
  27. package/index.cjs.map +1 -1
  28. package/index.d.cts +15 -8
  29. package/index.d.ts +15 -8
  30. package/index.js +58 -16
  31. package/index.js.map +1 -1
  32. package/metafile-cjs.json +1 -1
  33. package/metafile-esm.json +1 -1
  34. package/node/index.cjs +499 -474
  35. package/node/index.cjs.map +1 -1
  36. package/node/index.d.cts +3 -5
  37. package/node/index.d.ts +3 -5
  38. package/node/index.js +14 -16
  39. package/node/index.js.map +1 -1
  40. package/package.json +5 -5
  41. package/src/base-sys-abstraction.ts +106 -116
  42. package/src/cf/cf-basic-sys-abstraction.ts +79 -0
  43. package/src/cf/index.ts +1 -1
  44. package/src/cf-test-main.ts +10 -1
  45. package/src/coerce-binary.ts +39 -0
  46. package/src/deno/deno-basic-sys-abstraction.ts +39 -0
  47. package/src/deno/deno-file-service.ts +1 -1
  48. package/src/deno/deno-sys-abstraction.ts +19 -22
  49. package/src/index.ts +1 -0
  50. package/src/jsr.json +1 -1
  51. package/src/log-writer-impl.ts +6 -0
  52. package/src/logger-impl.ts +18 -20
  53. package/src/node/node-basic-sys-abstraction.ts +59 -0
  54. package/src/node/node-sys-abstraction.ts +19 -22
  55. package/src/sys-abstraction.ts +12 -6
  56. package/src/test/mock-logger.ts +2 -2
  57. package/src/txt-en-decoder.ts +3 -3
  58. package/src/web/index.ts +1 -1
  59. package/src/web/web-basic-sys-abstraction.ts +105 -0
  60. package/{sys-abstraction-B0x6IE7r.d.ts → sys-abstraction-CeAxxg9H.d.ts} +11 -7
  61. package/{sys-abstraction-BTs3Vzy4.d.cts → sys-abstraction-DDAwGTnk.d.cts} +11 -7
  62. package/test/index.cjs +1146 -1085
  63. package/test/index.cjs.map +1 -1
  64. package/test/index.d.cts +2 -2
  65. package/test/index.d.ts +2 -2
  66. package/test/index.js +4 -5
  67. package/ts/smoke/smoke.js +7 -8
  68. package/ts/smoke/smoke.js.map +1 -1
  69. package/ts/src/base-basic-sys-abstraction.test.d.ts +2 -0
  70. package/ts/src/base-basic-sys-abstraction.test.d.ts.map +1 -0
  71. package/ts/src/{base-sys-abstraction.test.js → base-basic-sys-abstraction.test.js} +9 -9
  72. package/ts/src/base-basic-sys-abstraction.test.js.map +1 -0
  73. package/ts/src/base-sys-abstraction.d.ts +33 -21
  74. package/ts/src/base-sys-abstraction.d.ts.map +1 -1
  75. package/ts/src/base-sys-abstraction.js +54 -67
  76. package/ts/src/base-sys-abstraction.js.map +1 -1
  77. package/ts/src/cf/cf-basic-sys-abstraction.d.ts +14 -0
  78. package/ts/src/cf/cf-basic-sys-abstraction.d.ts.map +1 -0
  79. package/ts/src/cf/cf-basic-sys-abstraction.js +67 -0
  80. package/ts/src/cf/cf-basic-sys-abstraction.js.map +1 -0
  81. package/ts/src/cf/index.d.ts +1 -1
  82. package/ts/src/cf/index.d.ts.map +1 -1
  83. package/ts/src/cf/index.js +1 -1
  84. package/ts/src/cf/index.js.map +1 -1
  85. package/ts/src/cf-test-main.d.ts.map +1 -1
  86. package/ts/src/cf-test-main.js +7 -1
  87. package/ts/src/cf-test-main.js.map +1 -1
  88. package/ts/src/coerce-binary.d.ts +6 -0
  89. package/ts/src/coerce-binary.d.ts.map +1 -0
  90. package/ts/src/coerce-binary.js +32 -0
  91. package/ts/src/coerce-binary.js.map +1 -0
  92. package/ts/src/coerce-binary.test.d.ts +2 -0
  93. package/ts/src/coerce-binary.test.d.ts.map +1 -0
  94. package/ts/src/coerce-binary.test.js +39 -0
  95. package/ts/src/coerce-binary.test.js.map +1 -0
  96. package/ts/src/deno/deno-basic-sys-abstraction.d.ts +14 -0
  97. package/ts/src/deno/deno-basic-sys-abstraction.d.ts.map +1 -0
  98. package/ts/src/deno/deno-basic-sys-abstraction.js +35 -0
  99. package/ts/src/deno/deno-basic-sys-abstraction.js.map +1 -0
  100. package/ts/src/deno/deno-file-service.d.ts +1 -1
  101. package/ts/src/deno/deno-file-service.d.ts.map +1 -1
  102. package/ts/src/deno/deno-sys-abstraction.d.ts +3 -6
  103. package/ts/src/deno/deno-sys-abstraction.d.ts.map +1 -1
  104. package/ts/src/deno/deno-sys-abstraction.js +13 -17
  105. package/ts/src/deno/deno-sys-abstraction.js.map +1 -1
  106. package/ts/src/index.d.ts +1 -0
  107. package/ts/src/index.d.ts.map +1 -1
  108. package/ts/src/index.js +1 -0
  109. package/ts/src/index.js.map +1 -1
  110. package/ts/src/log-writer-impl.d.ts +1 -0
  111. package/ts/src/log-writer-impl.d.ts.map +1 -1
  112. package/ts/src/log-writer-impl.js +1 -0
  113. package/ts/src/log-writer-impl.js.map +1 -1
  114. package/ts/src/logger-impl.d.ts +4 -4
  115. package/ts/src/logger-impl.d.ts.map +1 -1
  116. package/ts/src/logger-impl.js +4 -19
  117. package/ts/src/logger-impl.js.map +1 -1
  118. package/ts/src/logger.test.js +3 -4
  119. package/ts/src/logger.test.js.map +1 -1
  120. package/ts/src/node/node-basic-sys-abstraction.d.ts +25 -0
  121. package/ts/src/node/node-basic-sys-abstraction.d.ts.map +1 -0
  122. package/ts/src/node/node-basic-sys-abstraction.js +44 -0
  123. package/ts/src/node/node-basic-sys-abstraction.js.map +1 -0
  124. package/ts/src/node/node-sys-abstraction.d.ts +3 -6
  125. package/ts/src/node/node-sys-abstraction.d.ts.map +1 -1
  126. package/ts/src/node/node-sys-abstraction.js +13 -17
  127. package/ts/src/node/node-sys-abstraction.js.map +1 -1
  128. package/ts/src/node/node-sys-abstraction.test.js +1 -1
  129. package/ts/src/node/node-sys-abstraction.test.js.map +1 -1
  130. package/ts/src/sys-abstraction.d.ts +10 -6
  131. package/ts/src/sys-abstraction.d.ts.map +1 -1
  132. package/ts/src/test/mock-logger.d.ts +2 -2
  133. package/ts/src/test/mock-logger.d.ts.map +1 -1
  134. package/ts/src/test/mock-logger.js.map +1 -1
  135. package/ts/src/tracer.test.js +5 -8
  136. package/ts/src/tracer.test.js.map +1 -1
  137. package/ts/src/txt-en-decoder.d.ts.map +1 -1
  138. package/ts/src/txt-en-decoder.js +3 -3
  139. package/ts/src/txt-en-decoder.js.map +1 -1
  140. package/ts/src/web/index.d.ts +1 -1
  141. package/ts/src/web/index.d.ts.map +1 -1
  142. package/ts/src/web/index.js +1 -1
  143. package/ts/src/web/index.js.map +1 -1
  144. package/ts/src/web/web-basic-sys-abstraction.d.ts +4 -0
  145. package/ts/src/web/web-basic-sys-abstraction.d.ts.map +1 -0
  146. package/ts/src/web/web-basic-sys-abstraction.js +45 -0
  147. package/ts/src/web/web-basic-sys-abstraction.js.map +1 -0
  148. package/utils/index.cjs +132 -3
  149. package/utils/index.cjs.map +1 -1
  150. package/utils/index.js +5 -5
  151. package/web/index.cjs +277 -281
  152. package/web/index.cjs.map +1 -1
  153. package/web/index.d.cts +4 -17
  154. package/web/index.d.ts +4 -17
  155. package/web/index.js +4 -7
  156. package/base-sys-abstraction-BnBZ6zd0.d.ts +0 -84
  157. package/base-sys-abstraction-DAZ8tx5F.d.cts +0 -84
  158. package/chunk-23MCJYE6.js.map +0 -1
  159. package/chunk-H6MLKWIZ.js +0 -88
  160. package/chunk-H6MLKWIZ.js.map +0 -1
  161. package/chunk-LXTKPZ6M.js +0 -255
  162. package/chunk-LXTKPZ6M.js.map +0 -1
  163. package/chunk-PHS255C5.js.map +0 -1
  164. package/chunk-UEER5ZC2.js.map +0 -1
  165. package/src/cf/cf-sys-abstraction.ts +0 -34
  166. package/src/web/web-sys-abstraction.ts +0 -80
  167. package/ts/src/base-sys-abstraction.test.d.ts +0 -2
  168. package/ts/src/base-sys-abstraction.test.d.ts.map +0 -1
  169. package/ts/src/base-sys-abstraction.test.js.map +0 -1
  170. package/ts/src/cf/cf-sys-abstraction.d.ts +0 -11
  171. package/ts/src/cf/cf-sys-abstraction.d.ts.map +0 -1
  172. package/ts/src/cf/cf-sys-abstraction.js +0 -30
  173. package/ts/src/cf/cf-sys-abstraction.js.map +0 -1
  174. package/ts/src/web/web-sys-abstraction.d.ts +0 -18
  175. package/ts/src/web/web-sys-abstraction.d.ts.map +0 -1
  176. package/ts/src/web/web-sys-abstraction.js +0 -64
  177. package/ts/src/web/web-sys-abstraction.js.map +0 -1
  178. /package/{chunk-55W4AK2Z.js.map → chunk-YVACAIUX.js.map} +0 -0
package/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,947 +887,65 @@ 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();
667
- }
668
- };
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,
677
- };
678
-
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);
713
- }
714
- return this._step;
715
- }
716
- Sleep(duration) {
717
- this._step = new Date(this._step.getTime() + duration);
718
- return Promise.resolve();
719
- }
720
- };
721
- function TimeFactory(timeMode) {
722
- switch (timeMode) {
723
- case TimeMode.REAL:
724
- return new SysTime();
725
- case TimeMode.CONST:
726
- return new ConstTime();
727
- case TimeMode.STEP:
728
- return new StepTime();
729
- }
730
- return new SysTime();
731
- }
732
- var RandomService = class {
733
- constructor(mode) {
734
- this._step = 0;
735
- this._mode = mode;
736
- }
737
- Random0ToValue(value) {
738
- switch (this._mode) {
739
- case RandomMode.CONST:
740
- return 0.5 * value;
741
- case RandomMode.STEP:
742
- this._step += 1e-4;
743
- return this._step * value;
744
- case RandomMode.RANDOM:
745
- return Math.random() * value;
746
- default:
747
- throw new Error("Unknown RandomMode");
748
- }
749
- }
750
- };
751
- var IdService = class {
752
- constructor(mode) {
753
- this._step = 0;
754
- if (!mode) {
755
- mode = IDMode.UUID;
756
- }
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");
769
- }
770
- }
771
- };
772
- function consumeReadableStream(reader, writeFn) {
773
- reader.read().then(({ done, value }) => {
774
- if (done) {
775
- return;
776
- }
777
- writeFn(value).then(() => {
778
- consumeReadableStream(reader, writeFn);
779
- }).catch((e) => {
780
- console.error("consumeReadableStream:writeFn", e);
781
- });
782
- }).catch((e) => {
783
- console.error("consumeReadableStream:read", e);
784
- });
785
- }
786
- function CFWriteableStream(writeFn) {
787
- const ts = new TransformStream();
788
- consumeReadableStream(ts.readable.getReader(), writeFn);
789
- return ts.writable;
790
- }
791
- var BaseSysAbstraction = class {
792
- constructor(params) {
793
- this._time = new SysTime();
794
- this._idService = new IdService();
795
- this._randomService = new RandomService(RandomMode.RANDOM);
796
- this._fileSystem = params.FileSystem;
797
- this._systemService = params.SystemService;
798
- this._txtEnDe = params.TxtEnDecoder;
799
- const decoder = this._txtEnDe;
800
- this._stdout = CFWriteableStream((chunk) => {
801
- const decoded = decoder.decode(chunk);
802
- console.log(decoded.trimEnd());
803
- return Promise.resolve();
804
- });
805
- this._stderr = CFWriteableStream((chunk) => {
806
- const decoded = decoder.decode(chunk);
807
- console.error(decoded.trimEnd());
808
- return Promise.resolve();
809
- });
810
- }
811
- };
812
- var WrapperSysAbstraction = class {
813
- constructor(base, params) {
814
- this._time = base._time;
815
- this._stdout = base._stdout;
816
- this._stderr = base._stderr;
817
- this._idService = base._idService;
818
- this._randomService = base._randomService;
819
- this._fileSystem = base._fileSystem;
820
- this._systemService = base._systemService;
821
- if (params) {
822
- if (params.TimeMode) {
823
- this._time = TimeFactory(params.TimeMode);
824
- }
825
- if (params.Stdout) {
826
- this._stdout = params.Stdout;
827
- }
828
- if (params.Stderr) {
829
- this._stderr = params.Stderr;
830
- }
831
- if (params.IdMode) {
832
- this._idService = new IdService(params.IdMode);
833
- }
834
- if (params.RandomMode) {
835
- this._randomService = new RandomService(params.RandomMode);
836
- }
837
- if (params.FileSystem) {
838
- this._fileSystem = params.FileSystem;
839
- }
840
- if (params.SystemService) {
841
- this._systemService = params.SystemService;
842
- }
843
- }
844
- }
845
- Time() {
846
- return this._time;
847
- }
848
- NextId() {
849
- return this._idService.NextId();
850
- }
851
- Random0ToValue(value) {
852
- return this._randomService.Random0ToValue(value);
853
- }
854
- Stdout() {
855
- return this._stdout;
856
- }
857
- Stderr() {
858
- return this._stderr;
859
- }
860
- System() {
861
- return this._systemService;
862
- }
863
- FileSystem() {
864
- return this._fileSystem;
865
- }
866
- };
867
-
868
- // src/lru-map-set.ts
869
- var LRUMap = class {
870
- constructor(c = {}) {
871
- this._map = /* @__PURE__ */ new Map();
872
- this.param = {
873
- maxEntries: c.maxEntries || 100,
874
- maxAge: c.maxAge || 0
875
- };
876
- }
877
- touch(key) {
878
- if (!this._map.has(key)) {
879
- throw new Error(`key not found in cache: ${key}`);
880
- }
881
- const value = this._map.get(key);
882
- this._map.delete(key);
883
- this._map.set(key, value);
884
- return value;
885
- }
886
- setParam(param2 = {}) {
887
- if (typeof param2.maxEntries === "number") {
888
- this.param.maxEntries = param2.maxEntries;
889
- if (param2.maxEntries > 0 && this._map.size > param2.maxEntries) {
890
- const toDelete = [];
891
- let cacheSize = this._map.size;
892
- for (const key of this._map.keys()) {
893
- if (cacheSize > param2.maxEntries) {
894
- toDelete.push(key);
895
- cacheSize--;
896
- } else {
897
- break;
898
- }
899
- }
900
- for (const key of toDelete) {
901
- this._map.delete(key);
902
- }
903
- }
904
- }
905
- }
906
- has(key) {
907
- return this._map.has(key);
908
- }
909
- get size() {
910
- return this._map.size;
911
- }
912
- async getSet(key, createFN) {
913
- const val = this.get(key);
914
- if (val) {
915
- return val;
916
- } else {
917
- const val2 = await createFN(key);
918
- this.set(key, val2);
919
- return val2;
920
- }
921
- }
922
- get(key) {
923
- if (this._map.has(key)) {
924
- return this.touch(key);
925
- }
926
- return this._map.get(key);
927
- }
928
- set(key, value) {
929
- this._map.delete(key);
930
- if (this.param.maxEntries > 0 && this._map.size >= this.param.maxEntries) {
931
- this._map.delete(this._map.keys().next().value);
932
- this._map.set(key, value);
933
- } else {
934
- this._map.set(key, value);
935
- }
936
- }
937
- delete(key) {
938
- this._map.delete(key);
939
- }
940
- clear() {
941
- this._map.clear();
942
- }
943
- forEach(callbackfn) {
944
- this._map.forEach(callbackfn);
945
- }
946
- entries() {
947
- return this._map.entries();
948
- }
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;
970
- }
971
- get ready() {
972
- return this._onceDone;
973
- }
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;
986
- }
987
- }
988
- // T extends Option<infer U> ? U : T
989
- once(fn) {
990
- if (this._onceDone) {
991
- if (this._onceError) {
992
- if (this._isPromise) {
993
- return Promise.reject(this._onceError);
994
- } else {
995
- throw this._onceError;
996
- }
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");
1006
- }
1007
- const future = new Future();
1008
- this._onceFutures.push(future);
1009
- if (this._onceFutures.length === 1) {
1010
- const okFn = (value) => {
1011
- this._onceValue = value;
1012
- this._onceOk = true;
1013
- this._onceDone = true;
1014
- if (this._isPromise) {
1015
- this._onceFutures.forEach((f) => f.resolve(this._onceValue));
1016
- }
1017
- this._onceFutures.length = 0;
1018
- };
1019
- const catchFn = (e) => {
1020
- this._onceError = e;
1021
- this._onceOk = false;
1022
- this._onceValue = void 0;
1023
- this._onceDone = true;
1024
- if (this._isPromise) {
1025
- this._onceFutures.forEach((f) => f.reject(this._onceError));
1026
- }
1027
- this._onceFutures.length = 0;
1028
- };
1029
- this._inProgress = future;
1030
- try {
1031
- const ret = fn(this.ctx);
1032
- if (typeof ret.then === "function") {
1033
- this._isPromise = true;
1034
- ret.then(okFn).catch(catchFn).finally(() => {
1035
- this._inProgress = void 0;
1036
- });
1037
- } else {
1038
- okFn(ret);
1039
- }
1040
- } catch (e) {
1041
- catchFn(e);
1042
- }
1043
- if (!this._isPromise) {
1044
- this._inProgress = void 0;
1045
- }
1046
- }
1047
- if (this._isPromise) {
1048
- return future.asPromise();
1049
- } else {
1050
- return this.once(fn);
1051
- }
1052
- }
1053
- };
1054
- var Keyed = class {
1055
- constructor(factory, params) {
1056
- var _a;
1057
- this.factory = factory;
1058
- this._map = new LRUMap((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
1059
- }
1060
- setParam(params) {
1061
- this._map.setParam(params.lru);
1062
- }
1063
- async asyncGet(key) {
1064
- return this.get(await key());
1065
- }
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);
1074
- }
1075
- return keyed;
1076
- }
1077
- unget(key) {
1078
- const keyed = this._map.get(key);
1079
- keyed == null ? void 0 : keyed.reset();
1080
- this._map.delete(key);
1081
- }
1082
- reset() {
1083
- this._map.forEach((keyed) => keyed.reset());
1084
- this._map.clear();
1085
- }
1086
- };
1087
- var KeyedResolvOnce = class extends Keyed {
1088
- constructor(kp = {}) {
1089
- super((key) => new ResolveOnce(key), kp);
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
- };
1108
- }
1109
- throw new Error("KeyedResolvOnce.values impossible");
1110
- });
1111
- }
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
- }
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;
1141
- }
1142
- return {
1143
- isNodeIsh,
1144
- isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1145
- isDeno,
1146
- isReactNative,
1147
- isCFWorker
1148
- };
1149
- }
1150
-
1151
- // src/deno/deno-env-actions.ts
1152
- var once = new ResolveOnce();
1153
- var _deno;
1154
- var _DenoEnvActions = class _DenoEnvActions {
1155
- constructor(opts) {
1156
- __privateAdd(this, _deno, globalThis);
1157
- this.opts = opts;
1158
- }
1159
- static new(opts) {
1160
- return once.once(() => new _DenoEnvActions(opts));
1161
- }
1162
- get _env() {
1163
- return __privateGet(this, _deno).Deno.env;
1164
- }
1165
- register(env) {
1166
- for (const key of env.keys()) {
1167
- this._env.set(key, env.get(key) || "");
1168
- }
1169
- return env;
1170
- }
1171
- active() {
1172
- return runtimeFn().isDeno;
1173
- }
1174
- keys() {
1175
- return Object.keys(this._env.toObject());
1176
- }
1177
- get(key) {
1178
- return this._env.get(key);
1179
- }
1180
- set(key, value) {
1181
- if (value) {
1182
- this._env.set(key, value);
1183
- }
1184
- }
1185
- delete(key) {
1186
- this._env.delete(key);
1187
- }
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;
1200
- }
1201
- static new(opts) {
1202
- return once2.once(() => new _NodeEnvActions(opts));
1203
- }
1204
- register(env) {
1205
- for (const key of env.keys()) {
1206
- this._env[key] = env.get(key) || "";
1207
- }
1208
- return env;
1209
- }
1210
- active() {
1211
- return runtimeFn().isNodeIsh;
1212
- }
1213
- keys() {
1214
- return Object.keys(this._env);
1215
- }
1216
- get(key) {
1217
- return this._env[key];
1218
- }
1219
- set(key, value) {
1220
- if (value) {
1221
- this._env[key] = value;
1222
- }
1223
- }
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;
1237
- }
1238
- static new(opts) {
1239
- return once3.once(() => new _BrowserEnvActions(opts));
1240
- }
1241
- get(key) {
1242
- return this.env.get(key);
1243
- }
1244
- set(key, value) {
1245
- if (value) {
1246
- this.env.set(key, value);
1247
- }
1248
- }
1249
- delete(key) {
1250
- this.env.delete(key);
1251
- }
1252
- keys() {
1253
- return Array.from(this.env.keys());
1254
- }
1255
- active() {
1256
- return true;
1257
- }
1258
- register(env) {
1259
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1260
- const browser = globalThis;
1261
- browser[sym] = env;
1262
- return env;
1263
- }
1264
- };
1265
-
1266
- // src/cf/cf-env-actions.ts
1267
- var once4 = new ResolveOnce();
1268
- var CFEnvActions = class _CFEnvActions {
1269
- constructor(env) {
1270
- this.injectOnRegister = {};
1271
- this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
1272
- }
1273
- static new(opts) {
1274
- return once4.once(() => new _CFEnvActions(opts));
1275
- }
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
- }
1287
- }
1288
- }
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
- }
1306
- }
1307
- delete(key) {
1308
- this.cfEnv.delete(key);
1309
- }
1310
- keys() {
1311
- return Array.from(this.cfEnv.keys());
1312
- }
1313
- };
1314
-
1315
- // src/types.ts
1316
- var _Required = class {
1317
- constructor() {
1318
- this.type = "REQUIRED";
1319
- }
1320
- };
1321
- var _Optional = class {
1322
- constructor() {
1323
- this.type = "OPTIONAL";
1324
- }
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
- }
1369
- }
1370
- if (errors.length) {
1371
- return Result.Err(msgFn(...errors));
1372
- }
1373
- return Result.Ok(result);
1374
- }
1375
-
1376
- // src/sys-env.ts
1377
- var envActions = [
1378
- { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1379
- { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1380
- { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1381
- { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
1382
- ];
1383
- var _envFactories = new KeyedResolvOnce();
1384
- function envFactory(opts = {}) {
1385
- const found = envActions.find((fi) => fi.fn(opts).active());
1386
- if (!found) {
1387
- throw new Error("SysContainer:envFactory: no env available");
1388
- }
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;
1399
- }
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);
1407
- }
1408
- gets(...kparams) {
1409
- return getParamsResult(kparams, {
1410
- getParam: (k) => this.get(k)
1411
- });
1412
- }
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
- });
1451
- }
1452
- _updatePresets(presetEnv) {
1453
- if (!presetEnv) {
1454
- return;
1455
- }
1456
- for (const [key, value] of presetEnv) {
1457
- this._map.set(key, value);
1458
- }
896
+ var _Optional = class {
897
+ constructor() {
898
+ this.type = "OPTIONAL";
1459
899
  }
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();
900
+ };
901
+ var param = {
902
+ REQUIRED: new _Required(),
903
+ OPTIONAL: new _Optional()
904
+ };
905
+
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
+ );
1467
920
  }
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;
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);
1484
939
  }
1485
- item.fn(k, v);
1486
- });
1487
- });
1488
- }
1489
- keys() {
1490
- return this._map.keys();
1491
- }
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]);
1497
- }
1498
- get(key) {
1499
- return this._map.get(key);
1500
- }
1501
- set(key, value) {
1502
- if (!value) {
1503
- return;
940
+ }
941
+ } else {
942
+ result[kd.key] = val;
1504
943
  }
1505
- this._map.set(key, value);
1506
- this._applyOnSet(this._onSet, key, value);
1507
- }
1508
- delete(key) {
1509
- this._map.delete(key);
1510
- this._applyOnSet(this._onSet, key);
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
944
  }
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
- });
945
+ if (errors.length) {
946
+ return Result.Err(msgFn(...errors));
1584
947
  }
1585
- return new WrapperSysAbstraction(my, param2);
948
+ return Result.Ok(result);
1586
949
  }
1587
950
 
1588
951
  // src/utils/relative-path.ts
@@ -2038,42 +1401,154 @@ var BuildURI = class _BuildURI {
2038
1401
  this._url = new MutableURL(p.toString());
2039
1402
  return this;
2040
1403
  }
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);
2048
- }
2049
- return this;
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;
1413
+ }
1414
+ cleanParams() {
1415
+ for (const key of Array.from(this._url.searchParams.keys())) {
1416
+ this._url.searchParams.delete(key);
1417
+ }
1418
+ return this;
1419
+ }
1420
+ delParam(key) {
1421
+ this._url.searchParams.delete(key);
1422
+ return this;
1423
+ }
1424
+ defParam(key, str) {
1425
+ if (!this._url.searchParams.has(key)) {
1426
+ this._url.searchParams.set(key, str);
1427
+ }
1428
+ return this;
1429
+ }
1430
+ setParam(key, str) {
1431
+ this._url.searchParams.set(key, str);
1432
+ return this;
1433
+ }
1434
+ hasParam(key) {
1435
+ return this._url.searchParams.has(key);
1436
+ }
1437
+ get getParams() {
1438
+ return this._url.searchParams.entries();
1439
+ }
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;
1445
+ }
1446
+ return falsy2undef(val);
1447
+ }
1448
+ getParamResult(key, msgFn) {
1449
+ return getParamResult(key, this.getParam(key), msgFn);
1450
+ }
1451
+ getParamsResult(...keys) {
1452
+ return getParamsResult(keys, this);
1453
+ }
1454
+ toString() {
1455
+ this._url.searchParams.sort();
1456
+ return this._url.toString();
1457
+ }
1458
+ toJSON() {
1459
+ return this.toString();
1460
+ }
1461
+ asURL() {
1462
+ return this.URI().asURL();
1463
+ }
1464
+ asObj(...strips) {
1465
+ return this.URI().asObj(...strips);
1466
+ }
1467
+ clone() {
1468
+ return _BuildURI.from(this.toString());
1469
+ }
1470
+ URI() {
1471
+ return URI.from(this._url);
1472
+ }
1473
+ };
1474
+ var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
1475
+ var URI = class _URI {
1476
+ static protocolHasHostpart(protocol) {
1477
+ protocol = protocol.replace(/:$/, "");
1478
+ hasHostPartProtocols.add(protocol);
1479
+ return () => {
1480
+ hasHostPartProtocols.delete(protocol);
1481
+ };
1482
+ }
1483
+ match(other) {
1484
+ return match(this, other);
1485
+ }
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);
1494
+ }
1495
+ for (const [key, value] of fromUrl.getParams) {
1496
+ intoUrl.setParam(key, value);
1497
+ }
1498
+ return intoUrl.URI();
1499
+ }
1500
+ static is(value) {
1501
+ return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
1502
+ }
1503
+ // if no protocol is provided, default to file:
1504
+ static from(strURLUri, defaultProtocol = "file:") {
1505
+ return from((url) => new _URI(url), strURLUri, defaultProtocol);
1506
+ }
1507
+ static fromResult(strURLUri, defaultProtocol = "file:") {
1508
+ return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
2050
1509
  }
2051
- cleanParams() {
2052
- for (const key of Array.from(this._url.searchParams.keys())) {
2053
- this._url.searchParams.delete(key);
2054
- }
2055
- return this;
1510
+ constructor(url) {
1511
+ this._url = url.clone();
2056
1512
  }
2057
- delParam(key) {
2058
- this._url.searchParams.delete(key);
2059
- return this;
1513
+ build() {
1514
+ return BuildURI.from(this._url);
2060
1515
  }
2061
- defParam(key, str) {
2062
- if (!this._url.searchParams.has(key)) {
2063
- this._url.searchParams.set(key, str);
2064
- }
2065
- return this;
1516
+ get hostname() {
1517
+ return this._url.hostname;
2066
1518
  }
2067
- setParam(key, str) {
2068
- this._url.searchParams.set(key, str);
2069
- return this;
1519
+ // get password(): string {
1520
+ // return this._url.password;
1521
+ // }
1522
+ get port() {
1523
+ return this._url.port;
2070
1524
  }
2071
- hasParam(key) {
2072
- return this._url.searchParams.has(key);
1525
+ get host() {
1526
+ return this._url.host;
1527
+ }
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;
1536
+ }
1537
+ get pathname() {
1538
+ return this._url.pathname;
2073
1539
  }
1540
+ // get hash(): string {
1541
+ // return this._url.hash;
1542
+ // }
1543
+ // get host(): string {
1544
+ // return this._url.host;
1545
+ // }
2074
1546
  get getParams() {
2075
1547
  return this._url.searchParams.entries();
2076
1548
  }
1549
+ hasParam(key) {
1550
+ return this._url.searchParams.has(key);
1551
+ }
2077
1552
  getParam(key, def) {
2078
1553
  const { key: k, def: d } = coerceKey(key, def);
2079
1554
  let val = this._url.searchParams.get(k);
@@ -2088,146 +1563,407 @@ var BuildURI = class _BuildURI {
2088
1563
  getParamsResult(...keys) {
2089
1564
  return getParamsResult(keys, this);
2090
1565
  }
1566
+ clone() {
1567
+ return new _URI(this._url);
1568
+ }
1569
+ asURL() {
1570
+ return this._url.clone();
1571
+ }
2091
1572
  toString() {
2092
- this._url.searchParams.sort();
2093
1573
  return this._url.toString();
2094
1574
  }
2095
1575
  toJSON() {
2096
1576
  return this.toString();
2097
1577
  }
2098
- asURL() {
2099
- return this.URI().asURL();
2100
- }
2101
1578
  asObj(...strips) {
2102
- return this.URI().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
+ });
1592
+ }
1593
+ return stripper(strips, pathURI);
2103
1594
  }
2104
- clone() {
2105
- return _BuildURI.from(this.toString());
1595
+ };
1596
+
1597
+ // src/runtime.ts
1598
+ function isSet(value, ref = globalThis) {
1599
+ const [head, ...tail] = value.split(".");
1600
+ if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
1601
+ if (tail.length <= 1) {
1602
+ return true;
1603
+ }
1604
+ return isSet(tail.join("."), ref[head]);
2106
1605
  }
2107
- URI() {
2108
- return URI.from(this._url);
1606
+ return false;
1607
+ }
1608
+ function runtimeFn() {
1609
+ const gt = globalThis;
1610
+ let isReactNative = (
1611
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1612
+ isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative"
1613
+ );
1614
+ let isNodeIsh = false;
1615
+ if (!isSet("Deno")) {
1616
+ isNodeIsh = isSet("process.versions.node") && !isReactNative;
1617
+ }
1618
+ let isDeno = isSet("Deno");
1619
+ const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
1620
+ if (isCFWorker) {
1621
+ isDeno = false;
1622
+ isNodeIsh = false;
1623
+ isReactNative = false;
1624
+ }
1625
+ return {
1626
+ isNodeIsh,
1627
+ isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
1628
+ isDeno,
1629
+ isReactNative,
1630
+ isCFWorker
1631
+ };
1632
+ }
1633
+
1634
+ // src/sys-abstraction.ts
1635
+ var TimeMode = {
1636
+ REAL: "real",
1637
+ CONST: "const",
1638
+ STEP: "step"
1639
+ };
1640
+ var RandomMode = {
1641
+ CONST: "const",
1642
+ STEP: "step",
1643
+ RANDOM: "random"
1644
+ };
1645
+ var IDMode = {
1646
+ UUID: "uuid",
1647
+ CONST: "const",
1648
+ STEP: "step"
1649
+ };
1650
+
1651
+ // src/time.ts
1652
+ var Time = class {
1653
+ TimeSince(start) {
1654
+ const now = this.Now();
1655
+ return now.getTime() - start.getTime();
2109
1656
  }
2110
1657
  };
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
- };
1658
+ var TimeUnits = {
1659
+ Microsecond: 1,
1660
+ Second: 1e3 * 1,
1661
+ //Microsecond,
1662
+ Minute: 60 * 1e3 * 1,
1663
+ //Second,
1664
+ Hour: 60 * 60 * 1e3 * 1
1665
+ // Minute,
1666
+ };
1667
+
1668
+ // src/deno/deno-env-actions.ts
1669
+ var once = new ResolveOnce();
1670
+ var _deno;
1671
+ var _DenoEnvActions = class _DenoEnvActions {
1672
+ constructor(opts) {
1673
+ __privateAdd(this, _deno, globalThis);
1674
+ this.opts = opts;
1675
+ }
1676
+ static new(opts) {
1677
+ return once.once(() => new _DenoEnvActions(opts));
1678
+ }
1679
+ get _env() {
1680
+ return __privateGet(this, _deno).Deno.env;
1681
+ }
1682
+ register(env) {
1683
+ for (const key of env.keys()) {
1684
+ this._env.set(key, env.get(key) || "");
1685
+ }
1686
+ return env;
1687
+ }
1688
+ active() {
1689
+ return runtimeFn().isDeno;
1690
+ }
1691
+ keys() {
1692
+ return Object.keys(this._env.toObject());
1693
+ }
1694
+ get(key) {
1695
+ return this._env.get(key);
1696
+ }
1697
+ set(key, value) {
1698
+ if (value) {
1699
+ this._env.set(key, value);
1700
+ }
1701
+ }
1702
+ delete(key) {
1703
+ this._env.delete(key);
1704
+ }
1705
+ };
1706
+ _deno = new WeakMap();
1707
+ var DenoEnvActions = _DenoEnvActions;
1708
+
1709
+ // src/node/node-env-actions.ts
1710
+ var once2 = new ResolveOnce();
1711
+ var _node;
1712
+ var _NodeEnvActions = class _NodeEnvActions {
1713
+ constructor(opts) {
1714
+ __privateAdd(this, _node, globalThis);
1715
+ this._env = this.active() ? __privateGet(this, _node).process.env : {};
1716
+ this.opts = opts;
1717
+ }
1718
+ static new(opts) {
1719
+ return once2.once(() => new _NodeEnvActions(opts));
1720
+ }
1721
+ register(env) {
1722
+ for (const key of env.keys()) {
1723
+ this._env[key] = env.get(key) || "";
1724
+ }
1725
+ return env;
1726
+ }
1727
+ active() {
1728
+ return runtimeFn().isNodeIsh;
1729
+ }
1730
+ keys() {
1731
+ return Object.keys(this._env);
1732
+ }
1733
+ get(key) {
1734
+ return this._env[key];
1735
+ }
1736
+ set(key, value) {
1737
+ if (value) {
1738
+ this._env[key] = value;
1739
+ }
1740
+ }
1741
+ delete(key) {
1742
+ delete this._env[key];
1743
+ }
1744
+ };
1745
+ _node = new WeakMap();
1746
+ var NodeEnvActions = _NodeEnvActions;
1747
+
1748
+ // src/web/web-env-actions.ts
1749
+ var once3 = new ResolveOnce();
1750
+ var BrowserEnvActions = class _BrowserEnvActions {
1751
+ constructor(opts) {
1752
+ this.env = /* @__PURE__ */ new Map();
1753
+ this.opts = opts;
2119
1754
  }
2120
- match(other) {
2121
- return match(this, other);
1755
+ static new(opts) {
1756
+ return once3.once(() => new _BrowserEnvActions(opts));
2122
1757
  }
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);
2131
- }
2132
- for (const [key, value] of fromUrl.getParams) {
2133
- intoUrl.setParam(key, value);
1758
+ get(key) {
1759
+ return this.env.get(key);
1760
+ }
1761
+ set(key, value) {
1762
+ if (value) {
1763
+ this.env.set(key, value);
2134
1764
  }
2135
- return intoUrl.URI();
2136
1765
  }
2137
- static is(value) {
2138
- return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
1766
+ delete(key) {
1767
+ this.env.delete(key);
2139
1768
  }
2140
- // if no protocol is provided, default to file:
2141
- static from(strURLUri, defaultProtocol = "file:") {
2142
- return from((url) => new _URI(url), strURLUri, defaultProtocol);
1769
+ keys() {
1770
+ return Array.from(this.env.keys());
2143
1771
  }
2144
- static fromResult(strURLUri, defaultProtocol = "file:") {
2145
- return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
1772
+ active() {
1773
+ return true;
2146
1774
  }
2147
- constructor(url) {
2148
- this._url = url.clone();
1775
+ register(env) {
1776
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1777
+ const browser = globalThis;
1778
+ browser[sym] = env;
1779
+ return env;
2149
1780
  }
2150
- build() {
2151
- return BuildURI.from(this._url);
1781
+ };
1782
+
1783
+ // src/cf/cf-env-actions.ts
1784
+ var once4 = new ResolveOnce();
1785
+ var CFEnvActions = class _CFEnvActions {
1786
+ constructor(env) {
1787
+ this.injectOnRegister = {};
1788
+ this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
2152
1789
  }
2153
- get hostname() {
2154
- return this._url.hostname;
1790
+ static new(opts) {
1791
+ return once4.once(() => new _CFEnvActions(opts));
2155
1792
  }
2156
- // get password(): string {
2157
- // return this._url.password;
2158
- // }
2159
- get port() {
2160
- return this._url.port;
1793
+ static inject(o) {
1794
+ const env = _CFEnvActions.new({});
1795
+ for (const key in o) {
1796
+ const value = o[key];
1797
+ if (typeof value === "string") {
1798
+ if (env.env) {
1799
+ env.env.set(key, value);
1800
+ } else {
1801
+ env.injectOnRegister[key] = value;
1802
+ }
1803
+ }
1804
+ }
2161
1805
  }
2162
- get host() {
2163
- return this._url.host;
1806
+ active() {
1807
+ return runtimeFn().isCFWorker;
2164
1808
  }
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;
1809
+ register(env) {
1810
+ this.env = env;
1811
+ for (const key in this.injectOnRegister) {
1812
+ env.set(key, this.injectOnRegister[key]);
1813
+ }
1814
+ return env;
2173
1815
  }
2174
- get pathname() {
2175
- return this._url.pathname;
1816
+ get(key) {
1817
+ return this.cfEnv.get(key);
2176
1818
  }
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();
1819
+ set(key, value) {
1820
+ if (value) {
1821
+ this.cfEnv.set(key, value);
1822
+ }
2185
1823
  }
2186
- hasParam(key) {
2187
- return this._url.searchParams.has(key);
1824
+ delete(key) {
1825
+ this.cfEnv.delete(key);
2188
1826
  }
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);
1827
+ keys() {
1828
+ return Array.from(this.cfEnv.keys());
2196
1829
  }
2197
- getParamResult(key, msgFn) {
2198
- return getParamResult(key, this.getParam(key), msgFn);
1830
+ };
1831
+
1832
+ // src/sys-env.ts
1833
+ var envActions = [
1834
+ { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1835
+ { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1836
+ { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1837
+ { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
1838
+ ];
1839
+ var _envFactories = new KeyedResolvOnce();
1840
+ function envFactory(opts = {}) {
1841
+ const found = envActions.find((fi) => fi.fn(opts).active());
1842
+ if (!found) {
1843
+ throw new Error("SysContainer:envFactory: no env available");
2199
1844
  }
2200
- getParamsResult(...keys) {
2201
- return getParamsResult(keys, this);
1845
+ return _envFactories.get(found.id).once(() => {
1846
+ const action = found.fn(opts);
1847
+ const ret = new EnvImpl(action, opts);
1848
+ action.register(ret);
1849
+ return ret;
1850
+ });
1851
+ }
1852
+ function isIterable(obj) {
1853
+ if (obj == null) {
1854
+ return false;
2202
1855
  }
2203
- clone() {
2204
- return new _URI(this._url);
1856
+ return typeof obj[Symbol.iterator] === "function";
1857
+ }
1858
+ var EnvImpl = class {
1859
+ constructor(map, opts = {}) {
1860
+ this._onSet = [];
1861
+ this._map = map;
1862
+ this._updatePresets(opts.presetEnv);
2205
1863
  }
2206
- asURL() {
2207
- return this._url.clone();
1864
+ gets(...kparams) {
1865
+ return getParamsResult(kparams, {
1866
+ getParam: (k) => this.get(k)
1867
+ });
2208
1868
  }
2209
- toString() {
2210
- return this._url.toString();
1869
+ sets(...keys) {
1870
+ keys.forEach((key) => {
1871
+ if (Array.isArray(key)) {
1872
+ if (key.length === 2) {
1873
+ const [k, v] = key;
1874
+ if (typeof k === "string" && typeof v === "string") {
1875
+ this.set(k, v);
1876
+ return;
1877
+ }
1878
+ }
1879
+ for (const item of key) {
1880
+ if (Array.isArray(item)) {
1881
+ if (item.length === 2) {
1882
+ const [k, v] = item;
1883
+ if (typeof k === "string" && typeof v === "string") {
1884
+ this.set(k, v);
1885
+ }
1886
+ }
1887
+ }
1888
+ }
1889
+ } else {
1890
+ if (isIterable(key)) {
1891
+ for (const [k, v] of key) {
1892
+ if (typeof k === "string" && typeof v === "string") {
1893
+ this.set(k, v);
1894
+ }
1895
+ }
1896
+ } else {
1897
+ const rKey = key;
1898
+ for (const k in rKey) {
1899
+ const v = rKey[k];
1900
+ if (typeof k === "string" && typeof v === "string") {
1901
+ this.set(k, v);
1902
+ }
1903
+ }
1904
+ }
1905
+ }
1906
+ });
2211
1907
  }
2212
- toJSON() {
2213
- return this.toString();
1908
+ _updatePresets(presetEnv) {
1909
+ if (!presetEnv) {
1910
+ return;
1911
+ }
1912
+ for (const [key, value] of presetEnv) {
1913
+ this._map.set(key, value);
1914
+ }
2214
1915
  }
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
1916
+ _applyOnSet(onSet, key, value) {
1917
+ onSet.forEach((item) => {
1918
+ let keys = [];
1919
+ if (key) {
1920
+ keys = [key];
1921
+ } else {
1922
+ keys = this._map.keys();
1923
+ }
1924
+ keys.filter((k) => {
1925
+ if (item.filter.size === 0) {
1926
+ return true;
1927
+ }
1928
+ if (item.filter.has(k)) {
1929
+ return true;
1930
+ }
1931
+ return false;
1932
+ }).forEach((k) => {
1933
+ let v;
1934
+ if (!key && !value) {
1935
+ v = this._map.get(k);
1936
+ } else if (key && !value) {
1937
+ v = void 0;
1938
+ } else {
1939
+ v = value;
1940
+ }
1941
+ item.fn(k, v);
2228
1942
  });
1943
+ });
1944
+ }
1945
+ keys() {
1946
+ return this._map.keys();
1947
+ }
1948
+ // filter is not set all sets passed
1949
+ onSet(fn, ...filter) {
1950
+ const item = { filter: new Set(filter), fn };
1951
+ this._onSet.push(item);
1952
+ this._applyOnSet([item]);
1953
+ }
1954
+ get(key) {
1955
+ return this._map.get(key);
1956
+ }
1957
+ set(key, value) {
1958
+ if (!value) {
1959
+ return;
2229
1960
  }
2230
- return stripper(strips, pathURI);
1961
+ this._map.set(key, value);
1962
+ this._applyOnSet(this._onSet, key, value);
1963
+ }
1964
+ delete(key) {
1965
+ this._map.delete(key);
1966
+ this._applyOnSet(this._onSet, key);
2231
1967
  }
2232
1968
  };
2233
1969
 
@@ -2296,6 +2032,341 @@ var ConsoleWriterStream = class {
2296
2032
  }
2297
2033
  };
2298
2034
 
2035
+ // src/web/web-basic-sys-abstraction.ts
2036
+ var WebSystemService = class {
2037
+ constructor(ende) {
2038
+ this._txtEnDe = ende;
2039
+ }
2040
+ Env() {
2041
+ return envFactory();
2042
+ }
2043
+ Args() {
2044
+ throw new Error("Args-Method not implemented.");
2045
+ }
2046
+ Stdout() {
2047
+ return new ConsoleWriterStream();
2048
+ }
2049
+ Stderr() {
2050
+ const decoder = this._txtEnDe;
2051
+ return new WritableStream({
2052
+ write(chunk) {
2053
+ return new Promise((resolve) => {
2054
+ const decoded = decoder.decode(chunk);
2055
+ console.error(decoded.trimEnd());
2056
+ resolve();
2057
+ });
2058
+ }
2059
+ });
2060
+ }
2061
+ };
2062
+ var baseSysAbstraction = new ResolveOnce();
2063
+ function WebBasicSysAbstraction(param2) {
2064
+ var _a;
2065
+ const my = baseSysAbstraction.once(() => {
2066
+ return new BaseBasicSysAbstraction({
2067
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2068
+ });
2069
+ });
2070
+ return new WrapperBasicSysAbstraction(my, {
2071
+ basicRuntimeService: new WebSystemService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2072
+ ...param2
2073
+ });
2074
+ }
2075
+
2076
+ // src/cf/cf-basic-sys-abstraction.ts
2077
+ var CFRuntimeService = class {
2078
+ constructor(ende) {
2079
+ this._txtEnDe = ende;
2080
+ }
2081
+ Env() {
2082
+ return envFactory();
2083
+ }
2084
+ Args() {
2085
+ throw new Error("Args-Method not implemented.");
2086
+ }
2087
+ Stdout() {
2088
+ return CFWriteableStream((chunk) => {
2089
+ const decoded = this._txtEnDe.decode(chunk);
2090
+ console.log(decoded.trimEnd());
2091
+ return Promise.resolve();
2092
+ });
2093
+ }
2094
+ Stderr() {
2095
+ return CFWriteableStream((chunk) => {
2096
+ const decoded = this._txtEnDe.decode(chunk);
2097
+ console.error(decoded.trimEnd());
2098
+ return Promise.resolve();
2099
+ });
2100
+ }
2101
+ };
2102
+ function consumeReadableStream(reader, writeFn) {
2103
+ reader.read().then(({ done, value }) => {
2104
+ if (done) {
2105
+ return;
2106
+ }
2107
+ writeFn(value).then(() => {
2108
+ consumeReadableStream(reader, writeFn);
2109
+ }).catch((e) => {
2110
+ console.error("consumeReadableStream:writeFn", e);
2111
+ });
2112
+ }).catch((e) => {
2113
+ console.error("consumeReadableStream:read", e);
2114
+ });
2115
+ }
2116
+ function CFWriteableStream(writeFn) {
2117
+ const ts = new TransformStream();
2118
+ consumeReadableStream(ts.readable.getReader(), writeFn);
2119
+ return ts.writable;
2120
+ }
2121
+ var baseSysAbstraction2 = new ResolveOnce();
2122
+ function CFBasicSysAbstraction(param2) {
2123
+ var _a;
2124
+ const my = baseSysAbstraction2.once(() => {
2125
+ return new BaseBasicSysAbstraction({
2126
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2127
+ });
2128
+ });
2129
+ return new WrapperBasicSysAbstraction(my, {
2130
+ basicRuntimeService: new CFRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2131
+ ...param2
2132
+ });
2133
+ }
2134
+
2135
+ // src/deno/deno-basic-sys-abstraction.ts
2136
+ var DenoRuntimeService = class {
2137
+ constructor(ende) {
2138
+ this._txtEnDe = ende;
2139
+ }
2140
+ Env() {
2141
+ return envFactory();
2142
+ }
2143
+ Args() {
2144
+ return globalThis.Deno.args;
2145
+ }
2146
+ Stdout() {
2147
+ return globalThis.Deno.stdout.writable;
2148
+ }
2149
+ Stderr() {
2150
+ return globalThis.Deno.stderr.writable;
2151
+ }
2152
+ };
2153
+ var baseSysAbstraction3 = new ResolveOnce();
2154
+ function DenoBasicSysAbstraction(param2) {
2155
+ var _a;
2156
+ const my = baseSysAbstraction3.once(() => {
2157
+ return new BaseBasicSysAbstraction({
2158
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2159
+ });
2160
+ });
2161
+ return new WrapperBasicSysAbstraction(my, {
2162
+ basicRuntimeService: new DenoRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2163
+ ...param2
2164
+ });
2165
+ }
2166
+
2167
+ // src/node/node-basic-sys-abstraction.ts
2168
+ var NodeRuntimeService = class {
2169
+ constructor(ende) {
2170
+ this._txtEnDe = ende;
2171
+ this._gthis = globalThis;
2172
+ }
2173
+ Env() {
2174
+ return envFactory();
2175
+ }
2176
+ Args() {
2177
+ return this._gthis.process.argv;
2178
+ }
2179
+ Stdout() {
2180
+ return new WritableStream({
2181
+ write: (chunk) => {
2182
+ this._gthis.process.stdout.write(chunk);
2183
+ }
2184
+ });
2185
+ }
2186
+ Stderr() {
2187
+ return new WritableStream({
2188
+ write: (chunk) => {
2189
+ this._gthis.process.stderr.write(chunk);
2190
+ }
2191
+ });
2192
+ }
2193
+ };
2194
+ var baseSysAbstraction4 = new ResolveOnce();
2195
+ function NodeBasicSysAbstraction(param2) {
2196
+ var _a;
2197
+ const my = baseSysAbstraction4.once(() => {
2198
+ return new BaseBasicSysAbstraction({
2199
+ TxtEnDecoder: (param2 == null ? void 0 : param2.TxtEnDecoder) || TxtEnDecoderSingleton()
2200
+ });
2201
+ });
2202
+ return new WrapperBasicSysAbstraction(my, {
2203
+ basicRuntimeService: new NodeRuntimeService((_a = param2 == null ? void 0 : param2.TxtEnDecoder) != null ? _a : my._txtEnDe),
2204
+ ...param2
2205
+ });
2206
+ }
2207
+
2208
+ // src/base-sys-abstraction.ts
2209
+ var SysTime = class extends Time {
2210
+ Now() {
2211
+ return /* @__PURE__ */ new Date();
2212
+ }
2213
+ Sleep(duration) {
2214
+ return new Promise((resolve) => {
2215
+ setTimeout(() => {
2216
+ resolve();
2217
+ }, duration);
2218
+ });
2219
+ }
2220
+ };
2221
+ var ConstTime = class extends Time {
2222
+ Now() {
2223
+ return new Date(2021, 1, 1, 0, 0, 0, 0);
2224
+ }
2225
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2226
+ Sleep(duration) {
2227
+ return Promise.resolve();
2228
+ }
2229
+ };
2230
+ var StepTime = class extends Time {
2231
+ constructor() {
2232
+ super();
2233
+ this._step = new ConstTime().Now();
2234
+ this._start = this._step;
2235
+ }
2236
+ Now(steps = 1) {
2237
+ for (let i = 0; steps > 0 && i < steps; i++) {
2238
+ this._step = new Date(this._step.getTime() + 1e3);
2239
+ }
2240
+ if (steps < 1) {
2241
+ this._step = new Date(this._start.getTime() + steps * -1e3);
2242
+ }
2243
+ return this._step;
2244
+ }
2245
+ Sleep(duration) {
2246
+ this._step = new Date(this._step.getTime() + duration);
2247
+ return Promise.resolve();
2248
+ }
2249
+ };
2250
+ function TimeFactory(timeMode) {
2251
+ switch (timeMode) {
2252
+ case TimeMode.REAL:
2253
+ return new SysTime();
2254
+ case TimeMode.CONST:
2255
+ return new ConstTime();
2256
+ case TimeMode.STEP:
2257
+ return new StepTime();
2258
+ }
2259
+ return new SysTime();
2260
+ }
2261
+ var RandomService = class {
2262
+ constructor(mode) {
2263
+ this._step = 0;
2264
+ this._mode = mode;
2265
+ }
2266
+ Random0ToValue(value) {
2267
+ switch (this._mode) {
2268
+ case RandomMode.CONST:
2269
+ return 0.5 * value;
2270
+ case RandomMode.STEP:
2271
+ this._step += 1e-4;
2272
+ return this._step * value;
2273
+ case RandomMode.RANDOM:
2274
+ return Math.random() * value;
2275
+ default:
2276
+ throw new Error("Unknown RandomMode");
2277
+ }
2278
+ }
2279
+ };
2280
+ var IdService = class {
2281
+ constructor(mode) {
2282
+ this._step = 0;
2283
+ if (!mode) {
2284
+ mode = IDMode.UUID;
2285
+ }
2286
+ this._mode = mode;
2287
+ }
2288
+ NextId() {
2289
+ switch (this._mode) {
2290
+ case IDMode.UUID:
2291
+ return crypto.randomUUID();
2292
+ case IDMode.CONST:
2293
+ return "VeryUniqueID";
2294
+ case IDMode.STEP:
2295
+ return `STEPId-${this._step++}`;
2296
+ default:
2297
+ throw new Error("Unknown IDMode");
2298
+ }
2299
+ }
2300
+ };
2301
+ var BaseBasicSysAbstraction = class {
2302
+ constructor(params) {
2303
+ this._time = new SysTime();
2304
+ // system independent services
2305
+ this._idService = new IdService();
2306
+ this._randomService = new RandomService(RandomMode.RANDOM);
2307
+ this._txtEnDe = params.TxtEnDecoder;
2308
+ }
2309
+ };
2310
+ function BasicSysAbstractionFactory(params) {
2311
+ const fn = runtimeFn();
2312
+ switch (true) {
2313
+ case fn.isBrowser:
2314
+ return WebBasicSysAbstraction(params);
2315
+ case fn.isDeno:
2316
+ return DenoBasicSysAbstraction(params);
2317
+ case fn.isCFWorker:
2318
+ return CFBasicSysAbstraction(params);
2319
+ case fn.isNodeIsh:
2320
+ return NodeBasicSysAbstraction(params);
2321
+ default:
2322
+ throw new Error("Unknown runtime");
2323
+ }
2324
+ }
2325
+ var WrapperBasicSysAbstraction = class {
2326
+ constructor(base, params) {
2327
+ this._time = base._time;
2328
+ this._basicRuntimeService = params.basicRuntimeService;
2329
+ this._idService = base._idService;
2330
+ this._randomService = base._randomService;
2331
+ if (params.TimeMode) {
2332
+ this._time = TimeFactory(params.TimeMode);
2333
+ }
2334
+ if (params.IdMode) {
2335
+ this._idService = new IdService(params.IdMode);
2336
+ }
2337
+ if (params.RandomMode) {
2338
+ this._randomService = new RandomService(params.RandomMode);
2339
+ }
2340
+ }
2341
+ Time() {
2342
+ return this._time;
2343
+ }
2344
+ NextId() {
2345
+ return this._idService.NextId();
2346
+ }
2347
+ Random0ToValue(value) {
2348
+ return this._randomService.Random0ToValue(value);
2349
+ }
2350
+ Stdout() {
2351
+ return this._basicRuntimeService.Stdout();
2352
+ }
2353
+ Stderr() {
2354
+ return this._basicRuntimeService.Stderr();
2355
+ }
2356
+ Env() {
2357
+ return this._basicRuntimeService.Env();
2358
+ }
2359
+ Args() {
2360
+ return this._basicRuntimeService.Args();
2361
+ }
2362
+ // System(): SystemService {
2363
+ // return this._systemService;
2364
+ // }
2365
+ // FileSystem(): FileService {
2366
+ // return this._fileSystem;
2367
+ // }
2368
+ };
2369
+
2299
2370
  // src/log-writer-impl.ts
2300
2371
  var LogWriterStream = class {
2301
2372
  constructor(out) {
@@ -2303,9 +2374,10 @@ var LogWriterStream = class {
2303
2374
  this._flushIsRunning = false;
2304
2375
  this._flushDoneFns = [];
2305
2376
  this._out = out;
2377
+ this._id = Math.random();
2306
2378
  }
2307
2379
  write(encoded) {
2308
- const my2 = async () => {
2380
+ const my = async () => {
2309
2381
  try {
2310
2382
  const writer = this._out.getWriter();
2311
2383
  await writer.ready;
@@ -2315,7 +2387,7 @@ var LogWriterStream = class {
2315
2387
  console.error("Chunk error:", err);
2316
2388
  }
2317
2389
  };
2318
- this._toFlush.push(my2);
2390
+ this._toFlush.push(my);
2319
2391
  this._flush();
2320
2392
  }
2321
2393
  _flush(toFlush = void 0, done) {
@@ -2333,8 +2405,8 @@ var LogWriterStream = class {
2333
2405
  } else if (!toFlush) {
2334
2406
  return;
2335
2407
  }
2336
- const my2 = this._toFlush.shift();
2337
- my2 == null ? void 0 : my2().catch((e) => {
2408
+ const my = this._toFlush.shift();
2409
+ my == null ? void 0 : my().catch((e) => {
2338
2410
  console.error("Flush error:", e);
2339
2411
  }).finally(() => {
2340
2412
  this._flush(this._toFlush);
@@ -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
  }