@adviser/cement 0.2.31 → 0.2.33
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 +122 -29
- package/index.cjs.map +1 -1
- package/index.d.cts +12 -4
- package/index.d.ts +12 -4
- package/index.js +121 -27
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/jsr.json +1 -1
- package/src/logger-impl.ts +3 -1
- package/src/logger.ts +1 -0
- package/src/uri.ts +82 -4
- package/ts/index.d.ts +0 -1
- package/ts/index.d.ts.map +1 -1
- package/ts/index.js +0 -1
- package/ts/index.js.map +1 -1
- package/ts/logger-impl.d.ts.map +1 -1
- package/ts/logger-impl.js +3 -1
- package/ts/logger-impl.js.map +1 -1
- package/ts/logger.d.ts +1 -0
- package/ts/logger.d.ts.map +1 -1
- package/ts/logger.test.js +14 -0
- package/ts/logger.test.js.map +1 -1
- package/ts/uri.d.ts +9 -1
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +66 -4
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +64 -0
- package/ts/uri.test.js.map +1 -1
- package/src/refcounted.ts +0 -23
- package/ts/refcounted.d.ts +0 -2
- package/ts/refcounted.d.ts.map +0 -1
- package/ts/refcounted.js +0 -19
- package/ts/refcounted.js.map +0 -1
- package/ts/refcounted.test.d.ts +0 -2
- package/ts/refcounted.test.d.ts.map +0 -1
- package/ts/refcounted.test.js +0 -39
- package/ts/refcounted.test.js.map +0 -1
package/index.cjs
CHANGED
|
@@ -146,8 +146,7 @@ __export(src_exports, {
|
|
|
146
146
|
removeSelfRef: () => removeSelfRef,
|
|
147
147
|
runtimeFn: () => runtimeFn,
|
|
148
148
|
toCryptoRuntime: () => toCryptoRuntime,
|
|
149
|
-
utils: () => utils_exports
|
|
150
|
-
wrapRefcounted: () => wrapRefcounted
|
|
149
|
+
utils: () => utils_exports
|
|
151
150
|
});
|
|
152
151
|
module.exports = __toCommonJS(src_exports);
|
|
153
152
|
|
|
@@ -1052,6 +1051,61 @@ function exception2Result(fn) {
|
|
|
1052
1051
|
}
|
|
1053
1052
|
}
|
|
1054
1053
|
|
|
1054
|
+
// src/utils/stripper.ts
|
|
1055
|
+
function stripper(strip, obj) {
|
|
1056
|
+
const strips = Array.isArray(strip) ? strip : [strip];
|
|
1057
|
+
const restrips = strips.map((s) => {
|
|
1058
|
+
if (typeof s === "string") {
|
|
1059
|
+
const escaped = s.replace(/[-\\[\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g, "\\$&");
|
|
1060
|
+
return new RegExp(`^${escaped}$`);
|
|
1061
|
+
}
|
|
1062
|
+
return s;
|
|
1063
|
+
});
|
|
1064
|
+
return localStripper(void 0, restrips, obj);
|
|
1065
|
+
}
|
|
1066
|
+
function localStripper(path, restrips, obj) {
|
|
1067
|
+
if (typeof obj !== "object" || obj === null) {
|
|
1068
|
+
return obj;
|
|
1069
|
+
}
|
|
1070
|
+
const ret = __spreadValues({}, obj);
|
|
1071
|
+
const matcher = (key, nextPath) => {
|
|
1072
|
+
for (const re of restrips) {
|
|
1073
|
+
if (re.test(key) || re.test(nextPath)) {
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
return false;
|
|
1078
|
+
};
|
|
1079
|
+
for (const key in ret) {
|
|
1080
|
+
if (Object.prototype.hasOwnProperty.call(ret, key)) {
|
|
1081
|
+
let nextPath;
|
|
1082
|
+
if (path) {
|
|
1083
|
+
nextPath = [path, key].join(".");
|
|
1084
|
+
} else {
|
|
1085
|
+
nextPath = key;
|
|
1086
|
+
}
|
|
1087
|
+
if (matcher(key, nextPath)) {
|
|
1088
|
+
delete ret[key];
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
if (typeof ret[key] === "object") {
|
|
1092
|
+
if (Array.isArray(ret[key])) {
|
|
1093
|
+
ret[key] = ret[key].reduce((acc, v, i) => {
|
|
1094
|
+
const toDelete = matcher(key, `${nextPath}[${i}]`);
|
|
1095
|
+
if (!toDelete) {
|
|
1096
|
+
acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
|
|
1097
|
+
}
|
|
1098
|
+
return acc;
|
|
1099
|
+
}, []);
|
|
1100
|
+
} else {
|
|
1101
|
+
ret[key] = localStripper(nextPath, restrips, ret[key]);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return ret;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1055
1109
|
// src/uri.ts
|
|
1056
1110
|
function falsy2undef(value) {
|
|
1057
1111
|
return value === void 0 || value === null ? void 0 : value;
|
|
@@ -1190,6 +1244,35 @@ function from(fac, strURLUri, defaultProtocol) {
|
|
|
1190
1244
|
throw new Error(`Invalid argument: ${typeof strURLUri}`);
|
|
1191
1245
|
}
|
|
1192
1246
|
}
|
|
1247
|
+
function getParamResult(key, val, msgFn = (key2) => {
|
|
1248
|
+
return `missing parameter: ${key2}`;
|
|
1249
|
+
}) {
|
|
1250
|
+
if (val === void 0) {
|
|
1251
|
+
return Result.Err(msgFn(key));
|
|
1252
|
+
}
|
|
1253
|
+
return Result.Ok(val);
|
|
1254
|
+
}
|
|
1255
|
+
function getParamsResult(keys, getParam) {
|
|
1256
|
+
const keyStrs = keys.flat().filter((k) => typeof k === "string");
|
|
1257
|
+
const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
|
|
1258
|
+
const msg = keys2.join(",");
|
|
1259
|
+
return `missing parameters: ${msg}`;
|
|
1260
|
+
});
|
|
1261
|
+
const errors = [];
|
|
1262
|
+
const result = {};
|
|
1263
|
+
for (const key of keyStrs) {
|
|
1264
|
+
const val = getParam.getParam(key);
|
|
1265
|
+
if (val === void 0) {
|
|
1266
|
+
errors.push(key);
|
|
1267
|
+
} else {
|
|
1268
|
+
result[key] = val;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
if (errors.length) {
|
|
1272
|
+
return Result.Err(msgFn(...errors));
|
|
1273
|
+
}
|
|
1274
|
+
return Result.Ok(result);
|
|
1275
|
+
}
|
|
1193
1276
|
var BuildURI = class _BuildURI {
|
|
1194
1277
|
// pathname needs this
|
|
1195
1278
|
constructor(url) {
|
|
@@ -1241,6 +1324,20 @@ var BuildURI = class _BuildURI {
|
|
|
1241
1324
|
// this._url.host = h;
|
|
1242
1325
|
// return this;
|
|
1243
1326
|
// }
|
|
1327
|
+
appendRelative(p) {
|
|
1328
|
+
const url = URI.from(p);
|
|
1329
|
+
let pathname = url.pathname;
|
|
1330
|
+
if (url.pathname === "/") {
|
|
1331
|
+
pathname = "";
|
|
1332
|
+
} else if (!pathname.startsWith("/")) {
|
|
1333
|
+
pathname = `/${pathname}`;
|
|
1334
|
+
}
|
|
1335
|
+
this.pathname(this._url.pathname + pathname);
|
|
1336
|
+
for (const [key, value] of url.getParams) {
|
|
1337
|
+
this.setParam(key, value);
|
|
1338
|
+
}
|
|
1339
|
+
return this;
|
|
1340
|
+
}
|
|
1244
1341
|
delParam(key) {
|
|
1245
1342
|
this._url.searchParams.delete(key);
|
|
1246
1343
|
return this;
|
|
@@ -1261,6 +1358,12 @@ var BuildURI = class _BuildURI {
|
|
|
1261
1358
|
getParam(key) {
|
|
1262
1359
|
return falsy2undef(this._url.searchParams.get(key));
|
|
1263
1360
|
}
|
|
1361
|
+
getParamResult(key, msgFn) {
|
|
1362
|
+
return getParamResult(key, this.getParam(key), msgFn);
|
|
1363
|
+
}
|
|
1364
|
+
getParamsResult(...keys) {
|
|
1365
|
+
return getParamsResult(keys, this);
|
|
1366
|
+
}
|
|
1264
1367
|
toString() {
|
|
1265
1368
|
this._url.searchParams.sort();
|
|
1266
1369
|
return this._url.toString();
|
|
@@ -1268,6 +1371,9 @@ var BuildURI = class _BuildURI {
|
|
|
1268
1371
|
toJSON() {
|
|
1269
1372
|
return this.toString();
|
|
1270
1373
|
}
|
|
1374
|
+
asObj(...strips) {
|
|
1375
|
+
return this.URI().asObj(...strips);
|
|
1376
|
+
}
|
|
1271
1377
|
URI() {
|
|
1272
1378
|
return URI.from(this._url);
|
|
1273
1379
|
}
|
|
@@ -1350,6 +1456,12 @@ var URI = class _URI {
|
|
|
1350
1456
|
getParam(key) {
|
|
1351
1457
|
return falsy2undef(this._url.searchParams.get(key));
|
|
1352
1458
|
}
|
|
1459
|
+
getParamResult(key, msgFn) {
|
|
1460
|
+
return getParamResult(key, this.getParam(key), msgFn);
|
|
1461
|
+
}
|
|
1462
|
+
getParamsResult(...keys) {
|
|
1463
|
+
return getParamsResult(keys, this);
|
|
1464
|
+
}
|
|
1353
1465
|
clone() {
|
|
1354
1466
|
return new _URI(this._url);
|
|
1355
1467
|
}
|
|
@@ -1362,7 +1474,7 @@ var URI = class _URI {
|
|
|
1362
1474
|
toJSON() {
|
|
1363
1475
|
return this.toString();
|
|
1364
1476
|
}
|
|
1365
|
-
asObj() {
|
|
1477
|
+
asObj(...strips) {
|
|
1366
1478
|
const pathURI = {
|
|
1367
1479
|
style: "path",
|
|
1368
1480
|
protocol: this.protocol,
|
|
@@ -1370,13 +1482,13 @@ var URI = class _URI {
|
|
|
1370
1482
|
searchParams: Object.fromEntries(this.getParams)
|
|
1371
1483
|
};
|
|
1372
1484
|
if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
|
|
1373
|
-
return __spreadProps(__spreadValues({}, pathURI), {
|
|
1485
|
+
return stripper(strips, __spreadProps(__spreadValues({}, pathURI), {
|
|
1374
1486
|
style: "host",
|
|
1375
1487
|
hostname: this.hostname,
|
|
1376
1488
|
port: this.port
|
|
1377
|
-
});
|
|
1489
|
+
}));
|
|
1378
1490
|
}
|
|
1379
|
-
return pathURI;
|
|
1491
|
+
return stripper(strips, pathURI);
|
|
1380
1492
|
}
|
|
1381
1493
|
};
|
|
1382
1494
|
|
|
@@ -1869,8 +1981,10 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
1869
1981
|
}
|
|
1870
1982
|
return fnRet;
|
|
1871
1983
|
});
|
|
1984
|
+
const asError = () => new Error(this._txtEnDe.decode(fnError()));
|
|
1872
1985
|
return {
|
|
1873
|
-
|
|
1986
|
+
ResultError: () => Result.Err(asError()),
|
|
1987
|
+
AsError: asError
|
|
1874
1988
|
};
|
|
1875
1989
|
}
|
|
1876
1990
|
};
|
|
@@ -2346,26 +2460,6 @@ var VERSION = Object.keys({
|
|
|
2346
2460
|
__packageVersion__: "xxxx"
|
|
2347
2461
|
})[0];
|
|
2348
2462
|
|
|
2349
|
-
// src/refcounted.ts
|
|
2350
|
-
function wrapRefcounted(t, method) {
|
|
2351
|
-
const my2 = t;
|
|
2352
|
-
my2.__refcounted = (my2.__refcounted || 0) + 1;
|
|
2353
|
-
if (my2.__refcounted === 1) {
|
|
2354
|
-
my2.__unrefcounted = my2[method];
|
|
2355
|
-
const mRec = my2;
|
|
2356
|
-
mRec[method] = function() {
|
|
2357
|
-
this.__refcounted--;
|
|
2358
|
-
if (this.__refcounted === 0) {
|
|
2359
|
-
this.__unrefcounted();
|
|
2360
|
-
}
|
|
2361
|
-
if (this.__refcounted < 0) {
|
|
2362
|
-
throw new Error("already closed");
|
|
2363
|
-
}
|
|
2364
|
-
};
|
|
2365
|
-
}
|
|
2366
|
-
return t;
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
2463
|
// src/utils/index.ts
|
|
2370
2464
|
var utils_exports = {};
|
|
2371
2465
|
__export(utils_exports, {
|
|
@@ -2625,7 +2719,6 @@ function uint8array2stream(str) {
|
|
|
2625
2719
|
removeSelfRef,
|
|
2626
2720
|
runtimeFn,
|
|
2627
2721
|
toCryptoRuntime,
|
|
2628
|
-
utils
|
|
2629
|
-
wrapRefcounted
|
|
2722
|
+
utils
|
|
2630
2723
|
});
|
|
2631
2724
|
//# sourceMappingURL=index.cjs.map
|