@dereekb/util 12.1.14 → 12.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fetch/package.json +1 -1
- package/index.cjs.js +5 -3
- package/index.esm.js +5 -3
- package/package.json +1 -1
- package/src/lib/key.d.ts +4 -0
- package/src/lib/service/handler.config.d.ts +16 -16
- package/src/lib/service/handler.d.ts +15 -10
- package/src/lib/string/index.d.ts +1 -0
- package/src/lib/string/json.d.ts +4 -0
- package/test/CHANGELOG.md +8 -0
- package/test/package.json +1 -1
package/fetch/package.json
CHANGED
package/index.cjs.js
CHANGED
|
@@ -12475,7 +12475,9 @@ class ModelRelationUtility {
|
|
|
12475
12475
|
* Key used to signify
|
|
12476
12476
|
*/
|
|
12477
12477
|
const CATCH_ALL_HANDLE_RESULT_KEY = '__CATCH_ALL_HANDLE_RESULT_KEY__';
|
|
12478
|
-
function handlerFactory(readKey) {
|
|
12478
|
+
function handlerFactory(readKey, options) {
|
|
12479
|
+
const defaultResultValue = options?.defaultResult ?? true;
|
|
12480
|
+
const negativeResultValue = options?.negativeResult ?? false;
|
|
12479
12481
|
return () => {
|
|
12480
12482
|
let catchAll;
|
|
12481
12483
|
const map = new Map();
|
|
@@ -12499,9 +12501,9 @@ function handlerFactory(readKey) {
|
|
|
12499
12501
|
const handler = (key != null ? map.get(key) : undefined) ?? catchAll;
|
|
12500
12502
|
let handled;
|
|
12501
12503
|
if (handler) {
|
|
12502
|
-
handled = Promise.resolve(handler(value)).then(x => x ??
|
|
12504
|
+
handled = Promise.resolve(handler(value)).then(x => x ?? defaultResultValue);
|
|
12503
12505
|
} else {
|
|
12504
|
-
handled = Promise.resolve(
|
|
12506
|
+
handled = Promise.resolve(negativeResultValue);
|
|
12505
12507
|
}
|
|
12506
12508
|
return handled;
|
|
12507
12509
|
},
|
package/index.esm.js
CHANGED
|
@@ -12473,7 +12473,9 @@ class ModelRelationUtility {
|
|
|
12473
12473
|
* Key used to signify
|
|
12474
12474
|
*/
|
|
12475
12475
|
const CATCH_ALL_HANDLE_RESULT_KEY = '__CATCH_ALL_HANDLE_RESULT_KEY__';
|
|
12476
|
-
function handlerFactory(readKey) {
|
|
12476
|
+
function handlerFactory(readKey, options) {
|
|
12477
|
+
const defaultResultValue = options?.defaultResult ?? true;
|
|
12478
|
+
const negativeResultValue = options?.negativeResult ?? false;
|
|
12477
12479
|
return () => {
|
|
12478
12480
|
let catchAll;
|
|
12479
12481
|
const map = new Map();
|
|
@@ -12497,9 +12499,9 @@ function handlerFactory(readKey) {
|
|
|
12497
12499
|
const handler = (key != null ? map.get(key) : undefined) ?? catchAll;
|
|
12498
12500
|
let handled;
|
|
12499
12501
|
if (handler) {
|
|
12500
|
-
handled = Promise.resolve(handler(value)).then(x => x ??
|
|
12502
|
+
handled = Promise.resolve(handler(value)).then(x => x ?? defaultResultValue);
|
|
12501
12503
|
} else {
|
|
12502
|
-
handled = Promise.resolve(
|
|
12504
|
+
handled = Promise.resolve(negativeResultValue);
|
|
12503
12505
|
}
|
|
12504
12506
|
return handled;
|
|
12505
12507
|
},
|
package/package.json
CHANGED
package/src/lib/key.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export type FieldOfType<T> = keyof T;
|
|
|
13
13
|
* Reads a key from the input object.
|
|
14
14
|
*/
|
|
15
15
|
export type ReadKeyFunction<T, K extends PrimativeKey = PrimativeKey> = MapFunction<T, Maybe<K>>;
|
|
16
|
+
/**
|
|
17
|
+
* Reads a key value from the input object that is required to exist.
|
|
18
|
+
*/
|
|
19
|
+
export type ReadRequiredKeyFunction<T, K extends PrimativeKey = PrimativeKey> = MapFunction<T, K>;
|
|
16
20
|
/**
|
|
17
21
|
* Reads one or more keys from the input object.
|
|
18
22
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type MapFunction } from '../value/map';
|
|
2
2
|
import { type ArrayOrValue } from '../array/array';
|
|
3
3
|
import { type PrimativeKey } from '../key';
|
|
4
|
-
import { InternalHandlerFunction, type Handler, type HandlerAccessor, type HandlerSetAccessor } from './handler';
|
|
4
|
+
import { HandleResult, InternalHandlerFunction, type Handler, type HandlerAccessor, type HandlerSetAccessor } from './handler';
|
|
5
5
|
/**
|
|
6
6
|
* Wraps a HandlerAccessor and the item it is bound to in order to be a HandlerSetAccessor.
|
|
7
7
|
*/
|
|
8
|
-
export interface HandlerBindAccessor<T, K extends PrimativeKey = string> extends HandlerSetAccessor<T, K> {
|
|
9
|
-
readonly accessor: HandlerAccessor<T, K>;
|
|
8
|
+
export interface HandlerBindAccessor<T, K extends PrimativeKey = string, R = HandleResult> extends HandlerSetAccessor<T, K, R> {
|
|
9
|
+
readonly accessor: HandlerAccessor<T, K, R>;
|
|
10
10
|
readonly boundTo: unknown;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -16,11 +16,11 @@ export interface HandlerBindAccessor<T, K extends PrimativeKey = string> extends
|
|
|
16
16
|
* @param accessor
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
|
-
export declare function handlerBindAccessor<T, K extends PrimativeKey = string>(boundTo: unknown, accessor: HandlerAccessor<T, K>): HandlerBindAccessor<T, K>;
|
|
19
|
+
export declare function handlerBindAccessor<T, K extends PrimativeKey = string, R = HandleResult>(boundTo: unknown, accessor: HandlerAccessor<T, K, R>): HandlerBindAccessor<T, K, R>;
|
|
20
20
|
/**
|
|
21
21
|
* Contextual function that configures the context's Handler with the input function for the context's key.
|
|
22
22
|
*/
|
|
23
|
-
export type HandlerSetFunction<T> = (handlerFunction: InternalHandlerFunction<T>) => void;
|
|
23
|
+
export type HandlerSetFunction<T, R = HandleResult> = (handlerFunction: InternalHandlerFunction<T, R>) => void;
|
|
24
24
|
/**
|
|
25
25
|
* Creates a HandlerSetFunction.
|
|
26
26
|
*
|
|
@@ -28,21 +28,21 @@ export type HandlerSetFunction<T> = (handlerFunction: InternalHandlerFunction<T>
|
|
|
28
28
|
* @param key
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
export declare function handlerSetFunction<T, K extends PrimativeKey = string>(accessor: HandlerSetAccessor<T, K>, key: ArrayOrValue<K>): HandlerSetFunction<T>;
|
|
32
|
-
export type HandlerMappedSetFunction<I> = (handlerFunction: InternalHandlerFunction<I>) => void;
|
|
33
|
-
export declare function handlerMappedSetFunction<I, T, K extends PrimativeKey = string>(accessor: HandlerSetAccessor<T, K>, key: ArrayOrValue<K>, mapFn: MapFunction<T, I>): HandlerMappedSetFunction<I>;
|
|
31
|
+
export declare function handlerSetFunction<T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, key: ArrayOrValue<K>): HandlerSetFunction<T, R>;
|
|
32
|
+
export type HandlerMappedSetFunction<I, R = HandleResult> = (handlerFunction: InternalHandlerFunction<I, R>) => void;
|
|
33
|
+
export declare function handlerMappedSetFunction<I, T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, key: ArrayOrValue<K>, mapFn: MapFunction<T, I>): HandlerMappedSetFunction<I, R>;
|
|
34
34
|
/**
|
|
35
35
|
* Factory for a HandlerMappedSetFunction<I>.
|
|
36
36
|
*/
|
|
37
|
-
export type HandlerMappedSetFunctionFactory<I, K extends PrimativeKey = string> = (key: ArrayOrValue<K>) => HandlerMappedSetFunction<I>;
|
|
38
|
-
export declare function handlerMappedSetFunctionFactory<I, T, K extends PrimativeKey = string>(accessor: HandlerSetAccessor<T, K>, mapFn: MapFunction<T, I>): HandlerMappedSetFunctionFactory<I, K>;
|
|
39
|
-
export type HandlerConfigurerFunction<C extends HandlerBindAccessor<T, K>, T, K extends PrimativeKey = string> = (configurer: C) => void;
|
|
40
|
-
export type HandlerConfigurer<C extends HandlerBindAccessor<T, K>, T, K extends PrimativeKey = string> = (bindTo: unknown, configure: HandlerConfigurerFunction<C, T, K>) => void;
|
|
41
|
-
export type HandlerConfigurerFactory<C extends HandlerBindAccessor<T, K>, T, K extends PrimativeKey = string> = (handler: Handler<T, K>) => HandlerConfigurer<C, T, K>;
|
|
37
|
+
export type HandlerMappedSetFunctionFactory<I, K extends PrimativeKey = string, R = HandleResult> = (key: ArrayOrValue<K>) => HandlerMappedSetFunction<I, R>;
|
|
38
|
+
export declare function handlerMappedSetFunctionFactory<I, T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, mapFn: MapFunction<T, I>): HandlerMappedSetFunctionFactory<I, K, R>;
|
|
39
|
+
export type HandlerConfigurerFunction<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (configurer: C) => void;
|
|
40
|
+
export type HandlerConfigurer<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (bindTo: unknown, configure: HandlerConfigurerFunction<C, T, K, R>) => void;
|
|
41
|
+
export type HandlerConfigurerFactory<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (handler: Handler<T, K, R>) => HandlerConfigurer<C, T, K, R>;
|
|
42
42
|
/**
|
|
43
43
|
* Config for handlerConfigurerFactory().
|
|
44
44
|
*/
|
|
45
|
-
export interface HandlerConfigurerFactoryConfig<C extends HandlerBindAccessor<T, K>, T, K extends PrimativeKey = string> {
|
|
46
|
-
configurerForAccessor: (accessor: HandlerBindAccessor<T, K>) => C;
|
|
45
|
+
export interface HandlerConfigurerFactoryConfig<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> {
|
|
46
|
+
configurerForAccessor: (accessor: HandlerBindAccessor<T, K, R>) => C;
|
|
47
47
|
}
|
|
48
|
-
export declare function handlerConfigurerFactory<C extends HandlerBindAccessor<T, K>, T, K extends PrimativeKey = string>(config: HandlerConfigurerFactoryConfig<C, T, K>): HandlerConfigurerFactory<C, T, K>;
|
|
48
|
+
export declare function handlerConfigurerFactory<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult>(config: HandlerConfigurerFactoryConfig<C, T, K, R>): HandlerConfigurerFactory<C, T, K, R>;
|
|
@@ -22,27 +22,27 @@ export type HandlerKey<K extends PrimativeKey = string> = K | HandlerCatchAllKey
|
|
|
22
22
|
*
|
|
23
23
|
* If the value is not used/"handled", returns false.
|
|
24
24
|
*/
|
|
25
|
-
export type HandlerFunction<T> = (value: T) => Promise<
|
|
25
|
+
export type HandlerFunction<T, R = HandleResult> = (value: T) => Promise<R>;
|
|
26
26
|
/**
|
|
27
27
|
* HandleFunction, but used only by Handler that can return undefined.
|
|
28
28
|
*/
|
|
29
|
-
export type InternalHandlerFunction<T> = (value: T) => PromiseOrValue<
|
|
30
|
-
export interface HandlerSetAccessor<T, K extends PrimativeKey = string> {
|
|
29
|
+
export type InternalHandlerFunction<T, R = HandleResult> = (value: T) => PromiseOrValue<R | void>;
|
|
30
|
+
export interface HandlerSetAccessor<T, K extends PrimativeKey = string, R = HandleResult> {
|
|
31
31
|
/**
|
|
32
32
|
* Adds a new handler function to the current handler.
|
|
33
33
|
*
|
|
34
34
|
* @param key
|
|
35
35
|
* @param handle
|
|
36
36
|
*/
|
|
37
|
-
set(key: ArrayOrValue<HandlerKey<K>>, handle: InternalHandlerFunction<T>): void;
|
|
37
|
+
set(key: ArrayOrValue<HandlerKey<K>>, handle: InternalHandlerFunction<T, R>): void;
|
|
38
38
|
/**
|
|
39
39
|
* Sets the catch-all handler function to the current handler.
|
|
40
40
|
*
|
|
41
41
|
* @param handle
|
|
42
42
|
*/
|
|
43
|
-
setCatchAll(handle: InternalHandlerFunction<T>): void;
|
|
43
|
+
setCatchAll(handle: InternalHandlerFunction<T, R>): void;
|
|
44
44
|
}
|
|
45
|
-
export interface HandlerAccessor<T, K extends PrimativeKey = string> extends HandlerSetAccessor<T, K> {
|
|
45
|
+
export interface HandlerAccessor<T, K extends PrimativeKey = string, R = HandleResult> extends HandlerSetAccessor<T, K, R> {
|
|
46
46
|
/**
|
|
47
47
|
* Used to read a handler key from the input value.
|
|
48
48
|
*/
|
|
@@ -54,10 +54,15 @@ export interface HandlerAccessor<T, K extends PrimativeKey = string> extends Han
|
|
|
54
54
|
* @param key
|
|
55
55
|
* @param handle
|
|
56
56
|
*/
|
|
57
|
-
bindSet(bindTo: unknown, key: ArrayOrValue<HandlerKey<K>>, handle: InternalHandlerFunction<T>): void;
|
|
57
|
+
bindSet(bindTo: unknown, key: ArrayOrValue<HandlerKey<K>>, handle: InternalHandlerFunction<T, R>): void;
|
|
58
58
|
}
|
|
59
|
-
export type Handler<T, K extends PrimativeKey = string> = HandlerFunction<T> & HandlerAccessor<T, K>;
|
|
60
|
-
export type HandlerFactory<T, K extends PrimativeKey = string> = () => Handler<T, K>;
|
|
61
|
-
export
|
|
59
|
+
export type Handler<T, K extends PrimativeKey = string, R = HandleResult> = HandlerFunction<T, R> & HandlerAccessor<T, K, R>;
|
|
60
|
+
export type HandlerFactory<T, K extends PrimativeKey = string, R = HandleResult> = () => Handler<T, K, R>;
|
|
61
|
+
export interface HandlerFactoryOptions<R = HandleResult> {
|
|
62
|
+
readonly defaultResult: R;
|
|
63
|
+
readonly negativeResult: R;
|
|
64
|
+
}
|
|
65
|
+
export declare function handlerFactory<T, K extends PrimativeKey = string>(readKey: ReadKeyFunction<T, K>): HandlerFactory<T, K, HandleResult>;
|
|
66
|
+
export declare function handlerFactory<T, K extends PrimativeKey = string, R = HandleResult>(readKey: ReadKeyFunction<T, K>, options: HandlerFactoryOptions<R>): HandlerFactory<T, K, R>;
|
|
62
67
|
export declare function makeHandler<T, K extends PrimativeKey = string>(readKey: ReadKeyFunction<T, K>): Handler<T, K>;
|
|
63
68
|
export declare function catchAllHandlerKey(): typeof CATCH_ALL_HANDLE_RESULT_KEY;
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [12.2.1](https://github.com/dereekb/dbx-components/compare/v12.2.0-dev...v12.2.1) (2025-07-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# [12.2.0](https://github.com/dereekb/dbx-components/compare/v12.1.14-dev...v12.2.0) (2025-06-29)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## [12.1.14](https://github.com/dereekb/dbx-components/compare/v12.1.13-dev...v12.1.14) (2025-06-27)
|
|
6
14
|
|
|
7
15
|
|