@adviser/cement 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs +247 -15
- package/index.cjs.map +1 -1
- package/index.d.cts +137 -7
- package/index.d.ts +137 -7
- package/index.js +241 -14
- package/index.js.map +1 -1
- package/package.json +10 -7
- package/utils/index.cjs +3 -1
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +3 -1
- package/utils/index.js.map +1 -1
package/index.cjs
CHANGED
@@ -75,6 +75,7 @@ var __yieldStar = (value) => {
|
|
75
75
|
var src_exports = {};
|
76
76
|
__export(src_exports, {
|
77
77
|
BrowserEnvActions: () => BrowserEnvActions,
|
78
|
+
BuildURI: () => BuildURI,
|
78
79
|
EnvImpl: () => EnvImpl,
|
79
80
|
Future: () => Future,
|
80
81
|
IDMode: () => IDMode,
|
@@ -102,9 +103,13 @@ __export(src_exports, {
|
|
102
103
|
Time: () => Time,
|
103
104
|
TimeMode: () => TimeMode,
|
104
105
|
TimeUnits: () => TimeUnits,
|
106
|
+
URI: () => URI,
|
107
|
+
asyncLogValue: () => asyncLogValue,
|
105
108
|
envFactory: () => envFactory,
|
106
109
|
logValue: () => logValue,
|
107
|
-
removeSelfRef: () => removeSelfRef
|
110
|
+
removeSelfRef: () => removeSelfRef,
|
111
|
+
runtimeFn: () => runtimeFn,
|
112
|
+
toCryptoRuntime: () => toCryptoRuntime
|
108
113
|
});
|
109
114
|
module.exports = __toCommonJS(src_exports);
|
110
115
|
|
@@ -137,6 +142,9 @@ function removeSelfRef() {
|
|
137
142
|
return value;
|
138
143
|
};
|
139
144
|
}
|
145
|
+
function asyncLogValue(val) {
|
146
|
+
throw new Error("Not implemented");
|
147
|
+
}
|
140
148
|
function logValue(val) {
|
141
149
|
switch (typeof val) {
|
142
150
|
case "function":
|
@@ -927,6 +935,30 @@ var LogWriter = class {
|
|
927
935
|
});
|
928
936
|
}
|
929
937
|
};
|
938
|
+
function getLen(value) {
|
939
|
+
if (Array.isArray(value)) {
|
940
|
+
return logValue(() => value.length);
|
941
|
+
} else if (typeof value === "string") {
|
942
|
+
return logValue(() => value.length);
|
943
|
+
} else if (typeof value === "object" && value !== null) {
|
944
|
+
if (typeof value.size === "number") {
|
945
|
+
return logValue(() => value.size);
|
946
|
+
} else if (typeof value.length === "number") {
|
947
|
+
return logValue(() => value.length);
|
948
|
+
}
|
949
|
+
return logValue(() => Object.keys(value).length);
|
950
|
+
}
|
951
|
+
return logValue(() => -1);
|
952
|
+
}
|
953
|
+
function hash(value) {
|
954
|
+
return "not implemented";
|
955
|
+
}
|
956
|
+
function toLogValue(lop) {
|
957
|
+
if (lop && typeof lop.then === "function") {
|
958
|
+
throw new Error("async logValue Not implemented");
|
959
|
+
}
|
960
|
+
return lop;
|
961
|
+
}
|
930
962
|
var LoggerImpl = class _LoggerImpl {
|
931
963
|
// readonly _id: string = "logger-" + Math.random().toString(36)
|
932
964
|
constructor(params) {
|
@@ -1036,15 +1068,11 @@ var LoggerImpl = class _LoggerImpl {
|
|
1036
1068
|
return this;
|
1037
1069
|
}
|
1038
1070
|
Len(value, key = "len") {
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
this._attributes[key] = logValue(() => Object.keys(value).length);
|
1045
|
-
} else {
|
1046
|
-
this.Int(key, -1);
|
1047
|
-
}
|
1071
|
+
this._attributes[key] = getLen(value);
|
1072
|
+
return this;
|
1073
|
+
}
|
1074
|
+
Hash(value, key = "hash") {
|
1075
|
+
this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
|
1048
1076
|
return this;
|
1049
1077
|
}
|
1050
1078
|
Url(url, key = "url") {
|
@@ -1102,7 +1130,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1102
1130
|
if (typeof msg === "string" && !msg.trim().length) {
|
1103
1131
|
delete attr["msg"];
|
1104
1132
|
}
|
1105
|
-
if (((_a = attr["ts"]) == null ? void 0 : _a.value()) === "ETERNITY") {
|
1133
|
+
if (((_a = toLogValue(attr["ts"])) == null ? void 0 : _a.value()) === "ETERNITY") {
|
1106
1134
|
this.Timestamp.call({
|
1107
1135
|
_sys: this._sys,
|
1108
1136
|
_attributes: attr
|
@@ -1113,7 +1141,10 @@ var LoggerImpl = class _LoggerImpl {
|
|
1113
1141
|
Msg(...args) {
|
1114
1142
|
const fnError = this._resetAttributes(() => {
|
1115
1143
|
var _a, _b;
|
1116
|
-
const doWrite = this._levelHandler.isEnabled(
|
1144
|
+
const doWrite = this._levelHandler.isEnabled(
|
1145
|
+
(_a = toLogValue(this._attributes["level"])) == null ? void 0 : _a.value(),
|
1146
|
+
(_b = toLogValue(this._attributes["module"])) == null ? void 0 : _b.value()
|
1147
|
+
);
|
1117
1148
|
let fnRet = () => this._produceError(__spreadValues({}, this._attributes), ...args);
|
1118
1149
|
if (doWrite) {
|
1119
1150
|
const str = fnRet();
|
@@ -1160,6 +1191,10 @@ var WithLoggerBuilder = class {
|
|
1160
1191
|
this._li.Len(value, key);
|
1161
1192
|
return this;
|
1162
1193
|
}
|
1194
|
+
Hash(value, key) {
|
1195
|
+
this._li.Hash(value, key);
|
1196
|
+
return this;
|
1197
|
+
}
|
1163
1198
|
Ref(key, action) {
|
1164
1199
|
this._li.Ref(key, action);
|
1165
1200
|
return this;
|
@@ -1249,7 +1284,9 @@ var LogWriter2 = class {
|
|
1249
1284
|
releaseLock() {
|
1250
1285
|
}
|
1251
1286
|
write(chunk) {
|
1252
|
-
|
1287
|
+
if (chunk) {
|
1288
|
+
this._bufferArr.push(chunk);
|
1289
|
+
}
|
1253
1290
|
return Promise.resolve(void 0);
|
1254
1291
|
}
|
1255
1292
|
};
|
@@ -1310,7 +1347,9 @@ function MockLogger(params) {
|
|
1310
1347
|
sys: params == null ? void 0 : params.sys,
|
1311
1348
|
levelHandler: new LevelHandlerImpl()
|
1312
1349
|
}).With().Module(modNames[0]).Logger();
|
1313
|
-
!(params == null ? void 0 : params.disableDebug)
|
1350
|
+
if (!(params == null ? void 0 : params.disableDebug)) {
|
1351
|
+
logger.SetDebug(...modNames);
|
1352
|
+
}
|
1314
1353
|
return {
|
1315
1354
|
logCollector: lc,
|
1316
1355
|
logger
|
@@ -1438,9 +1477,198 @@ var None = class extends Option {
|
|
1438
1477
|
throw new Error("None.unwrap");
|
1439
1478
|
}
|
1440
1479
|
};
|
1480
|
+
|
1481
|
+
// src/runtime.ts
|
1482
|
+
function isSet(value, ref = globalThis) {
|
1483
|
+
const [head, ...tail] = value.split(".");
|
1484
|
+
if (["object", "function"].includes(typeof ref) && ref && ["object", "function"].includes(typeof ref[head]) && ref[head]) {
|
1485
|
+
if (tail.length <= 1) {
|
1486
|
+
return true;
|
1487
|
+
}
|
1488
|
+
return isSet(tail.join("."), ref[head]);
|
1489
|
+
}
|
1490
|
+
return false;
|
1491
|
+
}
|
1492
|
+
function runtimeFn() {
|
1493
|
+
const isNodeIsh = isSet("process.versions.node");
|
1494
|
+
const isDeno = isSet("Deno");
|
1495
|
+
return {
|
1496
|
+
isNodeIsh,
|
1497
|
+
isBrowser: !(isNodeIsh || isDeno),
|
1498
|
+
isDeno,
|
1499
|
+
isReactNative: false
|
1500
|
+
};
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
// src/uri.ts
|
1504
|
+
function falsy2undef(value) {
|
1505
|
+
return value === void 0 || value === null ? void 0 : value;
|
1506
|
+
}
|
1507
|
+
function ensureURLWithDefaultProto(url, defaultProtocol) {
|
1508
|
+
if (!url) {
|
1509
|
+
return new URL(`${defaultProtocol}//`);
|
1510
|
+
}
|
1511
|
+
if (typeof url === "string") {
|
1512
|
+
try {
|
1513
|
+
return new URL(url);
|
1514
|
+
} catch (e) {
|
1515
|
+
return new URL(`${defaultProtocol}//${url}`);
|
1516
|
+
}
|
1517
|
+
} else {
|
1518
|
+
return url;
|
1519
|
+
}
|
1520
|
+
}
|
1521
|
+
var BuildURI = class {
|
1522
|
+
constructor(url) {
|
1523
|
+
this._url = url;
|
1524
|
+
}
|
1525
|
+
hostname(h) {
|
1526
|
+
this._url.hostname = h;
|
1527
|
+
return this;
|
1528
|
+
}
|
1529
|
+
password(p) {
|
1530
|
+
this._url.password = p;
|
1531
|
+
return this;
|
1532
|
+
}
|
1533
|
+
port(p) {
|
1534
|
+
this._url.port = p;
|
1535
|
+
return this;
|
1536
|
+
}
|
1537
|
+
username(u) {
|
1538
|
+
this._url.username = u;
|
1539
|
+
return this;
|
1540
|
+
}
|
1541
|
+
search(s) {
|
1542
|
+
this._url.search = s;
|
1543
|
+
return this;
|
1544
|
+
}
|
1545
|
+
protocol(p) {
|
1546
|
+
this._url.protocol = p;
|
1547
|
+
return this;
|
1548
|
+
}
|
1549
|
+
pathname(p) {
|
1550
|
+
this._url.pathname = p;
|
1551
|
+
return this;
|
1552
|
+
}
|
1553
|
+
hash(h) {
|
1554
|
+
this._url.hash = h;
|
1555
|
+
return this;
|
1556
|
+
}
|
1557
|
+
host(h) {
|
1558
|
+
this._url.host = h;
|
1559
|
+
return this;
|
1560
|
+
}
|
1561
|
+
delParam(key) {
|
1562
|
+
this._url.searchParams.delete(key);
|
1563
|
+
return this;
|
1564
|
+
}
|
1565
|
+
setParam(key, str) {
|
1566
|
+
this._url.searchParams.set(key, str);
|
1567
|
+
return this;
|
1568
|
+
}
|
1569
|
+
toString() {
|
1570
|
+
return this._url.toString();
|
1571
|
+
}
|
1572
|
+
build() {
|
1573
|
+
return URI.from(this._url);
|
1574
|
+
}
|
1575
|
+
};
|
1576
|
+
var URI = class _URI {
|
1577
|
+
// if no protocol is provided, default to file:
|
1578
|
+
static from(strURLUri, defaultProtocol = "file:") {
|
1579
|
+
switch (typeof falsy2undef(strURLUri)) {
|
1580
|
+
case "undefined":
|
1581
|
+
return new _URI(new URL(`${defaultProtocol}//`));
|
1582
|
+
case "string":
|
1583
|
+
return new _URI(ensureURLWithDefaultProto(strURLUri, defaultProtocol));
|
1584
|
+
case "object":
|
1585
|
+
if (strURLUri instanceof _URI) {
|
1586
|
+
return new _URI(new URL(strURLUri._url.toString()));
|
1587
|
+
} else if (strURLUri instanceof URL) {
|
1588
|
+
return new _URI(new URL(strURLUri.toString()));
|
1589
|
+
}
|
1590
|
+
throw new Error(`unknown object type: ${strURLUri}`);
|
1591
|
+
default:
|
1592
|
+
throw new Error(`Invalid argument: ${typeof strURLUri}`);
|
1593
|
+
}
|
1594
|
+
}
|
1595
|
+
constructor(url) {
|
1596
|
+
this._url = url;
|
1597
|
+
}
|
1598
|
+
build() {
|
1599
|
+
return new BuildURI(this.asURL());
|
1600
|
+
}
|
1601
|
+
get hostname() {
|
1602
|
+
return this._url.hostname;
|
1603
|
+
}
|
1604
|
+
get password() {
|
1605
|
+
return this._url.password;
|
1606
|
+
}
|
1607
|
+
get port() {
|
1608
|
+
return this._url.port;
|
1609
|
+
}
|
1610
|
+
get username() {
|
1611
|
+
return this._url.username;
|
1612
|
+
}
|
1613
|
+
get search() {
|
1614
|
+
return this._url.search;
|
1615
|
+
}
|
1616
|
+
get protocol() {
|
1617
|
+
return this._url.protocol;
|
1618
|
+
}
|
1619
|
+
get pathname() {
|
1620
|
+
return this._url.toString().replace(/^.*:\/\//, "").replace(/\?.*$/, "");
|
1621
|
+
}
|
1622
|
+
get hash() {
|
1623
|
+
return this._url.hash;
|
1624
|
+
}
|
1625
|
+
get host() {
|
1626
|
+
return this._url.host;
|
1627
|
+
}
|
1628
|
+
hasParam(key) {
|
1629
|
+
return this._url.searchParams.has(key);
|
1630
|
+
}
|
1631
|
+
getParam(key) {
|
1632
|
+
return falsy2undef(this._url.searchParams.get(key));
|
1633
|
+
}
|
1634
|
+
clone() {
|
1635
|
+
return new _URI(this.asURL());
|
1636
|
+
}
|
1637
|
+
asURL() {
|
1638
|
+
const url = new URL(this._url.toString());
|
1639
|
+
url.searchParams.sort();
|
1640
|
+
return url;
|
1641
|
+
}
|
1642
|
+
toString() {
|
1643
|
+
return this._url.toString();
|
1644
|
+
}
|
1645
|
+
};
|
1646
|
+
|
1647
|
+
// src/crypto.ts
|
1648
|
+
function randomBytes(size) {
|
1649
|
+
const bytes = new Uint8Array(size);
|
1650
|
+
if (size > 0) {
|
1651
|
+
crypto.getRandomValues(bytes);
|
1652
|
+
}
|
1653
|
+
return bytes;
|
1654
|
+
}
|
1655
|
+
function digestSHA256(data) {
|
1656
|
+
return Promise.resolve(crypto.subtle.digest("SHA-256", data));
|
1657
|
+
}
|
1658
|
+
function toCryptoRuntime(cryptoOpts = {}) {
|
1659
|
+
const runtime = {
|
1660
|
+
importKey: cryptoOpts.importKey || crypto.subtle.importKey.bind(crypto.subtle),
|
1661
|
+
encrypt: cryptoOpts.encrypt || crypto.subtle.encrypt.bind(crypto.subtle),
|
1662
|
+
decrypt: cryptoOpts.decrypt || crypto.subtle.decrypt.bind(crypto.subtle),
|
1663
|
+
randomBytes: cryptoOpts.randomBytes || randomBytes,
|
1664
|
+
digestSHA256: cryptoOpts.digestSHA256 || digestSHA256
|
1665
|
+
};
|
1666
|
+
return runtime;
|
1667
|
+
}
|
1441
1668
|
// Annotate the CommonJS export names for ESM import in node:
|
1442
1669
|
0 && (module.exports = {
|
1443
1670
|
BrowserEnvActions,
|
1671
|
+
BuildURI,
|
1444
1672
|
EnvImpl,
|
1445
1673
|
Future,
|
1446
1674
|
IDMode,
|
@@ -1468,8 +1696,12 @@ var None = class extends Option {
|
|
1468
1696
|
Time,
|
1469
1697
|
TimeMode,
|
1470
1698
|
TimeUnits,
|
1699
|
+
URI,
|
1700
|
+
asyncLogValue,
|
1471
1701
|
envFactory,
|
1472
1702
|
logValue,
|
1473
|
-
removeSelfRef
|
1703
|
+
removeSelfRef,
|
1704
|
+
runtimeFn,
|
1705
|
+
toCryptoRuntime
|
1474
1706
|
});
|
1475
1707
|
//# sourceMappingURL=index.cjs.map
|