@adviser/cement 0.2.33 → 0.2.35
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +98 -32
- package/index.cjs.map +1 -1
- package/index.d.cts +10 -6
- package/index.d.ts +10 -6
- package/index.js +98 -31
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/jsr.json +1 -1
- package/src/logger-impl.ts +51 -4
- package/src/logger.ts +47 -16
- package/src/uri.ts +54 -28
- package/src/utils/stripper.ts +11 -4
- package/ts/logger-impl.d.ts +2 -0
- package/ts/logger-impl.d.ts.map +1 -1
- package/ts/logger-impl.js +49 -4
- package/ts/logger-impl.js.map +1 -1
- package/ts/logger.d.ts +2 -1
- 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 +175 -0
- package/ts/logger.test.js.map +1 -1
- package/ts/uri.d.ts +5 -4
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +24 -12
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +50 -0
- package/ts/uri.test.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/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) {
|
@@ -1325,15 +1335,17 @@ var BuildURI = class _BuildURI {
|
|
1325
1335
|
// return this;
|
1326
1336
|
// }
|
1327
1337
|
appendRelative(p) {
|
1328
|
-
const
|
1329
|
-
let pathname =
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1338
|
+
const appendUrl = URI.from(p);
|
1339
|
+
let pathname = appendUrl.pathname;
|
1340
|
+
let basePath = this._url.pathname;
|
1341
|
+
if (pathname.startsWith("/")) {
|
1342
|
+
pathname = pathname.replace(/^\//, "");
|
1343
|
+
}
|
1344
|
+
if (basePath.length > 0) {
|
1345
|
+
basePath = basePath.replace(/\/$/, "");
|
1346
|
+
}
|
1347
|
+
this.pathname(basePath + "/" + pathname);
|
1348
|
+
for (const [key, value] of appendUrl.getParams) {
|
1337
1349
|
this.setParam(key, value);
|
1338
1350
|
}
|
1339
1351
|
return this;
|
@@ -1355,8 +1367,12 @@ var BuildURI = class _BuildURI {
|
|
1355
1367
|
hasParam(key) {
|
1356
1368
|
return this._url.searchParams.has(key);
|
1357
1369
|
}
|
1358
|
-
getParam(key) {
|
1359
|
-
|
1370
|
+
getParam(key, def) {
|
1371
|
+
let val = this._url.searchParams.get(key);
|
1372
|
+
if (!falsy2undef(val) && def) {
|
1373
|
+
val = def;
|
1374
|
+
}
|
1375
|
+
return falsy2undef(val);
|
1360
1376
|
}
|
1361
1377
|
getParamResult(key, msgFn) {
|
1362
1378
|
return getParamResult(key, this.getParam(key), msgFn);
|
@@ -1371,6 +1387,9 @@ var BuildURI = class _BuildURI {
|
|
1371
1387
|
toJSON() {
|
1372
1388
|
return this.toString();
|
1373
1389
|
}
|
1390
|
+
asURL() {
|
1391
|
+
return this.URI().asURL();
|
1392
|
+
}
|
1374
1393
|
asObj(...strips) {
|
1375
1394
|
return this.URI().asObj(...strips);
|
1376
1395
|
}
|
@@ -1453,8 +1472,12 @@ var URI = class _URI {
|
|
1453
1472
|
hasParam(key) {
|
1454
1473
|
return this._url.searchParams.has(key);
|
1455
1474
|
}
|
1456
|
-
getParam(key) {
|
1457
|
-
|
1475
|
+
getParam(key, def) {
|
1476
|
+
let val = this._url.searchParams.get(key);
|
1477
|
+
if (!falsy2undef(val) && def) {
|
1478
|
+
val = def;
|
1479
|
+
}
|
1480
|
+
return falsy2undef(val);
|
1458
1481
|
}
|
1459
1482
|
getParamResult(key, msgFn) {
|
1460
1483
|
return getParamResult(key, this.getParam(key), msgFn);
|
@@ -1739,7 +1762,13 @@ var JSONFormatter = class {
|
|
1739
1762
|
this._space = space;
|
1740
1763
|
}
|
1741
1764
|
format(attr) {
|
1742
|
-
|
1765
|
+
let ret;
|
1766
|
+
try {
|
1767
|
+
ret = JSON.stringify(attr, null, this._space);
|
1768
|
+
} catch (e) {
|
1769
|
+
ret = JSON.stringify({ internal: { message: e.message, stack: e.stack } });
|
1770
|
+
}
|
1771
|
+
return this._txtEnDe.encode(ret + "\n");
|
1743
1772
|
}
|
1744
1773
|
};
|
1745
1774
|
var YAMLFormatter = class {
|
@@ -1748,7 +1777,7 @@ var YAMLFormatter = class {
|
|
1748
1777
|
this._space = space;
|
1749
1778
|
}
|
1750
1779
|
format(attr) {
|
1751
|
-
return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr,
|
1780
|
+
return this._txtEnDe.encode("---\n" + import_yaml.default.stringify(attr, null, this._space) + "\n");
|
1752
1781
|
}
|
1753
1782
|
};
|
1754
1783
|
var LoggerImpl = class _LoggerImpl {
|
@@ -1809,7 +1838,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1809
1838
|
return this._txtEnDe;
|
1810
1839
|
}
|
1811
1840
|
Attributes() {
|
1812
|
-
return JSON.parse(JSON.stringify(this._attributes,
|
1841
|
+
return JSON.parse(JSON.stringify(this._attributes, null));
|
1813
1842
|
}
|
1814
1843
|
SetExposeStack(enable) {
|
1815
1844
|
this._levelHandler.setExposeStack(enable);
|
@@ -1896,6 +1925,36 @@ var LoggerImpl = class _LoggerImpl {
|
|
1896
1925
|
this._attributes[key] = logValue(!!value);
|
1897
1926
|
return this;
|
1898
1927
|
}
|
1928
|
+
Http(res, req, key) {
|
1929
|
+
if (Result.Is(res)) {
|
1930
|
+
if (res.isErr()) {
|
1931
|
+
this.Err(res.Err());
|
1932
|
+
return this;
|
1933
|
+
}
|
1934
|
+
res = res.Ok();
|
1935
|
+
}
|
1936
|
+
let reqRes = res;
|
1937
|
+
if (req) {
|
1938
|
+
reqRes = { res, req };
|
1939
|
+
}
|
1940
|
+
this.Any(key || "Http", reqRes);
|
1941
|
+
return this;
|
1942
|
+
}
|
1943
|
+
Pair(x) {
|
1944
|
+
for (const key of Object.keys(x)) {
|
1945
|
+
const value = x[key];
|
1946
|
+
if (value instanceof LogValue) {
|
1947
|
+
this._attributes[key] = value;
|
1948
|
+
continue;
|
1949
|
+
}
|
1950
|
+
if (Result.Is(value)) {
|
1951
|
+
this.Result(key, value);
|
1952
|
+
continue;
|
1953
|
+
}
|
1954
|
+
this.Any(key, value);
|
1955
|
+
}
|
1956
|
+
return this;
|
1957
|
+
}
|
1899
1958
|
Result(key, res) {
|
1900
1959
|
if (res.isOk()) {
|
1901
1960
|
this._attributes[key] = logValue(res.Ok());
|
@@ -2026,6 +2085,14 @@ var WithLoggerBuilder = class {
|
|
2026
2085
|
this._li.SetDebug(...modules);
|
2027
2086
|
return this;
|
2028
2087
|
}
|
2088
|
+
Http(res, req, key) {
|
2089
|
+
this._li.Http(res, req, key);
|
2090
|
+
return this;
|
2091
|
+
}
|
2092
|
+
Pair(x) {
|
2093
|
+
this._li.Pair(x);
|
2094
|
+
return this;
|
2095
|
+
}
|
2029
2096
|
Str(key, value) {
|
2030
2097
|
this._li.Str(key, value);
|
2031
2098
|
return this;
|
@@ -2716,7 +2783,6 @@ function uint8array2stream(str) {
|
|
2716
2783
|
hasHostPartProtocols,
|
2717
2784
|
isURL,
|
2718
2785
|
logValue,
|
2719
|
-
removeSelfRef,
|
2720
2786
|
runtimeFn,
|
2721
2787
|
toCryptoRuntime,
|
2722
2788
|
utils
|