@adviser/cement 0.2.36 → 0.2.38

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -41,12 +41,14 @@ type StripCommand = string | RegExp;
41
41
 
42
42
  type NullOrUndef = null | undefined;
43
43
  type OneKey<K extends string, V = string> = Record<K, V>;
44
+ type MsgFn = (...keys: string[]) => string;
45
+ type KeysParam = (string | MsgFn | Record<string, unknown>)[];
44
46
  interface URIInterface<R extends URIInterface<R>> {
45
47
  readonly getParams: Iterable<[string, string]>;
46
48
  hasParam(key: string): boolean;
47
49
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
48
50
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
49
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
51
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
50
52
  clone(): R;
51
53
  asURL(): URL;
52
54
  toString(): string;
@@ -88,8 +90,6 @@ declare class MutableURL extends URL {
88
90
  get searchParams(): URLSearchParams;
89
91
  toString(): string;
90
92
  }
91
- type msgFn = (...keys: string[]) => string;
92
- type keysParam = (string | msgFn | Record<string, string>)[];
93
93
  declare class BuildURI implements URIInterface<BuildURI> {
94
94
  _url: MutableURL;
95
95
  private constructor();
@@ -107,7 +107,7 @@ declare class BuildURI implements URIInterface<BuildURI> {
107
107
  get getParams(): Iterable<[string, string]>;
108
108
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
109
109
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
110
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
110
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
111
111
  toString(): string;
112
112
  toJSON(): string;
113
113
  asURL(): URL;
@@ -135,7 +135,7 @@ declare class URI implements URIInterface<URI> {
135
135
  hasParam(key: string): boolean;
136
136
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
137
137
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
138
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
138
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
139
139
  clone(): URI;
140
140
  asURL(): URL;
141
141
  toString(): string;
@@ -179,6 +179,7 @@ interface LevelHandler {
179
179
  setDebug(...modules: (string | string[])[]): void;
180
180
  isEnabled(ilevel: unknown, module: unknown): boolean;
181
181
  }
182
+ type HttpType = Response | Result<Response> | Request | Result<Request>;
182
183
  interface LoggerInterface<R> {
183
184
  TxtEnDe(): TxtEnDecoder;
184
185
  Module(key: string): R;
@@ -200,7 +201,7 @@ interface LoggerInterface<R> {
200
201
  Int<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
201
202
  Bool<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
202
203
  Any<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
203
- Http(res: Response | Result<Response>, req?: Request, key?: string): R;
204
+ Http(...mix: (HttpType | string)[]): R;
204
205
  Pair(x: Record<string, unknown>): R;
205
206
  Error(): R;
206
207
  Warn(): R;
@@ -286,7 +287,7 @@ declare class LoggerImpl implements Logger {
286
287
  toString: () => string;
287
288
  } | FnSerialized): Logger;
288
289
  Bool(key: string | Record<string, unknown>, value: unknown): Logger;
289
- Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
290
+ Http(...mix: (HttpType | string)[]): Logger;
290
291
  Pair(x: Record<string, unknown>): Logger;
291
292
  Result<T>(key: string, res: Result<T, Error>): Logger;
292
293
  Len(value: unknown, key?: string): Logger;
@@ -575,4 +576,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
575
576
 
576
577
  declare const VERSION: string;
577
578
 
578
- 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 URIInterface, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, runtimeFn, toCryptoRuntime };
579
+ 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 HttpType, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type KeysParam, 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, type MsgFn, 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 URIInterface, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, runtimeFn, toCryptoRuntime };
package/index.d.ts CHANGED
@@ -41,12 +41,14 @@ type StripCommand = string | RegExp;
41
41
 
42
42
  type NullOrUndef = null | undefined;
43
43
  type OneKey<K extends string, V = string> = Record<K, V>;
44
+ type MsgFn = (...keys: string[]) => string;
45
+ type KeysParam = (string | MsgFn | Record<string, unknown>)[];
44
46
  interface URIInterface<R extends URIInterface<R>> {
45
47
  readonly getParams: Iterable<[string, string]>;
46
48
  hasParam(key: string): boolean;
47
49
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
48
50
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
49
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
51
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
50
52
  clone(): R;
51
53
  asURL(): URL;
52
54
  toString(): string;
@@ -88,8 +90,6 @@ declare class MutableURL extends URL {
88
90
  get searchParams(): URLSearchParams;
89
91
  toString(): string;
90
92
  }
91
- type msgFn = (...keys: string[]) => string;
92
- type keysParam = (string | msgFn | Record<string, string>)[];
93
93
  declare class BuildURI implements URIInterface<BuildURI> {
94
94
  _url: MutableURL;
95
95
  private constructor();
@@ -107,7 +107,7 @@ declare class BuildURI implements URIInterface<BuildURI> {
107
107
  get getParams(): Iterable<[string, string]>;
108
108
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
109
109
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
110
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
110
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
111
111
  toString(): string;
112
112
  toJSON(): string;
113
113
  asURL(): URL;
@@ -135,7 +135,7 @@ declare class URI implements URIInterface<URI> {
135
135
  hasParam(key: string): boolean;
136
136
  getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
137
137
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
138
- getParamsResult(...keys: keysParam): Result<Record<string, string>>;
138
+ getParamsResult(...keys: KeysParam): Result<Record<string, string>>;
139
139
  clone(): URI;
140
140
  asURL(): URL;
141
141
  toString(): string;
@@ -179,6 +179,7 @@ interface LevelHandler {
179
179
  setDebug(...modules: (string | string[])[]): void;
180
180
  isEnabled(ilevel: unknown, module: unknown): boolean;
181
181
  }
182
+ type HttpType = Response | Result<Response> | Request | Result<Request>;
182
183
  interface LoggerInterface<R> {
183
184
  TxtEnDe(): TxtEnDecoder;
184
185
  Module(key: string): R;
@@ -200,7 +201,7 @@ interface LoggerInterface<R> {
200
201
  Int<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
201
202
  Bool<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
202
203
  Any<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
203
- Http(res: Response | Result<Response>, req?: Request, key?: string): R;
204
+ Http(...mix: (HttpType | string)[]): R;
204
205
  Pair(x: Record<string, unknown>): R;
205
206
  Error(): R;
206
207
  Warn(): R;
@@ -286,7 +287,7 @@ declare class LoggerImpl implements Logger {
286
287
  toString: () => string;
287
288
  } | FnSerialized): Logger;
288
289
  Bool(key: string | Record<string, unknown>, value: unknown): Logger;
289
- Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
290
+ Http(...mix: (HttpType | string)[]): Logger;
290
291
  Pair(x: Record<string, unknown>): Logger;
291
292
  Result<T>(key: string, res: Result<T, Error>): Logger;
292
293
  Len(value: unknown, key?: string): Logger;
@@ -575,4 +576,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
575
576
 
576
577
  declare const VERSION: string;
577
578
 
578
- 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 URIInterface, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, runtimeFn, toCryptoRuntime };
579
+ 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 HttpType, type Invokaction, IsLogger, JSONFormatter, Keyed, KeyedResolvOnce, KeyedResolvSeq, type KeysParam, 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, type MsgFn, 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 URIInterface, type URIObject, VERSION, type WithLogger, type WithoutOption, type WithoutResult, YAMLFormatter, asyncLogValue, bin2string, bin2text, exception2Result, hasHostPartProtocols, isURL, logValue, runtimeFn, toCryptoRuntime };
package/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-USQXEZHL.js";
6
6
  import {
7
7
  WebSysAbstraction
8
- } from "./chunk-WMMUXBDX.js";
8
+ } from "./chunk-W2GV5KXV.js";
9
9
  import {
10
10
  BaseSysAbstraction,
11
11
  BrowserEnvActions,
@@ -30,7 +30,7 @@ import {
30
30
  TimeUnits,
31
31
  WrapperSysAbstraction,
32
32
  envFactory
33
- } from "./chunk-Q65HLCNL.js";
33
+ } from "./chunk-F5W6VELE.js";
34
34
  import {
35
35
  Utf8EnDecoder,
36
36
  Utf8EnDecoderSingleton,
@@ -141,7 +141,14 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
141
141
  return new LogValue(() => "null");
142
142
  }
143
143
  if (ArrayBuffer.isView(val)) {
144
- return logValue(bin2string(val, 512));
144
+ try {
145
+ const decoder = new TextDecoder();
146
+ const asStr = decoder.decode(val);
147
+ const obj = JSON.parse(asStr);
148
+ return logValue(obj, state);
149
+ } catch (e) {
150
+ return logValue(bin2string(val, 512));
151
+ }
145
152
  }
146
153
  if (Array.isArray(val)) {
147
154
  return new LogValue(() => val.map((v) => logValue(v).value()));
@@ -509,7 +516,7 @@ function getParamsResult(keys, getParam) {
509
516
  if (typeof i === "string") {
510
517
  acc.push({ key: i });
511
518
  } else if (typeof i === "object") {
512
- acc.push(...Object.keys(i).map((k) => ({ key: k, def: i[k] })));
519
+ acc.push(...Object.keys(i).map((k) => ({ key: k, def: typeof i[k] === "string" ? i[k] : void 0 })));
513
520
  }
514
521
  return acc;
515
522
  },
@@ -524,7 +531,7 @@ function getParamsResult(keys, getParam) {
524
531
  for (const kd of keyDef) {
525
532
  const val = getParam.getParam(kd.key);
526
533
  if (val === void 0) {
527
- if (kd.def) {
534
+ if (typeof kd.def === "string") {
528
535
  result[kd.key] = kd.def;
529
536
  } else {
530
537
  errors.push(kd.key);
@@ -1124,19 +1131,29 @@ var LoggerImpl = class _LoggerImpl {
1124
1131
  this.coerceKey(key, !!value);
1125
1132
  return this;
1126
1133
  }
1127
- Http(res, req, key) {
1128
- if (Result.Is(res)) {
1129
- if (res.isErr()) {
1130
- this.Err(res.Err());
1131
- return this;
1132
- }
1133
- res = res.Ok();
1134
- }
1135
- let reqRes = res;
1136
- if (req) {
1137
- reqRes = { res, req };
1134
+ Http(...mix) {
1135
+ const key = mix.find((x) => typeof x === "string");
1136
+ mix = mix.filter((x) => typeof x !== "string");
1137
+ const resErrors = mix.filter((x) => Result.Is(x) && x.isErr());
1138
+ if (resErrors.length) {
1139
+ this.Err(resErrors.map((x) => x.Err().message).join("\n"));
1140
+ return this;
1141
+ }
1142
+ const req = mix.map((reqOrResult) => Result.Is(reqOrResult) ? reqOrResult.Ok() : reqOrResult).find((req2) => typeof req2.status !== "number");
1143
+ const res = mix.map((resOrResult) => Result.Is(resOrResult) ? resOrResult.Ok() : resOrResult).find((res2) => typeof res2.status === "number");
1144
+ let reqAndOrres;
1145
+ if (res && req) {
1146
+ reqAndOrres = { res, req };
1147
+ } else if (!res && !req) {
1148
+ reqAndOrres = void 0;
1149
+ } else if (res) {
1150
+ reqAndOrres = res;
1151
+ } else if (req) {
1152
+ reqAndOrres = req;
1153
+ }
1154
+ if (reqAndOrres) {
1155
+ this.Any(key || "Http", reqAndOrres);
1138
1156
  }
1139
- this.Any(key || "Http", reqRes);
1140
1157
  return this;
1141
1158
  }
1142
1159
  Pair(x) {
@@ -1291,8 +1308,8 @@ var WithLoggerBuilder = class {
1291
1308
  this._li.SetDebug(...modules);
1292
1309
  return this;
1293
1310
  }
1294
- Http(res, req, key) {
1295
- this._li.Http(res, req, key);
1311
+ Http(...mix) {
1312
+ this._li.Http(...mix);
1296
1313
  return this;
1297
1314
  }
1298
1315
  Pair(x) {