inferred-types 0.16.1 → 0.18.2

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.
Files changed (191) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/dist/{types/utility/state/KeyStorage.d.ts → index.d.ts} +9780 -8195
  3. package/dist/index.js +687 -0
  4. package/dist/index.mjs +603 -0
  5. package/on-hold/Builder/index.ts +15 -21
  6. package/on-hold/types/index.ts +15 -20
  7. package/package.json +25 -36
  8. package/pnpm-lock.yaml +1680 -3233
  9. package/src/Mutation/index.ts +16 -18
  10. package/src/index.ts +15 -19
  11. package/src/shared/index.ts +16 -18
  12. package/src/types/Not.ts +3 -1
  13. package/src/types/Transformer.ts +1 -2
  14. package/src/types/Where.ts +36 -0
  15. package/src/types/alphabetic/PascalCase.ts +5 -4
  16. package/src/types/alphabetic/index.ts +16 -20
  17. package/src/types/dictionary/index.ts +16 -18
  18. package/src/types/{fluent.ts → fluent/fluent.ts} +8 -9
  19. package/src/types/fluent/index.ts +35 -0
  20. package/src/types/index.ts +18 -22
  21. package/src/types/kv/index.ts +16 -18
  22. package/src/types/lists/index.ts +16 -18
  23. package/src/types/ruleset-types.ts +1 -1
  24. package/src/types/string-literals/index.ts +16 -18
  25. package/src/types/tuples/index.ts +16 -18
  26. package/src/types/{SameKeys.ts → type-conversion/SameKeys.ts} +0 -0
  27. package/src/types/type-conversion/WrapValue.ts +15 -0
  28. package/src/types/type-conversion/index.ts +18 -18
  29. package/src/utility/api/index.ts +16 -18
  30. package/src/utility/dictionary/index.ts +16 -20
  31. package/src/utility/dictionary/kv/index.ts +16 -18
  32. package/src/utility/index.ts +16 -20
  33. package/src/utility/lists/index.ts +16 -18
  34. package/src/utility/literals/index.ts +16 -18
  35. package/src/utility/map-reduce/index.ts +16 -18
  36. package/src/utility/modelling/index.ts +16 -18
  37. package/src/utility/runtime/conditions/index.ts +16 -18
  38. package/src/utility/runtime/ifTypeOf.ts +1 -5
  39. package/src/utility/runtime/index.ts +16 -20
  40. package/src/utility/state/index.ts +16 -18
  41. package/tests/Where.spec.ts +39 -0
  42. package/tests/data/index.ts +9 -14
  43. package/tests/kv/dict-to-kv-and-back.spec.ts +6 -2
  44. package/tsconfig.json +4 -3
  45. package/dist/cjs/index.js +0 -1
  46. package/dist/es/index.js +0 -1
  47. package/dist/tsconfig.tsbuildinfo +0 -1
  48. package/dist/types/Mutation/MutationFunction.d.ts +0 -16
  49. package/dist/types/Mutation/MutationIdentity.d.ts +0 -30
  50. package/dist/types/Mutation/index.d.ts +0 -2
  51. package/dist/types/errors/InferenceError.d.ts +0 -1
  52. package/dist/types/errors/index.d.ts +0 -1
  53. package/dist/types/index.d.ts +0 -4
  54. package/dist/types/shared/index.d.ts +0 -3
  55. package/dist/types/shared/randomString.d.ts +0 -1
  56. package/dist/types/shared/uuid.d.ts +0 -1
  57. package/dist/types/shared/valueTypes.d.ts +0 -27
  58. package/dist/types/types/Api.d.ts +0 -10
  59. package/dist/types/types/Constructor.d.ts +0 -5
  60. package/dist/types/types/EnumValues.d.ts +0 -14
  61. package/dist/types/types/ExpandRecursively.d.ts +0 -3
  62. package/dist/types/types/First.d.ts +0 -4
  63. package/dist/types/types/FunctionType.d.ts +0 -9
  64. package/dist/types/types/If.d.ts +0 -10
  65. package/dist/types/types/Include.d.ts +0 -16
  66. package/dist/types/types/Includes.d.ts +0 -5
  67. package/dist/types/types/KeyedRecord.d.ts +0 -22
  68. package/dist/types/types/Keys.d.ts +0 -17
  69. package/dist/types/types/Length.d.ts +0 -8
  70. package/dist/types/types/Mutable.d.ts +0 -6
  71. package/dist/types/types/Narrowable.d.ts +0 -5
  72. package/dist/types/types/Not.d.ts +0 -11
  73. package/dist/types/types/Numeric.d.ts +0 -14
  74. package/dist/types/types/Opaque.d.ts +0 -12
  75. package/dist/types/types/Retain.d.ts +0 -16
  76. package/dist/types/types/SameKeys.d.ts +0 -11
  77. package/dist/types/types/Transformer.d.ts +0 -11
  78. package/dist/types/types/TypeGuard.d.ts +0 -7
  79. package/dist/types/types/alphabetic/AllCaps.d.ts +0 -12
  80. package/dist/types/types/alphabetic/CamelCase.d.ts +0 -2
  81. package/dist/types/types/alphabetic/CapFirstAlpha.d.ts +0 -13
  82. package/dist/types/types/alphabetic/CapitalizeWords.d.ts +0 -4
  83. package/dist/types/types/alphabetic/DashToSnake.d.ts +0 -1
  84. package/dist/types/types/alphabetic/DashUppercase.d.ts +0 -14
  85. package/dist/types/types/alphabetic/Dasherize.d.ts +0 -15
  86. package/dist/types/types/alphabetic/HasUppercase.d.ts +0 -13
  87. package/dist/types/types/alphabetic/Intrinsic.d.ts +0 -4
  88. package/dist/types/types/alphabetic/IsCapitalized.d.ts +0 -15
  89. package/dist/types/types/alphabetic/KebabCase.d.ts +0 -12
  90. package/dist/types/types/alphabetic/LowerAllCaps.d.ts +0 -4
  91. package/dist/types/types/alphabetic/PascalCase.d.ts +0 -16
  92. package/dist/types/types/alphabetic/Pluralize.d.ts +0 -36
  93. package/dist/types/types/alphabetic/SnakeCase.d.ts +0 -14
  94. package/dist/types/types/alphabetic/alpha-characters.d.ts +0 -36
  95. package/dist/types/types/alphabetic/index.d.ts +0 -16
  96. package/dist/types/types/append-types.d.ts +0 -9
  97. package/dist/types/types/dictionary/Get.d.ts +0 -7
  98. package/dist/types/types/dictionary/index.d.ts +0 -1
  99. package/dist/types/types/fluent.d.ts +0 -51
  100. package/dist/types/types/index.d.ts +0 -35
  101. package/dist/types/types/kv/DictFromKv.d.ts +0 -6
  102. package/dist/types/types/kv/KeyValue.d.ts +0 -11
  103. package/dist/types/types/kv/KvFrom.d.ts +0 -13
  104. package/dist/types/types/kv/KvTuple.d.ts +0 -14
  105. package/dist/types/types/kv/index.d.ts +0 -4
  106. package/dist/types/types/lists/UniqueForProp.d.ts +0 -14
  107. package/dist/types/types/lists/index.d.ts +0 -1
  108. package/dist/types/types/maybe.d.ts +0 -8
  109. package/dist/types/types/props.d.ts +0 -100
  110. package/dist/types/types/ruleset-types.d.ts +0 -59
  111. package/dist/types/types/runtime.d.ts +0 -33
  112. package/dist/types/types/string-literals/Break.d.ts +0 -12
  113. package/dist/types/types/string-literals/Concat.d.ts +0 -8
  114. package/dist/types/types/string-literals/LeftWhitespace.d.ts +0 -9
  115. package/dist/types/types/string-literals/Replace.d.ts +0 -11
  116. package/dist/types/types/string-literals/RightWhitespace.d.ts +0 -9
  117. package/dist/types/types/string-literals/StringLength.d.ts +0 -10
  118. package/dist/types/types/string-literals/Trim.d.ts +0 -11
  119. package/dist/types/types/string-literals/TrimLeft.d.ts +0 -11
  120. package/dist/types/types/string-literals/TrimRight.d.ts +0 -11
  121. package/dist/types/types/string-literals/form-fields.d.ts +0 -12
  122. package/dist/types/types/string-literals/index.d.ts +0 -10
  123. package/dist/types/types/tuples/DictArray.d.ts +0 -19
  124. package/dist/types/types/tuples/FirstKey.d.ts +0 -8
  125. package/dist/types/types/tuples/FirstKeyValue.d.ts +0 -8
  126. package/dist/types/types/tuples/FirstOfEach.d.ts +0 -11
  127. package/dist/types/types/tuples/FromDictArray.d.ts +0 -10
  128. package/dist/types/types/tuples/SecondOfEach.d.ts +0 -10
  129. package/dist/types/types/tuples/index.d.ts +0 -6
  130. package/dist/types/types/type-conversion/TupleToUnion.d.ts +0 -10
  131. package/dist/types/types/type-conversion/UnionToIntersection.d.ts +0 -5
  132. package/dist/types/types/type-conversion/UnionToTuple.d.ts +0 -9
  133. package/dist/types/types/type-conversion/index.d.ts +0 -3
  134. package/dist/types/types/type-testing.d.ts +0 -13
  135. package/dist/types/utility/api/api.d.ts +0 -2
  136. package/dist/types/utility/api/index.d.ts +0 -1
  137. package/dist/types/utility/createFnWithProps.d.ts +0 -1
  138. package/dist/types/utility/dictionary/arrayToKeyLookup.d.ts +0 -9
  139. package/dist/types/utility/dictionary/dictFilter.d.ts +0 -8
  140. package/dist/types/utility/dictionary/dictionaryTransform.d.ts +0 -9
  141. package/dist/types/utility/dictionary/entries.d.ts +0 -17
  142. package/dist/types/utility/dictionary/index.d.ts +0 -8
  143. package/dist/types/utility/dictionary/kv/dictToKv.d.ts +0 -16
  144. package/dist/types/utility/dictionary/kv/filterDictArray.d.ts +0 -9
  145. package/dist/types/utility/dictionary/kv/index.d.ts +0 -4
  146. package/dist/types/utility/dictionary/kv/kv.d.ts +0 -10
  147. package/dist/types/utility/dictionary/kv/kvToDict.d.ts +0 -15
  148. package/dist/types/utility/dictionary/mapValues.d.ts +0 -13
  149. package/dist/types/utility/dictionary/strArrayToDict.d.ts +0 -6
  150. package/dist/types/utility/dictionary/valuesOfProp.d.ts +0 -1
  151. package/dist/types/utility/index.d.ts +0 -11
  152. package/dist/types/utility/keys.d.ts +0 -5
  153. package/dist/types/utility/lists/groupBy.d.ts +0 -12
  154. package/dist/types/utility/lists/index.d.ts +0 -1
  155. package/dist/types/utility/literals/ExplicitFunction.d.ts +0 -6
  156. package/dist/types/utility/literals/arrayToObject.d.ts +0 -41
  157. package/dist/types/utility/literals/defineType.d.ts +0 -8
  158. package/dist/types/utility/literals/identity.d.ts +0 -6
  159. package/dist/types/utility/literals/index.d.ts +0 -5
  160. package/dist/types/utility/literals/literal.d.ts +0 -41
  161. package/dist/types/utility/map-reduce/filter.d.ts +0 -26
  162. package/dist/types/utility/map-reduce/index.d.ts +0 -1
  163. package/dist/types/utility/modelling/Model.d.ts +0 -22
  164. package/dist/types/utility/modelling/index.d.ts +0 -1
  165. package/dist/types/utility/ruleset.d.ts +0 -18
  166. package/dist/types/utility/runtime/condition.d.ts +0 -3
  167. package/dist/types/utility/runtime/conditions/index.d.ts +0 -12
  168. package/dist/types/utility/runtime/conditions/isArray.d.ts +0 -2
  169. package/dist/types/utility/runtime/conditions/isBoolean.d.ts +0 -5
  170. package/dist/types/utility/runtime/conditions/isFalse.d.ts +0 -4
  171. package/dist/types/utility/runtime/conditions/isFunction.d.ts +0 -15
  172. package/dist/types/utility/runtime/conditions/isLiteral.d.ts +0 -2
  173. package/dist/types/utility/runtime/conditions/isNull.d.ts +0 -1
  174. package/dist/types/utility/runtime/conditions/isNumber.d.ts +0 -1
  175. package/dist/types/utility/runtime/conditions/isObject.d.ts +0 -10
  176. package/dist/types/utility/runtime/conditions/isString.d.ts +0 -2
  177. package/dist/types/utility/runtime/conditions/isSymbol.d.ts +0 -1
  178. package/dist/types/utility/runtime/conditions/isTrue.d.ts +0 -20
  179. package/dist/types/utility/runtime/conditions/isUndefined.d.ts +0 -1
  180. package/dist/types/utility/runtime/ifTypeOf.d.ts +0 -23
  181. package/dist/types/utility/runtime/index.d.ts +0 -5
  182. package/dist/types/utility/runtime/type.d.ts +0 -27
  183. package/dist/types/utility/runtime/withValue.d.ts +0 -19
  184. package/dist/types/utility/state/Configurator.d.ts +0 -36
  185. package/dist/types/utility/state/FluentConfigurator.d.ts +0 -27
  186. package/dist/types/utility/state/index.d.ts +0 -3
  187. package/src/errors/InferenceError.ts +0 -3
  188. package/src/errors/index.ts +0 -37
  189. package/src/types/alphabetic/Intrinsic.ts +0 -6
  190. package/tests/FluentApi-spec.ts +0 -90
  191. package/tests/FluentConfigurator-spec.hold +0 -88
@@ -1,5 +0,0 @@
1
- export * from "./ExplicitFunction";
2
- export * from "./arrayToObject";
3
- export * from "./defineType";
4
- export * from "./identity";
5
- export * from "./literal";
@@ -1,41 +0,0 @@
1
- import { Narrowable } from "../../types";
2
- /**
3
- * Takes an object as input --which has an `id` property and returns it as the same
4
- * run-time content but with the _type_ of the `id` property being forced to a literal type
5
- */
6
- export declare function idLiteral<T extends {
7
- id: I;
8
- }, I extends PropertyKey>(o: T): T & {
9
- id: T["id"];
10
- };
11
- /**
12
- * Takes an object as input --which has an `name` property and returns it as the same
13
- * run-time content but with the _type_ of the `name` property being forced to a literal type
14
- */
15
- export declare function nameLiteral<T extends {
16
- name: I;
17
- }, I extends PropertyKey>(o: T): T & {
18
- name: T["name"];
19
- };
20
- /**
21
- * Takes an object as input --which has an `kind` property and returns it as the same
22
- * run-time content but with the _type_ of the `kind` property being forced to a literal type
23
- */
24
- export declare function kindLiteral<T extends {
25
- kind: I;
26
- }, I extends PropertyKey>(o: T): T & {
27
- kind: T["kind"];
28
- };
29
- export declare function idTypeGuard<T extends {
30
- id: I;
31
- }, I extends PropertyKey>(_o: T): _o is T & {
32
- id: I;
33
- };
34
- /**
35
- * Takes an object as input and infers the narrow literal types of the property
36
- * values on the object.
37
- *
38
- * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
39
- * > Hopefully at some point this will be addressed in the language.
40
- */
41
- export declare function literal<N extends Narrowable, T extends Record<keyof T, N>>(obj: T): T;
@@ -1,26 +0,0 @@
1
- export declare type Filter<A> = {
2
- kind: "Equals";
3
- field: keyof A;
4
- val: A[keyof A];
5
- } | {
6
- kind: "Greater";
7
- field: keyof A;
8
- val: A[keyof A];
9
- } | {
10
- kind: "Less";
11
- field: keyof A;
12
- val: A[keyof A];
13
- } | {
14
- kind: "And";
15
- a: Filter<A>;
16
- b: Filter<A>;
17
- } | {
18
- kind: "Or";
19
- a: Filter<A>;
20
- b: Filter<A>;
21
- };
22
- export declare const equals: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
23
- export declare const greater: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
24
- export declare const less: <A, K extends keyof A>(field: K, val: A[K]) => Filter<A>;
25
- export declare const and: <A>(a: Filter<A>, b: Filter<A>) => Filter<A>;
26
- export declare const or: <A>(a: Filter<A>, b: Filter<A>) => Filter<A>;
@@ -1 +0,0 @@
1
- export * from "./filter";
@@ -1,22 +0,0 @@
1
- export declare function Model<N extends string, _R extends {} = {}, _O extends {} = {}>(name: N): {
2
- required<P extends string>(_prop: P): {
3
- required<P_1 extends string>(_prop: P_1): any;
4
- optional<P_2 extends string>(_prop: P_2): any;
5
- done(): {
6
- __model__: N;
7
- __kind__: "model";
8
- };
9
- };
10
- optional<P_3 extends string>(_prop: P_3): {
11
- required<P_1 extends string>(_prop: P_1): any;
12
- optional<P_2 extends string>(_prop: P_2): any;
13
- done(): {
14
- __model__: N;
15
- __kind__: "model";
16
- };
17
- };
18
- done(): {
19
- __model__: N;
20
- __kind__: "model";
21
- };
22
- };
@@ -1 +0,0 @@
1
- export * from "./Model";
@@ -1,18 +0,0 @@
1
- import type { Narrowable } from "../types";
2
- /**
3
- * **ruleSet**
4
- *
5
- * Defines a ruleset composed of _dynamic_ and _static_ boolean operators.
6
- *
7
- * - the first function call defines _dynamic_ props (_optional_)
8
- * - the second function call defines static values
9
- *
10
- * ```ts
11
- * const rs = ruleSet(
12
- * r => r.state()( { maybe: r => r.extends({ foo: 1 }) })
13
- * )(
14
- * { color: true, age: false }
15
- * );
16
- * ```
17
- */
18
- export declare function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(defn?: TState): TState | undefined;
@@ -1,3 +0,0 @@
1
- import { Narrowable } from "../../types";
2
- export declare type Condition<TInput extends Narrowable, TResult extends boolean> = (input: TInput) => TResult;
3
- export declare const condition: <TInput extends Narrowable, C extends Condition<Narrowable, boolean>>(c: C, input: TInput) => boolean;
@@ -1,12 +0,0 @@
1
- export * from "./isArray";
2
- export * from "./isBoolean";
3
- export * from "./isFalse";
4
- export * from "./isFunction";
5
- export * from "./isLiteral";
6
- export * from "./isNull";
7
- export * from "./isNumber";
8
- export * from "./isObject";
9
- export * from "./isString";
10
- export * from "./isSymbol";
11
- export * from "./isTrue";
12
- export * from "./isUndefined";
@@ -1,2 +0,0 @@
1
- export declare type IsArray<T> = T extends any[] ? true : false;
2
- export declare function isArray<T>(i: T): IsArray<T>;
@@ -1,5 +0,0 @@
1
- export declare type IsBoolean<T> = T extends boolean ? true : false;
2
- /**
3
- * Runtime and type checks whether a variable is a boolean value.
4
- */
5
- export declare function isBoolean<T extends any>(i: T): IsBoolean<T>;
@@ -1,4 +0,0 @@
1
- import { Narrowable } from "../../../types";
2
- import { IsBoolean } from "../..";
3
- export declare type IsFalse<T extends Narrowable> = IsBoolean<T> extends true ? T extends false ? true : true extends T ? false : unknown : false;
4
- export declare function isFalse<T>(i: T): IsFalse<T>;
@@ -1,15 +0,0 @@
1
- import { FunctionType } from "../../../types";
2
- export declare type IsFunction<T> = T extends FunctionType ? true : false;
3
- /**
4
- * Checks whether a passed in value is a function and ensures run-time and types
5
- * are consistent.
6
- * ```ts
7
- * // true
8
- * const yup = isFunction(() => "hello world");
9
- * ```
10
- *
11
- * Note: the runtime `typeof [variable]` will correctly say "function" when a function is
12
- * encounted but if that function also has object types defined then the type will be a big
13
- * and ugly union type. This function will give you a proper boolean value in both cases.
14
- */
15
- export declare function isFunction<T extends unknown>(input: T): IsFunction<T>;
@@ -1,2 +0,0 @@
1
- export declare type IsLiteral<L extends string | number, T extends any> = T extends L ? true : false;
2
- export declare function isLiteral<L extends Readonly<string>>(...allowed: L[]): <T extends unknown>(i: T) => IsLiteral<L, T>;
@@ -1 +0,0 @@
1
- export declare function isNull<T>(i: T): T extends null ? true : false;
@@ -1 +0,0 @@
1
- export declare function isNumber<T>(i: T): T extends number ? true : false;
@@ -1,10 +0,0 @@
1
- import { FunctionType, Mutable, Narrowable, Not } from "../../../types";
2
- export declare type IsObject<T> = Mutable<T> extends Record<string, any> ? T extends FunctionType ? false : Mutable<T> extends any[] ? false : true : false;
3
- export declare type ObjectType = Not<Record<string, Narrowable>, FunctionType>;
4
- /**
5
- * Detects whether the passed in `v` is of type "object" where an object
6
- * is defined to be a string keyed dictionary style object. This means that
7
- * arrays are excluded, as well as functions which also have properties hanging
8
- * off of them.
9
- */
10
- export declare function isObject<T extends unknown>(i: T): IsObject<T>;
@@ -1,2 +0,0 @@
1
- export declare type IsString<T> = T extends string ? true : false;
2
- export declare function isString<T>(i: T): IsString<T>;
@@ -1 +0,0 @@
1
- export declare function isSymbol<T>(i: T): T extends symbol ? true : false;
@@ -1,20 +0,0 @@
1
- import { Narrowable } from "../../../types";
2
- import type { IsBoolean } from "./isBoolean";
3
- /**
4
- * Type utility which returns `true` or `false` based on
5
- * whether the type holds the narrow "true" type.
6
- * ```ts
7
- * // true
8
- * type T = IsTrue<true>;
9
- * // unknown
10
- * type U = IsTrue<boolean>;
11
- * // false
12
- * type F = IsTrue<false>;
13
- * type F2 = IsTrue<"false">;
14
- * ```
15
- */
16
- export declare type IsTrue<T> = IsBoolean<T> extends true ? T extends true ? true : T extends false ? false : unknown : false;
17
- /**
18
- * Run-time and type checking of whether a variable is `true`.
19
- */
20
- export declare function isTrue<T extends Narrowable>(i: T): IsTrue<T>;
@@ -1 +0,0 @@
1
- export declare function isUndefined<T>(i: T): undefined extends T ? true : false;
@@ -1,23 +0,0 @@
1
- import { Narrowable } from "../../types/Narrowable";
2
- /**
3
- * A conditional clause used in the application of the `ifTypeOf` utility
4
- */
5
- export declare type ExtendsClause<N extends Narrowable, TValue extends Record<keyof TValue, N> | number | string | boolean | symbol> = <TBase extends any>(base: TBase) => TValue extends TBase ? true : false;
6
- /**
7
- * A conditional clause used in the application of the `ifTypeOf` utility
8
- */
9
- export declare type ExtendsNarrowlyClause<N extends Narrowable, TValue extends Record<keyof TValue, N> | number | string | boolean | symbol> = <NB extends Narrowable, TBase extends Record<keyof TBase, NB> | number | string | boolean | symbol>(base: TBase) => TValue extends TBase ? true : false;
10
- /**
11
- * **TypeCondition**
12
- *
13
- * A partially applied type from the `ifTypeOf` utility where the base type has been
14
- * defined and we now need to express the type which is intended to extend it.
15
- *
16
- * - `extends` - compares with _wide_ types
17
- * - `narrowlyExtends` - compares with _narrow_ / _literal_ types
18
- */
19
- export declare type TypeCondition<N extends Narrowable, TValue extends Record<keyof TValue, N> | number | string | boolean | symbol> = {
20
- extends: ExtendsClause<N, TValue>;
21
- narrowlyExtends: ExtendsNarrowlyClause<N, TValue>;
22
- };
23
- export declare const ifTypeOf: <N extends Narrowable, TValue extends string | number | boolean | symbol | Record<keyof TValue, N>>(val: TValue) => TypeCondition<N, TValue>;
@@ -1,5 +0,0 @@
1
- export * from "./condition";
2
- export * from "./ifTypeOf";
3
- export * from "./type";
4
- export * from "./withValue";
5
- export * from "./conditions/index";
@@ -1,27 +0,0 @@
1
- import { Narrowable, TypeGuard } from "../../types";
2
- import { isString, isBoolean, isNumber, isFunction, isSymbol, isNull, isTrue, isFalse, isUndefined, isObject, isArray } from "./conditions";
3
- export declare type Type<T extends any, V extends Function> = {
4
- name: string;
5
- type: T;
6
- typeGuard: TypeGuard<T>;
7
- is: V;
8
- };
9
- export declare const typeApi: () => {
10
- readonly string: Type<string, typeof isString>;
11
- readonly boolean: Type<boolean, typeof isBoolean>;
12
- readonly number: Type<number, typeof isNumber>;
13
- readonly function: Type<Function | (Function & {
14
- [key: string]: any;
15
- }), typeof isFunction>;
16
- readonly null: Type<null, typeof isNull>;
17
- readonly symbol: Type<symbol, typeof isSymbol>;
18
- readonly undefined: Type<undefined, typeof isUndefined>;
19
- readonly true: Type<true, typeof isTrue>;
20
- readonly false: Type<false, typeof isFalse>;
21
- readonly object: Type<Record<string, Narrowable>, typeof isObject>;
22
- readonly array: Type<any[], typeof isArray>;
23
- };
24
- export declare type TypeApi = ReturnType<typeof typeApi>;
25
- export declare function isType<T extends any, V extends Function>(t: unknown): t is Type<T, V>;
26
- export declare type TypeDefinition<T extends any, V extends Function> = (defn: TypeApi) => Type<T, V>;
27
- export declare function type<T extends any, V extends Function>(fn: TypeDefinition<T, V>): Type<T, V>;
@@ -1,19 +0,0 @@
1
- import { ExpandRecursively, Narrowable } from "../../types";
2
- import { TypeDefinition } from "./";
3
- /**
4
- * **withValue**
5
- *
6
- * Reduces a dictionary object -- in both _type_ and _run-time_ structure -- to only those
7
- * key/value pairs which have a specified value. For instance:
8
- *
9
- * ```ts
10
- * const obj = { foo: 1, bar: 2, message: "hi there" };
11
- * // { message: "hi there" }
12
- * const onlyStrings = withValue(t => t.string)(obj);
13
- * // { foo: 1 }
14
- * const justOne = withValue(t => t.literal(1))(obj);
15
- * ```
16
- *
17
- * Note: _often useful to provide run-time type profiles with the_ `inferredType` _utility_
18
- */
19
- export declare function withValue<T extends any, V extends Function>(td: TypeDefinition<T, V>): <N extends Narrowable, R extends Record<string, N>>(obj: R) => ExpandRecursively<Pick<R, import("../../types").KeysWithValue<T, R>>>;
@@ -1,36 +0,0 @@
1
- import { ExpandRecursively } from "../../types";
2
- export interface IConfigurator<C = {}> {
3
- set<V, K extends string, KV = {
4
- [U in K]: V;
5
- }>(key: K, value: V): asserts this is IConfigurator<ExpandRecursively<C & KV>>;
6
- remove<K extends string & keyof C>(key: K): asserts this is IConfigurator<ExpandRecursively<Omit<C, K>>>;
7
- done(): C;
8
- }
9
- /**
10
- * **Configurator**
11
- *
12
- * This function provides a configurator which uses TypeScript assertions
13
- * to narrow the scope of variables. Using type assertions though means we
14
- * can't also return values and therefore a _fluent_ API style is not possible.
15
- *
16
- * Note: this approach does require, that you explicitly use the `IConfigurator`
17
- * interface exported by this library. Without it you'd getting annoying TS errors
18
- * on every call to `set()` but adding it is simple enough:
19
- *
20
- * ```ts
21
- * import { Configurator, IConfigurator } from "inferred-types";
22
- * const config: IConfigurator = Configurator();
23
- * ```
24
- *
25
- * If you want to specify some guideline params which you expect to be set, you
26
- * can add them like so:
27
- *
28
- * ```ts
29
- * export type IExpected = { foo: number, bar: string };
30
- * const config: IConfigurator<IExpected> = Configurator<IExpected>();
31
- * ```
32
- *
33
- * This configuration will ensure that `foo` and `bar` will be seen as optional
34
- * parameters. If you set them they will stop being optional.
35
- */
36
- export declare function Configurator(): IConfigurator<{}>;
@@ -1,27 +0,0 @@
1
- import type { ExpandRecursively } from "../../types";
2
- export interface IFluentConfigurator<C> {
3
- /**
4
- * **set**
5
- *
6
- * Sets a new key/value pair to the configurator.
7
- *
8
- * @param key the key to put this new configuration item
9
- * @param value the value of the configuration item
10
- */
11
- set<V, K extends string, KV = {
12
- [U in K]: V;
13
- }>(key: K, value: V): IFluentConfigurator<C & KV>;
14
- done(): ExpandRecursively<C>;
15
- }
16
- /**
17
- * This function will return a basic _configurator_ API surface which allows
18
- * you to add name/value pairs to a growing dictionary of strongly typed data.
19
- *
20
- * When configuration is complete, you call the `done()` endpoint and the typed
21
- * configuration will be returned with the API removed.
22
- *
23
- * > **Note:** the approach taken here requires that you configure using a **fluent style**
24
- * exclusively. If you don't the non-fluent properties set will not show up
25
- * in the typing or the run-time object.
26
- */
27
- export declare function FluentConfigurator<I>(initial?: I): IFluentConfigurator<{}>;
@@ -1,3 +0,0 @@
1
- export * from "./Configurator";
2
- export * from "./FluentConfigurator";
3
- export * from "./KeyStorage";
@@ -1,3 +0,0 @@
1
- import { createError } from "brilliant-errors";
2
-
3
- export const [InferenceError, isInferenceError] = createError("InferenceError", "inferred-types")()()()();
@@ -1,37 +0,0 @@
1
- // #autoindex
2
- // #region autoindexed files
3
-
4
- // index last changed at: 6th Jun, 2021, 07:11 PM ( GMT-7 )
5
- // export: named; exclusions: index, private.
6
- // files: InferenceError.
7
-
8
- // local file exports
9
- export * from "./InferenceError";
10
-
11
- // Note:
12
- // -----
13
- // This file was created by running: "dd devops autoindex"; it assumes you have
14
- // the 'do-devops' pkg 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
- // Also be aware that all of your content outside the defined region in this file
34
- // will be preserved in situations where you need to do something paricularly awesome.
35
- // Keep on being awesome.
36
-
37
- // #endregion
@@ -1,6 +0,0 @@
1
- /* eslint @typescript-eslint/no-unused-vars: "off" */
2
-
3
- export type Capitalize<T> = intrinsic;
4
- export type Uncapitalize<T> = intrinsic;
5
- export type Uppercase<T> = intrinsic;
6
- export type Lowercase<T> = intrinsic;
@@ -1,90 +0,0 @@
1
- import type { Expect, Equal, ExpectExtends, ExpectFalse } from "@type-challenges/utils";
2
- import { FluentApi, Keys } from "~/types";
3
-
4
- const escape = {
5
- hi: () => "hello",
6
- };
7
- const fluent = {
8
- foo: () => ({ ...fluent, ...escape }),
9
- bar: () => ({ ...fluent, ...escape }),
10
- };
11
- const fluentSolo = {
12
- foo: () => fluentSolo,
13
- bar: () => fluentSolo,
14
- };
15
-
16
- describe("FluentApi type", () => {
17
- it("Fluent API without escape API can be used as FluentAPI", () => {
18
- const api: FluentApi<typeof fluentSolo> = fluentSolo;
19
- type Api = typeof api;
20
-
21
- type cases = [
22
- // Api extends the type FluentApi
23
- Expect<ExpectExtends<FluentApi<any, any, any>, Api>>,
24
- // the fluent API keys are found on API
25
- Expect<ExpectExtends<Keys<Api>, "foo" | "bar">>,
26
- // the fluent API returns itself
27
- Expect<Equal<Api, ReturnType<Api["bar"]>>>,
28
- Expect<Equal<Api, ReturnType<Api["foo"]>>>
29
- ];
30
- const cases: cases = [true, true, true, true];
31
- expect(cases).toBe(cases);
32
- });
33
-
34
- it("Simple fluent API and escape API are combined", () => {
35
- const api: FluentApi<typeof fluent, typeof escape> = { ...fluent, ...escape };
36
- type Api = typeof api;
37
-
38
- type cases = [
39
- // Api extends the type FluentApi
40
- Expect<ExpectExtends<FluentApi<any, any, any>, Api>>,
41
- // the fluent and escape api keys are found on API
42
- Expect<ExpectExtends<Keys<Api>, "foo" | "bar" | "hi">>,
43
- // the fluent API returns itself
44
- Expect<Equal<Api, ReturnType<Api["bar"]>>>,
45
- Expect<Equal<Api, ReturnType<Api["foo"]>>>,
46
- // whereas the escape API just returns a string
47
- Expect<Equal<string, ReturnType<Api["hi"]>>>
48
- ];
49
- const cases: cases = [true, true, true, true, true];
50
- expect(cases).toBe(cases);
51
- });
52
-
53
- it("Exclusion masks certain API endpoints", () => {
54
- const api1: FluentApi<typeof fluent, typeof escape, "hi"> = { ...fluent, ...escape };
55
- type Api1 = typeof api1;
56
- const api2: FluentApi<typeof fluent, typeof escape, "foo" | "bar"> = { ...fluent, ...escape };
57
- type Api2 = typeof api2;
58
-
59
- type cases = [
60
- // excluding "hi" hides the escape api but leaves fluent API untouched
61
- Expect<ExpectExtends<"foo" | "bar", Keys<Api1>>>,
62
- ExpectFalse<ExpectExtends<"hi", Keys<Api1>>>,
63
- // similarly hiding "foo" and "bar" leaves the escape API untouched
64
- Expect<ExpectExtends<"hi", Keys<Api2>>>,
65
- ExpectFalse<ExpectExtends<"foo" | "bar", Keys<Api2>>>
66
- ];
67
-
68
- const cases: cases = [true, false, true, false];
69
- expect(cases).toBe(cases);
70
- });
71
-
72
- it("applying different FluentApi exclusions to the same runtime API modifies the API appropriately", () => {
73
- const api1: FluentApi<typeof fluent, typeof escape, "hi"> = { ...fluent, ...escape };
74
- type Api1 = typeof api1;
75
- const api2: FluentApi<typeof fluent, typeof escape, "foo" | "bar"> = api1 as any;
76
- type Api2 = typeof api2;
77
-
78
- type cases = [
79
- // excluding "hi" hides the escape api but leaves fluent API untouched
80
- Expect<ExpectExtends<"foo" | "bar", Keys<Api1>>>,
81
- ExpectFalse<ExpectExtends<"hi", Keys<Api1>>>,
82
- // similarly hiding "foo" and "bar" leaves the escape API untouched
83
- Expect<ExpectExtends<"hi", Keys<Api2>>>,
84
- ExpectFalse<ExpectExtends<"foo" | "bar", Keys<Api2>>>
85
- ];
86
-
87
- const cases: cases = [true, false, true, false];
88
- expect(cases).toBe(cases);
89
- });
90
- });
@@ -1,88 +0,0 @@
1
- import { FluentConfigurator, keys } from "../src";
2
- import { mySong, Playlist, Song } from "./data/index";
3
- import { SimpleTable } from "./data/SimpleTable";
4
-
5
- describe("Configurator => ", () => {
6
- it("Call to configurator returns API", () => {
7
- const c = FluentConfigurator();
8
- expect(typeof c.done).toBe("function");
9
- expect(typeof c.done()).toBe("object");
10
- expect(Object.keys(c.done())).toHaveLength(0);
11
- });
12
-
13
- it("Configurator with empty initial state, can have props added using set() and fluent API style", () => {
14
- const c = FluentConfigurator().set("a", 5).set("b", "foobar").done();
15
- expect(c).toHaveProperty("a");
16
- expect(typeof c.a).toBe("number");
17
- expect(c).toHaveProperty("b");
18
- expect(typeof c.b).toBe("string");
19
- });
20
-
21
- it("Configurator with starting state, can have props added using fluent API style", () => {
22
- const start = { foo: "bar", bar: "baz" };
23
- const c = FluentConfigurator(start).set("b", "foobar").set("a", 5).done();
24
- console.log(keys(c));
25
-
26
-
27
- // added state
28
- expect(c).toHaveProperty("a", 5);
29
- expect(typeof c.a).toBe("number");
30
- expect(c).toHaveProperty("b", "foobar");
31
- expect(typeof c.b).toBe("string");
32
-
33
- // starting state
34
- expect(c).toHaveProperty("foo");
35
- // TODO: need to ensure initial state is available to type system
36
- // expect(typeof c.foo).toBe("string");
37
- // expect(c.foo).toBe(start.foo);
38
- expect(c).toHaveProperty("bar");
39
- // expect(typeof c.bar).toBe("string");
40
- // expect(c.bar).toBe(start.bar);
41
- });
42
-
43
- it("Configurator stores Table objects and keeps the typing", () => {
44
- const c = FluentConfigurator()
45
- .set("songs", SimpleTable(Song))
46
- .set("playlists", SimpleTable(Playlist))
47
- .done();
48
- // structure
49
- expect(c).toHaveProperty("songs");
50
- expect(c.songs).toHaveProperty("is");
51
- expect(c.songs).toHaveProperty("select");
52
- expect(c).toHaveProperty("playlists");
53
- expect(c.playlists).toHaveProperty("is");
54
- expect(c.playlists).toHaveProperty("select");
55
- // type guards
56
- // TODO: get back to working types
57
- expect((c.songs as any).is(mySong)).toBe(true);
58
- expect((c.songs as any).is({ foo: false })).toBe(false);
59
- });
60
-
61
- it("set() function is able to set a simple value and have type retained", () => {
62
- const c = FluentConfigurator()
63
- .set("songs", SimpleTable(Song))
64
- .set("playlists", SimpleTable(Playlist))
65
- .set("foo", 15)
66
- .set("bar", 1);
67
- const t = c.done();
68
- // TODO: get back to working types
69
- expect((t.songs as any).is(mySong)).toBe(true);
70
- expect((t.songs as any).is({ foo: false })).toBe(false);
71
- expect(typeof t.songs).toBe("object");
72
- expect(typeof t.playlists).toBe("object");
73
- expect(typeof t.foo).toBe("number");
74
- expect(typeof t.bar).toBe("number");
75
- });
76
-
77
- it("a partially typed configurator can be configured with set()", () => {
78
- const c = FluentConfigurator<{ songs: object; playlists: object }>()
79
- .set("songs", SimpleTable(Song))
80
- .set("playlists", SimpleTable(Playlist))
81
- .set("foobar", true)
82
- .done();
83
-
84
- expect(c.songs.name).toBe("Song");
85
- expect(c.playlists.name).toBe("Playlist");
86
- expect(c.foobar).toBe(true);
87
- });
88
- });