inferred-types 0.20.0 → 0.22.5

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 (161) hide show
  1. package/.eslintrc +36 -20
  2. package/.github/workflows/main.yml +34 -0
  3. package/.github/workflows/other.yml +15 -0
  4. package/.vscode/settings.json +10 -2
  5. package/dist/index.d.ts +426 -8547
  6. package/dist/index.js +57 -76
  7. package/dist/index.mjs +47 -63
  8. package/package.json +38 -26
  9. package/src/Mutation/index.ts +6 -29
  10. package/src/index.ts +6 -29
  11. package/src/shared/index.ts +6 -29
  12. package/src/shared/valueTypes.ts +1 -1
  13. package/src/types/ExpandRecursively.ts +10 -1
  14. package/src/types/Keys.ts +10 -6
  15. package/src/types/SimplifyObject.ts +12 -0
  16. package/src/types/Transformer.ts +1 -1
  17. package/src/types/alphabetic/CamelCase.ts +2 -2
  18. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  19. package/src/types/alphabetic/Dasherize.ts +8 -5
  20. package/src/types/alphabetic/KebabCase.ts +1 -1
  21. package/src/types/alphabetic/PascalCase.ts +3 -1
  22. package/src/types/alphabetic/SnakeCase.ts +8 -3
  23. package/src/types/alphabetic/alpha-characters.ts +33 -9
  24. package/src/types/alphabetic/index.ts +6 -29
  25. package/src/types/dictionary/DictChangeValue.ts +26 -0
  26. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  27. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  28. package/src/types/dictionary/DictReturnValues.ts +27 -0
  29. package/src/types/dictionary/MutableProps.ts +19 -0
  30. package/src/types/dictionary/RequireProps.ts +15 -0
  31. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  32. package/src/types/dictionary/index.ts +13 -30
  33. package/src/types/{props.ts → dictionary/props.ts} +2 -2
  34. package/src/types/fluent/index.ts +6 -29
  35. package/src/types/functions/FinalReturn.ts +12 -0
  36. package/src/types/functions/index.ts +12 -0
  37. package/src/types/index.ts +8 -30
  38. package/src/types/kv/index.ts +6 -29
  39. package/src/types/lists/index.ts +6 -29
  40. package/src/types/ruleset-types.ts +3 -3
  41. package/src/types/runtime.ts +18 -18
  42. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  43. package/src/types/string-literals/RightWhitespace.ts +5 -2
  44. package/src/types/string-literals/index.ts +6 -29
  45. package/src/types/tuples/FirstKey.ts +3 -3
  46. package/src/types/tuples/FromDictArray.ts +5 -4
  47. package/src/types/tuples/index.ts +6 -29
  48. package/src/types/type-conversion/index.ts +6 -32
  49. package/src/utility/api/api.ts +8 -7
  50. package/src/utility/api/index.ts +6 -29
  51. package/src/utility/dictionary/defineProperties.ts +35 -0
  52. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  53. package/src/utility/dictionary/entries.ts +9 -5
  54. package/src/utility/dictionary/index.ts +7 -30
  55. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  56. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  57. package/src/utility/dictionary/kv/index.ts +6 -29
  58. package/src/utility/dictionary/kv/kv.ts +8 -3
  59. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  60. package/src/utility/dictionary/mapValues.ts +8 -5
  61. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  62. package/src/utility/errors/ReadOnlyViolation.ts +3 -0
  63. package/src/utility/errors/index.ts +12 -0
  64. package/src/utility/index.ts +7 -29
  65. package/src/utility/keys.ts +8 -4
  66. package/src/utility/lists/groupBy.ts +2 -9
  67. package/src/utility/lists/index.ts +6 -29
  68. package/src/utility/literals/arrayToObject.ts +29 -29
  69. package/src/utility/literals/defineType.ts +6 -6
  70. package/src/utility/literals/identity.ts +5 -2
  71. package/src/utility/literals/index.ts +6 -29
  72. package/src/utility/literals/literal.ts +3 -3
  73. package/src/utility/map-reduce/index.ts +6 -29
  74. package/src/utility/modelling/index.ts +6 -29
  75. package/src/utility/ruleset.ts +11 -9
  76. package/src/utility/runtime/condition.ts +1 -1
  77. package/src/utility/runtime/conditions/index.ts +6 -30
  78. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  79. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  80. package/src/utility/runtime/conditions/isObject.ts +4 -1
  81. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  82. package/src/utility/runtime/ifTypeOf.ts +5 -4
  83. package/src/utility/runtime/index.ts +6 -29
  84. package/src/utility/runtime/type.ts +3 -1
  85. package/src/utility/runtime/withValue.ts +5 -3
  86. package/src/utility/state/Configurator.ts +2 -2
  87. package/src/utility/state/FluentConfigurator.ts +2 -2
  88. package/src/utility/state/index.ts +6 -30
  89. package/tests/CamelCase-spec.ts +2 -0
  90. package/tests/ExplicitFunction-spec.ts +3 -2
  91. package/tests/IncludeAndRetain-spec.ts +7 -12
  92. package/tests/Includes-spec.ts +2 -0
  93. package/tests/KebabCase-spec.ts +2 -0
  94. package/tests/MutationIdentity-spec.ts +2 -1
  95. package/tests/PascalCase-spec.ts +2 -0
  96. package/tests/Pluralize-spec.ts +2 -0
  97. package/tests/SnakeCase-spec.ts +2 -0
  98. package/tests/Where.spec.ts +9 -10
  99. package/tests/arrayToKeyLookup-spec.ts +5 -5
  100. package/tests/arrayToObject-spec.ts +12 -8
  101. package/tests/constructor.spec.ts +2 -0
  102. package/tests/createFnWithProps.spec.ts +2 -2
  103. package/tests/data/index.ts +6 -29
  104. package/tests/defineType-spec.ts +17 -11
  105. package/tests/dictionary/DictChangeValue.test.ts +30 -0
  106. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  107. package/tests/dictionary/DictReturnValues.test.ts +36 -0
  108. package/tests/dictionary/Get.spec.ts +5 -3
  109. package/tests/dictionary/MutableProps.test.ts +30 -0
  110. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  111. package/tests/dictionary/RequireProps.test.ts +21 -0
  112. package/tests/dictionaryTransform-spec.ts +3 -3
  113. package/tests/ifTypeOf-spec.ts +31 -20
  114. package/tests/kv/KeyValue-spec.ts +4 -4
  115. package/tests/kv/SameKeys-spec.ts +6 -9
  116. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  117. package/tests/kv/entries-spec.ts +8 -9
  118. package/tests/kv/keys.spec.ts +9 -19
  119. package/tests/kv/kv-spec.ts +4 -4
  120. package/tests/lists/UniqueForProp.spec.ts +3 -1
  121. package/tests/literal-spec.ts +5 -3
  122. package/tests/mapValues-spec.ts +5 -3
  123. package/tests/props-spec.ts +3 -2
  124. package/tests/runtime/condition.spec.ts +2 -1
  125. package/tests/runtime/type.spec.ts +4 -3
  126. package/tests/strArrayToDict-spec.ts +6 -6
  127. package/tests/string-literals/AllCaps.spec.ts +6 -15
  128. package/tests/string-literals/CamelCase.spec.ts +13 -32
  129. package/tests/string-literals/Dasherize.spec.ts +13 -31
  130. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  131. package/tests/string-literals/PascalCase.spec.ts +13 -32
  132. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  133. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  134. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  135. package/tests/withValue.spec.ts +4 -3
  136. package/tsconfig.json +8 -19
  137. package/vitest.config.ts +13 -0
  138. package/jest.config.ts +0 -20
  139. package/on-hold/Builder/Builder.ts +0 -66
  140. package/on-hold/Builder/BuilderApi.ts +0 -21
  141. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  142. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  143. package/on-hold/Builder/index.ts +0 -35
  144. package/on-hold/tests/Builder-spec.ts +0 -310
  145. package/on-hold/tests/RuleSet-spec.ts +0 -59
  146. package/on-hold/tests/ToFluent-spec.ts +0 -60
  147. package/on-hold/tests/api-spec.ts +0 -73
  148. package/on-hold/tests/data/builder-data.ts +0 -53
  149. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  150. package/on-hold/tests/run-time-spec.ts +0 -44
  151. package/on-hold/type.ts +0 -20
  152. package/on-hold/types/index.ts +0 -34
  153. package/on-hold/types/object.ts +0 -19
  154. package/on-hold/types/prop.ts +0 -28
  155. package/on-hold/types/scalar.ts +0 -37
  156. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  157. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  158. package/src/types/type-conversion/WrapValue.ts +0 -15
  159. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  160. package/src/utility/runtime/conditions/isLiteral.ts +0 -7
  161. package/src/utility/state/KeyStorage.ts +0 -23
@@ -1,6 +1,8 @@
1
- import { Mutable, Narrowable, UnionToTuple } from "~/types";
2
- import { KvFrom } from "~/types/kv/KvFrom";
3
- import { keys } from "~/utility/keys";
1
+ import { KvFrom } from "src/types/kv";
2
+ import { Mutable } from "src/types/Mutable";
3
+ import { Narrowable } from "src/types/Narrowable";
4
+ import { UnionToTuple } from "src/types/type-conversion";
5
+ import { keys } from "src/utility/keys";
4
6
 
5
7
  /**
6
8
  * Converts a dictionary object into an array of dictionaries with `key` and `value` properties
@@ -1,5 +1,5 @@
1
- import type { DictArray, DictArrayFilterCallback } from "~/types";
2
- import { Configurator, IConfigurator } from "~/utility/state";
1
+ import { DictArray, DictArrayFilterCallback } from "src/types/tuples";
2
+ import { Configurator, IConfigurator } from "src/utility/state";
3
3
 
4
4
  export interface Array<T> {
5
5
  filter<U extends T>(pred: (a: T) => a is U): U[];
@@ -11,12 +11,11 @@ export interface Array<T> {
11
11
  */
12
12
  export function filterDictArray<
13
13
  T extends object,
14
- C extends DictArrayFilterCallback<keyof T, T, true | false>,
15
- >(dictArr: DictArray<T>, cb: C) {
16
-
14
+ C extends DictArrayFilterCallback<keyof T, T, true | false>
15
+ >(dictArr: DictArray<T>, cb: C) {
17
16
  const state: IConfigurator = Configurator();
18
17
 
19
- const updated = dictArr.filter(i => {
18
+ const updated = dictArr.filter((i) => {
20
19
  const [k, v] = i;
21
20
  const keep = cb(k, v);
22
21
  if (!keep) {
@@ -30,4 +29,3 @@ export function filterDictArray<
30
29
  type ExcludedKeys = "";
31
30
  return updated as unknown as DictArray<Omit<T, ExcludedKeys>>;
32
31
  }
33
-
@@ -1,7 +1,7 @@
1
1
  // #autoindex
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: e1ea6f41
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: dd4e4592
5
5
 
6
6
  // file exports
7
7
  export * from "./dictToKv";
@@ -9,30 +9,7 @@ export * from "./filterDictArray";
9
9
  export * from "./kv";
10
10
  export * from "./kvToDict";
11
11
 
12
- // #endregion
12
+ // #endregion auto-indexed files
13
13
 
14
- // This file was created by running: "dd autoindex"; it assumes you have
15
- // the 'do-devops' pkg (that's "dd" on npm) 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 and
22
- // converts the default export to the name of the 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
- //
26
- // You may also exclude certain files or directories by adding it to the
27
- // autoindex command. As an example:
28
- //
29
- // - autoindex:named, exclude: foo,bar,baz
30
- //
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
- // All content outside the "// #region" section in this file will be
37
- // preserved in situations where you need to do something paricularly awesome.
38
- // Keep on being awesome.
14
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
15
+ // for more info
@@ -1,13 +1,18 @@
1
- import { ExpandRecursively, Narrowable } from "~/types";
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
+ import { Narrowable } from "src/types/Narrowable";
2
3
 
3
4
  /**
4
5
  * Build a key-value pair where both _key_ and _value_ are inferred. This
5
6
  * includes ensuring that the _key_ is a type literal not just a "string".
6
7
  *
7
8
  * > note: the value will be inferred but if you need to constrain it
8
- * > to a narrower type then both inferrences will break and you should
9
+ * > to a narrower type then both inferences will break and you should
9
10
  * > instead use `KV2` to get this capability.
10
11
  */
11
- export function kv<K extends string, N extends Narrowable, V extends Record<any, N> | boolean | number | string | null | undefined>(key: K, value: V) {
12
+ export function kv<
13
+ K extends string,
14
+ N extends Narrowable,
15
+ V extends Record<any, N> | boolean | number | string | null | undefined
16
+ >(key: K, value: V) {
12
17
  return { [key]: value } as ExpandRecursively<Record<K, V>>;
13
18
  }
@@ -1,5 +1,6 @@
1
- import { Mutable, Narrowable } from "~/types";
2
- import { DictFromKv } from "~/types/kv";
1
+ import { DictFromKv } from "src/types/kv";
2
+ import { Mutable } from "src/types/Mutable";
3
+ import { Narrowable } from "src/types/Narrowable";
3
4
 
4
5
  /**
5
6
  * Converts an array of dictionaries with `key` and `value` properties to a singular dictionary.
@@ -1,20 +1,23 @@
1
- import { Narrowable } from "~/types";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
  import { entries } from "./entries";
3
3
 
4
4
  /**
5
5
  * **mapValues**
6
- *
6
+ *
7
7
  * Maps over a dictionary, preserving the keys but allowing the values to be mutated.
8
- *
8
+ *
9
9
  * ```ts
10
10
  * const colors = { red: 4, blue: 2, green: 3 };
11
11
  * // { red: 8, blue: 4, green: 6 }
12
12
  * const twoX = mapValues(colors, v => v * 2);
13
13
  * ```
14
14
  */
15
- export function mapValues<N extends Narrowable, T extends Record<string, N>, V>(obj: T, valueMapper: (k: T[keyof T]) => V) {
15
+ export function mapValues<N extends Narrowable, T extends Record<string, N>, V>(
16
+ obj: T,
17
+ valueMapper: (k: T[keyof T]) => V
18
+ ) {
16
19
  return Object.fromEntries(
17
20
  // TODO: fix the type error with v and valueMapper
18
21
  [...entries(obj)].map(([k, v]) => [k, valueMapper(v as any)])
19
22
  ) as { [K in keyof T]: V };
20
- }
23
+ }
@@ -1,5 +1,4 @@
1
- import { ExpandRecursively } from "~/types/ExpandRecursively";
2
-
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
3
2
 
4
3
  /**
5
4
  * converts an array of strings `["a", "b", "c"]` into a more type friendly
@@ -0,0 +1,3 @@
1
+ import { createError } from "brilliant-errors";
2
+
3
+ export default createError("read-only-violation", "inferred-types")()()()();
@@ -0,0 +1,12 @@
1
+ // #autoindex
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: 30d9ddb2
5
+
6
+ // file exports
7
+ export * from "./ReadOnlyViolation";
8
+
9
+ // #endregion auto-indexed files
10
+
11
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
12
+ // for more info
@@ -1,8 +1,8 @@
1
1
  // #autoindex
2
2
 
3
- // #region autoindexed files
4
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
5
- // hash-code: 6886d37a
3
+ // #region auto-indexed files
4
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
5
+ // hash-code: 9dd9ac96
6
6
 
7
7
  // file exports
8
8
  export * from "./createFnWithProps";
@@ -11,6 +11,7 @@ export * from "./ruleset";
11
11
  // directory exports
12
12
  export * from "./api/index";
13
13
  export * from "./dictionary/index";
14
+ export * from "./errors/index";
14
15
  export * from "./lists/index";
15
16
  export * from "./literals/index";
16
17
  export * from "./map-reduce/index";
@@ -18,30 +19,7 @@ export * from "./modelling/index";
18
19
  export * from "./runtime/index";
19
20
  export * from "./state/index";
20
21
 
21
- // #endregion
22
+ // #endregion auto-indexed files
22
23
 
23
- // This file was created by running: "dd autoindex"; it assumes you have
24
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
25
- //
26
- // By default it assumes that exports are named exports but this can be changed by
27
- // adding a modifier to the '// #autoindex' syntax:
28
- //
29
- // - autoindex:named same as default, exports "named symbols"
30
- // - autoindex:default assumes each file is exporting a default export and
31
- // converts the default export to the name of the file
32
- // - autoindex:offset assumes files export "named symbols" but that each
33
- // file's symbols should be offset by the file's name
34
- //
35
- // You may also exclude certain files or directories by adding it to the
36
- // autoindex command. As an example:
37
- //
38
- // - autoindex:named, exclude: foo,bar,baz
39
- //
40
- // Inversely, if you state a file to be an "orphan" then autoindex files
41
- // below this file will not reference this autoindex file:
42
- //
43
- // - autoindex:named, orphan
44
- //
45
- // All content outside the "// #region" section in this file will be
46
- // preserved in situations where you need to do something paricularly awesome.
47
- // Keep on being awesome.
24
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
25
+ // for more info
@@ -1,12 +1,16 @@
1
- import { Keys, Length } from "~/types";
1
+ import { Keys } from "src/types/Keys";
2
+ import { Length } from "src/types/Length";
2
3
 
3
4
  /**
4
5
  * Provides the _keys_ of an object with the `keyof T` made explicit.
5
6
  */
6
7
  export function keys<T extends {}, W extends readonly string[]>(obj: T, ...without: W) {
7
- const v = without.length > 0
8
- ? Object.keys(obj).filter(k => !without.includes(k)) as unknown as Array<Exclude<keyof T, Keys<W>>>
9
- : Object.keys(obj) as unknown as Array<keyof T>;
8
+ const v =
9
+ without.length > 0
10
+ ? (Object.keys(obj).filter((k) => !without.includes(k)) as unknown as Array<
11
+ Exclude<keyof T, Keys<W>>
12
+ >)
13
+ : (Object.keys(obj) as unknown as Array<keyof T>);
10
14
 
11
15
  return v as unknown as Length<W> extends 0 ? Array<keyof T> : Array<Exclude<keyof T, Keys<W>>>;
12
16
  }
@@ -1,5 +1,4 @@
1
- import { Narrowable } from "~/types";
2
- // import { UniqueForProp } from "~/types/lists/UniqueForProp";
1
+ import { Narrowable } from "src/types/Narrowable";
3
2
 
4
3
  /**
5
4
  * Groups an array of data based on the value of a property
@@ -11,12 +10,6 @@ import { Narrowable } from "~/types";
11
10
  *
12
11
  * @ignore not implemented
13
12
  */
14
- export function groupBy<T extends Record<string, Narrowable>, K extends keyof T & string>(
15
- _data: Readonly<T[]>
16
- ) {
13
+ export function groupBy<T extends Record<string, Narrowable>>(_data: Readonly<T[]>) {
17
14
  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
15
  }
@@ -1,36 +1,13 @@
1
1
  // #autoindex
2
2
 
3
- // #region autoindexed files
4
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
5
- // hash-code: 150c313
3
+ // #region auto-indexed files
4
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
5
+ // hash-code: bf4a6791
6
6
 
7
7
  // file exports
8
8
  export * from "./groupBy";
9
9
 
10
- // #endregion
10
+ // #endregion auto-indexed files
11
11
 
12
- // This file was created by running: "dd autoindex"; it assumes you have
13
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
14
- //
15
- // By default it assumes that exports are named exports but this can be changed by
16
- // adding a modifier to the '// #autoindex' syntax:
17
- //
18
- // - autoindex:named same as default, exports "named symbols"
19
- // - autoindex:default assumes each file is exporting a default export and
20
- // converts the default export to the name of the file
21
- // - autoindex:offset assumes files export "named symbols" but that each
22
- // file's symbols should be offset by the file's name
23
- //
24
- // You may also exclude certain files or directories by adding it to the
25
- // autoindex command. As an example:
26
- //
27
- // - autoindex:named, exclude: foo,bar,baz
28
- //
29
- // Inversely, if you state a file to be an "orphan" then autoindex files
30
- // below this file will not reference this autoindex file:
31
- //
32
- // - autoindex:named, orphan
33
- //
34
- // All content outside the "// #region" section in this file will be
35
- // preserved in situations where you need to do something paricularly awesome.
36
- // Keep on being awesome.
12
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
13
+ // for more info
@@ -1,22 +1,28 @@
1
- import { Narrowable } from "~/types/Narrowable";
2
-
1
+ import { Narrowable } from "src/types/Narrowable";
3
2
 
4
3
  /**
5
4
  * **UniqueDictionary**
6
- *
5
+ *
7
6
  * A dictionary converted by `arrayToObject()` which expects each key `S` to have a only a
8
7
  * single/unique value.
9
8
  */
10
- export type UniqueDictionary<S extends PropertyKey, N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>> = { [V in T as V[S]]: V };
9
+ export type UniqueDictionary<
10
+ S extends PropertyKey,
11
+ N extends Narrowable,
12
+ T extends Record<keyof T, N> & Record<S, any>
13
+ > = { [V in T as V[S]]: V };
11
14
 
12
15
  /**
13
16
  * **GeneralDictionary**
14
- *
17
+ *
15
18
  * A dictionary converted by `arrayToObject()` which expects each key `S` to have an
16
19
  * array of values.
17
20
  */
18
- export type GeneralDictionary<S extends PropertyKey, N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>> = { [V in T as V[S]]: V[] };
19
-
21
+ export type GeneralDictionary<
22
+ S extends PropertyKey,
23
+ N extends Narrowable,
24
+ T extends Record<keyof T, N> & Record<S, any>
25
+ > = { [V in T as V[S]]: V[] };
20
26
 
21
27
  export type ArrayConverter<S extends PropertyKey, U extends boolean> =
22
28
  /**
@@ -28,45 +34,40 @@ export type ArrayConverter<S extends PropertyKey, U extends boolean> =
28
34
  arr: readonly T[]
29
35
  ) => true extends U ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
30
36
 
31
-
32
37
  /**
33
38
  * Converts an array of objects into a dictionary by picking a property name contained
34
39
  * by all objects and using that as the key to the dictionary.
35
- *
40
+ *
36
41
  * ```ts
37
- * const arr = [
42
+ * const arr = [
38
43
  * { kind: "color", favorite: "blue", likes: 100 },
39
44
  * { kind: "song", favorite: "some song", likes: 25 }
40
45
  * ];
41
46
  * const dict = arrayToObject("kind")(arr);
42
47
  * ```
43
- *
48
+ *
44
49
  * This will produce a dictionary with keys of `color` and `song`.
45
50
  */
46
- export function arrayToObject<
47
- S extends PropertyKey,
48
- U extends boolean
49
- >(prop: S, unique?: U) {
51
+ export function arrayToObject<S extends PropertyKey, U extends boolean>(prop: S, unique?: U) {
50
52
  type X = true extends U ? true : false;
51
53
  /**
52
54
  * **arrayToObject** - partially applied
53
- *
55
+ *
54
56
  * pass in an array of objects to complete application of arrayToObject()
55
57
  */
56
- const transform: ArrayConverter<S, X> = <N extends Narrowable, T extends Record<keyof T, N> & Record<S, any>>(
58
+ const transform: ArrayConverter<S, X> = <
59
+ N extends Narrowable,
60
+ T extends Record<keyof T, N> & Record<S, any>
61
+ >(
57
62
  arr: readonly T[]
58
63
  ): true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T> => {
59
-
60
- const result = unique !== false
61
- ? arr.reduce(
62
- (acc, v) => ({ ...acc, [v[prop]]: v }), {} as UniqueDictionary<S, N, T>
63
- )
64
- : arr.reduce(
65
- (acc, v) => {
66
- const existing = acc[v[prop] as T[S]] || [];
67
- return { ...acc, [v[prop]]: [...existing, v] };
68
- }, {} as GeneralDictionary<S, N, T>
69
- );
64
+ const result =
65
+ unique !== false
66
+ ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {} as UniqueDictionary<S, N, T>)
67
+ : arr.reduce((acc, v) => {
68
+ const existing = acc[v[prop] as T[S]] || [];
69
+ return { ...acc, [v[prop]]: [...existing, v] };
70
+ }, {} as GeneralDictionary<S, N, T>);
70
71
 
71
72
  // type cast based on `U`
72
73
  return result as true extends X ? UniqueDictionary<S, N, T> : GeneralDictionary<S, N, T>;
@@ -75,4 +76,3 @@ export function arrayToObject<
75
76
  return transform;
76
77
  // return converter(prop, unique);
77
78
  }
78
-
@@ -1,15 +1,15 @@
1
- import { ExpandRecursively, Narrowable } from "~/types";
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
+ import { Narrowable } from "src/types/Narrowable";
2
3
 
3
4
  /**
4
5
  * Build a _type_ from two run-time dictionaries.
5
- *
6
+ *
6
7
  * 1. The _first_ -- which is optional -- is interpreted as a _literal_ type definition
7
8
  * 2. The _second_ dictionary is interpreted as a "wide" definition of prop types
8
9
  */
9
- export function defineType<
10
- N extends Narrowable,
11
- TLiteral extends Record<string, N>
12
- >(literal: TLiteral = {} as TLiteral) {
10
+ export function defineType<N extends Narrowable, TLiteral extends Record<string, N>>(
11
+ literal: TLiteral = {} as TLiteral
12
+ ) {
13
13
  /**
14
14
  * Add any key/value pairs which you want to have _wide_ types associated;
15
15
  * literal types are defined already and stated above.
@@ -1,4 +1,5 @@
1
- import { Narrowable } from "~/types/Narrowable";
1
+ import { Narrowable } from "src/types/Narrowable";
2
+
2
3
  /**
3
4
  * An identity function for any type, with the goal of preserving literal type information
4
5
  * whereever possible.
@@ -6,4 +7,6 @@ import { Narrowable } from "~/types/Narrowable";
6
7
  export const identity = <
7
8
  N extends Narrowable,
8
9
  T extends Record<any, N> | number | string | boolean | symbol | undefined | null
9
- >(v: T) => v;
10
+ >(
11
+ v: T
12
+ ) => v;
@@ -1,7 +1,7 @@
1
1
  // #autoindex
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: b7a5f43
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: 7a22bbbc
5
5
 
6
6
  // file exports
7
7
  export * from "./ExplicitFunction";
@@ -10,30 +10,7 @@ export * from "./defineType";
10
10
  export * from "./identity";
11
11
  export * from "./literal";
12
12
 
13
- // #endregion
13
+ // #endregion auto-indexed files
14
14
 
15
- // This file was created by running: "dd autoindex"; it assumes you have
16
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
17
- //
18
- // By default it assumes that exports are named exports but this can be changed by
19
- // adding a modifier to the '// #autoindex' syntax:
20
- //
21
- // - autoindex:named same as default, exports "named symbols"
22
- // - autoindex:default assumes each file is exporting a default export and
23
- // converts the default export to the name of the 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
- //
27
- // You may also exclude certain files or directories by adding it to the
28
- // autoindex command. As an example:
29
- //
30
- // - autoindex:named, exclude: foo,bar,baz
31
- //
32
- // Inversely, if you state a file to be an "orphan" then autoindex files
33
- // below this file will not reference this autoindex file:
34
- //
35
- // - autoindex:named, orphan
36
- //
37
- // All content outside the "// #region" section in this file will be
38
- // preserved in situations where you need to do something paricularly awesome.
39
- // Keep on being awesome.
15
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
16
+ // for more info
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-use-before-define */
2
2
 
3
- import { Narrowable } from "~/types";
3
+ import { Narrowable } from "src/types/Narrowable";
4
4
 
5
5
  /**
6
6
  * Takes an object as input --which has an `id` property and returns it as the same
@@ -39,8 +39,8 @@ export function idTypeGuard<T extends { id: I }, I extends PropertyKey>(
39
39
  /**
40
40
  * Takes an object as input and infers the narrow literal types of the property
41
41
  * values on the object.
42
- *
43
- * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
42
+ *
43
+ * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
44
44
  * > Hopefully at some point this will be addressed in the language.
45
45
  */
46
46
  export function literal<N extends Narrowable, T extends Record<keyof T, N>>(obj: T) {
@@ -1,35 +1,12 @@
1
1
  // #autoindex
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: 73454cdf
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: 5ffc538b
5
5
 
6
6
  // file exports
7
7
  export * from "./filter";
8
8
 
9
- // #endregion
9
+ // #endregion auto-indexed files
10
10
 
11
- // This file was created by running: "dd autoindex"; it assumes you have
12
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
13
- //
14
- // By default it assumes that exports are named exports but this can be changed by
15
- // adding a modifier to the '// #autoindex' syntax:
16
- //
17
- // - autoindex:named same as default, exports "named symbols"
18
- // - autoindex:default assumes each file is exporting a default export and
19
- // converts the default export to the name of the file
20
- // - autoindex:offset assumes files export "named symbols" but that each
21
- // file's symbols should be offset by the file's name
22
- //
23
- // You may also exclude certain files or directories by adding it to the
24
- // autoindex command. As an example:
25
- //
26
- // - autoindex:named, exclude: foo,bar,baz
27
- //
28
- // Inversely, if you state a file to be an "orphan" then autoindex files
29
- // below this file will not reference this autoindex file:
30
- //
31
- // - autoindex:named, orphan
32
- //
33
- // All content outside the "// #region" section in this file will be
34
- // preserved in situations where you need to do something paricularly awesome.
35
- // Keep on being awesome.
11
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
12
+ // for more info
@@ -1,35 +1,12 @@
1
1
  // #autoindex, exclude: IoModel
2
- // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: 34d6be17
2
+ // #region auto-indexed files
3
+ // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
+ // hash-code: db68628c
5
5
 
6
6
  // file exports
7
7
  export * from "./Model";
8
8
 
9
- // #endregion
9
+ // #endregion auto-indexed files
10
10
 
11
- // This file was created by running: "dd autoindex"; it assumes you have
12
- // the 'do-devops' pkg (that's "dd" on npm) installed as a dev dep.
13
- //
14
- // By default it assumes that exports are named exports but this can be changed by
15
- // adding a modifier to the '// #autoindex' syntax:
16
- //
17
- // - autoindex:named same as default, exports "named symbols"
18
- // - autoindex:default assumes each file is exporting a default export and
19
- // converts the default export to the name of the file
20
- // - autoindex:offset assumes files export "named symbols" but that each
21
- // file's symbols should be offset by the file's name
22
- //
23
- // You may also exclude certain files or directories by adding it to the
24
- // autoindex command. As an example:
25
- //
26
- // - autoindex:named, exclude: foo,bar,baz
27
- //
28
- // Inversely, if you state a file to be an "orphan" then autoindex files
29
- // below this file will not reference this autoindex file:
30
- //
31
- // - autoindex:named, orphan
32
- //
33
- // All content outside the "// #region" section in this file will be
34
- // preserved in situations where you need to do something paricularly awesome.
35
- // Keep on being awesome.
11
+ // see https://github.com/inocan-group/do-devops/docs/autoindex.md
12
+ // for more info
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-use-before-define */
2
- import type { Narrowable } from "~/types";
2
+
3
+ import { Narrowable } from "src/types/Narrowable";
3
4
 
4
5
  // TODO: get ruleset functionality working!
5
6
 
@@ -15,21 +16,23 @@ import type { Narrowable } from "~/types";
15
16
 
16
17
  /**
17
18
  * **ruleSet**
18
- *
19
+ *
19
20
  * Defines a ruleset composed of _dynamic_ and _static_ boolean operators.
20
- *
21
+ *
21
22
  * - the first function call defines _dynamic_ props (_optional_)
22
23
  * - the second function call defines static values
23
- *
24
+ *
24
25
  * ```ts
25
- * const rs = ruleSet(
26
+ * const rs = ruleSet(
26
27
  * r => r.state()( { maybe: r => r.extends({ foo: 1 }) })
27
- * )(
28
- * { color: true, age: false }
28
+ * )(
29
+ * { color: true, age: false }
29
30
  * );
30
31
  * ```
31
32
  */
32
- export function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(defn?: TState) {
33
+ export function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(
34
+ defn?: TState
35
+ ) {
33
36
  // return <
34
37
  // TStatic extends { [K in keyof TStatic]: Readonly<true | false> },
35
38
  // >(rules: TStatic) => {
@@ -37,4 +40,3 @@ export function ruleSet<N extends Narrowable, TState extends Record<keyof TState
37
40
  // };
38
41
  return defn;
39
42
  }
40
-