@adviser/cement 0.2.34 → 0.2.36
Sign up to get free protection for your applications and to get access to all the features.
- package/{chunk-7KFVMTOS.js → chunk-USQXEZHL.js} +7 -7
- package/chunk-USQXEZHL.js.map +1 -0
- package/index.cjs +138 -38
- package/index.cjs.map +1 -1
- package/index.d.cts +39 -19
- package/index.d.ts +39 -19
- package/index.js +137 -36
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/jsr.json +1 -1
- package/src/logger-impl.ts +76 -18
- package/src/logger.ts +52 -21
- package/src/uri.ts +95 -28
- package/src/utils/console-write-stream.ts +6 -6
- package/src/utils/stripper.ts +11 -4
- package/ts/logger-impl.d.ts +8 -5
- package/ts/logger-impl.d.ts.map +1 -1
- package/ts/logger-impl.js +61 -8
- package/ts/logger-impl.js.map +1 -1
- package/ts/logger.d.ts +7 -6
- package/ts/logger.d.ts.map +1 -1
- package/ts/logger.js +23 -15
- package/ts/logger.js.map +1 -1
- package/ts/logger.test.js +205 -0
- package/ts/logger.test.js.map +1 -1
- package/ts/uri.d.ts +23 -7
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +48 -9
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +55 -1
- package/ts/uri.test.js.map +1 -1
- package/ts/utils/console-write-stream.js +6 -6
- package/ts/utils/console-write-stream.js.map +1 -1
- package/ts/utils/stripper.d.ts +1 -1
- package/ts/utils/stripper.d.ts.map +1 -1
- package/ts/utils/stripper.js +3 -0
- package/ts/utils/stripper.js.map +1 -1
- package/ts/utils/stripper.test.js +31 -0
- package/ts/utils/stripper.test.js.map +1 -1
- package/utils/index.cjs +6 -6
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +1 -1
- package/chunk-7KFVMTOS.js.map +0 -1
@@ -224,22 +224,22 @@ var ConsoleWriterStreamDefaultWriter = class {
|
|
224
224
|
this.closed = Promise.resolve(void 0);
|
225
225
|
}
|
226
226
|
async write(chunk) {
|
227
|
-
|
227
|
+
let strObj = this.decoder.decode(chunk).trimEnd();
|
228
228
|
let output = "log";
|
229
229
|
try {
|
230
|
-
|
231
|
-
output =
|
230
|
+
strObj = JSON.parse(strObj);
|
231
|
+
output = strObj.level;
|
232
232
|
} catch (e) {
|
233
233
|
}
|
234
234
|
switch (output) {
|
235
235
|
case "error":
|
236
|
-
console.error(
|
236
|
+
console.error(strObj);
|
237
237
|
break;
|
238
238
|
case "warn":
|
239
|
-
console.warn(
|
239
|
+
console.warn(strObj);
|
240
240
|
break;
|
241
241
|
default:
|
242
|
-
console.log(
|
242
|
+
console.log(strObj);
|
243
243
|
}
|
244
244
|
}
|
245
245
|
};
|
@@ -308,4 +308,4 @@ export {
|
|
308
308
|
uint8array2stream,
|
309
309
|
utils_exports
|
310
310
|
};
|
311
|
-
//# sourceMappingURL=chunk-
|
311
|
+
//# sourceMappingURL=chunk-USQXEZHL.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/stream-map.ts","../../src/utils/rebuffer.ts","../../src/utils/stream2string.ts","../../src/utils/string2stream.ts","../../src/utils/console-write-stream.ts","../../src/utils/fanout-write-stream.ts"],"sourcesContent":["export * from \"./rebuffer.js\";\nexport * from \"./stream-map.js\";\nexport * from \"./stream2string.js\";\nexport * from \"./string2stream.js\";\nexport * from \"./console-write-stream.js\";\nexport * from \"./fanout-write-stream.js\";\n","export interface StreamMap<T, U> {\n Map(s: T, idx: number): U | Promise<U>;\n readonly Close?: () => void;\n}\nexport function streamMap<T, U>(s: ReadableStream<T>, sm: StreamMap<T, U>): ReadableStream<U> {\n const state = { reader: s.getReader(), streamMap: sm, idx: 0 };\n return new ReadableStream<U>({\n async pull(controller): Promise<void> {\n const { done, value } = await state.reader.read();\n if (done) {\n if (state.streamMap.Close) {\n state.streamMap.Close();\n }\n controller.close();\n return;\n }\n const promiseOrU = state.streamMap.Map(value, state.idx++);\n let mapped: U;\n if (promiseOrU instanceof Promise || typeof (promiseOrU as { then: () => void }).then === \"function\") {\n mapped = await promiseOrU;\n } else {\n mapped = promiseOrU;\n }\n controller.enqueue(mapped);\n },\n });\n}\n\nexport async function devnull<T>(a: ReadableStream<T>): Promise<number> {\n const reader = a.getReader();\n let cnt = 0;\n while (true) {\n const { done } = await reader.read();\n if (done) {\n break;\n }\n cnt++;\n }\n return cnt;\n}\n\nexport function array2stream<T>(a: T[]): ReadableStream<T> {\n let i = 0;\n return new ReadableStream<T>({\n pull(controller): void {\n if (i >= a.length) {\n controller.close();\n return;\n }\n controller.enqueue(a[i]);\n i++;\n },\n });\n}\n\nexport async function stream2array<T>(a: ReadableStream<T>): Promise<T[]> {\n const ret: T[] = [];\n const reader = a.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n ret.push(value);\n }\n return ret;\n}\n","import { array2stream, stream2array } from \"./stream-map.js\";\n\ninterface ReChunkResult {\n readonly rest: Uint8Array;\n readonly chunk: Uint8Array;\n}\n\nexport async function rebufferArray(a: Uint8Array[], chunkSize: number): Promise<Uint8Array[]> {\n return stream2array(rebuffer(array2stream(a), chunkSize));\n}\n\nfunction reChunk(cs: Uint8Array[], chunkSize: number): ReChunkResult {\n const len = cs.reduce((acc, v) => acc + v.length, 0);\n const last = cs[cs.length - 1];\n const lastOfs = len - last.length;\n // console.log(\"reChunk\", len, lastOfs, last.length, chunkSize, chunkSize - lastOfs)\n const rest = last.subarray(chunkSize - lastOfs);\n cs[cs.length - 1] = last.subarray(0, chunkSize - lastOfs);\n const chunk = new Uint8Array(chunkSize);\n let ofs = 0;\n for (const c of cs) {\n chunk.set(c, ofs);\n ofs += c.length;\n }\n return { rest, chunk };\n}\n\ninterface pumpState {\n readonly reader: ReadableStreamDefaultReader<Uint8Array>;\n tmp: Uint8Array[];\n tmpLen: number;\n readonly chunkSize: number;\n}\n\nfunction pump(ps: pumpState, controller: ReadableStreamDefaultController<Uint8Array>, next: () => void): void {\n ps.reader.read().then(({ done, value }) => {\n if (done) {\n if (ps.tmpLen > 0) {\n controller.enqueue(reChunk(ps.tmp, ps.tmpLen).chunk);\n }\n controller.close();\n next();\n return;\n }\n if (ps.tmpLen + value.length > ps.chunkSize) {\n ps.tmp.push(value);\n const res = reChunk(ps.tmp, ps.chunkSize);\n controller.enqueue(res.chunk);\n ps.tmp = [res.rest];\n ps.tmpLen = res.rest.length;\n next();\n return;\n } else if (value.length) {\n ps.tmp.push(value);\n ps.tmpLen += value.length;\n }\n pump(ps, controller, next);\n });\n}\n\nexport function rebuffer(a: ReadableStream<Uint8Array>, chunkSize: number): ReadableStream<Uint8Array> {\n const state: pumpState = {\n reader: a.getReader(),\n tmp: [],\n tmpLen: 0,\n chunkSize,\n };\n return new ReadableStream<Uint8Array>({\n async pull(controller): Promise<void> {\n return new Promise<void>((resolve) => {\n pump(state, controller, resolve);\n });\n },\n });\n}\n","export async function stream2string(stream?: ReadableStream<Uint8Array> | null, maxSize?: number): Promise<string> {\n if (!stream) {\n return Promise.resolve(\"\");\n }\n const reader = stream.getReader();\n let res = \"\";\n const decoder = new TextDecoder();\n let rSize = 0;\n while (typeof maxSize === \"undefined\" || rSize < maxSize) {\n try {\n const read = await reader.read();\n if (read.done) {\n break;\n }\n if (maxSize && rSize + read.value.length > maxSize) {\n read.value = read.value.slice(0, maxSize - rSize);\n }\n const block = decoder.decode(read.value, { stream: true });\n rSize += read.value.length;\n res += block;\n } catch (err) {\n return Promise.reject(err);\n }\n }\n return Promise.resolve(res);\n}\n\nexport async function stream2uint8array(stream?: ReadableStream<Uint8Array> | null): Promise<Uint8Array> {\n if (!stream) {\n return Promise.resolve(new Uint8Array());\n }\n const reader = stream.getReader();\n let res = new Uint8Array();\n // eslint-disable-next-line no-constant-condition\n while (1) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n res = new Uint8Array([...res, ...value]);\n } catch (err) {\n return Promise.reject(err);\n }\n }\n return Promise.resolve(res);\n}\n","import { TxtEnDecoder, Utf8EnDecoderSingleton } from \"../txt-en-decoder.js\";\n\nexport function string2stream(str: string, ende: TxtEnDecoder = Utf8EnDecoderSingleton()): ReadableStream<Uint8Array> {\n return uint8array2stream(ende.encode(str));\n}\n\nexport function uint8array2stream(str: Uint8Array): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller): void {\n controller.enqueue(str);\n controller.close();\n },\n });\n}\n","export class ConsoleWriterStreamDefaultWriter implements WritableStreamDefaultWriter<Uint8Array> {\n readonly desiredSize: number | null = null;\n readonly decoder: TextDecoder = new TextDecoder();\n\n closed: Promise<undefined>;\n ready: Promise<undefined>;\n readonly _stream: ConsoleWriterStream;\n\n constructor(private stream: ConsoleWriterStream) {\n this._stream = stream;\n this.ready = Promise.resolve(undefined);\n this.closed = Promise.resolve(undefined);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n // noop\n }\n releaseLock(): void {\n this._stream.locked = false;\n this.ready = Promise.resolve(undefined);\n this.closed = Promise.resolve(undefined);\n }\n async write(chunk?: Uint8Array | undefined): Promise<void> {\n let strObj: string | { level: string } = this.decoder.decode(chunk).trimEnd();\n let output = \"log\";\n try {\n strObj = JSON.parse(strObj) as { level: string };\n output = strObj.level;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* noop */\n }\n switch (output) {\n case \"error\":\n // eslint-disable-next-line no-console\n console.error(strObj);\n break;\n case \"warn\":\n // eslint-disable-next-line no-console\n console.warn(strObj);\n break;\n default:\n // eslint-disable-next-line no-console\n console.log(strObj);\n }\n }\n}\n\nexport class ConsoleWriterStream implements WritableStream<Uint8Array> {\n locked = false;\n _writer?: WritableStreamDefaultWriter<Uint8Array>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars\n abort(reason?: any): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n async close(): Promise<void> {\n return;\n }\n getWriter(): WritableStreamDefaultWriter<Uint8Array> {\n if (this.locked) {\n throw new Error(\"Stream is locked\");\n }\n this.locked = true;\n if (!this._writer) {\n this._writer = new ConsoleWriterStreamDefaultWriter(this);\n }\n return this._writer;\n }\n}\n","export class FanoutWriteStream implements WritableStreamDefaultWriter<Uint8Array> {\n readonly _writers: WritableStreamDefaultWriter<Uint8Array>[];\n readonly ready: Promise<undefined>;\n readonly closed: Promise<undefined>;\n readonly desiredSize: number | null = null;\n constructor(writers: WritableStreamDefaultWriter<Uint8Array>[]) {\n this._writers = writers;\n this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => undefined);\n this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => undefined);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abort(reason?: any): Promise<void> {\n return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {\n /* do nothing */\n });\n }\n close(): Promise<void> {\n return Promise.all(this._writers.map((w) => w.close())).then(() => {\n /* do nothing */\n });\n }\n releaseLock(): void {\n this._writers.map((w) => w.releaseLock());\n }\n\n write(chunk?: Uint8Array | undefined): Promise<void> {\n return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {\n /* do nothing */\n });\n }\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,SAAS,UAAgB,GAAsB,IAAwC;AAC5F,QAAM,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,WAAW,IAAI,KAAK,EAAE;AAC7D,SAAO,IAAI,eAAkB;AAAA,IAC3B,MAAM,KAAK,YAA2B;AACpC,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK;AAChD,UAAI,MAAM;AACR,YAAI,MAAM,UAAU,OAAO;AACzB,gBAAM,UAAU,MAAM;AAAA,QACxB;AACA,mBAAW,MAAM;AACjB;AAAA,MACF;AACA,YAAM,aAAa,MAAM,UAAU,IAAI,OAAO,MAA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;AAAA,IACpC;AACA,SAAK,SAAS;AACd,QAAI,CAAC,KAAK,SAAS;AACjB,WAAK,UAAU,IAAI,iCAAiC,IAAI;AAAA,IAC1D;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;ACvEO,IAAM,oBAAN,MAA2E;AAAA,EAKhF,YAAY,SAAoD;AADhE,SAAS,cAA6B;AAEpC,SAAK,WAAW;AAChB,SAAK,QAAQ,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,MAAM,MAAS;AAChF,SAAK,SAAS,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,MAAM,MAAS;AAAA,EACpF;AAAA;AAAA,EAGA,MAAM,QAA6B;AACjC,WAAO,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,EAAE,KAAK,MAAM;AAAA,IAEzE,CAAC;AAAA,EACH;AAAA,EACA,QAAuB;AACrB,WAAO,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,MAAM;AAAA,IAEnE,CAAC;AAAA,EACH;AAAA,EACA,cAAoB;AAClB,SAAK,SAAS,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC;AAAA,EAC1C;AAAA,EAEA,MAAM,OAA+C;AACnD,WAAO,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC,EAAE,KAAK,MAAM;AAAA,IAExE,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/index.cjs
CHANGED
@@ -143,7 +143,6 @@ __export(src_exports, {
|
|
143
143
|
hasHostPartProtocols: () => hasHostPartProtocols,
|
144
144
|
isURL: () => isURL,
|
145
145
|
logValue: () => logValue,
|
146
|
-
removeSelfRef: () => removeSelfRef,
|
147
146
|
runtimeFn: () => runtimeFn,
|
148
147
|
toCryptoRuntime: () => toCryptoRuntime,
|
149
148
|
utils: () => utils_exports
|
@@ -212,22 +211,16 @@ var LogValue = class {
|
|
212
211
|
this.fn = fn;
|
213
212
|
}
|
214
213
|
value() {
|
215
|
-
|
214
|
+
try {
|
215
|
+
return this.fn();
|
216
|
+
} catch (e) {
|
217
|
+
return `LogValue:${e.message}`;
|
218
|
+
}
|
216
219
|
}
|
217
220
|
toJSON() {
|
218
221
|
return this.value();
|
219
222
|
}
|
220
223
|
};
|
221
|
-
function removeSelfRef(lineEnd) {
|
222
|
-
const cache = /* @__PURE__ */ new Set();
|
223
|
-
return function(key, value) {
|
224
|
-
if (typeof value === "object" && value !== null) {
|
225
|
-
if (cache.has(value)) return "...";
|
226
|
-
cache.add(value);
|
227
|
-
}
|
228
|
-
return lineEnd ? value + lineEnd : value;
|
229
|
-
};
|
230
|
-
}
|
231
224
|
function asyncLogValue(val) {
|
232
225
|
throw new Error("Not implemented");
|
233
226
|
}
|
@@ -254,19 +247,31 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
|
|
254
247
|
case "boolean":
|
255
248
|
return new LogValue(() => val);
|
256
249
|
case "object": {
|
250
|
+
if (val === null) {
|
251
|
+
return new LogValue(() => "null");
|
252
|
+
}
|
257
253
|
if (ArrayBuffer.isView(val)) {
|
258
254
|
return logValue(bin2string(val, 512));
|
259
255
|
}
|
260
256
|
if (Array.isArray(val)) {
|
261
257
|
return new LogValue(() => val.map((v) => logValue(v).value()));
|
262
258
|
}
|
263
|
-
if (val
|
264
|
-
return new LogValue(() =>
|
259
|
+
if (val instanceof Headers) {
|
260
|
+
return new LogValue(() => Object.fromEntries(val.entries()));
|
261
|
+
}
|
262
|
+
if (val instanceof ReadableStream) {
|
263
|
+
return new LogValue(() => ">Stream<");
|
264
|
+
}
|
265
|
+
if (val instanceof Promise) {
|
266
|
+
return new LogValue(() => ">Promise<");
|
265
267
|
}
|
266
268
|
if (state.has(val)) {
|
267
269
|
return new LogValue(() => "...");
|
268
270
|
}
|
269
271
|
state.add(val);
|
272
|
+
if (typeof val.toJSON === "function") {
|
273
|
+
return new LogValue(() => val.toJSON());
|
274
|
+
}
|
270
275
|
const res = {};
|
271
276
|
const typedVal = val;
|
272
277
|
for (const key in typedVal) {
|
@@ -274,7 +279,9 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
|
|
274
279
|
if (element instanceof LogValue) {
|
275
280
|
res[key] = element;
|
276
281
|
} else {
|
277
|
-
|
282
|
+
if (typeof element !== "function") {
|
283
|
+
res[key] = logValue(element, state);
|
284
|
+
}
|
278
285
|
}
|
279
286
|
}
|
280
287
|
return new LogValue(() => res);
|
@@ -1067,6 +1074,9 @@ function localStripper(path, restrips, obj) {
|
|
1067
1074
|
if (typeof obj !== "object" || obj === null) {
|
1068
1075
|
return obj;
|
1069
1076
|
}
|
1077
|
+
if (Array.isArray(obj)) {
|
1078
|
+
return obj.map((i) => localStripper(path, restrips, i));
|
1079
|
+
}
|
1070
1080
|
const ret = __spreadValues({}, obj);
|
1071
1081
|
const matcher = (key, nextPath) => {
|
1072
1082
|
for (const re of restrips) {
|
@@ -1107,6 +1117,16 @@ function localStripper(path, restrips, obj) {
|
|
1107
1117
|
}
|
1108
1118
|
|
1109
1119
|
// src/uri.ts
|
1120
|
+
function coerceKey(key, def) {
|
1121
|
+
if (typeof key === "object") {
|
1122
|
+
const keys = Object.keys(key);
|
1123
|
+
if (keys.length !== 1) {
|
1124
|
+
throw new Error(`Invalid key: ${JSON.stringify(key)}`);
|
1125
|
+
}
|
1126
|
+
return { key: keys[0], def: key[keys[0]] };
|
1127
|
+
}
|
1128
|
+
return { key, def };
|
1129
|
+
}
|
1110
1130
|
function falsy2undef(value) {
|
1111
1131
|
return value === void 0 || value === null ? void 0 : value;
|
1112
1132
|
}
|
@@ -1253,19 +1273,33 @@ function getParamResult(key, val, msgFn = (key2) => {
|
|
1253
1273
|
return Result.Ok(val);
|
1254
1274
|
}
|
1255
1275
|
function getParamsResult(keys, getParam) {
|
1256
|
-
const
|
1276
|
+
const keyDef = keys.flat().reduce(
|
1277
|
+
(acc, i) => {
|
1278
|
+
if (typeof i === "string") {
|
1279
|
+
acc.push({ key: i });
|
1280
|
+
} else if (typeof i === "object") {
|
1281
|
+
acc.push(...Object.keys(i).map((k) => ({ key: k, def: i[k] })));
|
1282
|
+
}
|
1283
|
+
return acc;
|
1284
|
+
},
|
1285
|
+
[]
|
1286
|
+
);
|
1257
1287
|
const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
|
1258
1288
|
const msg = keys2.join(",");
|
1259
1289
|
return `missing parameters: ${msg}`;
|
1260
1290
|
});
|
1261
1291
|
const errors = [];
|
1262
1292
|
const result = {};
|
1263
|
-
for (const
|
1264
|
-
const val = getParam.getParam(key);
|
1293
|
+
for (const kd of keyDef) {
|
1294
|
+
const val = getParam.getParam(kd.key);
|
1265
1295
|
if (val === void 0) {
|
1266
|
-
|
1296
|
+
if (kd.def) {
|
1297
|
+
result[kd.key] = kd.def;
|
1298
|
+
} else {
|
1299
|
+
errors.push(kd.key);
|
1300
|
+
}
|
1267
1301
|
} else {
|
1268
|
-
result[key] = val;
|
1302
|
+
result[kd.key] = val;
|
1269
1303
|
}
|
1270
1304
|
}
|
1271
1305
|
if (errors.length) {
|
@@ -1357,8 +1391,16 @@ var BuildURI = class _BuildURI {
|
|
1357
1391
|
hasParam(key) {
|
1358
1392
|
return this._url.searchParams.has(key);
|
1359
1393
|
}
|
1360
|
-
|
1361
|
-
return
|
1394
|
+
get getParams() {
|
1395
|
+
return this._url.searchParams.entries();
|
1396
|
+
}
|
1397
|
+
getParam(key, def) {
|
1398
|
+
const { key: k, def: d } = coerceKey(key, def);
|
1399
|
+
let val = this._url.searchParams.get(k);
|
1400
|
+
if (!falsy2undef(val) && d) {
|
1401
|
+
val = d;
|
1402
|
+
}
|
1403
|
+
return falsy2undef(val);
|
1362
1404
|
}
|
1363
1405
|
getParamResult(key, msgFn) {
|
1364
1406
|
return getParamResult(key, this.getParam(key), msgFn);
|
@@ -1379,6 +1421,9 @@ var BuildURI = class _BuildURI {
|
|
1379
1421
|
asObj(...strips) {
|
1380
1422
|
return this.URI().asObj(...strips);
|
1381
1423
|
}
|
1424
|
+
clone() {
|
1425
|
+
return _BuildURI.from(this.toString());
|
1426
|
+
}
|
1382
1427
|
URI() {
|
1383
1428
|
return URI.from(this._url);
|
1384
1429
|
}
|
@@ -1458,8 +1503,13 @@ var URI = class _URI {
|
|
1458
1503
|
hasParam(key) {
|
1459
1504
|
return this._url.searchParams.has(key);
|
1460
1505
|
}
|
1461
|
-
getParam(key) {
|
1462
|
-
|
1506
|
+
getParam(key, def) {
|
1507
|
+
const { key: k, def: d } = coerceKey(key, def);
|
1508
|
+
let val = this._url.searchParams.get(k);
|
1509
|
+
if (!falsy2undef(val) && d) {
|
1510
|
+
val = d;
|
1511
|
+
}
|
1512
|
+
return falsy2undef(val);
|
1463
1513
|
}
|
1464
1514
|
getParamResult(key, msgFn) {
|
1465
1515
|
return getParamResult(key, this.getParam(key), msgFn);
|
@@ -1546,22 +1596,22 @@ var ConsoleWriterStreamDefaultWriter = class {
|
|
1546
1596
|
this.closed = Promise.resolve(void 0);
|
1547
1597
|
}
|
1548
1598
|
async write(chunk) {
|
1549
|
-
|
1599
|
+
let strObj = this.decoder.decode(chunk).trimEnd();
|
1550
1600
|
let output = "log";
|
1551
1601
|
try {
|
1552
|
-
|
1553
|
-
output =
|
1602
|
+
strObj = JSON.parse(strObj);
|
1603
|
+
output = strObj.level;
|
1554
1604
|
} catch (e) {
|
1555
1605
|
}
|
1556
1606
|
switch (output) {
|
1557
1607
|
case "error":
|
1558
|
-
console.error(
|
1608
|
+
console.error(strObj);
|
1559
1609
|
break;
|
1560
1610
|
case "warn":
|
1561
|
-
console.warn(
|
1611
|
+
console.warn(strObj);
|
1562
1612
|
break;
|
1563
1613
|
default:
|
1564
|
-
console.log(
|
1614
|
+
console.log(strObj);
|
1565
1615
|
}
|
1566
1616
|
}
|
1567
1617
|
};
|
@@ -1744,7 +1794,13 @@ var JSONFormatter = class {
|
|
1744
1794
|
this._space = space;
|
1745
1795
|
}
|
1746
1796
|
format(attr) {
|
1747
|
-
|
1797
|
+
let ret;
|
1798
|
+
try {
|
1799
|
+
ret = JSON.stringify(attr, null, this._space);
|
1800
|
+
} catch (e) {
|
1801
|
+
ret = JSON.stringify({ internal: { message: e.message, stack: e.stack } });
|
1802
|
+
}
|
1803
|
+
return this._txtEnDe.encode(ret + "\n");
|
1748
1804
|
}
|
1749
1805
|
};
|
1750
1806
|
var YAMLFormatter = class {
|
@@ -1753,7 +1809,7 @@ var YAMLFormatter = class {
|
|
1753
1809
|
this._space = space;
|
1754
1810
|
}
|
1755
1811
|
format(attr) {
|
1756
|
-
return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr,
|
1812
|
+
return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr, null, this._space) + "\n");
|
1757
1813
|
}
|
1758
1814
|
};
|
1759
1815
|
var LoggerImpl = class _LoggerImpl {
|
@@ -1814,7 +1870,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1814
1870
|
return this._txtEnDe;
|
1815
1871
|
}
|
1816
1872
|
Attributes() {
|
1817
|
-
return JSON.parse(JSON.stringify(this._attributes,
|
1873
|
+
return JSON.parse(JSON.stringify(this._attributes, null));
|
1818
1874
|
}
|
1819
1875
|
SetExposeStack(enable) {
|
1820
1876
|
this._levelHandler.setExposeStack(enable);
|
@@ -1898,7 +1954,37 @@ var LoggerImpl = class _LoggerImpl {
|
|
1898
1954
|
return this;
|
1899
1955
|
}
|
1900
1956
|
Bool(key, value) {
|
1901
|
-
this.
|
1957
|
+
this.coerceKey(key, !!value);
|
1958
|
+
return this;
|
1959
|
+
}
|
1960
|
+
Http(res, req, key) {
|
1961
|
+
if (Result.Is(res)) {
|
1962
|
+
if (res.isErr()) {
|
1963
|
+
this.Err(res.Err());
|
1964
|
+
return this;
|
1965
|
+
}
|
1966
|
+
res = res.Ok();
|
1967
|
+
}
|
1968
|
+
let reqRes = res;
|
1969
|
+
if (req) {
|
1970
|
+
reqRes = { res, req };
|
1971
|
+
}
|
1972
|
+
this.Any(key || "Http", reqRes);
|
1973
|
+
return this;
|
1974
|
+
}
|
1975
|
+
Pair(x) {
|
1976
|
+
for (const key of Object.keys(x)) {
|
1977
|
+
const value = x[key];
|
1978
|
+
if (value instanceof LogValue) {
|
1979
|
+
this._attributes[key] = value;
|
1980
|
+
continue;
|
1981
|
+
}
|
1982
|
+
if (Result.Is(value)) {
|
1983
|
+
this.Result(key, value);
|
1984
|
+
continue;
|
1985
|
+
}
|
1986
|
+
this.Any(key, value);
|
1987
|
+
}
|
1902
1988
|
return this;
|
1903
1989
|
}
|
1904
1990
|
Result(key, res) {
|
@@ -1921,12 +2007,19 @@ var LoggerImpl = class _LoggerImpl {
|
|
1921
2007
|
this.Ref(key, () => URI.from(url).toString());
|
1922
2008
|
return this;
|
1923
2009
|
}
|
2010
|
+
coerceKey(key, value) {
|
2011
|
+
if (typeof key === "string") {
|
2012
|
+
this._attributes[key] = logValue(value);
|
2013
|
+
} else {
|
2014
|
+
this.Pair(key);
|
2015
|
+
}
|
2016
|
+
}
|
1924
2017
|
Str(key, value) {
|
1925
|
-
this.
|
2018
|
+
this.coerceKey(key, value);
|
1926
2019
|
return this;
|
1927
2020
|
}
|
1928
2021
|
Any(key, value) {
|
1929
|
-
this.
|
2022
|
+
this.coerceKey(key, value);
|
1930
2023
|
return this;
|
1931
2024
|
}
|
1932
2025
|
Dur(key, nsec) {
|
@@ -1934,7 +2027,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1934
2027
|
return this;
|
1935
2028
|
}
|
1936
2029
|
Uint64(key, value) {
|
1937
|
-
this.
|
2030
|
+
this.coerceKey(key, value);
|
1938
2031
|
return this;
|
1939
2032
|
}
|
1940
2033
|
Int(key, value) {
|
@@ -2031,6 +2124,14 @@ var WithLoggerBuilder = class {
|
|
2031
2124
|
this._li.SetDebug(...modules);
|
2032
2125
|
return this;
|
2033
2126
|
}
|
2127
|
+
Http(res, req, key) {
|
2128
|
+
this._li.Http(res, req, key);
|
2129
|
+
return this;
|
2130
|
+
}
|
2131
|
+
Pair(x) {
|
2132
|
+
this._li.Pair(x);
|
2133
|
+
return this;
|
2134
|
+
}
|
2034
2135
|
Str(key, value) {
|
2035
2136
|
this._li.Str(key, value);
|
2036
2137
|
return this;
|
@@ -2721,7 +2822,6 @@ function uint8array2stream(str) {
|
|
2721
2822
|
hasHostPartProtocols,
|
2722
2823
|
isURL,
|
2723
2824
|
logValue,
|
2724
|
-
removeSelfRef,
|
2725
2825
|
runtimeFn,
|
2726
2826
|
toCryptoRuntime,
|
2727
2827
|
utils
|