@adviser/cement 0.3.1 → 0.3.2

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 (138) hide show
  1. package/base-sys-abstraction-CR_Z-Ceg.d.ts +84 -0
  2. package/base-sys-abstraction-DWtPI7Kg.d.cts +84 -0
  3. package/cf/index.cjs +929 -0
  4. package/cf/index.cjs.map +1 -0
  5. package/cf/index.d.cts +26 -0
  6. package/cf/index.d.ts +26 -0
  7. package/cf/index.js +12 -0
  8. package/cf/index.js.map +1 -0
  9. package/{chunk-3RHIVQAA.js → chunk-A7OPSHUV.js} +6 -94
  10. package/chunk-A7OPSHUV.js.map +1 -0
  11. package/chunk-DZPKZQIT.js +1182 -0
  12. package/chunk-DZPKZQIT.js.map +1 -0
  13. package/chunk-HFP74WLI.js +96 -0
  14. package/chunk-HFP74WLI.js.map +1 -0
  15. package/chunk-R2EEZNZN.js +1742 -0
  16. package/chunk-R2EEZNZN.js.map +1 -0
  17. package/deno/index.cjs +940 -0
  18. package/deno/index.cjs.map +1 -0
  19. package/deno/index.d.cts +59 -0
  20. package/deno/index.d.ts +59 -0
  21. package/deno/index.js +16 -0
  22. package/deno/index.js.map +1 -0
  23. package/index-BfZxTAe_.d.cts +318 -0
  24. package/index-CfSl8Gmj.d.ts +318 -0
  25. package/index.cjs +393 -143
  26. package/index.cjs.map +1 -1
  27. package/index.d.cts +7 -317
  28. package/index.d.ts +7 -317
  29. package/index.js +34 -1729
  30. package/index.js.map +1 -1
  31. package/node/index.cjs +265 -217
  32. package/node/index.cjs.map +1 -1
  33. package/node/index.d.cts +16 -21
  34. package/node/index.d.ts +16 -21
  35. package/node/index.js +8 -352
  36. package/node/index.js.map +1 -1
  37. package/package.json +18 -11
  38. package/src/cf/cf-sys-abstraction.ts +78 -0
  39. package/src/cf/index.ts +1 -0
  40. package/src/{node → deno}/deno-file-service.ts +2 -2
  41. package/src/{node → deno}/deno-sys-abstraction.ts +64 -7
  42. package/src/deno/index.ts +2 -0
  43. package/src/index.ts +1 -2
  44. package/src/jsr.json +1 -1
  45. package/src/logger-impl.ts +2 -2
  46. package/src/logger.ts +10 -3
  47. package/src/node/index.ts +0 -1
  48. package/src/node/node-sys-abstraction.ts +45 -1
  49. package/src/runtime.ts +13 -3
  50. package/src/sys-env.ts +19 -113
  51. package/src/test/index.ts +2 -0
  52. package/src/web/web-sys-abstraction.ts +42 -2
  53. package/sys-abstraction-GNnBj2sz.d.cts +102 -0
  54. package/sys-abstraction-GNnBj2sz.d.ts +102 -0
  55. package/test/index.cjs +2681 -0
  56. package/test/index.cjs.map +1 -0
  57. package/test/index.d.cts +3 -0
  58. package/test/index.d.ts +3 -0
  59. package/test/index.js +14 -0
  60. package/test/index.js.map +1 -0
  61. package/ts/base-sys-abstraction.test.js +8 -2
  62. package/ts/base-sys-abstraction.test.js.map +1 -1
  63. package/ts/cf/cf-sys-abstraction.d.ts +24 -0
  64. package/ts/cf/cf-sys-abstraction.d.ts.map +1 -0
  65. package/ts/cf/cf-sys-abstraction.js +72 -0
  66. package/ts/cf/cf-sys-abstraction.js.map +1 -0
  67. package/ts/cf/index.d.ts +2 -0
  68. package/ts/cf/index.d.ts.map +1 -0
  69. package/ts/cf/index.js +2 -0
  70. package/ts/cf/index.js.map +1 -0
  71. package/ts/crypto.test.js +1 -1
  72. package/ts/crypto.test.js.map +1 -1
  73. package/ts/{node → deno}/deno-file-service.d.ts.map +1 -1
  74. package/ts/{node → deno}/deno-file-service.js +1 -1
  75. package/ts/{node → deno}/deno-file-service.js.map +1 -1
  76. package/ts/deno/deno-sys-abstraction.d.ts +43 -0
  77. package/ts/deno/deno-sys-abstraction.d.ts.map +1 -0
  78. package/ts/{node → deno}/deno-sys-abstraction.js +46 -2
  79. package/ts/deno/deno-sys-abstraction.js.map +1 -0
  80. package/ts/deno/index.d.ts +3 -0
  81. package/ts/deno/index.d.ts.map +1 -0
  82. package/ts/deno/index.js +3 -0
  83. package/ts/deno/index.js.map +1 -0
  84. package/ts/index.d.ts +1 -2
  85. package/ts/index.d.ts.map +1 -1
  86. package/ts/index.js +1 -2
  87. package/ts/index.js.map +1 -1
  88. package/ts/logger-impl.js +2 -2
  89. package/ts/logger-impl.js.map +1 -1
  90. package/ts/logger.d.ts.map +1 -1
  91. package/ts/logger.js +9 -3
  92. package/ts/logger.js.map +1 -1
  93. package/ts/logger.test.js +9 -9
  94. package/ts/logger.test.js.map +1 -1
  95. package/ts/node/index.d.ts +0 -1
  96. package/ts/node/index.d.ts.map +1 -1
  97. package/ts/node/index.js +0 -1
  98. package/ts/node/index.js.map +1 -1
  99. package/ts/node/node-sys-abstraction.d.ts +14 -1
  100. package/ts/node/node-sys-abstraction.d.ts.map +1 -1
  101. package/ts/node/node-sys-abstraction.js +43 -0
  102. package/ts/node/node-sys-abstraction.js.map +1 -1
  103. package/ts/runtime.d.ts +1 -0
  104. package/ts/runtime.d.ts.map +1 -1
  105. package/ts/runtime.js +10 -3
  106. package/ts/runtime.js.map +1 -1
  107. package/ts/sys-env.d.ts +0 -11
  108. package/ts/sys-env.d.ts.map +1 -1
  109. package/ts/sys-env.js +19 -104
  110. package/ts/sys-env.js.map +1 -1
  111. package/ts/sys-env.test.js +16 -3
  112. package/ts/sys-env.test.js.map +1 -1
  113. package/ts/test/index.d.ts +3 -0
  114. package/ts/test/index.d.ts.map +1 -0
  115. package/ts/test/index.js +3 -0
  116. package/ts/test/index.js.map +1 -0
  117. package/ts/test/test-exit-handler.js +1 -1
  118. package/ts/web/web-sys-abstraction.d.ts +27 -0
  119. package/ts/web/web-sys-abstraction.d.ts.map +1 -1
  120. package/ts/web/web-sys-abstraction.js +35 -1
  121. package/ts/web/web-sys-abstraction.js.map +1 -1
  122. package/utils/index.js +6 -4
  123. package/web/index.cjs +389 -67
  124. package/web/index.cjs.map +1 -1
  125. package/web/index.d.cts +28 -2
  126. package/web/index.d.ts +28 -2
  127. package/web/index.js +5 -2
  128. package/base-sys-abstraction-BPFyK8XL.d.ts +0 -195
  129. package/base-sys-abstraction-KYXfUGd6.d.cts +0 -195
  130. package/chunk-3RHIVQAA.js.map +0 -1
  131. package/chunk-PSPOGR2I.js +0 -627
  132. package/chunk-PSPOGR2I.js.map +0 -1
  133. package/chunk-STUPETPE.js +0 -87
  134. package/chunk-STUPETPE.js.map +0 -1
  135. package/ts/node/deno-sys-abstraction.d.ts +0 -22
  136. package/ts/node/deno-sys-abstraction.d.ts.map +0 -1
  137. package/ts/node/deno-sys-abstraction.js.map +0 -1
  138. /package/ts/{node → deno}/deno-file-service.d.ts +0 -0
package/index.cjs CHANGED
@@ -38,10 +38,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
38
38
  var src_exports = {};
39
39
  __export(src_exports, {
40
40
  BaseSysAbstraction: () => BaseSysAbstraction,
41
- BrowserEnvActions: () => BrowserEnvActions,
42
41
  BuildURI: () => BuildURI,
43
42
  ConstTime: () => ConstTime,
44
- EnvImpl: () => EnvImpl,
43
+ EnvImpl: () => EnvImpl2,
45
44
  Future: () => Future,
46
45
  HeadersImpl: () => HeadersImpl,
47
46
  HttpHeader: () => HttpHeader,
@@ -200,11 +199,16 @@ function logValueInternal(val, ctx) {
200
199
  return logValueInternal(ret, ctx);
201
200
  }
202
201
  } catch (e) {
203
- if (val.match(/[\n\r]/)) {
204
- const lines = val.trimEnd().split(/[\n\r]/);
205
- return new LogValue(() => lines);
202
+ try {
203
+ const url = new URL(val);
204
+ return new LogValue(() => url.toString());
205
+ } catch (e2) {
206
206
  }
207
207
  }
208
+ if (val.match(/[\n\r]/)) {
209
+ const lines = val.split(/[\n\r]+/).map((v) => v.trim());
210
+ return new LogValue(() => lines);
211
+ }
208
212
  return new LogValue(() => val.toString());
209
213
  }
210
214
  case "number":
@@ -344,9 +348,9 @@ var SysTime = class extends Time {
344
348
  return /* @__PURE__ */ new Date();
345
349
  }
346
350
  Sleep(duration) {
347
- return new Promise((resolve) => {
351
+ return new Promise((resolve2) => {
348
352
  setTimeout(() => {
349
- resolve();
353
+ resolve2();
350
354
  }, duration);
351
355
  });
352
356
  }
@@ -536,8 +540,8 @@ var Future = class {
536
540
  __privateAdd(this, _rejectFn, () => {
537
541
  throw new Error("This Promise is not working as expected.");
538
542
  });
539
- __privateSet(this, _promise, new Promise((resolve, reject) => {
540
- __privateSet(this, _resolveFn, resolve);
543
+ __privateSet(this, _promise, new Promise((resolve2, reject) => {
544
+ __privateSet(this, _resolveFn, resolve2);
541
545
  __privateSet(this, _rejectFn, reject);
542
546
  }));
543
547
  }
@@ -699,53 +703,86 @@ var KeyedResolvSeq = class extends Keyed {
699
703
  }
700
704
  };
701
705
 
702
- // src/sys-env.ts
703
- var _node;
704
- var NodeEnvActions = class {
705
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
706
- constructor(opts) {
707
- __privateAdd(this, _node, globalThis);
708
- this._env = this.active() ? __privateGet(this, _node).process.env : {};
709
- }
710
- register(env) {
711
- return env;
712
- }
713
- active() {
714
- return typeof __privateGet(this, _node) === "object" && typeof __privateGet(this, _node).process === "object" && typeof __privateGet(this, _node).process.env === "object";
706
+ // src/runtime.ts
707
+ function isSet(value, ref = globalThis) {
708
+ const [head, ...tail] = value.split(".");
709
+ if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
710
+ if (tail.length <= 1) {
711
+ return true;
712
+ }
713
+ return isSet(tail.join("."), ref[head]);
715
714
  }
716
- keys() {
717
- return Object.keys(this._env);
715
+ return false;
716
+ }
717
+ function runtimeFn() {
718
+ const gt = globalThis;
719
+ let isReactNative = isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative";
720
+ let isNodeIsh = false;
721
+ if (!isSet("Deno")) {
722
+ isNodeIsh = isSet("process.versions.node") && !isReactNative;
718
723
  }
719
- get(key2) {
720
- return this._env[key2];
724
+ let isDeno = isSet("Deno");
725
+ const isCFWorker = isSet("caches.default") && isSet("WebSocketPair");
726
+ if (isCFWorker) {
727
+ isDeno = false;
728
+ isNodeIsh = false;
729
+ isReactNative = false;
721
730
  }
722
- set(key2, value) {
723
- if (value) {
724
- this._env[key2] = value;
725
- }
731
+ return {
732
+ isNodeIsh,
733
+ isBrowser: !(isNodeIsh || isDeno || isCFWorker || isReactNative),
734
+ isDeno,
735
+ isReactNative,
736
+ isCFWorker
737
+ };
738
+ }
739
+
740
+ // src/txt-en-decoder.ts
741
+ var encoder = new TextEncoder();
742
+ var decoder = new TextDecoder();
743
+ var Utf8EnDecoder = class {
744
+ encode(str) {
745
+ return encoder.encode(str);
726
746
  }
727
- delete(key2) {
728
- delete this._env[key2];
747
+ decode(data) {
748
+ return decoder.decode(data);
729
749
  }
730
750
  };
731
- _node = new WeakMap();
751
+ var utf8EnDecoder = new Utf8EnDecoder();
752
+ function Utf8EnDecoderSingleton() {
753
+ return utf8EnDecoder;
754
+ }
755
+
756
+ // src/deno/deno-file-service.ts
757
+ var path = __toESM(require("path"), 1);
758
+ var Deno = globalThis.Deno;
759
+
760
+ // src/deno/deno-sys-abstraction.ts
761
+ var Deno2 = globalThis.Deno;
762
+ var once = new ResolveOnce();
732
763
  var _deno;
733
- var DenoEnvActions = class {
734
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
764
+ var _DenoEnvActions = class _DenoEnvActions {
735
765
  constructor(opts) {
736
766
  __privateAdd(this, _deno, globalThis);
767
+ this.opts = opts;
768
+ }
769
+ static new(opts) {
770
+ return once.once(() => new _DenoEnvActions(opts));
737
771
  }
738
772
  get _env() {
739
773
  return __privateGet(this, _deno).Deno.env;
740
774
  }
741
775
  register(env) {
776
+ for (const key2 of env.keys()) {
777
+ this._env.set(key2, env.get(key2) || "");
778
+ }
742
779
  return env;
743
780
  }
744
781
  active() {
745
- return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
782
+ return runtimeFn().isDeno;
746
783
  }
747
784
  keys() {
748
- return Array.from(this._env.keys());
785
+ return Object.keys(this._env.toObject());
749
786
  }
750
787
  get(key2) {
751
788
  return this._env.get(key2);
@@ -760,44 +797,267 @@ var DenoEnvActions = class {
760
797
  }
761
798
  };
762
799
  _deno = new WeakMap();
763
- var BrowserEnvActions = class {
800
+ var DenoEnvActions = _DenoEnvActions;
801
+ var DenoExitServiceImpl = class {
802
+ constructor() {
803
+ this._exitHandlers = [];
804
+ this.invoked = false;
805
+ this._handleExit = async () => {
806
+ if (this.invoked) {
807
+ return;
808
+ }
809
+ this.invoked = true;
810
+ for (const h of this._exitHandlers) {
811
+ try {
812
+ const ret = h.hdl();
813
+ if (typeof ret.then === "function") {
814
+ await ret;
815
+ }
816
+ } finally {
817
+ }
818
+ }
819
+ };
820
+ globalThis.addEventListener("unhandledrejection", (e) => {
821
+ e.preventDefault();
822
+ this.exit(19);
823
+ });
824
+ globalThis.addEventListener("error", () => {
825
+ this.exit(19);
826
+ });
827
+ globalThis.addEventListener("uncaughtException", () => {
828
+ this.exit(19);
829
+ });
830
+ globalThis.addEventListener("unload", () => {
831
+ this.exit(0);
832
+ });
833
+ Deno2.addSignalListener("SIGQUIT", () => {
834
+ this.exit(3);
835
+ });
836
+ Deno2.addSignalListener("SIGINT", () => {
837
+ this.exit(2);
838
+ });
839
+ Deno2.addSignalListener("SIGTERM", () => {
840
+ this.exit(9);
841
+ });
842
+ }
843
+ injectExitHandlers(hdls) {
844
+ this._exitHandlers = hdls;
845
+ }
846
+ exit(code) {
847
+ this._handleExit().then(() => {
848
+ Deno2.exit(code);
849
+ }).catch((err) => {
850
+ console.error("ExitService: failed to handle exit", err);
851
+ Deno2.exit(code);
852
+ });
853
+ }
854
+ };
855
+ var _DenoSystemService = class _DenoSystemService {
856
+ constructor() {
857
+ this._exitService = new DenoExitServiceImpl();
858
+ this._exitService.injectExitHandlers(_DenoSystemService._exitHandlers);
859
+ }
860
+ Env() {
861
+ return envFactory();
862
+ }
863
+ Args() {
864
+ return Deno2.args;
865
+ }
866
+ OnExit(hdl) {
867
+ const id = crypto.randomUUID();
868
+ _DenoSystemService._exitHandlers.push({ hdl, id });
869
+ return () => {
870
+ const idx = _DenoSystemService._exitHandlers.findIndex((h) => h.id === id);
871
+ if (idx >= 0) {
872
+ _DenoSystemService._exitHandlers.splice(idx, 1);
873
+ }
874
+ };
875
+ }
876
+ Exit(code) {
877
+ this._exitService.exit(code);
878
+ }
879
+ };
880
+ _DenoSystemService._exitHandlers = [];
881
+ var DenoSystemService = _DenoSystemService;
882
+
883
+ // src/node/node-file-service.ts
884
+ var import_node_path = __toESM(require("path"), 1);
885
+ var import_node_fs = __toESM(require("fs"), 1);
886
+ var import_node_process = __toESM(require("process"), 1);
887
+
888
+ // src/node/node-sys-abstraction.ts
889
+ var import_node_process2 = __toESM(require("process"), 1);
890
+ var once2 = new ResolveOnce();
891
+ var _node;
892
+ var _NodeEnvActions = class _NodeEnvActions {
764
893
  constructor(opts) {
765
- this.env = /* @__PURE__ */ new Map();
894
+ __privateAdd(this, _node, globalThis);
895
+ this._env = this.active() ? __privateGet(this, _node).process.env : {};
766
896
  this.opts = opts;
767
897
  }
898
+ static new(opts) {
899
+ return once2.once(() => new _NodeEnvActions(opts));
900
+ }
901
+ register(env) {
902
+ for (const key2 of env.keys()) {
903
+ this._env[key2] = env.get(key2) || "";
904
+ }
905
+ return env;
906
+ }
907
+ active() {
908
+ return runtimeFn().isNodeIsh;
909
+ }
910
+ keys() {
911
+ return Object.keys(this._env);
912
+ }
768
913
  get(key2) {
769
- return this.env.get(key2);
914
+ return this._env[key2];
770
915
  }
771
916
  set(key2, value) {
772
917
  if (value) {
773
- this.env.set(key2, value);
918
+ this._env[key2] = value;
774
919
  }
775
920
  }
776
921
  delete(key2) {
777
- this.env.delete(key2);
922
+ delete this._env[key2];
778
923
  }
779
- keys() {
780
- return Array.from(this.env.keys());
924
+ };
925
+ _node = new WeakMap();
926
+ var NodeEnvActions = _NodeEnvActions;
927
+ var NodeExitServiceImpl = class {
928
+ constructor() {
929
+ this._exitHandlers = [];
930
+ this.invoked = false;
931
+ this._handleExit = async () => {
932
+ if (this.invoked) {
933
+ return;
934
+ }
935
+ this.invoked = true;
936
+ for (const h of this._exitHandlers) {
937
+ try {
938
+ const ret = h.hdl();
939
+ if (typeof ret.then === "function") {
940
+ await ret;
941
+ }
942
+ } finally {
943
+ }
944
+ }
945
+ };
946
+ import_node_process2.default.on("unhandledRejection", (reason, p) => {
947
+ this.exit(19);
948
+ });
949
+ import_node_process2.default.on("uncaughtException", (error) => {
950
+ this.exit(18);
951
+ });
952
+ import_node_process2.default.on("close", () => {
953
+ this.exit(0);
954
+ });
955
+ import_node_process2.default.on("exit", () => {
956
+ this.exit(0);
957
+ });
958
+ import_node_process2.default.on("SIGQUIT", () => {
959
+ this.exit(3);
960
+ });
961
+ import_node_process2.default.on("SIGINT", () => {
962
+ this.exit(2);
963
+ });
964
+ import_node_process2.default.on("SIGTERM", () => {
965
+ this.exit(9);
966
+ });
967
+ }
968
+ injectExitHandlers(hdls) {
969
+ this._exitHandlers = hdls;
970
+ }
971
+ exit(code) {
972
+ this._handleExit().then(() => {
973
+ import_node_process2.default.exit(code);
974
+ }).catch((err) => {
975
+ console.error("ExitService: failed to handle exit", err);
976
+ import_node_process2.default.exit(code);
977
+ });
978
+ }
979
+ };
980
+ var _NodeSystemService = class _NodeSystemService {
981
+ constructor() {
982
+ this._exitService = new NodeExitServiceImpl();
983
+ this._exitService.injectExitHandlers(_NodeSystemService._exitHandlers);
984
+ }
985
+ Env() {
986
+ return envFactory();
987
+ }
988
+ Args() {
989
+ return import_node_process2.default.argv;
990
+ }
991
+ OnExit(hdl) {
992
+ const id = crypto.randomUUID();
993
+ _NodeSystemService._exitHandlers.push({ hdl, id });
994
+ return () => {
995
+ const idx = _NodeSystemService._exitHandlers.findIndex((h) => h.id === id);
996
+ if (idx >= 0) {
997
+ _NodeSystemService._exitHandlers.splice(idx, 1);
998
+ }
999
+ };
1000
+ }
1001
+ Exit(code) {
1002
+ this._exitService.exit(code);
1003
+ }
1004
+ };
1005
+ _NodeSystemService._exitHandlers = [];
1006
+ var NodeSystemService = _NodeSystemService;
1007
+
1008
+ // src/cf/cf-sys-abstraction.ts
1009
+ var once3 = new ResolveOnce();
1010
+ var CFEnvActions = class _CFEnvActions {
1011
+ static new(opts) {
1012
+ return once3.once(() => new _CFEnvActions(opts));
1013
+ }
1014
+ static inject(o) {
1015
+ var _a;
1016
+ const env = _CFEnvActions.new({});
1017
+ for (const key2 in o) {
1018
+ const value = o[key2];
1019
+ if (typeof value === "string") {
1020
+ (_a = env.env) == null ? void 0 : _a.set(key2, value);
1021
+ }
1022
+ }
1023
+ }
1024
+ constructor(env) {
1025
+ this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
781
1026
  }
782
1027
  active() {
783
- return true;
1028
+ return runtimeFn().isCFWorker;
784
1029
  }
785
1030
  register(env) {
786
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
787
- const browser = globalThis;
788
- browser[sym] = env;
1031
+ this.env = env;
789
1032
  return env;
790
1033
  }
1034
+ get(key2) {
1035
+ return this.cfEnv.get(key2);
1036
+ }
1037
+ set(key2, value) {
1038
+ if (value) {
1039
+ this.cfEnv.set(key2, value);
1040
+ }
1041
+ }
1042
+ delete(key2) {
1043
+ this.cfEnv.delete(key2);
1044
+ }
1045
+ keys() {
1046
+ return Array.from(this.cfEnv.keys());
1047
+ }
791
1048
  };
1049
+
1050
+ // src/sys-env.ts
792
1051
  var envActions = [
793
- { id: "node", fn: (opts) => new NodeEnvActions(opts) },
794
- { id: "deno", fn: (opts) => new DenoEnvActions(opts) },
795
- { id: "browser", fn: (opts) => new BrowserEnvActions(opts) }
1052
+ { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1053
+ { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1054
+ { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1055
+ { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
796
1056
  ];
797
1057
  function registerEnvAction(fn) {
798
1058
  const id = `id-${Math.random()}`;
799
1059
  envActions.unshift({ id, fn });
800
- _envFactory.reset();
1060
+ _envFactories.unget(id);
801
1061
  return () => {
802
1062
  const index = envActions.findIndex((i) => i.id === id);
803
1063
  if (index >= 0) {
@@ -805,19 +1065,20 @@ function registerEnvAction(fn) {
805
1065
  }
806
1066
  };
807
1067
  }
808
- var _envFactory = new ResolveOnce();
1068
+ var _envFactories = new KeyedResolvOnce();
809
1069
  function envFactory(opts = {}) {
810
- return _envFactory.once(() => {
811
- const found = envActions.map((facItem) => facItem.fn(opts)).find((env) => env.active());
812
- if (!found) {
813
- throw new Error("SysContainer:envFactory: no env available");
814
- }
815
- const ret = new EnvImpl(found, opts);
816
- found.register(ret);
1070
+ const found = envActions.find((fi) => fi.fn(opts).active());
1071
+ if (!found) {
1072
+ throw new Error("SysContainer:envFactory: no env available");
1073
+ }
1074
+ return _envFactories.get(found.id).once(() => {
1075
+ const action = found.fn(opts);
1076
+ const ret = new EnvImpl2(action, opts);
1077
+ action.register(ret);
817
1078
  return ret;
818
1079
  });
819
1080
  }
820
- var EnvImpl = class {
1081
+ var EnvImpl2 = class {
821
1082
  constructor(map, opts = {}) {
822
1083
  this._onSet = [];
823
1084
  this._map = map;
@@ -885,23 +1146,40 @@ var EnvImpl = class {
885
1146
  }
886
1147
  };
887
1148
 
888
- // src/txt-en-decoder.ts
889
- var encoder = new TextEncoder();
890
- var decoder = new TextDecoder();
891
- var Utf8EnDecoder = class {
892
- encode(str) {
893
- return encoder.encode(str);
1149
+ // src/web/web-sys-abstraction.ts
1150
+ var once4 = new ResolveOnce();
1151
+ var BrowserEnvActions = class _BrowserEnvActions {
1152
+ constructor(opts) {
1153
+ this.env = /* @__PURE__ */ new Map();
1154
+ this.opts = opts;
894
1155
  }
895
- decode(data) {
896
- return decoder.decode(data);
1156
+ static new(opts) {
1157
+ return once4.once(() => new _BrowserEnvActions(opts));
1158
+ }
1159
+ get(key2) {
1160
+ return this.env.get(key2);
1161
+ }
1162
+ set(key2, value) {
1163
+ if (value) {
1164
+ this.env.set(key2, value);
1165
+ }
1166
+ }
1167
+ delete(key2) {
1168
+ this.env.delete(key2);
1169
+ }
1170
+ keys() {
1171
+ return Array.from(this.env.keys());
1172
+ }
1173
+ active() {
1174
+ return true;
1175
+ }
1176
+ register(env) {
1177
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1178
+ const browser = globalThis;
1179
+ browser[sym] = env;
1180
+ return env;
897
1181
  }
898
1182
  };
899
- var utf8EnDecoder = new Utf8EnDecoder();
900
- function Utf8EnDecoderSingleton() {
901
- return utf8EnDecoder;
902
- }
903
-
904
- // src/web/web-sys-abstraction.ts
905
1183
  var WebFileService = class {
906
1184
  get baseDir() {
907
1185
  throw new Error("basedir-Method not implemented.");
@@ -1112,23 +1390,23 @@ var Path = class {
1112
1390
  this.parts.push(part);
1113
1391
  }
1114
1392
  };
1115
- function splitPath(path) {
1393
+ function splitPath(path3) {
1116
1394
  const p = new Path();
1117
- if (path === "") {
1395
+ if (path3 === "") {
1118
1396
  return p;
1119
1397
  }
1120
- for (let count = 0; path.length; count++) {
1121
- if (path.match(/^\/+/)) {
1398
+ for (let count = 0; path3.length; count++) {
1399
+ if (path3.match(/^\/+/)) {
1122
1400
  if (count === 0) {
1123
1401
  p.add(3 /* Root */);
1124
1402
  } else {
1125
1403
  p.add(1 /* Slash */);
1126
1404
  }
1127
- path = path.replace(/^\/+/, "");
1405
+ path3 = path3.replace(/^\/+/, "");
1128
1406
  } else {
1129
- const part = path.replace(/\/.*$/, "");
1407
+ const part = path3.replace(/\/.*$/, "");
1130
1408
  p.add(part);
1131
- path = path.replace(/^[^/]+/, "");
1409
+ path3 = path3.replace(/^[^/]+/, "");
1132
1410
  }
1133
1411
  }
1134
1412
  return p;
@@ -1137,29 +1415,29 @@ function pathJoin(...paths) {
1137
1415
  let prev = "";
1138
1416
  const res = [];
1139
1417
  for (let i = 0; i < paths.length; i++) {
1140
- const path = paths[i];
1141
- if (path === "") {
1418
+ const path3 = paths[i];
1419
+ if (path3 === "") {
1142
1420
  continue;
1143
1421
  }
1144
- if (!(prev.endsWith("/") || path.startsWith("/"))) {
1422
+ if (!(prev.endsWith("/") || path3.startsWith("/"))) {
1145
1423
  if (prev !== "") {
1146
1424
  res.push("/");
1147
1425
  }
1148
- res.push(path);
1426
+ res.push(path3);
1149
1427
  } else {
1150
- res.push(path);
1428
+ res.push(path3);
1151
1429
  }
1152
- prev = path;
1430
+ prev = path3;
1153
1431
  }
1154
1432
  return res.join("");
1155
1433
  }
1156
- function relativePath(path, relative) {
1157
- const relativeParts = splitPath(relative);
1434
+ function relativePath(path3, relative2) {
1435
+ const relativeParts = splitPath(relative2);
1158
1436
  let result;
1159
1437
  if (relativeParts.parts[0] === 3 /* Root */) {
1160
- result = relative;
1438
+ result = relative2;
1161
1439
  } else {
1162
- result = pathJoin(path, relative);
1440
+ result = pathJoin(path3, relative2);
1163
1441
  }
1164
1442
  const unoptPath = splitPath(result);
1165
1443
  const out = [];
@@ -1211,12 +1489,12 @@ function stripper(strip, obj) {
1211
1489
  });
1212
1490
  return localStripper(void 0, restrips, obj);
1213
1491
  }
1214
- function localStripper(path, restrips, obj) {
1492
+ function localStripper(path3, restrips, obj) {
1215
1493
  if (typeof obj !== "object" || obj === null) {
1216
1494
  return obj;
1217
1495
  }
1218
1496
  if (Array.isArray(obj)) {
1219
- return obj.map((i) => localStripper(path, restrips, i));
1497
+ return obj.map((i) => localStripper(path3, restrips, i));
1220
1498
  }
1221
1499
  const ret = { ...obj };
1222
1500
  const matcher = (key2, nextPath) => {
@@ -1230,8 +1508,8 @@ function localStripper(path, restrips, obj) {
1230
1508
  for (const key2 in ret) {
1231
1509
  if (Object.prototype.hasOwnProperty.call(ret, key2)) {
1232
1510
  let nextPath;
1233
- if (path) {
1234
- nextPath = [path, key2].join(".");
1511
+ if (path3) {
1512
+ nextPath = [path3, key2].join(".");
1235
1513
  } else {
1236
1514
  nextPath = key2;
1237
1515
  }
@@ -1708,33 +1986,6 @@ var URI = class _URI {
1708
1986
  }
1709
1987
  };
1710
1988
 
1711
- // src/runtime.ts
1712
- function isSet(value, ref = globalThis) {
1713
- const [head, ...tail] = value.split(".");
1714
- if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
1715
- if (tail.length <= 1) {
1716
- return true;
1717
- }
1718
- return isSet(tail.join("."), ref[head]);
1719
- }
1720
- return false;
1721
- }
1722
- function runtimeFn() {
1723
- const gt = globalThis;
1724
- const isReactNative = isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative";
1725
- let isNodeIsh = false;
1726
- if (!isSet("Deno")) {
1727
- isNodeIsh = isSet("process.versions.node") && !isReactNative;
1728
- }
1729
- const isDeno = isSet("Deno");
1730
- return {
1731
- isNodeIsh,
1732
- isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
1733
- isDeno,
1734
- isReactNative
1735
- };
1736
- }
1737
-
1738
1989
  // src/utils/console-write-stream.ts
1739
1990
  var ConsoleWriterStreamDefaultWriter = class {
1740
1991
  constructor(stream) {
@@ -2067,7 +2318,7 @@ var LoggerImpl = class _LoggerImpl {
2067
2318
  if (rt.isBrowser) {
2068
2319
  stream = new ConsoleWriterStream();
2069
2320
  } else {
2070
- if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
2321
+ if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
2071
2322
  stream = this._sys.Stdout();
2072
2323
  } else {
2073
2324
  throw new Error("No output defined for runtime");
@@ -2171,7 +2422,7 @@ var LoggerImpl = class _LoggerImpl {
2171
2422
  }
2172
2423
  if (this.levelHandler.isStackExposed) {
2173
2424
  this._attributes["stack"] = logValue(
2174
- (_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()),
2425
+ (_a = err.stack) == null ? void 0 : _a.split(/[\r\n]+/).map((s) => s.trim()),
2175
2426
  toLogValueCtx(this.levelHandler)
2176
2427
  );
2177
2428
  }
@@ -2287,8 +2538,8 @@ var LoggerImpl = class _LoggerImpl {
2287
2538
  return this.Uint64(key2, value);
2288
2539
  }
2289
2540
  async Flush() {
2290
- return new Promise((resolve) => {
2291
- this._logWriter._flush(void 0, resolve);
2541
+ return new Promise((resolve2) => {
2542
+ this._logWriter._flush(void 0, resolve2);
2292
2543
  });
2293
2544
  }
2294
2545
  With() {
@@ -2599,8 +2850,8 @@ function MockLogger(params) {
2599
2850
 
2600
2851
  // src/tracer.ts
2601
2852
  var Metric = class {
2602
- constructor(path) {
2603
- this.path = path;
2853
+ constructor(path3) {
2854
+ this.path = path3;
2604
2855
  }
2605
2856
  set(value) {
2606
2857
  this.value = value;
@@ -2635,23 +2886,23 @@ var Metrics = class {
2635
2886
  return obj;
2636
2887
  }
2637
2888
  get(ipath) {
2638
- const path = ipath.replace(/[/]+/g, "/").trim();
2639
- if (path.startsWith("/")) {
2640
- if (path.slice(1).length === 0) {
2641
- throw new Error(`Metrics path must contain value /:${path}`);
2889
+ const path3 = ipath.replace(/[/]+/g, "/").trim();
2890
+ if (path3.startsWith("/")) {
2891
+ if (path3.slice(1).length === 0) {
2892
+ throw new Error(`Metrics path must contain value /:${path3}`);
2642
2893
  }
2643
- let metric = this.map.get(path);
2894
+ let metric = this.map.get(path3);
2644
2895
  if (!metric) {
2645
- metric = new Metric(path);
2646
- this.map.set(path, metric);
2896
+ metric = new Metric(path3);
2897
+ this.map.set(path3, metric);
2647
2898
  }
2648
- this.spanRefs.set(path, metric);
2899
+ this.spanRefs.set(path3, metric);
2649
2900
  return metric;
2650
- } else if (path.includes("/")) {
2651
- throw new Error(`Metrics path must start with /:${path}`);
2901
+ } else if (path3.includes("/")) {
2902
+ throw new Error(`Metrics path must start with /:${path3}`);
2652
2903
  }
2653
2904
  const rootPath = this.tracenode.getRootPath();
2654
- return this.get(`${rootPath}/${path}`);
2905
+ return this.get(`${rootPath}/${path3}`);
2655
2906
  }
2656
2907
  };
2657
2908
  var TraceNode = class _TraceNode {
@@ -3075,8 +3326,8 @@ function rebuffer(a, chunkSize) {
3075
3326
  };
3076
3327
  return new ReadableStream({
3077
3328
  async pull(controller) {
3078
- return new Promise((resolve) => {
3079
- pump(state, controller, resolve);
3329
+ return new Promise((resolve2) => {
3330
+ pump(state, controller, resolve2);
3080
3331
  });
3081
3332
  }
3082
3333
  });
@@ -3144,7 +3395,6 @@ function uint8array2stream(str) {
3144
3395
  // Annotate the CommonJS export names for ESM import in node:
3145
3396
  0 && (module.exports = {
3146
3397
  BaseSysAbstraction,
3147
- BrowserEnvActions,
3148
3398
  BuildURI,
3149
3399
  ConstTime,
3150
3400
  EnvImpl,