@adviser/cement 0.3.1 → 0.3.3

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 +936 -0
  4. package/cf/index.cjs.map +1 -0
  5. package/cf/index.d.cts +27 -0
  6. package/cf/index.d.ts +27 -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-HFP74WLI.js +96 -0
  12. package/chunk-HFP74WLI.js.map +1 -0
  13. package/chunk-P6LDM7PY.js +1189 -0
  14. package/chunk-P6LDM7PY.js.map +1 -0
  15. package/chunk-PRCFKZR7.js +1742 -0
  16. package/chunk-PRCFKZR7.js.map +1 -0
  17. package/deno/index.cjs +947 -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 +400 -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 +272 -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 +86 -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 +2688 -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 +25 -0
  64. package/ts/cf/cf-sys-abstraction.d.ts.map +1 -0
  65. package/ts/cf/cf-sys-abstraction.js +80 -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 +396 -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,274 @@ 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
+ constructor(env) {
1012
+ this.injectOnRegister = {};
1013
+ this.cfEnv = new Map(Object.entries(env.presetEnv || {}));
1014
+ }
1015
+ static new(opts) {
1016
+ return once3.once(() => new _CFEnvActions(opts));
1017
+ }
1018
+ static inject(o) {
1019
+ const env = _CFEnvActions.new({});
1020
+ for (const key2 in o) {
1021
+ const value = o[key2];
1022
+ if (typeof value === "string") {
1023
+ if (env.env) {
1024
+ env.env.set(key2, value);
1025
+ } else {
1026
+ env.injectOnRegister[key2] = value;
1027
+ }
1028
+ }
1029
+ }
781
1030
  }
782
1031
  active() {
783
- return true;
1032
+ return runtimeFn().isCFWorker;
784
1033
  }
785
1034
  register(env) {
786
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
787
- const browser = globalThis;
788
- browser[sym] = env;
1035
+ this.env = env;
1036
+ for (const key2 in this.injectOnRegister) {
1037
+ env.set(key2, this.injectOnRegister[key2]);
1038
+ }
789
1039
  return env;
790
1040
  }
1041
+ get(key2) {
1042
+ return this.cfEnv.get(key2);
1043
+ }
1044
+ set(key2, value) {
1045
+ if (value) {
1046
+ this.cfEnv.set(key2, value);
1047
+ }
1048
+ }
1049
+ delete(key2) {
1050
+ this.cfEnv.delete(key2);
1051
+ }
1052
+ keys() {
1053
+ return Array.from(this.cfEnv.keys());
1054
+ }
791
1055
  };
1056
+
1057
+ // src/sys-env.ts
792
1058
  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) }
1059
+ { id: "cf", fn: (opts) => CFEnvActions.new(opts) },
1060
+ { id: "node", fn: (opts) => NodeEnvActions.new(opts) },
1061
+ { id: "deno", fn: (opts) => DenoEnvActions.new(opts) },
1062
+ { id: "browser", fn: (opts) => BrowserEnvActions.new(opts) }
796
1063
  ];
797
1064
  function registerEnvAction(fn) {
798
1065
  const id = `id-${Math.random()}`;
799
1066
  envActions.unshift({ id, fn });
800
- _envFactory.reset();
1067
+ _envFactories.unget(id);
801
1068
  return () => {
802
1069
  const index = envActions.findIndex((i) => i.id === id);
803
1070
  if (index >= 0) {
@@ -805,19 +1072,20 @@ function registerEnvAction(fn) {
805
1072
  }
806
1073
  };
807
1074
  }
808
- var _envFactory = new ResolveOnce();
1075
+ var _envFactories = new KeyedResolvOnce();
809
1076
  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);
1077
+ const found = envActions.find((fi) => fi.fn(opts).active());
1078
+ if (!found) {
1079
+ throw new Error("SysContainer:envFactory: no env available");
1080
+ }
1081
+ return _envFactories.get(found.id).once(() => {
1082
+ const action = found.fn(opts);
1083
+ const ret = new EnvImpl2(action, opts);
1084
+ action.register(ret);
817
1085
  return ret;
818
1086
  });
819
1087
  }
820
- var EnvImpl = class {
1088
+ var EnvImpl2 = class {
821
1089
  constructor(map, opts = {}) {
822
1090
  this._onSet = [];
823
1091
  this._map = map;
@@ -885,23 +1153,40 @@ var EnvImpl = class {
885
1153
  }
886
1154
  };
887
1155
 
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);
1156
+ // src/web/web-sys-abstraction.ts
1157
+ var once4 = new ResolveOnce();
1158
+ var BrowserEnvActions = class _BrowserEnvActions {
1159
+ constructor(opts) {
1160
+ this.env = /* @__PURE__ */ new Map();
1161
+ this.opts = opts;
894
1162
  }
895
- decode(data) {
896
- return decoder.decode(data);
1163
+ static new(opts) {
1164
+ return once4.once(() => new _BrowserEnvActions(opts));
1165
+ }
1166
+ get(key2) {
1167
+ return this.env.get(key2);
1168
+ }
1169
+ set(key2, value) {
1170
+ if (value) {
1171
+ this.env.set(key2, value);
1172
+ }
1173
+ }
1174
+ delete(key2) {
1175
+ this.env.delete(key2);
1176
+ }
1177
+ keys() {
1178
+ return Array.from(this.env.keys());
1179
+ }
1180
+ active() {
1181
+ return true;
1182
+ }
1183
+ register(env) {
1184
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
1185
+ const browser = globalThis;
1186
+ browser[sym] = env;
1187
+ return env;
897
1188
  }
898
1189
  };
899
- var utf8EnDecoder = new Utf8EnDecoder();
900
- function Utf8EnDecoderSingleton() {
901
- return utf8EnDecoder;
902
- }
903
-
904
- // src/web/web-sys-abstraction.ts
905
1190
  var WebFileService = class {
906
1191
  get baseDir() {
907
1192
  throw new Error("basedir-Method not implemented.");
@@ -1112,23 +1397,23 @@ var Path = class {
1112
1397
  this.parts.push(part);
1113
1398
  }
1114
1399
  };
1115
- function splitPath(path) {
1400
+ function splitPath(path3) {
1116
1401
  const p = new Path();
1117
- if (path === "") {
1402
+ if (path3 === "") {
1118
1403
  return p;
1119
1404
  }
1120
- for (let count = 0; path.length; count++) {
1121
- if (path.match(/^\/+/)) {
1405
+ for (let count = 0; path3.length; count++) {
1406
+ if (path3.match(/^\/+/)) {
1122
1407
  if (count === 0) {
1123
1408
  p.add(3 /* Root */);
1124
1409
  } else {
1125
1410
  p.add(1 /* Slash */);
1126
1411
  }
1127
- path = path.replace(/^\/+/, "");
1412
+ path3 = path3.replace(/^\/+/, "");
1128
1413
  } else {
1129
- const part = path.replace(/\/.*$/, "");
1414
+ const part = path3.replace(/\/.*$/, "");
1130
1415
  p.add(part);
1131
- path = path.replace(/^[^/]+/, "");
1416
+ path3 = path3.replace(/^[^/]+/, "");
1132
1417
  }
1133
1418
  }
1134
1419
  return p;
@@ -1137,29 +1422,29 @@ function pathJoin(...paths) {
1137
1422
  let prev = "";
1138
1423
  const res = [];
1139
1424
  for (let i = 0; i < paths.length; i++) {
1140
- const path = paths[i];
1141
- if (path === "") {
1425
+ const path3 = paths[i];
1426
+ if (path3 === "") {
1142
1427
  continue;
1143
1428
  }
1144
- if (!(prev.endsWith("/") || path.startsWith("/"))) {
1429
+ if (!(prev.endsWith("/") || path3.startsWith("/"))) {
1145
1430
  if (prev !== "") {
1146
1431
  res.push("/");
1147
1432
  }
1148
- res.push(path);
1433
+ res.push(path3);
1149
1434
  } else {
1150
- res.push(path);
1435
+ res.push(path3);
1151
1436
  }
1152
- prev = path;
1437
+ prev = path3;
1153
1438
  }
1154
1439
  return res.join("");
1155
1440
  }
1156
- function relativePath(path, relative) {
1157
- const relativeParts = splitPath(relative);
1441
+ function relativePath(path3, relative2) {
1442
+ const relativeParts = splitPath(relative2);
1158
1443
  let result;
1159
1444
  if (relativeParts.parts[0] === 3 /* Root */) {
1160
- result = relative;
1445
+ result = relative2;
1161
1446
  } else {
1162
- result = pathJoin(path, relative);
1447
+ result = pathJoin(path3, relative2);
1163
1448
  }
1164
1449
  const unoptPath = splitPath(result);
1165
1450
  const out = [];
@@ -1211,12 +1496,12 @@ function stripper(strip, obj) {
1211
1496
  });
1212
1497
  return localStripper(void 0, restrips, obj);
1213
1498
  }
1214
- function localStripper(path, restrips, obj) {
1499
+ function localStripper(path3, restrips, obj) {
1215
1500
  if (typeof obj !== "object" || obj === null) {
1216
1501
  return obj;
1217
1502
  }
1218
1503
  if (Array.isArray(obj)) {
1219
- return obj.map((i) => localStripper(path, restrips, i));
1504
+ return obj.map((i) => localStripper(path3, restrips, i));
1220
1505
  }
1221
1506
  const ret = { ...obj };
1222
1507
  const matcher = (key2, nextPath) => {
@@ -1230,8 +1515,8 @@ function localStripper(path, restrips, obj) {
1230
1515
  for (const key2 in ret) {
1231
1516
  if (Object.prototype.hasOwnProperty.call(ret, key2)) {
1232
1517
  let nextPath;
1233
- if (path) {
1234
- nextPath = [path, key2].join(".");
1518
+ if (path3) {
1519
+ nextPath = [path3, key2].join(".");
1235
1520
  } else {
1236
1521
  nextPath = key2;
1237
1522
  }
@@ -1708,33 +1993,6 @@ var URI = class _URI {
1708
1993
  }
1709
1994
  };
1710
1995
 
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
1996
  // src/utils/console-write-stream.ts
1739
1997
  var ConsoleWriterStreamDefaultWriter = class {
1740
1998
  constructor(stream) {
@@ -2067,7 +2325,7 @@ var LoggerImpl = class _LoggerImpl {
2067
2325
  if (rt.isBrowser) {
2068
2326
  stream = new ConsoleWriterStream();
2069
2327
  } else {
2070
- if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
2328
+ if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
2071
2329
  stream = this._sys.Stdout();
2072
2330
  } else {
2073
2331
  throw new Error("No output defined for runtime");
@@ -2171,7 +2429,7 @@ var LoggerImpl = class _LoggerImpl {
2171
2429
  }
2172
2430
  if (this.levelHandler.isStackExposed) {
2173
2431
  this._attributes["stack"] = logValue(
2174
- (_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()),
2432
+ (_a = err.stack) == null ? void 0 : _a.split(/[\r\n]+/).map((s) => s.trim()),
2175
2433
  toLogValueCtx(this.levelHandler)
2176
2434
  );
2177
2435
  }
@@ -2287,8 +2545,8 @@ var LoggerImpl = class _LoggerImpl {
2287
2545
  return this.Uint64(key2, value);
2288
2546
  }
2289
2547
  async Flush() {
2290
- return new Promise((resolve) => {
2291
- this._logWriter._flush(void 0, resolve);
2548
+ return new Promise((resolve2) => {
2549
+ this._logWriter._flush(void 0, resolve2);
2292
2550
  });
2293
2551
  }
2294
2552
  With() {
@@ -2599,8 +2857,8 @@ function MockLogger(params) {
2599
2857
 
2600
2858
  // src/tracer.ts
2601
2859
  var Metric = class {
2602
- constructor(path) {
2603
- this.path = path;
2860
+ constructor(path3) {
2861
+ this.path = path3;
2604
2862
  }
2605
2863
  set(value) {
2606
2864
  this.value = value;
@@ -2635,23 +2893,23 @@ var Metrics = class {
2635
2893
  return obj;
2636
2894
  }
2637
2895
  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}`);
2896
+ const path3 = ipath.replace(/[/]+/g, "/").trim();
2897
+ if (path3.startsWith("/")) {
2898
+ if (path3.slice(1).length === 0) {
2899
+ throw new Error(`Metrics path must contain value /:${path3}`);
2642
2900
  }
2643
- let metric = this.map.get(path);
2901
+ let metric = this.map.get(path3);
2644
2902
  if (!metric) {
2645
- metric = new Metric(path);
2646
- this.map.set(path, metric);
2903
+ metric = new Metric(path3);
2904
+ this.map.set(path3, metric);
2647
2905
  }
2648
- this.spanRefs.set(path, metric);
2906
+ this.spanRefs.set(path3, metric);
2649
2907
  return metric;
2650
- } else if (path.includes("/")) {
2651
- throw new Error(`Metrics path must start with /:${path}`);
2908
+ } else if (path3.includes("/")) {
2909
+ throw new Error(`Metrics path must start with /:${path3}`);
2652
2910
  }
2653
2911
  const rootPath = this.tracenode.getRootPath();
2654
- return this.get(`${rootPath}/${path}`);
2912
+ return this.get(`${rootPath}/${path3}`);
2655
2913
  }
2656
2914
  };
2657
2915
  var TraceNode = class _TraceNode {
@@ -3075,8 +3333,8 @@ function rebuffer(a, chunkSize) {
3075
3333
  };
3076
3334
  return new ReadableStream({
3077
3335
  async pull(controller) {
3078
- return new Promise((resolve) => {
3079
- pump(state, controller, resolve);
3336
+ return new Promise((resolve2) => {
3337
+ pump(state, controller, resolve2);
3080
3338
  });
3081
3339
  }
3082
3340
  });
@@ -3144,7 +3402,6 @@ function uint8array2stream(str) {
3144
3402
  // Annotate the CommonJS export names for ESM import in node:
3145
3403
  0 && (module.exports = {
3146
3404
  BaseSysAbstraction,
3147
- BrowserEnvActions,
3148
3405
  BuildURI,
3149
3406
  ConstTime,
3150
3407
  EnvImpl,