@adviser/cement 0.0.0-jsr-t1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +39 -0
- package/base-sys-abstraction-BkEiLHl0.d.ts +193 -0
- package/base-sys-abstraction-Qj7pkY1N.d.cts +193 -0
- package/chunk-7KFVMTOS.js +311 -0
- package/chunk-7KFVMTOS.js.map +1 -0
- package/chunk-GES3MUGV.js +92 -0
- package/chunk-GES3MUGV.js.map +1 -0
- package/chunk-Q65HLCNL.js +601 -0
- package/chunk-Q65HLCNL.js.map +1 -0
- package/chunk-WMMUXBDX.js +87 -0
- package/chunk-WMMUXBDX.js.map +1 -0
- package/index-Q3phXzYr.d.cts +75 -0
- package/index-tIGZMHTc.d.ts +75 -0
- package/index.cjs +2593 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +532 -0
- package/index.d.ts +532 -0
- package/index.js +1533 -0
- package/index.js.map +1 -0
- package/node/index.cjs +924 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +65 -0
- package/node/index.d.ts +65 -0
- package/node/index.js +398 -0
- package/node/index.js.map +1 -0
- package/package.json +81 -0
- package/src/base-sys-abstraction.test.ts +95 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.test.ts +59 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.test.ts +15 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.test.ts +32 -0
- package/src/future.ts +27 -0
- package/src/index.ts +22 -0
- package/src/jsr.json +20 -0
- package/src/log-level-impl.ts +87 -0
- package/src/log-writer-impl.ts +58 -0
- package/src/logger-impl.ts +498 -0
- package/src/logger.test.ts +1132 -0
- package/src/logger.ts +208 -0
- package/src/node/deno-file-service.ts +92 -0
- package/src/node/deno-sys-abstraction.ts +133 -0
- package/src/node/index.ts +4 -0
- package/src/node/mock-file-service.ts +45 -0
- package/src/node/node-file-service.ts +91 -0
- package/src/node/node-sys-abstraction.ts +121 -0
- package/src/option.ts +60 -0
- package/src/resolve-once.test.ts +321 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.test.ts +102 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.ts +53 -0
- package/src/sys-env.test.ts +53 -0
- package/src/sys-env.ts +216 -0
- package/src/test/log-write-stream.ts +95 -0
- package/src/test/mock-logger.ts +40 -0
- package/src/time.ts +20 -0
- package/src/tracer.test.ts +314 -0
- package/src/tracer.ts +222 -0
- package/src/txt-en-decoder.ts +21 -0
- package/src/uri.test.ts +155 -0
- package/src/uri.ts +421 -0
- package/src/utils/console-write-stream.ts +72 -0
- package/src/utils/fanout-write-stream.ts +32 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/rebuffer.ts +75 -0
- package/src/utils/stream-map.ts +67 -0
- package/src/utils/stream2string.ts +47 -0
- package/src/utils/string2stream.ts +14 -0
- package/src/version.ts +3 -0
- package/src/web/index.ts +1 -0
- package/src/web/web-sys-abstraction.ts +80 -0
- package/ts/LICENSE +201 -0
- package/ts/README.md +39 -0
- package/ts/base-sys-abstraction.d.ts +84 -0
- package/ts/base-sys-abstraction.d.ts.map +1 -0
- package/ts/base-sys-abstraction.js +178 -0
- package/ts/base-sys-abstraction.js.map +1 -0
- package/ts/base-sys-abstraction.test.d.ts +2 -0
- package/ts/base-sys-abstraction.test.d.ts.map +1 -0
- package/ts/base-sys-abstraction.test.js +82 -0
- package/ts/base-sys-abstraction.test.js.map +1 -0
- package/ts/bin2text.d.ts +3 -0
- package/ts/bin2text.d.ts.map +1 -0
- package/ts/bin2text.js +43 -0
- package/ts/bin2text.js.map +1 -0
- package/ts/bin2text.test.d.ts +2 -0
- package/ts/bin2text.test.d.ts.map +1 -0
- package/ts/bin2text.test.js +51 -0
- package/ts/bin2text.test.js.map +1 -0
- package/ts/crypto.d.ts +76 -0
- package/ts/crypto.d.ts.map +1 -0
- package/ts/crypto.js +22 -0
- package/ts/crypto.js.map +1 -0
- package/ts/crypto.test.d.ts +2 -0
- package/ts/crypto.test.d.ts.map +1 -0
- package/ts/crypto.test.js +14 -0
- package/ts/crypto.test.js.map +1 -0
- package/ts/file-service.d.ts +17 -0
- package/ts/file-service.d.ts.map +1 -0
- package/ts/file-service.js +2 -0
- package/ts/file-service.js.map +1 -0
- package/ts/future.d.ts +8 -0
- package/ts/future.d.ts.map +1 -0
- package/ts/future.js +38 -0
- package/ts/future.js.map +1 -0
- package/ts/future.test.d.ts +2 -0
- package/ts/future.test.d.ts.map +1 -0
- package/ts/future.test.js +28 -0
- package/ts/future.test.js.map +1 -0
- package/ts/index.d.ts +23 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +23 -0
- package/ts/index.js.map +1 -0
- package/ts/log-level-impl.d.ts +14 -0
- package/ts/log-level-impl.d.ts.map +1 -0
- package/ts/log-level-impl.js +72 -0
- package/ts/log-level-impl.js.map +1 -0
- package/ts/log-writer-impl.d.ts +10 -0
- package/ts/log-writer-impl.d.ts.map +1 -0
- package/ts/log-writer-impl.js +45 -0
- package/ts/log-writer-impl.js.map +1 -0
- package/ts/logger-impl.d.ts +71 -0
- package/ts/logger-impl.d.ts.map +1 -0
- package/ts/logger-impl.js +412 -0
- package/ts/logger-impl.js.map +1 -0
- package/ts/logger.d.ts +84 -0
- package/ts/logger.d.ts.map +1 -0
- package/ts/logger.js +114 -0
- package/ts/logger.js.map +1 -0
- package/ts/logger.test.d.ts +2 -0
- package/ts/logger.test.d.ts.map +1 -0
- package/ts/logger.test.js +1023 -0
- package/ts/logger.test.js.map +1 -0
- package/ts/node/deno-file-service.d.ts +17 -0
- package/ts/node/deno-file-service.d.ts.map +1 -0
- package/ts/node/deno-file-service.js +65 -0
- package/ts/node/deno-file-service.js.map +1 -0
- package/ts/node/deno-sys-abstraction.d.ts +22 -0
- package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
- package/ts/node/deno-sys-abstraction.js +101 -0
- package/ts/node/deno-sys-abstraction.js.map +1 -0
- package/ts/node/index.d.ts +5 -0
- package/ts/node/index.d.ts.map +1 -0
- package/ts/node/index.js +5 -0
- package/ts/node/index.js.map +1 -0
- package/ts/node/mock-file-service.d.ts +11 -0
- package/ts/node/mock-file-service.d.ts.map +1 -0
- package/ts/node/mock-file-service.js +34 -0
- package/ts/node/mock-file-service.js.map +1 -0
- package/ts/node/mock-file-service.test.d.ts +2 -0
- package/ts/node/mock-file-service.test.d.ts.map +1 -0
- package/ts/node/mock-file-service.test.js +31 -0
- package/ts/node/mock-file-service.test.js.map +1 -0
- package/ts/node/node-file-service.d.ts +16 -0
- package/ts/node/node-file-service.d.ts.map +1 -0
- package/ts/node/node-file-service.js +71 -0
- package/ts/node/node-file-service.js.map +1 -0
- package/ts/node/node-sys-abstraction.d.ts +22 -0
- package/ts/node/node-sys-abstraction.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.js +99 -0
- package/ts/node/node-sys-abstraction.js.map +1 -0
- package/ts/node/node-sys-abstraction.test.d.ts +2 -0
- package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.test.js +87 -0
- package/ts/node/node-sys-abstraction.test.js.map +1 -0
- package/ts/option.d.ts +25 -0
- package/ts/option.d.ts.map +1 -0
- package/ts/option.js +47 -0
- package/ts/option.js.map +1 -0
- package/ts/resolve-once.d.ts +46 -0
- package/ts/resolve-once.d.ts.map +1 -0
- package/ts/resolve-once.js +152 -0
- package/ts/resolve-once.js.map +1 -0
- package/ts/resolve-once.test.d.ts +2 -0
- package/ts/resolve-once.test.d.ts.map +1 -0
- package/ts/resolve-once.test.js +283 -0
- package/ts/resolve-once.test.js.map +1 -0
- package/ts/result.d.ts +34 -0
- package/ts/result.d.ts.map +1 -0
- package/ts/result.js +85 -0
- package/ts/result.js.map +1 -0
- package/ts/result.test.d.ts +2 -0
- package/ts/result.test.d.ts.map +1 -0
- package/ts/result.test.js +79 -0
- package/ts/result.test.js.map +1 -0
- package/ts/runtime.d.ts +8 -0
- package/ts/runtime.d.ts.map +1 -0
- package/ts/runtime.js +26 -0
- package/ts/runtime.js.map +1 -0
- package/ts/sys-abstraction.d.ts +36 -0
- package/ts/sys-abstraction.d.ts.map +1 -0
- package/ts/sys-abstraction.js +31 -0
- package/ts/sys-abstraction.js.map +1 -0
- package/ts/sys-env.d.ts +48 -0
- package/ts/sys-env.d.ts.map +1 -0
- package/ts/sys-env.js +176 -0
- package/ts/sys-env.js.map +1 -0
- package/ts/sys-env.test.d.ts +2 -0
- package/ts/sys-env.test.d.ts.map +1 -0
- package/ts/sys-env.test.js +51 -0
- package/ts/sys-env.test.js.map +1 -0
- package/ts/test/log-write-stream.d.ts +27 -0
- package/ts/test/log-write-stream.d.ts.map +1 -0
- package/ts/test/log-write-stream.js +74 -0
- package/ts/test/log-write-stream.js.map +1 -0
- package/ts/test/mock-logger.d.ts +14 -0
- package/ts/test/mock-logger.d.ts.map +1 -0
- package/ts/test/mock-logger.js +29 -0
- package/ts/test/mock-logger.js.map +1 -0
- package/ts/test/mock-logger.test.d.ts +2 -0
- package/ts/test/mock-logger.test.d.ts.map +1 -0
- package/ts/test/mock-logger.test.js +63 -0
- package/ts/test/mock-logger.test.js.map +1 -0
- package/ts/test/test-exit-handler.d.ts +2 -0
- package/ts/test/test-exit-handler.d.ts.map +1 -0
- package/ts/test/test-exit-handler.js +57 -0
- package/ts/test/test-exit-handler.js.map +1 -0
- package/ts/time.d.ts +13 -0
- package/ts/time.d.ts.map +1 -0
- package/ts/time.js +14 -0
- package/ts/time.js.map +1 -0
- package/ts/tracer.d.ts +59 -0
- package/ts/tracer.d.ts.map +1 -0
- package/ts/tracer.js +148 -0
- package/ts/tracer.js.map +1 -0
- package/ts/tracer.test.d.ts +2 -0
- package/ts/tracer.test.d.ts.map +1 -0
- package/ts/tracer.test.js +311 -0
- package/ts/tracer.test.js.map +1 -0
- package/ts/txt-en-decoder.d.ts +10 -0
- package/ts/txt-en-decoder.d.ts.map +1 -0
- package/ts/txt-en-decoder.js +15 -0
- package/ts/txt-en-decoder.js.map +1 -0
- package/ts/uri.d.ts +67 -0
- package/ts/uri.d.ts.map +1 -0
- package/ts/uri.js +283 -0
- package/ts/uri.js.map +1 -0
- package/ts/uri.test.d.ts +2 -0
- package/ts/uri.test.d.ts.map +1 -0
- package/ts/uri.test.js +119 -0
- package/ts/uri.test.js.map +1 -0
- package/ts/utils/console-write-stream.d.ts +21 -0
- package/ts/utils/console-write-stream.d.ts.map +1 -0
- package/ts/utils/console-write-stream.js +62 -0
- package/ts/utils/console-write-stream.js.map +1 -0
- package/ts/utils/fanout-write-stream.d.ts +12 -0
- package/ts/utils/fanout-write-stream.d.ts.map +1 -0
- package/ts/utils/fanout-write-stream.js +24 -0
- package/ts/utils/fanout-write-stream.js.map +1 -0
- package/ts/utils/index.d.ts +7 -0
- package/ts/utils/index.d.ts.map +1 -0
- package/ts/utils/index.js +7 -0
- package/ts/utils/index.js.map +1 -0
- package/ts/utils/rebuffer.d.ts +3 -0
- package/ts/utils/rebuffer.d.ts.map +1 -0
- package/ts/utils/rebuffer.js +60 -0
- package/ts/utils/rebuffer.js.map +1 -0
- package/ts/utils/rebuffer.test.d.ts +2 -0
- package/ts/utils/rebuffer.test.d.ts.map +1 -0
- package/ts/utils/rebuffer.test.js +77 -0
- package/ts/utils/rebuffer.test.js.map +1 -0
- package/ts/utils/stream-map.d.ts +9 -0
- package/ts/utils/stream-map.d.ts.map +1 -0
- package/ts/utils/stream-map.js +62 -0
- package/ts/utils/stream-map.js.map +1 -0
- package/ts/utils/stream-map.test.d.ts +2 -0
- package/ts/utils/stream-map.test.d.ts.map +1 -0
- package/ts/utils/stream-map.test.js +87 -0
- package/ts/utils/stream-map.test.js.map +1 -0
- package/ts/utils/stream-test-helper.d.ts +17 -0
- package/ts/utils/stream-test-helper.d.ts.map +1 -0
- package/ts/utils/stream-test-helper.js +37 -0
- package/ts/utils/stream-test-helper.js.map +1 -0
- package/ts/utils/stream2string.d.ts +3 -0
- package/ts/utils/stream2string.d.ts.map +1 -0
- package/ts/utils/stream2string.js +48 -0
- package/ts/utils/stream2string.js.map +1 -0
- package/ts/utils/stream2string.test.d.ts +2 -0
- package/ts/utils/stream2string.test.d.ts.map +1 -0
- package/ts/utils/stream2string.test.js +29 -0
- package/ts/utils/stream2string.test.js.map +1 -0
- package/ts/utils/string2stream.d.ts +4 -0
- package/ts/utils/string2stream.d.ts.map +1 -0
- package/ts/utils/string2stream.js +13 -0
- package/ts/utils/string2stream.js.map +1 -0
- package/ts/utils/string2stream.test.d.ts +2 -0
- package/ts/utils/string2stream.test.d.ts.map +1 -0
- package/ts/utils/string2stream.test.js +6 -0
- package/ts/utils/string2stream.test.js.map +1 -0
- package/ts/version.d.ts +2 -0
- package/ts/version.d.ts.map +1 -0
- package/ts/version.js +4 -0
- package/ts/version.js.map +1 -0
- package/ts/web/index.d.ts +2 -0
- package/ts/web/index.d.ts.map +1 -0
- package/ts/web/index.js +2 -0
- package/ts/web/index.js.map +1 -0
- package/ts/web/web-sys-abstraction.d.ts +4 -0
- package/ts/web/web-sys-abstraction.d.ts.map +1 -0
- package/ts/web/web-sys-abstraction.js +64 -0
- package/ts/web/web-sys-abstraction.js.map +1 -0
- package/txt-en-decoder-CZYJUju2.d.cts +11 -0
- package/txt-en-decoder-CZYJUju2.d.ts +11 -0
- package/utils/index.cjs +341 -0
- package/utils/index.cjs.map +1 -0
- package/utils/index.d.cts +2 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +32 -0
- package/utils/index.js.map +1 -0
- package/web/index.cjs +593 -0
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +6 -0
- package/web/index.d.ts +6 -0
- package/web/index.js +9 -0
- package/web/index.js.map +1 -0
package/index.js
ADDED
@@ -0,0 +1,1533 @@
|
|
1
|
+
import {
|
2
|
+
ConsoleWriterStream,
|
3
|
+
FanoutWriteStream,
|
4
|
+
utils_exports
|
5
|
+
} from "./chunk-7KFVMTOS.js";
|
6
|
+
import {
|
7
|
+
WebSysAbstraction
|
8
|
+
} from "./chunk-WMMUXBDX.js";
|
9
|
+
import {
|
10
|
+
BaseSysAbstraction,
|
11
|
+
BrowserEnvActions,
|
12
|
+
ConstTime,
|
13
|
+
EnvImpl,
|
14
|
+
Future,
|
15
|
+
IDMode,
|
16
|
+
IdService,
|
17
|
+
Keyed,
|
18
|
+
KeyedResolvOnce,
|
19
|
+
KeyedResolvSeq,
|
20
|
+
RandomMode,
|
21
|
+
RandomService,
|
22
|
+
ResolveOnce,
|
23
|
+
ResolveSeq,
|
24
|
+
StepTime,
|
25
|
+
String2TimeMode,
|
26
|
+
SysTime,
|
27
|
+
Time,
|
28
|
+
TimeFactory,
|
29
|
+
TimeMode,
|
30
|
+
TimeUnits,
|
31
|
+
WrapperSysAbstraction,
|
32
|
+
envFactory
|
33
|
+
} from "./chunk-Q65HLCNL.js";
|
34
|
+
import {
|
35
|
+
Utf8EnDecoder,
|
36
|
+
Utf8EnDecoderSingleton,
|
37
|
+
__spreadProps,
|
38
|
+
__spreadValues,
|
39
|
+
__yieldStar
|
40
|
+
} from "./chunk-GES3MUGV.js";
|
41
|
+
|
42
|
+
// src/logger-impl.ts
|
43
|
+
import YAML from "yaml";
|
44
|
+
|
45
|
+
// src/bin2text.ts
|
46
|
+
function bin2text(hex, lineFn, size = 0) {
|
47
|
+
const arr = new Uint8Array(hex.buffer, hex.byteOffset, hex.byteLength);
|
48
|
+
let cutted = " ";
|
49
|
+
if (size == 0) {
|
50
|
+
size = arr.length;
|
51
|
+
}
|
52
|
+
size = Math.min(size, arr.length);
|
53
|
+
const cols = 16;
|
54
|
+
for (let line = 0; line < size; line += cols) {
|
55
|
+
if (line + cols <= size || arr.length == size) {
|
56
|
+
} else {
|
57
|
+
line = arr.length - arr.length % cols;
|
58
|
+
size = arr.length;
|
59
|
+
cutted = ">>";
|
60
|
+
}
|
61
|
+
const l = [line.toString(16).padStart(4, "0"), cutted];
|
62
|
+
for (let col = 0; col < cols; col++) {
|
63
|
+
if (line + col < size) {
|
64
|
+
l.push(arr[line + col].toString(16).padStart(2, "0"));
|
65
|
+
} else {
|
66
|
+
l.push(" ");
|
67
|
+
}
|
68
|
+
l.push(" ");
|
69
|
+
}
|
70
|
+
for (let col = 0; col < cols; col++) {
|
71
|
+
if (line + col < size) {
|
72
|
+
const ch = arr[line + col];
|
73
|
+
l.push(ch >= 32 && ch < 127 ? String.fromCharCode(ch) : ".");
|
74
|
+
}
|
75
|
+
}
|
76
|
+
lineFn(l.join(""));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
function bin2string(hex, size = 0) {
|
80
|
+
const collector = [];
|
81
|
+
bin2text(
|
82
|
+
hex,
|
83
|
+
(line) => {
|
84
|
+
collector.push(line);
|
85
|
+
},
|
86
|
+
size
|
87
|
+
);
|
88
|
+
return collector.join("\n");
|
89
|
+
}
|
90
|
+
|
91
|
+
// src/logger.ts
|
92
|
+
var Level = /* @__PURE__ */ ((Level2) => {
|
93
|
+
Level2["WARN"] = "warn";
|
94
|
+
Level2["DEBUG"] = "debug";
|
95
|
+
Level2["INFO"] = "info";
|
96
|
+
Level2["ERROR"] = "error";
|
97
|
+
return Level2;
|
98
|
+
})(Level || {});
|
99
|
+
var LogValue = class {
|
100
|
+
constructor(fn) {
|
101
|
+
this.fn = fn;
|
102
|
+
}
|
103
|
+
value() {
|
104
|
+
return this.fn();
|
105
|
+
}
|
106
|
+
toJSON() {
|
107
|
+
return this.value();
|
108
|
+
}
|
109
|
+
};
|
110
|
+
function removeSelfRef(lineEnd) {
|
111
|
+
const cache = /* @__PURE__ */ new Set();
|
112
|
+
return function(key, value) {
|
113
|
+
if (typeof value === "object" && value !== null) {
|
114
|
+
if (cache.has(value)) return "...";
|
115
|
+
cache.add(value);
|
116
|
+
}
|
117
|
+
return lineEnd ? value + lineEnd : value;
|
118
|
+
};
|
119
|
+
}
|
120
|
+
function asyncLogValue(val) {
|
121
|
+
throw new Error("Not implemented");
|
122
|
+
}
|
123
|
+
function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
|
124
|
+
switch (typeof val) {
|
125
|
+
case "function":
|
126
|
+
return new LogValue(val);
|
127
|
+
case "string": {
|
128
|
+
try {
|
129
|
+
const ret = JSON.parse(val);
|
130
|
+
if (typeof ret === "object" && ret !== null) {
|
131
|
+
return logValue(ret, state);
|
132
|
+
}
|
133
|
+
} catch (e) {
|
134
|
+
if (val.match(/[\n\r]/)) {
|
135
|
+
const lines = val.trimEnd().split(/[\n\r]/);
|
136
|
+
return new LogValue(() => lines);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return new LogValue(() => val.toString());
|
140
|
+
}
|
141
|
+
case "number":
|
142
|
+
return new LogValue(() => val);
|
143
|
+
case "boolean":
|
144
|
+
return new LogValue(() => val);
|
145
|
+
case "object": {
|
146
|
+
if (ArrayBuffer.isView(val)) {
|
147
|
+
return logValue(bin2string(val, 512));
|
148
|
+
}
|
149
|
+
if (Array.isArray(val)) {
|
150
|
+
return new LogValue(() => val.map((v) => logValue(v).value()));
|
151
|
+
}
|
152
|
+
if (val === null) {
|
153
|
+
return new LogValue(() => "null");
|
154
|
+
}
|
155
|
+
if (state.has(val)) {
|
156
|
+
return new LogValue(() => "...");
|
157
|
+
}
|
158
|
+
state.add(val);
|
159
|
+
const res = {};
|
160
|
+
const typedVal = val;
|
161
|
+
for (const key in typedVal) {
|
162
|
+
const element = typedVal[key];
|
163
|
+
if (element instanceof LogValue) {
|
164
|
+
res[key] = element;
|
165
|
+
} else {
|
166
|
+
res[key] = logValue(element, state);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return new LogValue(() => res);
|
170
|
+
}
|
171
|
+
default:
|
172
|
+
if (!val) {
|
173
|
+
return new LogValue(() => "--Falsy--");
|
174
|
+
}
|
175
|
+
throw new Error(`Invalid type:${typeof val}`);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
function IsLogger(obj) {
|
179
|
+
return typeof obj === "object" && [
|
180
|
+
"Module",
|
181
|
+
"EnableLevel",
|
182
|
+
"DisableLevel",
|
183
|
+
"SetDebug",
|
184
|
+
"Str",
|
185
|
+
"Error",
|
186
|
+
"Warn",
|
187
|
+
"Debug",
|
188
|
+
"Log",
|
189
|
+
"WithLevel",
|
190
|
+
"Err",
|
191
|
+
"Info",
|
192
|
+
"Timestamp",
|
193
|
+
"Any",
|
194
|
+
"Dur",
|
195
|
+
"Uint64"
|
196
|
+
].map((fn) => typeof obj[fn] === "function").reduce((a, b) => a && b, true);
|
197
|
+
}
|
198
|
+
|
199
|
+
// src/result.ts
|
200
|
+
var Result = class _Result {
|
201
|
+
static Ok(t) {
|
202
|
+
return new ResultOK(t);
|
203
|
+
}
|
204
|
+
static Err(t) {
|
205
|
+
if (typeof t === "string") {
|
206
|
+
return new ResultError(new Error(t));
|
207
|
+
}
|
208
|
+
return new ResultError(t);
|
209
|
+
}
|
210
|
+
static Is(t) {
|
211
|
+
if (!t) {
|
212
|
+
return false;
|
213
|
+
}
|
214
|
+
if (t instanceof _Result) {
|
215
|
+
return true;
|
216
|
+
}
|
217
|
+
const rt = t;
|
218
|
+
if ([typeof rt.is_ok, typeof rt.is_err, typeof rt.unwrap, typeof rt.unwrap_err].every((x) => x === "function")) {
|
219
|
+
return true;
|
220
|
+
}
|
221
|
+
return false;
|
222
|
+
}
|
223
|
+
isOk() {
|
224
|
+
return this.is_ok();
|
225
|
+
}
|
226
|
+
isErr() {
|
227
|
+
return this.is_err();
|
228
|
+
}
|
229
|
+
Ok() {
|
230
|
+
return this.unwrap();
|
231
|
+
}
|
232
|
+
Err() {
|
233
|
+
return this.unwrap_err();
|
234
|
+
}
|
235
|
+
};
|
236
|
+
var ResultOK = class extends Result {
|
237
|
+
constructor(t) {
|
238
|
+
super();
|
239
|
+
this._t = t;
|
240
|
+
}
|
241
|
+
is_ok() {
|
242
|
+
return true;
|
243
|
+
}
|
244
|
+
is_err() {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
unwrap_err() {
|
248
|
+
throw new Error("Result is Ok");
|
249
|
+
}
|
250
|
+
unwrap() {
|
251
|
+
return this._t;
|
252
|
+
}
|
253
|
+
};
|
254
|
+
var ResultError = class extends Result {
|
255
|
+
constructor(t) {
|
256
|
+
super();
|
257
|
+
this._error = t;
|
258
|
+
}
|
259
|
+
is_ok() {
|
260
|
+
return false;
|
261
|
+
}
|
262
|
+
is_err() {
|
263
|
+
return true;
|
264
|
+
}
|
265
|
+
unwrap() {
|
266
|
+
throw new Error(`Result is Err: ${this._error}`);
|
267
|
+
}
|
268
|
+
unwrap_err() {
|
269
|
+
return this._error;
|
270
|
+
}
|
271
|
+
};
|
272
|
+
function exception2Result(fn) {
|
273
|
+
try {
|
274
|
+
const res = fn();
|
275
|
+
if (res instanceof Promise) {
|
276
|
+
return res.then((value) => Result.Ok(value)).catch((e) => Result.Err(e));
|
277
|
+
}
|
278
|
+
return Result.Ok(res);
|
279
|
+
} catch (e) {
|
280
|
+
return Result.Err(e);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
// src/uri.ts
|
285
|
+
function falsy2undef(value) {
|
286
|
+
return value === void 0 || value === null ? void 0 : value;
|
287
|
+
}
|
288
|
+
function ensureURLWithDefaultProto(url, defaultProtocol) {
|
289
|
+
if (!url) {
|
290
|
+
return new MutableURL(`${defaultProtocol}//`);
|
291
|
+
}
|
292
|
+
if (typeof url === "string") {
|
293
|
+
try {
|
294
|
+
return new MutableURL(url);
|
295
|
+
} catch (e) {
|
296
|
+
return new MutableURL(`${defaultProtocol}//${url}`);
|
297
|
+
}
|
298
|
+
} else {
|
299
|
+
return new MutableURL(url.toString());
|
300
|
+
}
|
301
|
+
}
|
302
|
+
function isURL(value) {
|
303
|
+
return value instanceof URL || !!value && typeof value.searchParams === "object" && typeof value.searchParams.sort === "function" && typeof value.hash === "string";
|
304
|
+
}
|
305
|
+
var MutableURL = class _MutableURL extends URL {
|
306
|
+
constructor(urlStr) {
|
307
|
+
super("defect://does.not.exist");
|
308
|
+
const partedURL = urlStr.split(":");
|
309
|
+
this._hasHostpart = protocols.has(partedURL[0]);
|
310
|
+
let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
|
311
|
+
if (!this._hasHostpart) {
|
312
|
+
const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
|
313
|
+
hostPartUrl = hostPartUrl.replace(/http:\/\//, `http://localhost/${pathname}`);
|
314
|
+
}
|
315
|
+
try {
|
316
|
+
this._sysURL = new URL(hostPartUrl);
|
317
|
+
} catch (ie) {
|
318
|
+
const e = ie;
|
319
|
+
e.message = `${e.message} for URL: ${urlStr}`;
|
320
|
+
throw e;
|
321
|
+
}
|
322
|
+
this._protocol = `${partedURL[0]}:`;
|
323
|
+
if (this._hasHostpart) {
|
324
|
+
this._pathname = this._sysURL.pathname;
|
325
|
+
} else {
|
326
|
+
this._pathname = urlStr.replace(new RegExp(`^${this._protocol}//`), "").replace(/[#?].*$/, "");
|
327
|
+
}
|
328
|
+
this.hash = this._sysURL.hash;
|
329
|
+
}
|
330
|
+
clone() {
|
331
|
+
return new _MutableURL(this.toString());
|
332
|
+
}
|
333
|
+
get host() {
|
334
|
+
if (!this._hasHostpart) {
|
335
|
+
throw new Error(
|
336
|
+
`you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(protocols.keys()))}`
|
337
|
+
);
|
338
|
+
}
|
339
|
+
return this._sysURL.host;
|
340
|
+
}
|
341
|
+
get port() {
|
342
|
+
if (!this._hasHostpart) {
|
343
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
|
344
|
+
}
|
345
|
+
return this._sysURL.port;
|
346
|
+
}
|
347
|
+
set port(p) {
|
348
|
+
if (!this._hasHostpart) {
|
349
|
+
throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
|
350
|
+
}
|
351
|
+
this._sysURL.port = p;
|
352
|
+
}
|
353
|
+
get hostname() {
|
354
|
+
if (!this._hasHostpart) {
|
355
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
|
356
|
+
}
|
357
|
+
return this._sysURL.hostname;
|
358
|
+
}
|
359
|
+
set hostname(h) {
|
360
|
+
if (!this._hasHostpart) {
|
361
|
+
throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
|
362
|
+
}
|
363
|
+
this._sysURL.hostname = h;
|
364
|
+
}
|
365
|
+
set pathname(p) {
|
366
|
+
this._pathname = p;
|
367
|
+
}
|
368
|
+
get pathname() {
|
369
|
+
return this._pathname;
|
370
|
+
}
|
371
|
+
get protocol() {
|
372
|
+
return this._protocol;
|
373
|
+
}
|
374
|
+
set protocol(p) {
|
375
|
+
if (!p.endsWith(":")) {
|
376
|
+
p = `${p}:`;
|
377
|
+
}
|
378
|
+
this._protocol = p;
|
379
|
+
}
|
380
|
+
get searchParams() {
|
381
|
+
return this._sysURL.searchParams;
|
382
|
+
}
|
383
|
+
toString() {
|
384
|
+
let search = "";
|
385
|
+
if (this._sysURL.searchParams.size) {
|
386
|
+
for (const [key, value] of Array.from(this._sysURL.searchParams.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
387
|
+
search += `${!search.length ? "?" : "&"}${key}=${encodeURIComponent(value)}`;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
let hostpart = "";
|
391
|
+
if (this._hasHostpart) {
|
392
|
+
hostpart = this._sysURL.hostname;
|
393
|
+
if (this._sysURL.port) {
|
394
|
+
hostpart += `:${this._sysURL.port}`;
|
395
|
+
}
|
396
|
+
if (!this._pathname.startsWith("/")) {
|
397
|
+
hostpart += "/";
|
398
|
+
}
|
399
|
+
}
|
400
|
+
return `${this._protocol}//${hostpart}${this._pathname}${search}`;
|
401
|
+
}
|
402
|
+
};
|
403
|
+
function from(fac, strURLUri, defaultProtocol) {
|
404
|
+
switch (typeof falsy2undef(strURLUri)) {
|
405
|
+
case "undefined":
|
406
|
+
return fac(new MutableURL(`${defaultProtocol}///`));
|
407
|
+
case "string":
|
408
|
+
return fac(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
|
409
|
+
case "object":
|
410
|
+
if (BuildURI.is(strURLUri)) {
|
411
|
+
return fac(new MutableURL(strURLUri._url.toString()));
|
412
|
+
} else if (URI.is(strURLUri)) {
|
413
|
+
return fac(new MutableURL(strURLUri._url.toString()));
|
414
|
+
} else if (isURL(strURLUri)) {
|
415
|
+
return fac(new MutableURL(strURLUri.toString()));
|
416
|
+
}
|
417
|
+
throw new Error(`unknown object type: ${strURLUri}`);
|
418
|
+
default:
|
419
|
+
throw new Error(`Invalid argument: ${typeof strURLUri}`);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
var BuildURI = class _BuildURI {
|
423
|
+
// pathname needs this
|
424
|
+
constructor(url) {
|
425
|
+
this._url = url;
|
426
|
+
}
|
427
|
+
static is(value) {
|
428
|
+
return value instanceof _BuildURI || !!value && typeof value.delParam === "function" && typeof value.setParam === "function";
|
429
|
+
}
|
430
|
+
static from(strURLUri, defaultProtocol = "file:") {
|
431
|
+
return from((url) => new _BuildURI(url), strURLUri, defaultProtocol);
|
432
|
+
}
|
433
|
+
port(p) {
|
434
|
+
this._url.port = p;
|
435
|
+
return this;
|
436
|
+
}
|
437
|
+
hostname(h) {
|
438
|
+
this._url.hostname = h;
|
439
|
+
return this;
|
440
|
+
}
|
441
|
+
// password(p: string) {
|
442
|
+
// this._url.password = p;
|
443
|
+
// return this;
|
444
|
+
// }
|
445
|
+
// port(p: string) {
|
446
|
+
// this._url.port = p;
|
447
|
+
// return this;
|
448
|
+
// }
|
449
|
+
// username(u: string) {
|
450
|
+
// this._url.username = u;
|
451
|
+
// return this;
|
452
|
+
// }
|
453
|
+
// search(s: string) {
|
454
|
+
// this._url.search = s;
|
455
|
+
// return this;
|
456
|
+
// }
|
457
|
+
protocol(p) {
|
458
|
+
this._url.protocol = p;
|
459
|
+
return this;
|
460
|
+
}
|
461
|
+
pathname(p) {
|
462
|
+
this._url.pathname = p;
|
463
|
+
return this;
|
464
|
+
}
|
465
|
+
// hash(h: string) {
|
466
|
+
// this._url.hash = h;
|
467
|
+
// return this;
|
468
|
+
// }
|
469
|
+
// host(h: string) {
|
470
|
+
// this._url.host = h;
|
471
|
+
// return this;
|
472
|
+
// }
|
473
|
+
delParam(key) {
|
474
|
+
this._url.searchParams.delete(key);
|
475
|
+
return this;
|
476
|
+
}
|
477
|
+
defParam(key, str) {
|
478
|
+
if (!this._url.searchParams.has(key)) {
|
479
|
+
this._url.searchParams.set(key, str);
|
480
|
+
}
|
481
|
+
return this;
|
482
|
+
}
|
483
|
+
setParam(key, str) {
|
484
|
+
this._url.searchParams.set(key, str);
|
485
|
+
return this;
|
486
|
+
}
|
487
|
+
hasParam(key) {
|
488
|
+
return this._url.searchParams.has(key);
|
489
|
+
}
|
490
|
+
getParam(key) {
|
491
|
+
return falsy2undef(this._url.searchParams.get(key));
|
492
|
+
}
|
493
|
+
toString() {
|
494
|
+
this._url.searchParams.sort();
|
495
|
+
return this._url.toString();
|
496
|
+
}
|
497
|
+
toJSON() {
|
498
|
+
return this.toString();
|
499
|
+
}
|
500
|
+
URI() {
|
501
|
+
return URI.from(this._url);
|
502
|
+
}
|
503
|
+
};
|
504
|
+
var protocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
|
505
|
+
var URI = class _URI {
|
506
|
+
static protocolHasHostpart(protocol) {
|
507
|
+
protocol = protocol.replace(/:$/, "");
|
508
|
+
protocols.add(protocol);
|
509
|
+
return () => {
|
510
|
+
protocols.delete(protocol);
|
511
|
+
};
|
512
|
+
}
|
513
|
+
// if no protocol is provided, default to file:
|
514
|
+
static merge(into, from2, defaultProtocol = "file:") {
|
515
|
+
const intoUrl = BuildURI.from(into, defaultProtocol);
|
516
|
+
const fromUrl = _URI.from(from2, defaultProtocol);
|
517
|
+
intoUrl.protocol(fromUrl.protocol);
|
518
|
+
const fPath = fromUrl.pathname;
|
519
|
+
if (!(fPath.length === 0 || fPath === "/" || fPath === "./")) {
|
520
|
+
intoUrl.pathname(fromUrl.pathname);
|
521
|
+
}
|
522
|
+
for (const [key, value] of fromUrl.getParams) {
|
523
|
+
intoUrl.setParam(key, value);
|
524
|
+
}
|
525
|
+
return intoUrl.URI();
|
526
|
+
}
|
527
|
+
static is(value) {
|
528
|
+
return value instanceof _URI || !!value && typeof value.asURL === "function" && typeof value.getParam === "function" && typeof value.hasParam === "function";
|
529
|
+
}
|
530
|
+
// if no protocol is provided, default to file:
|
531
|
+
static from(strURLUri, defaultProtocol = "file:") {
|
532
|
+
return from((url) => new _URI(url), strURLUri, defaultProtocol);
|
533
|
+
}
|
534
|
+
static fromResult(strURLUri, defaultProtocol = "file:") {
|
535
|
+
return exception2Result(() => from((url) => new _URI(url), strURLUri, defaultProtocol));
|
536
|
+
}
|
537
|
+
constructor(url) {
|
538
|
+
this._url = url.clone();
|
539
|
+
}
|
540
|
+
build() {
|
541
|
+
return BuildURI.from(this._url);
|
542
|
+
}
|
543
|
+
get hostname() {
|
544
|
+
return this._url.hostname;
|
545
|
+
}
|
546
|
+
// get password(): string {
|
547
|
+
// return this._url.password;
|
548
|
+
// }
|
549
|
+
get port() {
|
550
|
+
return this._url.port;
|
551
|
+
}
|
552
|
+
get host() {
|
553
|
+
return this._url.host;
|
554
|
+
}
|
555
|
+
// get username(): string {
|
556
|
+
// return this._url.username;
|
557
|
+
// }
|
558
|
+
// get search(): string {
|
559
|
+
// return this._url.search;
|
560
|
+
// }
|
561
|
+
get protocol() {
|
562
|
+
return this._url.protocol;
|
563
|
+
}
|
564
|
+
get pathname() {
|
565
|
+
return this._url.pathname;
|
566
|
+
}
|
567
|
+
// get hash(): string {
|
568
|
+
// return this._url.hash;
|
569
|
+
// }
|
570
|
+
// get host(): string {
|
571
|
+
// return this._url.host;
|
572
|
+
// }
|
573
|
+
get getParams() {
|
574
|
+
return this._url.searchParams.entries();
|
575
|
+
}
|
576
|
+
hasParam(key) {
|
577
|
+
return this._url.searchParams.has(key);
|
578
|
+
}
|
579
|
+
getParam(key) {
|
580
|
+
return falsy2undef(this._url.searchParams.get(key));
|
581
|
+
}
|
582
|
+
clone() {
|
583
|
+
return new _URI(this._url);
|
584
|
+
}
|
585
|
+
asURL() {
|
586
|
+
return this._url.clone();
|
587
|
+
}
|
588
|
+
toString() {
|
589
|
+
return this._url.toString();
|
590
|
+
}
|
591
|
+
toJSON() {
|
592
|
+
return this.toString();
|
593
|
+
}
|
594
|
+
};
|
595
|
+
|
596
|
+
// src/runtime.ts
|
597
|
+
function isSet(value, ref = globalThis) {
|
598
|
+
const [head, ...tail] = value.split(".");
|
599
|
+
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
600
|
+
if (tail.length <= 1) {
|
601
|
+
return true;
|
602
|
+
}
|
603
|
+
return isSet(tail.join("."), ref[head]);
|
604
|
+
}
|
605
|
+
return false;
|
606
|
+
}
|
607
|
+
function runtimeFn() {
|
608
|
+
const gt = globalThis;
|
609
|
+
const isReactNative = isSet("navigator.product") && typeof gt["navigator"] === "object" && gt["navigator"]["product"] === "ReactNative";
|
610
|
+
let isNodeIsh = false;
|
611
|
+
if (!isSet("Deno")) {
|
612
|
+
isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
613
|
+
}
|
614
|
+
const isDeno = isSet("Deno");
|
615
|
+
return {
|
616
|
+
isNodeIsh,
|
617
|
+
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
618
|
+
isDeno,
|
619
|
+
isReactNative
|
620
|
+
};
|
621
|
+
}
|
622
|
+
|
623
|
+
// src/log-writer-impl.ts
|
624
|
+
var LogWriterStream = class {
|
625
|
+
constructor(out) {
|
626
|
+
this._toFlush = [];
|
627
|
+
this._flushIsRunning = false;
|
628
|
+
this._flushDoneFns = [];
|
629
|
+
this._out = out;
|
630
|
+
}
|
631
|
+
write(encoded) {
|
632
|
+
const my = async () => {
|
633
|
+
try {
|
634
|
+
const writer = this._out.getWriter();
|
635
|
+
await writer.ready;
|
636
|
+
await writer.write(encoded);
|
637
|
+
await writer.releaseLock();
|
638
|
+
} catch (err) {
|
639
|
+
console.error("Chunk error:", err);
|
640
|
+
}
|
641
|
+
};
|
642
|
+
this._toFlush.push(my);
|
643
|
+
this._flush();
|
644
|
+
}
|
645
|
+
_flush(toFlush = void 0, done) {
|
646
|
+
if (done) {
|
647
|
+
this._flushDoneFns.push(done);
|
648
|
+
}
|
649
|
+
if (this._toFlush.length == 0) {
|
650
|
+
this._flushIsRunning = false;
|
651
|
+
this._flushDoneFns.forEach((fn) => fn());
|
652
|
+
this._flushDoneFns = [];
|
653
|
+
return;
|
654
|
+
}
|
655
|
+
if (!toFlush && this._toFlush.length == 1 && !this._flushIsRunning) {
|
656
|
+
this._flushIsRunning = true;
|
657
|
+
} else if (!toFlush) {
|
658
|
+
return;
|
659
|
+
}
|
660
|
+
const my = this._toFlush.shift();
|
661
|
+
my == null ? void 0 : my().finally(() => {
|
662
|
+
this._flush(this._toFlush);
|
663
|
+
});
|
664
|
+
}
|
665
|
+
};
|
666
|
+
|
667
|
+
// src/log-level-impl.ts
|
668
|
+
var LevelHandlerImpl = class {
|
669
|
+
constructor() {
|
670
|
+
this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
|
671
|
+
this._modules = /* @__PURE__ */ new Map();
|
672
|
+
this.isStackExposed = false;
|
673
|
+
}
|
674
|
+
enableLevel(level, ...modules) {
|
675
|
+
if (modules.length == 0) {
|
676
|
+
this._globalLevels.add(level);
|
677
|
+
return;
|
678
|
+
}
|
679
|
+
this.forModules(
|
680
|
+
level,
|
681
|
+
(p) => {
|
682
|
+
this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, level]));
|
683
|
+
},
|
684
|
+
...modules
|
685
|
+
);
|
686
|
+
}
|
687
|
+
disableLevel(level, ...modules) {
|
688
|
+
if (modules.length == 0) {
|
689
|
+
this._globalLevels.delete(level);
|
690
|
+
return;
|
691
|
+
}
|
692
|
+
this.forModules(
|
693
|
+
level,
|
694
|
+
(p) => {
|
695
|
+
this._modules.delete(p);
|
696
|
+
},
|
697
|
+
...modules
|
698
|
+
);
|
699
|
+
}
|
700
|
+
setExposeStack(enable) {
|
701
|
+
this.isStackExposed = !!enable;
|
702
|
+
}
|
703
|
+
forModules(level, fnAction, ...modules) {
|
704
|
+
for (const m of modules.flat()) {
|
705
|
+
if (typeof m !== "string") {
|
706
|
+
continue;
|
707
|
+
}
|
708
|
+
const parts = m.split(",").map((s) => s.trim()).filter((s) => s.length);
|
709
|
+
for (const p of parts) {
|
710
|
+
fnAction(p);
|
711
|
+
}
|
712
|
+
}
|
713
|
+
}
|
714
|
+
setDebug(...modules) {
|
715
|
+
this.forModules(
|
716
|
+
"debug" /* DEBUG */,
|
717
|
+
(p) => {
|
718
|
+
this._modules.set(p, /* @__PURE__ */ new Set([...this._globalLevels, "debug" /* DEBUG */]));
|
719
|
+
},
|
720
|
+
...modules
|
721
|
+
);
|
722
|
+
}
|
723
|
+
isEnabled(ilevel, module) {
|
724
|
+
const level = ilevel;
|
725
|
+
if (typeof module === "string") {
|
726
|
+
const levels = this._modules.get(module);
|
727
|
+
if (levels && levels.has(level)) {
|
728
|
+
return true;
|
729
|
+
}
|
730
|
+
}
|
731
|
+
const wlevel = this._modules.get("*");
|
732
|
+
if (wlevel && typeof level === "string") {
|
733
|
+
if (wlevel.has(level)) {
|
734
|
+
return true;
|
735
|
+
}
|
736
|
+
}
|
737
|
+
if (typeof level !== "string") {
|
738
|
+
return true;
|
739
|
+
}
|
740
|
+
return this._globalLevels.has(level);
|
741
|
+
}
|
742
|
+
};
|
743
|
+
var levelSingleton = new LevelHandlerImpl();
|
744
|
+
function LevelHandlerSingleton() {
|
745
|
+
return levelSingleton;
|
746
|
+
}
|
747
|
+
|
748
|
+
// src/logger-impl.ts
|
749
|
+
function getLen(value) {
|
750
|
+
if (Array.isArray(value)) {
|
751
|
+
return logValue(() => value.length);
|
752
|
+
} else if (typeof value === "string") {
|
753
|
+
return logValue(() => value.length);
|
754
|
+
} else if (typeof value === "object" && value !== null) {
|
755
|
+
if (typeof value.size === "number") {
|
756
|
+
return logValue(() => value.size);
|
757
|
+
} else if (typeof value.length === "number") {
|
758
|
+
return logValue(() => value.length);
|
759
|
+
}
|
760
|
+
return logValue(() => Object.keys(value).length);
|
761
|
+
}
|
762
|
+
return logValue(() => -1);
|
763
|
+
}
|
764
|
+
function hash(value) {
|
765
|
+
return "not implemented";
|
766
|
+
}
|
767
|
+
function toLogValue(lop) {
|
768
|
+
if (lop && typeof lop.then === "function") {
|
769
|
+
throw new Error("async logValue Not implemented");
|
770
|
+
}
|
771
|
+
return lop;
|
772
|
+
}
|
773
|
+
var JSONFormatter = class {
|
774
|
+
constructor(txtEnde, space) {
|
775
|
+
this._txtEnDe = txtEnde;
|
776
|
+
this._space = space;
|
777
|
+
}
|
778
|
+
format(attr) {
|
779
|
+
return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
|
780
|
+
}
|
781
|
+
};
|
782
|
+
var YAMLFormatter = class {
|
783
|
+
constructor(txtEnde, space) {
|
784
|
+
this._txtEnDe = txtEnde;
|
785
|
+
this._space = space;
|
786
|
+
}
|
787
|
+
format(attr) {
|
788
|
+
return this._txtEnDe.encode("---\n" + YAML.stringify(attr, removeSelfRef(), this._space) + "\n");
|
789
|
+
}
|
790
|
+
};
|
791
|
+
var LoggerImpl = class _LoggerImpl {
|
792
|
+
// readonly _id: string = "logger-" + Math.random().toString(36)
|
793
|
+
constructor(params) {
|
794
|
+
this._attributes = {};
|
795
|
+
if (!params) {
|
796
|
+
params = {};
|
797
|
+
}
|
798
|
+
if (!params.sys) {
|
799
|
+
this._sys = WebSysAbstraction();
|
800
|
+
} else {
|
801
|
+
this._sys = params.sys;
|
802
|
+
}
|
803
|
+
if (!params.txtEnDe) {
|
804
|
+
this._txtEnDe = Utf8EnDecoderSingleton();
|
805
|
+
} else {
|
806
|
+
this._txtEnDe = params.txtEnDe;
|
807
|
+
}
|
808
|
+
if (!params.formatter) {
|
809
|
+
this._formatter = new JSONFormatter(this._txtEnDe);
|
810
|
+
} else {
|
811
|
+
this._formatter = params.formatter;
|
812
|
+
}
|
813
|
+
if (params.logWriter) {
|
814
|
+
this._logWriter = params.logWriter;
|
815
|
+
} else {
|
816
|
+
if (!params.out) {
|
817
|
+
const rt = runtimeFn();
|
818
|
+
let stream;
|
819
|
+
if (rt.isBrowser) {
|
820
|
+
stream = new ConsoleWriterStream();
|
821
|
+
} else {
|
822
|
+
if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
|
823
|
+
stream = this._sys.Stdout();
|
824
|
+
} else {
|
825
|
+
throw new Error("No output defined for runtime");
|
826
|
+
}
|
827
|
+
}
|
828
|
+
this._logWriter = new LogWriterStream(stream);
|
829
|
+
} else {
|
830
|
+
this._logWriter = new LogWriterStream(params.out);
|
831
|
+
}
|
832
|
+
}
|
833
|
+
if (!params.withAttributes) {
|
834
|
+
this._withAttributes = {};
|
835
|
+
} else {
|
836
|
+
this._withAttributes = __spreadValues({}, params.withAttributes);
|
837
|
+
}
|
838
|
+
this._attributes = __spreadValues({}, this._withAttributes);
|
839
|
+
if (params.levelHandler) {
|
840
|
+
this._levelHandler = params.levelHandler;
|
841
|
+
} else {
|
842
|
+
this._levelHandler = LevelHandlerSingleton();
|
843
|
+
}
|
844
|
+
}
|
845
|
+
TxtEnDe() {
|
846
|
+
return this._txtEnDe;
|
847
|
+
}
|
848
|
+
Attributes() {
|
849
|
+
return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
|
850
|
+
}
|
851
|
+
SetExposeStack(enable) {
|
852
|
+
this._levelHandler.setExposeStack(enable);
|
853
|
+
return this;
|
854
|
+
}
|
855
|
+
EnableLevel(level, ...modules) {
|
856
|
+
this._levelHandler.enableLevel(level, ...modules);
|
857
|
+
return this;
|
858
|
+
}
|
859
|
+
DisableLevel(level, ...modules) {
|
860
|
+
this._levelHandler.disableLevel(level, ...modules);
|
861
|
+
return this;
|
862
|
+
}
|
863
|
+
Module(key) {
|
864
|
+
this._attributes["module"] = logValue(key);
|
865
|
+
this._withAttributes["module"] = logValue(key);
|
866
|
+
return this;
|
867
|
+
}
|
868
|
+
// if the string is "*" it will enable for all modules
|
869
|
+
SetDebug(...modules) {
|
870
|
+
this._levelHandler.setDebug(...modules);
|
871
|
+
return this;
|
872
|
+
}
|
873
|
+
SetFormatter(formatter) {
|
874
|
+
this._formatter = formatter;
|
875
|
+
return this;
|
876
|
+
}
|
877
|
+
Timestamp() {
|
878
|
+
this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
|
879
|
+
return this;
|
880
|
+
}
|
881
|
+
Warn() {
|
882
|
+
this._attributes["level"] = logValue("warn" /* WARN */);
|
883
|
+
return this;
|
884
|
+
}
|
885
|
+
Log() {
|
886
|
+
return this;
|
887
|
+
}
|
888
|
+
Debug() {
|
889
|
+
this._attributes["level"] = logValue("debug" /* DEBUG */);
|
890
|
+
return this;
|
891
|
+
}
|
892
|
+
Error() {
|
893
|
+
this._attributes["level"] = logValue("error" /* ERROR */);
|
894
|
+
return this;
|
895
|
+
}
|
896
|
+
Info() {
|
897
|
+
this._attributes["level"] = logValue("info" /* INFO */);
|
898
|
+
return this;
|
899
|
+
}
|
900
|
+
Err(err) {
|
901
|
+
var _a;
|
902
|
+
if (Result.Is(err)) {
|
903
|
+
if (err.isOk()) {
|
904
|
+
this.Result("noerror", err);
|
905
|
+
} else {
|
906
|
+
this.Result("error", err);
|
907
|
+
}
|
908
|
+
} else if (err instanceof Error) {
|
909
|
+
this._attributes["error"] = logValue(err.message);
|
910
|
+
if (this._levelHandler.isStackExposed) {
|
911
|
+
this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
|
912
|
+
}
|
913
|
+
} else {
|
914
|
+
this._attributes["error"] = logValue("" + err);
|
915
|
+
}
|
916
|
+
return this;
|
917
|
+
}
|
918
|
+
WithLevel(l) {
|
919
|
+
this._attributes["level"] = logValue(l);
|
920
|
+
return this;
|
921
|
+
}
|
922
|
+
Ref(key, action) {
|
923
|
+
if (typeof action === "function") {
|
924
|
+
this._attributes[key] = logValue(action);
|
925
|
+
} else if (typeof action.toString === "function") {
|
926
|
+
this._attributes[key] = logValue(() => action.toString());
|
927
|
+
} else {
|
928
|
+
this._attributes[key] = logValue("INVALID REF");
|
929
|
+
}
|
930
|
+
return this;
|
931
|
+
}
|
932
|
+
Bool(key, value) {
|
933
|
+
this._attributes[key] = logValue(!!value);
|
934
|
+
return this;
|
935
|
+
}
|
936
|
+
Result(key, res) {
|
937
|
+
if (res.isOk()) {
|
938
|
+
this._attributes[key] = logValue(res.Ok());
|
939
|
+
} else {
|
940
|
+
this.Err(res.Err());
|
941
|
+
}
|
942
|
+
return this;
|
943
|
+
}
|
944
|
+
Len(value, key = "len") {
|
945
|
+
this._attributes[key] = getLen(value);
|
946
|
+
return this;
|
947
|
+
}
|
948
|
+
Hash(value, key = "hash") {
|
949
|
+
this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
|
950
|
+
return this;
|
951
|
+
}
|
952
|
+
Url(url, key = "url") {
|
953
|
+
this.Ref(key, () => URI.from(url).toString());
|
954
|
+
return this;
|
955
|
+
}
|
956
|
+
Str(key, value) {
|
957
|
+
this._attributes[key] = logValue(value);
|
958
|
+
return this;
|
959
|
+
}
|
960
|
+
Any(key, value) {
|
961
|
+
this._attributes[key] = logValue(value);
|
962
|
+
return this;
|
963
|
+
}
|
964
|
+
Dur(key, nsec) {
|
965
|
+
this._attributes[key] = logValue(`${nsec}ms`);
|
966
|
+
return this;
|
967
|
+
}
|
968
|
+
Uint64(key, value) {
|
969
|
+
this._attributes[key] = logValue(value);
|
970
|
+
return this;
|
971
|
+
}
|
972
|
+
Int(key, value) {
|
973
|
+
return this.Uint64(key, value);
|
974
|
+
}
|
975
|
+
async Flush() {
|
976
|
+
return new Promise((resolve) => {
|
977
|
+
this._logWriter._flush(void 0, resolve);
|
978
|
+
});
|
979
|
+
}
|
980
|
+
With() {
|
981
|
+
return new WithLoggerBuilder(
|
982
|
+
new _LoggerImpl({
|
983
|
+
logWriter: this._logWriter,
|
984
|
+
sys: this._sys,
|
985
|
+
levelHandler: this._levelHandler,
|
986
|
+
formatter: this._formatter,
|
987
|
+
withAttributes: __spreadValues({
|
988
|
+
module: this._attributes["module"]
|
989
|
+
}, this._withAttributes)
|
990
|
+
})
|
991
|
+
);
|
992
|
+
}
|
993
|
+
_resetAttributes(fn) {
|
994
|
+
const ret = fn();
|
995
|
+
Object.keys(this._attributes).forEach((key) => {
|
996
|
+
delete this._attributes[key];
|
997
|
+
});
|
998
|
+
Object.assign(this._attributes, this._withAttributes);
|
999
|
+
return ret;
|
1000
|
+
}
|
1001
|
+
Msg(...args) {
|
1002
|
+
const fnError = this._resetAttributes(() => {
|
1003
|
+
var _a, _b;
|
1004
|
+
const doWrite = this._levelHandler.isEnabled(
|
1005
|
+
(_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
|
1006
|
+
(_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
|
1007
|
+
);
|
1008
|
+
this._attributes["msg"] = logValue(args.join(" "));
|
1009
|
+
const msg = this._attributes["msg"].value();
|
1010
|
+
if (typeof msg === "string" && !msg.trim().length) {
|
1011
|
+
delete this._attributes["msg"];
|
1012
|
+
}
|
1013
|
+
let fnRet = () => this._formatter.format(__spreadValues({}, this._attributes));
|
1014
|
+
if (doWrite) {
|
1015
|
+
const encoded = fnRet();
|
1016
|
+
this._logWriter.write(encoded);
|
1017
|
+
fnRet = () => encoded;
|
1018
|
+
}
|
1019
|
+
return fnRet;
|
1020
|
+
});
|
1021
|
+
return {
|
1022
|
+
AsError: () => new Error(this._txtEnDe.decode(fnError()))
|
1023
|
+
};
|
1024
|
+
}
|
1025
|
+
};
|
1026
|
+
var WithLoggerBuilder = class {
|
1027
|
+
constructor(li) {
|
1028
|
+
this._li = li;
|
1029
|
+
}
|
1030
|
+
TxtEnDe() {
|
1031
|
+
return this._li.TxtEnDe();
|
1032
|
+
}
|
1033
|
+
Logger() {
|
1034
|
+
Object.assign(this._li._withAttributes, this._li._attributes);
|
1035
|
+
return this._li;
|
1036
|
+
}
|
1037
|
+
Attributes() {
|
1038
|
+
return __spreadValues({}, this._li._attributes);
|
1039
|
+
}
|
1040
|
+
SetExposeStack(enable) {
|
1041
|
+
this._li._levelHandler.setExposeStack(enable);
|
1042
|
+
return this;
|
1043
|
+
}
|
1044
|
+
SetFormatter(fmt) {
|
1045
|
+
this._li.SetFormatter(fmt);
|
1046
|
+
return this;
|
1047
|
+
}
|
1048
|
+
EnableLevel(level, ...modules) {
|
1049
|
+
this._li._levelHandler.enableLevel(level, ...modules);
|
1050
|
+
return this;
|
1051
|
+
}
|
1052
|
+
DisableLevel(level, ...modules) {
|
1053
|
+
this._li._levelHandler.enableLevel(level, ...modules);
|
1054
|
+
return this;
|
1055
|
+
}
|
1056
|
+
Module(key) {
|
1057
|
+
this._li.Module(key);
|
1058
|
+
return this;
|
1059
|
+
}
|
1060
|
+
SetDebug(...modules) {
|
1061
|
+
this._li.SetDebug(...modules);
|
1062
|
+
return this;
|
1063
|
+
}
|
1064
|
+
Str(key, value) {
|
1065
|
+
this._li.Str(key, value);
|
1066
|
+
return this;
|
1067
|
+
}
|
1068
|
+
Len(value, key) {
|
1069
|
+
this._li.Len(value, key);
|
1070
|
+
return this;
|
1071
|
+
}
|
1072
|
+
Hash(value, key) {
|
1073
|
+
this._li.Hash(value, key);
|
1074
|
+
return this;
|
1075
|
+
}
|
1076
|
+
Ref(key, action) {
|
1077
|
+
this._li.Ref(key, action);
|
1078
|
+
return this;
|
1079
|
+
}
|
1080
|
+
Bool(key, value) {
|
1081
|
+
this._li.Bool(key, value);
|
1082
|
+
return this;
|
1083
|
+
}
|
1084
|
+
Result(key, res) {
|
1085
|
+
this._li.Result(key, res);
|
1086
|
+
return this;
|
1087
|
+
}
|
1088
|
+
Url(url, key) {
|
1089
|
+
this._li.Url(url, key);
|
1090
|
+
return this;
|
1091
|
+
}
|
1092
|
+
Int(key, value) {
|
1093
|
+
this._li.Int(key, value);
|
1094
|
+
return this;
|
1095
|
+
}
|
1096
|
+
Log() {
|
1097
|
+
this._li.Log();
|
1098
|
+
return this;
|
1099
|
+
}
|
1100
|
+
WithLevel(level) {
|
1101
|
+
this._li.WithLevel(level);
|
1102
|
+
return this;
|
1103
|
+
}
|
1104
|
+
Error() {
|
1105
|
+
this._li.Error();
|
1106
|
+
return this;
|
1107
|
+
}
|
1108
|
+
Warn() {
|
1109
|
+
this._li.Error();
|
1110
|
+
return this;
|
1111
|
+
}
|
1112
|
+
Debug() {
|
1113
|
+
this._li.Debug();
|
1114
|
+
return this;
|
1115
|
+
}
|
1116
|
+
Err(err) {
|
1117
|
+
this._li.Err(err);
|
1118
|
+
return this;
|
1119
|
+
}
|
1120
|
+
Info() {
|
1121
|
+
this._li.Info();
|
1122
|
+
return this;
|
1123
|
+
}
|
1124
|
+
Timestamp() {
|
1125
|
+
this._li.Timestamp();
|
1126
|
+
return this;
|
1127
|
+
}
|
1128
|
+
Any(key, value) {
|
1129
|
+
this._li.Any(key, value);
|
1130
|
+
return this;
|
1131
|
+
}
|
1132
|
+
Dur(key, nsec) {
|
1133
|
+
this._li.Dur(key, nsec);
|
1134
|
+
return this;
|
1135
|
+
}
|
1136
|
+
Uint64(key, value) {
|
1137
|
+
this._li.Uint64(key, value);
|
1138
|
+
return this;
|
1139
|
+
}
|
1140
|
+
};
|
1141
|
+
|
1142
|
+
// src/test/log-write-stream.ts
|
1143
|
+
var LogWriteStream = class {
|
1144
|
+
constructor(bufferArr) {
|
1145
|
+
this._resolveClosed = new Future();
|
1146
|
+
this.closed = this._resolveClosed.asPromise();
|
1147
|
+
this.desiredSize = null;
|
1148
|
+
this.ready = Promise.resolve(void 0);
|
1149
|
+
this._bufferArr = bufferArr;
|
1150
|
+
}
|
1151
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
1152
|
+
abort(reason) {
|
1153
|
+
throw new Error("Method not implemented.");
|
1154
|
+
}
|
1155
|
+
async close() {
|
1156
|
+
await this.closed;
|
1157
|
+
return Promise.resolve(void 0);
|
1158
|
+
}
|
1159
|
+
releaseLock() {
|
1160
|
+
}
|
1161
|
+
async write(chunk) {
|
1162
|
+
if (chunk) {
|
1163
|
+
this._bufferArr.push(chunk);
|
1164
|
+
}
|
1165
|
+
return Promise.resolve(void 0);
|
1166
|
+
}
|
1167
|
+
};
|
1168
|
+
var LogCollector = class {
|
1169
|
+
constructor(pass, txtEnDe) {
|
1170
|
+
this.locked = false;
|
1171
|
+
this._bufferArr = [];
|
1172
|
+
this._pass = pass;
|
1173
|
+
this._txtEnDe = txtEnDe || Utf8EnDecoderSingleton();
|
1174
|
+
}
|
1175
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1176
|
+
abort(reason) {
|
1177
|
+
throw new Error("Method not implemented.");
|
1178
|
+
}
|
1179
|
+
async close() {
|
1180
|
+
if (this._writer) {
|
1181
|
+
const ret = await this._writer.close();
|
1182
|
+
this._writer = void 0;
|
1183
|
+
return ret;
|
1184
|
+
}
|
1185
|
+
return Promise.resolve(void 0);
|
1186
|
+
}
|
1187
|
+
getWriter() {
|
1188
|
+
if (!this._writer) {
|
1189
|
+
const dests = [new LogWriteStream(this._bufferArr)];
|
1190
|
+
if (this._pass) {
|
1191
|
+
dests.push(this._pass);
|
1192
|
+
}
|
1193
|
+
this._writer = new FanoutWriteStream(dests);
|
1194
|
+
}
|
1195
|
+
return this._writer;
|
1196
|
+
}
|
1197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1198
|
+
Logs(notJsonLine = false) {
|
1199
|
+
if (!this._writer) {
|
1200
|
+
return [];
|
1201
|
+
}
|
1202
|
+
const jsonNlStr = this._txtEnDe.decode(
|
1203
|
+
new Uint8Array(
|
1204
|
+
function* (res) {
|
1205
|
+
for (const x of res) {
|
1206
|
+
yield* __yieldStar(x);
|
1207
|
+
}
|
1208
|
+
}(this._bufferArr)
|
1209
|
+
)
|
1210
|
+
);
|
1211
|
+
if (!notJsonLine) {
|
1212
|
+
const splitStr = jsonNlStr.split("\n");
|
1213
|
+
const filterStr = splitStr.filter((a) => a.length);
|
1214
|
+
const mapStr = filterStr.map((a) => JSON.parse(a));
|
1215
|
+
return mapStr;
|
1216
|
+
}
|
1217
|
+
return jsonNlStr.split("\n").filter((a) => a.length);
|
1218
|
+
}
|
1219
|
+
};
|
1220
|
+
|
1221
|
+
// src/test/mock-logger.ts
|
1222
|
+
function MockLogger(params) {
|
1223
|
+
const lc = new LogCollector(params == null ? void 0 : params.pass);
|
1224
|
+
let modNames = ["MockLogger"];
|
1225
|
+
if (typeof (params == null ? void 0 : params.moduleName) === "string") {
|
1226
|
+
modNames = [params == null ? void 0 : params.moduleName];
|
1227
|
+
} else if (Array.isArray(params == null ? void 0 : params.moduleName)) {
|
1228
|
+
modNames = [...params.moduleName, ...modNames];
|
1229
|
+
}
|
1230
|
+
const logger = new LoggerImpl({
|
1231
|
+
out: lc,
|
1232
|
+
sys: params == null ? void 0 : params.sys,
|
1233
|
+
levelHandler: new LevelHandlerImpl()
|
1234
|
+
}).With().Module(modNames[0]).Logger();
|
1235
|
+
if (!(params == null ? void 0 : params.disableDebug)) {
|
1236
|
+
logger.SetDebug(...modNames);
|
1237
|
+
}
|
1238
|
+
return {
|
1239
|
+
logCollector: lc,
|
1240
|
+
logger
|
1241
|
+
};
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
// src/option.ts
|
1245
|
+
var Option = class _Option {
|
1246
|
+
static Some(t) {
|
1247
|
+
return new Some(t);
|
1248
|
+
}
|
1249
|
+
static None() {
|
1250
|
+
return new None();
|
1251
|
+
}
|
1252
|
+
static Is(t) {
|
1253
|
+
return t instanceof _Option;
|
1254
|
+
}
|
1255
|
+
IsNone() {
|
1256
|
+
return this.is_none();
|
1257
|
+
}
|
1258
|
+
IsSome() {
|
1259
|
+
return this.is_some();
|
1260
|
+
}
|
1261
|
+
Unwrap() {
|
1262
|
+
return this.unwrap();
|
1263
|
+
}
|
1264
|
+
};
|
1265
|
+
var Some = class extends Option {
|
1266
|
+
constructor(_t) {
|
1267
|
+
super();
|
1268
|
+
this._t = _t;
|
1269
|
+
}
|
1270
|
+
is_none() {
|
1271
|
+
return false;
|
1272
|
+
}
|
1273
|
+
is_some() {
|
1274
|
+
return true;
|
1275
|
+
}
|
1276
|
+
unwrap() {
|
1277
|
+
return this._t;
|
1278
|
+
}
|
1279
|
+
};
|
1280
|
+
var None = class extends Option {
|
1281
|
+
is_none() {
|
1282
|
+
return true;
|
1283
|
+
}
|
1284
|
+
is_some() {
|
1285
|
+
return false;
|
1286
|
+
}
|
1287
|
+
unwrap() {
|
1288
|
+
throw new Error("None.unwrap");
|
1289
|
+
}
|
1290
|
+
};
|
1291
|
+
|
1292
|
+
// src/tracer.ts
|
1293
|
+
var Metric = class {
|
1294
|
+
constructor(path) {
|
1295
|
+
this.path = path;
|
1296
|
+
}
|
1297
|
+
set(value) {
|
1298
|
+
this.value = value;
|
1299
|
+
}
|
1300
|
+
add(value) {
|
1301
|
+
if (typeof value === "number") {
|
1302
|
+
if (this.value === void 0) {
|
1303
|
+
this.value = 0;
|
1304
|
+
}
|
1305
|
+
this.value = this.value + value;
|
1306
|
+
} else if (Array.isArray(value)) {
|
1307
|
+
if (!Array.isArray(this.value)) {
|
1308
|
+
this.value = [];
|
1309
|
+
}
|
1310
|
+
this.value.push(...value);
|
1311
|
+
} else {
|
1312
|
+
throw new Error("add only support number or array");
|
1313
|
+
}
|
1314
|
+
}
|
1315
|
+
};
|
1316
|
+
var Metrics = class {
|
1317
|
+
constructor(tracenode) {
|
1318
|
+
this.spanRefs = /* @__PURE__ */ new Map();
|
1319
|
+
this.tracenode = tracenode;
|
1320
|
+
this.map = tracenode.ctx.metrics;
|
1321
|
+
}
|
1322
|
+
toJSON() {
|
1323
|
+
const obj = {};
|
1324
|
+
for (const [key, value] of this.map) {
|
1325
|
+
obj[key] = value.value;
|
1326
|
+
}
|
1327
|
+
return obj;
|
1328
|
+
}
|
1329
|
+
get(ipath) {
|
1330
|
+
const path = ipath.replace(/[/]+/g, "/").trim();
|
1331
|
+
if (path.startsWith("/")) {
|
1332
|
+
if (path.slice(1).length === 0) {
|
1333
|
+
throw new Error(`Metrics path must contain value /:${path}`);
|
1334
|
+
}
|
1335
|
+
let metric = this.map.get(path);
|
1336
|
+
if (!metric) {
|
1337
|
+
metric = new Metric(path);
|
1338
|
+
this.map.set(path, metric);
|
1339
|
+
}
|
1340
|
+
this.spanRefs.set(path, metric);
|
1341
|
+
return metric;
|
1342
|
+
} else if (path.includes("/")) {
|
1343
|
+
throw new Error(`Metrics path must start with /:${path}`);
|
1344
|
+
}
|
1345
|
+
const rootPath = this.tracenode.getRootPath();
|
1346
|
+
return this.get(`${rootPath}/${path}`);
|
1347
|
+
}
|
1348
|
+
};
|
1349
|
+
var TraceNode = class _TraceNode {
|
1350
|
+
constructor(ctx) {
|
1351
|
+
this.childs = /* @__PURE__ */ new Map();
|
1352
|
+
this.invokations = [];
|
1353
|
+
this.spanId = ctx.spanId;
|
1354
|
+
this.ctx = ctx;
|
1355
|
+
this.metrics = new Metrics(this);
|
1356
|
+
}
|
1357
|
+
static root(time, logger) {
|
1358
|
+
return new _TraceNode({
|
1359
|
+
spanId: "root",
|
1360
|
+
time,
|
1361
|
+
logger,
|
1362
|
+
metrics: /* @__PURE__ */ new Map(),
|
1363
|
+
parent: void 0
|
1364
|
+
});
|
1365
|
+
}
|
1366
|
+
getRootPath(rpath = []) {
|
1367
|
+
if (!this.ctx.parent) {
|
1368
|
+
return "/" + rpath.reverse().join("/");
|
1369
|
+
}
|
1370
|
+
return this.ctx.parent.getRootPath(rpath.concat(this.ctx.spanId));
|
1371
|
+
}
|
1372
|
+
invokes() {
|
1373
|
+
const cleanCtx = __spreadValues({}, this.ctx);
|
1374
|
+
delete cleanCtx.parent;
|
1375
|
+
delete cleanCtx.time;
|
1376
|
+
delete cleanCtx.logger;
|
1377
|
+
delete cleanCtx.metrics;
|
1378
|
+
const spanRefs = this.metrics.toJSON.call({ map: this.metrics.spanRefs });
|
1379
|
+
const metricsRefs = Object.keys(spanRefs).length > 0 ? { metricRefs: spanRefs } : {};
|
1380
|
+
return __spreadValues({
|
1381
|
+
ctx: cleanCtx,
|
1382
|
+
invokations: this.invokations
|
1383
|
+
}, metricsRefs);
|
1384
|
+
}
|
1385
|
+
ctxWith(spanId, logger) {
|
1386
|
+
const ctx = __spreadProps(__spreadValues({}, this.ctx), {
|
1387
|
+
spanId
|
1388
|
+
});
|
1389
|
+
if (logger) {
|
1390
|
+
ctx.logger = logger;
|
1391
|
+
}
|
1392
|
+
return ctx;
|
1393
|
+
}
|
1394
|
+
// <V extends () => Promise<T> | T, T>(id: string, fn: V): ReturnType<V>
|
1395
|
+
span(inSpanId, fn) {
|
1396
|
+
let ctx;
|
1397
|
+
if (typeof inSpanId === "string") {
|
1398
|
+
ctx = __spreadProps(__spreadValues({}, this.ctx), {
|
1399
|
+
spanId: inSpanId,
|
1400
|
+
parent: this
|
1401
|
+
});
|
1402
|
+
} else {
|
1403
|
+
ctx = __spreadProps(__spreadValues(__spreadValues({}, this.ctx), inSpanId), {
|
1404
|
+
parent: this
|
1405
|
+
});
|
1406
|
+
}
|
1407
|
+
if (ctx.logger) {
|
1408
|
+
ctx = __spreadValues(__spreadValues({}, ctx), ctx.logger.Attributes());
|
1409
|
+
}
|
1410
|
+
const spanId = ctx.spanId;
|
1411
|
+
let spanTrace = this.childs.get(spanId);
|
1412
|
+
if (!spanTrace) {
|
1413
|
+
spanTrace = new _TraceNode(ctx);
|
1414
|
+
this.childs.set(spanId.toString(), spanTrace);
|
1415
|
+
}
|
1416
|
+
const invokation = {
|
1417
|
+
start: this.ctx.time.Now().getTime(),
|
1418
|
+
end: 0,
|
1419
|
+
result: "success"
|
1420
|
+
};
|
1421
|
+
spanTrace.invokations.push(invokation);
|
1422
|
+
try {
|
1423
|
+
const possiblePromise = fn(spanTrace);
|
1424
|
+
if (possiblePromise instanceof Promise) {
|
1425
|
+
return possiblePromise.then((v) => {
|
1426
|
+
return v;
|
1427
|
+
}).catch((e) => {
|
1428
|
+
invokation.result = "error";
|
1429
|
+
throw e;
|
1430
|
+
}).finally(() => {
|
1431
|
+
invokation.end = this.ctx.time.Now().getTime();
|
1432
|
+
});
|
1433
|
+
}
|
1434
|
+
invokation.end = this.ctx.time.Now().getTime();
|
1435
|
+
return possiblePromise;
|
1436
|
+
} catch (e) {
|
1437
|
+
invokation.result = "error";
|
1438
|
+
invokation.end = this.ctx.time.Now().getTime();
|
1439
|
+
throw e;
|
1440
|
+
}
|
1441
|
+
}
|
1442
|
+
};
|
1443
|
+
|
1444
|
+
// src/crypto.ts
|
1445
|
+
function randomBytes(size) {
|
1446
|
+
const bytes = new Uint8Array(size);
|
1447
|
+
if (size > 0) {
|
1448
|
+
crypto.getRandomValues(bytes);
|
1449
|
+
}
|
1450
|
+
return bytes;
|
1451
|
+
}
|
1452
|
+
function digestSHA256(data) {
|
1453
|
+
return Promise.resolve(crypto.subtle.digest("SHA-256", data));
|
1454
|
+
}
|
1455
|
+
function toCryptoRuntime(cryptoOpts = {}) {
|
1456
|
+
const runtime = {
|
1457
|
+
importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),
|
1458
|
+
exportKey: cryptoOpts.exportKey || crypto.subtle.exportKey.bind(crypto.subtle),
|
1459
|
+
encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),
|
1460
|
+
decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),
|
1461
|
+
randomBytes: cryptoOpts.randomBytes || randomBytes,
|
1462
|
+
digestSHA256: cryptoOpts.digestSHA256 || digestSHA256
|
1463
|
+
};
|
1464
|
+
return runtime;
|
1465
|
+
}
|
1466
|
+
|
1467
|
+
// src/version.ts
|
1468
|
+
var VERSION = Object.keys({
|
1469
|
+
__packageVersion__: "xxxx"
|
1470
|
+
})[0];
|
1471
|
+
export {
|
1472
|
+
BaseSysAbstraction,
|
1473
|
+
BrowserEnvActions,
|
1474
|
+
BuildURI,
|
1475
|
+
ConstTime,
|
1476
|
+
EnvImpl,
|
1477
|
+
Future,
|
1478
|
+
IDMode,
|
1479
|
+
IdService,
|
1480
|
+
IsLogger,
|
1481
|
+
JSONFormatter,
|
1482
|
+
Keyed,
|
1483
|
+
KeyedResolvOnce,
|
1484
|
+
KeyedResolvSeq,
|
1485
|
+
Level,
|
1486
|
+
LevelHandlerImpl,
|
1487
|
+
LevelHandlerSingleton,
|
1488
|
+
LogCollector,
|
1489
|
+
LogValue,
|
1490
|
+
LogWriteStream,
|
1491
|
+
LoggerImpl,
|
1492
|
+
Metric,
|
1493
|
+
Metrics,
|
1494
|
+
MockLogger,
|
1495
|
+
MutableURL,
|
1496
|
+
None,
|
1497
|
+
Option,
|
1498
|
+
RandomMode,
|
1499
|
+
RandomService,
|
1500
|
+
ResolveOnce,
|
1501
|
+
ResolveSeq,
|
1502
|
+
Result,
|
1503
|
+
ResultError,
|
1504
|
+
ResultOK,
|
1505
|
+
Some,
|
1506
|
+
StepTime,
|
1507
|
+
String2TimeMode,
|
1508
|
+
SysTime,
|
1509
|
+
Time,
|
1510
|
+
TimeFactory,
|
1511
|
+
TimeMode,
|
1512
|
+
TimeUnits,
|
1513
|
+
TraceNode,
|
1514
|
+
URI,
|
1515
|
+
Utf8EnDecoder,
|
1516
|
+
Utf8EnDecoderSingleton,
|
1517
|
+
VERSION,
|
1518
|
+
WrapperSysAbstraction,
|
1519
|
+
YAMLFormatter,
|
1520
|
+
asyncLogValue,
|
1521
|
+
bin2string,
|
1522
|
+
bin2text,
|
1523
|
+
envFactory,
|
1524
|
+
exception2Result,
|
1525
|
+
isURL,
|
1526
|
+
logValue,
|
1527
|
+
protocols,
|
1528
|
+
removeSelfRef,
|
1529
|
+
runtimeFn,
|
1530
|
+
toCryptoRuntime,
|
1531
|
+
utils_exports as utils
|
1532
|
+
};
|
1533
|
+
//# sourceMappingURL=index.js.map
|