inferred-types 0.15.0 → 0.18.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/.tsbuildinfo +1 -0
- package/devops/build.js +1 -3
- package/dist/{types/utility/state/KeyStorage.d.ts → index.d.ts} +9767 -8195
- package/dist/index.js +659 -0
- package/dist/index.mjs +577 -0
- package/on-hold/tests/api-spec.ts +9 -15
- package/package.json +27 -37
- package/pnpm-lock.yaml +2385 -2117
- package/src/errors/InferenceError.ts +1 -1
- package/src/shared/randomString.ts +1 -1
- package/src/types/Constructor.ts +5 -0
- package/src/types/Not.ts +3 -1
- package/src/types/Transformer.ts +1 -2
- package/src/types/Where.ts +36 -0
- package/src/types/alphabetic/PascalCase.ts +5 -4
- package/src/types/alphabetic/index.ts +9 -5
- package/src/types/{fluent.ts → fluent/fluent.ts} +8 -9
- package/src/types/fluent/index.ts +42 -0
- package/src/types/index.ts +13 -7
- package/src/types/lists/UniqueForProp.ts +13 -3
- package/src/types/ruleset-types.ts +1 -1
- package/src/types/{SameKeys.ts → type-conversion/SameKeys.ts} +0 -0
- package/src/types/type-conversion/WrapValue.ts +15 -0
- package/src/types/type-conversion/index.ts +11 -4
- package/src/utility/dictionary/arrayToKeyLookup.ts +3 -4
- package/src/utility/dictionary/dictionaryTransform.ts +6 -7
- package/src/utility/index.ts +3 -2
- package/src/utility/lists/groupBy.ts +22 -0
- package/src/utility/lists/index.ts +38 -0
- package/tests/Where.spec.ts +39 -0
- package/tests/constructor.spec.ts +40 -0
- package/tests/data/index.ts +8 -3
- package/tests/kv/dict-to-kv-and-back.spec.ts +2 -6
- package/tsconfig.json +4 -3
- package/dist/cjs/index.js +0 -21
- package/dist/es/index.js +0 -17
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/Mutation/MutationFunction.d.ts +0 -16
- package/dist/types/Mutation/MutationIdentity.d.ts +0 -30
- package/dist/types/Mutation/index.d.ts +0 -2
- package/dist/types/errors/InferenceError.d.ts +0 -1
- package/dist/types/errors/index.d.ts +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/shared/index.d.ts +0 -3
- package/dist/types/shared/randomString.d.ts +0 -1
- package/dist/types/shared/uuid.d.ts +0 -1
- package/dist/types/shared/valueTypes.d.ts +0 -27
- package/dist/types/types/Api.d.ts +0 -10
- package/dist/types/types/EnumValues.d.ts +0 -14
- package/dist/types/types/ExpandRecursively.d.ts +0 -3
- package/dist/types/types/First.d.ts +0 -4
- package/dist/types/types/FunctionType.d.ts +0 -9
- package/dist/types/types/If.d.ts +0 -10
- package/dist/types/types/Include.d.ts +0 -16
- package/dist/types/types/Includes.d.ts +0 -5
- package/dist/types/types/KeyedRecord.d.ts +0 -22
- package/dist/types/types/Keys.d.ts +0 -17
- package/dist/types/types/Length.d.ts +0 -8
- package/dist/types/types/Mutable.d.ts +0 -6
- package/dist/types/types/Narrowable.d.ts +0 -5
- package/dist/types/types/Not.d.ts +0 -11
- package/dist/types/types/Numeric.d.ts +0 -14
- package/dist/types/types/Opaque.d.ts +0 -12
- package/dist/types/types/Retain.d.ts +0 -16
- package/dist/types/types/SameKeys.d.ts +0 -11
- package/dist/types/types/Transformer.d.ts +0 -11
- package/dist/types/types/TypeGuard.d.ts +0 -7
- package/dist/types/types/alphabetic/AllCaps.d.ts +0 -12
- package/dist/types/types/alphabetic/CamelCase.d.ts +0 -2
- package/dist/types/types/alphabetic/CapFirstAlpha.d.ts +0 -13
- package/dist/types/types/alphabetic/CapitalizeWords.d.ts +0 -4
- package/dist/types/types/alphabetic/DashToSnake.d.ts +0 -1
- package/dist/types/types/alphabetic/DashUppercase.d.ts +0 -14
- package/dist/types/types/alphabetic/Dasherize.d.ts +0 -15
- package/dist/types/types/alphabetic/HasUppercase.d.ts +0 -13
- package/dist/types/types/alphabetic/Intrinsic.d.ts +0 -4
- package/dist/types/types/alphabetic/IsCapitalized.d.ts +0 -15
- package/dist/types/types/alphabetic/KebabCase.d.ts +0 -12
- package/dist/types/types/alphabetic/LowerAllCaps.d.ts +0 -4
- package/dist/types/types/alphabetic/PascalCase.d.ts +0 -16
- package/dist/types/types/alphabetic/Pluralize.d.ts +0 -36
- package/dist/types/types/alphabetic/SnakeCase.d.ts +0 -14
- package/dist/types/types/alphabetic/alpha-characters.d.ts +0 -36
- package/dist/types/types/alphabetic/index.d.ts +0 -16
- package/dist/types/types/append-types.d.ts +0 -9
- package/dist/types/types/dictionary/Get.d.ts +0 -7
- package/dist/types/types/dictionary/index.d.ts +0 -1
- package/dist/types/types/fluent.d.ts +0 -51
- package/dist/types/types/index.d.ts +0 -34
- package/dist/types/types/kv/DictFromKv.d.ts +0 -6
- package/dist/types/types/kv/KeyValue.d.ts +0 -11
- package/dist/types/types/kv/KvFrom.d.ts +0 -13
- package/dist/types/types/kv/KvTuple.d.ts +0 -14
- package/dist/types/types/kv/index.d.ts +0 -4
- package/dist/types/types/lists/UniqueForProp.d.ts +0 -5
- package/dist/types/types/lists/index.d.ts +0 -1
- package/dist/types/types/maybe.d.ts +0 -8
- package/dist/types/types/props.d.ts +0 -100
- package/dist/types/types/ruleset-types.d.ts +0 -59
- package/dist/types/types/runtime.d.ts +0 -33
- package/dist/types/types/string-literals/Break.d.ts +0 -12
- package/dist/types/types/string-literals/Concat.d.ts +0 -8
- package/dist/types/types/string-literals/LeftWhitespace.d.ts +0 -9
- package/dist/types/types/string-literals/Replace.d.ts +0 -11
- package/dist/types/types/string-literals/RightWhitespace.d.ts +0 -9
- package/dist/types/types/string-literals/StringLength.d.ts +0 -10
- package/dist/types/types/string-literals/Trim.d.ts +0 -11
- package/dist/types/types/string-literals/TrimLeft.d.ts +0 -11
- package/dist/types/types/string-literals/TrimRight.d.ts +0 -11
- package/dist/types/types/string-literals/form-fields.d.ts +0 -12
- package/dist/types/types/string-literals/index.d.ts +0 -10
- package/dist/types/types/tuples/DictArray.d.ts +0 -19
- package/dist/types/types/tuples/FirstKey.d.ts +0 -8
- package/dist/types/types/tuples/FirstKeyValue.d.ts +0 -8
- package/dist/types/types/tuples/FirstOfEach.d.ts +0 -11
- package/dist/types/types/tuples/FromDictArray.d.ts +0 -10
- package/dist/types/types/tuples/SecondOfEach.d.ts +0 -10
- package/dist/types/types/tuples/index.d.ts +0 -6
- package/dist/types/types/type-conversion/TupleToUnion.d.ts +0 -10
- package/dist/types/types/type-conversion/UnionToIntersection.d.ts +0 -5
- package/dist/types/types/type-conversion/UnionToTuple.d.ts +0 -9
- package/dist/types/types/type-conversion/index.d.ts +0 -3
- package/dist/types/types/type-testing.d.ts +0 -13
- package/dist/types/utility/api/api.d.ts +0 -2
- package/dist/types/utility/api/index.d.ts +0 -1
- package/dist/types/utility/createFnWithProps.d.ts +0 -1
- package/dist/types/utility/dictionary/arrayToKeyLookup.d.ts +0 -10
- package/dist/types/utility/dictionary/dictFilter.d.ts +0 -8
- package/dist/types/utility/dictionary/dictionaryTransform.d.ts +0 -9
- package/dist/types/utility/dictionary/entries.d.ts +0 -17
- package/dist/types/utility/dictionary/index.d.ts +0 -8
- package/dist/types/utility/dictionary/kv/dictToKv.d.ts +0 -16
- package/dist/types/utility/dictionary/kv/filterDictArray.d.ts +0 -9
- package/dist/types/utility/dictionary/kv/index.d.ts +0 -4
- package/dist/types/utility/dictionary/kv/kv.d.ts +0 -10
- package/dist/types/utility/dictionary/kv/kvToDict.d.ts +0 -15
- package/dist/types/utility/dictionary/mapValues.d.ts +0 -13
- package/dist/types/utility/dictionary/strArrayToDict.d.ts +0 -6
- package/dist/types/utility/dictionary/valuesOfProp.d.ts +0 -1
- package/dist/types/utility/index.d.ts +0 -10
- package/dist/types/utility/keys.d.ts +0 -5
- package/dist/types/utility/literals/ExplicitFunction.d.ts +0 -6
- package/dist/types/utility/literals/arrayToObject.d.ts +0 -41
- package/dist/types/utility/literals/defineType.d.ts +0 -8
- package/dist/types/utility/literals/identity.d.ts +0 -6
- package/dist/types/utility/literals/index.d.ts +0 -5
- package/dist/types/utility/literals/literal.d.ts +0 -41
- package/dist/types/utility/map-reduce/filter.d.ts +0 -26
- package/dist/types/utility/map-reduce/index.d.ts +0 -1
- package/dist/types/utility/modelling/IoModel.d.ts +0 -26
- package/dist/types/utility/modelling/Model.d.ts +0 -22
- package/dist/types/utility/modelling/index.d.ts +0 -1
- package/dist/types/utility/ruleset.d.ts +0 -18
- package/dist/types/utility/runtime/condition.d.ts +0 -3
- package/dist/types/utility/runtime/conditions/index.d.ts +0 -12
- package/dist/types/utility/runtime/conditions/isArray.d.ts +0 -2
- package/dist/types/utility/runtime/conditions/isBoolean.d.ts +0 -5
- package/dist/types/utility/runtime/conditions/isFalse.d.ts +0 -4
- package/dist/types/utility/runtime/conditions/isFunction.d.ts +0 -15
- package/dist/types/utility/runtime/conditions/isLiteral.d.ts +0 -2
- package/dist/types/utility/runtime/conditions/isNull.d.ts +0 -1
- package/dist/types/utility/runtime/conditions/isNumber.d.ts +0 -1
- package/dist/types/utility/runtime/conditions/isObject.d.ts +0 -10
- package/dist/types/utility/runtime/conditions/isString.d.ts +0 -2
- package/dist/types/utility/runtime/conditions/isSymbol.d.ts +0 -1
- package/dist/types/utility/runtime/conditions/isTrue.d.ts +0 -20
- package/dist/types/utility/runtime/conditions/isUndefined.d.ts +0 -1
- package/dist/types/utility/runtime/ifTypeOf.d.ts +0 -23
- package/dist/types/utility/runtime/index.d.ts +0 -5
- package/dist/types/utility/runtime/type.d.ts +0 -27
- package/dist/types/utility/runtime/withValue.d.ts +0 -19
- package/dist/types/utility/state/Configurator.d.ts +0 -36
- package/dist/types/utility/state/FluentConfigurator.d.ts +0 -27
- package/dist/types/utility/state/index.d.ts +0 -3
- package/src/types/alphabetic/Intrinsic.ts +0 -6
- package/src/utility/modelling/IoModel.ts +0 -38
- package/tests/FluentApi-spec.ts +0 -90
- package/tests/FluentConfigurator-spec.hold +0 -88
- package/tests/IoModel-spec.hold +0 -209
package/src/types/Not.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides a negation of a type of the type `T` _not_ `U
|
|
2
|
+
* Provides a negation of a type of the type `T` _not_ `U`.
|
|
3
3
|
* ```ts
|
|
4
4
|
* const foo = 42;
|
|
5
5
|
* // 33
|
|
@@ -7,5 +7,7 @@
|
|
|
7
7
|
* // never
|
|
8
8
|
* type NotTheMeaningOfLife = Not<42, 42>;
|
|
9
9
|
* ```
|
|
10
|
+
*
|
|
11
|
+
* Note: same as `Exclude`
|
|
10
12
|
*/
|
|
11
13
|
export type Not<T, U> = T extends U ? never : T;
|
package/src/types/Transformer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SameKeys } from "./SameKeys";
|
|
1
|
+
import { SameKeys } from "./type-conversion/SameKeys";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* **Transformer**
|
|
@@ -13,4 +13,3 @@ export type Transformer<I extends object, O extends SameKeys<I>, K extends keyof
|
|
|
13
13
|
input: I,
|
|
14
14
|
key: K
|
|
15
15
|
) => O[K];
|
|
16
|
-
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Include } from "native-dash";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Allows filtering down `T` to those which extend a given type `U`.
|
|
5
|
+
*
|
|
6
|
+
* - `T` is either a dictionary (where keys will be used to compare) or
|
|
7
|
+
* a readonly sting array.
|
|
8
|
+
* ```ts
|
|
9
|
+
* const arr = ["foo", "bar", "baz"];
|
|
10
|
+
* // "bar" | "baz"
|
|
11
|
+
* type BA = Where<typeof arr, `ba${string}`>;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type Where<T extends Record<string, any> | readonly string[], U> = T extends readonly string[]
|
|
15
|
+
? Include<T[number], U>
|
|
16
|
+
: {
|
|
17
|
+
[K in keyof T]: K extends U ? K : never;
|
|
18
|
+
}[keyof T];
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Allows filtering down `T` to those which extend a given type `U`.
|
|
23
|
+
*
|
|
24
|
+
* - `T` is either a dictionary (where keys will be used to compare) or
|
|
25
|
+
* a readonly sting array.
|
|
26
|
+
* ```ts
|
|
27
|
+
* const arr = ["foo", "bar", "baz"];
|
|
28
|
+
* // "foo"
|
|
29
|
+
* type F = WhereNot<typeof arr, `ba${string}`>;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type WhereNot<T extends Record<string, any> | readonly string[], U> = T extends readonly string[]
|
|
33
|
+
? Exclude<T[number], U>
|
|
34
|
+
: {
|
|
35
|
+
[K in keyof T]: K extends U ? never : K;
|
|
36
|
+
}[keyof T];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
2
|
-
import type {
|
|
2
|
+
import type { LowerAllCaps, Trim } from "~/types";
|
|
3
3
|
|
|
4
4
|
type Delimiter = "_" | "-" | " ";
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ type DashDelim<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
|
|
|
10
10
|
? DashDelim<`${Begin}-${Rest}`>
|
|
11
11
|
: T;
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
14
|
* Converts a string literal type to a **PascalCase** representation.
|
|
15
15
|
* ```ts
|
|
16
16
|
* // "FooBar"
|
|
@@ -20,7 +20,8 @@ type DashDelim<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
|
|
|
20
20
|
* type T = PascalCase<"\n foo_bar \t">;
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export type PascalCase<S extends string> = string extends S
|
|
24
|
-
|
|
23
|
+
export type PascalCase<S extends string> = string extends S
|
|
24
|
+
? string
|
|
25
|
+
: Trim<DashDelim<LowerAllCaps<S>>> extends `${infer Begin}${Delimiter}${infer Rest}`
|
|
25
26
|
? PascalCase<`${Capitalize<Begin>}${Capitalize<Rest>}`>
|
|
26
27
|
: Capitalize<Trim<LowerAllCaps<S>>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// #autoindex, exclude: Alpha
|
|
2
2
|
// #region autoindexed files
|
|
3
3
|
|
|
4
|
-
// index last changed at:
|
|
4
|
+
// index last changed at: 12th Dec, 2021, 12:24 PM ( GMT-8 )
|
|
5
5
|
// export: named; exclusions: Alpha, index, private.
|
|
6
|
-
// files: AllCaps, CamelCase, CapFirstAlpha, CapitalizeWords, DashToSnake, DashUppercase, Dasherize, HasUppercase,
|
|
6
|
+
// files: AllCaps, CamelCase, CapFirstAlpha, CapitalizeWords, DashToSnake, DashUppercase, Dasherize, HasUppercase, IsCapitalized, KebabCase, LowerAllCaps, PascalCase, Pluralize, SnakeCase, alpha-characters.
|
|
7
7
|
|
|
8
8
|
// local file exports
|
|
9
9
|
export * from "./AllCaps";
|
|
@@ -14,7 +14,6 @@ export * from "./DashToSnake";
|
|
|
14
14
|
export * from "./DashUppercase";
|
|
15
15
|
export * from "./Dasherize";
|
|
16
16
|
export * from "./HasUppercase";
|
|
17
|
-
export * from "./Intrinsic";
|
|
18
17
|
export * from "./IsCapitalized";
|
|
19
18
|
export * from "./KebabCase";
|
|
20
19
|
export * from "./LowerAllCaps";
|
|
@@ -26,7 +25,7 @@ export * from "./alpha-characters";
|
|
|
26
25
|
// Note:
|
|
27
26
|
// -----
|
|
28
27
|
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
29
|
-
// the 'do-devops' pkg installed as a dev dep.
|
|
28
|
+
// the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
|
|
30
29
|
//
|
|
31
30
|
// By default it assumes that exports are named exports but this can be changed by
|
|
32
31
|
// adding a modifier to the '// #autoindex' syntax:
|
|
@@ -45,7 +44,12 @@ export * from "./alpha-characters";
|
|
|
45
44
|
//
|
|
46
45
|
// - autoindex:named, exclude: foo,bar,baz
|
|
47
46
|
//
|
|
48
|
-
//
|
|
47
|
+
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
48
|
+
// below this file will not reference this autoindex file:
|
|
49
|
+
//
|
|
50
|
+
// - autoindex:named, orphan
|
|
51
|
+
//
|
|
52
|
+
// Also be aware that all of your content outside the "// #region" section in this file
|
|
49
53
|
// will be preserved in situations where you need to do something paricularly awesome.
|
|
50
54
|
// Keep on being awesome.
|
|
51
55
|
|
|
@@ -14,8 +14,7 @@ export type ToFluent<
|
|
|
14
14
|
X extends object = {}
|
|
15
15
|
> = {
|
|
16
16
|
[K in keyof T]: (...args: Parameters<T[K]>) => ToFluent<T, X> & X;
|
|
17
|
-
} &
|
|
18
|
-
X;
|
|
17
|
+
} & X;
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* A _pure_ Fluent API which promotes an API surface where _every_ API endpoint must be a function
|
|
@@ -53,10 +52,10 @@ export type PureFluentApi<
|
|
|
53
52
|
* pass out the interior state which has been configured by the fluent parts of the API
|
|
54
53
|
* - `TExclude` represents part of the API which -- due to the internal state -- should be hidden
|
|
55
54
|
*/
|
|
56
|
-
export type FluentApi<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
> = Omit<TFluent & TEscape, TExclude>;
|
|
55
|
+
// export type FluentApi<
|
|
56
|
+
// TFluent extends {
|
|
57
|
+
// [K in keyof TFluent]: (...args: Parameters<TFluent[K]>) => FluentApi<TFluent, TEscape>;
|
|
58
|
+
// },
|
|
59
|
+
// TEscape extends object = {},
|
|
60
|
+
// TExclude extends string = ""
|
|
61
|
+
// > = Omit<TFluent & TEscape, TExclude>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// #autoindex
|
|
2
|
+
// #region autoindexed files
|
|
3
|
+
|
|
4
|
+
// index last changed at: 12th Dec, 2021, 12:28 PM ( GMT-8 )
|
|
5
|
+
// export: named; exclusions: index, private.
|
|
6
|
+
// files: fluent.
|
|
7
|
+
|
|
8
|
+
// local file exports
|
|
9
|
+
export * from "./fluent";
|
|
10
|
+
|
|
11
|
+
// Note:
|
|
12
|
+
// -----
|
|
13
|
+
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
14
|
+
// the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
|
|
15
|
+
//
|
|
16
|
+
// By default it assumes that exports are named exports but this can be changed by
|
|
17
|
+
// adding a modifier to the '// #autoindex' syntax:
|
|
18
|
+
//
|
|
19
|
+
// - autoindex:named same as default, exports "named symbols"
|
|
20
|
+
// - autoindex:default assumes each file is exporting a default export
|
|
21
|
+
// and converts the default export to the name of the
|
|
22
|
+
// file
|
|
23
|
+
// - autoindex:offset assumes files export "named symbols" but that each
|
|
24
|
+
// file's symbols should be offset by the file's name
|
|
25
|
+
// (useful for files which might symbols which collide
|
|
26
|
+
// or where the namespacing helps consumers)
|
|
27
|
+
//
|
|
28
|
+
// You may also exclude certain files or directories by adding it to the
|
|
29
|
+
// autoindex command. As an example:
|
|
30
|
+
//
|
|
31
|
+
// - autoindex:named, exclude: foo,bar,baz
|
|
32
|
+
//
|
|
33
|
+
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
34
|
+
// below this file will not reference this autoindex file:
|
|
35
|
+
//
|
|
36
|
+
// - autoindex:named, orphan
|
|
37
|
+
//
|
|
38
|
+
// Also be aware that all of your content outside the "// #region" section in this file
|
|
39
|
+
// will be preserved in situations where you need to do something paricularly awesome.
|
|
40
|
+
// Keep on being awesome.
|
|
41
|
+
|
|
42
|
+
// #endregion
|
package/src/types/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// #autoindex
|
|
2
2
|
// #region autoindexed files
|
|
3
3
|
|
|
4
|
-
// index last changed at:
|
|
4
|
+
// index last changed at: 10th Oct, 2021, 08:32 PM ( GMT-7 )
|
|
5
5
|
// export: named; exclusions: index, private.
|
|
6
|
-
// files: Api, EnumValues, ExpandRecursively, First, FunctionType, If, Include, Includes, KeyedRecord, Keys, Length, Mutable, Narrowable, Not, Numeric, Opaque, Retain,
|
|
7
|
-
// directories: alphabetic, dictionary, kv, lists, string-literals, tuples, type-conversion.
|
|
6
|
+
// files: Api, Constructor, EnumValues, ExpandRecursively, First, FunctionType, If, Include, Includes, KeyedRecord, Keys, Length, Mutable, Narrowable, Not, Numeric, Opaque, Retain, Transformer, TypeGuard, Where, append-types, maybe, props, ruleset-types, runtime, type-testing.
|
|
7
|
+
// directories: alphabetic, dictionary, fluent, kv, lists, string-literals, tuples, type-conversion.
|
|
8
8
|
|
|
9
9
|
// local file exports
|
|
10
10
|
export * from "./Api";
|
|
11
|
+
export * from "./Constructor";
|
|
11
12
|
export * from "./EnumValues";
|
|
12
13
|
export * from "./ExpandRecursively";
|
|
13
14
|
export * from "./First";
|
|
@@ -24,11 +25,10 @@ export * from "./Not";
|
|
|
24
25
|
export * from "./Numeric";
|
|
25
26
|
export * from "./Opaque";
|
|
26
27
|
export * from "./Retain";
|
|
27
|
-
export * from "./SameKeys";
|
|
28
28
|
export * from "./Transformer";
|
|
29
29
|
export * from "./TypeGuard";
|
|
30
|
+
export * from "./Where";
|
|
30
31
|
export * from "./append-types";
|
|
31
|
-
export * from "./fluent";
|
|
32
32
|
export * from "./maybe";
|
|
33
33
|
export * from "./props";
|
|
34
34
|
export * from "./ruleset-types";
|
|
@@ -38,6 +38,7 @@ export * from "./type-testing";
|
|
|
38
38
|
// directory exports
|
|
39
39
|
export * from "./alphabetic/index";
|
|
40
40
|
export * from "./dictionary/index";
|
|
41
|
+
export * from "./fluent/index";
|
|
41
42
|
export * from "./kv/index";
|
|
42
43
|
export * from "./lists/index";
|
|
43
44
|
export * from "./string-literals/index";
|
|
@@ -47,7 +48,7 @@ export * from "./type-conversion/index";
|
|
|
47
48
|
// Note:
|
|
48
49
|
// -----
|
|
49
50
|
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
50
|
-
// the 'do-devops' pkg installed as a dev dep.
|
|
51
|
+
// the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
|
|
51
52
|
//
|
|
52
53
|
// By default it assumes that exports are named exports but this can be changed by
|
|
53
54
|
// adding a modifier to the '// #autoindex' syntax:
|
|
@@ -66,7 +67,12 @@ export * from "./type-conversion/index";
|
|
|
66
67
|
//
|
|
67
68
|
// - autoindex:named, exclude: foo,bar,baz
|
|
68
69
|
//
|
|
69
|
-
//
|
|
70
|
+
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
71
|
+
// below this file will not reference this autoindex file:
|
|
72
|
+
//
|
|
73
|
+
// - autoindex:named, orphan
|
|
74
|
+
//
|
|
75
|
+
// Also be aware that all of your content outside the "// #region" section in this file
|
|
70
76
|
// will be preserved in situations where you need to do something paricularly awesome.
|
|
71
77
|
// Keep on being awesome.
|
|
72
78
|
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Get } from "../dictionary/Get";
|
|
2
|
+
import { Narrowable } from "../Narrowable";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Create a union type based on a given property in an array of objects
|
|
6
|
+
* ```ts
|
|
7
|
+
* const data = [
|
|
8
|
+
* { id: 123, color: "blue" },
|
|
9
|
+
* { id: 456, color: "red" },
|
|
10
|
+
* ] as const;
|
|
11
|
+
* // 123 | 456
|
|
12
|
+
* type U = UniqueForProp<typeof data, "id">;
|
|
13
|
+
* ```
|
|
5
14
|
*/
|
|
6
|
-
export type UniqueForProp<
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
export type UniqueForProp<
|
|
16
|
+
T extends readonly Record<string, Narrowable>[],
|
|
17
|
+
P extends string
|
|
18
|
+
> = Readonly<Get<T[number], P>>;
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ValueFunction<T extends any> = <R extends any>(v: T) => R;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **SameKeys**
|
|
5
|
+
*
|
|
6
|
+
* Given a dictionary `T` and a type-strong wrapper function `F`, returns a dictionary with the
|
|
7
|
+
* same keys but
|
|
8
|
+
*
|
|
9
|
+
* Note: meant to be used as part of an _extends_ clause in most cases.
|
|
10
|
+
*/
|
|
11
|
+
export type WrapValue<T extends {}, F extends ValueFunction<T>> = {
|
|
12
|
+
[P in keyof T]: ReturnType<F>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
|
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
// #region autoindexed files
|
|
4
4
|
|
|
5
|
-
// index last changed at:
|
|
5
|
+
// index last changed at: 10th Oct, 2021, 08:32 PM ( GMT-7 )
|
|
6
6
|
// export: named; exclusions: index, private.
|
|
7
|
-
// files: TupleToUnion, UnionToIntersection, UnionToTuple.
|
|
7
|
+
// files: SameKeys, TupleToUnion, UnionToIntersection, UnionToTuple, WrapValue.
|
|
8
8
|
|
|
9
9
|
// local file exports
|
|
10
|
+
export * from "./SameKeys";
|
|
10
11
|
export * from "./TupleToUnion";
|
|
11
12
|
export * from "./UnionToIntersection";
|
|
12
13
|
export * from "./UnionToTuple";
|
|
14
|
+
export * from "./WrapValue";
|
|
13
15
|
|
|
14
16
|
// Note:
|
|
15
17
|
// -----
|
|
16
18
|
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
17
|
-
// the 'do-devops' pkg installed as a dev dep.
|
|
19
|
+
// the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
|
|
18
20
|
//
|
|
19
21
|
// By default it assumes that exports are named exports but this can be changed by
|
|
20
22
|
// adding a modifier to the '// #autoindex' syntax:
|
|
@@ -33,7 +35,12 @@ export * from "./UnionToTuple";
|
|
|
33
35
|
//
|
|
34
36
|
// - autoindex:named, exclude: foo,bar,baz
|
|
35
37
|
//
|
|
36
|
-
//
|
|
38
|
+
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
39
|
+
// below this file will not reference this autoindex file:
|
|
40
|
+
//
|
|
41
|
+
// - autoindex:named, orphan
|
|
42
|
+
//
|
|
43
|
+
// Also be aware that all of your content outside the "// #region" section in this file
|
|
37
44
|
// will be preserved in situations where you need to do something paricularly awesome.
|
|
38
45
|
// Keep on being awesome.
|
|
39
46
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Passing in an array of strings, you are passed back a dictionary with
|
|
3
|
-
* being the strings and values set to `true`.
|
|
4
|
-
*
|
|
2
|
+
* Passing in an array of strings, you are passed back a dictionary with
|
|
3
|
+
* all the keys being the strings and values set to `true`.
|
|
5
4
|
* ```ts
|
|
6
5
|
* // { foo: true, bar: true }
|
|
7
6
|
* const fooBar = arrayToKeyLookup("foo", "bar");
|
|
@@ -15,4 +14,4 @@ export function arrayToKeyLookup<T extends readonly string[]>(...keys: T): Recor
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
return obj;
|
|
18
|
-
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { keys } from "~/utility/keys";
|
|
2
3
|
import { SameKeys, Transformer } from "~/types";
|
|
3
|
-
import { kv } from "native-dash";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Takes a dictionary of type `I` and converts it to a dictionary of type `O` where
|
|
@@ -10,13 +10,12 @@ import { kv } from "native-dash";
|
|
|
10
10
|
* and key, and then return expected value of `O` for the given key.
|
|
11
11
|
*/
|
|
12
12
|
export function dictionaryTransform<I extends object, O extends SameKeys<I>>(
|
|
13
|
-
|
|
13
|
+
input: I,
|
|
14
14
|
transform: Transformer<I, O>
|
|
15
15
|
) {
|
|
16
|
-
const result = {} as any;
|
|
17
|
-
for (const pair of kv(i)) {
|
|
18
|
-
result[pair.key] = transform(i, pair.key);
|
|
19
|
-
}
|
|
20
16
|
|
|
21
|
-
return
|
|
17
|
+
return keys(input).reduce((acc, i) => {
|
|
18
|
+
const key = i as string & keyof I;
|
|
19
|
+
return {...acc, [key]: transform(input, key)};
|
|
20
|
+
}, {} as O);
|
|
22
21
|
}
|
package/src/utility/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
// #region autoindexed files
|
|
4
4
|
|
|
5
|
-
// index last changed at: 8th Aug, 2021,
|
|
5
|
+
// index last changed at: 8th Aug, 2021, 10:32 AM ( GMT-7 )
|
|
6
6
|
// export: named; exclusions: index, private.
|
|
7
7
|
// files: createFnWithProps, keys, ruleset.
|
|
8
|
-
// directories: api, dictionary, literals, map-reduce, modelling, runtime, state.
|
|
8
|
+
// directories: api, dictionary, lists, literals, map-reduce, modelling, runtime, state.
|
|
9
9
|
|
|
10
10
|
// local file exports
|
|
11
11
|
export * from "./createFnWithProps";
|
|
@@ -15,6 +15,7 @@ export * from "./ruleset";
|
|
|
15
15
|
// directory exports
|
|
16
16
|
export * from "./api/index";
|
|
17
17
|
export * from "./dictionary/index";
|
|
18
|
+
export * from "./lists/index";
|
|
18
19
|
export * from "./literals/index";
|
|
19
20
|
export * from "./map-reduce/index";
|
|
20
21
|
export * from "./modelling/index";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Narrowable } from "~/types";
|
|
2
|
+
// import { UniqueForProp } from "~/types/lists/UniqueForProp";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Groups an array of data based on the value of a property
|
|
6
|
+
* in the objects within the array.
|
|
7
|
+
* ```ts
|
|
8
|
+
* const data = [ {}, {}, {} ];
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @ignore not implemented
|
|
13
|
+
*/
|
|
14
|
+
export function groupBy<T extends Record<string, Narrowable>, K extends keyof T & string>(
|
|
15
|
+
_data: Readonly<T[]>
|
|
16
|
+
) {
|
|
17
|
+
throw new Error("not implemented");
|
|
18
|
+
return (_groupBy: K) => {
|
|
19
|
+
// type _GroupedBy = UniqueForProp<typeof data, K>;
|
|
20
|
+
// const _output = {} as Record<GroupedBy, Narrowable>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// #autoindex
|
|
2
|
+
|
|
3
|
+
// #region autoindexed files
|
|
4
|
+
|
|
5
|
+
// index last changed at: 8th Aug, 2021, 10:32 AM ( GMT-7 )
|
|
6
|
+
// export: named; exclusions: index, private.
|
|
7
|
+
// files: groupBy.
|
|
8
|
+
|
|
9
|
+
// local file exports
|
|
10
|
+
export * from "./groupBy";
|
|
11
|
+
|
|
12
|
+
// Note:
|
|
13
|
+
// -----
|
|
14
|
+
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
15
|
+
// the 'do-devops' pkg installed as a dev dep.
|
|
16
|
+
//
|
|
17
|
+
// By default it assumes that exports are named exports but this can be changed by
|
|
18
|
+
// adding a modifier to the '// #autoindex' syntax:
|
|
19
|
+
//
|
|
20
|
+
// - autoindex:named same as default, exports "named symbols"
|
|
21
|
+
// - autoindex:default assumes each file is exporting a default export
|
|
22
|
+
// and converts the default export to the name of the
|
|
23
|
+
// file
|
|
24
|
+
// - autoindex:offset assumes files export "named symbols" but that each
|
|
25
|
+
// file's symbols should be offset by the file's name
|
|
26
|
+
// (useful for files which might symbols which collide
|
|
27
|
+
// or where the namespacing helps consumers)
|
|
28
|
+
//
|
|
29
|
+
// You may also exclude certain files or directories by adding it to the
|
|
30
|
+
// autoindex command. As an example:
|
|
31
|
+
//
|
|
32
|
+
// - autoindex:named, exclude: foo,bar,baz
|
|
33
|
+
//
|
|
34
|
+
// Also be aware that all of your content outside the defined region in this file
|
|
35
|
+
// will be preserved in situations where you need to do something paricularly awesome.
|
|
36
|
+
// Keep on being awesome.
|
|
37
|
+
|
|
38
|
+
// #endregion
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Expect, Equal } from "@type-challenges/utils";
|
|
2
|
+
import { Where, WhereNot } from "../src/types/Where";
|
|
3
|
+
|
|
4
|
+
describe("Where<T,U> and WhereNot<T,U> type utility", () => {
|
|
5
|
+
|
|
6
|
+
it("readonly string array works correctly", () => {
|
|
7
|
+
const arr = ["foo", "bar", "baz"] as const;
|
|
8
|
+
type A = typeof arr;
|
|
9
|
+
type B = Where<A, `ba${string}`>;
|
|
10
|
+
type F = WhereNot<A, `ba${string}`>;
|
|
11
|
+
|
|
12
|
+
type cases = [
|
|
13
|
+
//
|
|
14
|
+
Expect<Equal<B, "bar"| "baz">>,
|
|
15
|
+
Expect<Equal<F, "foo">>
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const c: cases = [ true, true ];
|
|
19
|
+
expect(c).toBe(c);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("object with literal keys works", () => {
|
|
23
|
+
const arr = {foo: true, bar: true, baz: true} as const;
|
|
24
|
+
type A = typeof arr;
|
|
25
|
+
type B = Where<A, `ba${string}`>;
|
|
26
|
+
type F = WhereNot<A, `ba${string}`>;
|
|
27
|
+
|
|
28
|
+
type cases = [
|
|
29
|
+
//
|
|
30
|
+
Expect<Equal<B, "bar"| "baz">>,
|
|
31
|
+
Expect<Equal<F, "foo">>
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const c: cases = [ true, true ];
|
|
35
|
+
expect(c).toBe(c);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Expect, Equal } from "@type-challenges/utils";
|
|
2
|
+
import { Constructor } from "../src/types/Constructor";
|
|
3
|
+
|
|
4
|
+
class TestClass {
|
|
5
|
+
public foo: number;
|
|
6
|
+
public bar: string;
|
|
7
|
+
|
|
8
|
+
constructor(foo: number, bar: string) {
|
|
9
|
+
this.foo = foo;
|
|
10
|
+
this.bar = bar;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("Constructor<Ctor, Klass>", () => {
|
|
15
|
+
it("simple test", () => {
|
|
16
|
+
type KlassParams = ConstructorParameters<typeof TestClass>;
|
|
17
|
+
type KlassInstance = InstanceType<typeof TestClass>;
|
|
18
|
+
type Synthetic = Constructor<[foo: number, bar: string], TestClass>;
|
|
19
|
+
type SynReturn = InstanceType<Synthetic>;
|
|
20
|
+
const s: Synthetic = TestClass;
|
|
21
|
+
|
|
22
|
+
const myS = new s(1, "bar");
|
|
23
|
+
|
|
24
|
+
const inst = new TestClass(1, "bar");
|
|
25
|
+
type Instance = typeof inst;
|
|
26
|
+
|
|
27
|
+
type cases = [
|
|
28
|
+
// prep
|
|
29
|
+
Expect<Equal<Instance, { foo: number; bar: string }>>,
|
|
30
|
+
Expect<Equal<Instance, KlassInstance>>,
|
|
31
|
+
Expect<Equal<KlassParams, [foo: number, bar: string]>>,
|
|
32
|
+
//
|
|
33
|
+
Expect<Equal<SynReturn, TestClass>>
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const c: cases = [true, true, true, true];
|
|
37
|
+
expect(c).toBe(c);
|
|
38
|
+
expect(myS).toBeInstanceOf(TestClass);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/tests/data/index.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
// #region autoindexed files
|
|
4
4
|
|
|
5
|
-
// index last changed at:
|
|
5
|
+
// index last changed at: 12th Dec, 2021, 12:35 PM ( GMT-8 )
|
|
6
6
|
// export: named; exclusions: index, private.
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// Note:
|
|
10
10
|
// -----
|
|
11
11
|
// This file was created by running: "dd devops autoindex"; it assumes you have
|
|
12
|
-
// the 'do-devops' pkg installed as a dev dep.
|
|
12
|
+
// the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
|
|
13
13
|
//
|
|
14
14
|
// By default it assumes that exports are named exports but this can be changed by
|
|
15
15
|
// adding a modifier to the '// #autoindex' syntax:
|
|
@@ -28,7 +28,12 @@
|
|
|
28
28
|
//
|
|
29
29
|
// - autoindex:named, exclude: foo,bar,baz
|
|
30
30
|
//
|
|
31
|
-
//
|
|
31
|
+
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
32
|
+
// below this file will not reference this autoindex file:
|
|
33
|
+
//
|
|
34
|
+
// - autoindex:named, orphan
|
|
35
|
+
//
|
|
36
|
+
// Also be aware that all of your content outside the "// #region" section in this file
|
|
32
37
|
// will be preserved in situations where you need to do something paricularly awesome.
|
|
33
38
|
// Keep on being awesome.
|
|
34
39
|
|
|
@@ -23,10 +23,7 @@ describe("dictToKv()", () => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
type cases = [
|
|
26
|
-
Expect<
|
|
27
|
-
Equal<
|
|
28
|
-
Val,
|
|
29
|
-
[
|
|
26
|
+
Expect<Equal<Val, [
|
|
30
27
|
{
|
|
31
28
|
key: "id";
|
|
32
29
|
value: 123;
|
|
@@ -35,8 +32,7 @@ describe("dictToKv()", () => {
|
|
|
35
32
|
key: "foo";
|
|
36
33
|
value: "bar";
|
|
37
34
|
}
|
|
38
|
-
]
|
|
39
|
-
>
|
|
35
|
+
]>
|
|
40
36
|
>
|
|
41
37
|
];
|
|
42
38
|
|