@adviser/cement 0.2.31 → 0.2.32
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 +119 -29
- package/index.cjs.map +1 -1
- package/index.d.cts +11 -4
- package/index.d.ts +11 -4
- package/index.js +123 -32
- 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 +78 -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 +8 -1
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +63 -4
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +57 -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,9 @@ 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
|
+
}
|
|
1353
1462
|
clone() {
|
|
1354
1463
|
return new _URI(this._url);
|
|
1355
1464
|
}
|
|
@@ -1362,7 +1471,7 @@ var URI = class _URI {
|
|
|
1362
1471
|
toJSON() {
|
|
1363
1472
|
return this.toString();
|
|
1364
1473
|
}
|
|
1365
|
-
asObj() {
|
|
1474
|
+
asObj(...strips) {
|
|
1366
1475
|
const pathURI = {
|
|
1367
1476
|
style: "path",
|
|
1368
1477
|
protocol: this.protocol,
|
|
@@ -1370,13 +1479,13 @@ var URI = class _URI {
|
|
|
1370
1479
|
searchParams: Object.fromEntries(this.getParams)
|
|
1371
1480
|
};
|
|
1372
1481
|
if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
|
|
1373
|
-
return __spreadProps(__spreadValues({}, pathURI), {
|
|
1482
|
+
return stripper(strips, __spreadProps(__spreadValues({}, pathURI), {
|
|
1374
1483
|
style: "host",
|
|
1375
1484
|
hostname: this.hostname,
|
|
1376
1485
|
port: this.port
|
|
1377
|
-
});
|
|
1486
|
+
}));
|
|
1378
1487
|
}
|
|
1379
|
-
return pathURI;
|
|
1488
|
+
return stripper(strips, pathURI);
|
|
1380
1489
|
}
|
|
1381
1490
|
};
|
|
1382
1491
|
|
|
@@ -1869,8 +1978,10 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
1869
1978
|
}
|
|
1870
1979
|
return fnRet;
|
|
1871
1980
|
});
|
|
1981
|
+
const asError = () => new Error(this._txtEnDe.decode(fnError()));
|
|
1872
1982
|
return {
|
|
1873
|
-
|
|
1983
|
+
ResultError: () => Result.Err(asError()),
|
|
1984
|
+
AsError: asError
|
|
1874
1985
|
};
|
|
1875
1986
|
}
|
|
1876
1987
|
};
|
|
@@ -2346,26 +2457,6 @@ var VERSION = Object.keys({
|
|
|
2346
2457
|
__packageVersion__: "xxxx"
|
|
2347
2458
|
})[0];
|
|
2348
2459
|
|
|
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
2460
|
// src/utils/index.ts
|
|
2370
2461
|
var utils_exports = {};
|
|
2371
2462
|
__export(utils_exports, {
|
|
@@ -2625,7 +2716,6 @@ function uint8array2stream(str) {
|
|
|
2625
2716
|
removeSelfRef,
|
|
2626
2717
|
runtimeFn,
|
|
2627
2718
|
toCryptoRuntime,
|
|
2628
|
-
utils
|
|
2629
|
-
wrapRefcounted
|
|
2719
|
+
utils
|
|
2630
2720
|
});
|
|
2631
2721
|
//# sourceMappingURL=index.cjs.map
|