@adviser/cement 0.2.31 → 0.2.32

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -37,6 +37,8 @@ type WithoutResult<T> = T extends Result<infer U> ? U : T;
37
37
  type WithResult<T> = T extends Promise<infer U> ? Promise<Result<U>> : Result<T>;
38
38
  declare function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): WithResult<ReturnType<FN>>;
39
39
 
40
+ type StripCommand = string | RegExp;
41
+
40
42
  type NullOrUndef = null | undefined;
41
43
  interface URIObject {
42
44
  readonly style: "host" | "path";
@@ -73,6 +75,7 @@ declare class MutableURL extends URL {
73
75
  get searchParams(): URLSearchParams;
74
76
  toString(): string;
75
77
  }
78
+ type keysParam = (string | ((...keys: string[]) => string))[];
76
79
  declare class BuildURI {
77
80
  _url: MutableURL;
78
81
  private constructor();
@@ -82,13 +85,17 @@ declare class BuildURI {
82
85
  hostname(h: string): BuildURI;
83
86
  protocol(p: string): BuildURI;
84
87
  pathname(p: string): BuildURI;
88
+ appendRelative(p: CoerceURI): BuildURI;
85
89
  delParam(key: string): BuildURI;
86
90
  defParam(key: string, str: string): BuildURI;
87
91
  setParam(key: string, str: string): BuildURI;
88
92
  hasParam(key: string): boolean;
89
93
  getParam(key: string): string | undefined;
94
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
+ getParamsResult(...keys: keysParam): Result<Record<string, string>>;
90
96
  toString(): string;
91
97
  toJSON(): string;
98
+ asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
92
99
  URI(): URI;
93
100
  }
94
101
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
@@ -110,11 +117,12 @@ declare class URI {
110
117
  get getParams(): Iterable<[string, string]>;
111
118
  hasParam(key: string): boolean;
112
119
  getParam(key: string): string | undefined;
120
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
113
121
  clone(): URI;
114
122
  asURL(): URL;
115
123
  toString(): string;
116
124
  toJSON(): string;
117
- asObj(): HostURIObject | PathURIObject;
125
+ asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
118
126
  }
119
127
 
120
128
  declare enum Level {
@@ -191,6 +199,7 @@ interface WithLogger extends LoggerInterface<WithLogger> {
191
199
  }
192
200
  interface AsError {
193
201
  AsError(): Error;
202
+ ResultError<T>(): Result<T>;
194
203
  }
195
204
  interface Logger extends LoggerInterface<Logger> {
196
205
  With(): WithLogger;
@@ -544,6 +553,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
544
553
 
545
554
  declare const VERSION: string;
546
555
 
547
- declare function wrapRefcounted<T, M extends string>(t: T, method: M): T;
548
-
549
- export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type HostURIObject, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, type PathURIObject, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, removeSelfRef, runtimeFn, toCryptoRuntime, wrapRefcounted };
556
+ export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type HostURIObject, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, type PathURIObject, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, removeSelfRef, runtimeFn, toCryptoRuntime };
package/index.d.ts CHANGED
@@ -37,6 +37,8 @@ type WithoutResult<T> = T extends Result<infer U> ? U : T;
37
37
  type WithResult<T> = T extends Promise<infer U> ? Promise<Result<U>> : Result<T>;
38
38
  declare function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): WithResult<ReturnType<FN>>;
39
39
 
40
+ type StripCommand = string | RegExp;
41
+
40
42
  type NullOrUndef = null | undefined;
41
43
  interface URIObject {
42
44
  readonly style: "host" | "path";
@@ -73,6 +75,7 @@ declare class MutableURL extends URL {
73
75
  get searchParams(): URLSearchParams;
74
76
  toString(): string;
75
77
  }
78
+ type keysParam = (string | ((...keys: string[]) => string))[];
76
79
  declare class BuildURI {
77
80
  _url: MutableURL;
78
81
  private constructor();
@@ -82,13 +85,17 @@ declare class BuildURI {
82
85
  hostname(h: string): BuildURI;
83
86
  protocol(p: string): BuildURI;
84
87
  pathname(p: string): BuildURI;
88
+ appendRelative(p: CoerceURI): BuildURI;
85
89
  delParam(key: string): BuildURI;
86
90
  defParam(key: string, str: string): BuildURI;
87
91
  setParam(key: string, str: string): BuildURI;
88
92
  hasParam(key: string): boolean;
89
93
  getParam(key: string): string | undefined;
94
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
+ getParamsResult(...keys: keysParam): Result<Record<string, string>>;
90
96
  toString(): string;
91
97
  toJSON(): string;
98
+ asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
92
99
  URI(): URI;
93
100
  }
94
101
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
@@ -110,11 +117,12 @@ declare class URI {
110
117
  get getParams(): Iterable<[string, string]>;
111
118
  hasParam(key: string): boolean;
112
119
  getParam(key: string): string | undefined;
120
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
113
121
  clone(): URI;
114
122
  asURL(): URL;
115
123
  toString(): string;
116
124
  toJSON(): string;
117
- asObj(): HostURIObject | PathURIObject;
125
+ asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
118
126
  }
119
127
 
120
128
  declare enum Level {
@@ -191,6 +199,7 @@ interface WithLogger extends LoggerInterface<WithLogger> {
191
199
  }
192
200
  interface AsError {
193
201
  AsError(): Error;
202
+ ResultError<T>(): Result<T>;
194
203
  }
195
204
  interface Logger extends LoggerInterface<Logger> {
196
205
  With(): WithLogger;
@@ -544,6 +553,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
544
553
 
545
554
  declare const VERSION: string;
546
555
 
547
- declare function wrapRefcounted<T, M extends string>(t: T, method: M): T;
548
-
549
- export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type HostURIObject, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, type PathURIObject, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, removeSelfRef, runtimeFn, toCryptoRuntime, wrapRefcounted };
556
+ export { type AsError, BuildURI, type CTAesKeyAlgorithm, type CTAlgorithm, type CTAlgorithmIdentifier, type CTArrayBufferView, type CTBufferSource, type CTCryptoKey, type CTEcKeyImportParams, type CTHmacImportParams, type CTJsonWebKey, type CTKeyFormat, type CTKeyType, type CTKeyUsage, type CTNamedCurve, type CTRsaHashedImportParams, type CleanCtx, type CoerceURI, type CryptoRuntime, type FnSerialized, Future, type HostURIObject, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type Lengthed, Level, type LevelHandler, LevelHandlerImpl, LevelHandlerSingleton, LogCollector, type LogFormatter, type LogSerializable, LogValue, type LogValueArg, LogWriteStream, type Logger, LoggerImpl, type LoggerImplParams, type LoggerInterface, Metric, type MetricMap, Metrics, MockLogger, type MockLoggerReturn, MutableURL, None, Option, type PathURIObject, ResolveOnce, ResolveSeq, Result, ResultError, ResultOK, type Runtime, type Serialized, type SizeOrLength, type Sized, Some, SysAbstraction, Time, type TraceCtx, type TraceCtxParam, TraceNode, type TraceNodeMap, TxtEnDecoder, URI, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, removeSelfRef, runtimeFn, toCryptoRuntime };
package/index.js CHANGED
@@ -1,8 +1,3 @@
1
- import {
2
- ConsoleWriterStream,
3
- FanoutWriteStream,
4
- utils_exports
5
- } from "./chunk-7KFVMTOS.js";
6
1
  import {
7
2
  WebSysAbstraction
8
3
  } from "./chunk-WMMUXBDX.js";
@@ -31,6 +26,11 @@ import {
31
26
  WrapperSysAbstraction,
32
27
  envFactory
33
28
  } from "./chunk-Q65HLCNL.js";
29
+ import {
30
+ ConsoleWriterStream,
31
+ FanoutWriteStream,
32
+ utils_exports
33
+ } from "./chunk-7KFVMTOS.js";
34
34
  import {
35
35
  Utf8EnDecoder,
36
36
  Utf8EnDecoderSingleton,
@@ -281,6 +281,61 @@ function exception2Result(fn) {
281
281
  }
282
282
  }
283
283
 
284
+ // src/utils/stripper.ts
285
+ function stripper(strip, obj) {
286
+ const strips = Array.isArray(strip) ? strip : [strip];
287
+ const restrips = strips.map((s) => {
288
+ if (typeof s === "string") {
289
+ const escaped = s.replace(/[-\\[\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g, "\\$&");
290
+ return new RegExp(`^${escaped}$`);
291
+ }
292
+ return s;
293
+ });
294
+ return localStripper(void 0, restrips, obj);
295
+ }
296
+ function localStripper(path, restrips, obj) {
297
+ if (typeof obj !== "object" || obj === null) {
298
+ return obj;
299
+ }
300
+ const ret = __spreadValues({}, obj);
301
+ const matcher = (key, nextPath) => {
302
+ for (const re of restrips) {
303
+ if (re.test(key) || re.test(nextPath)) {
304
+ return true;
305
+ }
306
+ }
307
+ return false;
308
+ };
309
+ for (const key in ret) {
310
+ if (Object.prototype.hasOwnProperty.call(ret, key)) {
311
+ let nextPath;
312
+ if (path) {
313
+ nextPath = [path, key].join(".");
314
+ } else {
315
+ nextPath = key;
316
+ }
317
+ if (matcher(key, nextPath)) {
318
+ delete ret[key];
319
+ continue;
320
+ }
321
+ if (typeof ret[key] === "object") {
322
+ if (Array.isArray(ret[key])) {
323
+ ret[key] = ret[key].reduce((acc, v, i) => {
324
+ const toDelete = matcher(key, `${nextPath}[${i}]`);
325
+ if (!toDelete) {
326
+ acc.push(localStripper(`${nextPath}[${i}]`, restrips, v));
327
+ }
328
+ return acc;
329
+ }, []);
330
+ } else {
331
+ ret[key] = localStripper(nextPath, restrips, ret[key]);
332
+ }
333
+ }
334
+ }
335
+ }
336
+ return ret;
337
+ }
338
+
284
339
  // src/uri.ts
285
340
  function falsy2undef(value) {
286
341
  return value === void 0 || value === null ? void 0 : value;
@@ -419,6 +474,35 @@ function from(fac, strURLUri, defaultProtocol) {
419
474
  throw new Error(`Invalid argument: ${typeof strURLUri}`);
420
475
  }
421
476
  }
477
+ function getParamResult(key, val, msgFn = (key2) => {
478
+ return `missing parameter: ${key2}`;
479
+ }) {
480
+ if (val === void 0) {
481
+ return Result.Err(msgFn(key));
482
+ }
483
+ return Result.Ok(val);
484
+ }
485
+ function getParamsResult(keys, getParam) {
486
+ const keyStrs = keys.flat().filter((k) => typeof k === "string");
487
+ const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
488
+ const msg = keys2.join(",");
489
+ return `missing parameters: ${msg}`;
490
+ });
491
+ const errors = [];
492
+ const result = {};
493
+ for (const key of keyStrs) {
494
+ const val = getParam.getParam(key);
495
+ if (val === void 0) {
496
+ errors.push(key);
497
+ } else {
498
+ result[key] = val;
499
+ }
500
+ }
501
+ if (errors.length) {
502
+ return Result.Err(msgFn(...errors));
503
+ }
504
+ return Result.Ok(result);
505
+ }
422
506
  var BuildURI = class _BuildURI {
423
507
  // pathname needs this
424
508
  constructor(url) {
@@ -470,6 +554,20 @@ var BuildURI = class _BuildURI {
470
554
  // this._url.host = h;
471
555
  // return this;
472
556
  // }
557
+ appendRelative(p) {
558
+ const url = URI.from(p);
559
+ let pathname = url.pathname;
560
+ if (url.pathname === "/") {
561
+ pathname = "";
562
+ } else if (!pathname.startsWith("/")) {
563
+ pathname = `/${pathname}`;
564
+ }
565
+ this.pathname(this._url.pathname + pathname);
566
+ for (const [key, value] of url.getParams) {
567
+ this.setParam(key, value);
568
+ }
569
+ return this;
570
+ }
473
571
  delParam(key) {
474
572
  this._url.searchParams.delete(key);
475
573
  return this;
@@ -490,6 +588,12 @@ var BuildURI = class _BuildURI {
490
588
  getParam(key) {
491
589
  return falsy2undef(this._url.searchParams.get(key));
492
590
  }
591
+ getParamResult(key, msgFn) {
592
+ return getParamResult(key, this.getParam(key), msgFn);
593
+ }
594
+ getParamsResult(...keys) {
595
+ return getParamsResult(keys, this);
596
+ }
493
597
  toString() {
494
598
  this._url.searchParams.sort();
495
599
  return this._url.toString();
@@ -497,6 +601,9 @@ var BuildURI = class _BuildURI {
497
601
  toJSON() {
498
602
  return this.toString();
499
603
  }
604
+ asObj(...strips) {
605
+ return this.URI().asObj(...strips);
606
+ }
500
607
  URI() {
501
608
  return URI.from(this._url);
502
609
  }
@@ -579,6 +686,9 @@ var URI = class _URI {
579
686
  getParam(key) {
580
687
  return falsy2undef(this._url.searchParams.get(key));
581
688
  }
689
+ getParamResult(key, msgFn) {
690
+ return getParamResult(key, this.getParam(key), msgFn);
691
+ }
582
692
  clone() {
583
693
  return new _URI(this._url);
584
694
  }
@@ -591,7 +701,7 @@ var URI = class _URI {
591
701
  toJSON() {
592
702
  return this.toString();
593
703
  }
594
- asObj() {
704
+ asObj(...strips) {
595
705
  const pathURI = {
596
706
  style: "path",
597
707
  protocol: this.protocol,
@@ -599,13 +709,13 @@ var URI = class _URI {
599
709
  searchParams: Object.fromEntries(this.getParams)
600
710
  };
601
711
  if (hasHostPartProtocols.has(this.protocol.replace(/:$/, ""))) {
602
- return __spreadProps(__spreadValues({}, pathURI), {
712
+ return stripper(strips, __spreadProps(__spreadValues({}, pathURI), {
603
713
  style: "host",
604
714
  hostname: this.hostname,
605
715
  port: this.port
606
- });
716
+ }));
607
717
  }
608
- return pathURI;
718
+ return stripper(strips, pathURI);
609
719
  }
610
720
  };
611
721
 
@@ -1034,8 +1144,10 @@ var LoggerImpl = class _LoggerImpl {
1034
1144
  }
1035
1145
  return fnRet;
1036
1146
  });
1147
+ const asError = () => new Error(this._txtEnDe.decode(fnError()));
1037
1148
  return {
1038
- AsError: () => new Error(this._txtEnDe.decode(fnError()))
1149
+ ResultError: () => Result.Err(asError()),
1150
+ AsError: asError
1039
1151
  };
1040
1152
  }
1041
1153
  };
@@ -1484,26 +1596,6 @@ function toCryptoRuntime(cryptoOpts = {}) {
1484
1596
  var VERSION = Object.keys({
1485
1597
  __packageVersion__: "xxxx"
1486
1598
  })[0];
1487
-
1488
- // src/refcounted.ts
1489
- function wrapRefcounted(t, method) {
1490
- const my = t;
1491
- my.__refcounted = (my.__refcounted || 0) + 1;
1492
- if (my.__refcounted === 1) {
1493
- my.__unrefcounted = my[method];
1494
- const mRec = my;
1495
- mRec[method] = function() {
1496
- this.__refcounted--;
1497
- if (this.__refcounted === 0) {
1498
- this.__unrefcounted();
1499
- }
1500
- if (this.__refcounted < 0) {
1501
- throw new Error("already closed");
1502
- }
1503
- };
1504
- }
1505
- return t;
1506
- }
1507
1599
  export {
1508
1600
  BaseSysAbstraction,
1509
1601
  BrowserEnvActions,
@@ -1564,7 +1656,6 @@ export {
1564
1656
  removeSelfRef,
1565
1657
  runtimeFn,
1566
1658
  toCryptoRuntime,
1567
- utils_exports as utils,
1568
- wrapRefcounted
1659
+ utils_exports as utils
1569
1660
  };
1570
1661
  //# sourceMappingURL=index.js.map