@adviser/cement 0.2.34 → 0.2.35
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/index.cjs +84 -23
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -6
- package/index.d.ts +9 -6
- package/index.js +89 -27
- 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 +29 -20
- 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 +4 -4
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +12 -4
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +15 -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) {
|
|
@@ -1357,8 +1367,12 @@ var BuildURI = class _BuildURI {
|
|
|
1357
1367
|
hasParam(key) {
|
|
1358
1368
|
return this._url.searchParams.has(key);
|
|
1359
1369
|
}
|
|
1360
|
-
getParam(key) {
|
|
1361
|
-
|
|
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);
|
|
1362
1376
|
}
|
|
1363
1377
|
getParamResult(key, msgFn) {
|
|
1364
1378
|
return getParamResult(key, this.getParam(key), msgFn);
|
|
@@ -1458,8 +1472,12 @@ var URI = class _URI {
|
|
|
1458
1472
|
hasParam(key) {
|
|
1459
1473
|
return this._url.searchParams.has(key);
|
|
1460
1474
|
}
|
|
1461
|
-
getParam(key) {
|
|
1462
|
-
|
|
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);
|
|
1463
1481
|
}
|
|
1464
1482
|
getParamResult(key, msgFn) {
|
|
1465
1483
|
return getParamResult(key, this.getParam(key), msgFn);
|
|
@@ -1744,7 +1762,13 @@ var JSONFormatter = class {
|
|
|
1744
1762
|
this._space = space;
|
|
1745
1763
|
}
|
|
1746
1764
|
format(attr) {
|
|
1747
|
-
|
|
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");
|
|
1748
1772
|
}
|
|
1749
1773
|
};
|
|
1750
1774
|
var YAMLFormatter = class {
|
|
@@ -1753,7 +1777,7 @@ var YAMLFormatter = class {
|
|
|
1753
1777
|
this._space = space;
|
|
1754
1778
|
}
|
|
1755
1779
|
format(attr) {
|
|
1756
|
-
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");
|
|
1757
1781
|
}
|
|
1758
1782
|
};
|
|
1759
1783
|
var LoggerImpl = class _LoggerImpl {
|
|
@@ -1814,7 +1838,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
1814
1838
|
return this._txtEnDe;
|
|
1815
1839
|
}
|
|
1816
1840
|
Attributes() {
|
|
1817
|
-
return JSON.parse(JSON.stringify(this._attributes,
|
|
1841
|
+
return JSON.parse(JSON.stringify(this._attributes, null));
|
|
1818
1842
|
}
|
|
1819
1843
|
SetExposeStack(enable) {
|
|
1820
1844
|
this._levelHandler.setExposeStack(enable);
|
|
@@ -1901,6 +1925,36 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
1901
1925
|
this._attributes[key] = logValue(!!value);
|
|
1902
1926
|
return this;
|
|
1903
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
|
+
}
|
|
1904
1958
|
Result(key, res) {
|
|
1905
1959
|
if (res.isOk()) {
|
|
1906
1960
|
this._attributes[key] = logValue(res.Ok());
|
|
@@ -2031,6 +2085,14 @@ var WithLoggerBuilder = class {
|
|
|
2031
2085
|
this._li.SetDebug(...modules);
|
|
2032
2086
|
return this;
|
|
2033
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
|
+
}
|
|
2034
2096
|
Str(key, value) {
|
|
2035
2097
|
this._li.Str(key, value);
|
|
2036
2098
|
return this;
|
|
@@ -2721,7 +2783,6 @@ function uint8array2stream(str) {
|
|
|
2721
2783
|
hasHostPartProtocols,
|
|
2722
2784
|
isURL,
|
|
2723
2785
|
logValue,
|
|
2724
|
-
removeSelfRef,
|
|
2725
2786
|
runtimeFn,
|
|
2726
2787
|
toCryptoRuntime,
|
|
2727
2788
|
utils
|