@adviser/cement 0.3.0 → 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 (141) 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 +407 -139
  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 +36 -1729
  30. package/index.js.map +1 -1
  31. package/node/index.cjs +267 -214
  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 +36 -109
  51. package/src/test/index.ts +2 -0
  52. package/src/uri.ts +2 -2
  53. package/src/web/web-sys-abstraction.ts +42 -2
  54. package/sys-abstraction-GNnBj2sz.d.cts +102 -0
  55. package/sys-abstraction-GNnBj2sz.d.ts +102 -0
  56. package/test/index.cjs +2681 -0
  57. package/test/index.cjs.map +1 -0
  58. package/test/index.d.cts +3 -0
  59. package/test/index.d.ts +3 -0
  60. package/test/index.js +14 -0
  61. package/test/index.js.map +1 -0
  62. package/ts/base-sys-abstraction.test.js +8 -2
  63. package/ts/base-sys-abstraction.test.js.map +1 -1
  64. package/ts/cf/cf-sys-abstraction.d.ts +24 -0
  65. package/ts/cf/cf-sys-abstraction.d.ts.map +1 -0
  66. package/ts/cf/cf-sys-abstraction.js +72 -0
  67. package/ts/cf/cf-sys-abstraction.js.map +1 -0
  68. package/ts/cf/index.d.ts +2 -0
  69. package/ts/cf/index.d.ts.map +1 -0
  70. package/ts/cf/index.js +2 -0
  71. package/ts/cf/index.js.map +1 -0
  72. package/ts/crypto.test.js +1 -1
  73. package/ts/crypto.test.js.map +1 -1
  74. package/ts/{node → deno}/deno-file-service.d.ts.map +1 -1
  75. package/ts/{node → deno}/deno-file-service.js +1 -1
  76. package/ts/{node → deno}/deno-file-service.js.map +1 -1
  77. package/ts/deno/deno-sys-abstraction.d.ts +43 -0
  78. package/ts/deno/deno-sys-abstraction.d.ts.map +1 -0
  79. package/ts/{node → deno}/deno-sys-abstraction.js +46 -2
  80. package/ts/deno/deno-sys-abstraction.js.map +1 -0
  81. package/ts/deno/index.d.ts +3 -0
  82. package/ts/deno/index.d.ts.map +1 -0
  83. package/ts/deno/index.js +3 -0
  84. package/ts/deno/index.js.map +1 -0
  85. package/ts/index.d.ts +1 -2
  86. package/ts/index.d.ts.map +1 -1
  87. package/ts/index.js +1 -2
  88. package/ts/index.js.map +1 -1
  89. package/ts/logger-impl.js +2 -2
  90. package/ts/logger-impl.js.map +1 -1
  91. package/ts/logger.d.ts.map +1 -1
  92. package/ts/logger.js +9 -3
  93. package/ts/logger.js.map +1 -1
  94. package/ts/logger.test.js +9 -9
  95. package/ts/logger.test.js.map +1 -1
  96. package/ts/node/index.d.ts +0 -1
  97. package/ts/node/index.d.ts.map +1 -1
  98. package/ts/node/index.js +0 -1
  99. package/ts/node/index.js.map +1 -1
  100. package/ts/node/node-sys-abstraction.d.ts +14 -1
  101. package/ts/node/node-sys-abstraction.d.ts.map +1 -1
  102. package/ts/node/node-sys-abstraction.js +43 -0
  103. package/ts/node/node-sys-abstraction.js.map +1 -1
  104. package/ts/runtime.d.ts +1 -0
  105. package/ts/runtime.d.ts.map +1 -1
  106. package/ts/runtime.js +10 -3
  107. package/ts/runtime.js.map +1 -1
  108. package/ts/sys-env.d.ts +2 -11
  109. package/ts/sys-env.d.ts.map +1 -1
  110. package/ts/sys-env.js +29 -98
  111. package/ts/sys-env.js.map +1 -1
  112. package/ts/sys-env.test.js +68 -3
  113. package/ts/sys-env.test.js.map +1 -1
  114. package/ts/test/index.d.ts +3 -0
  115. package/ts/test/index.d.ts.map +1 -0
  116. package/ts/test/index.js +3 -0
  117. package/ts/test/index.js.map +1 -0
  118. package/ts/test/test-exit-handler.js +1 -1
  119. package/ts/uri.d.ts +2 -2
  120. package/ts/uri.d.ts.map +1 -1
  121. package/ts/web/web-sys-abstraction.d.ts +27 -0
  122. package/ts/web/web-sys-abstraction.d.ts.map +1 -1
  123. package/ts/web/web-sys-abstraction.js +35 -1
  124. package/ts/web/web-sys-abstraction.js.map +1 -1
  125. package/utils/index.js +6 -4
  126. package/web/index.cjs +391 -64
  127. package/web/index.cjs.map +1 -1
  128. package/web/index.d.cts +28 -2
  129. package/web/index.d.ts +28 -2
  130. package/web/index.js +5 -2
  131. package/base-sys-abstraction-BkEiLHl0.d.ts +0 -193
  132. package/base-sys-abstraction-Qj7pkY1N.d.cts +0 -193
  133. package/chunk-3RHIVQAA.js.map +0 -1
  134. package/chunk-N3NUTN4B.js +0 -87
  135. package/chunk-N3NUTN4B.js.map +0 -1
  136. package/chunk-N5LQQXOU.js +0 -610
  137. package/chunk-N5LQQXOU.js.map +0 -1
  138. package/ts/node/deno-sys-abstraction.d.ts +0 -22
  139. package/ts/node/deno-sys-abstraction.d.ts.map +0 -1
  140. package/ts/node/deno-sys-abstraction.js.map +0 -1
  141. /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,
@@ -96,6 +95,7 @@ __export(src_exports, {
96
95
  isURL: () => isURL,
97
96
  key: () => key,
98
97
  logValue: () => logValue,
98
+ registerEnvAction: () => registerEnvAction,
99
99
  runtimeFn: () => runtimeFn,
100
100
  toCryptoRuntime: () => toCryptoRuntime,
101
101
  utils: () => utils_exports
@@ -199,11 +199,16 @@ function logValueInternal(val, ctx) {
199
199
  return logValueInternal(ret, ctx);
200
200
  }
201
201
  } catch (e) {
202
- if (val.match(/[\n\r]/)) {
203
- const lines = val.trimEnd().split(/[\n\r]/);
204
- return new LogValue(() => lines);
202
+ try {
203
+ const url = new URL(val);
204
+ return new LogValue(() => url.toString());
205
+ } catch (e2) {
205
206
  }
206
207
  }
208
+ if (val.match(/[\n\r]/)) {
209
+ const lines = val.split(/[\n\r]+/).map((v) => v.trim());
210
+ return new LogValue(() => lines);
211
+ }
207
212
  return new LogValue(() => val.toString());
208
213
  }
209
214
  case "number":
@@ -343,9 +348,9 @@ var SysTime = class extends Time {
343
348
  return /* @__PURE__ */ new Date();
344
349
  }
345
350
  Sleep(duration) {
346
- return new Promise((resolve) => {
351
+ return new Promise((resolve2) => {
347
352
  setTimeout(() => {
348
- resolve();
353
+ resolve2();
349
354
  }, duration);
350
355
  });
351
356
  }
@@ -535,8 +540,8 @@ var Future = class {
535
540
  __privateAdd(this, _rejectFn, () => {
536
541
  throw new Error("This Promise is not working as expected.");
537
542
  });
538
- __privateSet(this, _promise, new Promise((resolve, reject) => {
539
- __privateSet(this, _resolveFn, resolve);
543
+ __privateSet(this, _promise, new Promise((resolve2, reject) => {
544
+ __privateSet(this, _resolveFn, resolve2);
540
545
  __privateSet(this, _rejectFn, reject);
541
546
  }));
542
547
  }
@@ -698,53 +703,86 @@ var KeyedResolvSeq = class extends Keyed {
698
703
  }
699
704
  };
700
705
 
701
- // src/sys-env.ts
702
- var _node;
703
- var NodeEnvActions = class {
704
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
705
- constructor(opts) {
706
- __privateAdd(this, _node, globalThis);
707
- this._env = this.active() ? __privateGet(this, _node).process.env : {};
708
- }
709
- register(env) {
710
- return env;
711
- }
712
- active() {
713
- 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]);
714
714
  }
715
- keys() {
716
- 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;
717
723
  }
718
- get(key2) {
719
- 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;
720
730
  }
721
- set(key2, value) {
722
- if (value) {
723
- this._env[key2] = value;
724
- }
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);
725
746
  }
726
- delete(key2) {
727
- delete this._env[key2];
747
+ decode(data) {
748
+ return decoder.decode(data);
728
749
  }
729
750
  };
730
- _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();
731
763
  var _deno;
732
- var DenoEnvActions = class {
733
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
764
+ var _DenoEnvActions = class _DenoEnvActions {
734
765
  constructor(opts) {
735
766
  __privateAdd(this, _deno, globalThis);
767
+ this.opts = opts;
768
+ }
769
+ static new(opts) {
770
+ return once.once(() => new _DenoEnvActions(opts));
736
771
  }
737
772
  get _env() {
738
773
  return __privateGet(this, _deno).Deno.env;
739
774
  }
740
775
  register(env) {
776
+ for (const key2 of env.keys()) {
777
+ this._env.set(key2, env.get(key2) || "");
778
+ }
741
779
  return env;
742
780
  }
743
781
  active() {
744
- return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
782
+ return runtimeFn().isDeno;
745
783
  }
746
784
  keys() {
747
- return Array.from(this._env.keys());
785
+ return Object.keys(this._env.toObject());
748
786
  }
749
787
  get(key2) {
750
788
  return this._env.get(key2);
@@ -759,48 +797,288 @@ var DenoEnvActions = class {
759
797
  }
760
798
  };
761
799
  _deno = new WeakMap();
762
- 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 {
763
893
  constructor(opts) {
764
- this.env = /* @__PURE__ */ new Map();
894
+ __privateAdd(this, _node, globalThis);
895
+ this._env = this.active() ? __privateGet(this, _node).process.env : {};
765
896
  this.opts = opts;
766
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
+ }
767
913
  get(key2) {
768
- return this.env.get(key2);
914
+ return this._env[key2];
769
915
  }
770
916
  set(key2, value) {
771
917
  if (value) {
772
- this.env.set(key2, value);
918
+ this._env[key2] = value;
773
919
  }
774
920
  }
775
921
  delete(key2) {
776
- this.env.delete(key2);
922
+ delete this._env[key2];
777
923
  }
778
- keys() {
779
- 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 || {}));
780
1026
  }
781
1027
  active() {
782
- return true;
1028
+ return runtimeFn().isCFWorker;
783
1029
  }
784
1030
  register(env) {
785
- const sym = Symbol.for(this.opts.symbol || "CP_ENV");
786
- const browser = globalThis;
787
- browser[sym] = env;
1031
+ this.env = env;
788
1032
  return env;
789
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
+ }
790
1048
  };
791
- var _envFactory = new ResolveOnce();
792
- function envFactory(opts = {}) {
793
- return _envFactory.once(() => {
794
- const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());
795
- if (!found) {
796
- throw new Error("SysContainer:envFactory: no env available");
1049
+
1050
+ // src/sys-env.ts
1051
+ var envActions = [
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) }
1056
+ ];
1057
+ function registerEnvAction(fn) {
1058
+ const id = `id-${Math.random()}`;
1059
+ envActions.unshift({ id, fn });
1060
+ _envFactories.unget(id);
1061
+ return () => {
1062
+ const index = envActions.findIndex((i) => i.id === id);
1063
+ if (index >= 0) {
1064
+ envActions.splice(index, 1);
797
1065
  }
798
- const ret = new EnvImpl(found, opts);
799
- found.register(ret);
1066
+ };
1067
+ }
1068
+ var _envFactories = new KeyedResolvOnce();
1069
+ function envFactory(opts = {}) {
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);
800
1078
  return ret;
801
1079
  });
802
1080
  }
803
- var EnvImpl = class {
1081
+ var EnvImpl2 = class {
804
1082
  constructor(map, opts = {}) {
805
1083
  this._onSet = [];
806
1084
  this._map = map;
@@ -868,23 +1146,40 @@ var EnvImpl = class {
868
1146
  }
869
1147
  };
870
1148
 
871
- // src/txt-en-decoder.ts
872
- var encoder = new TextEncoder();
873
- var decoder = new TextDecoder();
874
- var Utf8EnDecoder = class {
875
- encode(str) {
876
- 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;
877
1155
  }
878
- decode(data) {
879
- 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;
880
1181
  }
881
1182
  };
882
- var utf8EnDecoder = new Utf8EnDecoder();
883
- function Utf8EnDecoderSingleton() {
884
- return utf8EnDecoder;
885
- }
886
-
887
- // src/web/web-sys-abstraction.ts
888
1183
  var WebFileService = class {
889
1184
  get baseDir() {
890
1185
  throw new Error("basedir-Method not implemented.");
@@ -1095,23 +1390,23 @@ var Path = class {
1095
1390
  this.parts.push(part);
1096
1391
  }
1097
1392
  };
1098
- function splitPath(path) {
1393
+ function splitPath(path3) {
1099
1394
  const p = new Path();
1100
- if (path === "") {
1395
+ if (path3 === "") {
1101
1396
  return p;
1102
1397
  }
1103
- for (let count = 0; path.length; count++) {
1104
- if (path.match(/^\/+/)) {
1398
+ for (let count = 0; path3.length; count++) {
1399
+ if (path3.match(/^\/+/)) {
1105
1400
  if (count === 0) {
1106
1401
  p.add(3 /* Root */);
1107
1402
  } else {
1108
1403
  p.add(1 /* Slash */);
1109
1404
  }
1110
- path = path.replace(/^\/+/, "");
1405
+ path3 = path3.replace(/^\/+/, "");
1111
1406
  } else {
1112
- const part = path.replace(/\/.*$/, "");
1407
+ const part = path3.replace(/\/.*$/, "");
1113
1408
  p.add(part);
1114
- path = path.replace(/^[^/]+/, "");
1409
+ path3 = path3.replace(/^[^/]+/, "");
1115
1410
  }
1116
1411
  }
1117
1412
  return p;
@@ -1120,29 +1415,29 @@ function pathJoin(...paths) {
1120
1415
  let prev = "";
1121
1416
  const res = [];
1122
1417
  for (let i = 0; i < paths.length; i++) {
1123
- const path = paths[i];
1124
- if (path === "") {
1418
+ const path3 = paths[i];
1419
+ if (path3 === "") {
1125
1420
  continue;
1126
1421
  }
1127
- if (!(prev.endsWith("/") || path.startsWith("/"))) {
1422
+ if (!(prev.endsWith("/") || path3.startsWith("/"))) {
1128
1423
  if (prev !== "") {
1129
1424
  res.push("/");
1130
1425
  }
1131
- res.push(path);
1426
+ res.push(path3);
1132
1427
  } else {
1133
- res.push(path);
1428
+ res.push(path3);
1134
1429
  }
1135
- prev = path;
1430
+ prev = path3;
1136
1431
  }
1137
1432
  return res.join("");
1138
1433
  }
1139
- function relativePath(path, relative) {
1140
- const relativeParts = splitPath(relative);
1434
+ function relativePath(path3, relative2) {
1435
+ const relativeParts = splitPath(relative2);
1141
1436
  let result;
1142
1437
  if (relativeParts.parts[0] === 3 /* Root */) {
1143
- result = relative;
1438
+ result = relative2;
1144
1439
  } else {
1145
- result = pathJoin(path, relative);
1440
+ result = pathJoin(path3, relative2);
1146
1441
  }
1147
1442
  const unoptPath = splitPath(result);
1148
1443
  const out = [];
@@ -1194,12 +1489,12 @@ function stripper(strip, obj) {
1194
1489
  });
1195
1490
  return localStripper(void 0, restrips, obj);
1196
1491
  }
1197
- function localStripper(path, restrips, obj) {
1492
+ function localStripper(path3, restrips, obj) {
1198
1493
  if (typeof obj !== "object" || obj === null) {
1199
1494
  return obj;
1200
1495
  }
1201
1496
  if (Array.isArray(obj)) {
1202
- return obj.map((i) => localStripper(path, restrips, i));
1497
+ return obj.map((i) => localStripper(path3, restrips, i));
1203
1498
  }
1204
1499
  const ret = { ...obj };
1205
1500
  const matcher = (key2, nextPath) => {
@@ -1213,8 +1508,8 @@ function localStripper(path, restrips, obj) {
1213
1508
  for (const key2 in ret) {
1214
1509
  if (Object.prototype.hasOwnProperty.call(ret, key2)) {
1215
1510
  let nextPath;
1216
- if (path) {
1217
- nextPath = [path, key2].join(".");
1511
+ if (path3) {
1512
+ nextPath = [path3, key2].join(".");
1218
1513
  } else {
1219
1514
  nextPath = key2;
1220
1515
  }
@@ -1691,33 +1986,6 @@ var URI = class _URI {
1691
1986
  }
1692
1987
  };
1693
1988
 
1694
- // src/runtime.ts
1695
- function isSet(value, ref = globalThis) {
1696
- const [head, ...tail] = value.split(".");
1697
- if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
1698
- if (tail.length <= 1) {
1699
- return true;
1700
- }
1701
- return isSet(tail.join("."), ref[head]);
1702
- }
1703
- return false;
1704
- }
1705
- function runtimeFn() {
1706
- const gt = globalThis;
1707
- const isReactNative = isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative";
1708
- let isNodeIsh = false;
1709
- if (!isSet("Deno")) {
1710
- isNodeIsh = isSet("process.versions.node") && !isReactNative;
1711
- }
1712
- const isDeno = isSet("Deno");
1713
- return {
1714
- isNodeIsh,
1715
- isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
1716
- isDeno,
1717
- isReactNative
1718
- };
1719
- }
1720
-
1721
1989
  // src/utils/console-write-stream.ts
1722
1990
  var ConsoleWriterStreamDefaultWriter = class {
1723
1991
  constructor(stream) {
@@ -2050,7 +2318,7 @@ var LoggerImpl = class _LoggerImpl {
2050
2318
  if (rt.isBrowser) {
2051
2319
  stream = new ConsoleWriterStream();
2052
2320
  } else {
2053
- if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
2321
+ if (rt.isNodeIsh || rt.isReactNative || rt.isDeno || rt.isCFWorker) {
2054
2322
  stream = this._sys.Stdout();
2055
2323
  } else {
2056
2324
  throw new Error("No output defined for runtime");
@@ -2154,7 +2422,7 @@ var LoggerImpl = class _LoggerImpl {
2154
2422
  }
2155
2423
  if (this.levelHandler.isStackExposed) {
2156
2424
  this._attributes["stack"] = logValue(
2157
- (_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()),
2158
2426
  toLogValueCtx(this.levelHandler)
2159
2427
  );
2160
2428
  }
@@ -2270,8 +2538,8 @@ var LoggerImpl = class _LoggerImpl {
2270
2538
  return this.Uint64(key2, value);
2271
2539
  }
2272
2540
  async Flush() {
2273
- return new Promise((resolve) => {
2274
- this._logWriter._flush(void 0, resolve);
2541
+ return new Promise((resolve2) => {
2542
+ this._logWriter._flush(void 0, resolve2);
2275
2543
  });
2276
2544
  }
2277
2545
  With() {
@@ -2582,8 +2850,8 @@ function MockLogger(params) {
2582
2850
 
2583
2851
  // src/tracer.ts
2584
2852
  var Metric = class {
2585
- constructor(path) {
2586
- this.path = path;
2853
+ constructor(path3) {
2854
+ this.path = path3;
2587
2855
  }
2588
2856
  set(value) {
2589
2857
  this.value = value;
@@ -2618,23 +2886,23 @@ var Metrics = class {
2618
2886
  return obj;
2619
2887
  }
2620
2888
  get(ipath) {
2621
- const path = ipath.replace(/[/]+/g, "/").trim();
2622
- if (path.startsWith("/")) {
2623
- if (path.slice(1).length === 0) {
2624
- 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}`);
2625
2893
  }
2626
- let metric = this.map.get(path);
2894
+ let metric = this.map.get(path3);
2627
2895
  if (!metric) {
2628
- metric = new Metric(path);
2629
- this.map.set(path, metric);
2896
+ metric = new Metric(path3);
2897
+ this.map.set(path3, metric);
2630
2898
  }
2631
- this.spanRefs.set(path, metric);
2899
+ this.spanRefs.set(path3, metric);
2632
2900
  return metric;
2633
- } else if (path.includes("/")) {
2634
- throw new Error(`Metrics path must start with /:${path}`);
2901
+ } else if (path3.includes("/")) {
2902
+ throw new Error(`Metrics path must start with /:${path3}`);
2635
2903
  }
2636
2904
  const rootPath = this.tracenode.getRootPath();
2637
- return this.get(`${rootPath}/${path}`);
2905
+ return this.get(`${rootPath}/${path3}`);
2638
2906
  }
2639
2907
  };
2640
2908
  var TraceNode = class _TraceNode {
@@ -3058,8 +3326,8 @@ function rebuffer(a, chunkSize) {
3058
3326
  };
3059
3327
  return new ReadableStream({
3060
3328
  async pull(controller) {
3061
- return new Promise((resolve) => {
3062
- pump(state, controller, resolve);
3329
+ return new Promise((resolve2) => {
3330
+ pump(state, controller, resolve2);
3063
3331
  });
3064
3332
  }
3065
3333
  });
@@ -3127,7 +3395,6 @@ function uint8array2stream(str) {
3127
3395
  // Annotate the CommonJS export names for ESM import in node:
3128
3396
  0 && (module.exports = {
3129
3397
  BaseSysAbstraction,
3130
- BrowserEnvActions,
3131
3398
  BuildURI,
3132
3399
  ConstTime,
3133
3400
  EnvImpl,
@@ -3185,6 +3452,7 @@ function uint8array2stream(str) {
3185
3452
  isURL,
3186
3453
  key,
3187
3454
  logValue,
3455
+ registerEnvAction,
3188
3456
  runtimeFn,
3189
3457
  toCryptoRuntime,
3190
3458
  utils