@adviser/cement 0.2.16 → 0.2.17
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 +147 -43
- package/index.cjs.map +1 -1
- package/index.d.cts +36 -20
- package/index.d.ts +36 -20
- package/index.js +144 -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,6 +1026,29 @@ 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 {
|
@@ -1102,7 +1127,7 @@ var LevelHandlerImpl = class {
|
|
1102
1127
|
}
|
1103
1128
|
};
|
1104
1129
|
var levelSingleton = new LevelHandlerImpl();
|
1105
|
-
var
|
1130
|
+
var LogWriterStream = class {
|
1106
1131
|
constructor(out) {
|
1107
1132
|
this._toFlush = [];
|
1108
1133
|
this._flushIsRunning = false;
|
@@ -1168,6 +1193,68 @@ function toLogValue(lop) {
|
|
1168
1193
|
}
|
1169
1194
|
return lop;
|
1170
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
|
+
};
|
1171
1258
|
var LoggerImpl = class _LoggerImpl {
|
1172
1259
|
// readonly _id: string = "logger-" + Math.random().toString(36)
|
1173
1260
|
constructor(params) {
|
@@ -1184,9 +1271,20 @@ var LoggerImpl = class _LoggerImpl {
|
|
1184
1271
|
this._logWriter = params.logWriter;
|
1185
1272
|
} else {
|
1186
1273
|
if (!params.out) {
|
1187
|
-
|
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);
|
1188
1286
|
} else {
|
1189
|
-
this._logWriter = new
|
1287
|
+
this._logWriter = new LogWriterStream(params.out);
|
1190
1288
|
}
|
1191
1289
|
}
|
1192
1290
|
if (!params.withAttributes) {
|
@@ -1483,37 +1581,60 @@ var WithLoggerBuilder = class {
|
|
1483
1581
|
};
|
1484
1582
|
|
1485
1583
|
// src/test/log_collector.ts
|
1486
|
-
var
|
1487
|
-
constructor() {
|
1488
|
-
this.
|
1584
|
+
var LogWriterCollector = class {
|
1585
|
+
constructor(bufferArr) {
|
1586
|
+
this._resolveClosed = new Future();
|
1587
|
+
this.closed = this._resolveClosed.asPromise();
|
1489
1588
|
this.desiredSize = null;
|
1490
1589
|
this.ready = Promise.resolve(void 0);
|
1491
|
-
this.
|
1492
|
-
};
|
1493
|
-
this.closed = new Promise((resolve) => {
|
1494
|
-
this._resolveClosed = resolve;
|
1495
|
-
});
|
1590
|
+
this._bufferArr = bufferArr;
|
1496
1591
|
}
|
1497
1592
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
1498
1593
|
abort(reason) {
|
1499
1594
|
throw new Error("Method not implemented.");
|
1500
1595
|
}
|
1501
|
-
close() {
|
1502
|
-
this.
|
1596
|
+
async close() {
|
1597
|
+
await this.closed;
|
1503
1598
|
return Promise.resolve(void 0);
|
1504
1599
|
}
|
1505
1600
|
releaseLock() {
|
1506
1601
|
}
|
1507
|
-
write(chunk) {
|
1602
|
+
async write(chunk) {
|
1508
1603
|
if (chunk) {
|
1509
1604
|
this._bufferArr.push(chunk);
|
1510
1605
|
}
|
1511
1606
|
return Promise.resolve(void 0);
|
1512
1607
|
}
|
1513
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
|
+
};
|
1514
1633
|
var LogCollector = class {
|
1515
|
-
constructor() {
|
1634
|
+
constructor(pass) {
|
1516
1635
|
this.locked = false;
|
1636
|
+
this._bufferArr = [];
|
1637
|
+
this._pass = pass;
|
1517
1638
|
}
|
1518
1639
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1519
1640
|
abort(reason) {
|
@@ -1529,7 +1650,11 @@ var LogCollector = class {
|
|
1529
1650
|
}
|
1530
1651
|
getWriter() {
|
1531
1652
|
if (!this._writer) {
|
1532
|
-
|
1653
|
+
const dests = [new LogWriterCollector(this._bufferArr)];
|
1654
|
+
if (this._pass) {
|
1655
|
+
dests.push(this._pass);
|
1656
|
+
}
|
1657
|
+
this._writer = new FanoutWriter(dests);
|
1533
1658
|
}
|
1534
1659
|
return this._writer;
|
1535
1660
|
}
|
@@ -1544,7 +1669,7 @@ var LogCollector = class {
|
|
1544
1669
|
for (const x of res) {
|
1545
1670
|
yield* __yieldStar(x);
|
1546
1671
|
}
|
1547
|
-
}(this.
|
1672
|
+
}(this._bufferArr)
|
1548
1673
|
)
|
1549
1674
|
);
|
1550
1675
|
const splitStr = jsonNlStr.split("\n");
|
@@ -1556,7 +1681,7 @@ var LogCollector = class {
|
|
1556
1681
|
|
1557
1682
|
// src/test/mock_logger.ts
|
1558
1683
|
function MockLogger(params) {
|
1559
|
-
const lc = new LogCollector();
|
1684
|
+
const lc = new LogCollector(params == null ? void 0 : params.pass);
|
1560
1685
|
let modNames = ["MockLogger"];
|
1561
1686
|
if (typeof (params == null ? void 0 : params.moduleName) === "string") {
|
1562
1687
|
modNames = [params == null ? void 0 : params.moduleName];
|
@@ -1699,29 +1824,6 @@ var None = class extends Option {
|
|
1699
1824
|
}
|
1700
1825
|
};
|
1701
1826
|
|
1702
|
-
// src/runtime.ts
|
1703
|
-
function isSet(value, ref = globalThis) {
|
1704
|
-
const [head, ...tail] = value.split(".");
|
1705
|
-
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
1706
|
-
if (tail.length <= 1) {
|
1707
|
-
return true;
|
1708
|
-
}
|
1709
|
-
return isSet(tail.join("."), ref[head]);
|
1710
|
-
}
|
1711
|
-
return false;
|
1712
|
-
}
|
1713
|
-
function runtimeFn() {
|
1714
|
-
const isReactNative = isSet("navigator.product") && globalThis.navigator.product === "ReactNative";
|
1715
|
-
const isNodeIsh = isSet("process.versions.node") && !isReactNative;
|
1716
|
-
const isDeno = isSet("Deno") && !isReactNative;
|
1717
|
-
return {
|
1718
|
-
isNodeIsh,
|
1719
|
-
isBrowser: !(isNodeIsh || isDeno) && !isReactNative,
|
1720
|
-
isDeno,
|
1721
|
-
isReactNative
|
1722
|
-
};
|
1723
|
-
}
|
1724
|
-
|
1725
1827
|
// src/crypto.ts
|
1726
1828
|
function randomBytes(size) {
|
1727
1829
|
const bytes = new Uint8Array(size);
|
@@ -1748,6 +1850,7 @@ function toCryptoRuntime(cryptoOpts = {}) {
|
|
1748
1850
|
BrowserEnvActions,
|
1749
1851
|
BuildURI,
|
1750
1852
|
EnvImpl,
|
1853
|
+
FanoutWriter,
|
1751
1854
|
Future,
|
1752
1855
|
IDMode,
|
1753
1856
|
IsLogger,
|
@@ -1758,7 +1861,8 @@ function toCryptoRuntime(cryptoOpts = {}) {
|
|
1758
1861
|
LevelHandlerImpl,
|
1759
1862
|
LogCollector,
|
1760
1863
|
LogValue,
|
1761
|
-
|
1864
|
+
LogWriterCollector,
|
1865
|
+
LogWriterStream,
|
1762
1866
|
LoggerImpl,
|
1763
1867
|
MockLogger,
|
1764
1868
|
None,
|