@adviser/cement 0.2.34 → 0.2.35

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -90,13 +90,13 @@ declare class BuildURI {
90
90
  defParam(key: string, str: string): BuildURI;
91
91
  setParam(key: string, str: string): BuildURI;
92
92
  hasParam(key: string): boolean;
93
- getParam(key: string): string | undefined;
93
+ getParam<T extends string | undefined>(key: string, def?: T): T extends string ? string : string | undefined;
94
94
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
95
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
96
96
  toString(): string;
97
97
  toJSON(): string;
98
98
  asURL(): URL;
99
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
99
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
100
100
  URI(): URI;
101
101
  }
102
102
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
@@ -117,14 +117,14 @@ declare class URI {
117
117
  get pathname(): string;
118
118
  get getParams(): Iterable<[string, string]>;
119
119
  hasParam(key: string): boolean;
120
- getParam(key: string): string | undefined;
120
+ getParam<T extends string | undefined>(key: string, def?: T): T extends string ? string : string | undefined;
121
121
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
122
122
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
123
123
  clone(): URI;
124
124
  asURL(): URL;
125
125
  toString(): string;
126
126
  toJSON(): string;
127
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
127
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
128
128
  }
129
129
 
130
130
  declare enum Level {
@@ -142,7 +142,6 @@ declare class LogValue {
142
142
  toJSON(): Serialized | Serialized[];
143
143
  }
144
144
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
145
- declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
146
145
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
147
146
  type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
148
147
  declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
@@ -181,6 +180,8 @@ interface LoggerInterface<R> {
181
180
  Len(value: unknown, key?: string): R;
182
181
  Hash(value: unknown, key?: string): R;
183
182
  Str(key: string, value?: string): R;
183
+ Http(res: Response | Result<Response>, req?: Request, key?: string): R;
184
+ Pair(x: Record<string, unknown>): R;
184
185
  Error(): R;
185
186
  Warn(): R;
186
187
  Debug(): R;
@@ -269,6 +270,8 @@ declare class LoggerImpl implements Logger {
269
270
  toString: () => string;
270
271
  } | FnSerialized): Logger;
271
272
  Bool(key: string, value: unknown): Logger;
273
+ Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
274
+ Pair(x: Record<string, unknown>): Logger;
272
275
  Result<T>(key: string, res: Result<T, Error>): Logger;
273
276
  Len(value: unknown, key?: string): Logger;
274
277
  Hash(value: unknown, key?: string): Logger;
@@ -555,4 +558,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
555
558
 
556
559
  declare const VERSION: string;
557
560
 
558
- 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 };
561
+ 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, runtimeFn, toCryptoRuntime };
package/index.d.ts CHANGED
@@ -90,13 +90,13 @@ declare class BuildURI {
90
90
  defParam(key: string, str: string): BuildURI;
91
91
  setParam(key: string, str: string): BuildURI;
92
92
  hasParam(key: string): boolean;
93
- getParam(key: string): string | undefined;
93
+ getParam<T extends string | undefined>(key: string, def?: T): T extends string ? string : string | undefined;
94
94
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
95
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
96
96
  toString(): string;
97
97
  toJSON(): string;
98
98
  asURL(): URL;
99
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
99
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
100
100
  URI(): URI;
101
101
  }
102
102
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
@@ -117,14 +117,14 @@ declare class URI {
117
117
  get pathname(): string;
118
118
  get getParams(): Iterable<[string, string]>;
119
119
  hasParam(key: string): boolean;
120
- getParam(key: string): string | undefined;
120
+ getParam<T extends string | undefined>(key: string, def?: T): T extends string ? string : string | undefined;
121
121
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
122
122
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
123
123
  clone(): URI;
124
124
  asURL(): URL;
125
125
  toString(): string;
126
126
  toJSON(): string;
127
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
127
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
128
128
  }
129
129
 
130
130
  declare enum Level {
@@ -142,7 +142,6 @@ declare class LogValue {
142
142
  toJSON(): Serialized | Serialized[];
143
143
  }
144
144
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
145
- declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
146
145
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
147
146
  type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
148
147
  declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
@@ -181,6 +180,8 @@ interface LoggerInterface<R> {
181
180
  Len(value: unknown, key?: string): R;
182
181
  Hash(value: unknown, key?: string): R;
183
182
  Str(key: string, value?: string): R;
183
+ Http(res: Response | Result<Response>, req?: Request, key?: string): R;
184
+ Pair(x: Record<string, unknown>): R;
184
185
  Error(): R;
185
186
  Warn(): R;
186
187
  Debug(): R;
@@ -269,6 +270,8 @@ declare class LoggerImpl implements Logger {
269
270
  toString: () => string;
270
271
  } | FnSerialized): Logger;
271
272
  Bool(key: string, value: unknown): Logger;
273
+ Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
274
+ Pair(x: Record<string, unknown>): Logger;
272
275
  Result<T>(key: string, res: Result<T, Error>): Logger;
273
276
  Len(value: unknown, key?: string): Logger;
274
277
  Hash(value: unknown, key?: string): Logger;
@@ -555,4 +558,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
555
558
 
556
559
  declare const VERSION: string;
557
560
 
558
- 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 };
561
+ 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, runtimeFn, toCryptoRuntime };
package/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ ConsoleWriterStream,
3
+ FanoutWriteStream,
4
+ utils_exports
5
+ } from "./chunk-7KFVMTOS.js";
1
6
  import {
2
7
  WebSysAbstraction
3
8
  } from "./chunk-WMMUXBDX.js";
@@ -26,11 +31,6 @@ import {
26
31
  WrapperSysAbstraction,
27
32
  envFactory
28
33
  } 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,
@@ -101,22 +101,16 @@ var LogValue = class {
101
101
  this.fn = fn;
102
102
  }
103
103
  value() {
104
- return this.fn();
104
+ try {
105
+ return this.fn();
106
+ } catch (e) {
107
+ return `LogValue:${e.message}`;
108
+ }
105
109
  }
106
110
  toJSON() {
107
111
  return this.value();
108
112
  }
109
113
  };
110
- function removeSelfRef(lineEnd) {
111
- const cache = /* @__PURE__ */ new Set();
112
- return function(key, value) {
113
- if (typeof value === "object" && value !== null) {
114
- if (cache.has(value)) return "...";
115
- cache.add(value);
116
- }
117
- return lineEnd ? value + lineEnd : value;
118
- };
119
- }
120
114
  function asyncLogValue(val) {
121
115
  throw new Error("Not implemented");
122
116
  }
@@ -143,19 +137,31 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
143
137
  case "boolean":
144
138
  return new LogValue(() => val);
145
139
  case "object": {
140
+ if (val === null) {
141
+ return new LogValue(() => "null");
142
+ }
146
143
  if (ArrayBuffer.isView(val)) {
147
144
  return logValue(bin2string(val, 512));
148
145
  }
149
146
  if (Array.isArray(val)) {
150
147
  return new LogValue(() => val.map((v) => logValue(v).value()));
151
148
  }
152
- if (val === null) {
153
- return new LogValue(() => "null");
149
+ if (val instanceof Headers) {
150
+ return new LogValue(() => Object.fromEntries(val.entries()));
151
+ }
152
+ if (val instanceof ReadableStream) {
153
+ return new LogValue(() => ">Stream<");
154
+ }
155
+ if (val instanceof Promise) {
156
+ return new LogValue(() => ">Promise<");
154
157
  }
155
158
  if (state.has(val)) {
156
159
  return new LogValue(() => "...");
157
160
  }
158
161
  state.add(val);
162
+ if (typeof val.toJSON === "function") {
163
+ return new LogValue(() => val.toJSON());
164
+ }
159
165
  const res = {};
160
166
  const typedVal = val;
161
167
  for (const key in typedVal) {
@@ -163,7 +169,9 @@ function logValue(val, state = /* @__PURE__ */ new Set([Math.random()])) {
163
169
  if (element instanceof LogValue) {
164
170
  res[key] = element;
165
171
  } else {
166
- res[key] = logValue(element, state);
172
+ if (typeof element !== "function") {
173
+ res[key] = logValue(element, state);
174
+ }
167
175
  }
168
176
  }
169
177
  return new LogValue(() => res);
@@ -297,6 +305,9 @@ function localStripper(path, restrips, obj) {
297
305
  if (typeof obj !== "object" || obj === null) {
298
306
  return obj;
299
307
  }
308
+ if (Array.isArray(obj)) {
309
+ return obj.map((i) => localStripper(path, restrips, i));
310
+ }
300
311
  const ret = __spreadValues({}, obj);
301
312
  const matcher = (key, nextPath) => {
302
313
  for (const re of restrips) {
@@ -587,8 +598,12 @@ var BuildURI = class _BuildURI {
587
598
  hasParam(key) {
588
599
  return this._url.searchParams.has(key);
589
600
  }
590
- getParam(key) {
591
- return falsy2undef(this._url.searchParams.get(key));
601
+ getParam(key, def) {
602
+ let val = this._url.searchParams.get(key);
603
+ if (!falsy2undef(val) && def) {
604
+ val = def;
605
+ }
606
+ return falsy2undef(val);
592
607
  }
593
608
  getParamResult(key, msgFn) {
594
609
  return getParamResult(key, this.getParam(key), msgFn);
@@ -688,8 +703,12 @@ var URI = class _URI {
688
703
  hasParam(key) {
689
704
  return this._url.searchParams.has(key);
690
705
  }
691
- getParam(key) {
692
- return falsy2undef(this._url.searchParams.get(key));
706
+ getParam(key, def) {
707
+ let val = this._url.searchParams.get(key);
708
+ if (!falsy2undef(val) && def) {
709
+ val = def;
710
+ }
711
+ return falsy2undef(val);
693
712
  }
694
713
  getParamResult(key, msgFn) {
695
714
  return getParamResult(key, this.getParam(key), msgFn);
@@ -910,7 +929,13 @@ var JSONFormatter = class {
910
929
  this._space = space;
911
930
  }
912
931
  format(attr) {
913
- return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
932
+ let ret;
933
+ try {
934
+ ret = JSON.stringify(attr, null, this._space);
935
+ } catch (e) {
936
+ ret = JSON.stringify({ internal: { message: e.message, stack: e.stack } });
937
+ }
938
+ return this._txtEnDe.encode(ret + "\n");
914
939
  }
915
940
  };
916
941
  var YAMLFormatter = class {
@@ -919,7 +944,7 @@ var YAMLFormatter = class {
919
944
  this._space = space;
920
945
  }
921
946
  format(attr) {
922
- return this._txtEnDe.encode("---\n" + YAML.stringify(attr, removeSelfRef(), this._space) + "\n");
947
+ return this._txtEnDe.encode("---\n" + YAML.stringify(attr, null, this._space) + "\n");
923
948
  }
924
949
  };
925
950
  var LoggerImpl = class _LoggerImpl {
@@ -980,7 +1005,7 @@ var LoggerImpl = class _LoggerImpl {
980
1005
  return this._txtEnDe;
981
1006
  }
982
1007
  Attributes() {
983
- return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
1008
+ return JSON.parse(JSON.stringify(this._attributes, null));
984
1009
  }
985
1010
  SetExposeStack(enable) {
986
1011
  this._levelHandler.setExposeStack(enable);
@@ -1067,6 +1092,36 @@ var LoggerImpl = class _LoggerImpl {
1067
1092
  this._attributes[key] = logValue(!!value);
1068
1093
  return this;
1069
1094
  }
1095
+ Http(res, req, key) {
1096
+ if (Result.Is(res)) {
1097
+ if (res.isErr()) {
1098
+ this.Err(res.Err());
1099
+ return this;
1100
+ }
1101
+ res = res.Ok();
1102
+ }
1103
+ let reqRes = res;
1104
+ if (req) {
1105
+ reqRes = { res, req };
1106
+ }
1107
+ this.Any(key || "Http", reqRes);
1108
+ return this;
1109
+ }
1110
+ Pair(x) {
1111
+ for (const key of Object.keys(x)) {
1112
+ const value = x[key];
1113
+ if (value instanceof LogValue) {
1114
+ this._attributes[key] = value;
1115
+ continue;
1116
+ }
1117
+ if (Result.Is(value)) {
1118
+ this.Result(key, value);
1119
+ continue;
1120
+ }
1121
+ this.Any(key, value);
1122
+ }
1123
+ return this;
1124
+ }
1070
1125
  Result(key, res) {
1071
1126
  if (res.isOk()) {
1072
1127
  this._attributes[key] = logValue(res.Ok());
@@ -1197,6 +1252,14 @@ var WithLoggerBuilder = class {
1197
1252
  this._li.SetDebug(...modules);
1198
1253
  return this;
1199
1254
  }
1255
+ Http(res, req, key) {
1256
+ this._li.Http(res, req, key);
1257
+ return this;
1258
+ }
1259
+ Pair(x) {
1260
+ this._li.Pair(x);
1261
+ return this;
1262
+ }
1200
1263
  Str(key, value) {
1201
1264
  this._li.Str(key, value);
1202
1265
  return this;
@@ -1661,7 +1724,6 @@ export {
1661
1724
  hasHostPartProtocols,
1662
1725
  isURL,
1663
1726
  logValue,
1664
- removeSelfRef,
1665
1727
  runtimeFn,
1666
1728
  toCryptoRuntime,
1667
1729
  utils_exports as utils