@adviser/cement 0.2.15 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +163 -43
- package/index.cjs.map +1 -1
- package/index.d.cts +46 -24
- package/index.d.ts +46 -24
- package/index.js +160 -42
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
@@ -77,6 +77,7 @@ __export(src_exports, {
|
|
77
77
|
BrowserEnvActions: () => BrowserEnvActions,
|
78
78
|
BuildURI: () => BuildURI,
|
79
79
|
EnvImpl: () => EnvImpl,
|
80
|
+
FanoutWriter: () => FanoutWriter,
|
80
81
|
Future: () => Future,
|
81
82
|
IDMode: () => IDMode,
|
82
83
|
IsLogger: () => IsLogger,
|
@@ -87,7 +88,8 @@ __export(src_exports, {
|
|
87
88
|
LevelHandlerImpl: () => LevelHandlerImpl,
|
88
89
|
LogCollector: () => LogCollector,
|
89
90
|
LogValue: () => LogValue,
|
90
|
-
|
91
|
+
LogWriterCollector: () => LogWriterCollector,
|
92
|
+
LogWriterStream: () => LogWriterStream,
|
91
93
|
LoggerImpl: () => LoggerImpl,
|
92
94
|
MockLogger: () => MockLogger,
|
93
95
|
None: () => None,
|
@@ -1024,12 +1026,36 @@ var URI = class _URI {
|
|
1024
1026
|
}
|
1025
1027
|
};
|
1026
1028
|
|
1029
|
+
// src/runtime.ts
|
1030
|
+
function isSet(value, ref = globalThis) {
|
1031
|
+
const [head, ...tail] = value.split(".");
|
1032
|
+
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
1033
|
+
if (tail.length <= 1) {
|
1034
|
+
return true;
|
1035
|
+
}
|
1036
|
+
return isSet(tail.join("."), ref[head]);
|
1037
|
+
}
|
1038
|
+
return false;
|
1039
|
+
}
|
1040
|
+
function runtimeFn() {
|
1041
|
+
const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
|
1042
|
+
const isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
1043
|
+
const isDeno = isSet("Deno") && !isReactNative;
|
1044
|
+
return {
|
1045
|
+
isNodeIsh,
|
1046
|
+
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
1047
|
+
isDeno,
|
1048
|
+
isReactNative
|
1049
|
+
};
|
1050
|
+
}
|
1051
|
+
|
1027
1052
|
// src/logger_impl.ts
|
1028
1053
|
var encoder = new TextEncoder();
|
1029
1054
|
var LevelHandlerImpl = class {
|
1030
1055
|
constructor() {
|
1031
1056
|
this._globalLevels = /* @__PURE__ */ new Set(["info" /* INFO */, "error" /* ERROR */, "warn" /* WARN */]);
|
1032
1057
|
this._modules = /* @__PURE__ */ new Map();
|
1058
|
+
this.isStackExposed = false;
|
1033
1059
|
}
|
1034
1060
|
enableLevel(level, ...modules) {
|
1035
1061
|
if (modules.length == 0) {
|
@@ -1057,6 +1083,9 @@ var LevelHandlerImpl = class {
|
|
1057
1083
|
...modules
|
1058
1084
|
);
|
1059
1085
|
}
|
1086
|
+
setExposeStack(enable) {
|
1087
|
+
this.isStackExposed = !!enable;
|
1088
|
+
}
|
1060
1089
|
forModules(level, fnAction, ...modules) {
|
1061
1090
|
for (const m of modules.flat()) {
|
1062
1091
|
if (typeof m !== "string") {
|
@@ -1098,7 +1127,7 @@ var LevelHandlerImpl = class {
|
|
1098
1127
|
}
|
1099
1128
|
};
|
1100
1129
|
var levelSingleton = new LevelHandlerImpl();
|
1101
|
-
var
|
1130
|
+
var LogWriterStream = class {
|
1102
1131
|
constructor(out) {
|
1103
1132
|
this._toFlush = [];
|
1104
1133
|
this._flushIsRunning = false;
|
@@ -1164,6 +1193,68 @@ function toLogValue(lop) {
|
|
1164
1193
|
}
|
1165
1194
|
return lop;
|
1166
1195
|
}
|
1196
|
+
var ConsoleWriterStreamDefaultWriter = class {
|
1197
|
+
constructor(stream) {
|
1198
|
+
this.stream = stream;
|
1199
|
+
this.desiredSize = null;
|
1200
|
+
this.decoder = new TextDecoder();
|
1201
|
+
this._stream = stream;
|
1202
|
+
this.ready = Promise.resolve(void 0);
|
1203
|
+
this.closed = Promise.resolve(void 0);
|
1204
|
+
}
|
1205
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
1206
|
+
abort(reason) {
|
1207
|
+
throw new Error("Method not implemented.");
|
1208
|
+
}
|
1209
|
+
async close() {
|
1210
|
+
}
|
1211
|
+
releaseLock() {
|
1212
|
+
this._stream.locked = false;
|
1213
|
+
this.ready = Promise.resolve(void 0);
|
1214
|
+
this.closed = Promise.resolve(void 0);
|
1215
|
+
}
|
1216
|
+
async write(chunk) {
|
1217
|
+
const str = this.decoder.decode(chunk).trimEnd();
|
1218
|
+
let output = "log";
|
1219
|
+
try {
|
1220
|
+
const decode = JSON.parse(str);
|
1221
|
+
output = decode.level;
|
1222
|
+
} catch (e) {
|
1223
|
+
}
|
1224
|
+
switch (output) {
|
1225
|
+
case "error":
|
1226
|
+
console.error(str);
|
1227
|
+
break;
|
1228
|
+
case "warn":
|
1229
|
+
console.warn(str);
|
1230
|
+
break;
|
1231
|
+
default:
|
1232
|
+
console.log(str);
|
1233
|
+
}
|
1234
|
+
}
|
1235
|
+
};
|
1236
|
+
var ConsoleWriterStream = class {
|
1237
|
+
constructor() {
|
1238
|
+
this.locked = false;
|
1239
|
+
}
|
1240
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
1241
|
+
abort(reason) {
|
1242
|
+
throw new Error("Method not implemented.");
|
1243
|
+
}
|
1244
|
+
async close() {
|
1245
|
+
return;
|
1246
|
+
}
|
1247
|
+
getWriter() {
|
1248
|
+
if (this.locked) {
|
1249
|
+
throw new Error("Stream is locked");
|
1250
|
+
}
|
1251
|
+
this.locked = true;
|
1252
|
+
if (!this._writer) {
|
1253
|
+
this._writer = new ConsoleWriterStreamDefaultWriter(this);
|
1254
|
+
}
|
1255
|
+
return this._writer;
|
1256
|
+
}
|
1257
|
+
};
|
1167
1258
|
var LoggerImpl = class _LoggerImpl {
|
1168
1259
|
// readonly _id: string = "logger-" + Math.random().toString(36)
|
1169
1260
|
constructor(params) {
|
@@ -1180,9 +1271,20 @@ var LoggerImpl = class _LoggerImpl {
|
|
1180
1271
|
this._logWriter = params.logWriter;
|
1181
1272
|
} else {
|
1182
1273
|
if (!params.out) {
|
1183
|
-
|
1274
|
+
const rt = runtimeFn();
|
1275
|
+
let stream;
|
1276
|
+
if (rt.isBrowser) {
|
1277
|
+
stream = new ConsoleWriterStream();
|
1278
|
+
} else {
|
1279
|
+
if (rt.isNodeIsh || rt.isReactNative) {
|
1280
|
+
stream = this._sys.Stdout();
|
1281
|
+
} else {
|
1282
|
+
throw new Error("No output defined for runtime");
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
this._logWriter = new LogWriterStream(stream);
|
1184
1286
|
} else {
|
1185
|
-
this._logWriter = new
|
1287
|
+
this._logWriter = new LogWriterStream(params.out);
|
1186
1288
|
}
|
1187
1289
|
}
|
1188
1290
|
if (!params.withAttributes) {
|
@@ -1197,6 +1299,10 @@ var LoggerImpl = class _LoggerImpl {
|
|
1197
1299
|
this._levelHandler = levelSingleton;
|
1198
1300
|
}
|
1199
1301
|
}
|
1302
|
+
SetExposeStack(enable) {
|
1303
|
+
this._levelHandler.setExposeStack(enable);
|
1304
|
+
return this;
|
1305
|
+
}
|
1200
1306
|
EnableLevel(level, ...modules) {
|
1201
1307
|
this._levelHandler.enableLevel(level, ...modules);
|
1202
1308
|
return this;
|
@@ -1239,8 +1345,12 @@ var LoggerImpl = class _LoggerImpl {
|
|
1239
1345
|
return this;
|
1240
1346
|
}
|
1241
1347
|
Err(err) {
|
1348
|
+
var _a;
|
1242
1349
|
if (err instanceof Error) {
|
1243
1350
|
this._attributes["error"] = logValue(err.message);
|
1351
|
+
if (this._levelHandler.isStackExposed) {
|
1352
|
+
this._attributes["stack"] = logValue((_a = err.stack) == null ? void 0 : _a.split("\n").map((s) => s.trim()));
|
1353
|
+
}
|
1244
1354
|
} else {
|
1245
1355
|
this._attributes["error"] = logValue("" + err);
|
1246
1356
|
}
|
@@ -1372,6 +1482,10 @@ var WithLoggerBuilder = class {
|
|
1372
1482
|
Object.assign(this._li._withAttributes, this._li._attributes);
|
1373
1483
|
return this._li;
|
1374
1484
|
}
|
1485
|
+
SetExposeStack(enable) {
|
1486
|
+
this._li._levelHandler.setExposeStack(enable);
|
1487
|
+
return this;
|
1488
|
+
}
|
1375
1489
|
EnableLevel(level, ...modules) {
|
1376
1490
|
this._li._levelHandler.enableLevel(level, ...modules);
|
1377
1491
|
return this;
|
@@ -1467,37 +1581,60 @@ var WithLoggerBuilder = class {
|
|
1467
1581
|
};
|
1468
1582
|
|
1469
1583
|
// src/test/log_collector.ts
|
1470
|
-
var
|
1471
|
-
constructor() {
|
1472
|
-
this.
|
1584
|
+
var LogWriterCollector = class {
|
1585
|
+
constructor(bufferArr) {
|
1586
|
+
this._resolveClosed = new Future();
|
1587
|
+
this.closed = this._resolveClosed.asPromise();
|
1473
1588
|
this.desiredSize = null;
|
1474
1589
|
this.ready = Promise.resolve(void 0);
|
1475
|
-
this.
|
1476
|
-
};
|
1477
|
-
this.closed = new Promise((resolve) => {
|
1478
|
-
this._resolveClosed = resolve;
|
1479
|
-
});
|
1590
|
+
this._bufferArr = bufferArr;
|
1480
1591
|
}
|
1481
1592
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
1482
1593
|
abort(reason) {
|
1483
1594
|
throw new Error("Method not implemented.");
|
1484
1595
|
}
|
1485
|
-
close() {
|
1486
|
-
this.
|
1596
|
+
async close() {
|
1597
|
+
await this.closed;
|
1487
1598
|
return Promise.resolve(void 0);
|
1488
1599
|
}
|
1489
1600
|
releaseLock() {
|
1490
1601
|
}
|
1491
|
-
write(chunk) {
|
1602
|
+
async write(chunk) {
|
1492
1603
|
if (chunk) {
|
1493
1604
|
this._bufferArr.push(chunk);
|
1494
1605
|
}
|
1495
1606
|
return Promise.resolve(void 0);
|
1496
1607
|
}
|
1497
1608
|
};
|
1609
|
+
var FanoutWriter = class {
|
1610
|
+
constructor(writers) {
|
1611
|
+
this.desiredSize = null;
|
1612
|
+
this._writers = writers;
|
1613
|
+
this.ready = Promise.all(this._writers.map((w) => w.ready)).then(() => void 0);
|
1614
|
+
this.closed = Promise.all(this._writers.map((w) => w.closed)).then(() => void 0);
|
1615
|
+
}
|
1616
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1617
|
+
abort(reason) {
|
1618
|
+
return Promise.all(this._writers.map((w) => w.abort(reason))).then(() => {
|
1619
|
+
});
|
1620
|
+
}
|
1621
|
+
close() {
|
1622
|
+
return Promise.all(this._writers.map((w) => w.close())).then(() => {
|
1623
|
+
});
|
1624
|
+
}
|
1625
|
+
releaseLock() {
|
1626
|
+
this._writers.map((w) => w.releaseLock());
|
1627
|
+
}
|
1628
|
+
write(chunk) {
|
1629
|
+
return Promise.all(this._writers.map((w) => w.write(chunk))).then(() => {
|
1630
|
+
});
|
1631
|
+
}
|
1632
|
+
};
|
1498
1633
|
var LogCollector = class {
|
1499
|
-
constructor() {
|
1634
|
+
constructor(pass) {
|
1500
1635
|
this.locked = false;
|
1636
|
+
this._bufferArr = [];
|
1637
|
+
this._pass = pass;
|
1501
1638
|
}
|
1502
1639
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1503
1640
|
abort(reason) {
|
@@ -1513,7 +1650,11 @@ var LogCollector = class {
|
|
1513
1650
|
}
|
1514
1651
|
getWriter() {
|
1515
1652
|
if (!this._writer) {
|
1516
|
-
|
1653
|
+
const dests = [new LogWriterCollector(this._bufferArr)];
|
1654
|
+
if (this._pass) {
|
1655
|
+
dests.push(this._pass);
|
1656
|
+
}
|
1657
|
+
this._writer = new FanoutWriter(dests);
|
1517
1658
|
}
|
1518
1659
|
return this._writer;
|
1519
1660
|
}
|
@@ -1528,7 +1669,7 @@ var LogCollector = class {
|
|
1528
1669
|
for (const x of res) {
|
1529
1670
|
yield* __yieldStar(x);
|
1530
1671
|
}
|
1531
|
-
}(this.
|
1672
|
+
}(this._bufferArr)
|
1532
1673
|
)
|
1533
1674
|
);
|
1534
1675
|
const splitStr = jsonNlStr.split("\n");
|
@@ -1540,7 +1681,7 @@ var LogCollector = class {
|
|
1540
1681
|
|
1541
1682
|
// src/test/mock_logger.ts
|
1542
1683
|
function MockLogger(params) {
|
1543
|
-
const lc = new LogCollector();
|
1684
|
+
const lc = new LogCollector(params == null ? void 0 : params.pass);
|
1544
1685
|
let modNames = ["MockLogger"];
|
1545
1686
|
if (typeof (params == null ? void 0 : params.moduleName) === "string") {
|
1546
1687
|
modNames = [params == null ? void 0 : params.moduleName];
|
@@ -1683,29 +1824,6 @@ var None = class extends Option {
|
|
1683
1824
|
}
|
1684
1825
|
};
|
1685
1826
|
|
1686
|
-
// src/runtime.ts
|
1687
|
-
function isSet(value, ref = globalThis) {
|
1688
|
-
const [head, ...tail] = value.split(".");
|
1689
|
-
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
1690
|
-
if (tail.length <= 1) {
|
1691
|
-
return true;
|
1692
|
-
}
|
1693
|
-
return isSet(tail.join("."), ref[head]);
|
1694
|
-
}
|
1695
|
-
return false;
|
1696
|
-
}
|
1697
|
-
function runtimeFn() {
|
1698
|
-
const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
|
1699
|
-
const isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
1700
|
-
const isDeno = isSet("Deno") && !isReactNative;
|
1701
|
-
return {
|
1702
|
-
isNodeIsh,
|
1703
|
-
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
1704
|
-
isDeno,
|
1705
|
-
isReactNative
|
1706
|
-
};
|
1707
|
-
}
|
1708
|
-
|
1709
1827
|
// src/crypto.ts
|
1710
1828
|
function randomBytes(size) {
|
1711
1829
|
const bytes = new Uint8Array(size);
|
@@ -1732,6 +1850,7 @@ function toCryptoRuntime(cryptoOpts = {}) {
|
|
1732
1850
|
BrowserEnvActions,
|
1733
1851
|
BuildURI,
|
1734
1852
|
EnvImpl,
|
1853
|
+
FanoutWriter,
|
1735
1854
|
Future,
|
1736
1855
|
IDMode,
|
1737
1856
|
IsLogger,
|
@@ -1742,7 +1861,8 @@ function toCryptoRuntime(cryptoOpts = {}) {
|
|
1742
1861
|
LevelHandlerImpl,
|
1743
1862
|
LogCollector,
|
1744
1863
|
LogValue,
|
1745
|
-
|
1864
|
+
LogWriterCollector,
|
1865
|
+
LogWriterStream,
|
1746
1866
|
LoggerImpl,
|
1747
1867
|
MockLogger,
|
1748
1868
|
None,
|