@adviser/cement 0.2.34 → 0.2.36

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -40,6 +40,19 @@ declare function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): W
40
40
  type StripCommand = string | RegExp;
41
41
 
42
42
  type NullOrUndef = null | undefined;
43
+ type OneKey<K extends string, V = string> = Record<K, V>;
44
+ interface URIInterface<R extends URIInterface<R>> {
45
+ readonly getParams: Iterable<[string, string]>;
46
+ hasParam(key: string): boolean;
47
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
48
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
49
+ getParamsResult(...keys: keysParam): Result<Record<string, string>>;
50
+ clone(): R;
51
+ asURL(): URL;
52
+ toString(): string;
53
+ toJSON(): string;
54
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
55
+ }
43
56
  interface URIObject {
44
57
  readonly style: "host" | "path";
45
58
  readonly protocol: string;
@@ -75,8 +88,9 @@ declare class MutableURL extends URL {
75
88
  get searchParams(): URLSearchParams;
76
89
  toString(): string;
77
90
  }
78
- type keysParam = (string | ((...keys: string[]) => string))[];
79
- declare class BuildURI {
91
+ type msgFn = (...keys: string[]) => string;
92
+ type keysParam = (string | msgFn | Record<string, string>)[];
93
+ declare class BuildURI implements URIInterface<BuildURI> {
80
94
  _url: MutableURL;
81
95
  private constructor();
82
96
  static is(value: unknown): value is BuildURI;
@@ -90,18 +104,20 @@ declare class BuildURI {
90
104
  defParam(key: string, str: string): BuildURI;
91
105
  setParam(key: string, str: string): BuildURI;
92
106
  hasParam(key: string): boolean;
93
- getParam(key: string): string | undefined;
107
+ get getParams(): Iterable<[string, string]>;
108
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
94
109
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
110
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
96
111
  toString(): string;
97
112
  toJSON(): string;
98
113
  asURL(): URL;
99
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
114
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
115
+ clone(): BuildURI;
100
116
  URI(): URI;
101
117
  }
102
118
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
103
119
  declare const hasHostPartProtocols: Set<string>;
104
- declare class URI {
120
+ declare class URI implements URIInterface<URI> {
105
121
  static protocolHasHostpart(protocol: string): () => void;
106
122
  static merge(into: CoerceURI, from: CoerceURI, defaultProtocol?: string): URI;
107
123
  static is(value: unknown): value is URI;
@@ -117,14 +133,14 @@ declare class URI {
117
133
  get pathname(): string;
118
134
  get getParams(): Iterable<[string, string]>;
119
135
  hasParam(key: string): boolean;
120
- getParam(key: string): string | undefined;
136
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
121
137
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
122
138
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
123
139
  clone(): URI;
124
140
  asURL(): URL;
125
141
  toString(): string;
126
142
  toJSON(): string;
127
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
143
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
128
144
  }
129
145
 
130
146
  declare enum Level {
@@ -142,7 +158,6 @@ declare class LogValue {
142
158
  toJSON(): Serialized | Serialized[];
143
159
  }
144
160
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
145
- declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
146
161
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
147
162
  type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
148
163
  declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
@@ -180,7 +195,13 @@ interface LoggerInterface<R> {
180
195
  Url(url: CoerceURI, key?: string): R;
181
196
  Len(value: unknown, key?: string): R;
182
197
  Hash(value: unknown, key?: string): R;
183
- Str(key: string, value?: string): R;
198
+ Str<T extends string | Record<string, string>>(key: T, value?: T extends string ? string : undefined): R;
199
+ Uint64<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
200
+ Int<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
201
+ Bool<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
202
+ 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
+ Pair(x: Record<string, unknown>): R;
184
205
  Error(): R;
185
206
  Warn(): R;
186
207
  Debug(): R;
@@ -189,11 +210,7 @@ interface LoggerInterface<R> {
189
210
  Err(err: unknown | Result<unknown> | Error): R;
190
211
  Info(): R;
191
212
  Timestamp(): R;
192
- Any(key: string, value: unknown): R;
193
213
  Dur(key: string, nsec: number): R;
194
- Uint64(key: string, value: number): R;
195
- Int(key: string, value: number): R;
196
- Bool(key: string, value: unknown): R;
197
214
  }
198
215
  declare function IsLogger(obj: unknown): obj is Logger;
199
216
  interface WithLogger extends LoggerInterface<WithLogger> {
@@ -268,16 +285,19 @@ declare class LoggerImpl implements Logger {
268
285
  Ref(key: string, action: {
269
286
  toString: () => string;
270
287
  } | FnSerialized): Logger;
271
- Bool(key: string, value: unknown): Logger;
288
+ Bool(key: string | Record<string, unknown>, value: unknown): Logger;
289
+ Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
290
+ Pair(x: Record<string, unknown>): Logger;
272
291
  Result<T>(key: string, res: Result<T, Error>): Logger;
273
292
  Len(value: unknown, key?: string): Logger;
274
293
  Hash(value: unknown, key?: string): Logger;
275
294
  Url(url: CoerceURI, key?: string): Logger;
276
- Str(key: string, value?: string): Logger;
277
- Any(key: string, value?: string | number | boolean | LogSerializable): Logger;
295
+ private coerceKey;
296
+ Str(key: string | Record<string, string>, value?: string): Logger;
297
+ Any(key: string | Record<string, unknown>, value?: unknown): Logger;
278
298
  Dur(key: string, nsec: number): Logger;
279
- Uint64(key: string, value: number): Logger;
280
- Int(key: string, value: number): Logger;
299
+ Uint64(key: string | Record<string, number>, value?: number): Logger;
300
+ Int(key: string | Record<string, number>, value?: number): Logger;
281
301
  Flush(): Promise<void>;
282
302
  With(): WithLogger;
283
303
  _resetAttributes(fn: () => () => Uint8Array): () => Uint8Array;
@@ -555,4 +575,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
555
575
 
556
576
  declare const VERSION: string;
557
577
 
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 };
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 };
package/index.d.ts CHANGED
@@ -40,6 +40,19 @@ declare function exception2Result<FN extends () => Promise<T> | T, T>(fn: FN): W
40
40
  type StripCommand = string | RegExp;
41
41
 
42
42
  type NullOrUndef = null | undefined;
43
+ type OneKey<K extends string, V = string> = Record<K, V>;
44
+ interface URIInterface<R extends URIInterface<R>> {
45
+ readonly getParams: Iterable<[string, string]>;
46
+ hasParam(key: string): boolean;
47
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
48
+ getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
49
+ getParamsResult(...keys: keysParam): Result<Record<string, string>>;
50
+ clone(): R;
51
+ asURL(): URL;
52
+ toString(): string;
53
+ toJSON(): string;
54
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
55
+ }
43
56
  interface URIObject {
44
57
  readonly style: "host" | "path";
45
58
  readonly protocol: string;
@@ -75,8 +88,9 @@ declare class MutableURL extends URL {
75
88
  get searchParams(): URLSearchParams;
76
89
  toString(): string;
77
90
  }
78
- type keysParam = (string | ((...keys: string[]) => string))[];
79
- declare class BuildURI {
91
+ type msgFn = (...keys: string[]) => string;
92
+ type keysParam = (string | msgFn | Record<string, string>)[];
93
+ declare class BuildURI implements URIInterface<BuildURI> {
80
94
  _url: MutableURL;
81
95
  private constructor();
82
96
  static is(value: unknown): value is BuildURI;
@@ -90,18 +104,20 @@ declare class BuildURI {
90
104
  defParam(key: string, str: string): BuildURI;
91
105
  setParam(key: string, str: string): BuildURI;
92
106
  hasParam(key: string): boolean;
93
- getParam(key: string): string | undefined;
107
+ get getParams(): Iterable<[string, string]>;
108
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
94
109
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
95
110
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
96
111
  toString(): string;
97
112
  toJSON(): string;
98
113
  asURL(): URL;
99
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
114
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
115
+ clone(): BuildURI;
100
116
  URI(): URI;
101
117
  }
102
118
  type CoerceURI = string | URI | MutableURL | URL | BuildURI | NullOrUndef;
103
119
  declare const hasHostPartProtocols: Set<string>;
104
- declare class URI {
120
+ declare class URI implements URIInterface<URI> {
105
121
  static protocolHasHostpart(protocol: string): () => void;
106
122
  static merge(into: CoerceURI, from: CoerceURI, defaultProtocol?: string): URI;
107
123
  static is(value: unknown): value is URI;
@@ -117,14 +133,14 @@ declare class URI {
117
133
  get pathname(): string;
118
134
  get getParams(): Iterable<[string, string]>;
119
135
  hasParam(key: string): boolean;
120
- getParam(key: string): string | undefined;
136
+ getParam<T extends string | undefined>(key: string | OneKey<string>, def?: T): T extends string ? string : string | undefined;
121
137
  getParamResult(key: string, msgFn?: (key: string) => string): Result<string>;
122
138
  getParamsResult(...keys: keysParam): Result<Record<string, string>>;
123
139
  clone(): URI;
124
140
  asURL(): URL;
125
141
  toString(): string;
126
142
  toJSON(): string;
127
- asObj(...strips: StripCommand[]): HostURIObject | PathURIObject;
143
+ asObj(...strips: StripCommand[]): Partial<HostURIObject | PathURIObject>;
128
144
  }
129
145
 
130
146
  declare enum Level {
@@ -142,7 +158,6 @@ declare class LogValue {
142
158
  toJSON(): Serialized | Serialized[];
143
159
  }
144
160
  type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
145
- declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
146
161
  declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
147
162
  type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
148
163
  declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
@@ -180,7 +195,13 @@ interface LoggerInterface<R> {
180
195
  Url(url: CoerceURI, key?: string): R;
181
196
  Len(value: unknown, key?: string): R;
182
197
  Hash(value: unknown, key?: string): R;
183
- Str(key: string, value?: string): R;
198
+ Str<T extends string | Record<string, string>>(key: T, value?: T extends string ? string : undefined): R;
199
+ Uint64<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
200
+ Int<T extends string | Record<string, number>>(key: T, value?: T extends string ? number : undefined): R;
201
+ Bool<T extends string | Record<string, unknown>>(key: T, value?: T extends string ? unknown : undefined): R;
202
+ 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
+ Pair(x: Record<string, unknown>): R;
184
205
  Error(): R;
185
206
  Warn(): R;
186
207
  Debug(): R;
@@ -189,11 +210,7 @@ interface LoggerInterface<R> {
189
210
  Err(err: unknown | Result<unknown> | Error): R;
190
211
  Info(): R;
191
212
  Timestamp(): R;
192
- Any(key: string, value: unknown): R;
193
213
  Dur(key: string, nsec: number): R;
194
- Uint64(key: string, value: number): R;
195
- Int(key: string, value: number): R;
196
- Bool(key: string, value: unknown): R;
197
214
  }
198
215
  declare function IsLogger(obj: unknown): obj is Logger;
199
216
  interface WithLogger extends LoggerInterface<WithLogger> {
@@ -268,16 +285,19 @@ declare class LoggerImpl implements Logger {
268
285
  Ref(key: string, action: {
269
286
  toString: () => string;
270
287
  } | FnSerialized): Logger;
271
- Bool(key: string, value: unknown): Logger;
288
+ Bool(key: string | Record<string, unknown>, value: unknown): Logger;
289
+ Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
290
+ Pair(x: Record<string, unknown>): Logger;
272
291
  Result<T>(key: string, res: Result<T, Error>): Logger;
273
292
  Len(value: unknown, key?: string): Logger;
274
293
  Hash(value: unknown, key?: string): Logger;
275
294
  Url(url: CoerceURI, key?: string): Logger;
276
- Str(key: string, value?: string): Logger;
277
- Any(key: string, value?: string | number | boolean | LogSerializable): Logger;
295
+ private coerceKey;
296
+ Str(key: string | Record<string, string>, value?: string): Logger;
297
+ Any(key: string | Record<string, unknown>, value?: unknown): Logger;
278
298
  Dur(key: string, nsec: number): Logger;
279
- Uint64(key: string, value: number): Logger;
280
- Int(key: string, value: number): Logger;
299
+ Uint64(key: string | Record<string, number>, value?: number): Logger;
300
+ Int(key: string | Record<string, number>, value?: number): Logger;
281
301
  Flush(): Promise<void>;
282
302
  With(): WithLogger;
283
303
  _resetAttributes(fn: () => () => Uint8Array): () => Uint8Array;
@@ -555,4 +575,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
555
575
 
556
576
  declare const VERSION: string;
557
577
 
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 };
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 };
package/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ ConsoleWriterStream,
3
+ FanoutWriteStream,
4
+ utils_exports
5
+ } from "./chunk-USQXEZHL.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) {
@@ -337,6 +348,16 @@ function localStripper(path, restrips, obj) {
337
348
  }
338
349
 
339
350
  // src/uri.ts
351
+ function coerceKey(key, def) {
352
+ if (typeof key === "object") {
353
+ const keys = Object.keys(key);
354
+ if (keys.length !== 1) {
355
+ throw new Error(`Invalid key: ${JSON.stringify(key)}`);
356
+ }
357
+ return { key: keys[0], def: key[keys[0]] };
358
+ }
359
+ return { key, def };
360
+ }
340
361
  function falsy2undef(value) {
341
362
  return value === void 0 || value === null ? void 0 : value;
342
363
  }
@@ -483,19 +504,33 @@ function getParamResult(key, val, msgFn = (key2) => {
483
504
  return Result.Ok(val);
484
505
  }
485
506
  function getParamsResult(keys, getParam) {
486
- const keyStrs = keys.flat().filter((k) => typeof k === "string");
507
+ const keyDef = keys.flat().reduce(
508
+ (acc, i) => {
509
+ if (typeof i === "string") {
510
+ acc.push({ key: i });
511
+ } else if (typeof i === "object") {
512
+ acc.push(...Object.keys(i).map((k) => ({ key: k, def: i[k] })));
513
+ }
514
+ return acc;
515
+ },
516
+ []
517
+ );
487
518
  const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
488
519
  const msg = keys2.join(",");
489
520
  return `missing parameters: ${msg}`;
490
521
  });
491
522
  const errors = [];
492
523
  const result = {};
493
- for (const key of keyStrs) {
494
- const val = getParam.getParam(key);
524
+ for (const kd of keyDef) {
525
+ const val = getParam.getParam(kd.key);
495
526
  if (val === void 0) {
496
- errors.push(key);
527
+ if (kd.def) {
528
+ result[kd.key] = kd.def;
529
+ } else {
530
+ errors.push(kd.key);
531
+ }
497
532
  } else {
498
- result[key] = val;
533
+ result[kd.key] = val;
499
534
  }
500
535
  }
501
536
  if (errors.length) {
@@ -587,8 +622,16 @@ var BuildURI = class _BuildURI {
587
622
  hasParam(key) {
588
623
  return this._url.searchParams.has(key);
589
624
  }
590
- getParam(key) {
591
- return falsy2undef(this._url.searchParams.get(key));
625
+ get getParams() {
626
+ return this._url.searchParams.entries();
627
+ }
628
+ getParam(key, def) {
629
+ const { key: k, def: d } = coerceKey(key, def);
630
+ let val = this._url.searchParams.get(k);
631
+ if (!falsy2undef(val) && d) {
632
+ val = d;
633
+ }
634
+ return falsy2undef(val);
592
635
  }
593
636
  getParamResult(key, msgFn) {
594
637
  return getParamResult(key, this.getParam(key), msgFn);
@@ -609,6 +652,9 @@ var BuildURI = class _BuildURI {
609
652
  asObj(...strips) {
610
653
  return this.URI().asObj(...strips);
611
654
  }
655
+ clone() {
656
+ return _BuildURI.from(this.toString());
657
+ }
612
658
  URI() {
613
659
  return URI.from(this._url);
614
660
  }
@@ -688,8 +734,13 @@ var URI = class _URI {
688
734
  hasParam(key) {
689
735
  return this._url.searchParams.has(key);
690
736
  }
691
- getParam(key) {
692
- return falsy2undef(this._url.searchParams.get(key));
737
+ getParam(key, def) {
738
+ const { key: k, def: d } = coerceKey(key, def);
739
+ let val = this._url.searchParams.get(k);
740
+ if (!falsy2undef(val) && d) {
741
+ val = d;
742
+ }
743
+ return falsy2undef(val);
693
744
  }
694
745
  getParamResult(key, msgFn) {
695
746
  return getParamResult(key, this.getParam(key), msgFn);
@@ -910,7 +961,13 @@ var JSONFormatter = class {
910
961
  this._space = space;
911
962
  }
912
963
  format(attr) {
913
- return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
964
+ let ret;
965
+ try {
966
+ ret = JSON.stringify(attr, null, this._space);
967
+ } catch (e) {
968
+ ret = JSON.stringify({ internal: { message: e.message, stack: e.stack } });
969
+ }
970
+ return this._txtEnDe.encode(ret + "\n");
914
971
  }
915
972
  };
916
973
  var YAMLFormatter = class {
@@ -919,7 +976,7 @@ var YAMLFormatter = class {
919
976
  this._space = space;
920
977
  }
921
978
  format(attr) {
922
- return this._txtEnDe.encode("---\n" + YAML.stringify(attr, removeSelfRef(), this._space) + "\n");
979
+ return this._txtEnDe.encode("---\n" + YAML.stringify(attr, null, this._space) + "\n");
923
980
  }
924
981
  };
925
982
  var LoggerImpl = class _LoggerImpl {
@@ -980,7 +1037,7 @@ var LoggerImpl = class _LoggerImpl {
980
1037
  return this._txtEnDe;
981
1038
  }
982
1039
  Attributes() {
983
- return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
1040
+ return JSON.parse(JSON.stringify(this._attributes, null));
984
1041
  }
985
1042
  SetExposeStack(enable) {
986
1043
  this._levelHandler.setExposeStack(enable);
@@ -1064,7 +1121,37 @@ var LoggerImpl = class _LoggerImpl {
1064
1121
  return this;
1065
1122
  }
1066
1123
  Bool(key, value) {
1067
- this._attributes[key] = logValue(!!value);
1124
+ this.coerceKey(key, !!value);
1125
+ return this;
1126
+ }
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 };
1138
+ }
1139
+ this.Any(key || "Http", reqRes);
1140
+ return this;
1141
+ }
1142
+ Pair(x) {
1143
+ for (const key of Object.keys(x)) {
1144
+ const value = x[key];
1145
+ if (value instanceof LogValue) {
1146
+ this._attributes[key] = value;
1147
+ continue;
1148
+ }
1149
+ if (Result.Is(value)) {
1150
+ this.Result(key, value);
1151
+ continue;
1152
+ }
1153
+ this.Any(key, value);
1154
+ }
1068
1155
  return this;
1069
1156
  }
1070
1157
  Result(key, res) {
@@ -1087,12 +1174,19 @@ var LoggerImpl = class _LoggerImpl {
1087
1174
  this.Ref(key, () => URI.from(url).toString());
1088
1175
  return this;
1089
1176
  }
1177
+ coerceKey(key, value) {
1178
+ if (typeof key === "string") {
1179
+ this._attributes[key] = logValue(value);
1180
+ } else {
1181
+ this.Pair(key);
1182
+ }
1183
+ }
1090
1184
  Str(key, value) {
1091
- this._attributes[key] = logValue(value);
1185
+ this.coerceKey(key, value);
1092
1186
  return this;
1093
1187
  }
1094
1188
  Any(key, value) {
1095
- this._attributes[key] = logValue(value);
1189
+ this.coerceKey(key, value);
1096
1190
  return this;
1097
1191
  }
1098
1192
  Dur(key, nsec) {
@@ -1100,7 +1194,7 @@ var LoggerImpl = class _LoggerImpl {
1100
1194
  return this;
1101
1195
  }
1102
1196
  Uint64(key, value) {
1103
- this._attributes[key] = logValue(value);
1197
+ this.coerceKey(key, value);
1104
1198
  return this;
1105
1199
  }
1106
1200
  Int(key, value) {
@@ -1197,6 +1291,14 @@ var WithLoggerBuilder = class {
1197
1291
  this._li.SetDebug(...modules);
1198
1292
  return this;
1199
1293
  }
1294
+ Http(res, req, key) {
1295
+ this._li.Http(res, req, key);
1296
+ return this;
1297
+ }
1298
+ Pair(x) {
1299
+ this._li.Pair(x);
1300
+ return this;
1301
+ }
1200
1302
  Str(key, value) {
1201
1303
  this._li.Str(key, value);
1202
1304
  return this;
@@ -1661,7 +1763,6 @@ export {
1661
1763
  hasHostPartProtocols,
1662
1764
  isURL,
1663
1765
  logValue,
1664
- removeSelfRef,
1665
1766
  runtimeFn,
1666
1767
  toCryptoRuntime,
1667
1768
  utils_exports as utils