@adviser/cement 0.2.35 → 0.2.36
Sign up to get free protection for your applications and to get access to all the features.
- package/{chunk-7KFVMTOS.js → chunk-USQXEZHL.js} +7 -7
- package/chunk-USQXEZHL.js.map +1 -0
- package/index.cjs +60 -21
- package/index.cjs.map +1 -1
- package/index.d.cts +33 -16
- package/index.d.ts +33 -16
- package/index.js +55 -16
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/jsr.json +1 -1
- package/src/logger-impl.ts +25 -14
- package/src/logger.ts +5 -5
- package/src/uri.ts +74 -16
- package/src/utils/console-write-stream.ts +6 -6
- package/ts/logger-impl.d.ts +6 -5
- package/ts/logger-impl.d.ts.map +1 -1
- package/ts/logger-impl.js +12 -4
- package/ts/logger-impl.js.map +1 -1
- package/ts/logger.d.ts +5 -5
- package/ts/logger.d.ts.map +1 -1
- package/ts/logger.test.js +30 -0
- package/ts/logger.test.js.map +1 -1
- package/ts/uri.d.ts +21 -5
- package/ts/uri.d.ts.map +1 -1
- package/ts/uri.js +42 -11
- package/ts/uri.js.map +1 -1
- package/ts/uri.test.js +40 -1
- package/ts/uri.test.js.map +1 -1
- package/ts/utils/console-write-stream.js +6 -6
- package/ts/utils/console-write-stream.js.map +1 -1
- package/utils/index.cjs +6 -6
- package/utils/index.cjs.map +1 -1
- package/utils/index.js +1 -1
- package/chunk-7KFVMTOS.js.map +0 -1
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
|
79
|
-
|
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
|
-
|
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
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,7 +133,7 @@ declare class URI {
|
|
117
133
|
get pathname(): string;
|
118
134
|
get getParams(): Iterable<[string, string]>;
|
119
135
|
hasParam(key: string): boolean;
|
120
|
-
getParam<T extends string | undefined>(key: string
|
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;
|
@@ -179,7 +195,11 @@ interface LoggerInterface<R> {
|
|
179
195
|
Url(url: CoerceURI, key?: string): R;
|
180
196
|
Len(value: unknown, key?: string): R;
|
181
197
|
Hash(value: unknown, key?: string): R;
|
182
|
-
Str(key:
|
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;
|
183
203
|
Http(res: Response | Result<Response>, req?: Request, key?: string): R;
|
184
204
|
Pair(x: Record<string, unknown>): R;
|
185
205
|
Error(): R;
|
@@ -190,11 +210,7 @@ interface LoggerInterface<R> {
|
|
190
210
|
Err(err: unknown | Result<unknown> | Error): R;
|
191
211
|
Info(): R;
|
192
212
|
Timestamp(): R;
|
193
|
-
Any(key: string, value: unknown): R;
|
194
213
|
Dur(key: string, nsec: number): R;
|
195
|
-
Uint64(key: string, value: number): R;
|
196
|
-
Int(key: string, value: number): R;
|
197
|
-
Bool(key: string, value: unknown): R;
|
198
214
|
}
|
199
215
|
declare function IsLogger(obj: unknown): obj is Logger;
|
200
216
|
interface WithLogger extends LoggerInterface<WithLogger> {
|
@@ -269,18 +285,19 @@ declare class LoggerImpl implements Logger {
|
|
269
285
|
Ref(key: string, action: {
|
270
286
|
toString: () => string;
|
271
287
|
} | FnSerialized): Logger;
|
272
|
-
Bool(key: string, value: unknown): Logger;
|
288
|
+
Bool(key: string | Record<string, unknown>, value: unknown): Logger;
|
273
289
|
Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
|
274
290
|
Pair(x: Record<string, unknown>): Logger;
|
275
291
|
Result<T>(key: string, res: Result<T, Error>): Logger;
|
276
292
|
Len(value: unknown, key?: string): Logger;
|
277
293
|
Hash(value: unknown, key?: string): Logger;
|
278
294
|
Url(url: CoerceURI, key?: string): Logger;
|
279
|
-
|
280
|
-
|
295
|
+
private coerceKey;
|
296
|
+
Str(key: string | Record<string, string>, value?: string): Logger;
|
297
|
+
Any(key: string | Record<string, unknown>, value?: unknown): Logger;
|
281
298
|
Dur(key: string, nsec: number): Logger;
|
282
|
-
Uint64(key: string, value
|
283
|
-
Int(key: string, value
|
299
|
+
Uint64(key: string | Record<string, number>, value?: number): Logger;
|
300
|
+
Int(key: string | Record<string, number>, value?: number): Logger;
|
284
301
|
Flush(): Promise<void>;
|
285
302
|
With(): WithLogger;
|
286
303
|
_resetAttributes(fn: () => () => Uint8Array): () => Uint8Array;
|
@@ -558,4 +575,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
|
|
558
575
|
|
559
576
|
declare const VERSION: string;
|
560
577
|
|
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 };
|
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
|
79
|
-
|
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
|
-
|
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
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,7 +133,7 @@ declare class URI {
|
|
117
133
|
get pathname(): string;
|
118
134
|
get getParams(): Iterable<[string, string]>;
|
119
135
|
hasParam(key: string): boolean;
|
120
|
-
getParam<T extends string | undefined>(key: string
|
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;
|
@@ -179,7 +195,11 @@ interface LoggerInterface<R> {
|
|
179
195
|
Url(url: CoerceURI, key?: string): R;
|
180
196
|
Len(value: unknown, key?: string): R;
|
181
197
|
Hash(value: unknown, key?: string): R;
|
182
|
-
Str(key:
|
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;
|
183
203
|
Http(res: Response | Result<Response>, req?: Request, key?: string): R;
|
184
204
|
Pair(x: Record<string, unknown>): R;
|
185
205
|
Error(): R;
|
@@ -190,11 +210,7 @@ interface LoggerInterface<R> {
|
|
190
210
|
Err(err: unknown | Result<unknown> | Error): R;
|
191
211
|
Info(): R;
|
192
212
|
Timestamp(): R;
|
193
|
-
Any(key: string, value: unknown): R;
|
194
213
|
Dur(key: string, nsec: number): R;
|
195
|
-
Uint64(key: string, value: number): R;
|
196
|
-
Int(key: string, value: number): R;
|
197
|
-
Bool(key: string, value: unknown): R;
|
198
214
|
}
|
199
215
|
declare function IsLogger(obj: unknown): obj is Logger;
|
200
216
|
interface WithLogger extends LoggerInterface<WithLogger> {
|
@@ -269,18 +285,19 @@ declare class LoggerImpl implements Logger {
|
|
269
285
|
Ref(key: string, action: {
|
270
286
|
toString: () => string;
|
271
287
|
} | FnSerialized): Logger;
|
272
|
-
Bool(key: string, value: unknown): Logger;
|
288
|
+
Bool(key: string | Record<string, unknown>, value: unknown): Logger;
|
273
289
|
Http(res: Response | Result<Response>, req?: Request, key?: string): Logger;
|
274
290
|
Pair(x: Record<string, unknown>): Logger;
|
275
291
|
Result<T>(key: string, res: Result<T, Error>): Logger;
|
276
292
|
Len(value: unknown, key?: string): Logger;
|
277
293
|
Hash(value: unknown, key?: string): Logger;
|
278
294
|
Url(url: CoerceURI, key?: string): Logger;
|
279
|
-
|
280
|
-
|
295
|
+
private coerceKey;
|
296
|
+
Str(key: string | Record<string, string>, value?: string): Logger;
|
297
|
+
Any(key: string | Record<string, unknown>, value?: unknown): Logger;
|
281
298
|
Dur(key: string, nsec: number): Logger;
|
282
|
-
Uint64(key: string, value
|
283
|
-
Int(key: string, value
|
299
|
+
Uint64(key: string | Record<string, number>, value?: number): Logger;
|
300
|
+
Int(key: string | Record<string, number>, value?: number): Logger;
|
284
301
|
Flush(): Promise<void>;
|
285
302
|
With(): WithLogger;
|
286
303
|
_resetAttributes(fn: () => () => Uint8Array): () => Uint8Array;
|
@@ -558,4 +575,4 @@ declare function bin2string(hex: ArrayBufferView, size?: number): string;
|
|
558
575
|
|
559
576
|
declare const VERSION: string;
|
560
577
|
|
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 };
|
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
@@ -2,7 +2,7 @@ import {
|
|
2
2
|
ConsoleWriterStream,
|
3
3
|
FanoutWriteStream,
|
4
4
|
utils_exports
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-USQXEZHL.js";
|
6
6
|
import {
|
7
7
|
WebSysAbstraction
|
8
8
|
} from "./chunk-WMMUXBDX.js";
|
@@ -348,6 +348,16 @@ function localStripper(path, restrips, obj) {
|
|
348
348
|
}
|
349
349
|
|
350
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
|
+
}
|
351
361
|
function falsy2undef(value) {
|
352
362
|
return value === void 0 || value === null ? void 0 : value;
|
353
363
|
}
|
@@ -494,19 +504,33 @@ function getParamResult(key, val, msgFn = (key2) => {
|
|
494
504
|
return Result.Ok(val);
|
495
505
|
}
|
496
506
|
function getParamsResult(keys, getParam) {
|
497
|
-
const
|
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
|
+
);
|
498
518
|
const msgFn = keys.find((k) => typeof k === "function") || ((...keys2) => {
|
499
519
|
const msg = keys2.join(",");
|
500
520
|
return `missing parameters: ${msg}`;
|
501
521
|
});
|
502
522
|
const errors = [];
|
503
523
|
const result = {};
|
504
|
-
for (const
|
505
|
-
const val = getParam.getParam(key);
|
524
|
+
for (const kd of keyDef) {
|
525
|
+
const val = getParam.getParam(kd.key);
|
506
526
|
if (val === void 0) {
|
507
|
-
|
527
|
+
if (kd.def) {
|
528
|
+
result[kd.key] = kd.def;
|
529
|
+
} else {
|
530
|
+
errors.push(kd.key);
|
531
|
+
}
|
508
532
|
} else {
|
509
|
-
result[key] = val;
|
533
|
+
result[kd.key] = val;
|
510
534
|
}
|
511
535
|
}
|
512
536
|
if (errors.length) {
|
@@ -598,10 +622,14 @@ var BuildURI = class _BuildURI {
|
|
598
622
|
hasParam(key) {
|
599
623
|
return this._url.searchParams.has(key);
|
600
624
|
}
|
625
|
+
get getParams() {
|
626
|
+
return this._url.searchParams.entries();
|
627
|
+
}
|
601
628
|
getParam(key, def) {
|
602
|
-
|
603
|
-
|
604
|
-
|
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;
|
605
633
|
}
|
606
634
|
return falsy2undef(val);
|
607
635
|
}
|
@@ -624,6 +652,9 @@ var BuildURI = class _BuildURI {
|
|
624
652
|
asObj(...strips) {
|
625
653
|
return this.URI().asObj(...strips);
|
626
654
|
}
|
655
|
+
clone() {
|
656
|
+
return _BuildURI.from(this.toString());
|
657
|
+
}
|
627
658
|
URI() {
|
628
659
|
return URI.from(this._url);
|
629
660
|
}
|
@@ -704,9 +735,10 @@ var URI = class _URI {
|
|
704
735
|
return this._url.searchParams.has(key);
|
705
736
|
}
|
706
737
|
getParam(key, def) {
|
707
|
-
|
708
|
-
|
709
|
-
|
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;
|
710
742
|
}
|
711
743
|
return falsy2undef(val);
|
712
744
|
}
|
@@ -1089,7 +1121,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1089
1121
|
return this;
|
1090
1122
|
}
|
1091
1123
|
Bool(key, value) {
|
1092
|
-
this.
|
1124
|
+
this.coerceKey(key, !!value);
|
1093
1125
|
return this;
|
1094
1126
|
}
|
1095
1127
|
Http(res, req, key) {
|
@@ -1142,12 +1174,19 @@ var LoggerImpl = class _LoggerImpl {
|
|
1142
1174
|
this.Ref(key, () => URI.from(url).toString());
|
1143
1175
|
return this;
|
1144
1176
|
}
|
1177
|
+
coerceKey(key, value) {
|
1178
|
+
if (typeof key === "string") {
|
1179
|
+
this._attributes[key] = logValue(value);
|
1180
|
+
} else {
|
1181
|
+
this.Pair(key);
|
1182
|
+
}
|
1183
|
+
}
|
1145
1184
|
Str(key, value) {
|
1146
|
-
this.
|
1185
|
+
this.coerceKey(key, value);
|
1147
1186
|
return this;
|
1148
1187
|
}
|
1149
1188
|
Any(key, value) {
|
1150
|
-
this.
|
1189
|
+
this.coerceKey(key, value);
|
1151
1190
|
return this;
|
1152
1191
|
}
|
1153
1192
|
Dur(key, nsec) {
|
@@ -1155,7 +1194,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
1155
1194
|
return this;
|
1156
1195
|
}
|
1157
1196
|
Uint64(key, value) {
|
1158
|
-
this.
|
1197
|
+
this.coerceKey(key, value);
|
1159
1198
|
return this;
|
1160
1199
|
}
|
1161
1200
|
Int(key, value) {
|