inferred-types 0.37.0 → 0.37.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/dist/index.d.ts +2745 -0
- package/dist/index.js +854 -0
- package/package.json +6 -12
- package/.eslintrc +0 -77
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/other.yml +0 -15
- package/.nvmrc +0 -1
- package/.prettierrc.js +0 -3
- package/.vscode/launch.json +0 -27
- package/.vscode/settings.json +0 -19
- package/devops/build.js +0 -243
- package/docs/builder-overview.md +0 -45
- package/docs/builder.md +0 -94
- package/src/errors/ReadOnlyViolation.ts +0 -3
- package/src/errors/index.ts +0 -12
- package/src/index.ts +0 -14
- package/src/runtime/README.md +0 -3
- package/src/runtime/api/api.ts +0 -10
- package/src/runtime/api/index.ts +0 -12
- package/src/runtime/builders/Model.ts +0 -25
- package/src/runtime/builders/url.ts +0 -15
- package/src/runtime/combinators/and.ts +0 -15
- package/src/runtime/combinators/filter.ts +0 -267
- package/src/runtime/combinators/index.ts +0 -4
- package/src/runtime/combinators/not.ts +0 -15
- package/src/runtime/combinators/or.ts +0 -5
- package/src/runtime/createFnWithProps.ts +0 -37
- package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
- package/src/runtime/dictionary/defineProperties.ts +0 -35
- package/src/runtime/dictionary/dictArr.ts +0 -69
- package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
- package/src/runtime/dictionary/entries.ts +0 -33
- package/src/runtime/dictionary/index.ts +0 -21
- package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
- package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
- package/src/runtime/dictionary/kv/index.ts +0 -15
- package/src/runtime/dictionary/kv/kv.ts +0 -18
- package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
- package/src/runtime/dictionary/mapTo.ts +0 -206
- package/src/runtime/dictionary/mapValues.ts +0 -23
- package/src/runtime/dictionary/merge.ts +0 -36
- package/src/runtime/dictionary/strArrayToDict.ts +0 -12
- package/src/runtime/index.ts +0 -23
- package/src/runtime/keys.ts +0 -16
- package/src/runtime/lists/asArray.ts +0 -38
- package/src/runtime/lists/createConverter.ts +0 -62
- package/src/runtime/lists/groupBy.ts +0 -15
- package/src/runtime/lists/index.ts +0 -15
- package/src/runtime/literals/ExplicitFunction.ts +0 -10
- package/src/runtime/literals/Suggest.ts +0 -19
- package/src/runtime/literals/arrayToObject.ts +0 -78
- package/src/runtime/literals/box.ts +0 -98
- package/src/runtime/literals/defineType.ts +0 -20
- package/src/runtime/literals/ensureLeading.ts +0 -17
- package/src/runtime/literals/ensureTrailing.ts +0 -17
- package/src/runtime/literals/identity.ts +0 -12
- package/src/runtime/literals/index.ts +0 -23
- package/src/runtime/literals/literal.ts +0 -48
- package/src/runtime/literals/pathJoin.ts +0 -33
- package/src/runtime/literals/stripLeading.ts +0 -15
- package/src/runtime/literals/stripTrailing.ts +0 -15
- package/src/runtime/literals/wide.ts +0 -13
- package/src/runtime/ruleset.ts +0 -42
- package/src/runtime/runtime/README.md +0 -3
- package/src/runtime/runtime/condition.ts +0 -13
- package/src/runtime/runtime/index.ts +0 -16
- package/src/runtime/runtime/type.ts +0 -127
- package/src/runtime/runtime/withValue.ts +0 -39
- package/src/runtime/state/Configurator.ts +0 -76
- package/src/runtime/state/FluentConfigurator.ts +0 -49
- package/src/runtime/state/index.ts +0 -13
- package/src/runtime/type-checks/ifSameType.ts +0 -20
- package/src/runtime/type-checks/ifTypeOf.ts +0 -124
- package/src/runtime/type-checks/index.ts +0 -24
- package/src/runtime/type-checks/isArray.ts +0 -34
- package/src/runtime/type-checks/isBoolean.ts +0 -24
- package/src/runtime/type-checks/isFalse.ts +0 -29
- package/src/runtime/type-checks/isFunction.ts +0 -26
- package/src/runtime/type-checks/isNull.ts +0 -26
- package/src/runtime/type-checks/isNumber.ts +0 -20
- package/src/runtime/type-checks/isObject.ts +0 -22
- package/src/runtime/type-checks/isString.ts +0 -34
- package/src/runtime/type-checks/isSymbol.ts +0 -3
- package/src/runtime/type-checks/isTrue.ts +0 -31
- package/src/runtime/type-checks/isUndefined.ts +0 -33
- package/src/runtime/type-checks/startsWith.ts +0 -107
- package/src/runtime/valueTypes.ts +0 -48
- package/src/types/Api.ts +0 -16
- package/src/types/Constructor.ts +0 -5
- package/src/types/EnumValues.ts +0 -14
- package/src/types/ExpandRecursively.ts +0 -12
- package/src/types/FunctionType.ts +0 -19
- package/src/types/If.ts +0 -10
- package/src/types/Include.ts +0 -18
- package/src/types/KeyedRecord.ts +0 -21
- package/src/types/Keys.ts +0 -26
- package/src/types/Length.ts +0 -8
- package/src/types/Mutable.ts +0 -8
- package/src/types/Narrowable.ts +0 -5
- package/src/types/Not.ts +0 -13
- package/src/types/Numeric.ts +0 -20
- package/src/types/Opaque.ts +0 -11
- package/src/types/README.md +0 -3
- package/src/types/Retain.ts +0 -16
- package/src/types/SimplifyObject.ts +0 -12
- package/src/types/Transformer.ts +0 -15
- package/src/types/TypeGuard.ts +0 -7
- package/src/types/Where.ts +0 -40
- package/src/types/alphabetic/AllCaps.ts +0 -15
- package/src/types/alphabetic/CamelCase.ts +0 -3
- package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
- package/src/types/alphabetic/CapitalizeWords.ts +0 -9
- package/src/types/alphabetic/Cardinality.ts +0 -80
- package/src/types/alphabetic/DashToSnake.ts +0 -3
- package/src/types/alphabetic/DashUppercase.ts +0 -19
- package/src/types/alphabetic/Dasherize.ts +0 -23
- package/src/types/alphabetic/EnsureLeading.ts +0 -24
- package/src/types/alphabetic/EnsureTrailing.ts +0 -24
- package/src/types/alphabetic/HasUppercase.ts +0 -16
- package/src/types/alphabetic/IsCapitalized.ts +0 -18
- package/src/types/alphabetic/KebabCase.ts +0 -13
- package/src/types/alphabetic/LowerAllCaps.ts +0 -5
- package/src/types/alphabetic/PascalCase.ts +0 -29
- package/src/types/alphabetic/PathJoin.ts +0 -54
- package/src/types/alphabetic/Pluralize.ts +0 -112
- package/src/types/alphabetic/SnakeCase.ts +0 -27
- package/src/types/alphabetic/StripLeading.ts +0 -23
- package/src/types/alphabetic/StripTrailing.ts +0 -23
- package/src/types/alphabetic/Url.ts +0 -29
- package/src/types/alphabetic/alpha-characters.ts +0 -81
- package/src/types/alphabetic/index.ts +0 -32
- package/src/types/append-types.ts +0 -10
- package/src/types/boolean-logic/EndsWith.ts +0 -40
- package/src/types/boolean-logic/Extends.ts +0 -22
- package/src/types/boolean-logic/HasParameters.ts +0 -21
- package/src/types/boolean-logic/Includes.ts +0 -33
- package/src/types/boolean-logic/IsLiteral.ts +0 -101
- package/src/types/boolean-logic/IsScalar.ts +0 -20
- package/src/types/boolean-logic/IsUndefined.ts +0 -20
- package/src/types/boolean-logic/Or.ts +0 -12
- package/src/types/boolean-logic/StartsWith.ts +0 -42
- package/src/types/boolean-logic/TypeDefault.ts +0 -58
- package/src/types/boolean-logic/array.ts +0 -57
- package/src/types/boolean-logic/boolean.ts +0 -84
- package/src/types/boolean-logic/equivalency.ts +0 -15
- package/src/types/boolean-logic/index.ts +0 -14
- package/src/types/boolean-logic/object.ts +0 -30
- package/src/types/boolean-logic/string.ts +0 -21
- package/src/types/dictionary/DictChangeValue.ts +0 -34
- package/src/types/dictionary/DictPartialApplication.ts +0 -30
- package/src/types/dictionary/DictPrependWithFn.ts +0 -23
- package/src/types/dictionary/DictReturnValues.ts +0 -27
- package/src/types/dictionary/Get.ts +0 -14
- package/src/types/dictionary/MapTo.ts +0 -428
- package/src/types/dictionary/MutableProps.ts +0 -19
- package/src/types/dictionary/RequireProps.ts +0 -15
- package/src/types/dictionary/SameKeys.ts +0 -11
- package/src/types/dictionary/index.ts +0 -21
- package/src/types/dictionary/props.ts +0 -145
- package/src/types/fluent/fluent.ts +0 -61
- package/src/types/fluent/index.ts +0 -12
- package/src/types/functions/FinalReturn.ts +0 -12
- package/src/types/functions/LogicFunction.ts +0 -4
- package/src/types/functions/index.ts +0 -13
- package/src/types/index.ts +0 -49
- package/src/types/kv/DictFromKv.ts +0 -3
- package/src/types/kv/KeyValue.ts +0 -12
- package/src/types/kv/KvFrom.ts +0 -8
- package/src/types/kv/KvTuple.ts +0 -14
- package/src/types/kv/index.ts +0 -15
- package/src/types/lists/AfterFirst.ts +0 -10
- package/src/types/lists/ConvertAndMap.ts +0 -152
- package/src/types/lists/FilterTuple.ts +0 -20
- package/src/types/lists/First.ts +0 -8
- package/src/types/lists/FirstString.ts +0 -4
- package/src/types/lists/Split.ts +0 -21
- package/src/types/lists/UniqueForProp.ts +0 -18
- package/src/types/lists/index.ts +0 -18
- package/src/types/literal-unions/OptRequired.ts +0 -4
- package/src/types/literal-unions/index.ts +0 -1
- package/src/types/maybe.ts +0 -9
- package/src/types/ruleset-types.ts +0 -76
- package/src/types/runtime.ts +0 -39
- package/src/types/string-literals/Break.ts +0 -22
- package/src/types/string-literals/Concat.ts +0 -9
- package/src/types/string-literals/LeftWhitespace.ts +0 -13
- package/src/types/string-literals/Replace.ts +0 -17
- package/src/types/string-literals/RightWhitespace.ts +0 -13
- package/src/types/string-literals/StringLength.ts +0 -34
- package/src/types/string-literals/Trim.ts +0 -15
- package/src/types/string-literals/TrimLeft.ts +0 -14
- package/src/types/string-literals/TrimRight.ts +0 -14
- package/src/types/string-literals/form-fields.ts +0 -15
- package/src/types/string-literals/index.ts +0 -21
- package/src/types/tuples/DictArray.ts +0 -21
- package/src/types/tuples/FirstKey.ts +0 -10
- package/src/types/tuples/FirstKeyValue.ts +0 -9
- package/src/types/tuples/FirstOfEach.ts +0 -13
- package/src/types/tuples/FromDictArray.ts +0 -14
- package/src/types/tuples/SecondOfEach.ts +0 -13
- package/src/types/tuples/index.ts +0 -17
- package/src/types/type-conversion/TupleToUnion.ts +0 -9
- package/src/types/type-conversion/UnionToIntersection.ts +0 -9
- package/src/types/type-conversion/UnionToTuple.ts +0 -20
- package/src/types/type-conversion/Widen.ts +0 -22
- package/src/types/type-conversion/index.ts +0 -16
- package/src/types/type-testing.ts +0 -14
- package/tests/CamelCase-spec.ts +0 -20
- package/tests/Configurator-spec.hold +0 -106
- package/tests/ExplicitFunction-spec.ts +0 -50
- package/tests/IncludeAndRetain-spec.ts +0 -67
- package/tests/Includes-spec.ts +0 -36
- package/tests/KebabCase-spec.ts +0 -21
- package/tests/PascalCase-spec.ts +0 -22
- package/tests/Pluralize-spec.ts +0 -23
- package/tests/SnakeCase-spec.ts +0 -21
- package/tests/Where.spec.ts +0 -38
- package/tests/arrayToKeyLookup-spec.ts +0 -17
- package/tests/arrayToObject-spec.ts +0 -115
- package/tests/boolean-logic/Contains.test.ts +0 -55
- package/tests/boolean-logic/HasParameters.ts +0 -29
- package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
- package/tests/boolean-logic/boolean.spec.ts +0 -21
- package/tests/boolean-logic/filter.spec.ts +0 -52
- package/tests/constructor.spec.ts +0 -42
- package/tests/createFnWithProps.spec.ts +0 -14
- package/tests/data/SimpleTable.hold +0 -21
- package/tests/data/index.ts +0 -12
- package/tests/data/playlist.hold +0 -25
- package/tests/data/song.hold +0 -23
- package/tests/defineType-spec.ts +0 -57
- package/tests/dictionary/DictChangeValue.test.ts +0 -30
- package/tests/dictionary/DictPartialApplication.test.ts +0 -43
- package/tests/dictionary/DictReturnValues.test.ts +0 -36
- package/tests/dictionary/Get.spec.ts +0 -28
- package/tests/dictionary/IntersectingKeys.test.ts +0 -42
- package/tests/dictionary/MutableProps.test.ts +0 -30
- package/tests/dictionary/OptionalKeys.test.ts +0 -24
- package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
- package/tests/dictionary/RequireProps.test.ts +0 -21
- package/tests/dictionary/RequiredKeys.test.ts +0 -53
- package/tests/dictionary/TypeDefault.test.ts +0 -76
- package/tests/dictionary/mapTo.test.ts +0 -388
- package/tests/dictionary/merge.test.ts +0 -41
- package/tests/dictionaryTransform-spec.ts +0 -280
- package/tests/ifTypeOf-spec.ts +0 -191
- package/tests/kv/KeyValue-spec.ts +0 -22
- package/tests/kv/SameKeys-spec.ts +0 -35
- package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
- package/tests/kv/entries-spec.ts +0 -65
- package/tests/kv/keys.spec.ts +0 -66
- package/tests/kv/kv-spec.ts +0 -20
- package/tests/lists/First.test.ts +0 -43
- package/tests/lists/Length.test.ts +0 -19
- package/tests/lists/Split.test.ts +0 -29
- package/tests/lists/UniqueForProp.spec.ts +0 -59
- package/tests/lists/asArray.test.ts +0 -109
- package/tests/lists/dictArr.test.ts +0 -110
- package/tests/literal-spec.ts +0 -82
- package/tests/literals/AllCaps.spec.ts +0 -33
- package/tests/literals/CamelCase.spec.ts +0 -109
- package/tests/literals/Dasherize.spec.ts +0 -107
- package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
- package/tests/literals/HasUppercase.spec.ts +0 -33
- package/tests/literals/PascalCase.spec.ts +0 -109
- package/tests/literals/PathJoin.test.ts +0 -111
- package/tests/literals/SnakeCase.spec.ts +0 -109
- package/tests/literals/box.test.ts +0 -85
- package/tests/literals/whitespace-capture.spec.ts +0 -60
- package/tests/mapValues-spec.ts +0 -50
- package/tests/props-spec.ts +0 -234
- package/tests/runtime/condition.spec.ts +0 -19
- package/tests/runtime/if-is.spec.ts +0 -390
- package/tests/runtime/map-and-convert.test.ts +0 -31
- package/tests/runtime/type.spec.ts +0 -190
- package/tests/strArrayToDict-spec.ts +0 -40
- package/tests/tuples/TupleToUnion.spec.ts +0 -20
- package/tests/withValue.spec.ts +0 -173
- package/tsconfig.json +0 -36
- package/vitest.config.ts +0 -17
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ExpandRecursively } from "src/types/ExpandRecursively";
|
|
2
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Build a key-value pair where both _key_ and _value_ are inferred. This
|
|
6
|
-
* includes ensuring that the _key_ is a type literal not just a "string".
|
|
7
|
-
*
|
|
8
|
-
* > note: the value will be inferred but if you need to constrain it
|
|
9
|
-
* > to a narrower type then both inferences will break and you should
|
|
10
|
-
* > instead use `KV2` to get this capability.
|
|
11
|
-
*/
|
|
12
|
-
export function kv<
|
|
13
|
-
K extends string,
|
|
14
|
-
N extends Narrowable,
|
|
15
|
-
V extends Record<any, N> | boolean | number | string | null | undefined
|
|
16
|
-
>(key: K, value: V) {
|
|
17
|
-
return { [key]: value } as ExpandRecursively<Record<K, V>>;
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { DictFromKv } from "src/types/kv";
|
|
2
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Converts an array of dictionaries with `key` and `value` properties to a singular dictionary.
|
|
6
|
-
* ```ts
|
|
7
|
-
* // { id: 123, foo: "bar" }
|
|
8
|
-
* const arr = kvToDict([{ key: "id", value: 123 }, { key: "foo", value: "bar" }]);
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* Note: this is the inverse of `dictToKv()` function
|
|
12
|
-
*/
|
|
13
|
-
export function kvToDict<
|
|
14
|
-
K extends string,
|
|
15
|
-
V extends Narrowable,
|
|
16
|
-
T extends readonly Readonly<{ key: K; value: V }>[]
|
|
17
|
-
>(kvArr: T): DictFromKv<T> {
|
|
18
|
-
const out = {} as any;
|
|
19
|
-
for (const kv of kvArr) {
|
|
20
|
-
out[kv.key as keyof DictFromKv<T>] = kv.value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return out as DictFromKv<T>;
|
|
24
|
-
}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FinalizedMapConfig,
|
|
3
|
-
MapCardinalityIllustrated,
|
|
4
|
-
MapperApi,
|
|
5
|
-
MapTo,
|
|
6
|
-
AsFinalizedConfig,
|
|
7
|
-
MapConfig,
|
|
8
|
-
ConfiguredMap,
|
|
9
|
-
Mapper,
|
|
10
|
-
MapFn,
|
|
11
|
-
} from "src/types/dictionary";
|
|
12
|
-
import { OptRequired } from "src/types/literal-unions";
|
|
13
|
-
import { createFnWithProps } from "../createFnWithProps";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* utility function to take a fully-qualified _user_ config
|
|
17
|
-
* and make it into a FinalizedMapConfig
|
|
18
|
-
*/
|
|
19
|
-
const toFinalizedConfig = <
|
|
20
|
-
IR extends OptRequired,
|
|
21
|
-
D extends MapCardinalityIllustrated,
|
|
22
|
-
OR extends OptRequired
|
|
23
|
-
>(
|
|
24
|
-
config: MapConfig<IR, D, OR>
|
|
25
|
-
) => {
|
|
26
|
-
return { ...config, finalized: true } as FinalizedMapConfig<IR, D, OR>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const DEFAULT_ONE_TO_MANY_MAPPING = toFinalizedConfig({
|
|
30
|
-
input: "req",
|
|
31
|
-
output: "opt",
|
|
32
|
-
cardinality: "I -> O[]",
|
|
33
|
-
});
|
|
34
|
-
export const DEFAULT_ONE_TO_ONE_MAPPING = toFinalizedConfig({
|
|
35
|
-
input: "req",
|
|
36
|
-
output: "req",
|
|
37
|
-
cardinality: "I -> O",
|
|
38
|
-
});
|
|
39
|
-
export const DEFAULT_MANY_TO_ONE_MAPPING = toFinalizedConfig({
|
|
40
|
-
input: "req",
|
|
41
|
-
output: "req",
|
|
42
|
-
cardinality: "I[] -> O",
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
export type DefaultOneToManyMapping = typeof DEFAULT_ONE_TO_MANY_MAPPING;
|
|
46
|
-
export type DefaultOneToOneMapping = typeof DEFAULT_ONE_TO_ONE_MAPPING;
|
|
47
|
-
export type DefaultManyToOneMapping = typeof DEFAULT_MANY_TO_ONE_MAPPING;
|
|
48
|
-
|
|
49
|
-
const debugMsg = <C extends FinalizedMapConfig<any, any, any>>(
|
|
50
|
-
config: C,
|
|
51
|
-
source: any,
|
|
52
|
-
output: any
|
|
53
|
-
) => {
|
|
54
|
-
if (config.debug) {
|
|
55
|
-
console.error(
|
|
56
|
-
`MapFn[${typeof config.output === "string" ? `${config.output}, ` : ""}${config.input}, ${
|
|
57
|
-
config.cardinality
|
|
58
|
-
}, ${config.output}] received:\n\n${JSON.stringify(source)}\n\nAnd produced: ${JSON.stringify(
|
|
59
|
-
output
|
|
60
|
-
)}\n\n`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The single implementation for all mapping
|
|
67
|
-
*/
|
|
68
|
-
const mapper =
|
|
69
|
-
<
|
|
70
|
-
//
|
|
71
|
-
C extends FinalizedMapConfig<
|
|
72
|
-
OptRequired, //
|
|
73
|
-
MapCardinalityIllustrated,
|
|
74
|
-
OptRequired
|
|
75
|
-
>
|
|
76
|
-
>(
|
|
77
|
-
config: C
|
|
78
|
-
) =>
|
|
79
|
-
<I, O>(map: MapTo<I, O, C>): Mapper<I, O, C> => {
|
|
80
|
-
const fn: MapFn<I, O, C> = <S>(source: S) => {
|
|
81
|
-
/**
|
|
82
|
-
* Determine whether input is an array; this will be true
|
|
83
|
-
*/
|
|
84
|
-
const isArray =
|
|
85
|
-
config.cardinality === "I -> O[]" && Array.isArray(source)
|
|
86
|
-
? true
|
|
87
|
-
: config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0])
|
|
88
|
-
? true
|
|
89
|
-
: false;
|
|
90
|
-
|
|
91
|
-
if (isArray) {
|
|
92
|
-
// iterate over inputs with flatMap to return mapped values as
|
|
93
|
-
// well as supporting filtering functionality. We could achieve
|
|
94
|
-
// the same results by simply passing in all inputs to our mapper
|
|
95
|
-
// in most cardinalities but when cardinality is M:1 we need to
|
|
96
|
-
// make sure that the first array of elements is passed as a single
|
|
97
|
-
// item and this approach achieves this.
|
|
98
|
-
// TODO: we should check that the approach below doesn't work for M:1 here
|
|
99
|
-
// as well
|
|
100
|
-
const output = (source as any).flatMap(map);
|
|
101
|
-
debugMsg(config, source, output);
|
|
102
|
-
|
|
103
|
-
return output;
|
|
104
|
-
} else {
|
|
105
|
-
// receive _all_ inputs provided as pass into ; this is just a single input unless the
|
|
106
|
-
// cardinality is
|
|
107
|
-
const output = map(source as any);
|
|
108
|
-
debugMsg(config, source, output);
|
|
109
|
-
|
|
110
|
-
return output;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return createFnWithProps(fn, {
|
|
115
|
-
input: config.input,
|
|
116
|
-
output: config.output,
|
|
117
|
-
cardinality: config.cardinality,
|
|
118
|
-
debug: config.debug,
|
|
119
|
-
inputType: {} as I,
|
|
120
|
-
outputType: {} as O,
|
|
121
|
-
fnSignature: null as unknown as MapFn<I, O, C>,
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Takes a userland configuration and a default configuration and then produces
|
|
127
|
-
* the appropriately typed `ConfiguredMap` API surface.
|
|
128
|
-
*/
|
|
129
|
-
const setMapper = <
|
|
130
|
-
U extends MapConfig<
|
|
131
|
-
OptRequired | undefined,
|
|
132
|
-
MapCardinalityIllustrated | undefined,
|
|
133
|
-
OptRequired | undefined
|
|
134
|
-
>,
|
|
135
|
-
D extends FinalizedMapConfig<OptRequired, MapCardinalityIllustrated, OptRequired>
|
|
136
|
-
>(
|
|
137
|
-
config: U = { input: undefined, output: undefined, cardinality: undefined } as U,
|
|
138
|
-
defaultValue: D
|
|
139
|
-
): ConfiguredMap<AsFinalizedConfig<U, D>> => ({
|
|
140
|
-
map: (source) => {
|
|
141
|
-
// merge userland config with defaults for a cardinality
|
|
142
|
-
const c = {
|
|
143
|
-
...defaultValue,
|
|
144
|
-
...config,
|
|
145
|
-
} as unknown as AsFinalizedConfig<U, D>;
|
|
146
|
-
return mapper(c)(source);
|
|
147
|
-
},
|
|
148
|
-
input: config?.input || defaultValue.input,
|
|
149
|
-
output: config?.output || defaultValue.output,
|
|
150
|
-
cardinality: config?.cardinality || defaultValue.cardinality,
|
|
151
|
-
debug: config?.debug || false,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* **mapTo** _utility_
|
|
156
|
-
*
|
|
157
|
-
* This utility -- by default -- creates a strongly typed 1:M data mapper which maps from one
|
|
158
|
-
* known source `I` to any array of another `O[]`:
|
|
159
|
-
* ```ts
|
|
160
|
-
* const mapper = mapTo<I, O>(i => [{
|
|
161
|
-
* foo: i.bar
|
|
162
|
-
* }]);
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export const mapToFn: ConfiguredMap<DefaultOneToManyMapping>["map"] = (map) => {
|
|
166
|
-
return mapper(DEFAULT_ONE_TO_MANY_MAPPING)(map);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Provides a `config` method which allows the relationships between _inputs_
|
|
171
|
-
* and _outputs_ to be configured.
|
|
172
|
-
*/
|
|
173
|
-
export const mapToDict: MapperApi = {
|
|
174
|
-
config(config) {
|
|
175
|
-
const c = { ...DEFAULT_ONE_TO_MANY_MAPPING, ...config };
|
|
176
|
-
return setMapper(c, DEFAULT_ONE_TO_MANY_MAPPING);
|
|
177
|
-
},
|
|
178
|
-
oneToOne(config) {
|
|
179
|
-
const c = { ...DEFAULT_ONE_TO_ONE_MAPPING, ...config };
|
|
180
|
-
return setMapper(c, DEFAULT_ONE_TO_ONE_MAPPING);
|
|
181
|
-
},
|
|
182
|
-
manyToOne(config) {
|
|
183
|
-
const c = { ...DEFAULT_MANY_TO_ONE_MAPPING, ...config };
|
|
184
|
-
return setMapper(c, DEFAULT_MANY_TO_ONE_MAPPING);
|
|
185
|
-
},
|
|
186
|
-
oneToMany(config) {
|
|
187
|
-
const c = { ...DEFAULT_ONE_TO_MANY_MAPPING, ...config };
|
|
188
|
-
return setMapper(c, DEFAULT_ONE_TO_MANY_MAPPING);
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* **mapTo** _utility_
|
|
194
|
-
*
|
|
195
|
-
* This utility creates a strongly typed data mapper which maps from one
|
|
196
|
-
* known source `I` to another `O`.
|
|
197
|
-
*
|
|
198
|
-
* Signatures:
|
|
199
|
-
* ```ts
|
|
200
|
-
* const defMap = mapTo<I,O>( ... );
|
|
201
|
-
* const configured = mapTo.config({ output: "req" }).map<I,O>( ... );
|
|
202
|
-
* const one2one = mapTo.oneToOne().map<I,O>( ... );
|
|
203
|
-
* const many2one = mapTo.manyToOne().map<I,O>( ... );
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
export const mapTo = createFnWithProps(mapToFn, mapToDict);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
2
|
-
import { entries } from "./entries";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* **mapValues**
|
|
6
|
-
*
|
|
7
|
-
* Maps over a dictionary, preserving the keys but allowing the values to be mutated.
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* const colors = { red: 4, blue: 2, green: 3 };
|
|
11
|
-
* // { red: 8, blue: 4, green: 6 }
|
|
12
|
-
* const twoX = mapValues(colors, v => v * 2);
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function mapValues<N extends Narrowable, T extends Record<string, N>, V>(
|
|
16
|
-
obj: T,
|
|
17
|
-
valueMapper: (k: T[keyof T]) => V
|
|
18
|
-
) {
|
|
19
|
-
return Object.fromEntries(
|
|
20
|
-
// TODO: fix the type error with v and valueMapper
|
|
21
|
-
[...entries(obj)].map(([k, v]) => [k, valueMapper(v as any)])
|
|
22
|
-
) as { [K in keyof T]: V };
|
|
23
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Mutable, Narrowable, SimplifyObject, TypeDefault } from "src/types";
|
|
2
|
-
import { keys } from "../keys";
|
|
3
|
-
import { isObject } from "../runtime";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* **merge**(val, defaultVal)
|
|
7
|
-
*
|
|
8
|
-
* Merges two values together where the second property is considered the
|
|
9
|
-
* the "default value". This means that in any cases where the primary value
|
|
10
|
-
* os _undefined_ it will be replaced by the default value. The merging will
|
|
11
|
-
* also recurse into object types to do matching at a property-by-property
|
|
12
|
-
* level.
|
|
13
|
-
*
|
|
14
|
-
* As much as is possible, this utility will maintain strong and narrow types
|
|
15
|
-
* across the merge process.
|
|
16
|
-
*/
|
|
17
|
-
export const merge = <T extends Narrowable, D extends Narrowable>(
|
|
18
|
-
val: T,
|
|
19
|
-
defVal: D
|
|
20
|
-
): SimplifyObject<Mutable<TypeDefault<T, D>>> => {
|
|
21
|
-
const result =
|
|
22
|
-
val === undefined
|
|
23
|
-
? // value is undefined; use default value
|
|
24
|
-
defVal
|
|
25
|
-
: isObject(defVal) && isObject(val)
|
|
26
|
-
? // value and and default value are objects; recurse via default values
|
|
27
|
-
keys(defVal as Record<string, any>).reduce((acc, key) => {
|
|
28
|
-
const v = (val as Record<string, any>)[key];
|
|
29
|
-
const dv = (defVal as Record<string, any>)[key];
|
|
30
|
-
|
|
31
|
-
return { ...acc, [key]: merge(v, dv) };
|
|
32
|
-
}, {} as Record<string, any>)
|
|
33
|
-
: val;
|
|
34
|
-
|
|
35
|
-
return result as SimplifyObject<Mutable<TypeDefault<T, D>>>;
|
|
36
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ExpandRecursively } from "src/types/ExpandRecursively";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* converts an array of strings `["a", "b", "c"]` into a more type friendly
|
|
5
|
-
* dictionary of the type `{ a: true, b: true, c: true }`
|
|
6
|
-
*/
|
|
7
|
-
export function strArrayToDict<T extends readonly string[]>(...strings: T) {
|
|
8
|
-
return strings.reduce((acc, str) => {
|
|
9
|
-
acc = { ...acc, [str]: true };
|
|
10
|
-
return acc;
|
|
11
|
-
}, {} as ExpandRecursively<Record<typeof strings[number], true>>);
|
|
12
|
-
}
|
package/src/runtime/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
|
|
3
|
-
// #region auto-indexed files
|
|
4
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
-
// hash-code: 9dd9ac96
|
|
6
|
-
|
|
7
|
-
// file exports
|
|
8
|
-
export * from "./createFnWithProps";
|
|
9
|
-
export * from "./keys";
|
|
10
|
-
export * from "./ruleset";
|
|
11
|
-
// directory exports
|
|
12
|
-
export * from "./api/index";
|
|
13
|
-
export * from "./combinators/index";
|
|
14
|
-
export * from "./dictionary/index";
|
|
15
|
-
export * from "./lists/index";
|
|
16
|
-
export * from "./literals/index";
|
|
17
|
-
export * from "./runtime/index";
|
|
18
|
-
export * from "./state/index";
|
|
19
|
-
|
|
20
|
-
// #endregion auto-indexed files
|
|
21
|
-
|
|
22
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
23
|
-
// for more info
|
package/src/runtime/keys.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Keys } from "src/types/Keys";
|
|
2
|
-
import { Length } from "src/types/Length";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Provides the _keys_ of an object with the `keyof T` made explicit.
|
|
6
|
-
*/
|
|
7
|
-
export function keys<T extends {}, W extends readonly string[]>(obj: T, ...without: W) {
|
|
8
|
-
const v =
|
|
9
|
-
without.length > 0
|
|
10
|
-
? (Object.keys(obj).filter((k) => !without.includes(k)) as unknown as Array<
|
|
11
|
-
Exclude<keyof T, Keys<W>>
|
|
12
|
-
>)
|
|
13
|
-
: (Object.keys(obj) as unknown as Array<keyof T>);
|
|
14
|
-
|
|
15
|
-
return v as unknown as Length<W> extends 0 ? Array<keyof T> : Array<Exclude<keyof T, Keys<W>>>;
|
|
16
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Narrowable, Widen } from "src/types";
|
|
2
|
-
import { isArray } from "../runtime";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Type utility which converts `undefined[]` to `unknown[]`
|
|
6
|
-
*/
|
|
7
|
-
export type UndefinedArrayIsUnknown<T extends any[]> = undefined[] extends T ? unknown[] : T;
|
|
8
|
-
|
|
9
|
-
export type AsArray<T, W extends boolean = false> = T extends any[]
|
|
10
|
-
? W extends true
|
|
11
|
-
? Widen<T>
|
|
12
|
-
: T
|
|
13
|
-
: W extends true
|
|
14
|
-
? UndefinedArrayIsUnknown<Widen<T>[]>
|
|
15
|
-
: UndefinedArrayIsUnknown<T[]>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Ensures that any input passed in is passed back as an array:
|
|
19
|
-
*
|
|
20
|
-
* - if it was already an array than this just serves as an _identity_ function
|
|
21
|
-
* - if it was not then it wraps the element into a one element array of the
|
|
22
|
-
* given type
|
|
23
|
-
*
|
|
24
|
-
* Note: by default the _type_ of values will be intentionally widened so that the value "abc"
|
|
25
|
-
* is of type `string` not the literal `abc`. If you want to keep literal types then
|
|
26
|
-
* change the optional _widen_ parameter to _false_.
|
|
27
|
-
*/
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
-
export const asArray = <T extends Narrowable, W extends boolean = true>(thing: T, _widen?: W) => {
|
|
30
|
-
return (
|
|
31
|
-
isArray(thing)
|
|
32
|
-
? // proxy thing back as it's already an array
|
|
33
|
-
thing
|
|
34
|
-
: typeof thing === "undefined"
|
|
35
|
-
? ([] as T[])
|
|
36
|
-
: [thing]
|
|
37
|
-
) as AsArray<T, W>;
|
|
38
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "src/types";
|
|
2
|
-
import { ConverterShape, AvailableConverters } from "src/types/lists/ConvertAndMap";
|
|
3
|
-
import { boxDictionaryValues } from "../literals/box";
|
|
4
|
-
import { wide } from "../literals/wide";
|
|
5
|
-
import { ifSameType } from "../type-checks";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* **createConverter**(mapper)
|
|
9
|
-
*
|
|
10
|
-
* A runtime utility which allows for the creation of a function which
|
|
11
|
-
* receives multiple wide types (string, number, boolean, object) and then transform it
|
|
12
|
-
* based on the "wide type" but while retaining the potentially narrow values passed in.
|
|
13
|
-
*
|
|
14
|
-
* The number of wide types which the converter will accept is based on how it configured
|
|
15
|
-
* as there are discrete functions which must be passed in for handling: strings, numbers,
|
|
16
|
-
* booleans, and "objects" (aka, Record<string,any>).
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* // handles strings and numbers
|
|
20
|
-
* const convert = createConverter({
|
|
21
|
-
* string: s => `the string was ${s}`,
|
|
22
|
-
* number: n => `the number was ${n}`,
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export function createConverter<
|
|
27
|
-
S extends Narrowable = undefined,
|
|
28
|
-
N extends Narrowable = undefined,
|
|
29
|
-
B extends Narrowable = undefined,
|
|
30
|
-
O extends Narrowable = undefined
|
|
31
|
-
>(mapper: Partial<ConverterShape<S, N, B, O>>) {
|
|
32
|
-
type Mapper = Required<typeof mapper>;
|
|
33
|
-
const converter = boxDictionaryValues(mapper as Mapper);
|
|
34
|
-
|
|
35
|
-
return <T extends AvailableConverters<S, N, B, O>>(input: T) => {
|
|
36
|
-
const v = ifSameType(
|
|
37
|
-
input,
|
|
38
|
-
wide.string,
|
|
39
|
-
<T extends string>(i: T) => converter.string.unbox(i),
|
|
40
|
-
(i) =>
|
|
41
|
-
ifSameType(
|
|
42
|
-
i,
|
|
43
|
-
wide.number,
|
|
44
|
-
(i) => converter.number.unbox(i),
|
|
45
|
-
(i) =>
|
|
46
|
-
ifSameType(
|
|
47
|
-
i,
|
|
48
|
-
wide.boolean,
|
|
49
|
-
(i) => converter.boolean.unbox(i),
|
|
50
|
-
(i) =>
|
|
51
|
-
ifSameType(
|
|
52
|
-
i,
|
|
53
|
-
{} as Record<string, any>,
|
|
54
|
-
(i) => converter.object.unbox(i),
|
|
55
|
-
(i) => i as unknown
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
return v;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Groups an array of data based on the value of a property
|
|
5
|
-
* in the objects within the array.
|
|
6
|
-
* ```ts
|
|
7
|
-
* const data = [ {}, {}, {} ];
|
|
8
|
-
*
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* @ignore not implemented
|
|
12
|
-
*/
|
|
13
|
-
export function groupBy<T extends Record<string, Narrowable>>(_data: Readonly<T[]>) {
|
|
14
|
-
throw new Error("not implemented");
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
|
|
3
|
-
// #region auto-indexed files
|
|
4
|
-
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
-
// hash-code: bf4a6791
|
|
6
|
-
|
|
7
|
-
// file exports
|
|
8
|
-
export * from "./asArray";
|
|
9
|
-
export * from "./groupBy";
|
|
10
|
-
export * from "./createConverter";
|
|
11
|
-
|
|
12
|
-
// #endregion auto-indexed files
|
|
13
|
-
|
|
14
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
15
|
-
// for more info
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
export type ExplicitFunction<P extends any[], R extends any> = (...args: P) => R;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Takes a given function and converts it to an explicit representation
|
|
6
|
-
* where the generics represent the _parameter_ and _return_ typings.
|
|
7
|
-
*/
|
|
8
|
-
export function ExplicitFunction<T extends (...args: any[]) => any>(fn: T) {
|
|
9
|
-
return fn as ExplicitFunction<Parameters<T>, ReturnType<T>>;
|
|
10
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* **Suggest**
|
|
3
|
-
*
|
|
4
|
-
* Type utility that helps to build a enumerated set
|
|
5
|
-
* of string literals which _could_ be the value for
|
|
6
|
-
* a string based property but _allows_ a string that
|
|
7
|
-
* is not part of the suggestion to be typed in too.
|
|
8
|
-
*/
|
|
9
|
-
export type Suggest<T extends string> = T | (string & {});
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* **SuggestNumeric**`<T>`
|
|
13
|
-
*
|
|
14
|
-
* Type utility that helps to build a enumerated set
|
|
15
|
-
* of numeric literals which _could_ be the value for
|
|
16
|
-
* a number based property but _allows_ a number that
|
|
17
|
-
* is not part of the suggestion to be typed in too.
|
|
18
|
-
*/
|
|
19
|
-
export type SuggestNumeric<T extends number> = T | (number & {});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Narrowable } from "src/types/Narrowable";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* **UniqueDictionary**
|
|
5
|
-
*
|
|
6
|
-
* A dictionary converted by `arrayToObject()` which expects each key `S` to have a only a
|
|
7
|
-
* single/unique value.
|
|
8
|
-
*/
|
|
9
|
-
export type UniqueDictionary<
|
|
10
|
-
S extends PropertyKey,
|
|
11
|
-
N extends Narrowable,
|
|
12
|
-
T extends Record<keyof T, N> & Record<S, any>
|
|
13
|
-
> = { [V in T as V[S]]: V };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* **GeneralDictionary**
|
|
17
|
-
*
|
|
18
|
-
* A dictionary converted by `arrayToObject()` which expects each key `S` to have an
|
|
19
|
-
* array of values.
|
|
20
|
-
*/
|
|
21
|
-
export type GeneralDictionary<
|
|
22
|
-
S extends PropertyKey,
|
|
23
|
-
N extends Narrowable,
|
|
24
|
-
T extends Record<keyof T, N> & Record<S, any>
|
|
25
|
-
> = { [V in T as V[S]]: V[] };
|
|
26
|
-
|
|
27
|
-
export type ArrayConverter<S extends PropertyKey, U extends boolean> =
|
|
28
|
-
/**
|
|
29
|
-
* An `ArrayConverter` is the partial application of the `arrayToObject()`
|
|
30
|
-
* utility. At this point, the configuration is setup already and all that's
|
|
31
|
-
* left is to pass in an array of objects.
|
|
32
|
-
*/
|
|
33
|
-
<N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>>(
|
|
34
|
-
arr: readonly T[]
|
|
35
|
-
) => true extends U ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Converts an array of objects into a dictionary by picking a property name contained
|
|
39
|
-
* by all objects and using that as the key to the dictionary.
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* const arr = [
|
|
43
|
-
* { kind: "color", favorite: "blue", likes: 100 },
|
|
44
|
-
* { kind: "song", favorite: "some song", likes: 25 }
|
|
45
|
-
* ];
|
|
46
|
-
* const dict = arrayToObject("kind")(arr);
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* This will produce a dictionary with keys of `color` and `song`.
|
|
50
|
-
*/
|
|
51
|
-
export function arrayToObject<S extends PropertyKey, U extends boolean>(prop: S, unique?: U) {
|
|
52
|
-
type X = true extends U ? true : false;
|
|
53
|
-
/**
|
|
54
|
-
* **arrayToObject** - partially applied
|
|
55
|
-
*
|
|
56
|
-
* pass in an array of objects to complete application of arrayToObject()
|
|
57
|
-
*/
|
|
58
|
-
const transform: ArrayConverter<S, X> = <
|
|
59
|
-
N extends Narrowable,
|
|
60
|
-
T extends Record<keyof T, N> & Record<S, any>
|
|
61
|
-
>(
|
|
62
|
-
arr: readonly T[]
|
|
63
|
-
): true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T> => {
|
|
64
|
-
const result =
|
|
65
|
-
unique !== false
|
|
66
|
-
? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {} as UniqueDictionary<S, N, T>)
|
|
67
|
-
: arr.reduce((acc, v) => {
|
|
68
|
-
const existing = acc[v[prop] as T[S]] || [];
|
|
69
|
-
return { ...acc, [v[prop]]: [...existing, v] };
|
|
70
|
-
}, {} as GeneralDictionary<S, N, T>);
|
|
71
|
-
|
|
72
|
-
// type cast based on `U`
|
|
73
|
-
return result as true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
return transform;
|
|
77
|
-
// return converter(prop, unique);
|
|
78
|
-
}
|