@adviser/cement 0.0.0-jsr-t1

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 (320) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +39 -0
  3. package/base-sys-abstraction-BkEiLHl0.d.ts +193 -0
  4. package/base-sys-abstraction-Qj7pkY1N.d.cts +193 -0
  5. package/chunk-7KFVMTOS.js +311 -0
  6. package/chunk-7KFVMTOS.js.map +1 -0
  7. package/chunk-GES3MUGV.js +92 -0
  8. package/chunk-GES3MUGV.js.map +1 -0
  9. package/chunk-Q65HLCNL.js +601 -0
  10. package/chunk-Q65HLCNL.js.map +1 -0
  11. package/chunk-WMMUXBDX.js +87 -0
  12. package/chunk-WMMUXBDX.js.map +1 -0
  13. package/index-Q3phXzYr.d.cts +75 -0
  14. package/index-tIGZMHTc.d.ts +75 -0
  15. package/index.cjs +2593 -0
  16. package/index.cjs.map +1 -0
  17. package/index.d.cts +532 -0
  18. package/index.d.ts +532 -0
  19. package/index.js +1533 -0
  20. package/index.js.map +1 -0
  21. package/node/index.cjs +924 -0
  22. package/node/index.cjs.map +1 -0
  23. package/node/index.d.cts +65 -0
  24. package/node/index.d.ts +65 -0
  25. package/node/index.js +398 -0
  26. package/node/index.js.map +1 -0
  27. package/package.json +81 -0
  28. package/src/base-sys-abstraction.test.ts +95 -0
  29. package/src/base-sys-abstraction.ts +242 -0
  30. package/src/bin2text.test.ts +59 -0
  31. package/src/bin2text.ts +47 -0
  32. package/src/crypto.test.ts +15 -0
  33. package/src/crypto.ts +125 -0
  34. package/src/file-service.ts +24 -0
  35. package/src/future.test.ts +32 -0
  36. package/src/future.ts +27 -0
  37. package/src/index.ts +22 -0
  38. package/src/jsr.json +20 -0
  39. package/src/log-level-impl.ts +87 -0
  40. package/src/log-writer-impl.ts +58 -0
  41. package/src/logger-impl.ts +498 -0
  42. package/src/logger.test.ts +1132 -0
  43. package/src/logger.ts +208 -0
  44. package/src/node/deno-file-service.ts +92 -0
  45. package/src/node/deno-sys-abstraction.ts +133 -0
  46. package/src/node/index.ts +4 -0
  47. package/src/node/mock-file-service.ts +45 -0
  48. package/src/node/node-file-service.ts +91 -0
  49. package/src/node/node-sys-abstraction.ts +121 -0
  50. package/src/option.ts +60 -0
  51. package/src/resolve-once.test.ts +321 -0
  52. package/src/resolve-once.ts +179 -0
  53. package/src/result.test.ts +102 -0
  54. package/src/result.ts +165 -0
  55. package/src/runtime.ts +36 -0
  56. package/src/sys-abstraction.ts +53 -0
  57. package/src/sys-env.test.ts +53 -0
  58. package/src/sys-env.ts +216 -0
  59. package/src/test/log-write-stream.ts +95 -0
  60. package/src/test/mock-logger.ts +40 -0
  61. package/src/time.ts +20 -0
  62. package/src/tracer.test.ts +314 -0
  63. package/src/tracer.ts +222 -0
  64. package/src/txt-en-decoder.ts +21 -0
  65. package/src/uri.test.ts +155 -0
  66. package/src/uri.ts +421 -0
  67. package/src/utils/console-write-stream.ts +72 -0
  68. package/src/utils/fanout-write-stream.ts +32 -0
  69. package/src/utils/index.ts +6 -0
  70. package/src/utils/rebuffer.ts +75 -0
  71. package/src/utils/stream-map.ts +67 -0
  72. package/src/utils/stream2string.ts +47 -0
  73. package/src/utils/string2stream.ts +14 -0
  74. package/src/version.ts +3 -0
  75. package/src/web/index.ts +1 -0
  76. package/src/web/web-sys-abstraction.ts +80 -0
  77. package/ts/LICENSE +201 -0
  78. package/ts/README.md +39 -0
  79. package/ts/base-sys-abstraction.d.ts +84 -0
  80. package/ts/base-sys-abstraction.d.ts.map +1 -0
  81. package/ts/base-sys-abstraction.js +178 -0
  82. package/ts/base-sys-abstraction.js.map +1 -0
  83. package/ts/base-sys-abstraction.test.d.ts +2 -0
  84. package/ts/base-sys-abstraction.test.d.ts.map +1 -0
  85. package/ts/base-sys-abstraction.test.js +82 -0
  86. package/ts/base-sys-abstraction.test.js.map +1 -0
  87. package/ts/bin2text.d.ts +3 -0
  88. package/ts/bin2text.d.ts.map +1 -0
  89. package/ts/bin2text.js +43 -0
  90. package/ts/bin2text.js.map +1 -0
  91. package/ts/bin2text.test.d.ts +2 -0
  92. package/ts/bin2text.test.d.ts.map +1 -0
  93. package/ts/bin2text.test.js +51 -0
  94. package/ts/bin2text.test.js.map +1 -0
  95. package/ts/crypto.d.ts +76 -0
  96. package/ts/crypto.d.ts.map +1 -0
  97. package/ts/crypto.js +22 -0
  98. package/ts/crypto.js.map +1 -0
  99. package/ts/crypto.test.d.ts +2 -0
  100. package/ts/crypto.test.d.ts.map +1 -0
  101. package/ts/crypto.test.js +14 -0
  102. package/ts/crypto.test.js.map +1 -0
  103. package/ts/file-service.d.ts +17 -0
  104. package/ts/file-service.d.ts.map +1 -0
  105. package/ts/file-service.js +2 -0
  106. package/ts/file-service.js.map +1 -0
  107. package/ts/future.d.ts +8 -0
  108. package/ts/future.d.ts.map +1 -0
  109. package/ts/future.js +38 -0
  110. package/ts/future.js.map +1 -0
  111. package/ts/future.test.d.ts +2 -0
  112. package/ts/future.test.d.ts.map +1 -0
  113. package/ts/future.test.js +28 -0
  114. package/ts/future.test.js.map +1 -0
  115. package/ts/index.d.ts +23 -0
  116. package/ts/index.d.ts.map +1 -0
  117. package/ts/index.js +23 -0
  118. package/ts/index.js.map +1 -0
  119. package/ts/log-level-impl.d.ts +14 -0
  120. package/ts/log-level-impl.d.ts.map +1 -0
  121. package/ts/log-level-impl.js +72 -0
  122. package/ts/log-level-impl.js.map +1 -0
  123. package/ts/log-writer-impl.d.ts +10 -0
  124. package/ts/log-writer-impl.d.ts.map +1 -0
  125. package/ts/log-writer-impl.js +45 -0
  126. package/ts/log-writer-impl.js.map +1 -0
  127. package/ts/logger-impl.d.ts +71 -0
  128. package/ts/logger-impl.d.ts.map +1 -0
  129. package/ts/logger-impl.js +412 -0
  130. package/ts/logger-impl.js.map +1 -0
  131. package/ts/logger.d.ts +84 -0
  132. package/ts/logger.d.ts.map +1 -0
  133. package/ts/logger.js +114 -0
  134. package/ts/logger.js.map +1 -0
  135. package/ts/logger.test.d.ts +2 -0
  136. package/ts/logger.test.d.ts.map +1 -0
  137. package/ts/logger.test.js +1023 -0
  138. package/ts/logger.test.js.map +1 -0
  139. package/ts/node/deno-file-service.d.ts +17 -0
  140. package/ts/node/deno-file-service.d.ts.map +1 -0
  141. package/ts/node/deno-file-service.js +65 -0
  142. package/ts/node/deno-file-service.js.map +1 -0
  143. package/ts/node/deno-sys-abstraction.d.ts +22 -0
  144. package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
  145. package/ts/node/deno-sys-abstraction.js +101 -0
  146. package/ts/node/deno-sys-abstraction.js.map +1 -0
  147. package/ts/node/index.d.ts +5 -0
  148. package/ts/node/index.d.ts.map +1 -0
  149. package/ts/node/index.js +5 -0
  150. package/ts/node/index.js.map +1 -0
  151. package/ts/node/mock-file-service.d.ts +11 -0
  152. package/ts/node/mock-file-service.d.ts.map +1 -0
  153. package/ts/node/mock-file-service.js +34 -0
  154. package/ts/node/mock-file-service.js.map +1 -0
  155. package/ts/node/mock-file-service.test.d.ts +2 -0
  156. package/ts/node/mock-file-service.test.d.ts.map +1 -0
  157. package/ts/node/mock-file-service.test.js +31 -0
  158. package/ts/node/mock-file-service.test.js.map +1 -0
  159. package/ts/node/node-file-service.d.ts +16 -0
  160. package/ts/node/node-file-service.d.ts.map +1 -0
  161. package/ts/node/node-file-service.js +71 -0
  162. package/ts/node/node-file-service.js.map +1 -0
  163. package/ts/node/node-sys-abstraction.d.ts +22 -0
  164. package/ts/node/node-sys-abstraction.d.ts.map +1 -0
  165. package/ts/node/node-sys-abstraction.js +99 -0
  166. package/ts/node/node-sys-abstraction.js.map +1 -0
  167. package/ts/node/node-sys-abstraction.test.d.ts +2 -0
  168. package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
  169. package/ts/node/node-sys-abstraction.test.js +87 -0
  170. package/ts/node/node-sys-abstraction.test.js.map +1 -0
  171. package/ts/option.d.ts +25 -0
  172. package/ts/option.d.ts.map +1 -0
  173. package/ts/option.js +47 -0
  174. package/ts/option.js.map +1 -0
  175. package/ts/resolve-once.d.ts +46 -0
  176. package/ts/resolve-once.d.ts.map +1 -0
  177. package/ts/resolve-once.js +152 -0
  178. package/ts/resolve-once.js.map +1 -0
  179. package/ts/resolve-once.test.d.ts +2 -0
  180. package/ts/resolve-once.test.d.ts.map +1 -0
  181. package/ts/resolve-once.test.js +283 -0
  182. package/ts/resolve-once.test.js.map +1 -0
  183. package/ts/result.d.ts +34 -0
  184. package/ts/result.d.ts.map +1 -0
  185. package/ts/result.js +85 -0
  186. package/ts/result.js.map +1 -0
  187. package/ts/result.test.d.ts +2 -0
  188. package/ts/result.test.d.ts.map +1 -0
  189. package/ts/result.test.js +79 -0
  190. package/ts/result.test.js.map +1 -0
  191. package/ts/runtime.d.ts +8 -0
  192. package/ts/runtime.d.ts.map +1 -0
  193. package/ts/runtime.js +26 -0
  194. package/ts/runtime.js.map +1 -0
  195. package/ts/sys-abstraction.d.ts +36 -0
  196. package/ts/sys-abstraction.d.ts.map +1 -0
  197. package/ts/sys-abstraction.js +31 -0
  198. package/ts/sys-abstraction.js.map +1 -0
  199. package/ts/sys-env.d.ts +48 -0
  200. package/ts/sys-env.d.ts.map +1 -0
  201. package/ts/sys-env.js +176 -0
  202. package/ts/sys-env.js.map +1 -0
  203. package/ts/sys-env.test.d.ts +2 -0
  204. package/ts/sys-env.test.d.ts.map +1 -0
  205. package/ts/sys-env.test.js +51 -0
  206. package/ts/sys-env.test.js.map +1 -0
  207. package/ts/test/log-write-stream.d.ts +27 -0
  208. package/ts/test/log-write-stream.d.ts.map +1 -0
  209. package/ts/test/log-write-stream.js +74 -0
  210. package/ts/test/log-write-stream.js.map +1 -0
  211. package/ts/test/mock-logger.d.ts +14 -0
  212. package/ts/test/mock-logger.d.ts.map +1 -0
  213. package/ts/test/mock-logger.js +29 -0
  214. package/ts/test/mock-logger.js.map +1 -0
  215. package/ts/test/mock-logger.test.d.ts +2 -0
  216. package/ts/test/mock-logger.test.d.ts.map +1 -0
  217. package/ts/test/mock-logger.test.js +63 -0
  218. package/ts/test/mock-logger.test.js.map +1 -0
  219. package/ts/test/test-exit-handler.d.ts +2 -0
  220. package/ts/test/test-exit-handler.d.ts.map +1 -0
  221. package/ts/test/test-exit-handler.js +57 -0
  222. package/ts/test/test-exit-handler.js.map +1 -0
  223. package/ts/time.d.ts +13 -0
  224. package/ts/time.d.ts.map +1 -0
  225. package/ts/time.js +14 -0
  226. package/ts/time.js.map +1 -0
  227. package/ts/tracer.d.ts +59 -0
  228. package/ts/tracer.d.ts.map +1 -0
  229. package/ts/tracer.js +148 -0
  230. package/ts/tracer.js.map +1 -0
  231. package/ts/tracer.test.d.ts +2 -0
  232. package/ts/tracer.test.d.ts.map +1 -0
  233. package/ts/tracer.test.js +311 -0
  234. package/ts/tracer.test.js.map +1 -0
  235. package/ts/txt-en-decoder.d.ts +10 -0
  236. package/ts/txt-en-decoder.d.ts.map +1 -0
  237. package/ts/txt-en-decoder.js +15 -0
  238. package/ts/txt-en-decoder.js.map +1 -0
  239. package/ts/uri.d.ts +67 -0
  240. package/ts/uri.d.ts.map +1 -0
  241. package/ts/uri.js +283 -0
  242. package/ts/uri.js.map +1 -0
  243. package/ts/uri.test.d.ts +2 -0
  244. package/ts/uri.test.d.ts.map +1 -0
  245. package/ts/uri.test.js +119 -0
  246. package/ts/uri.test.js.map +1 -0
  247. package/ts/utils/console-write-stream.d.ts +21 -0
  248. package/ts/utils/console-write-stream.d.ts.map +1 -0
  249. package/ts/utils/console-write-stream.js +62 -0
  250. package/ts/utils/console-write-stream.js.map +1 -0
  251. package/ts/utils/fanout-write-stream.d.ts +12 -0
  252. package/ts/utils/fanout-write-stream.d.ts.map +1 -0
  253. package/ts/utils/fanout-write-stream.js +24 -0
  254. package/ts/utils/fanout-write-stream.js.map +1 -0
  255. package/ts/utils/index.d.ts +7 -0
  256. package/ts/utils/index.d.ts.map +1 -0
  257. package/ts/utils/index.js +7 -0
  258. package/ts/utils/index.js.map +1 -0
  259. package/ts/utils/rebuffer.d.ts +3 -0
  260. package/ts/utils/rebuffer.d.ts.map +1 -0
  261. package/ts/utils/rebuffer.js +60 -0
  262. package/ts/utils/rebuffer.js.map +1 -0
  263. package/ts/utils/rebuffer.test.d.ts +2 -0
  264. package/ts/utils/rebuffer.test.d.ts.map +1 -0
  265. package/ts/utils/rebuffer.test.js +77 -0
  266. package/ts/utils/rebuffer.test.js.map +1 -0
  267. package/ts/utils/stream-map.d.ts +9 -0
  268. package/ts/utils/stream-map.d.ts.map +1 -0
  269. package/ts/utils/stream-map.js +62 -0
  270. package/ts/utils/stream-map.js.map +1 -0
  271. package/ts/utils/stream-map.test.d.ts +2 -0
  272. package/ts/utils/stream-map.test.d.ts.map +1 -0
  273. package/ts/utils/stream-map.test.js +87 -0
  274. package/ts/utils/stream-map.test.js.map +1 -0
  275. package/ts/utils/stream-test-helper.d.ts +17 -0
  276. package/ts/utils/stream-test-helper.d.ts.map +1 -0
  277. package/ts/utils/stream-test-helper.js +37 -0
  278. package/ts/utils/stream-test-helper.js.map +1 -0
  279. package/ts/utils/stream2string.d.ts +3 -0
  280. package/ts/utils/stream2string.d.ts.map +1 -0
  281. package/ts/utils/stream2string.js +48 -0
  282. package/ts/utils/stream2string.js.map +1 -0
  283. package/ts/utils/stream2string.test.d.ts +2 -0
  284. package/ts/utils/stream2string.test.d.ts.map +1 -0
  285. package/ts/utils/stream2string.test.js +29 -0
  286. package/ts/utils/stream2string.test.js.map +1 -0
  287. package/ts/utils/string2stream.d.ts +4 -0
  288. package/ts/utils/string2stream.d.ts.map +1 -0
  289. package/ts/utils/string2stream.js +13 -0
  290. package/ts/utils/string2stream.js.map +1 -0
  291. package/ts/utils/string2stream.test.d.ts +2 -0
  292. package/ts/utils/string2stream.test.d.ts.map +1 -0
  293. package/ts/utils/string2stream.test.js +6 -0
  294. package/ts/utils/string2stream.test.js.map +1 -0
  295. package/ts/version.d.ts +2 -0
  296. package/ts/version.d.ts.map +1 -0
  297. package/ts/version.js +4 -0
  298. package/ts/version.js.map +1 -0
  299. package/ts/web/index.d.ts +2 -0
  300. package/ts/web/index.d.ts.map +1 -0
  301. package/ts/web/index.js +2 -0
  302. package/ts/web/index.js.map +1 -0
  303. package/ts/web/web-sys-abstraction.d.ts +4 -0
  304. package/ts/web/web-sys-abstraction.d.ts.map +1 -0
  305. package/ts/web/web-sys-abstraction.js +64 -0
  306. package/ts/web/web-sys-abstraction.js.map +1 -0
  307. package/txt-en-decoder-CZYJUju2.d.cts +11 -0
  308. package/txt-en-decoder-CZYJUju2.d.ts +11 -0
  309. package/utils/index.cjs +341 -0
  310. package/utils/index.cjs.map +1 -0
  311. package/utils/index.d.cts +2 -0
  312. package/utils/index.d.ts +2 -0
  313. package/utils/index.js +32 -0
  314. package/utils/index.js.map +1 -0
  315. package/web/index.cjs +593 -0
  316. package/web/index.cjs.map +1 -0
  317. package/web/index.d.cts +6 -0
  318. package/web/index.d.ts +6 -0
  319. package/web/index.js +9 -0
  320. package/web/index.js.map +1 -0
package/index.cjs ADDED
@@ -0,0 +1,2593 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
13
+ var __typeError = (msg) => {
14
+ throw TypeError(msg);
15
+ };
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, { get: all[name], enumerable: true });
32
+ };
33
+ var __copyProps = (to, from2, except, desc) => {
34
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
35
+ for (let key of __getOwnPropNames(from2))
36
+ if (!__hasOwnProp.call(to, key) && key !== except)
37
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
38
+ }
39
+ return to;
40
+ };
41
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
42
+ // If the importer is in node compatibility mode or this is not an ESM
43
+ // file that has been converted to a CommonJS file using a Babel-
44
+ // compatible transform (i.e. "__esModule" has not been set), then set
45
+ // "default" to the CommonJS "module.exports" for node compatibility.
46
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
47
+ mod
48
+ ));
49
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
51
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
52
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
53
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
54
+ var __await = function(promise, isYieldStar) {
55
+ this[0] = promise;
56
+ this[1] = isYieldStar;
57
+ };
58
+ var __yieldStar = (value) => {
59
+ var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
60
+ if (obj == null) {
61
+ obj = value[__knownSymbol("iterator")]();
62
+ method = (k) => it[k] = (x) => obj[k](x);
63
+ } else {
64
+ obj = obj.call(value);
65
+ method = (k) => it[k] = (v) => {
66
+ if (isAwait) {
67
+ isAwait = false;
68
+ if (k === "throw") throw v;
69
+ return v;
70
+ }
71
+ isAwait = true;
72
+ return {
73
+ done: false,
74
+ value: new __await(new Promise((resolve) => {
75
+ var x = obj[k](v);
76
+ if (!(x instanceof Object)) __typeError("Object expected");
77
+ resolve(x);
78
+ }), 1)
79
+ };
80
+ };
81
+ }
82
+ return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
83
+ throw x;
84
+ }, "return" in obj && method("return"), it;
85
+ };
86
+
87
+ // src/index.ts
88
+ var src_exports = {};
89
+ __export(src_exports, {
90
+ BaseSysAbstraction: () => BaseSysAbstraction,
91
+ BrowserEnvActions: () => BrowserEnvActions,
92
+ BuildURI: () => BuildURI,
93
+ ConstTime: () => ConstTime,
94
+ EnvImpl: () => EnvImpl,
95
+ Future: () => Future,
96
+ IDMode: () => IDMode,
97
+ IdService: () => IdService,
98
+ IsLogger: () => IsLogger,
99
+ JSONFormatter: () => JSONFormatter,
100
+ Keyed: () => Keyed,
101
+ KeyedResolvOnce: () => KeyedResolvOnce,
102
+ KeyedResolvSeq: () => KeyedResolvSeq,
103
+ Level: () => Level,
104
+ LevelHandlerImpl: () => LevelHandlerImpl,
105
+ LevelHandlerSingleton: () => LevelHandlerSingleton,
106
+ LogCollector: () => LogCollector,
107
+ LogValue: () => LogValue,
108
+ LogWriteStream: () => LogWriteStream,
109
+ LoggerImpl: () => LoggerImpl,
110
+ Metric: () => Metric,
111
+ Metrics: () => Metrics,
112
+ MockLogger: () => MockLogger,
113
+ MutableURL: () => MutableURL,
114
+ None: () => None,
115
+ Option: () => Option,
116
+ RandomMode: () => RandomMode,
117
+ RandomService: () => RandomService,
118
+ ResolveOnce: () => ResolveOnce,
119
+ ResolveSeq: () => ResolveSeq,
120
+ Result: () => Result,
121
+ ResultError: () => ResultError,
122
+ ResultOK: () => ResultOK,
123
+ Some: () => Some,
124
+ StepTime: () => StepTime,
125
+ String2TimeMode: () => String2TimeMode,
126
+ SysTime: () => SysTime,
127
+ Time: () => Time,
128
+ TimeFactory: () => TimeFactory,
129
+ TimeMode: () => TimeMode,
130
+ TimeUnits: () => TimeUnits,
131
+ TraceNode: () => TraceNode,
132
+ URI: () => URI,
133
+ Utf8EnDecoder: () => Utf8EnDecoder,
134
+ Utf8EnDecoderSingleton: () => Utf8EnDecoderSingleton,
135
+ VERSION: () => VERSION,
136
+ WrapperSysAbstraction: () => WrapperSysAbstraction,
137
+ YAMLFormatter: () => YAMLFormatter,
138
+ asyncLogValue: () => asyncLogValue,
139
+ bin2string: () => bin2string,
140
+ bin2text: () => bin2text,
141
+ envFactory: () => envFactory,
142
+ exception2Result: () => exception2Result,
143
+ isURL: () => isURL,
144
+ logValue: () => logValue,
145
+ protocols: () => protocols,
146
+ removeSelfRef: () => removeSelfRef,
147
+ runtimeFn: () => runtimeFn,
148
+ toCryptoRuntime: () => toCryptoRuntime,
149
+ utils: () => utils_exports
150
+ });
151
+ module.exports = __toCommonJS(src_exports);
152
+
153
+ // src/logger-impl.ts
154
+ var import_yaml = __toESM(require("yaml"), 1);
155
+
156
+ // src/bin2text.ts
157
+ function bin2text(hex, lineFn, size = 0) {
158
+ const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);
159
+ let cutted = " ";
160
+ if (size == 0) {
161
+ size = arr.length;
162
+ }
163
+ size = Math.min(size, arr.length);
164
+ const cols = 16;
165
+ for (let line = 0; line < size; line += cols) {
166
+ if (line + cols <= size || arr.length == size) {
167
+ } else {
168
+ line = arr.length - arr.length % cols;
169
+ size = arr.length;
170
+ cutted = ">>";
171
+ }
172
+ const l = [line.toString(16).padStart(4, "0"), cutted];
173
+ for (let col = 0; col < cols; col++) {
174
+ if (line + col < size) {
175
+ l.push(arr[line + col].toString(16).padStart(2, "0"));
176
+ } else {
177
+ l.push(" ");
178
+ }
179
+ l.push(" ");
180
+ }
181
+ for (let col = 0; col < cols; col++) {
182
+ if (line + col < size) {
183
+ const ch = arr[line + col];
184
+ l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : ".");
185
+ }
186
+ }
187
+ lineFn(l.join(""));
188
+ }
189
+ }
190
+ function bin2string(hex, size = 0) {
191
+ const collector = [];
192
+ bin2text(
193
+ hex,
194
+ (line) => {
195
+ collector.push(line);
196
+ },
197
+ size
198
+ );
199
+ return collector.join("\n");
200
+ }
201
+
202
+ // src/logger.ts
203
+ var Level = /* @__PURE__ */ ((Level2) => {
204
+ Level2["WARN"] = "warn";
205
+ Level2["DEBUG"] = "debug";
206
+ Level2["INFO"] = "info";
207
+ Level2["ERROR"] = "error";
208
+ return Level2;
209
+ })(Level || {});
210
+ var LogValue = class {
211
+ constructor(fn) {
212
+ this.fn = fn;
213
+ }
214
+ value() {
215
+ return this.fn();
216
+ }
217
+ toJSON() {
218
+ return this.value();
219
+ }
220
+ };
221
+ function removeSelfRef(lineEnd) {
222
+ const cache = /* @__PURE__ */ new Set();
223
+ return function(key, value) {
224
+ if (typeof value === "object" && value !== null) {
225
+ if (cache.has(value)) return "...";
226
+ cache.add(value);
227
+ }
228
+ return lineEnd ? value + lineEnd : value;
229
+ };
230
+ }
231
+ function asyncLogValue(val) {
232
+ throw new Error("Not implemented");
233
+ }
234
+ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
235
+ switch (typeof val) {
236
+ case "function":
237
+ return new LogValue(val);
238
+ case "string": {
239
+ try {
240
+ const ret = JSON.parse(val);
241
+ if (typeof ret === "object" && ret !== null) {
242
+ return logValue(ret, state);
243
+ }
244
+ } catch (e) {
245
+ if (val.match(/[\n\r]/)) {
246
+ const lines = val.trimEnd().split(/[\n\r]/);
247
+ return new LogValue(() => lines);
248
+ }
249
+ }
250
+ return new LogValue(() => val.toString());
251
+ }
252
+ case "number":
253
+ return new LogValue(() => val);
254
+ case "boolean":
255
+ return new LogValue(() => val);
256
+ case "object": {
257
+ if (ArrayBuffer.isView(val)) {
258
+ return logValue(bin2string(val, 512));
259
+ }
260
+ if (Array.isArray(val)) {
261
+ return new LogValue(() => val.map((v) => logValue(v).value()));
262
+ }
263
+ if (val === null) {
264
+ return new LogValue(() => "null");
265
+ }
266
+ if (state.has(val)) {
267
+ return new LogValue(() => "...");
268
+ }
269
+ state.add(val);
270
+ const res = {};
271
+ const typedVal = val;
272
+ for (const key in typedVal) {
273
+ const element = typedVal[key];
274
+ if (element instanceof LogValue) {
275
+ res[key] = element;
276
+ } else {
277
+ res[key] = logValue(element, state);
278
+ }
279
+ }
280
+ return new LogValue(() => res);
281
+ }
282
+ default:
283
+ if (!val) {
284
+ return new LogValue(() => "--Falsy--");
285
+ }
286
+ throw new Error(`Invalid type:${typeof val}`);
287
+ }
288
+ }
289
+ function IsLogger(obj) {
290
+ return typeof obj === "object" && [
291
+ "Module",
292
+ "EnableLevel",
293
+ "DisableLevel",
294
+ "SetDebug",
295
+ "Str",
296
+ "Error",
297
+ "Warn",
298
+ "Debug",
299
+ "Log",
300
+ "WithLevel",
301
+ "Err",
302
+ "Info",
303
+ "Timestamp",
304
+ "Any",
305
+ "Dur",
306
+ "Uint64"
307
+ ].map((fn) => typeof obj[fn] === "function").reduce((a, b) => a && b, true);
308
+ }
309
+
310
+ // src/sys-abstraction.ts
311
+ var TimeMode = /* @__PURE__ */ ((TimeMode2) => {
312
+ TimeMode2["REAL"] = "real";
313
+ TimeMode2["CONST"] = "const";
314
+ TimeMode2["STEP"] = "step";
315
+ return TimeMode2;
316
+ })(TimeMode || {});
317
+ var RandomMode = /* @__PURE__ */ ((RandomMode2) => {
318
+ RandomMode2["CONST"] = "const";
319
+ RandomMode2["STEP"] = "step";
320
+ RandomMode2["RANDOM"] = "random";
321
+ return RandomMode2;
322
+ })(RandomMode || {});
323
+ var IDMode = /* @__PURE__ */ ((IDMode2) => {
324
+ IDMode2["UUID"] = "uuid";
325
+ IDMode2["CONST"] = "const";
326
+ IDMode2["STEP"] = "step";
327
+ return IDMode2;
328
+ })(IDMode || {});
329
+ function String2TimeMode(s) {
330
+ switch (s == null ? void 0 : s.toLowerCase()) {
331
+ case "real":
332
+ return "real" /* REAL */;
333
+ case "const":
334
+ return "const" /* CONST */;
335
+ case "step":
336
+ return "step" /* STEP */;
337
+ default:
338
+ return "real" /* REAL */;
339
+ }
340
+ }
341
+
342
+ // src/time.ts
343
+ var Time = class {
344
+ TimeSince(start) {
345
+ const now = this.Now();
346
+ return now.getTime() - start.getTime();
347
+ }
348
+ };
349
+ var TimeUnits = /* @__PURE__ */ ((TimeUnits2) => {
350
+ TimeUnits2[TimeUnits2["Microsecond"] = 1] = "Microsecond";
351
+ TimeUnits2[TimeUnits2["Second"] = 1e3] = "Second";
352
+ TimeUnits2[TimeUnits2["Minute"] = 6e4] = "Minute";
353
+ TimeUnits2[TimeUnits2["Hour"] = 36e5] = "Hour";
354
+ return TimeUnits2;
355
+ })(TimeUnits || {});
356
+
357
+ // src/base-sys-abstraction.ts
358
+ var SysTime = class extends Time {
359
+ Now() {
360
+ return /* @__PURE__ */ new Date();
361
+ }
362
+ Sleep(duration) {
363
+ return new Promise((resolve) => {
364
+ setTimeout(() => {
365
+ resolve();
366
+ }, duration);
367
+ });
368
+ }
369
+ };
370
+ var ConstTime = class extends Time {
371
+ Now() {
372
+ return new Date(2021, 1, 1, 0, 0, 0, 0);
373
+ }
374
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
375
+ Sleep(duration) {
376
+ return Promise.resolve();
377
+ }
378
+ };
379
+ var StepTime = class extends Time {
380
+ constructor() {
381
+ super();
382
+ this._step = new ConstTime().Now();
383
+ this._start = this._step;
384
+ }
385
+ Now(steps = 1) {
386
+ for (let i = 0; steps > 0 && i < steps; i++) {
387
+ this._step = new Date(this._step.getTime() + 1e3);
388
+ }
389
+ if (steps < 1) {
390
+ this._step = new Date(this._start.getTime() + steps * -1e3);
391
+ }
392
+ return this._step;
393
+ }
394
+ Sleep(duration) {
395
+ this._step = new Date(this._step.getTime() + duration);
396
+ return Promise.resolve();
397
+ }
398
+ };
399
+ function TimeFactory(timeMode) {
400
+ switch (timeMode) {
401
+ case "real" /* REAL */:
402
+ return new SysTime();
403
+ case "const" /* CONST */:
404
+ return new ConstTime();
405
+ case "step" /* STEP */:
406
+ return new StepTime();
407
+ }
408
+ return new SysTime();
409
+ }
410
+ var RandomService = class {
411
+ constructor(mode) {
412
+ this._step = 0;
413
+ this._mode = mode;
414
+ }
415
+ Random0ToValue(value) {
416
+ switch (this._mode) {
417
+ case "const" /* CONST */:
418
+ return 0.5 * value;
419
+ case "step" /* STEP */:
420
+ this._step += 1e-4;
421
+ return this._step * value;
422
+ case "random" /* RANDOM */:
423
+ return Math.random() * value;
424
+ default:
425
+ throw new Error("Unknown RandomMode");
426
+ }
427
+ }
428
+ };
429
+ var IdService = class {
430
+ constructor(mode) {
431
+ this._step = 0;
432
+ if (!mode) {
433
+ mode = "uuid" /* UUID */;
434
+ }
435
+ this._mode = mode;
436
+ }
437
+ NextId() {
438
+ switch (this._mode) {
439
+ case "uuid" /* UUID */:
440
+ return crypto.randomUUID();
441
+ case "const" /* CONST */:
442
+ return "VeryUniqueID";
443
+ case "step" /* STEP */:
444
+ return `STEPId-${this._step++}`;
445
+ default:
446
+ throw new Error("Unknown IDMode");
447
+ }
448
+ }
449
+ };
450
+ var BaseSysAbstraction = class {
451
+ constructor(params) {
452
+ this._time = new SysTime();
453
+ this._idService = new IdService();
454
+ this._randomService = new RandomService("random" /* RANDOM */);
455
+ this._fileSystem = params.FileSystem;
456
+ this._systemService = params.SystemService;
457
+ this._txtEnDe = params.TxtEnDecoder;
458
+ const decoder2 = this._txtEnDe;
459
+ this._stdout = new WritableStream({
460
+ write(chunk) {
461
+ return new Promise((resolve) => {
462
+ const decoded = decoder2.decode(chunk);
463
+ console.log(decoded.trimEnd());
464
+ resolve();
465
+ });
466
+ }
467
+ });
468
+ this._stderr = new WritableStream({
469
+ write(chunk) {
470
+ return new Promise((resolve) => {
471
+ const decoded = decoder2.decode(chunk);
472
+ console.error(decoded.trimEnd());
473
+ resolve();
474
+ });
475
+ }
476
+ });
477
+ }
478
+ };
479
+ var WrapperSysAbstraction = class {
480
+ constructor(base, params) {
481
+ this._time = base._time;
482
+ this._stdout = base._stdout;
483
+ this._stderr = base._stderr;
484
+ this._idService = base._idService;
485
+ this._randomService = base._randomService;
486
+ this._fileSystem = base._fileSystem;
487
+ this._systemService = base._systemService;
488
+ if (params) {
489
+ if (params.TimeMode) {
490
+ this._time = TimeFactory(params.TimeMode);
491
+ }
492
+ if (params.Stdout) {
493
+ this._stdout = params.Stdout;
494
+ }
495
+ if (params.Stderr) {
496
+ this._stderr = params.Stderr;
497
+ }
498
+ if (params.IdMode) {
499
+ this._idService = new IdService(params.IdMode);
500
+ }
501
+ if (params.RandomMode) {
502
+ this._randomService = new RandomService(params.RandomMode);
503
+ }
504
+ if (params.FileSystem) {
505
+ this._fileSystem = params.FileSystem;
506
+ }
507
+ if (params.SystemService) {
508
+ this._systemService = params.SystemService;
509
+ }
510
+ }
511
+ }
512
+ Time() {
513
+ return this._time;
514
+ }
515
+ NextId() {
516
+ return this._idService.NextId();
517
+ }
518
+ Random0ToValue(value) {
519
+ return this._randomService.Random0ToValue(value);
520
+ }
521
+ Stdout() {
522
+ return this._stdout;
523
+ }
524
+ Stderr() {
525
+ return this._stderr;
526
+ }
527
+ System() {
528
+ return this._systemService;
529
+ }
530
+ FileSystem() {
531
+ return this._fileSystem;
532
+ }
533
+ };
534
+
535
+ // src/future.ts
536
+ var _promise, _resolveFn, _rejectFn;
537
+ var Future = class {
538
+ constructor() {
539
+ __privateAdd(this, _promise);
540
+ __privateAdd(this, _resolveFn, () => {
541
+ throw new Error("This Promise is not working as expected.");
542
+ });
543
+ __privateAdd(this, _rejectFn, () => {
544
+ throw new Error("This Promise is not working as expected.");
545
+ });
546
+ __privateSet(this, _promise, new Promise((resolve, reject) => {
547
+ __privateSet(this, _resolveFn, resolve);
548
+ __privateSet(this, _rejectFn, reject);
549
+ }));
550
+ }
551
+ async asPromise() {
552
+ return __privateGet(this, _promise);
553
+ }
554
+ resolve(value) {
555
+ __privateGet(this, _resolveFn).call(this, value);
556
+ }
557
+ reject(reason) {
558
+ __privateGet(this, _rejectFn).call(this, reason);
559
+ }
560
+ };
561
+ _promise = new WeakMap();
562
+ _resolveFn = new WeakMap();
563
+ _rejectFn = new WeakMap();
564
+
565
+ // src/resolve-once.ts
566
+ var ResolveSeq = class {
567
+ constructor(ctx) {
568
+ this._seqFutures = [];
569
+ this.ctx = ctx;
570
+ }
571
+ reset() {
572
+ }
573
+ async _step(item) {
574
+ if (!item) {
575
+ return;
576
+ }
577
+ item.fn(this.ctx).then((value) => item.future.resolve(value)).catch((e) => item.future.reject(e)).finally(() => {
578
+ this._seqFutures.shift();
579
+ this._step(this._seqFutures[0]);
580
+ });
581
+ }
582
+ async add(fn, id) {
583
+ const future = new Future();
584
+ this._seqFutures.push({ future, fn, id });
585
+ if (this._seqFutures.length === 1) {
586
+ this._step(this._seqFutures[0]);
587
+ }
588
+ return future.asPromise();
589
+ }
590
+ };
591
+ var ResolveOnce = class {
592
+ constructor(ctx) {
593
+ this._onceDone = false;
594
+ this._onceFutures = [];
595
+ this._onceOk = false;
596
+ this._isPromise = false;
597
+ this.ctx = ctx;
598
+ }
599
+ get ready() {
600
+ return this._onceDone;
601
+ }
602
+ reset() {
603
+ this._onceDone = false;
604
+ this._onceOk = false;
605
+ this._onceValue = void 0;
606
+ this._onceError = void 0;
607
+ this._onceFutures.length = 0;
608
+ }
609
+ // T extends Option<infer U> ? U : T
610
+ once(fn) {
611
+ if (this._onceDone) {
612
+ if (this._onceError) {
613
+ if (this._isPromise) {
614
+ return Promise.reject(this._onceError);
615
+ } else {
616
+ throw this._onceError;
617
+ }
618
+ }
619
+ if (this._onceOk) {
620
+ if (this._isPromise) {
621
+ return Promise.resolve(this._onceValue);
622
+ } else {
623
+ return this._onceValue;
624
+ }
625
+ }
626
+ throw new Error("ResolveOnce.once impossible");
627
+ }
628
+ const future = new Future();
629
+ this._onceFutures.push(future);
630
+ if (this._onceFutures.length === 1) {
631
+ const okFn = (value) => {
632
+ this._onceValue = value;
633
+ this._onceOk = true;
634
+ this._onceDone = true;
635
+ if (this._isPromise) {
636
+ this._onceFutures.forEach((f) => f.resolve(this._onceValue));
637
+ }
638
+ this._onceFutures.length = 0;
639
+ };
640
+ const catchFn = (e) => {
641
+ this._onceError = e;
642
+ this._onceOk = false;
643
+ this._onceValue = void 0;
644
+ this._onceDone = true;
645
+ if (this._isPromise) {
646
+ this._onceFutures.forEach((f) => f.reject(this._onceError));
647
+ }
648
+ this._onceFutures.length = 0;
649
+ };
650
+ try {
651
+ const ret = fn(this.ctx);
652
+ if (typeof ret.then === "function") {
653
+ this._isPromise = true;
654
+ ret.then(okFn).catch(catchFn);
655
+ } else {
656
+ okFn(ret);
657
+ }
658
+ } catch (e) {
659
+ catchFn(e);
660
+ }
661
+ }
662
+ if (this._isPromise) {
663
+ return future.asPromise();
664
+ } else {
665
+ return this.once(fn);
666
+ }
667
+ }
668
+ };
669
+ var Keyed = class {
670
+ constructor(factory) {
671
+ this._map = /* @__PURE__ */ new Map();
672
+ this.factory = factory;
673
+ }
674
+ async asyncGet(key) {
675
+ return this.get(await key());
676
+ }
677
+ get(key) {
678
+ if (typeof key === "function") {
679
+ key = key();
680
+ }
681
+ let keyed = this._map.get(key);
682
+ if (!keyed) {
683
+ keyed = this.factory(key);
684
+ this._map.set(key, keyed);
685
+ }
686
+ return keyed;
687
+ }
688
+ unget(key) {
689
+ const keyed = this._map.get(key);
690
+ keyed == null ? void 0 : keyed.reset();
691
+ this._map.delete(key);
692
+ }
693
+ reset() {
694
+ this._map.forEach((keyed) => keyed.reset());
695
+ this._map.clear();
696
+ }
697
+ };
698
+ var KeyedResolvOnce = class extends Keyed {
699
+ constructor() {
700
+ super((key) => new ResolveOnce(key));
701
+ }
702
+ };
703
+ var KeyedResolvSeq = class extends Keyed {
704
+ constructor() {
705
+ super((key) => new ResolveSeq(key));
706
+ }
707
+ };
708
+
709
+ // src/sys-env.ts
710
+ var _node;
711
+ var NodeEnvActions = class {
712
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
713
+ constructor(opts) {
714
+ __privateAdd(this, _node, globalThis);
715
+ this._env = this.active() ? __privateGet(this, _node).process.env : {};
716
+ }
717
+ register(env) {
718
+ return env;
719
+ }
720
+ active() {
721
+ return typeof __privateGet(this, _node) === "object" && typeof __privateGet(this, _node).process === "object" && typeof __privateGet(this, _node).process.env === "object";
722
+ }
723
+ keys() {
724
+ return Object.keys(this._env);
725
+ }
726
+ get(key) {
727
+ return this._env[key];
728
+ }
729
+ set(key, value) {
730
+ if (value) {
731
+ this._env[key] = value;
732
+ }
733
+ }
734
+ delete(key) {
735
+ delete this._env[key];
736
+ }
737
+ };
738
+ _node = new WeakMap();
739
+ var _deno;
740
+ var DenoEnvActions = class {
741
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
742
+ constructor(opts) {
743
+ __privateAdd(this, _deno, globalThis);
744
+ }
745
+ get _env() {
746
+ return __privateGet(this, _deno).Deno.env;
747
+ }
748
+ register(env) {
749
+ return env;
750
+ }
751
+ active() {
752
+ return typeof __privateGet(this, _deno) === "object" && typeof __privateGet(this, _deno).Deno === "object" && typeof __privateGet(this, _deno).Deno.env === "object";
753
+ }
754
+ keys() {
755
+ return Array.from(this._env.keys());
756
+ }
757
+ get(key) {
758
+ return this._env.get(key);
759
+ }
760
+ set(key, value) {
761
+ if (value) {
762
+ this._env.set(key, value);
763
+ }
764
+ }
765
+ delete(key) {
766
+ this._env.delete(key);
767
+ }
768
+ };
769
+ _deno = new WeakMap();
770
+ var BrowserEnvActions = class {
771
+ constructor(opts) {
772
+ this.env = /* @__PURE__ */ new Map();
773
+ this.opts = opts;
774
+ }
775
+ get(key) {
776
+ return this.env.get(key);
777
+ }
778
+ set(key, value) {
779
+ if (value) {
780
+ this.env.set(key, value);
781
+ }
782
+ }
783
+ delete(key) {
784
+ this.env.delete(key);
785
+ }
786
+ keys() {
787
+ return Array.from(this.env.keys());
788
+ }
789
+ active() {
790
+ return true;
791
+ }
792
+ register(env) {
793
+ const sym = Symbol.for(this.opts.symbol || "CP_ENV");
794
+ const browser = globalThis;
795
+ browser[sym] = env;
796
+ return env;
797
+ }
798
+ };
799
+ var _envFactory = new ResolveOnce();
800
+ function envFactory(opts = {}) {
801
+ return _envFactory.once(() => {
802
+ const found = [new NodeEnvActions(opts), new DenoEnvActions(opts), new BrowserEnvActions(opts)].find((env) => env.active());
803
+ if (!found) {
804
+ throw new Error("SysContainer:envFactory: no env available");
805
+ }
806
+ const ret = new EnvImpl(found, opts);
807
+ found.register(ret);
808
+ return ret;
809
+ });
810
+ }
811
+ var EnvImpl = class {
812
+ constructor(map, opts = {}) {
813
+ this._onSet = [];
814
+ this._map = map;
815
+ this._updatePresets(opts.presetEnv);
816
+ }
817
+ _updatePresets(presetEnv) {
818
+ if (!presetEnv) {
819
+ return;
820
+ }
821
+ for (const [key, value] of presetEnv) {
822
+ this._map.set(key, value);
823
+ }
824
+ }
825
+ _applyOnSet(onSet, key, value) {
826
+ onSet.forEach((item) => {
827
+ let keys = [];
828
+ if (key) {
829
+ keys = [key];
830
+ } else {
831
+ keys = this._map.keys();
832
+ }
833
+ keys.filter((k) => {
834
+ if (item.filter.size === 0) {
835
+ return true;
836
+ }
837
+ if (item.filter.has(k)) {
838
+ return true;
839
+ }
840
+ return false;
841
+ }).forEach((k) => {
842
+ let v;
843
+ if (!key && !value) {
844
+ v = this._map.get(k);
845
+ } else if (key && !value) {
846
+ v = void 0;
847
+ } else {
848
+ v = value;
849
+ }
850
+ item.fn(k, v);
851
+ });
852
+ });
853
+ }
854
+ keys() {
855
+ return this._map.keys();
856
+ }
857
+ // filter is not set all sets passed
858
+ onSet(fn, ...filter) {
859
+ const item = { filter: new Set(filter), fn };
860
+ this._onSet.push(item);
861
+ this._applyOnSet([item]);
862
+ }
863
+ get(key) {
864
+ return this._map.get(key);
865
+ }
866
+ set(key, value) {
867
+ if (!value) {
868
+ return;
869
+ }
870
+ this._map.set(key, value);
871
+ this._applyOnSet(this._onSet, key, value);
872
+ }
873
+ delete(key) {
874
+ this._map.delete(key);
875
+ this._applyOnSet(this._onSet, key);
876
+ }
877
+ };
878
+
879
+ // src/txt-en-decoder.ts
880
+ var encoder = new TextEncoder();
881
+ var decoder = new TextDecoder();
882
+ var Utf8EnDecoder = class {
883
+ encode(str) {
884
+ return encoder.encode(str);
885
+ }
886
+ decode(data) {
887
+ return decoder.decode(data);
888
+ }
889
+ };
890
+ var utf8EnDecoder = new Utf8EnDecoder();
891
+ function Utf8EnDecoderSingleton() {
892
+ return utf8EnDecoder;
893
+ }
894
+
895
+ // src/web/web-sys-abstraction.ts
896
+ var WebFileService = class {
897
+ get baseDir() {
898
+ throw new Error("basedir-Method not implemented.");
899
+ }
900
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
901
+ create(fname) {
902
+ throw new Error("create-Method not implemented.");
903
+ }
904
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
905
+ readFileString(fname) {
906
+ throw new Error("readFileString-Method not implemented.");
907
+ }
908
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
909
+ writeFileString(fname, content) {
910
+ throw new Error("writeFileString-Method not implemented.");
911
+ }
912
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
913
+ abs(fname) {
914
+ throw new Error("abs-Method not implemented.");
915
+ }
916
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
917
+ join(...paths) {
918
+ throw new Error("join-Method not implemented.");
919
+ }
920
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
921
+ relative(from2, to) {
922
+ throw new Error("relative-Method not implemented.");
923
+ }
924
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
925
+ dirname(fname) {
926
+ throw new Error("dirname-Method not implemented.");
927
+ }
928
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
929
+ basename(fname) {
930
+ throw new Error("basename-Method not implemented.");
931
+ }
932
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
933
+ nodeImport(fname) {
934
+ throw new Error("nodeImport-Method not implemented.");
935
+ }
936
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
937
+ isAbsolute(fname) {
938
+ throw new Error("isAbsolute-Method not implemented.");
939
+ }
940
+ };
941
+ var WebSystemService = class {
942
+ Env() {
943
+ return envFactory();
944
+ }
945
+ Args() {
946
+ throw new Error("Args-Method not implemented.");
947
+ }
948
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
949
+ OnExit(hdl) {
950
+ throw new Error("OnExit-Method not implemented.");
951
+ }
952
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
953
+ Exit(code) {
954
+ throw new Error("Exit-Method not implemented.");
955
+ }
956
+ };
957
+ var my = void 0;
958
+ function WebSysAbstraction(param) {
959
+ if (!my) {
960
+ my = new BaseSysAbstraction({
961
+ TxtEnDecoder: (param == null ? void 0 : param.TxtEnDecoder) || Utf8EnDecoderSingleton(),
962
+ FileSystem: new WebFileService(),
963
+ SystemService: new WebSystemService()
964
+ });
965
+ }
966
+ return new WrapperSysAbstraction(my, param);
967
+ }
968
+
969
+ // src/result.ts
970
+ var Result = class _Result {
971
+ static Ok(t) {
972
+ return new ResultOK(t);
973
+ }
974
+ static Err(t) {
975
+ if (typeof t === "string") {
976
+ return new ResultError(new Error(t));
977
+ }
978
+ return new ResultError(t);
979
+ }
980
+ static Is(t) {
981
+ if (!t) {
982
+ return false;
983
+ }
984
+ if (t instanceof _Result) {
985
+ return true;
986
+ }
987
+ const rt = t;
988
+ if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
989
+ return true;
990
+ }
991
+ return false;
992
+ }
993
+ isOk() {
994
+ return this.is_ok();
995
+ }
996
+ isErr() {
997
+ return this.is_err();
998
+ }
999
+ Ok() {
1000
+ return this.unwrap();
1001
+ }
1002
+ Err() {
1003
+ return this.unwrap_err();
1004
+ }
1005
+ };
1006
+ var ResultOK = class extends Result {
1007
+ constructor(t) {
1008
+ super();
1009
+ this._t = t;
1010
+ }
1011
+ is_ok() {
1012
+ return true;
1013
+ }
1014
+ is_err() {
1015
+ return false;
1016
+ }
1017
+ unwrap_err() {
1018
+ throw new Error("Result is Ok");
1019
+ }
1020
+ unwrap() {
1021
+ return this._t;
1022
+ }
1023
+ };
1024
+ var ResultError = class extends Result {
1025
+ constructor(t) {
1026
+ super();
1027
+ this._error = t;
1028
+ }
1029
+ is_ok() {
1030
+ return false;
1031
+ }
1032
+ is_err() {
1033
+ return true;
1034
+ }
1035
+ unwrap() {
1036
+ throw new Error(`Result is Err: ${this._error}`);
1037
+ }
1038
+ unwrap_err() {
1039
+ return this._error;
1040
+ }
1041
+ };
1042
+ function exception2Result(fn) {
1043
+ try {
1044
+ const res = fn();
1045
+ if (res instanceof Promise) {
1046
+ return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
1047
+ }
1048
+ return Result.Ok(res);
1049
+ } catch (e) {
1050
+ return Result.Err(e);
1051
+ }
1052
+ }
1053
+
1054
+ // src/uri.ts
1055
+ function falsy2undef(value) {
1056
+ return value === void 0 || value === null ? void 0 : value;
1057
+ }
1058
+ function ensureURLWithDefaultProto(url, defaultProtocol) {
1059
+ if (!url) {
1060
+ return new MutableURL(`${defaultProtocol}//`);
1061
+ }
1062
+ if (typeof url === "string") {
1063
+ try {
1064
+ return new MutableURL(url);
1065
+ } catch (e) {
1066
+ return new MutableURL(`${defaultProtocol}//${url}`);
1067
+ }
1068
+ } else {
1069
+ return new MutableURL(url.toString());
1070
+ }
1071
+ }
1072
+ function isURL(value) {
1073
+ return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
1074
+ }
1075
+ var MutableURL = class _MutableURL extends URL {
1076
+ constructor(urlStr) {
1077
+ super("defect://does.not.exist");
1078
+ const partedURL = urlStr.split(":");
1079
+ this._hasHostpart = protocols.has(partedURL[0]);
1080
+ let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
1081
+ if (!this._hasHostpart) {
1082
+ const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
1083
+ hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
1084
+ }
1085
+ try {
1086
+ this._sysURL = new URL(hostPartUrl);
1087
+ } catch (ie) {
1088
+ const e = ie;
1089
+ e.message = `${e.message} for URL: ${urlStr}`;
1090
+ throw e;
1091
+ }
1092
+ this._protocol = `${partedURL[0]}:`;
1093
+ if (this._hasHostpart) {
1094
+ this._pathname = this._sysURL.pathname;
1095
+ } else {
1096
+ this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
1097
+ }
1098
+ this.hash = this._sysURL.hash;
1099
+ }
1100
+ clone() {
1101
+ return new _MutableURL(this.toString());
1102
+ }
1103
+ get host() {
1104
+ if (!this._hasHostpart) {
1105
+ throw new Error(
1106
+ `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(protocols.keys()))}`
1107
+ );
1108
+ }
1109
+ return this._sysURL.host;
1110
+ }
1111
+ get port() {
1112
+ if (!this._hasHostpart) {
1113
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1114
+ }
1115
+ return this._sysURL.port;
1116
+ }
1117
+ set port(p) {
1118
+ if (!this._hasHostpart) {
1119
+ throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1120
+ }
1121
+ this._sysURL.port = p;
1122
+ }
1123
+ get hostname() {
1124
+ if (!this._hasHostpart) {
1125
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1126
+ }
1127
+ return this._sysURL.hostname;
1128
+ }
1129
+ set hostname(h) {
1130
+ if (!this._hasHostpart) {
1131
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1132
+ }
1133
+ this._sysURL.hostname = h;
1134
+ }
1135
+ set pathname(p) {
1136
+ this._pathname = p;
1137
+ }
1138
+ get pathname() {
1139
+ return this._pathname;
1140
+ }
1141
+ get protocol() {
1142
+ return this._protocol;
1143
+ }
1144
+ set protocol(p) {
1145
+ if (!p.endsWith(":")) {
1146
+ p = `${p}:`;
1147
+ }
1148
+ this._protocol = p;
1149
+ }
1150
+ get searchParams() {
1151
+ return this._sysURL.searchParams;
1152
+ }
1153
+ toString() {
1154
+ let search = "";
1155
+ if (this._sysURL.searchParams.size) {
1156
+ for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
1157
+ search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
1158
+ }
1159
+ }
1160
+ let hostpart = "";
1161
+ if (this._hasHostpart) {
1162
+ hostpart = this._sysURL.hostname;
1163
+ if (this._sysURL.port) {
1164
+ hostpart += `:${this._sysURL.port}`;
1165
+ }
1166
+ if (!this._pathname.startsWith("/")) {
1167
+ hostpart += "/";
1168
+ }
1169
+ }
1170
+ return `${this._protocol}//${hostpart}${this._pathname}${search}`;
1171
+ }
1172
+ };
1173
+ function from(fac, strURLUri, defaultProtocol) {
1174
+ switch (typeof falsy2undef(strURLUri)) {
1175
+ case "undefined":
1176
+ return fac(new MutableURL(`${defaultProtocol}///`));
1177
+ case "string":
1178
+ return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
1179
+ case "object":
1180
+ if (BuildURI.is(strURLUri)) {
1181
+ return fac(new MutableURL(strURLUri._url.toString()));
1182
+ } else if (URI.is(strURLUri)) {
1183
+ return fac(new MutableURL(strURLUri._url.toString()));
1184
+ } else if (isURL(strURLUri)) {
1185
+ return fac(new MutableURL(strURLUri.toString()));
1186
+ }
1187
+ throw new Error(`unknown object type: ${strURLUri}`);
1188
+ default:
1189
+ throw new Error(`Invalid argument: ${typeof strURLUri}`);
1190
+ }
1191
+ }
1192
+ var BuildURI = class _BuildURI {
1193
+ // pathname needs this
1194
+ constructor(url) {
1195
+ this._url = url;
1196
+ }
1197
+ static is(value) {
1198
+ return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
1199
+ }
1200
+ static from(strURLUri, defaultProtocol = "file:") {
1201
+ return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
1202
+ }
1203
+ port(p) {
1204
+ this._url.port = p;
1205
+ return this;
1206
+ }
1207
+ hostname(h) {
1208
+ this._url.hostname = h;
1209
+ return this;
1210
+ }
1211
+ // password(p: string) {
1212
+ // this._url.password = p;
1213
+ // return this;
1214
+ // }
1215
+ // port(p: string) {
1216
+ // this._url.port = p;
1217
+ // return this;
1218
+ // }
1219
+ // username(u: string) {
1220
+ // this._url.username = u;
1221
+ // return this;
1222
+ // }
1223
+ // search(s: string) {
1224
+ // this._url.search = s;
1225
+ // return this;
1226
+ // }
1227
+ protocol(p) {
1228
+ this._url.protocol = p;
1229
+ return this;
1230
+ }
1231
+ pathname(p) {
1232
+ this._url.pathname = p;
1233
+ return this;
1234
+ }
1235
+ // hash(h: string) {
1236
+ // this._url.hash = h;
1237
+ // return this;
1238
+ // }
1239
+ // host(h: string) {
1240
+ // this._url.host = h;
1241
+ // return this;
1242
+ // }
1243
+ delParam(key) {
1244
+ this._url.searchParams.delete(key);
1245
+ return this;
1246
+ }
1247
+ defParam(key, str) {
1248
+ if (!this._url.searchParams.has(key)) {
1249
+ this._url.searchParams.set(key, str);
1250
+ }
1251
+ return this;
1252
+ }
1253
+ setParam(key, str) {
1254
+ this._url.searchParams.set(key, str);
1255
+ return this;
1256
+ }
1257
+ hasParam(key) {
1258
+ return this._url.searchParams.has(key);
1259
+ }
1260
+ getParam(key) {
1261
+ return falsy2undef(this._url.searchParams.get(key));
1262
+ }
1263
+ toString() {
1264
+ this._url.searchParams.sort();
1265
+ return this._url.toString();
1266
+ }
1267
+ toJSON() {
1268
+ return this.toString();
1269
+ }
1270
+ URI() {
1271
+ return URI.from(this._url);
1272
+ }
1273
+ };
1274
+ var protocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
1275
+ var URI = class _URI {
1276
+ static protocolHasHostpart(protocol) {
1277
+ protocol = protocol.replace(/:$/, "");
1278
+ protocols.add(protocol);
1279
+ return () => {
1280
+ protocols.delete(protocol);
1281
+ };
1282
+ }
1283
+ // if no protocol is provided, default to file:
1284
+ static merge(into, from2, defaultProtocol = "file:") {
1285
+ const intoUrl = BuildURI.from(into, defaultProtocol);
1286
+ const fromUrl = _URI.from(from2, defaultProtocol);
1287
+ intoUrl.protocol(fromUrl.protocol);
1288
+ const fPath = fromUrl.pathname;
1289
+ if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
1290
+ intoUrl.pathname(fromUrl.pathname);
1291
+ }
1292
+ for (const [key, value] of fromUrl.getParams) {
1293
+ intoUrl.setParam(key, value);
1294
+ }
1295
+ return intoUrl.URI();
1296
+ }
1297
+ static is(value) {
1298
+ return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
1299
+ }
1300
+ // if no protocol is provided, default to file:
1301
+ static from(strURLUri, defaultProtocol = "file:") {
1302
+ return from((url) => new _URI(url), strURLUri, defaultProtocol);
1303
+ }
1304
+ static fromResult(strURLUri, defaultProtocol = "file:") {
1305
+ return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
1306
+ }
1307
+ constructor(url) {
1308
+ this._url = url.clone();
1309
+ }
1310
+ build() {
1311
+ return BuildURI.from(this._url);
1312
+ }
1313
+ get hostname() {
1314
+ return this._url.hostname;
1315
+ }
1316
+ // get password(): string {
1317
+ // return this._url.password;
1318
+ // }
1319
+ get port() {
1320
+ return this._url.port;
1321
+ }
1322
+ get host() {
1323
+ return this._url.host;
1324
+ }
1325
+ // get username(): string {
1326
+ // return this._url.username;
1327
+ // }
1328
+ // get search(): string {
1329
+ // return this._url.search;
1330
+ // }
1331
+ get protocol() {
1332
+ return this._url.protocol;
1333
+ }
1334
+ get pathname() {
1335
+ return this._url.pathname;
1336
+ }
1337
+ // get hash(): string {
1338
+ // return this._url.hash;
1339
+ // }
1340
+ // get host(): string {
1341
+ // return this._url.host;
1342
+ // }
1343
+ get getParams() {
1344
+ return this._url.searchParams.entries();
1345
+ }
1346
+ hasParam(key) {
1347
+ return this._url.searchParams.has(key);
1348
+ }
1349
+ getParam(key) {
1350
+ return falsy2undef(this._url.searchParams.get(key));
1351
+ }
1352
+ clone() {
1353
+ return new _URI(this._url);
1354
+ }
1355
+ asURL() {
1356
+ return this._url.clone();
1357
+ }
1358
+ toString() {
1359
+ return this._url.toString();
1360
+ }
1361
+ toJSON() {
1362
+ return this.toString();
1363
+ }
1364
+ };
1365
+
1366
+ // src/runtime.ts
1367
+ function isSet(value, ref = globalThis) {
1368
+ const [head, ...tail] = value.split(".");
1369
+ if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
1370
+ if (tail.length <= 1) {
1371
+ return true;
1372
+ }
1373
+ return isSet(tail.join("."), ref[head]);
1374
+ }
1375
+ return false;
1376
+ }
1377
+ function runtimeFn() {
1378
+ const gt = globalThis;
1379
+ const isReactNative = isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative";
1380
+ let isNodeIsh = false;
1381
+ if (!isSet("Deno")) {
1382
+ isNodeIsh = isSet("process.versions.node") && !isReactNative;
1383
+ }
1384
+ const isDeno = isSet("Deno");
1385
+ return {
1386
+ isNodeIsh,
1387
+ isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
1388
+ isDeno,
1389
+ isReactNative
1390
+ };
1391
+ }
1392
+
1393
+ // src/utils/console-write-stream.ts
1394
+ var ConsoleWriterStreamDefaultWriter = class {
1395
+ constructor(stream) {
1396
+ this.stream = stream;
1397
+ this.desiredSize = null;
1398
+ this.decoder = new TextDecoder();
1399
+ this._stream = stream;
1400
+ this.ready = Promise.resolve(void 0);
1401
+ this.closed = Promise.resolve(void 0);
1402
+ }
1403
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
1404
+ abort(reason) {
1405
+ throw new Error("Method not implemented.");
1406
+ }
1407
+ async close() {
1408
+ }
1409
+ releaseLock() {
1410
+ this._stream.locked = false;
1411
+ this.ready = Promise.resolve(void 0);
1412
+ this.closed = Promise.resolve(void 0);
1413
+ }
1414
+ async write(chunk) {
1415
+ const str = this.decoder.decode(chunk).trimEnd();
1416
+ let output = "log";
1417
+ try {
1418
+ const decode = JSON.parse(str);
1419
+ output = decode.level;
1420
+ } catch (e) {
1421
+ }
1422
+ switch (output) {
1423
+ case "error":
1424
+ console.error(str);
1425
+ break;
1426
+ case "warn":
1427
+ console.warn(str);
1428
+ break;
1429
+ default:
1430
+ console.log(str);
1431
+ }
1432
+ }
1433
+ };
1434
+ var ConsoleWriterStream = class {
1435
+ constructor() {
1436
+ this.locked = false;
1437
+ }
1438
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
1439
+ abort(reason) {
1440
+ throw new Error("Method not implemented.");
1441
+ }
1442
+ async close() {
1443
+ return;
1444
+ }
1445
+ getWriter() {
1446
+ if (this.locked) {
1447
+ throw new Error("Stream is locked");
1448
+ }
1449
+ this.locked = true;
1450
+ if (!this._writer) {
1451
+ this._writer = new ConsoleWriterStreamDefaultWriter(this);
1452
+ }
1453
+ return this._writer;
1454
+ }
1455
+ };
1456
+
1457
+ // src/log-writer-impl.ts
1458
+ var LogWriterStream = class {
1459
+ constructor(out) {
1460
+ this._toFlush = [];
1461
+ this._flushIsRunning = false;
1462
+ this._flushDoneFns = [];
1463
+ this._out = out;
1464
+ }
1465
+ write(encoded) {
1466
+ const my2 = async () => {
1467
+ try {
1468
+ const writer = this._out.getWriter();
1469
+ await writer.ready;
1470
+ await writer.write(encoded);
1471
+ await writer.releaseLock();
1472
+ } catch (err) {
1473
+ console.error("Chunk error:", err);
1474
+ }
1475
+ };
1476
+ this._toFlush.push(my2);
1477
+ this._flush();
1478
+ }
1479
+ _flush(toFlush = void 0, done) {
1480
+ if (done) {
1481
+ this._flushDoneFns.push(done);
1482
+ }
1483
+ if (this._toFlush.length == 0) {
1484
+ this._flushIsRunning = false;
1485
+ this._flushDoneFns.forEach((fn) => fn());
1486
+ this._flushDoneFns = [];
1487
+ return;
1488
+ }
1489
+ if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
1490
+ this._flushIsRunning = true;
1491
+ } else if (!toFlush) {
1492
+ return;
1493
+ }
1494
+ const my2 = this._toFlush.shift();
1495
+ my2 == null ? void 0 : my2().finally(() => {
1496
+ this._flush(this._toFlush);
1497
+ });
1498
+ }
1499
+ };
1500
+
1501
+ // src/log-level-impl.ts
1502
+ var LevelHandlerImpl = class {
1503
+ constructor() {
1504
+ this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
1505
+ this._modules = /* @__PURE__ */ new Map();
1506
+ this.isStackExposed = false;
1507
+ }
1508
+ enableLevel(level, ...modules) {
1509
+ if (modules.length == 0) {
1510
+ this._globalLevels.add(level);
1511
+ return;
1512
+ }
1513
+ this.forModules(
1514
+ level,
1515
+ (p) => {
1516
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, level]));
1517
+ },
1518
+ ...modules
1519
+ );
1520
+ }
1521
+ disableLevel(level, ...modules) {
1522
+ if (modules.length == 0) {
1523
+ this._globalLevels.delete(level);
1524
+ return;
1525
+ }
1526
+ this.forModules(
1527
+ level,
1528
+ (p) => {
1529
+ this._modules.delete(p);
1530
+ },
1531
+ ...modules
1532
+ );
1533
+ }
1534
+ setExposeStack(enable) {
1535
+ this.isStackExposed = !!enable;
1536
+ }
1537
+ forModules(level, fnAction, ...modules) {
1538
+ for (const m of modules.flat()) {
1539
+ if (typeof m !== "string") {
1540
+ continue;
1541
+ }
1542
+ const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
1543
+ for (const p of parts) {
1544
+ fnAction(p);
1545
+ }
1546
+ }
1547
+ }
1548
+ setDebug(...modules) {
1549
+ this.forModules(
1550
+ "debug" /* DEBUG */,
1551
+ (p) => {
1552
+ this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, "debug" /* DEBUG */]));
1553
+ },
1554
+ ...modules
1555
+ );
1556
+ }
1557
+ isEnabled(ilevel, module2) {
1558
+ const level = ilevel;
1559
+ if (typeof module2 === "string") {
1560
+ const levels = this._modules.get(module2);
1561
+ if (levels && levels.has(level)) {
1562
+ return true;
1563
+ }
1564
+ }
1565
+ const wlevel = this._modules.get("*");
1566
+ if (wlevel && typeof level === "string") {
1567
+ if (wlevel.has(level)) {
1568
+ return true;
1569
+ }
1570
+ }
1571
+ if (typeof level !== "string") {
1572
+ return true;
1573
+ }
1574
+ return this._globalLevels.has(level);
1575
+ }
1576
+ };
1577
+ var levelSingleton = new LevelHandlerImpl();
1578
+ function LevelHandlerSingleton() {
1579
+ return levelSingleton;
1580
+ }
1581
+
1582
+ // src/logger-impl.ts
1583
+ function getLen(value) {
1584
+ if (Array.isArray(value)) {
1585
+ return logValue(() => value.length);
1586
+ } else if (typeof value === "string") {
1587
+ return logValue(() => value.length);
1588
+ } else if (typeof value === "object" && value !== null) {
1589
+ if (typeof value.size === "number") {
1590
+ return logValue(() => value.size);
1591
+ } else if (typeof value.length === "number") {
1592
+ return logValue(() => value.length);
1593
+ }
1594
+ return logValue(() => Object.keys(value).length);
1595
+ }
1596
+ return logValue(() => -1);
1597
+ }
1598
+ function hash(value) {
1599
+ return "not implemented";
1600
+ }
1601
+ function toLogValue(lop) {
1602
+ if (lop && typeof lop.then === "function") {
1603
+ throw new Error("async logValue Not implemented");
1604
+ }
1605
+ return lop;
1606
+ }
1607
+ var JSONFormatter = class {
1608
+ constructor(txtEnde, space) {
1609
+ this._txtEnDe = txtEnde;
1610
+ this._space = space;
1611
+ }
1612
+ format(attr) {
1613
+ return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
1614
+ }
1615
+ };
1616
+ var YAMLFormatter = class {
1617
+ constructor(txtEnde, space) {
1618
+ this._txtEnDe = txtEnde;
1619
+ this._space = space;
1620
+ }
1621
+ format(attr) {
1622
+ return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr, removeSelfRef(), this._space) + "\n");
1623
+ }
1624
+ };
1625
+ var LoggerImpl = class _LoggerImpl {
1626
+ // readonly _id: string = "logger-" + Math.random().toString(36)
1627
+ constructor(params) {
1628
+ this._attributes = {};
1629
+ if (!params) {
1630
+ params = {};
1631
+ }
1632
+ if (!params.sys) {
1633
+ this._sys = WebSysAbstraction();
1634
+ } else {
1635
+ this._sys = params.sys;
1636
+ }
1637
+ if (!params.txtEnDe) {
1638
+ this._txtEnDe = Utf8EnDecoderSingleton();
1639
+ } else {
1640
+ this._txtEnDe = params.txtEnDe;
1641
+ }
1642
+ if (!params.formatter) {
1643
+ this._formatter = new JSONFormatter(this._txtEnDe);
1644
+ } else {
1645
+ this._formatter = params.formatter;
1646
+ }
1647
+ if (params.logWriter) {
1648
+ this._logWriter = params.logWriter;
1649
+ } else {
1650
+ if (!params.out) {
1651
+ const rt = runtimeFn();
1652
+ let stream;
1653
+ if (rt.isBrowser) {
1654
+ stream = new ConsoleWriterStream();
1655
+ } else {
1656
+ if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
1657
+ stream = this._sys.Stdout();
1658
+ } else {
1659
+ throw new Error("No output defined for runtime");
1660
+ }
1661
+ }
1662
+ this._logWriter = new LogWriterStream(stream);
1663
+ } else {
1664
+ this._logWriter = new LogWriterStream(params.out);
1665
+ }
1666
+ }
1667
+ if (!params.withAttributes) {
1668
+ this._withAttributes = {};
1669
+ } else {
1670
+ this._withAttributes = __spreadValues({}, params.withAttributes);
1671
+ }
1672
+ this._attributes = __spreadValues({}, this._withAttributes);
1673
+ if (params.levelHandler) {
1674
+ this._levelHandler = params.levelHandler;
1675
+ } else {
1676
+ this._levelHandler = LevelHandlerSingleton();
1677
+ }
1678
+ }
1679
+ TxtEnDe() {
1680
+ return this._txtEnDe;
1681
+ }
1682
+ Attributes() {
1683
+ return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
1684
+ }
1685
+ SetExposeStack(enable) {
1686
+ this._levelHandler.setExposeStack(enable);
1687
+ return this;
1688
+ }
1689
+ EnableLevel(level, ...modules) {
1690
+ this._levelHandler.enableLevel(level, ...modules);
1691
+ return this;
1692
+ }
1693
+ DisableLevel(level, ...modules) {
1694
+ this._levelHandler.disableLevel(level, ...modules);
1695
+ return this;
1696
+ }
1697
+ Module(key) {
1698
+ this._attributes["module"] = logValue(key);
1699
+ this._withAttributes["module"] = logValue(key);
1700
+ return this;
1701
+ }
1702
+ // if the string is "*" it will enable for all modules
1703
+ SetDebug(...modules) {
1704
+ this._levelHandler.setDebug(...modules);
1705
+ return this;
1706
+ }
1707
+ SetFormatter(formatter) {
1708
+ this._formatter = formatter;
1709
+ return this;
1710
+ }
1711
+ Timestamp() {
1712
+ this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
1713
+ return this;
1714
+ }
1715
+ Warn() {
1716
+ this._attributes["level"] = logValue("warn" /* WARN */);
1717
+ return this;
1718
+ }
1719
+ Log() {
1720
+ return this;
1721
+ }
1722
+ Debug() {
1723
+ this._attributes["level"] = logValue("debug" /* DEBUG */);
1724
+ return this;
1725
+ }
1726
+ Error() {
1727
+ this._attributes["level"] = logValue("error" /* ERROR */);
1728
+ return this;
1729
+ }
1730
+ Info() {
1731
+ this._attributes["level"] = logValue("info" /* INFO */);
1732
+ return this;
1733
+ }
1734
+ Err(err) {
1735
+ var _a;
1736
+ if (Result.Is(err)) {
1737
+ if (err.isOk()) {
1738
+ this.Result("noerror", err);
1739
+ } else {
1740
+ this.Result("error", err);
1741
+ }
1742
+ } else if (err instanceof Error) {
1743
+ this._attributes["error"] = logValue(err.message);
1744
+ if (this._levelHandler.isStackExposed) {
1745
+ this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
1746
+ }
1747
+ } else {
1748
+ this._attributes["error"] = logValue("" + err);
1749
+ }
1750
+ return this;
1751
+ }
1752
+ WithLevel(l) {
1753
+ this._attributes["level"] = logValue(l);
1754
+ return this;
1755
+ }
1756
+ Ref(key, action) {
1757
+ if (typeof action === "function") {
1758
+ this._attributes[key] = logValue(action);
1759
+ } else if (typeof action.toString === "function") {
1760
+ this._attributes[key] = logValue(() => action.toString());
1761
+ } else {
1762
+ this._attributes[key] = logValue("INVALID REF");
1763
+ }
1764
+ return this;
1765
+ }
1766
+ Bool(key, value) {
1767
+ this._attributes[key] = logValue(!!value);
1768
+ return this;
1769
+ }
1770
+ Result(key, res) {
1771
+ if (res.isOk()) {
1772
+ this._attributes[key] = logValue(res.Ok());
1773
+ } else {
1774
+ this.Err(res.Err());
1775
+ }
1776
+ return this;
1777
+ }
1778
+ Len(value, key = "len") {
1779
+ this._attributes[key] = getLen(value);
1780
+ return this;
1781
+ }
1782
+ Hash(value, key = "hash") {
1783
+ this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
1784
+ return this;
1785
+ }
1786
+ Url(url, key = "url") {
1787
+ this.Ref(key, () => URI.from(url).toString());
1788
+ return this;
1789
+ }
1790
+ Str(key, value) {
1791
+ this._attributes[key] = logValue(value);
1792
+ return this;
1793
+ }
1794
+ Any(key, value) {
1795
+ this._attributes[key] = logValue(value);
1796
+ return this;
1797
+ }
1798
+ Dur(key, nsec) {
1799
+ this._attributes[key] = logValue(`${nsec}ms`);
1800
+ return this;
1801
+ }
1802
+ Uint64(key, value) {
1803
+ this._attributes[key] = logValue(value);
1804
+ return this;
1805
+ }
1806
+ Int(key, value) {
1807
+ return this.Uint64(key, value);
1808
+ }
1809
+ async Flush() {
1810
+ return new Promise((resolve) => {
1811
+ this._logWriter._flush(void 0, resolve);
1812
+ });
1813
+ }
1814
+ With() {
1815
+ return new WithLoggerBuilder(
1816
+ new _LoggerImpl({
1817
+ logWriter: this._logWriter,
1818
+ sys: this._sys,
1819
+ levelHandler: this._levelHandler,
1820
+ formatter: this._formatter,
1821
+ withAttributes: __spreadValues({
1822
+ module: this._attributes["module"]
1823
+ }, this._withAttributes)
1824
+ })
1825
+ );
1826
+ }
1827
+ _resetAttributes(fn) {
1828
+ const ret = fn();
1829
+ Object.keys(this._attributes).forEach((key) => {
1830
+ delete this._attributes[key];
1831
+ });
1832
+ Object.assign(this._attributes, this._withAttributes);
1833
+ return ret;
1834
+ }
1835
+ Msg(...args) {
1836
+ const fnError = this._resetAttributes(() => {
1837
+ var _a, _b;
1838
+ const doWrite = this._levelHandler.isEnabled(
1839
+ (_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
1840
+ (_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
1841
+ );
1842
+ this._attributes["msg"] = logValue(args.join(" "));
1843
+ const msg = this._attributes["msg"].value();
1844
+ if (typeof msg === "string" && !msg.trim().length) {
1845
+ delete this._attributes["msg"];
1846
+ }
1847
+ let fnRet = () => this._formatter.format(__spreadValues({}, this._attributes));
1848
+ if (doWrite) {
1849
+ const encoded = fnRet();
1850
+ this._logWriter.write(encoded);
1851
+ fnRet = () => encoded;
1852
+ }
1853
+ return fnRet;
1854
+ });
1855
+ return {
1856
+ AsError: () => new Error(this._txtEnDe.decode(fnError()))
1857
+ };
1858
+ }
1859
+ };
1860
+ var WithLoggerBuilder = class {
1861
+ constructor(li) {
1862
+ this._li = li;
1863
+ }
1864
+ TxtEnDe() {
1865
+ return this._li.TxtEnDe();
1866
+ }
1867
+ Logger() {
1868
+ Object.assign(this._li._withAttributes, this._li._attributes);
1869
+ return this._li;
1870
+ }
1871
+ Attributes() {
1872
+ return __spreadValues({}, this._li._attributes);
1873
+ }
1874
+ SetExposeStack(enable) {
1875
+ this._li._levelHandler.setExposeStack(enable);
1876
+ return this;
1877
+ }
1878
+ SetFormatter(fmt) {
1879
+ this._li.SetFormatter(fmt);
1880
+ return this;
1881
+ }
1882
+ EnableLevel(level, ...modules) {
1883
+ this._li._levelHandler.enableLevel(level, ...modules);
1884
+ return this;
1885
+ }
1886
+ DisableLevel(level, ...modules) {
1887
+ this._li._levelHandler.enableLevel(level, ...modules);
1888
+ return this;
1889
+ }
1890
+ Module(key) {
1891
+ this._li.Module(key);
1892
+ return this;
1893
+ }
1894
+ SetDebug(...modules) {
1895
+ this._li.SetDebug(...modules);
1896
+ return this;
1897
+ }
1898
+ Str(key, value) {
1899
+ this._li.Str(key, value);
1900
+ return this;
1901
+ }
1902
+ Len(value, key) {
1903
+ this._li.Len(value, key);
1904
+ return this;
1905
+ }
1906
+ Hash(value, key) {
1907
+ this._li.Hash(value, key);
1908
+ return this;
1909
+ }
1910
+ Ref(key, action) {
1911
+ this._li.Ref(key, action);
1912
+ return this;
1913
+ }
1914
+ Bool(key, value) {
1915
+ this._li.Bool(key, value);
1916
+ return this;
1917
+ }
1918
+ Result(key, res) {
1919
+ this._li.Result(key, res);
1920
+ return this;
1921
+ }
1922
+ Url(url, key) {
1923
+ this._li.Url(url, key);
1924
+ return this;
1925
+ }
1926
+ Int(key, value) {
1927
+ this._li.Int(key, value);
1928
+ return this;
1929
+ }
1930
+ Log() {
1931
+ this._li.Log();
1932
+ return this;
1933
+ }
1934
+ WithLevel(level) {
1935
+ this._li.WithLevel(level);
1936
+ return this;
1937
+ }
1938
+ Error() {
1939
+ this._li.Error();
1940
+ return this;
1941
+ }
1942
+ Warn() {
1943
+ this._li.Error();
1944
+ return this;
1945
+ }
1946
+ Debug() {
1947
+ this._li.Debug();
1948
+ return this;
1949
+ }
1950
+ Err(err) {
1951
+ this._li.Err(err);
1952
+ return this;
1953
+ }
1954
+ Info() {
1955
+ this._li.Info();
1956
+ return this;
1957
+ }
1958
+ Timestamp() {
1959
+ this._li.Timestamp();
1960
+ return this;
1961
+ }
1962
+ Any(key, value) {
1963
+ this._li.Any(key, value);
1964
+ return this;
1965
+ }
1966
+ Dur(key, nsec) {
1967
+ this._li.Dur(key, nsec);
1968
+ return this;
1969
+ }
1970
+ Uint64(key, value) {
1971
+ this._li.Uint64(key, value);
1972
+ return this;
1973
+ }
1974
+ };
1975
+
1976
+ // src/utils/fanout-write-stream.ts
1977
+ var FanoutWriteStream = class {
1978
+ constructor(writers) {
1979
+ this.desiredSize = null;
1980
+ this._writers = writers;
1981
+ this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
1982
+ this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
1983
+ }
1984
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1985
+ abort(reason) {
1986
+ return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
1987
+ });
1988
+ }
1989
+ close() {
1990
+ return Promise.all(this._writers.map((w) => w.close())).then(() => {
1991
+ });
1992
+ }
1993
+ releaseLock() {
1994
+ this._writers.map((w) => w.releaseLock());
1995
+ }
1996
+ write(chunk) {
1997
+ return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
1998
+ });
1999
+ }
2000
+ };
2001
+
2002
+ // src/test/log-write-stream.ts
2003
+ var LogWriteStream = class {
2004
+ constructor(bufferArr) {
2005
+ this._resolveClosed = new Future();
2006
+ this.closed = this._resolveClosed.asPromise();
2007
+ this.desiredSize = null;
2008
+ this.ready = Promise.resolve(void 0);
2009
+ this._bufferArr = bufferArr;
2010
+ }
2011
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
2012
+ abort(reason) {
2013
+ throw new Error("Method not implemented.");
2014
+ }
2015
+ async close() {
2016
+ await this.closed;
2017
+ return Promise.resolve(void 0);
2018
+ }
2019
+ releaseLock() {
2020
+ }
2021
+ async write(chunk) {
2022
+ if (chunk) {
2023
+ this._bufferArr.push(chunk);
2024
+ }
2025
+ return Promise.resolve(void 0);
2026
+ }
2027
+ };
2028
+ var LogCollector = class {
2029
+ constructor(pass, txtEnDe) {
2030
+ this.locked = false;
2031
+ this._bufferArr = [];
2032
+ this._pass = pass;
2033
+ this._txtEnDe = txtEnDe || Utf8EnDecoderSingleton();
2034
+ }
2035
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2036
+ abort(reason) {
2037
+ throw new Error("Method not implemented.");
2038
+ }
2039
+ async close() {
2040
+ if (this._writer) {
2041
+ const ret = await this._writer.close();
2042
+ this._writer = void 0;
2043
+ return ret;
2044
+ }
2045
+ return Promise.resolve(void 0);
2046
+ }
2047
+ getWriter() {
2048
+ if (!this._writer) {
2049
+ const dests = [new LogWriteStream(this._bufferArr)];
2050
+ if (this._pass) {
2051
+ dests.push(this._pass);
2052
+ }
2053
+ this._writer = new FanoutWriteStream(dests);
2054
+ }
2055
+ return this._writer;
2056
+ }
2057
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2058
+ Logs(notJsonLine = false) {
2059
+ if (!this._writer) {
2060
+ return [];
2061
+ }
2062
+ const jsonNlStr = this._txtEnDe.decode(
2063
+ new Uint8Array(
2064
+ function* (res) {
2065
+ for (const x of res) {
2066
+ yield* __yieldStar(x);
2067
+ }
2068
+ }(this._bufferArr)
2069
+ )
2070
+ );
2071
+ if (!notJsonLine) {
2072
+ const splitStr = jsonNlStr.split("\n");
2073
+ const filterStr = splitStr.filter((a) => a.length);
2074
+ const mapStr = filterStr.map((a) => JSON.parse(a));
2075
+ return mapStr;
2076
+ }
2077
+ return jsonNlStr.split("\n").filter((a) => a.length);
2078
+ }
2079
+ };
2080
+
2081
+ // src/test/mock-logger.ts
2082
+ function MockLogger(params) {
2083
+ const lc = new LogCollector(params == null ? void 0 : params.pass);
2084
+ let modNames = ["MockLogger"];
2085
+ if (typeof (params == null ? void 0 : params.moduleName) === "string") {
2086
+ modNames = [params == null ? void 0 : params.moduleName];
2087
+ } else if (Array.isArray(params == null ? void 0 : params.moduleName)) {
2088
+ modNames = [...params.moduleName, ...modNames];
2089
+ }
2090
+ const logger = new LoggerImpl({
2091
+ out: lc,
2092
+ sys: params == null ? void 0 : params.sys,
2093
+ levelHandler: new LevelHandlerImpl()
2094
+ }).With().Module(modNames[0]).Logger();
2095
+ if (!(params == null ? void 0 : params.disableDebug)) {
2096
+ logger.SetDebug(...modNames);
2097
+ }
2098
+ return {
2099
+ logCollector: lc,
2100
+ logger
2101
+ };
2102
+ }
2103
+
2104
+ // src/option.ts
2105
+ var Option = class _Option {
2106
+ static Some(t) {
2107
+ return new Some(t);
2108
+ }
2109
+ static None() {
2110
+ return new None();
2111
+ }
2112
+ static Is(t) {
2113
+ return t instanceof _Option;
2114
+ }
2115
+ IsNone() {
2116
+ return this.is_none();
2117
+ }
2118
+ IsSome() {
2119
+ return this.is_some();
2120
+ }
2121
+ Unwrap() {
2122
+ return this.unwrap();
2123
+ }
2124
+ };
2125
+ var Some = class extends Option {
2126
+ constructor(_t) {
2127
+ super();
2128
+ this._t = _t;
2129
+ }
2130
+ is_none() {
2131
+ return false;
2132
+ }
2133
+ is_some() {
2134
+ return true;
2135
+ }
2136
+ unwrap() {
2137
+ return this._t;
2138
+ }
2139
+ };
2140
+ var None = class extends Option {
2141
+ is_none() {
2142
+ return true;
2143
+ }
2144
+ is_some() {
2145
+ return false;
2146
+ }
2147
+ unwrap() {
2148
+ throw new Error("None.unwrap");
2149
+ }
2150
+ };
2151
+
2152
+ // src/tracer.ts
2153
+ var Metric = class {
2154
+ constructor(path) {
2155
+ this.path = path;
2156
+ }
2157
+ set(value) {
2158
+ this.value = value;
2159
+ }
2160
+ add(value) {
2161
+ if (typeof value === "number") {
2162
+ if (this.value === void 0) {
2163
+ this.value = 0;
2164
+ }
2165
+ this.value = this.value + value;
2166
+ } else if (Array.isArray(value)) {
2167
+ if (!Array.isArray(this.value)) {
2168
+ this.value = [];
2169
+ }
2170
+ this.value.push(...value);
2171
+ } else {
2172
+ throw new Error("add only support number or array");
2173
+ }
2174
+ }
2175
+ };
2176
+ var Metrics = class {
2177
+ constructor(tracenode) {
2178
+ this.spanRefs = /* @__PURE__ */ new Map();
2179
+ this.tracenode = tracenode;
2180
+ this.map = tracenode.ctx.metrics;
2181
+ }
2182
+ toJSON() {
2183
+ const obj = {};
2184
+ for (const [key, value] of this.map) {
2185
+ obj[key] = value.value;
2186
+ }
2187
+ return obj;
2188
+ }
2189
+ get(ipath) {
2190
+ const path = ipath.replace(/[/]+/g, "/").trim();
2191
+ if (path.startsWith("/")) {
2192
+ if (path.slice(1).length === 0) {
2193
+ throw new Error(`Metrics path must contain value /:${path}`);
2194
+ }
2195
+ let metric = this.map.get(path);
2196
+ if (!metric) {
2197
+ metric = new Metric(path);
2198
+ this.map.set(path, metric);
2199
+ }
2200
+ this.spanRefs.set(path, metric);
2201
+ return metric;
2202
+ } else if (path.includes("/")) {
2203
+ throw new Error(`Metrics path must start with /:${path}`);
2204
+ }
2205
+ const rootPath = this.tracenode.getRootPath();
2206
+ return this.get(`${rootPath}/${path}`);
2207
+ }
2208
+ };
2209
+ var TraceNode = class _TraceNode {
2210
+ constructor(ctx) {
2211
+ this.childs = /* @__PURE__ */ new Map();
2212
+ this.invokations = [];
2213
+ this.spanId = ctx.spanId;
2214
+ this.ctx = ctx;
2215
+ this.metrics = new Metrics(this);
2216
+ }
2217
+ static root(time, logger) {
2218
+ return new _TraceNode({
2219
+ spanId: "root",
2220
+ time,
2221
+ logger,
2222
+ metrics: /* @__PURE__ */ new Map(),
2223
+ parent: void 0
2224
+ });
2225
+ }
2226
+ getRootPath(rpath = []) {
2227
+ if (!this.ctx.parent) {
2228
+ return "/" + rpath.reverse().join("/");
2229
+ }
2230
+ return this.ctx.parent.getRootPath(rpath.concat(this.ctx.spanId));
2231
+ }
2232
+ invokes() {
2233
+ const cleanCtx = __spreadValues({}, this.ctx);
2234
+ delete cleanCtx.parent;
2235
+ delete cleanCtx.time;
2236
+ delete cleanCtx.logger;
2237
+ delete cleanCtx.metrics;
2238
+ const spanRefs = this.metrics.toJSON.call({ map: this.metrics.spanRefs });
2239
+ const metricsRefs = Object.keys(spanRefs).length > 0 ? { metricRefs: spanRefs } : {};
2240
+ return __spreadValues({
2241
+ ctx: cleanCtx,
2242
+ invokations: this.invokations
2243
+ }, metricsRefs);
2244
+ }
2245
+ ctxWith(spanId, logger) {
2246
+ const ctx = __spreadProps(__spreadValues({}, this.ctx), {
2247
+ spanId
2248
+ });
2249
+ if (logger) {
2250
+ ctx.logger = logger;
2251
+ }
2252
+ return ctx;
2253
+ }
2254
+ // <V extends () => Promise<T> | T, T>(id: string, fn: V): ReturnType<V>
2255
+ span(inSpanId, fn) {
2256
+ let ctx;
2257
+ if (typeof inSpanId === "string") {
2258
+ ctx = __spreadProps(__spreadValues({}, this.ctx), {
2259
+ spanId: inSpanId,
2260
+ parent: this
2261
+ });
2262
+ } else {
2263
+ ctx = __spreadProps(__spreadValues(__spreadValues({}, this.ctx), inSpanId), {
2264
+ parent: this
2265
+ });
2266
+ }
2267
+ if (ctx.logger) {
2268
+ ctx = __spreadValues(__spreadValues({}, ctx), ctx.logger.Attributes());
2269
+ }
2270
+ const spanId = ctx.spanId;
2271
+ let spanTrace = this.childs.get(spanId);
2272
+ if (!spanTrace) {
2273
+ spanTrace = new _TraceNode(ctx);
2274
+ this.childs.set(spanId.toString(), spanTrace);
2275
+ }
2276
+ const invokation = {
2277
+ start: this.ctx.time.Now().getTime(),
2278
+ end: 0,
2279
+ result: "success"
2280
+ };
2281
+ spanTrace.invokations.push(invokation);
2282
+ try {
2283
+ const possiblePromise = fn(spanTrace);
2284
+ if (possiblePromise instanceof Promise) {
2285
+ return possiblePromise.then((v) => {
2286
+ return v;
2287
+ }).catch((e) => {
2288
+ invokation.result = "error";
2289
+ throw e;
2290
+ }).finally(() => {
2291
+ invokation.end = this.ctx.time.Now().getTime();
2292
+ });
2293
+ }
2294
+ invokation.end = this.ctx.time.Now().getTime();
2295
+ return possiblePromise;
2296
+ } catch (e) {
2297
+ invokation.result = "error";
2298
+ invokation.end = this.ctx.time.Now().getTime();
2299
+ throw e;
2300
+ }
2301
+ }
2302
+ };
2303
+
2304
+ // src/crypto.ts
2305
+ function randomBytes(size) {
2306
+ const bytes = new Uint8Array(size);
2307
+ if (size > 0) {
2308
+ crypto.getRandomValues(bytes);
2309
+ }
2310
+ return bytes;
2311
+ }
2312
+ function digestSHA256(data) {
2313
+ return Promise.resolve(crypto.subtle.digest("SHA-256", data));
2314
+ }
2315
+ function toCryptoRuntime(cryptoOpts = {}) {
2316
+ const runtime = {
2317
+ importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),
2318
+ exportKey: cryptoOpts.exportKey || crypto.subtle.exportKey.bind(crypto.subtle),
2319
+ encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),
2320
+ decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),
2321
+ randomBytes: cryptoOpts.randomBytes || randomBytes,
2322
+ digestSHA256: cryptoOpts.digestSHA256 || digestSHA256
2323
+ };
2324
+ return runtime;
2325
+ }
2326
+
2327
+ // src/version.ts
2328
+ var VERSION = Object.keys({
2329
+ __packageVersion__: "xxxx"
2330
+ })[0];
2331
+
2332
+ // src/utils/index.ts
2333
+ var utils_exports = {};
2334
+ __export(utils_exports, {
2335
+ ConsoleWriterStream: () => ConsoleWriterStream,
2336
+ ConsoleWriterStreamDefaultWriter: () => ConsoleWriterStreamDefaultWriter,
2337
+ FanoutWriteStream: () => FanoutWriteStream,
2338
+ array2stream: () => array2stream,
2339
+ devnull: () => devnull,
2340
+ rebuffer: () => rebuffer,
2341
+ rebufferArray: () => rebufferArray,
2342
+ stream2array: () => stream2array,
2343
+ stream2string: () => stream2string,
2344
+ stream2uint8array: () => stream2uint8array,
2345
+ streamMap: () => streamMap,
2346
+ string2stream: () => string2stream,
2347
+ uint8array2stream: () => uint8array2stream
2348
+ });
2349
+
2350
+ // src/utils/stream-map.ts
2351
+ function streamMap(s, sm) {
2352
+ const state = { reader: s.getReader(), streamMap: sm, idx: 0 };
2353
+ return new ReadableStream({
2354
+ async pull(controller) {
2355
+ const { done, value } = await state.reader.read();
2356
+ if (done) {
2357
+ if (state.streamMap.Close) {
2358
+ state.streamMap.Close();
2359
+ }
2360
+ controller.close();
2361
+ return;
2362
+ }
2363
+ const promiseOrU = state.streamMap.Map(value, state.idx++);
2364
+ let mapped;
2365
+ if (promiseOrU instanceof Promise || typeof promiseOrU.then === "function") {
2366
+ mapped = await promiseOrU;
2367
+ } else {
2368
+ mapped = promiseOrU;
2369
+ }
2370
+ controller.enqueue(mapped);
2371
+ }
2372
+ });
2373
+ }
2374
+ async function devnull(a) {
2375
+ const reader = a.getReader();
2376
+ let cnt = 0;
2377
+ while (true) {
2378
+ const { done } = await reader.read();
2379
+ if (done) {
2380
+ break;
2381
+ }
2382
+ cnt++;
2383
+ }
2384
+ return cnt;
2385
+ }
2386
+ function array2stream(a) {
2387
+ let i = 0;
2388
+ return new ReadableStream({
2389
+ pull(controller) {
2390
+ if (i >= a.length) {
2391
+ controller.close();
2392
+ return;
2393
+ }
2394
+ controller.enqueue(a[i]);
2395
+ i++;
2396
+ }
2397
+ });
2398
+ }
2399
+ async function stream2array(a) {
2400
+ const ret = [];
2401
+ const reader = a.getReader();
2402
+ while (true) {
2403
+ const { done, value } = await reader.read();
2404
+ if (done) {
2405
+ break;
2406
+ }
2407
+ ret.push(value);
2408
+ }
2409
+ return ret;
2410
+ }
2411
+
2412
+ // src/utils/rebuffer.ts
2413
+ async function rebufferArray(a, chunkSize) {
2414
+ return stream2array(rebuffer(array2stream(a), chunkSize));
2415
+ }
2416
+ function reChunk(cs, chunkSize) {
2417
+ const len = cs.reduce((acc, v) => acc + v.length, 0);
2418
+ const last = cs[cs.length - 1];
2419
+ const lastOfs = len - last.length;
2420
+ const rest = last.subarray(chunkSize - lastOfs);
2421
+ cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);
2422
+ const chunk = new Uint8Array(chunkSize);
2423
+ let ofs = 0;
2424
+ for (const c of cs) {
2425
+ chunk.set(c, ofs);
2426
+ ofs += c.length;
2427
+ }
2428
+ return { rest, chunk };
2429
+ }
2430
+ function pump(ps, controller, next) {
2431
+ ps.reader.read().then(({ done, value }) => {
2432
+ if (done) {
2433
+ if (ps.tmpLen > 0) {
2434
+ controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);
2435
+ }
2436
+ controller.close();
2437
+ next();
2438
+ return;
2439
+ }
2440
+ if (ps.tmpLen + value.length > ps.chunkSize) {
2441
+ ps.tmp.push(value);
2442
+ const res = reChunk(ps.tmp, ps.chunkSize);
2443
+ controller.enqueue(res.chunk);
2444
+ ps.tmp = [res.rest];
2445
+ ps.tmpLen = res.rest.length;
2446
+ next();
2447
+ return;
2448
+ } else if (value.length) {
2449
+ ps.tmp.push(value);
2450
+ ps.tmpLen += value.length;
2451
+ }
2452
+ pump(ps, controller, next);
2453
+ });
2454
+ }
2455
+ function rebuffer(a, chunkSize) {
2456
+ const state = {
2457
+ reader: a.getReader(),
2458
+ tmp: [],
2459
+ tmpLen: 0,
2460
+ chunkSize
2461
+ };
2462
+ return new ReadableStream({
2463
+ async pull(controller) {
2464
+ return new Promise((resolve) => {
2465
+ pump(state, controller, resolve);
2466
+ });
2467
+ }
2468
+ });
2469
+ }
2470
+
2471
+ // src/utils/stream2string.ts
2472
+ async function stream2string(stream, maxSize) {
2473
+ if (!stream) {
2474
+ return Promise.resolve("");
2475
+ }
2476
+ const reader = stream.getReader();
2477
+ let res = "";
2478
+ const decoder2 = new TextDecoder();
2479
+ let rSize = 0;
2480
+ while (typeof maxSize === "undefined" || rSize < maxSize) {
2481
+ try {
2482
+ const read = await reader.read();
2483
+ if (read.done) {
2484
+ break;
2485
+ }
2486
+ if (maxSize && rSize + read.value.length > maxSize) {
2487
+ read.value = read.value.slice(0, maxSize - rSize);
2488
+ }
2489
+ const block = decoder2.decode(read.value, { stream: true });
2490
+ rSize += read.value.length;
2491
+ res += block;
2492
+ } catch (err) {
2493
+ return Promise.reject(err);
2494
+ }
2495
+ }
2496
+ return Promise.resolve(res);
2497
+ }
2498
+ async function stream2uint8array(stream) {
2499
+ if (!stream) {
2500
+ return Promise.resolve(new Uint8Array());
2501
+ }
2502
+ const reader = stream.getReader();
2503
+ let res = new Uint8Array();
2504
+ while (1) {
2505
+ try {
2506
+ const { done, value } = await reader.read();
2507
+ if (done) {
2508
+ break;
2509
+ }
2510
+ res = new Uint8Array([...res, ...value]);
2511
+ } catch (err) {
2512
+ return Promise.reject(err);
2513
+ }
2514
+ }
2515
+ return Promise.resolve(res);
2516
+ }
2517
+
2518
+ // src/utils/string2stream.ts
2519
+ function string2stream(str, ende = Utf8EnDecoderSingleton()) {
2520
+ return uint8array2stream(ende.encode(str));
2521
+ }
2522
+ function uint8array2stream(str) {
2523
+ return new ReadableStream({
2524
+ start(controller) {
2525
+ controller.enqueue(str);
2526
+ controller.close();
2527
+ }
2528
+ });
2529
+ }
2530
+ // Annotate the CommonJS export names for ESM import in node:
2531
+ 0 && (module.exports = {
2532
+ BaseSysAbstraction,
2533
+ BrowserEnvActions,
2534
+ BuildURI,
2535
+ ConstTime,
2536
+ EnvImpl,
2537
+ Future,
2538
+ IDMode,
2539
+ IdService,
2540
+ IsLogger,
2541
+ JSONFormatter,
2542
+ Keyed,
2543
+ KeyedResolvOnce,
2544
+ KeyedResolvSeq,
2545
+ Level,
2546
+ LevelHandlerImpl,
2547
+ LevelHandlerSingleton,
2548
+ LogCollector,
2549
+ LogValue,
2550
+ LogWriteStream,
2551
+ LoggerImpl,
2552
+ Metric,
2553
+ Metrics,
2554
+ MockLogger,
2555
+ MutableURL,
2556
+ None,
2557
+ Option,
2558
+ RandomMode,
2559
+ RandomService,
2560
+ ResolveOnce,
2561
+ ResolveSeq,
2562
+ Result,
2563
+ ResultError,
2564
+ ResultOK,
2565
+ Some,
2566
+ StepTime,
2567
+ String2TimeMode,
2568
+ SysTime,
2569
+ Time,
2570
+ TimeFactory,
2571
+ TimeMode,
2572
+ TimeUnits,
2573
+ TraceNode,
2574
+ URI,
2575
+ Utf8EnDecoder,
2576
+ Utf8EnDecoderSingleton,
2577
+ VERSION,
2578
+ WrapperSysAbstraction,
2579
+ YAMLFormatter,
2580
+ asyncLogValue,
2581
+ bin2string,
2582
+ bin2text,
2583
+ envFactory,
2584
+ exception2Result,
2585
+ isURL,
2586
+ logValue,
2587
+ protocols,
2588
+ removeSelfRef,
2589
+ runtimeFn,
2590
+ toCryptoRuntime,
2591
+ utils
2592
+ });
2593
+ //# sourceMappingURL=index.cjs.map