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.
Files changed (179) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/devops/build.js +1 -3
  3. package/dist/{types/utility/state/KeyStorage.d.ts → index.d.ts} +9767 -8195
  4. package/dist/index.js +659 -0
  5. package/dist/index.mjs +577 -0
  6. package/on-hold/tests/api-spec.ts +9 -15
  7. package/package.json +27 -37
  8. package/pnpm-lock.yaml +2385 -2117
  9. package/src/errors/InferenceError.ts +1 -1
  10. package/src/shared/randomString.ts +1 -1
  11. package/src/types/Constructor.ts +5 -0
  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 +9 -5
  17. package/src/types/{fluent.ts → fluent/fluent.ts} +8 -9
  18. package/src/types/fluent/index.ts +42 -0
  19. package/src/types/index.ts +13 -7
  20. package/src/types/lists/UniqueForProp.ts +13 -3
  21. package/src/types/ruleset-types.ts +1 -1
  22. package/src/types/{SameKeys.ts → type-conversion/SameKeys.ts} +0 -0
  23. package/src/types/type-conversion/WrapValue.ts +15 -0
  24. package/src/types/type-conversion/index.ts +11 -4
  25. package/src/utility/dictionary/arrayToKeyLookup.ts +3 -4
  26. package/src/utility/dictionary/dictionaryTransform.ts +6 -7
  27. package/src/utility/index.ts +3 -2
  28. package/src/utility/lists/groupBy.ts +22 -0
  29. package/src/utility/lists/index.ts +38 -0
  30. package/tests/Where.spec.ts +39 -0
  31. package/tests/constructor.spec.ts +40 -0
  32. package/tests/data/index.ts +8 -3
  33. package/tests/kv/dict-to-kv-and-back.spec.ts +2 -6
  34. package/tsconfig.json +4 -3
  35. package/dist/cjs/index.js +0 -21
  36. package/dist/es/index.js +0 -17
  37. package/dist/tsconfig.tsbuildinfo +0 -1
  38. package/dist/types/Mutation/MutationFunction.d.ts +0 -16
  39. package/dist/types/Mutation/MutationIdentity.d.ts +0 -30
  40. package/dist/types/Mutation/index.d.ts +0 -2
  41. package/dist/types/errors/InferenceError.d.ts +0 -1
  42. package/dist/types/errors/index.d.ts +0 -1
  43. package/dist/types/index.d.ts +0 -4
  44. package/dist/types/shared/index.d.ts +0 -3
  45. package/dist/types/shared/randomString.d.ts +0 -1
  46. package/dist/types/shared/uuid.d.ts +0 -1
  47. package/dist/types/shared/valueTypes.d.ts +0 -27
  48. package/dist/types/types/Api.d.ts +0 -10
  49. package/dist/types/types/EnumValues.d.ts +0 -14
  50. package/dist/types/types/ExpandRecursively.d.ts +0 -3
  51. package/dist/types/types/First.d.ts +0 -4
  52. package/dist/types/types/FunctionType.d.ts +0 -9
  53. package/dist/types/types/If.d.ts +0 -10
  54. package/dist/types/types/Include.d.ts +0 -16
  55. package/dist/types/types/Includes.d.ts +0 -5
  56. package/dist/types/types/KeyedRecord.d.ts +0 -22
  57. package/dist/types/types/Keys.d.ts +0 -17
  58. package/dist/types/types/Length.d.ts +0 -8
  59. package/dist/types/types/Mutable.d.ts +0 -6
  60. package/dist/types/types/Narrowable.d.ts +0 -5
  61. package/dist/types/types/Not.d.ts +0 -11
  62. package/dist/types/types/Numeric.d.ts +0 -14
  63. package/dist/types/types/Opaque.d.ts +0 -12
  64. package/dist/types/types/Retain.d.ts +0 -16
  65. package/dist/types/types/SameKeys.d.ts +0 -11
  66. package/dist/types/types/Transformer.d.ts +0 -11
  67. package/dist/types/types/TypeGuard.d.ts +0 -7
  68. package/dist/types/types/alphabetic/AllCaps.d.ts +0 -12
  69. package/dist/types/types/alphabetic/CamelCase.d.ts +0 -2
  70. package/dist/types/types/alphabetic/CapFirstAlpha.d.ts +0 -13
  71. package/dist/types/types/alphabetic/CapitalizeWords.d.ts +0 -4
  72. package/dist/types/types/alphabetic/DashToSnake.d.ts +0 -1
  73. package/dist/types/types/alphabetic/DashUppercase.d.ts +0 -14
  74. package/dist/types/types/alphabetic/Dasherize.d.ts +0 -15
  75. package/dist/types/types/alphabetic/HasUppercase.d.ts +0 -13
  76. package/dist/types/types/alphabetic/Intrinsic.d.ts +0 -4
  77. package/dist/types/types/alphabetic/IsCapitalized.d.ts +0 -15
  78. package/dist/types/types/alphabetic/KebabCase.d.ts +0 -12
  79. package/dist/types/types/alphabetic/LowerAllCaps.d.ts +0 -4
  80. package/dist/types/types/alphabetic/PascalCase.d.ts +0 -16
  81. package/dist/types/types/alphabetic/Pluralize.d.ts +0 -36
  82. package/dist/types/types/alphabetic/SnakeCase.d.ts +0 -14
  83. package/dist/types/types/alphabetic/alpha-characters.d.ts +0 -36
  84. package/dist/types/types/alphabetic/index.d.ts +0 -16
  85. package/dist/types/types/append-types.d.ts +0 -9
  86. package/dist/types/types/dictionary/Get.d.ts +0 -7
  87. package/dist/types/types/dictionary/index.d.ts +0 -1
  88. package/dist/types/types/fluent.d.ts +0 -51
  89. package/dist/types/types/index.d.ts +0 -34
  90. package/dist/types/types/kv/DictFromKv.d.ts +0 -6
  91. package/dist/types/types/kv/KeyValue.d.ts +0 -11
  92. package/dist/types/types/kv/KvFrom.d.ts +0 -13
  93. package/dist/types/types/kv/KvTuple.d.ts +0 -14
  94. package/dist/types/types/kv/index.d.ts +0 -4
  95. package/dist/types/types/lists/UniqueForProp.d.ts +0 -5
  96. package/dist/types/types/lists/index.d.ts +0 -1
  97. package/dist/types/types/maybe.d.ts +0 -8
  98. package/dist/types/types/props.d.ts +0 -100
  99. package/dist/types/types/ruleset-types.d.ts +0 -59
  100. package/dist/types/types/runtime.d.ts +0 -33
  101. package/dist/types/types/string-literals/Break.d.ts +0 -12
  102. package/dist/types/types/string-literals/Concat.d.ts +0 -8
  103. package/dist/types/types/string-literals/LeftWhitespace.d.ts +0 -9
  104. package/dist/types/types/string-literals/Replace.d.ts +0 -11
  105. package/dist/types/types/string-literals/RightWhitespace.d.ts +0 -9
  106. package/dist/types/types/string-literals/StringLength.d.ts +0 -10
  107. package/dist/types/types/string-literals/Trim.d.ts +0 -11
  108. package/dist/types/types/string-literals/TrimLeft.d.ts +0 -11
  109. package/dist/types/types/string-literals/TrimRight.d.ts +0 -11
  110. package/dist/types/types/string-literals/form-fields.d.ts +0 -12
  111. package/dist/types/types/string-literals/index.d.ts +0 -10
  112. package/dist/types/types/tuples/DictArray.d.ts +0 -19
  113. package/dist/types/types/tuples/FirstKey.d.ts +0 -8
  114. package/dist/types/types/tuples/FirstKeyValue.d.ts +0 -8
  115. package/dist/types/types/tuples/FirstOfEach.d.ts +0 -11
  116. package/dist/types/types/tuples/FromDictArray.d.ts +0 -10
  117. package/dist/types/types/tuples/SecondOfEach.d.ts +0 -10
  118. package/dist/types/types/tuples/index.d.ts +0 -6
  119. package/dist/types/types/type-conversion/TupleToUnion.d.ts +0 -10
  120. package/dist/types/types/type-conversion/UnionToIntersection.d.ts +0 -5
  121. package/dist/types/types/type-conversion/UnionToTuple.d.ts +0 -9
  122. package/dist/types/types/type-conversion/index.d.ts +0 -3
  123. package/dist/types/types/type-testing.d.ts +0 -13
  124. package/dist/types/utility/api/api.d.ts +0 -2
  125. package/dist/types/utility/api/index.d.ts +0 -1
  126. package/dist/types/utility/createFnWithProps.d.ts +0 -1
  127. package/dist/types/utility/dictionary/arrayToKeyLookup.d.ts +0 -10
  128. package/dist/types/utility/dictionary/dictFilter.d.ts +0 -8
  129. package/dist/types/utility/dictionary/dictionaryTransform.d.ts +0 -9
  130. package/dist/types/utility/dictionary/entries.d.ts +0 -17
  131. package/dist/types/utility/dictionary/index.d.ts +0 -8
  132. package/dist/types/utility/dictionary/kv/dictToKv.d.ts +0 -16
  133. package/dist/types/utility/dictionary/kv/filterDictArray.d.ts +0 -9
  134. package/dist/types/utility/dictionary/kv/index.d.ts +0 -4
  135. package/dist/types/utility/dictionary/kv/kv.d.ts +0 -10
  136. package/dist/types/utility/dictionary/kv/kvToDict.d.ts +0 -15
  137. package/dist/types/utility/dictionary/mapValues.d.ts +0 -13
  138. package/dist/types/utility/dictionary/strArrayToDict.d.ts +0 -6
  139. package/dist/types/utility/dictionary/valuesOfProp.d.ts +0 -1
  140. package/dist/types/utility/index.d.ts +0 -10
  141. package/dist/types/utility/keys.d.ts +0 -5
  142. package/dist/types/utility/literals/ExplicitFunction.d.ts +0 -6
  143. package/dist/types/utility/literals/arrayToObject.d.ts +0 -41
  144. package/dist/types/utility/literals/defineType.d.ts +0 -8
  145. package/dist/types/utility/literals/identity.d.ts +0 -6
  146. package/dist/types/utility/literals/index.d.ts +0 -5
  147. package/dist/types/utility/literals/literal.d.ts +0 -41
  148. package/dist/types/utility/map-reduce/filter.d.ts +0 -26
  149. package/dist/types/utility/map-reduce/index.d.ts +0 -1
  150. package/dist/types/utility/modelling/IoModel.d.ts +0 -26
  151. package/dist/types/utility/modelling/Model.d.ts +0 -22
  152. package/dist/types/utility/modelling/index.d.ts +0 -1
  153. package/dist/types/utility/ruleset.d.ts +0 -18
  154. package/dist/types/utility/runtime/condition.d.ts +0 -3
  155. package/dist/types/utility/runtime/conditions/index.d.ts +0 -12
  156. package/dist/types/utility/runtime/conditions/isArray.d.ts +0 -2
  157. package/dist/types/utility/runtime/conditions/isBoolean.d.ts +0 -5
  158. package/dist/types/utility/runtime/conditions/isFalse.d.ts +0 -4
  159. package/dist/types/utility/runtime/conditions/isFunction.d.ts +0 -15
  160. package/dist/types/utility/runtime/conditions/isLiteral.d.ts +0 -2
  161. package/dist/types/utility/runtime/conditions/isNull.d.ts +0 -1
  162. package/dist/types/utility/runtime/conditions/isNumber.d.ts +0 -1
  163. package/dist/types/utility/runtime/conditions/isObject.d.ts +0 -10
  164. package/dist/types/utility/runtime/conditions/isString.d.ts +0 -2
  165. package/dist/types/utility/runtime/conditions/isSymbol.d.ts +0 -1
  166. package/dist/types/utility/runtime/conditions/isTrue.d.ts +0 -20
  167. package/dist/types/utility/runtime/conditions/isUndefined.d.ts +0 -1
  168. package/dist/types/utility/runtime/ifTypeOf.d.ts +0 -23
  169. package/dist/types/utility/runtime/index.d.ts +0 -5
  170. package/dist/types/utility/runtime/type.d.ts +0 -27
  171. package/dist/types/utility/runtime/withValue.d.ts +0 -19
  172. package/dist/types/utility/state/Configurator.d.ts +0 -36
  173. package/dist/types/utility/state/FluentConfigurator.d.ts +0 -27
  174. package/dist/types/utility/state/index.d.ts +0 -3
  175. package/src/types/alphabetic/Intrinsic.ts +0 -6
  176. package/src/utility/modelling/IoModel.ts +0 -38
  177. package/tests/FluentApi-spec.ts +0 -90
  178. package/tests/FluentConfigurator-spec.hold +0 -88
  179. package/tests/IoModel-spec.hold +0 -209
@@ -1,3 +1,3 @@
1
1
  import { createError } from "brilliant-errors";
2
2
 
3
- export const InferenceError = createError("InferenceError", "inferred-types");
3
+ export const [InferenceError, isInferenceError] = createError("InferenceError", "inferred-types")()()()();
@@ -1,5 +1,5 @@
1
1
  export function randomString() {
2
- return Math.trunc((1 + Math.random()) * 0x10000)
2
+ return Math.trunc((1 + Math.random()) * 0x1_00_00)
3
3
  .toString(16)
4
4
  .slice(1);
5
5
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Define a class constructor; allowing strong typing for constructor's parameters
3
+ * and the returned class structure.
4
+ */
5
+ export type Constructor<Ctor extends any[], Klass extends any> = new (...props: Ctor) => Klass;
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;
@@ -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 { Capitalize, LowerAllCaps, Trim } from "~/types";
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 ? string :
24
- Trim<DashDelim<LowerAllCaps<S>>> extends `${infer Begin}${Delimiter}${infer Rest}`
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: 7th Jul, 2021, 01:59 PM ( GMT-7 )
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, Intrinsic, IsCapitalized, KebabCase, LowerAllCaps, PascalCase, Pluralize, SnakeCase, alpha-characters.
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
- // Also be aware that all of your content outside the defined region in this file
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
- TFluent extends {
58
- [K in keyof TFluent]: (...args: Parameters<TFluent[K]>) => FluentApi<TFluent, TEscape>;
59
- },
60
- TEscape extends object = {},
61
- TExclude extends string = ""
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
@@ -1,13 +1,14 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
3
 
4
- // index last changed at: 8th Aug, 2021, 05:44 PM ( GMT-7 )
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, SameKeys, Transformer, TypeGuard, append-types, fluent, maybe, props, ruleset-types, runtime, type-testing.
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
- // Also be aware that all of your content outside the defined region in this file
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<T extends readonly Record<string, any>[], P extends string> = Readonly<
7
- Get<T[number], P>
8
- >;
15
+ export type UniqueForProp<
16
+ T extends readonly Record<string, Narrowable>[],
17
+ P extends string
18
+ > = Readonly<Get<T[number], P>>;
@@ -1,6 +1,6 @@
1
1
  import type { TypeCondition } from "~/utility/runtime/ifTypeOf";
2
2
  import { OptionalKeys } from "./props";
3
- import { SameKeys } from "./SameKeys";
3
+ import { SameKeys } from "./type-conversion/SameKeys";
4
4
 
5
5
  /**
6
6
  * **RuleDefinition**
@@ -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: 8th Aug, 2021, 04:13 PM ( GMT-7 )
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
- // Also be aware that all of your content outside the defined region in this file
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 all the keys
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
- i: I,
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 result as O;
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
  }
@@ -2,10 +2,10 @@
2
2
 
3
3
  // #region autoindexed files
4
4
 
5
- // index last changed at: 8th Aug, 2021, 11:56 AM ( GMT-7 )
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
+ });
@@ -2,14 +2,14 @@
2
2
 
3
3
  // #region autoindexed files
4
4
 
5
- // index last changed at: 8th Aug, 2021, 09:49 AM ( GMT-7 )
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
- // Also be aware that all of your content outside the defined region in this file
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