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