@adviser/cement 0.2.30 → 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.
Files changed (47) hide show
  1. package/index.cjs +142 -36
  2. package/index.cjs.map +1 -1
  3. package/index.d.cts +26 -4
  4. package/index.d.ts +26 -4
  5. package/index.js +140 -33
  6. package/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/index.ts +0 -1
  9. package/src/jsr.json +1 -1
  10. package/src/logger-impl.ts +3 -1
  11. package/src/logger.ts +1 -0
  12. package/src/uri.ts +117 -9
  13. package/src/utils/stripper.ts +59 -0
  14. package/ts/index.d.ts +0 -1
  15. package/ts/index.d.ts.map +1 -1
  16. package/ts/index.js +0 -1
  17. package/ts/index.js.map +1 -1
  18. package/ts/logger-impl.d.ts.map +1 -1
  19. package/ts/logger-impl.js +3 -1
  20. package/ts/logger-impl.js.map +1 -1
  21. package/ts/logger.d.ts +1 -0
  22. package/ts/logger.d.ts.map +1 -1
  23. package/ts/logger.test.js +14 -0
  24. package/ts/logger.test.js.map +1 -1
  25. package/ts/uri.d.ts +23 -1
  26. package/ts/uri.d.ts.map +1 -1
  27. package/ts/uri.js +81 -10
  28. package/ts/uri.js.map +1 -1
  29. package/ts/uri.test.js +85 -0
  30. package/ts/uri.test.js.map +1 -1
  31. package/ts/utils/stripper.d.ts +3 -0
  32. package/ts/utils/stripper.d.ts.map +1 -0
  33. package/ts/utils/stripper.js +56 -0
  34. package/ts/utils/stripper.js.map +1 -0
  35. package/ts/utils/stripper.test.d.ts +2 -0
  36. package/ts/utils/stripper.test.d.ts.map +1 -0
  37. package/ts/utils/stripper.test.js +97 -0
  38. package/ts/utils/stripper.test.js.map +1 -0
  39. package/src/refcounted.ts +0 -23
  40. package/ts/refcounted.d.ts +0 -2
  41. package/ts/refcounted.d.ts.map +0 -1
  42. package/ts/refcounted.js +0 -19
  43. package/ts/refcounted.js.map +0 -1
  44. package/ts/refcounted.test.d.ts +0 -2
  45. package/ts/refcounted.test.d.ts.map +0 -1
  46. package/ts/refcounted.test.js +0 -39
  47. package/ts/refcounted.test.js.map +0 -1
package/index.cjs CHANGED
@@ -140,14 +140,13 @@ __export(src_exports, {
140
140
  bin2text: () => bin2text,
141
141
  envFactory: () => envFactory,
142
142
  exception2Result: () => exception2Result,
143
+ hasHostPartProtocols: () => hasHostPartProtocols,
143
144
  isURL: () => isURL,
144
145
  logValue: () => logValue,
145
- protocols: () => protocols,
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;
@@ -1077,7 +1131,7 @@ var MutableURL = class _MutableURL extends URL {
1077
1131
  constructor(urlStr) {
1078
1132
  super("defect://does.not.exist");
1079
1133
  const partedURL = urlStr.split(":");
1080
- this._hasHostpart = protocols.has(partedURL[0]);
1134
+ this._hasHostpart = hasHostPartProtocols.has(partedURL[0]);
1081
1135
  let hostPartUrl = ["http", ...partedURL.slice(1)].join(":");
1082
1136
  if (!this._hasHostpart) {
1083
1137
  const pathname = hostPartUrl.replace(/http:\/\/[/]*/, "").replace(/[#?].*$/, "");
@@ -1104,32 +1158,32 @@ var MutableURL = class _MutableURL extends URL {
1104
1158
  get host() {
1105
1159
  if (!this._hasHostpart) {
1106
1160
  throw new Error(
1107
- `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(protocols.keys()))}`
1161
+ `you can use hostname only if protocol is ${this.toString()} ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`
1108
1162
  );
1109
1163
  }
1110
1164
  return this._sysURL.host;
1111
1165
  }
1112
1166
  get port() {
1113
1167
  if (!this._hasHostpart) {
1114
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1168
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1115
1169
  }
1116
1170
  return this._sysURL.port;
1117
1171
  }
1118
1172
  set port(p) {
1119
1173
  if (!this._hasHostpart) {
1120
- throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1174
+ throw new Error(`you can use port only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1121
1175
  }
1122
1176
  this._sysURL.port = p;
1123
1177
  }
1124
1178
  get hostname() {
1125
1179
  if (!this._hasHostpart) {
1126
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1180
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1127
1181
  }
1128
1182
  return this._sysURL.hostname;
1129
1183
  }
1130
1184
  set hostname(h) {
1131
1185
  if (!this._hasHostpart) {
1132
- throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(protocols.keys()))}`);
1186
+ throw new Error(`you can use hostname only if protocol is ${JSON.stringify(Array.from(hasHostPartProtocols.keys()))}`);
1133
1187
  }
1134
1188
  this._sysURL.hostname = h;
1135
1189
  }
@@ -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,17 +1371,20 @@ 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
  }
1274
1380
  };
1275
- var protocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
1381
+ var hasHostPartProtocols = /* @__PURE__ */ new Set(["http", "https", "ws", "wss"]);
1276
1382
  var URI = class _URI {
1277
1383
  static protocolHasHostpart(protocol) {
1278
1384
  protocol = protocol.replace(/:$/, "");
1279
- protocols.add(protocol);
1385
+ hasHostPartProtocols.add(protocol);
1280
1386
  return () => {
1281
- protocols.delete(protocol);
1387
+ hasHostPartProtocols.delete(protocol);
1282
1388
  };
1283
1389
  }
1284
1390
  // if no protocol is provided, default to file:
@@ -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,6 +1471,22 @@ var URI = class _URI {
1362
1471
  toJSON() {
1363
1472
  return this.toString();
1364
1473
  }
1474
+ asObj(...strips) {
1475
+ const pathURI = {
1476
+ style: "path",
1477
+ protocol: this.protocol,
1478
+ pathname: this.pathname,
1479
+ searchParams: Object.fromEntries(this.getParams)
1480
+ };
1481
+ if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
1482
+ return stripper(strips, __spreadProps(__spreadValues({}, pathURI), {
1483
+ style: "host",
1484
+ hostname: this.hostname,
1485
+ port: this.port
1486
+ }));
1487
+ }
1488
+ return stripper(strips, pathURI);
1489
+ }
1365
1490
  };
1366
1491
 
1367
1492
  // src/runtime.ts
@@ -1853,8 +1978,10 @@ var LoggerImpl = class _LoggerImpl {
1853
1978
  }
1854
1979
  return fnRet;
1855
1980
  });
1981
+ const asError = () => new Error(this._txtEnDe.decode(fnError()));
1856
1982
  return {
1857
- AsError: () => new Error(this._txtEnDe.decode(fnError()))
1983
+ ResultError: () => Result.Err(asError()),
1984
+ AsError: asError
1858
1985
  };
1859
1986
  }
1860
1987
  };
@@ -2330,26 +2457,6 @@ var VERSION = Object.keys({
2330
2457
  __packageVersion__: "xxxx"
2331
2458
  })[0];
2332
2459
 
2333
- // src/refcounted.ts
2334
- function wrapRefcounted(t, method) {
2335
- const my2 = t;
2336
- my2.__refcounted = (my2.__refcounted || 0) + 1;
2337
- if (my2.__refcounted === 1) {
2338
- my2.__unrefcounted = my2[method];
2339
- const mRec = my2;
2340
- mRec[method] = function() {
2341
- this.__refcounted--;
2342
- if (this.__refcounted === 0) {
2343
- this.__unrefcounted();
2344
- }
2345
- if (this.__refcounted < 0) {
2346
- throw new Error("already closed");
2347
- }
2348
- };
2349
- }
2350
- return t;
2351
- }
2352
-
2353
2460
  // src/utils/index.ts
2354
2461
  var utils_exports = {};
2355
2462
  __export(utils_exports, {
@@ -2603,13 +2710,12 @@ function uint8array2stream(str) {
2603
2710
  bin2text,
2604
2711
  envFactory,
2605
2712
  exception2Result,
2713
+ hasHostPartProtocols,
2606
2714
  isURL,
2607
2715
  logValue,
2608
- protocols,
2609
2716
  removeSelfRef,
2610
2717
  runtimeFn,
2611
2718
  toCryptoRuntime,
2612
- utils,
2613
- wrapRefcounted
2719
+ utils
2614
2720
  });
2615
2721
  //# sourceMappingURL=index.cjs.map