@dereekb/util 7.2.0 → 7.5.0
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/CHANGELOG.md +32 -0
- package/package.json +1 -1
- package/src/lib/array/array.boolean.d.ts +1 -1
- package/src/lib/array/array.d.ts +1 -1
- package/src/lib/array/array.index.d.ts +1 -1
- package/src/lib/array/array.limit.d.ts +1 -1
- package/src/lib/array/array.map.d.ts +1 -1
- package/src/lib/array/array.string.js +1 -1
- package/src/lib/array/array.string.js.map +1 -1
- package/src/lib/array/array.unique.d.ts +1 -1
- package/src/lib/array/array.value.d.ts +14 -2
- package/src/lib/array/array.value.js +24 -6
- package/src/lib/array/array.value.js.map +1 -1
- package/src/lib/auth/auth.role.claims.d.ts +4 -3
- package/src/lib/auth/auth.role.claims.js +16 -11
- package/src/lib/auth/auth.role.claims.js.map +1 -1
- package/src/lib/auth/auth.role.d.ts +1 -1
- package/src/lib/date/date.d.ts +1 -1
- package/src/lib/date/date.time.d.ts +1 -1
- package/src/lib/error/error.d.ts +1 -1
- package/src/lib/error/error.server.d.ts +1 -1
- package/src/lib/filter/filter.d.ts +3 -0
- package/src/lib/filter/filter.js.map +1 -1
- package/src/lib/grouping.d.ts +1 -1
- package/src/lib/iterable/iterable.d.ts +8 -1
- package/src/lib/iterable/iterable.js +14 -1
- package/src/lib/iterable/iterable.js.map +1 -1
- package/src/lib/key.d.ts +1 -1
- package/src/lib/misc/host.d.ts +1 -1
- package/src/lib/model/model.conversion.d.ts +1 -1
- package/src/lib/model/model.conversion.js +7 -6
- package/src/lib/model/model.conversion.js.map +1 -1
- package/src/lib/model/model.copy.d.ts +1 -1
- package/src/lib/model/model.d.ts +1 -1
- package/src/lib/model/model.modify.d.ts +1 -1
- package/src/lib/object/index.d.ts +3 -0
- package/src/lib/object/index.js +3 -0
- package/src/lib/object/index.js.map +1 -1
- package/src/lib/object/object.d.ts +4 -112
- package/src/lib/object/object.empty.d.ts +7 -0
- package/src/lib/object/object.empty.js +27 -0
- package/src/lib/object/object.empty.js.map +1 -0
- package/src/lib/object/object.filter.pojo.d.ts +154 -0
- package/src/lib/object/object.filter.pojo.js +235 -0
- package/src/lib/object/object.filter.pojo.js.map +1 -0
- package/src/lib/object/object.filter.tuple.d.ts +64 -0
- package/src/lib/object/object.filter.tuple.js +120 -0
- package/src/lib/object/object.filter.tuple.js.map +1 -0
- package/src/lib/object/object.js +6 -224
- package/src/lib/object/object.js.map +1 -1
- package/src/lib/object/object.map.d.ts +23 -1
- package/src/lib/object/object.map.js +26 -4
- package/src/lib/object/object.map.js.map +1 -1
- package/src/lib/page/page.d.ts +1 -1
- package/src/lib/promise/promise.d.ts +1 -1
- package/src/lib/promise/promise.loop.d.ts +1 -1
- package/src/lib/relation/relation.d.ts +8 -7
- package/src/lib/relation/relation.js +2 -1
- package/src/lib/relation/relation.js.map +1 -1
- package/src/lib/service/typed.service.js +2 -2
- package/src/lib/service/typed.service.js.map +1 -1
- package/src/lib/set/set.allowed.d.ts +1 -1
- package/src/lib/set/set.d.ts +1 -1
- package/src/lib/set/set.hashset.d.ts +1 -1
- package/src/lib/set/set.maybe.d.ts +1 -1
- package/src/lib/storage/storage.memory.d.ts +1 -1
- package/src/lib/storage/storage.object.d.ts +1 -1
- package/src/lib/storage/storage.object.js +4 -3
- package/src/lib/storage/storage.object.js.map +1 -1
- package/src/lib/string.d.ts +1 -1
- package/src/lib/tree/tree.expand.d.ts +1 -1
- package/src/lib/value/index.d.ts +2 -0
- package/src/lib/value/index.js +2 -0
- package/src/lib/value/index.js.map +1 -1
- package/src/lib/value/map.d.ts +5 -1
- package/src/lib/value/maybe.d.ts +16 -41
- package/src/lib/value/maybe.js +57 -4
- package/src/lib/value/maybe.js.map +1 -1
- package/src/lib/value/maybe.type.d.ts +19 -0
- package/src/lib/value/maybe.type.js +3 -0
- package/src/lib/value/maybe.type.js.map +1 -0
- package/src/lib/value/modifier.d.ts +1 -1
- package/src/lib/value/use.d.ts +22 -0
- package/src/lib/value/use.js +41 -0
- package/src/lib/value/use.js.map +1 -0
- package/test/CHANGELOG.md +12 -0
- package/test/package.json +2 -2
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { FieldOfType } from '../key';
|
|
2
|
-
import { Maybe } from '../value/maybe';
|
|
3
|
-
import { FilterFunction } from '../filter/filter';
|
|
4
2
|
export declare type EmptyObject = Record<string, never>;
|
|
5
3
|
export declare function objectHasNoKeys(obj: object): obj is EmptyObject;
|
|
6
4
|
export declare function objectHasKey<T, K extends keyof T = keyof T>(obj: T, key: K): boolean;
|
|
@@ -11,117 +9,11 @@ export declare function applyToMultipleFields<T extends object, X = unknown>(val
|
|
|
11
9
|
export declare function mapToObject<T, K extends PropertyKey>(map: Map<K, T>): {
|
|
12
10
|
[key: PropertyKey]: T;
|
|
13
11
|
};
|
|
14
|
-
export
|
|
15
|
-
copy?: boolean;
|
|
16
|
-
filter?: Omit<KeyValueTupleFilter<T>, 'inverse'>;
|
|
17
|
-
}
|
|
12
|
+
export declare type CopyObjectFunction<T> = (input: T) => T;
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
14
|
+
* Creates a shallow copy of an object using the spread operator.
|
|
20
15
|
*
|
|
21
|
-
* @param
|
|
16
|
+
* @param input
|
|
22
17
|
* @returns
|
|
23
18
|
*/
|
|
24
|
-
export declare function
|
|
25
|
-
/**
|
|
26
|
-
* Returns a copy of the input object with all undefined values filtered from it.
|
|
27
|
-
*
|
|
28
|
-
* @param obj
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
export declare function filterUndefinedValues<T extends object = object>(obj: T, filterNull?: boolean): T;
|
|
32
|
-
/**
|
|
33
|
-
* Returns all keys that are not associated with an undefined value.
|
|
34
|
-
*
|
|
35
|
-
* @param obj
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
export declare function allNonUndefinedKeys<T extends object = object>(obj: T): (keyof T)[];
|
|
39
|
-
export declare function allMaybeSoKeys<T extends object = object>(obj: T): (keyof T)[];
|
|
40
|
-
/**
|
|
41
|
-
* Finds keys from the POJO that meet the filter.
|
|
42
|
-
*
|
|
43
|
-
* @param obj
|
|
44
|
-
* @param filter
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
export declare function findPOJOKeys<T extends object = object>(obj: T, filter: FilterKeyValueTuplesInput<T>): (keyof T)[];
|
|
48
|
-
/**
|
|
49
|
-
* Finds and counts the number of keys from the POJO that meet the filter.
|
|
50
|
-
*
|
|
51
|
-
* @param obj
|
|
52
|
-
* @param filter
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
export declare function countPOJOKeys<T extends object = object>(obj: T, filter?: FilterKeyValueTuplesInput<T>): number;
|
|
56
|
-
/**
|
|
57
|
-
* Removes values, per the the filter config, from the input object.
|
|
58
|
-
*
|
|
59
|
-
* @param obj POJO to remove undefined values from.
|
|
60
|
-
* @param copy Whether or not to return a copy of the input object. Default is true.
|
|
61
|
-
*/
|
|
62
|
-
export declare function filterFromPOJO<T extends object = object>(obj: T, { copy, filter }?: FilterFromPOJO<T>): T;
|
|
63
|
-
export declare function assignValuesToPOJO<T extends object = object>(target: T, obj: T, filter?: FilterKeyValueTuplesInput<T>): T;
|
|
64
|
-
/**
|
|
65
|
-
* Reads all values from the pojo based on the filter and puts them into an array.
|
|
66
|
-
*
|
|
67
|
-
* @param target
|
|
68
|
-
* @param filter
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
export declare function valuesFromPOJO<O = unknown, I extends object = object>(target: I, filter?: FilterKeyValueTuplesInput<I>): O[];
|
|
72
|
-
export declare type KeyValueTuple<T extends object = object, K extends keyof T = keyof T> = [K, T[K]];
|
|
73
|
-
export declare function allKeyValueTuples<T extends object = object, K extends keyof T = keyof T>(obj: T): KeyValueTuple<T, K>[];
|
|
74
|
-
export declare enum KeyValueTypleValueFilter {
|
|
75
|
-
/**
|
|
76
|
-
* No filter
|
|
77
|
-
*/
|
|
78
|
-
NONE = 0,
|
|
79
|
-
/**
|
|
80
|
-
* Only undefined values.
|
|
81
|
-
*/
|
|
82
|
-
UNDEFINED = 1,
|
|
83
|
-
/**
|
|
84
|
-
* All values that are null or undefined.
|
|
85
|
-
*/
|
|
86
|
-
NULL = 2,
|
|
87
|
-
/**
|
|
88
|
-
* All values that are falsy.
|
|
89
|
-
*/
|
|
90
|
-
FALSY = 3
|
|
91
|
-
}
|
|
92
|
-
export declare type ForEachKeyValueFunction<T extends object = object, K extends keyof T = keyof T> = (tuple: KeyValueTuple<T, K>, index: number) => void;
|
|
93
|
-
export interface ForEachKeyValue<T extends object = object, K extends keyof T = keyof T> {
|
|
94
|
-
filter?: FilterKeyValueTuplesInput<T, K>;
|
|
95
|
-
forEach: ForEachKeyValueFunction<T, K>;
|
|
96
|
-
}
|
|
97
|
-
export declare function forEachKeyValue<T extends object = object, K extends keyof T = keyof T>(obj: T, { forEach, filter }: ForEachKeyValue<T, K>): void;
|
|
98
|
-
export declare function filterKeyValueTuples<T extends object = object, K extends keyof T = keyof T>(obj: T, filter?: FilterKeyValueTuplesInput<T, K>): KeyValueTuple<T, K>[];
|
|
99
|
-
export interface KeyValueTupleFilter<T extends object = object, K extends keyof T = keyof T> {
|
|
100
|
-
valueFilter?: KeyValueTypleValueFilter;
|
|
101
|
-
invertFilter?: boolean;
|
|
102
|
-
keysFilter?: K[];
|
|
103
|
-
}
|
|
104
|
-
export declare type FilterKeyValueTuplesInput<T extends object = object, K extends keyof T = keyof T> = KeyValueTypleValueFilter | KeyValueTupleFilter<T, K>;
|
|
105
|
-
export declare type FilterKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T> = FilterFunction<KeyValueTuple<T, K>>;
|
|
106
|
-
export declare function filterKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T>(input: FilterKeyValueTuplesInput<T, K>): FilterKeyValueTupleFunction<T, K>;
|
|
107
|
-
/**
|
|
108
|
-
* Recursively function that returns true if the input is not an object or if every key on the object is empty.
|
|
109
|
-
*
|
|
110
|
-
* @param obj
|
|
111
|
-
*/
|
|
112
|
-
export declare function objectIsEmpty<T extends object>(obj: Maybe<T>): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Merges all input objects into one. The order of overrides is kept, so the right-most item in the array will have priority over all objects before it.
|
|
115
|
-
*
|
|
116
|
-
* @param objects
|
|
117
|
-
*/
|
|
118
|
-
export declare function mergeObjects<T extends object>(objects: Maybe<Partial<T>>[], filter?: KeyValueTupleFilter<T>): Partial<T>;
|
|
119
|
-
/**
|
|
120
|
-
* Assigns all undefined valeus from one or more objects into the target object.
|
|
121
|
-
*
|
|
122
|
-
* @param object
|
|
123
|
-
*/
|
|
124
|
-
export declare function overrideInObject<T extends object>(target: Partial<T>, { from, filter }: {
|
|
125
|
-
from: Partial<T>[];
|
|
126
|
-
filter?: KeyValueTupleFilter<T>;
|
|
127
|
-
}): Partial<T>;
|
|
19
|
+
export declare function copyObject<T extends object>(input: T): T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Maybe } from '../value/maybe.type';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively function that returns true if the input is not an object or if every key on the object is empty.
|
|
4
|
+
*
|
|
5
|
+
* @param obj
|
|
6
|
+
*/
|
|
7
|
+
export declare function objectIsEmpty<T extends object>(obj: Maybe<T>): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectIsEmpty = void 0;
|
|
4
|
+
const maybe_1 = require("../value/maybe");
|
|
5
|
+
/**
|
|
6
|
+
* Recursively function that returns true if the input is not an object or if every key on the object is empty.
|
|
7
|
+
*
|
|
8
|
+
* @param obj
|
|
9
|
+
*/
|
|
10
|
+
function objectIsEmpty(obj) {
|
|
11
|
+
if (obj != null && typeof obj === 'object') {
|
|
12
|
+
const keys = Object.keys(obj);
|
|
13
|
+
if (keys.length > 0) {
|
|
14
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
15
|
+
const key = keys[i];
|
|
16
|
+
const value = obj[key];
|
|
17
|
+
const isEmpty = typeof obj === 'object' ? objectIsEmpty(value) : !(0, maybe_1.hasValueOrNotEmpty)(value);
|
|
18
|
+
if (!isEmpty) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
exports.objectIsEmpty = objectIsEmpty;
|
|
27
|
+
//# sourceMappingURL=object.empty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.empty.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/object/object.empty.ts"],"names":[],"mappings":";;;AACA,0CAAoD;AAEpD;;;;GAIG;AACH,SAAgB,aAAa,CAAmB,GAAa;IAC3D,IAAI,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;gBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACpB,MAAM,KAAK,GAAI,GAAS,CAAC,GAAc,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAS,KAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC;gBAEhI,IAAI,CAAC,OAAO,EAAE;oBACZ,OAAO,KAAK,CAAC;iBACd;aACF;SACF;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAlBD,sCAkBC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Maybe } from '../value/maybe.type';
|
|
2
|
+
import { FilterKeyValueTuplesInput, KeyValueTuple, KeyValueTupleFilter } from './object.filter.tuple';
|
|
3
|
+
/**
|
|
4
|
+
* Assigns all undefined values from one or more objects into the target object.
|
|
5
|
+
*
|
|
6
|
+
* @param object
|
|
7
|
+
*/
|
|
8
|
+
export declare function overrideInObject<T extends object>(target: Partial<T>, { copy, from, filter }: {
|
|
9
|
+
copy?: boolean;
|
|
10
|
+
from: Partial<T>[];
|
|
11
|
+
filter?: KeyValueTupleFilter<T>;
|
|
12
|
+
}): Partial<T>;
|
|
13
|
+
export declare type OverrideInObjectFunction<T> = (target: Partial<T>) => Partial<T>;
|
|
14
|
+
export declare type OverrideInObjectFunctionFactory<T> = (from: Partial<T>[]) => OverrideInObjectFunction<T>;
|
|
15
|
+
export interface OverrideInObjectFunctionFactoryConfig<T extends object> {
|
|
16
|
+
filter?: KeyValueTupleFilter<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Whether or not to return a copy of the input value, rather than change it directly.
|
|
19
|
+
* If true, a copy of the input object will be returned.
|
|
20
|
+
* If false, the input object will be modified.
|
|
21
|
+
*
|
|
22
|
+
* False by default.
|
|
23
|
+
*/
|
|
24
|
+
copy?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether or not the template being applied to objects should be recalculated each time.
|
|
27
|
+
*
|
|
28
|
+
* This is only necessary if you expect the input targets to change and you want those changes reflected in your copy functions.
|
|
29
|
+
*
|
|
30
|
+
* False by default.
|
|
31
|
+
*/
|
|
32
|
+
dynamic?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function overrideInObjectFunctionFactory<T extends object>({ filter, copy, dynamic }: OverrideInObjectFunctionFactoryConfig<T>): OverrideInObjectFunctionFactory<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Merges all input objects into one. The order of overrides is kept, so the right-most item in the array will have priority over all objects before it.
|
|
37
|
+
*
|
|
38
|
+
* @param objects
|
|
39
|
+
*/
|
|
40
|
+
export declare function mergeObjects<T extends object>(objects: Maybe<Partial<T>>[], filter?: KeyValueTupleFilter<T>): Partial<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Merges all values from the input objects into a single object.
|
|
43
|
+
*
|
|
44
|
+
* The order of overrides is kept, so the right-most item in the array will have priority over all objects before it.
|
|
45
|
+
*/
|
|
46
|
+
export declare type MergeObjectsFunction<T extends object> = (objects: Maybe<Partial<T>>[]) => Partial<T>;
|
|
47
|
+
export declare function mergeObjectsFunction<T extends object>(filter?: KeyValueTupleFilter<T>): MergeObjectsFunction<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a copy of the input object with all undefined (and null values if filterNull=true) values filtered/removed from it.
|
|
50
|
+
*
|
|
51
|
+
* @param obj
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export declare function filterUndefinedValues<T extends object>(obj: T, filterNull?: boolean): T;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a copy of the input object with all undefined values filtered from it.
|
|
57
|
+
*
|
|
58
|
+
* @param obj
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export declare const filterOnlyUndefinedValues: GeneralFilterFromPOJOFunction;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a copy of the input object with all null and undefined values filtered from it.
|
|
64
|
+
*
|
|
65
|
+
* @param obj
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export declare const filterNullAndUndefinedValues: GeneralFilterFromPOJOFunction;
|
|
69
|
+
/**
|
|
70
|
+
* Returns all keys that are not associated with an undefined value.
|
|
71
|
+
*
|
|
72
|
+
* @param obj
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
export declare const allNonUndefinedKeys: GeneralFindPOJOKeysFunction;
|
|
76
|
+
/**
|
|
77
|
+
* Returns all keys that are not associated with a null/undefined value.
|
|
78
|
+
*
|
|
79
|
+
* @param obj
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
export declare const allMaybeSoKeys: GeneralFindPOJOKeysFunction;
|
|
83
|
+
/**
|
|
84
|
+
* Finds keys from the POJO that meet the filter.
|
|
85
|
+
*
|
|
86
|
+
* @param obj
|
|
87
|
+
* @param filter
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
export declare function findPOJOKeys<T extends object>(obj: T, filter: FilterKeyValueTuplesInput<T>): (keyof T)[];
|
|
91
|
+
/**
|
|
92
|
+
* Finds and finds the number of keys from the POJO that meet the filter.
|
|
93
|
+
*/
|
|
94
|
+
export declare type FindPOJOKeysFunction<T> = (obj: T) => (keyof T)[];
|
|
95
|
+
export declare type GeneralFindPOJOKeysFunction = <T extends object>(obj: T) => (keyof T)[];
|
|
96
|
+
export declare function findPOJOKeysFunction<T extends object>(filter: FilterKeyValueTuplesInput<T>): FindPOJOKeysFunction<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Finds and counts the number of keys from the POJO that meet the filter.
|
|
99
|
+
*
|
|
100
|
+
* @param obj
|
|
101
|
+
* @param filter
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
export declare function countPOJOKeys<T extends object>(obj: T, filter?: FilterKeyValueTuplesInput<T>): number;
|
|
105
|
+
/**
|
|
106
|
+
* Finds and counts the number of keys from the POJO that meet the filter.
|
|
107
|
+
*/
|
|
108
|
+
export declare type CountPOJOKeysFunction<T> = (obj: T) => number;
|
|
109
|
+
export declare function countPOJOKeysFunction<T extends object>(filter?: FilterKeyValueTuplesInput<T>): CountPOJOKeysFunction<T>;
|
|
110
|
+
export interface FilterFromPOJO<T extends object> {
|
|
111
|
+
copy?: boolean;
|
|
112
|
+
filter?: Omit<FilterKeyValueTuplesInput<T>, 'inverse'>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Removes values, per the the filter config, from the input object.
|
|
116
|
+
*
|
|
117
|
+
* @param obj POJO to remove undefined values from.
|
|
118
|
+
* @param copy Whether or not to return a copy of the input object. Default is true.
|
|
119
|
+
*/
|
|
120
|
+
export declare function filterFromPOJO<T extends object>(obj: T, config?: FilterFromPOJO<T>): T;
|
|
121
|
+
/**
|
|
122
|
+
* Removes values from the input object.
|
|
123
|
+
*
|
|
124
|
+
* @param obj POJO to remove undefined values from.
|
|
125
|
+
* @param copy Whether or not to return a copy of the input object. Default is true.
|
|
126
|
+
*/
|
|
127
|
+
export declare type FilterFromPOJOFunction<T> = (input: T) => T;
|
|
128
|
+
export declare type GeneralFilterFromPOJOFunction<X = object> = <T extends X>(input: T) => T;
|
|
129
|
+
export declare function filterFromPOJOFunction<T extends object>({ copy, filter: inputFilter }?: FilterFromPOJO<T>): FilterFromPOJOFunction<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Convenience function from filterFromPOJOFunction with copy set to false and using the default filter.
|
|
132
|
+
*/
|
|
133
|
+
export declare const defaultFilterFromPOJOFunctionNoCopy: FilterFromPOJOFunction<object>;
|
|
134
|
+
export declare function assignValuesToPOJO<T extends object>(target: T, obj: T, filter?: FilterKeyValueTuplesInput<T>): T;
|
|
135
|
+
export declare type AssignValuesToPOJOFunction<T> = (target: T, obj: T) => T;
|
|
136
|
+
export declare function assignValuesToPOJOFunction<T extends object>(filter?: FilterKeyValueTuplesInput<T>): AssignValuesToPOJOFunction<T>;
|
|
137
|
+
/**
|
|
138
|
+
* Reads values from matching keys based on the filter and puts them into an array.
|
|
139
|
+
*/
|
|
140
|
+
export declare function valuesFromPOJO<O = unknown, I extends object = object>(target: I, filter?: FilterKeyValueTuplesInput<I>): O[];
|
|
141
|
+
/**
|
|
142
|
+
* Reads values from matching keys based on the filter and puts them into an array.
|
|
143
|
+
*/
|
|
144
|
+
export declare type ValuesFromPOJOFunction<O = unknown, I extends object = object> = (obj: I) => O[];
|
|
145
|
+
export declare function valuesFromPOJOFunction<O = unknown, I extends object = object>(filter?: FilterKeyValueTuplesInput<I>): ValuesFromPOJOFunction<O, I>;
|
|
146
|
+
export declare type ForEachKeyValueOnPOJOTupleFunction<T extends object, C = unknown, K extends keyof T = keyof T> = (tuple: KeyValueTuple<T, K>, index: number, object: T, context: C) => void;
|
|
147
|
+
export declare type ForEachKeyValueOnPOJOFunction<T extends object, C = unknown> = C extends void ? ForEachKeyValueOnPOJOFunctionWithoutContext<T> : ForEachKeyValueOnPOJOFunctionWithContext<T, C>;
|
|
148
|
+
export declare type ForEachKeyValueOnPOJOFunctionWithoutContext<T extends object> = (object: T) => void;
|
|
149
|
+
export declare type ForEachKeyValueOnPOJOFunctionWithContext<T extends object, C = unknown> = (object: T, context: C) => void;
|
|
150
|
+
export declare type ForEachKeyValueOnPOJOConfig<T extends object, C = unknown, K extends keyof T = keyof T> = {
|
|
151
|
+
filter?: FilterKeyValueTuplesInput<T, K>;
|
|
152
|
+
forEach: ForEachKeyValueOnPOJOTupleFunction<T, C, K>;
|
|
153
|
+
};
|
|
154
|
+
export declare function forEachKeyValueOnPOJOFunction<T extends object, C = unknown, K extends keyof T = keyof T>({ forEach, filter }: ForEachKeyValueOnPOJOConfig<T, C, K>): ForEachKeyValueOnPOJOFunction<T, C>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forEachKeyValueOnPOJOFunction = exports.valuesFromPOJOFunction = exports.valuesFromPOJO = exports.assignValuesToPOJOFunction = exports.assignValuesToPOJO = exports.defaultFilterFromPOJOFunctionNoCopy = exports.filterFromPOJOFunction = exports.filterFromPOJO = exports.countPOJOKeysFunction = exports.countPOJOKeys = exports.findPOJOKeysFunction = exports.findPOJOKeys = exports.allMaybeSoKeys = exports.allNonUndefinedKeys = exports.filterNullAndUndefinedValues = exports.filterOnlyUndefinedValues = exports.filterUndefinedValues = exports.mergeObjectsFunction = exports.mergeObjects = exports.overrideInObjectFunctionFactory = exports.overrideInObject = void 0;
|
|
4
|
+
const array_value_1 = require("../array/array.value");
|
|
5
|
+
const object_filter_tuple_1 = require("./object.filter.tuple");
|
|
6
|
+
const getter_1 = require("../getter");
|
|
7
|
+
const object_1 = require("./object");
|
|
8
|
+
// MARK: Object Merging/Overriding
|
|
9
|
+
/**
|
|
10
|
+
* Assigns all undefined values from one or more objects into the target object.
|
|
11
|
+
*
|
|
12
|
+
* @param object
|
|
13
|
+
*/
|
|
14
|
+
function overrideInObject(target, { copy = false, from, filter }) {
|
|
15
|
+
return overrideInObjectFunctionFactory({
|
|
16
|
+
copy,
|
|
17
|
+
filter,
|
|
18
|
+
dynamic: true // using only once, so no need to use the cache
|
|
19
|
+
})(from)(target);
|
|
20
|
+
}
|
|
21
|
+
exports.overrideInObject = overrideInObject;
|
|
22
|
+
function overrideInObjectFunctionFactory({ filter, copy, dynamic = false }) {
|
|
23
|
+
const filterToRelevantValuesObject = filter != null ? filterFromPOJOFunction({ filter, copy: false }) : exports.defaultFilterFromPOJOFunctionNoCopy;
|
|
24
|
+
return (from) => {
|
|
25
|
+
const rebuildTemplate = () => {
|
|
26
|
+
const template = {};
|
|
27
|
+
from.forEach((x) => {
|
|
28
|
+
const relevantValues = filterToRelevantValuesObject(Object.assign({}, x));
|
|
29
|
+
Object.assign(template, relevantValues);
|
|
30
|
+
});
|
|
31
|
+
return template;
|
|
32
|
+
};
|
|
33
|
+
const templateGetter = dynamic ? rebuildTemplate : (0, getter_1.cachedGetter)(rebuildTemplate);
|
|
34
|
+
return (target) => {
|
|
35
|
+
const template = templateGetter();
|
|
36
|
+
if (copy) {
|
|
37
|
+
target = (0, object_1.copyObject)(target);
|
|
38
|
+
}
|
|
39
|
+
Object.assign(target, template);
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.overrideInObjectFunctionFactory = overrideInObjectFunctionFactory;
|
|
45
|
+
/**
|
|
46
|
+
* Merges all input objects into one. The order of overrides is kept, so the right-most item in the array will have priority over all objects before it.
|
|
47
|
+
*
|
|
48
|
+
* @param objects
|
|
49
|
+
*/
|
|
50
|
+
function mergeObjects(objects, filter) {
|
|
51
|
+
return mergeObjectsFunction(filter)(objects);
|
|
52
|
+
}
|
|
53
|
+
exports.mergeObjects = mergeObjects;
|
|
54
|
+
function mergeObjectsFunction(filter) {
|
|
55
|
+
const overrideFn = overrideInObjectFunctionFactory({
|
|
56
|
+
filter,
|
|
57
|
+
copy: false,
|
|
58
|
+
dynamic: true // no need to use cache, as cache won't be used.
|
|
59
|
+
});
|
|
60
|
+
return (objects) => overrideFn((0, array_value_1.filterMaybeValues)(objects))({});
|
|
61
|
+
}
|
|
62
|
+
exports.mergeObjectsFunction = mergeObjectsFunction;
|
|
63
|
+
// MARK: POJO
|
|
64
|
+
/**
|
|
65
|
+
* Returns a copy of the input object with all undefined (and null values if filterNull=true) values filtered/removed from it.
|
|
66
|
+
*
|
|
67
|
+
* @param obj
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
function filterUndefinedValues(obj, filterNull = false) {
|
|
71
|
+
const filterFn = filterNull ? exports.filterNullAndUndefinedValues : exports.filterOnlyUndefinedValues;
|
|
72
|
+
return filterFn(obj);
|
|
73
|
+
}
|
|
74
|
+
exports.filterUndefinedValues = filterUndefinedValues;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a copy of the input object with all undefined values filtered from it.
|
|
77
|
+
*
|
|
78
|
+
* @param obj
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
exports.filterOnlyUndefinedValues = filterFromPOJOFunction({ copy: true, filter: { valueFilter: object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED } });
|
|
82
|
+
/**
|
|
83
|
+
* Returns a copy of the input object with all null and undefined values filtered from it.
|
|
84
|
+
*
|
|
85
|
+
* @param obj
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
exports.filterNullAndUndefinedValues = filterFromPOJOFunction({ copy: true, filter: { valueFilter: object_filter_tuple_1.KeyValueTypleValueFilter.NULL } });
|
|
89
|
+
/**
|
|
90
|
+
* Returns all keys that are not associated with an undefined value.
|
|
91
|
+
*
|
|
92
|
+
* @param obj
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
exports.allNonUndefinedKeys = findPOJOKeysFunction({ valueFilter: object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED });
|
|
96
|
+
/**
|
|
97
|
+
* Returns all keys that are not associated with a null/undefined value.
|
|
98
|
+
*
|
|
99
|
+
* @param obj
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
exports.allMaybeSoKeys = findPOJOKeysFunction({ valueFilter: object_filter_tuple_1.KeyValueTypleValueFilter.NULL });
|
|
103
|
+
// MARK: FindPOJOKeys
|
|
104
|
+
/**
|
|
105
|
+
* Finds keys from the POJO that meet the filter.
|
|
106
|
+
*
|
|
107
|
+
* @param obj
|
|
108
|
+
* @param filter
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
function findPOJOKeys(obj, filter) {
|
|
112
|
+
return findPOJOKeysFunction(filter)(obj);
|
|
113
|
+
}
|
|
114
|
+
exports.findPOJOKeys = findPOJOKeys;
|
|
115
|
+
function findPOJOKeysFunction(filter) {
|
|
116
|
+
const findEachMatchingKeyOnTarget = forEachKeyValueOnPOJOFunction({
|
|
117
|
+
filter,
|
|
118
|
+
forEach: ([key], i, obj, context) => {
|
|
119
|
+
context.keys.push(key);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return (obj) => {
|
|
123
|
+
const context = { keys: [] };
|
|
124
|
+
findEachMatchingKeyOnTarget(obj, context);
|
|
125
|
+
return context.keys;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
exports.findPOJOKeysFunction = findPOJOKeysFunction;
|
|
129
|
+
// MARK: CountPOJOKeys
|
|
130
|
+
/**
|
|
131
|
+
* Finds and counts the number of keys from the POJO that meet the filter.
|
|
132
|
+
*
|
|
133
|
+
* @param obj
|
|
134
|
+
* @param filter
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
function countPOJOKeys(obj, filter = object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED) {
|
|
138
|
+
return countPOJOKeysFunction(filter)(obj);
|
|
139
|
+
}
|
|
140
|
+
exports.countPOJOKeys = countPOJOKeys;
|
|
141
|
+
function countPOJOKeysFunction(filter = object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED) {
|
|
142
|
+
const countEachMatchingKeyOnTarget = forEachKeyValueOnPOJOFunction({
|
|
143
|
+
filter,
|
|
144
|
+
forEach: (x, i, obj, context) => {
|
|
145
|
+
context.count += 1;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return (obj) => {
|
|
149
|
+
const context = { count: 0 };
|
|
150
|
+
countEachMatchingKeyOnTarget(obj, context);
|
|
151
|
+
return context.count;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
exports.countPOJOKeysFunction = countPOJOKeysFunction;
|
|
155
|
+
/**
|
|
156
|
+
* Removes values, per the the filter config, from the input object.
|
|
157
|
+
*
|
|
158
|
+
* @param obj POJO to remove undefined values from.
|
|
159
|
+
* @param copy Whether or not to return a copy of the input object. Default is true.
|
|
160
|
+
*/
|
|
161
|
+
function filterFromPOJO(obj, config = {}) {
|
|
162
|
+
return filterFromPOJOFunction(config)(obj);
|
|
163
|
+
}
|
|
164
|
+
exports.filterFromPOJO = filterFromPOJO;
|
|
165
|
+
function filterFromPOJOFunction({ copy = false, filter: inputFilter = { valueFilter: object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED } } = {}) {
|
|
166
|
+
const filter = (0, object_filter_tuple_1.filterKeyValueTuplesInputToFilter)(inputFilter);
|
|
167
|
+
filter.invertFilter = !filter.invertFilter; // use the inversion of the filter to retain values
|
|
168
|
+
const forEachFn = forEachKeyValueOnPOJOFunction({
|
|
169
|
+
filter,
|
|
170
|
+
forEach: ([key], i, object) => {
|
|
171
|
+
delete object[key];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return (obj) => {
|
|
175
|
+
if (copy) {
|
|
176
|
+
obj = Object.assign({}, obj);
|
|
177
|
+
}
|
|
178
|
+
forEachFn(obj);
|
|
179
|
+
return obj;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
exports.filterFromPOJOFunction = filterFromPOJOFunction;
|
|
183
|
+
/**
|
|
184
|
+
* Convenience function from filterFromPOJOFunction with copy set to false and using the default filter.
|
|
185
|
+
*/
|
|
186
|
+
exports.defaultFilterFromPOJOFunctionNoCopy = filterFromPOJOFunction({ copy: false });
|
|
187
|
+
// MARK: AssignValuesToPOJO
|
|
188
|
+
function assignValuesToPOJO(target, obj, filter) {
|
|
189
|
+
return assignValuesToPOJOFunction(filter)(target, obj);
|
|
190
|
+
}
|
|
191
|
+
exports.assignValuesToPOJO = assignValuesToPOJO;
|
|
192
|
+
function assignValuesToPOJOFunction(filter = object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED) {
|
|
193
|
+
const assignEachValueToTarget = forEachKeyValueOnPOJOFunction({
|
|
194
|
+
filter,
|
|
195
|
+
forEach: ([key, value], i, object, target) => {
|
|
196
|
+
target[key] = value;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return (target, obj) => {
|
|
200
|
+
assignEachValueToTarget(obj, target);
|
|
201
|
+
return obj;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
exports.assignValuesToPOJOFunction = assignValuesToPOJOFunction;
|
|
205
|
+
// MARK: ValuesFromPOJO
|
|
206
|
+
/**
|
|
207
|
+
* Reads values from matching keys based on the filter and puts them into an array.
|
|
208
|
+
*/
|
|
209
|
+
function valuesFromPOJO(target, filter = object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED) {
|
|
210
|
+
return valuesFromPOJOFunction(filter)(target);
|
|
211
|
+
}
|
|
212
|
+
exports.valuesFromPOJO = valuesFromPOJO;
|
|
213
|
+
function valuesFromPOJOFunction(filter = object_filter_tuple_1.KeyValueTypleValueFilter.UNDEFINED) {
|
|
214
|
+
const addValuesFromObjectToContext = forEachKeyValueOnPOJOFunction({
|
|
215
|
+
filter,
|
|
216
|
+
forEach: ([, value], i, obj, context) => {
|
|
217
|
+
context.values.push(value);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return (obj) => {
|
|
221
|
+
const context = { values: [] };
|
|
222
|
+
addValuesFromObjectToContext(obj, context);
|
|
223
|
+
return context.values;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
exports.valuesFromPOJOFunction = valuesFromPOJOFunction;
|
|
227
|
+
function forEachKeyValueOnPOJOFunction({ forEach, filter }) {
|
|
228
|
+
const filterKeyValues = (0, object_filter_tuple_1.filterKeyValueTuplesFunction)(filter);
|
|
229
|
+
return ((obj, context) => {
|
|
230
|
+
const keyValues = filterKeyValues(obj);
|
|
231
|
+
keyValues.forEach((x, i) => forEach(x, i, obj, context));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
exports.forEachKeyValueOnPOJOFunction = forEachKeyValueOnPOJOFunction;
|
|
235
|
+
//# sourceMappingURL=object.filter.pojo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.filter.pojo.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/object/object.filter.pojo.ts"],"names":[],"mappings":";;;AACA,sDAAyD;AACzD,+DAAiM;AACjM,sCAAiD;AACjD,qCAAsC;AAEtC,kCAAkC;AAClC;;;;GAIG;AACH,SAAgB,gBAAgB,CAAmB,MAAkB,EAAE,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,EAA2E;IAC5K,OAAO,+BAA+B,CAAC;QACrC,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,IAAI,CAAC,+CAA+C;KAC9D,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACnB,CAAC;AAND,4CAMC;AAyBD,SAAgB,+BAA+B,CAAmB,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,EAA4C;IAC3I,MAAM,4BAA4B,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OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAwC,CAAC;AAC5C,CAAC;AAPD,sEAOC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FilterFunction } from '../filter/filter';
|
|
2
|
+
export declare type ForEachKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T> = (tuple: KeyValueTuple<T, K>, index: number) => void;
|
|
3
|
+
export interface ForEachKeyValue<T extends object = object, K extends keyof T = keyof T> {
|
|
4
|
+
filter?: FilterKeyValueTuplesInput<T, K>;
|
|
5
|
+
forEach: ForEachKeyValueTupleFunction<T, K>;
|
|
6
|
+
}
|
|
7
|
+
export declare function forEachKeyValue<T extends object = object, K extends keyof T = keyof T>(obj: T, { forEach, filter }: ForEachKeyValue<T, K>): void;
|
|
8
|
+
export declare function filterKeyValueTuples<T extends object = object, K extends keyof T = keyof T>(obj: T, filter?: FilterKeyValueTuplesInput<T, K>): KeyValueTuple<T, K>[];
|
|
9
|
+
/**
|
|
10
|
+
* A Key-Value pair within an Tuple array value.
|
|
11
|
+
*/
|
|
12
|
+
export declare type KeyValueTuple<T extends object = object, K extends keyof T = keyof T> = [K, T[K]];
|
|
13
|
+
export declare type FilterKeyValueTuplesFunction<T extends object = object, K extends keyof T = keyof T> = (obj: T) => KeyValueTuple<T, K>[];
|
|
14
|
+
export declare function filterKeyValueTuplesFunction<T extends object = object, K extends keyof T = keyof T>(filter?: FilterKeyValueTuplesInput<T, K>): FilterKeyValueTuplesFunction<T, K>;
|
|
15
|
+
export declare function allKeyValueTuples<T extends object = object, K extends keyof T = keyof T>(obj: T): KeyValueTuple<T, K>[];
|
|
16
|
+
export declare type FilterKeyValueTuplesInput<T extends object = object, K extends keyof T = keyof T> = KeyValueTypleValueFilter | KeyValueTupleFilter<T, K>;
|
|
17
|
+
export declare enum KeyValueTypleValueFilter {
|
|
18
|
+
/**
|
|
19
|
+
* No filter
|
|
20
|
+
*/
|
|
21
|
+
NONE = 0,
|
|
22
|
+
/**
|
|
23
|
+
* Only undefined values.
|
|
24
|
+
*/
|
|
25
|
+
UNDEFINED = 1,
|
|
26
|
+
/**
|
|
27
|
+
* All values that are null or undefined.
|
|
28
|
+
*/
|
|
29
|
+
NULL = 2,
|
|
30
|
+
/**
|
|
31
|
+
* All values that are falsy.
|
|
32
|
+
*/
|
|
33
|
+
FALSY = 3,
|
|
34
|
+
/**
|
|
35
|
+
* All values that are empty.
|
|
36
|
+
*/
|
|
37
|
+
EMPTY = 4,
|
|
38
|
+
/**
|
|
39
|
+
* All values that are empty. Objects that have no keys are considered empty too.
|
|
40
|
+
*/
|
|
41
|
+
EMPTY_STRICT = 5,
|
|
42
|
+
/**
|
|
43
|
+
* All values that are falsy or empty.
|
|
44
|
+
*/
|
|
45
|
+
FALSY_AND_EMPTY = 6,
|
|
46
|
+
/**
|
|
47
|
+
* All values that are falsy or empty or an empty objects.
|
|
48
|
+
*/
|
|
49
|
+
FALSY_AND_EMPTY_STRICT = 7
|
|
50
|
+
}
|
|
51
|
+
export interface KeyValueTupleFilter<T extends object = object, K extends keyof T = keyof T> {
|
|
52
|
+
valueFilter?: KeyValueTypleValueFilter;
|
|
53
|
+
invertFilter?: boolean;
|
|
54
|
+
keysFilter?: K[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts an input FilterKeyValueTuplesInput to a KeyValueTupleFilter.
|
|
58
|
+
*
|
|
59
|
+
* @param input
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare function filterKeyValueTuplesInputToFilter<T extends object = object, K extends keyof T = keyof T>(input: FilterKeyValueTuplesInput<T, K>): KeyValueTupleFilter<T, K>;
|
|
63
|
+
export declare type FilterKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T> = FilterFunction<KeyValueTuple<T, K>>;
|
|
64
|
+
export declare function filterKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T>(inputFilter: FilterKeyValueTuplesInput<T, K>): FilterKeyValueTupleFunction<T, K>;
|