inferred-types 0.16.0 → 0.18.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/.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 -39
- package/pnpm-lock.yaml +2807 -3858
- 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/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/dictionaryTransform.ts +6 -7
- 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 -14
- 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 -9
- 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 -11
- package/dist/types/utility/keys.d.ts +0 -5
- package/dist/types/utility/lists/groupBy.d.ts +0 -12
- package/dist/types/utility/lists/index.d.ts +0 -1
- 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/tests/lists/groupBy.spec.ts +0 -0
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
|
|
|
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,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
|
}
|
|
@@ -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
|
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"module": "
|
|
4
|
-
"target": "
|
|
3
|
+
"module": "ESNEXT",
|
|
4
|
+
"target": "ESNEXT",
|
|
5
5
|
"moduleResolution": "node",
|
|
6
6
|
|
|
7
7
|
"sourceMap": true,
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"noImplicitReturns": true,
|
|
17
17
|
"allowSyntheticDefaultImports": true,
|
|
18
18
|
|
|
19
|
-
"lib": ["
|
|
19
|
+
"lib": ["ES2020"],
|
|
20
20
|
|
|
21
21
|
"baseUrl": ".",
|
|
22
22
|
"declaration": true,
|
|
23
23
|
"outDir": "dist",
|
|
24
|
+
"tsBuildInfoFile": ".tsbuildinfo",
|
|
24
25
|
|
|
25
26
|
"paths": {
|
|
26
27
|
"~/*": ["src/*"],
|
package/dist/cjs/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});function createMutationFunction(a){return b=>b(a)}function MutationIdentity(){return function(a){return a}}class d extends Error{constructor(){super(...arguments);this.kind="BrilliantError"}}var f={exports:{}};let g=()=>{let a=Error.prepareStackTrace;Error.prepareStackTrace=(a,b)=>b;let b=Error().stack.slice(1);Error.prepareStackTrace=a;return b};f.exports=g;f.exports.default=g;var k=f.exports;
|
|
2
|
-
function l(a){return a.map(a=>{let b=(a.getFileName()||"[file unknown]").split("/").slice(-2).join("/"),e=a.getFunctionName()||a.getMethodName()||"unknown";a=a.getLineNumber();return`\t- ${b}, ${e}()${a?`, at line ${a}`:""}`}).join("\n")}
|
|
3
|
-
function createError(a,b){class c extends d{constructor(c,m,h={}){super(c);this.kind="BrilliantError";this.name=a;this.origin=b;this.classification=m;this.structuredStack=k().slice(1)||[];this.filename=(this.structuredStack[0].getFileName()||"").split("/").slice(-2).join("/");this.line=this.structuredStack[0].getLineNumber();this.fn=this.structuredStack[0].getMethodName()||this.structuredStack[0].getFunctionName();this.message=`${c} [ ${this.classification} ]\n\n${l(this.structuredStack)}`;h.httpStatusCode&&
|
|
4
|
-
(this.httpStatus=h.httpStatusCode)}toJSON(){return{name:this.name,message:this.message,classification:this.classification,origin:this.origin,fn:this.fn,line:this.line,stack:this.structuredStack}}}return c}let InferenceError=createError("InferenceError","inferred-types");function keys$1(a,...b){return 0<b.length?Object.keys(a).filter(a=>!b.includes(a)):Object.keys(a)}function createFnWithProps(a,b){for(let c of keys$1(b))a[c]=b[c];return a}function ruleSet(a){return a}
|
|
5
|
-
let api=a=>b=>{const c=()=>b;c.prototype.priv=()=>a;return c};function arrayToKeyLookup(...a){let b={};for(let c of a)b[c]=!0;return b}var DataType;
|
|
6
|
-
(function(a){a["null"]="null";a.string="string";a.number="number";a.bigint="bigint";a.symbol="symbol";a["boolean"]="boolean";a["function"]="function";a.undefined="undefined";a.dictionary="dictionary";a.object="object";a.array="array";a.stringArray="string[]";a.numberArray="number[]";a.booleanArray="boolean[]";a.symbolArray="symbol[]";a.functionArray="function[]";a.undefinedArray="undefined[]";a.nullArray="null[]";a.objectArray="object[]";a.dictionaryArray="dictionary[]"})(DataType||(DataType={}));
|
|
7
|
-
function keys(a){if(null===a)throw Error("Can not run keys() on a null value!");return Object.keys(a)}function kv$1(a){if("object"!==typeof a||null===a)throw Error("Value passed into kv() must be an object");return keys(a).reduce((b,c)=>{let e=a[c];return[...b,{key:c,value:e}]},[])}function omit(a,...b){return Object.fromEntries(Object.entries(a).filter(([a])=>!b.includes(a)))}var Rule;(function(a){a[a.regex=0]="regex";a[a.fn=1]="fn";a[a.exceptions=2]="exceptions"})(Rule||(Rule={}));var ExplicitRule;
|
|
8
|
-
(function(a){a[a.singular=0]="singular";a[a.plural=1]="plural"})(ExplicitRule||(ExplicitRule={}));function dictFilter(a,b){keys$1(a).filter(c=>!b(c,a));return omit(a,...keys$1(a).filter(c=>!b(c,a)))}function dictionaryTransform(a,b){let c={};for(let e of kv$1(a))c[e.key]=b(a,e.key);return c}function entries(a){return{*[Symbol.iterator](){for(const b of keys$1(a))yield[b,a[b]]}}}function mapValues(a,b){return Object.fromEntries([...entries(a)].map(([a,e])=>[a,b(e)]))}
|
|
9
|
-
function strArrayToDict(...a){return a.reduce((a,c)=>a={...a,[c]:!0},{})}function valuesOfProp(){}function dictToKv(a,b){return keys$1(a).map(b=>({key:b,value:a[b]}))}function Configurator(){let a=()=>({});return(()=>({set(b,c){b={[b]:c};const e={...a(),...b};a=()=>e;return e},remove(b){const c=a(),e=omit(c,b);a=()=>e;return e},done(){return a()}}))()}
|
|
10
|
-
function FluentConfigurator(a={}){let b=a=>({set(c,m){return b({[c]:m,...a})},done(){return a}});if(a&&"object"!==typeof a)throw Error("The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed.");return a?b(a):b({})}function KeyStorage(){let a=b=>({add:(...c)=>a([...b,...c]),remove:c=>a(b.filter(a=>a!==c)),done:()=>b});return a([])}function filterDictArray(a,b){let c=Configurator();return a.filter(a=>{const [e,h]=a;(a=b(e,h))||c.set(e,!0);return a})}
|
|
11
|
-
function kv(a,b){return{[a]:b}}function kvToDict(a){let b={};for(let c of a)b[c.key]=c.value;return b}function groupBy(a){throw Error("not implemented");}function ExplicitFunction(a){return a}function arrayToObject(a,b){return c=>!1!==b?c.reduce((b,c)=>({...b,[c[a]]:c}),{}):c.reduce((b,c)=>({...b,[c[a]]:[...b[c[a]]||[],c]}),{})}function defineType(a={}){return(b={})=>a?{...b,...a}:b}let identity=a=>a;function idLiteral(a){return{...a,id:a.id}}function nameLiteral(a){return a}
|
|
12
|
-
function kindLiteral(a){return a}function idTypeGuard(a){return!0}function literal(a){return a}let equals=(a,b)=>({kind:"Equals",field:a,val:b}),greater=(a,b)=>({kind:"Greater",field:a,val:b}),less=(a,b)=>({kind:"Less",field:a,val:b}),and=(a,b)=>({kind:"And",a,b}),or=(a,b)=>({kind:"Or",a,b});function Model(a){return{required(b){return Model(a)},optional(b){return Model(a)},done(){return{__model__:a,__kind__:"model"}}}}let condition=(a,b)=>a(b);
|
|
13
|
-
function runtimeExtendsCheck(a,b,c=!1){if(typeof a!==typeof b)return!1;switch(typeof a){case "boolean":case "string":case "number":case "symbol":case "bigint":return c?a===b:!0;case "undefined":return!0;case "function":if(c)throw new InferenceError("Use of narrowlyExtends with a function is not possible!","ifTypeOf/not-allowed");return!0;case "object":return null===a&&null===b?!0:keys$1(b).every(e=>runtimeExtendsCheck(a[e],b[e],c))}}
|
|
14
|
-
let ifTypeOf=a=>({extends:b=>runtimeExtendsCheck(a,b,!1)?!0:!1,narrowlyExtends:b=>runtimeExtendsCheck(a,b,!0)?!0:!1});function isArray(a){return!0===Array.isArray(a)}function isBoolean(a){return"boolean"===typeof a}function isFalse(a){return"boolean"===typeof a&&!a}function isFunction(a){return"function"===typeof a}function isLiteral(...a){return b=>!a.every(a=>b!==a)}function isNull(a){return null===a}function isNumber(a){return"number"===typeof a}
|
|
15
|
-
function isObject(a){return"object"===typeof a&&null!==a&&!1===Array.isArray(a)}function isString(a){return"string"===typeof a}function isSymbol(a){return"symbol"===typeof a}function isTrue(a){return"boolean"===typeof a&&a}function isUndefined(a){return"undefined"===typeof a}
|
|
16
|
-
let typeApi=()=>({string:{name:"string",type:"",typeGuard:a=>isString(a),is:isString},boolean:{name:"boolean",type:!0,typeGuard:a=>isBoolean(a),is:isBoolean},number:{name:"number",type:1,typeGuard:a=>isNumber(a),is:isNumber},function:{name:"function",type:Function,typeGuard:a=>isFunction(a),is:isFunction},null:{name:"null",type:null,typeGuard:a=>isNull(a),is:isNull},symbol:{name:"symbol",type:Symbol(),typeGuard:a=>isSymbol(a),is:isSymbol},undefined:{name:"undefined",type:void 0,typeGuard:a=>isUndefined(a),
|
|
17
|
-
is:isUndefined},true:{name:"true",type:!0,typeGuard:a=>isTrue(a),is:isTrue},false:{name:"false",type:!1,typeGuard:a=>isFalse(a),is:isFalse},object:{name:"object",type:{},typeGuard:a=>isObject(a),is:isObject},array:{name:"array",type:{},typeGuard:a=>isArray(a),is:isObject}});function isType(a){return"object"===typeof a&&["name","type","is"].every(b=>Object.keys(a).includes(b))}
|
|
18
|
-
function type(a){a=a(typeApi());if(!isType(a))throw Error(`When using type(), the callback passed in returned an invalid type! Value returned was: ${a}`);return a}function withValue(a){return b=>{let c=type(a);return Object.fromEntries([...entries(b)].filter(([,a])=>c.typeGuard(a)))}}exports.Configurator=Configurator;exports.ExplicitFunction=ExplicitFunction;exports.FluentConfigurator=FluentConfigurator;exports.InferenceError=InferenceError;exports.KeyStorage=KeyStorage;exports.Model=Model;
|
|
19
|
-
exports.MutationIdentity=MutationIdentity;exports.and=and;exports.api=api;exports.arrayToKeyLookup=arrayToKeyLookup;exports.arrayToObject=arrayToObject;exports.condition=condition;exports.createFnWithProps=createFnWithProps;exports.createMutationFunction=createMutationFunction;exports.defineType=defineType;exports.dictFilter=dictFilter;exports.dictToKv=dictToKv;exports.dictionaryTransform=dictionaryTransform;exports.entries=entries;exports.equals=equals;exports.filterDictArray=filterDictArray;
|
|
20
|
-
exports.greater=greater;exports.groupBy=groupBy;exports.idLiteral=idLiteral;exports.idTypeGuard=idTypeGuard;exports.identity=identity;exports.ifTypeOf=ifTypeOf;exports.isArray=isArray;exports.isBoolean=isBoolean;exports.isFalse=isFalse;exports.isFunction=isFunction;exports.isLiteral=isLiteral;exports.isNull=isNull;exports.isNumber=isNumber;exports.isObject=isObject;exports.isString=isString;exports.isSymbol=isSymbol;exports.isTrue=isTrue;exports.isType=isType;exports.isUndefined=isUndefined;
|
|
21
|
-
exports.keys=keys$1;exports.kindLiteral=kindLiteral;exports.kv=kv;exports.kvToDict=kvToDict;exports.less=less;exports.literal=literal;exports.mapValues=mapValues;exports.nameLiteral=nameLiteral;exports.or=or;exports.ruleSet=ruleSet;exports.strArrayToDict=strArrayToDict;exports.type=type;exports.typeApi=typeApi;exports.valuesOfProp=valuesOfProp;exports.withValue=withValue
|
package/dist/es/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class e extends Error{constructor(){super(...arguments);this.kind="BrilliantError"}}var f={exports:{}};let g=()=>{let a=Error.prepareStackTrace;Error.prepareStackTrace=(a,b)=>b;let b=Error().stack.slice(1);Error.prepareStackTrace=a;return b};f.exports=g;f.exports.default=g;var k=f.exports;
|
|
2
|
-
function l(a){return a.map(a=>{let b=(a.getFileName()||"[file unknown]").split("/").slice(-2).join("/"),d=a.getFunctionName()||a.getMethodName()||"unknown";a=a.getLineNumber();return`\t- ${b}, ${d}()${a?`, at line ${a}`:""}`}).join("\n")}
|
|
3
|
-
let m=function(a,b){class c extends e{constructor(c,n,h={}){super(c);this.kind="BrilliantError";this.name=a;this.origin=b;this.classification=n;this.structuredStack=k().slice(1)||[];this.filename=(this.structuredStack[0].getFileName()||"").split("/").slice(-2).join("/");this.line=this.structuredStack[0].getLineNumber();this.fn=this.structuredStack[0].getMethodName()||this.structuredStack[0].getFunctionName();this.message=`${c} [ ${this.classification} ]\n\n${l(this.structuredStack)}`;h.httpStatusCode&&
|
|
4
|
-
(this.httpStatus=h.httpStatusCode)}toJSON(){return{name:this.name,message:this.message,classification:this.classification,origin:this.origin,fn:this.fn,line:this.line,stack:this.structuredStack}}}return c}("InferenceError","inferred-types");function p(a,...b){return 0<b.length?Object.keys(a).filter(a=>!b.includes(a)):Object.keys(a)}var q,r=q||(q={});r["null"]="null";r.string="string";r.number="number";r.bigint="bigint";r.symbol="symbol";r["boolean"]="boolean";r["function"]="function";
|
|
5
|
-
r.undefined="undefined";r.dictionary="dictionary";r.object="object";r.array="array";r.stringArray="string[]";r.numberArray="number[]";r.booleanArray="boolean[]";r.symbolArray="symbol[]";r.functionArray="function[]";r.undefinedArray="undefined[]";r.nullArray="null[]";r.objectArray="object[]";r.dictionaryArray="dictionary[]";
|
|
6
|
-
function t(a){if("object"!==typeof a||null===a)throw Error("Value passed into kv() must be an object");if(null===a)throw Error("Can not run keys() on a null value!");return Object.keys(a).reduce((b,c)=>{let d=a[c];return[...b,{key:c,value:d}]},[])}function u(a,...b){return Object.fromEntries(Object.entries(a).filter(([a])=>!b.includes(a)))}var v,w=v||(v={});w[w.regex=0]="regex";w[w.fn=1]="fn";w[w.exceptions=2]="exceptions";var x,y=x||(x={});y[y.singular=0]="singular";y[y.plural=1]="plural";
|
|
7
|
-
function z(a){return{*[Symbol.iterator](){for(const b of p(a))yield[b,a[b]]}}}function A(){let a=()=>({});return(()=>({set(b,c){b={[b]:c};const d={...a(),...b};a=()=>d;return d},remove(b){const c=a(),d=u(c,b);a=()=>d;return d},done(){return a()}}))()}function B(a){return{required(){return B(a)},optional(){return B(a)},done(){return{__model__:a,__kind__:"model"}}}}
|
|
8
|
-
function C(a,b,c=!1){if(typeof a!==typeof b)return!1;switch(typeof a){case "boolean":case "string":case "number":case "symbol":case "bigint":return c?a===b:!0;case "undefined":return!0;case "function":if(c)throw new m("Use of narrowlyExtends with a function is not possible!","ifTypeOf/not-allowed");return!0;case "object":return null===a&&null===b?!0:p(b).every(d=>C(a[d],b[d],c))}}function D(a){return!0===Array.isArray(a)}function E(a){return"boolean"===typeof a}
|
|
9
|
-
function F(a){return"boolean"===typeof a&&!a}function G(a){return"function"===typeof a}function H(a){return null===a}function I(a){return"number"===typeof a}function J(a){return"object"===typeof a&&null!==a&&!1===Array.isArray(a)}function K(a){return"string"===typeof a}function L(a){return"symbol"===typeof a}function M(a){return"boolean"===typeof a&&a}function N(a){return"undefined"===typeof a}
|
|
10
|
-
let O=()=>({string:{name:"string",type:"",typeGuard:a=>K(a),is:K},boolean:{name:"boolean",type:!0,typeGuard:a=>E(a),is:E},number:{name:"number",type:1,typeGuard:a=>I(a),is:I},function:{name:"function",type:Function,typeGuard:a=>G(a),is:G},null:{name:"null",type:null,typeGuard:a=>null===a,is:H},symbol:{name:"symbol",type:Symbol(),typeGuard:a=>L(a),is:L},undefined:{name:"undefined",type:void 0,typeGuard:a=>N(a),is:N},true:{name:"true",type:!0,typeGuard:a=>M(a),is:M},false:{name:"false",type:!1,typeGuard:a=>
|
|
11
|
-
F(a),is:F},object:{name:"object",type:{},typeGuard:a=>J(a),is:J},array:{name:"array",type:{},typeGuard:a=>D(a),is:J}});function P(a){return"object"===typeof a&&["name","type","is"].every(b=>Object.keys(a).includes(b))}function Q(a){a=a(O());if(!P(a))throw Error(`When using type(), the callback passed in returned an invalid type! Value returned was: ${a}`);return a}function ExplicitFunction(a){return a};
|
|
12
|
-
function FluentConfigurator(a={}){let b=a=>({set(c,n){return b({[c]:n,...a})},done(){return a}});if(a&&"object"!==typeof a)throw Error("The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed.");return a?b(a):b({})};function KeyStorage(){let a=b=>({add:(...c)=>a([...b,...c]),remove:c=>a(b.filter(a=>a!==c)),done:()=>b});return a([])};function MutationIdentity(){return function(a){return a}};
|
|
13
|
-
var and=(a,b)=>({kind:"And",a,b});var api=a=>b=>{const c=()=>b;c.prototype.priv=()=>a;return c};function arrayToKeyLookup(...a){let b={};for(let c of a)b[c]=!0;return b};function arrayToObject(a,b){return c=>!1!==b?c.reduce((b,c)=>({...b,[c[a]]:c}),{}):c.reduce((b,c)=>({...b,[c[a]]:[...b[c[a]]||[],c]}),{})};var condition=(a,b)=>a(b);function createFnWithProps(a,b){for(let c of p(b))a[c]=b[c];return a};function createMutationFunction(a){return b=>b(a)};
|
|
14
|
-
function defineType(a={}){return(b={})=>a?{...b,...a}:b};function dictFilter(a,b){p(a).filter(c=>!b(c,a));return u(a,...p(a).filter(c=>!b(c,a)))};function dictToKv(a){return p(a).map(b=>({key:b,value:a[b]}))};function dictionaryTransform(a,b){let c={};for(let d of t(a))c[d.key]=b(a,d.key);return c};var equals=(a,b)=>({kind:"Equals",field:a,val:b});
|
|
15
|
-
function filterDictArray(a,b){let c=A();return a.filter(a=>{const [d,h]=a;(a=b(d,h))||c.set(d,!0);return a})};var greater=(a,b)=>({kind:"Greater",field:a,val:b});function groupBy(){throw Error("not implemented");};function idLiteral(a){return{...a,id:a.id}};function idTypeGuard(){return!0};var identity=a=>a;var ifTypeOf=a=>({extends:b=>C(a,b,!1)?!0:!1,narrowlyExtends:b=>C(a,b,!0)?!0:!1});
|
|
16
|
-
function isLiteral(...a){return b=>!a.every(a=>b!==a)};function kindLiteral(a){return a};function kv(a,b){return{[a]:b}};function kvToDict(a){let b={};for(let c of a)b[c.key]=c.value;return b};var less=(a,b)=>({kind:"Less",field:a,val:b});function literal(a){return a};
|
|
17
|
-
function mapValues(a,b){return Object.fromEntries([...z(a)].map(([a,d])=>[a,b(d)]))};function nameLiteral(a){return a};var or=(a,b)=>({kind:"Or",a,b});function ruleSet(a){return a};function strArrayToDict(...a){return a.reduce((a,c)=>a={...a,[c]:!0},{})};function valuesOfProp(){};function withValue(a){return b=>{let c=Q(a);return Object.fromEntries([...z(b)].filter(([,a])=>c.typeGuard(a)))}};export{A as Configurator,ExplicitFunction,FluentConfigurator,m as InferenceError,KeyStorage,B as Model,MutationIdentity,and,api,arrayToKeyLookup,arrayToObject,condition,createFnWithProps,createMutationFunction,defineType,dictFilter,dictToKv,dictionaryTransform,z as entries,equals,filterDictArray,greater,groupBy,idLiteral,idTypeGuard,identity,ifTypeOf,D as isArray,E as isBoolean,F as isFalse,G as isFunction,isLiteral,H as isNull,I as isNumber,J as isObject,K as isString,L as isSymbol,M as isTrue,P as isType,N as isUndefined,p as keys,kindLiteral,kv,kvToDict,less,literal,mapValues,nameLiteral,or,ruleSet,strArrayToDict,Q as type,O as typeApi,valuesOfProp,withValue}
|