@adviser/cement 0.2.36 → 0.2.38
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/{chunk-Q65HLCNL.js → chunk-F5W6VELE.js} +26 -17
- package/chunk-F5W6VELE.js.map +1 -0
- package/{chunk-WMMUXBDX.js → chunk-W2GV5KXV.js} +2 -2
- package/index.cjs +59 -33
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -8
- package/index.d.ts +9 -8
- package/index.js +36 -19
- package/index.js.map +1 -1
- package/node/index.cjs +25 -16
- package/node/index.cjs.map +1 -1
- package/node/index.js +1 -1
- package/package.json +2 -2
- package/src/base-sys-abstraction.ts +44 -0
- package/src/jsr.json +1 -1
- package/src/log-writer-impl.ts +1 -1
- package/src/logger-impl.ts +28 -13
- package/src/logger.ts +16 -2
- package/src/uri.ts +23 -9
- package/ts/base-sys-abstraction.d.ts.map +1 -1
- package/ts/base-sys-abstraction.js +30 -16
- package/ts/base-sys-abstraction.js.map +1 -1
- package/ts/logger-impl.d.ts +2 -2
- package/ts/logger-impl.d.ts.map +1 -1
- package/ts/logger-impl.js +30 -13
- 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 +9 -1
- package/ts/logger.js.map +1 -1
- package/ts/logger.test.js +343 -64
- package/ts/logger.test.js.map +1 -1
- package/ts/uri.d.ts +5 -5
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +2 -2
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +47 -0
- package/ts/uri.test.js.map +1 -1
- package/web/index.cjs +25 -16
- package/web/index.cjs.map +1 -1
- package/web/index.js +2 -2
- package/chunk-Q65HLCNL.js.map +0 -1
- /package/{chunk-WMMUXBDX.js.map → chunk-W2GV5KXV.js.map} +0 -0
package/ts/logger.test.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
1
12
|
import { TimeFactory, IsLogger, Level, LevelHandlerImpl, LogCollector, LoggerImpl, logValue, Result, runtimeFn, TimeMode, BuildURI, URI, MutableURL, JSONFormatter, YAMLFormatter, } from "@adviser/cement";
|
|
2
13
|
import { WebSysAbstraction } from "@adviser/cement/web";
|
|
3
14
|
import { stripper } from "./utils/stripper.js";
|
|
4
15
|
describe("TestLogger", () => {
|
|
16
|
+
var _TestResponse_url;
|
|
5
17
|
let logCollector;
|
|
6
18
|
let logger;
|
|
7
19
|
beforeEach(() => {
|
|
@@ -1094,110 +1106,358 @@ describe("TestLogger", () => {
|
|
|
1094
1106
|
}),
|
|
1095
1107
|
]);
|
|
1096
1108
|
});
|
|
1097
|
-
|
|
1098
|
-
|
|
1109
|
+
class TestResponse extends Response {
|
|
1110
|
+
constructor(body, init) {
|
|
1111
|
+
super(body, init);
|
|
1112
|
+
_TestResponse_url.set(this, void 0);
|
|
1113
|
+
__classPrivateFieldSet(this, _TestResponse_url, (init === null || init === void 0 ? void 0 : init.url) || "", "f");
|
|
1114
|
+
}
|
|
1115
|
+
get url() {
|
|
1116
|
+
return __classPrivateFieldGet(this, _TestResponse_url, "f");
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
_TestResponse_url = new WeakMap();
|
|
1120
|
+
describe("fetch-formatter", async () => {
|
|
1121
|
+
const resp = new TestResponse("body", {
|
|
1099
1122
|
status: 200,
|
|
1100
1123
|
statusText: "OK",
|
|
1101
1124
|
headers: new Headers({
|
|
1102
1125
|
"Content-Type": "text/html",
|
|
1103
1126
|
"X-Test": "test",
|
|
1104
1127
|
}),
|
|
1128
|
+
url: "https://www.google.com",
|
|
1105
1129
|
});
|
|
1106
|
-
logger.Error().Any("res", { the: result }).Msg("ok");
|
|
1107
|
-
logger.Error().Http(Result.Ok(result)).Msg("1");
|
|
1108
1130
|
const req = new Request("https://www.google.com", {
|
|
1109
1131
|
method: "PUT",
|
|
1110
1132
|
headers: new Headers({
|
|
1111
1133
|
"Content-Type": "text/html",
|
|
1112
1134
|
"X-Test": "xtest",
|
|
1113
1135
|
}),
|
|
1136
|
+
body: "String",
|
|
1114
1137
|
});
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1138
|
+
async function fixupLogs() {
|
|
1139
|
+
await logger.Flush();
|
|
1140
|
+
return stripper(["isReloadNavigation", "reason", "targetAddressSpace", "attribute", "duplex", "cache", "credentials", "destination"], logCollector.Logs(true).map((i) => JSON.parse(i)));
|
|
1141
|
+
}
|
|
1142
|
+
it("res", async () => {
|
|
1143
|
+
logger.Error().Any("res", { the: resp }).Msg("ok-the-res");
|
|
1144
|
+
expect(await fixupLogs()).toEqual([
|
|
1145
|
+
{
|
|
1146
|
+
level: "error",
|
|
1147
|
+
res: {
|
|
1148
|
+
the: {
|
|
1149
|
+
type: "default",
|
|
1150
|
+
redirected: false,
|
|
1151
|
+
status: 200,
|
|
1152
|
+
ok: true,
|
|
1153
|
+
statusText: "OK",
|
|
1154
|
+
headers: {
|
|
1155
|
+
"content-type": "text/html",
|
|
1156
|
+
"x-test": "test",
|
|
1157
|
+
},
|
|
1158
|
+
body: ">Stream<",
|
|
1159
|
+
bodyUsed: false,
|
|
1131
1160
|
},
|
|
1132
|
-
body: ">Stream<",
|
|
1133
|
-
bodyUsed: false,
|
|
1134
1161
|
},
|
|
1162
|
+
msg: "ok-the-res",
|
|
1135
1163
|
},
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1164
|
+
]);
|
|
1165
|
+
});
|
|
1166
|
+
it("res", async () => {
|
|
1167
|
+
logger.Error().Any("req", { the: req }).Msg("ok-the-req");
|
|
1168
|
+
expect(await fixupLogs()).toEqual([
|
|
1169
|
+
{
|
|
1170
|
+
level: "error",
|
|
1171
|
+
msg: "ok-the-req",
|
|
1172
|
+
req: {
|
|
1173
|
+
the: {
|
|
1174
|
+
body: ">Stream<",
|
|
1175
|
+
bodyUsed: false,
|
|
1176
|
+
headers: {
|
|
1177
|
+
"content-type": "text/html",
|
|
1178
|
+
"x-test": "xtest",
|
|
1179
|
+
},
|
|
1180
|
+
keepalive: false,
|
|
1181
|
+
method: "PUT",
|
|
1182
|
+
mode: "cors",
|
|
1183
|
+
integrity: "",
|
|
1184
|
+
isHistoryNavigation: false,
|
|
1185
|
+
redirect: "follow",
|
|
1186
|
+
referrer: "about:client",
|
|
1187
|
+
referrerPolicy: "",
|
|
1188
|
+
signal: {
|
|
1189
|
+
aborted: false,
|
|
1190
|
+
onabort: "null",
|
|
1191
|
+
},
|
|
1192
|
+
url: "https://www.google.com/",
|
|
1193
|
+
},
|
|
1150
1194
|
},
|
|
1151
|
-
body: ">Stream<",
|
|
1152
|
-
bodyUsed: false,
|
|
1153
1195
|
},
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1196
|
+
]);
|
|
1197
|
+
});
|
|
1198
|
+
it("req-res", async () => {
|
|
1199
|
+
logger
|
|
1200
|
+
.Error()
|
|
1201
|
+
.Any("req-res", { the: { req, res: resp } })
|
|
1202
|
+
.Msg("ok-the-req-res");
|
|
1203
|
+
expect(await fixupLogs()).toEqual([
|
|
1204
|
+
{
|
|
1205
|
+
level: "error",
|
|
1206
|
+
msg: "ok-the-req-res",
|
|
1207
|
+
"req-res": {
|
|
1208
|
+
the: {
|
|
1209
|
+
req: {
|
|
1210
|
+
body: ">Stream<",
|
|
1211
|
+
bodyUsed: false,
|
|
1212
|
+
headers: {
|
|
1213
|
+
"content-type": "text/html",
|
|
1214
|
+
"x-test": "xtest",
|
|
1215
|
+
},
|
|
1216
|
+
integrity: "",
|
|
1217
|
+
isHistoryNavigation: false,
|
|
1218
|
+
keepalive: false,
|
|
1219
|
+
method: "PUT",
|
|
1220
|
+
mode: "cors",
|
|
1221
|
+
redirect: "follow",
|
|
1222
|
+
referrer: "about:client",
|
|
1223
|
+
referrerPolicy: "",
|
|
1224
|
+
signal: {
|
|
1225
|
+
aborted: false,
|
|
1226
|
+
onabort: "null",
|
|
1227
|
+
},
|
|
1228
|
+
url: "https://www.google.com/",
|
|
1229
|
+
},
|
|
1230
|
+
res: {
|
|
1231
|
+
body: ">Stream<",
|
|
1232
|
+
bodyUsed: false,
|
|
1233
|
+
headers: {
|
|
1234
|
+
"content-type": "text/html",
|
|
1235
|
+
"x-test": "test",
|
|
1236
|
+
},
|
|
1237
|
+
ok: true,
|
|
1238
|
+
redirected: false,
|
|
1239
|
+
status: 200,
|
|
1240
|
+
statusText: "OK",
|
|
1241
|
+
type: "default",
|
|
1242
|
+
},
|
|
1243
|
+
},
|
|
1244
|
+
},
|
|
1245
|
+
},
|
|
1246
|
+
]);
|
|
1247
|
+
});
|
|
1248
|
+
it("req-res", async () => {
|
|
1249
|
+
logger.Error().Http(Result.Ok(resp)).Msg("-1");
|
|
1250
|
+
expect(await fixupLogs()).toEqual([
|
|
1251
|
+
{
|
|
1252
|
+
Http: {
|
|
1253
|
+
body: ">Stream<",
|
|
1254
|
+
bodyUsed: false,
|
|
1166
1255
|
headers: {
|
|
1167
1256
|
"content-type": "text/html",
|
|
1168
1257
|
"x-test": "test",
|
|
1169
1258
|
},
|
|
1259
|
+
ok: true,
|
|
1260
|
+
redirected: false,
|
|
1261
|
+
status: 200,
|
|
1262
|
+
statusText: "OK",
|
|
1263
|
+
type: "default",
|
|
1264
|
+
},
|
|
1265
|
+
level: "error",
|
|
1266
|
+
msg: "-1",
|
|
1267
|
+
},
|
|
1268
|
+
]);
|
|
1269
|
+
});
|
|
1270
|
+
it("0", async () => {
|
|
1271
|
+
logger.Error().Http().Msg("0");
|
|
1272
|
+
expect(await fixupLogs()).toEqual([
|
|
1273
|
+
{
|
|
1274
|
+
level: "error",
|
|
1275
|
+
msg: "0",
|
|
1276
|
+
},
|
|
1277
|
+
]);
|
|
1278
|
+
});
|
|
1279
|
+
it("1", async () => {
|
|
1280
|
+
logger.Error().Http(resp, req, "Https").Msg("1");
|
|
1281
|
+
expect(await fixupLogs()).toEqual([
|
|
1282
|
+
{
|
|
1283
|
+
Https: {
|
|
1284
|
+
req: {
|
|
1285
|
+
body: ">Stream<",
|
|
1286
|
+
bodyUsed: false,
|
|
1287
|
+
headers: {
|
|
1288
|
+
"content-type": "text/html",
|
|
1289
|
+
"x-test": "xtest",
|
|
1290
|
+
},
|
|
1291
|
+
integrity: "",
|
|
1292
|
+
isHistoryNavigation: false,
|
|
1293
|
+
keepalive: false,
|
|
1294
|
+
method: "PUT",
|
|
1295
|
+
mode: "cors",
|
|
1296
|
+
redirect: "follow",
|
|
1297
|
+
referrer: "about:client",
|
|
1298
|
+
referrerPolicy: "",
|
|
1299
|
+
signal: {
|
|
1300
|
+
aborted: false,
|
|
1301
|
+
onabort: "null",
|
|
1302
|
+
},
|
|
1303
|
+
url: "https://www.google.com/",
|
|
1304
|
+
},
|
|
1305
|
+
res: {
|
|
1306
|
+
body: ">Stream<",
|
|
1307
|
+
bodyUsed: false,
|
|
1308
|
+
headers: {
|
|
1309
|
+
"content-type": "text/html",
|
|
1310
|
+
"x-test": "test",
|
|
1311
|
+
},
|
|
1312
|
+
ok: true,
|
|
1313
|
+
redirected: false,
|
|
1314
|
+
status: 200,
|
|
1315
|
+
statusText: "OK",
|
|
1316
|
+
type: "default",
|
|
1317
|
+
},
|
|
1318
|
+
},
|
|
1319
|
+
level: "error",
|
|
1320
|
+
msg: "1",
|
|
1321
|
+
},
|
|
1322
|
+
]);
|
|
1323
|
+
});
|
|
1324
|
+
it("1.1", async () => {
|
|
1325
|
+
logger.Error().Http("Yolo", Result.Ok(req), Result.Ok(resp)).Msg("1.1");
|
|
1326
|
+
expect(await fixupLogs()).toEqual([
|
|
1327
|
+
{
|
|
1328
|
+
Yolo: {
|
|
1329
|
+
req: {
|
|
1330
|
+
body: ">Stream<",
|
|
1331
|
+
bodyUsed: false,
|
|
1332
|
+
headers: {
|
|
1333
|
+
"content-type": "text/html",
|
|
1334
|
+
"x-test": "xtest",
|
|
1335
|
+
},
|
|
1336
|
+
integrity: "",
|
|
1337
|
+
isHistoryNavigation: false,
|
|
1338
|
+
keepalive: false,
|
|
1339
|
+
method: "PUT",
|
|
1340
|
+
mode: "cors",
|
|
1341
|
+
redirect: "follow",
|
|
1342
|
+
referrer: "about:client",
|
|
1343
|
+
referrerPolicy: "",
|
|
1344
|
+
signal: {
|
|
1345
|
+
aborted: false,
|
|
1346
|
+
onabort: "null",
|
|
1347
|
+
},
|
|
1348
|
+
url: "https://www.google.com/",
|
|
1349
|
+
},
|
|
1350
|
+
res: {
|
|
1351
|
+
body: ">Stream<",
|
|
1352
|
+
bodyUsed: false,
|
|
1353
|
+
headers: {
|
|
1354
|
+
"content-type": "text/html",
|
|
1355
|
+
"x-test": "test",
|
|
1356
|
+
},
|
|
1357
|
+
ok: true,
|
|
1358
|
+
redirected: false,
|
|
1359
|
+
status: 200,
|
|
1360
|
+
statusText: "OK",
|
|
1361
|
+
type: "default",
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
level: "error",
|
|
1365
|
+
msg: "1.1",
|
|
1366
|
+
},
|
|
1367
|
+
]);
|
|
1368
|
+
});
|
|
1369
|
+
it("1.2", async () => {
|
|
1370
|
+
logger.Error().Http("Yerr", Result.Err("e1"), Result.Err("e2")).Msg("1.2");
|
|
1371
|
+
expect(await fixupLogs()).toEqual([
|
|
1372
|
+
{
|
|
1373
|
+
error: ["e1", "e2"],
|
|
1374
|
+
level: "error",
|
|
1375
|
+
msg: "1.2",
|
|
1376
|
+
},
|
|
1377
|
+
]);
|
|
1378
|
+
});
|
|
1379
|
+
it("2", async () => {
|
|
1380
|
+
logger.Error().Http(req, "Https").Msg("2");
|
|
1381
|
+
expect(await fixupLogs()).toEqual([
|
|
1382
|
+
{
|
|
1383
|
+
Https: {
|
|
1170
1384
|
body: ">Stream<",
|
|
1171
1385
|
bodyUsed: false,
|
|
1172
|
-
},
|
|
1173
|
-
req: {
|
|
1174
|
-
method: "PUT",
|
|
1175
|
-
url: "https://www.google.com/",
|
|
1176
1386
|
headers: {
|
|
1177
1387
|
"content-type": "text/html",
|
|
1178
1388
|
"x-test": "xtest",
|
|
1179
1389
|
},
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1390
|
+
integrity: "",
|
|
1391
|
+
isHistoryNavigation: false,
|
|
1392
|
+
keepalive: false,
|
|
1393
|
+
method: "PUT",
|
|
1183
1394
|
mode: "cors",
|
|
1184
|
-
credentials: "same-origin",
|
|
1185
|
-
cache: "default",
|
|
1186
1395
|
redirect: "follow",
|
|
1396
|
+
referrer: "about:client",
|
|
1397
|
+
referrerPolicy: "",
|
|
1398
|
+
signal: {
|
|
1399
|
+
aborted: false,
|
|
1400
|
+
onabort: "null",
|
|
1401
|
+
},
|
|
1402
|
+
url: "https://www.google.com/",
|
|
1403
|
+
},
|
|
1404
|
+
level: "error",
|
|
1405
|
+
msg: "2",
|
|
1406
|
+
},
|
|
1407
|
+
]);
|
|
1408
|
+
});
|
|
1409
|
+
it("3", async () => {
|
|
1410
|
+
logger.Error().Any("HttpReq", req).Msg("3");
|
|
1411
|
+
expect(await fixupLogs()).toEqual([
|
|
1412
|
+
{
|
|
1413
|
+
HttpReq: {
|
|
1414
|
+
body: ">Stream<",
|
|
1415
|
+
bodyUsed: false,
|
|
1416
|
+
headers: {
|
|
1417
|
+
"content-type": "text/html",
|
|
1418
|
+
"x-test": "xtest",
|
|
1419
|
+
},
|
|
1187
1420
|
integrity: "",
|
|
1188
|
-
keepalive: false,
|
|
1189
1421
|
isHistoryNavigation: false,
|
|
1422
|
+
keepalive: false,
|
|
1423
|
+
method: "PUT",
|
|
1424
|
+
mode: "cors",
|
|
1425
|
+
redirect: "follow",
|
|
1426
|
+
referrer: "about:client",
|
|
1427
|
+
referrerPolicy: "",
|
|
1190
1428
|
signal: {
|
|
1191
1429
|
aborted: false,
|
|
1192
1430
|
onabort: "null",
|
|
1193
1431
|
},
|
|
1194
|
-
|
|
1432
|
+
url: "https://www.google.com/",
|
|
1433
|
+
},
|
|
1434
|
+
level: "error",
|
|
1435
|
+
msg: "3",
|
|
1436
|
+
},
|
|
1437
|
+
]);
|
|
1438
|
+
});
|
|
1439
|
+
it("4", async () => {
|
|
1440
|
+
logger.Error().Any("HttpRes", resp).Msg("4");
|
|
1441
|
+
expect(await fixupLogs()).toEqual([
|
|
1442
|
+
{
|
|
1443
|
+
HttpRes: {
|
|
1444
|
+
body: ">Stream<",
|
|
1195
1445
|
bodyUsed: false,
|
|
1446
|
+
headers: {
|
|
1447
|
+
"content-type": "text/html",
|
|
1448
|
+
"x-test": "test",
|
|
1449
|
+
},
|
|
1450
|
+
ok: true,
|
|
1451
|
+
redirected: false,
|
|
1452
|
+
status: 200,
|
|
1453
|
+
statusText: "OK",
|
|
1454
|
+
type: "default",
|
|
1196
1455
|
},
|
|
1456
|
+
level: "error",
|
|
1457
|
+
msg: "4",
|
|
1197
1458
|
},
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
]);
|
|
1459
|
+
]);
|
|
1460
|
+
});
|
|
1201
1461
|
});
|
|
1202
1462
|
it("use toJSON", async () => {
|
|
1203
1463
|
logger
|
|
@@ -1238,5 +1498,24 @@ describe("TestLogger", () => {
|
|
|
1238
1498
|
},
|
|
1239
1499
|
].map((i) => JSON.stringify(i)));
|
|
1240
1500
|
});
|
|
1501
|
+
it("if uint8array is json do not hexdump", async () => {
|
|
1502
|
+
logger
|
|
1503
|
+
.Error()
|
|
1504
|
+
.Any("res", new TextEncoder().encode(JSON.stringify({ a: 1, b: { c: "x" } })))
|
|
1505
|
+
.Msg("ok");
|
|
1506
|
+
await logger.Flush();
|
|
1507
|
+
expect(logCollector.Logs()).toEqual([
|
|
1508
|
+
{
|
|
1509
|
+
level: "error",
|
|
1510
|
+
msg: "ok",
|
|
1511
|
+
res: {
|
|
1512
|
+
a: 1,
|
|
1513
|
+
b: {
|
|
1514
|
+
c: "x",
|
|
1515
|
+
},
|
|
1516
|
+
},
|
|
1517
|
+
},
|
|
1518
|
+
]);
|
|
1519
|
+
});
|
|
1241
1520
|
});
|
|
1242
1521
|
//# sourceMappingURL=logger.test.js.map
|