inferred-types 0.37.0 → 0.37.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 (280) hide show
  1. package/dist/index.d.ts +2745 -0
  2. package/dist/index.js +854 -0
  3. package/package.json +8 -13
  4. package/.eslintrc +0 -77
  5. package/.github/workflows/main.yml +0 -34
  6. package/.github/workflows/other.yml +0 -15
  7. package/.nvmrc +0 -1
  8. package/.prettierrc.js +0 -3
  9. package/.vscode/launch.json +0 -27
  10. package/.vscode/settings.json +0 -19
  11. package/devops/build.js +0 -243
  12. package/docs/builder-overview.md +0 -45
  13. package/docs/builder.md +0 -94
  14. package/src/errors/ReadOnlyViolation.ts +0 -3
  15. package/src/errors/index.ts +0 -12
  16. package/src/index.ts +0 -14
  17. package/src/runtime/README.md +0 -3
  18. package/src/runtime/api/api.ts +0 -10
  19. package/src/runtime/api/index.ts +0 -12
  20. package/src/runtime/builders/Model.ts +0 -25
  21. package/src/runtime/builders/url.ts +0 -15
  22. package/src/runtime/combinators/and.ts +0 -15
  23. package/src/runtime/combinators/filter.ts +0 -267
  24. package/src/runtime/combinators/index.ts +0 -4
  25. package/src/runtime/combinators/not.ts +0 -15
  26. package/src/runtime/combinators/or.ts +0 -5
  27. package/src/runtime/createFnWithProps.ts +0 -37
  28. package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
  29. package/src/runtime/dictionary/defineProperties.ts +0 -35
  30. package/src/runtime/dictionary/dictArr.ts +0 -69
  31. package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
  32. package/src/runtime/dictionary/entries.ts +0 -33
  33. package/src/runtime/dictionary/index.ts +0 -21
  34. package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
  35. package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
  36. package/src/runtime/dictionary/kv/index.ts +0 -15
  37. package/src/runtime/dictionary/kv/kv.ts +0 -18
  38. package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
  39. package/src/runtime/dictionary/mapTo.ts +0 -206
  40. package/src/runtime/dictionary/mapValues.ts +0 -23
  41. package/src/runtime/dictionary/merge.ts +0 -36
  42. package/src/runtime/dictionary/strArrayToDict.ts +0 -12
  43. package/src/runtime/index.ts +0 -23
  44. package/src/runtime/keys.ts +0 -16
  45. package/src/runtime/lists/asArray.ts +0 -38
  46. package/src/runtime/lists/createConverter.ts +0 -62
  47. package/src/runtime/lists/groupBy.ts +0 -15
  48. package/src/runtime/lists/index.ts +0 -15
  49. package/src/runtime/literals/ExplicitFunction.ts +0 -10
  50. package/src/runtime/literals/Suggest.ts +0 -19
  51. package/src/runtime/literals/arrayToObject.ts +0 -78
  52. package/src/runtime/literals/box.ts +0 -98
  53. package/src/runtime/literals/defineType.ts +0 -20
  54. package/src/runtime/literals/ensureLeading.ts +0 -17
  55. package/src/runtime/literals/ensureTrailing.ts +0 -17
  56. package/src/runtime/literals/identity.ts +0 -12
  57. package/src/runtime/literals/index.ts +0 -23
  58. package/src/runtime/literals/literal.ts +0 -48
  59. package/src/runtime/literals/pathJoin.ts +0 -33
  60. package/src/runtime/literals/stripLeading.ts +0 -15
  61. package/src/runtime/literals/stripTrailing.ts +0 -15
  62. package/src/runtime/literals/wide.ts +0 -13
  63. package/src/runtime/ruleset.ts +0 -42
  64. package/src/runtime/runtime/README.md +0 -3
  65. package/src/runtime/runtime/condition.ts +0 -13
  66. package/src/runtime/runtime/index.ts +0 -16
  67. package/src/runtime/runtime/type.ts +0 -127
  68. package/src/runtime/runtime/withValue.ts +0 -39
  69. package/src/runtime/state/Configurator.ts +0 -76
  70. package/src/runtime/state/FluentConfigurator.ts +0 -49
  71. package/src/runtime/state/index.ts +0 -13
  72. package/src/runtime/type-checks/ifSameType.ts +0 -20
  73. package/src/runtime/type-checks/ifTypeOf.ts +0 -124
  74. package/src/runtime/type-checks/index.ts +0 -24
  75. package/src/runtime/type-checks/isArray.ts +0 -34
  76. package/src/runtime/type-checks/isBoolean.ts +0 -24
  77. package/src/runtime/type-checks/isFalse.ts +0 -29
  78. package/src/runtime/type-checks/isFunction.ts +0 -26
  79. package/src/runtime/type-checks/isNull.ts +0 -26
  80. package/src/runtime/type-checks/isNumber.ts +0 -20
  81. package/src/runtime/type-checks/isObject.ts +0 -22
  82. package/src/runtime/type-checks/isString.ts +0 -34
  83. package/src/runtime/type-checks/isSymbol.ts +0 -3
  84. package/src/runtime/type-checks/isTrue.ts +0 -31
  85. package/src/runtime/type-checks/isUndefined.ts +0 -33
  86. package/src/runtime/type-checks/startsWith.ts +0 -107
  87. package/src/runtime/valueTypes.ts +0 -48
  88. package/src/types/Api.ts +0 -16
  89. package/src/types/Constructor.ts +0 -5
  90. package/src/types/EnumValues.ts +0 -14
  91. package/src/types/ExpandRecursively.ts +0 -12
  92. package/src/types/FunctionType.ts +0 -19
  93. package/src/types/If.ts +0 -10
  94. package/src/types/Include.ts +0 -18
  95. package/src/types/KeyedRecord.ts +0 -21
  96. package/src/types/Keys.ts +0 -26
  97. package/src/types/Length.ts +0 -8
  98. package/src/types/Mutable.ts +0 -8
  99. package/src/types/Narrowable.ts +0 -5
  100. package/src/types/Not.ts +0 -13
  101. package/src/types/Numeric.ts +0 -20
  102. package/src/types/Opaque.ts +0 -11
  103. package/src/types/README.md +0 -3
  104. package/src/types/Retain.ts +0 -16
  105. package/src/types/SimplifyObject.ts +0 -12
  106. package/src/types/Transformer.ts +0 -15
  107. package/src/types/TypeGuard.ts +0 -7
  108. package/src/types/Where.ts +0 -40
  109. package/src/types/alphabetic/AllCaps.ts +0 -15
  110. package/src/types/alphabetic/CamelCase.ts +0 -3
  111. package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
  112. package/src/types/alphabetic/CapitalizeWords.ts +0 -9
  113. package/src/types/alphabetic/Cardinality.ts +0 -80
  114. package/src/types/alphabetic/DashToSnake.ts +0 -3
  115. package/src/types/alphabetic/DashUppercase.ts +0 -19
  116. package/src/types/alphabetic/Dasherize.ts +0 -23
  117. package/src/types/alphabetic/EnsureLeading.ts +0 -24
  118. package/src/types/alphabetic/EnsureTrailing.ts +0 -24
  119. package/src/types/alphabetic/HasUppercase.ts +0 -16
  120. package/src/types/alphabetic/IsCapitalized.ts +0 -18
  121. package/src/types/alphabetic/KebabCase.ts +0 -13
  122. package/src/types/alphabetic/LowerAllCaps.ts +0 -5
  123. package/src/types/alphabetic/PascalCase.ts +0 -29
  124. package/src/types/alphabetic/PathJoin.ts +0 -54
  125. package/src/types/alphabetic/Pluralize.ts +0 -112
  126. package/src/types/alphabetic/SnakeCase.ts +0 -27
  127. package/src/types/alphabetic/StripLeading.ts +0 -23
  128. package/src/types/alphabetic/StripTrailing.ts +0 -23
  129. package/src/types/alphabetic/Url.ts +0 -29
  130. package/src/types/alphabetic/alpha-characters.ts +0 -81
  131. package/src/types/alphabetic/index.ts +0 -32
  132. package/src/types/append-types.ts +0 -10
  133. package/src/types/boolean-logic/EndsWith.ts +0 -40
  134. package/src/types/boolean-logic/Extends.ts +0 -22
  135. package/src/types/boolean-logic/HasParameters.ts +0 -21
  136. package/src/types/boolean-logic/Includes.ts +0 -33
  137. package/src/types/boolean-logic/IsLiteral.ts +0 -101
  138. package/src/types/boolean-logic/IsScalar.ts +0 -20
  139. package/src/types/boolean-logic/IsUndefined.ts +0 -20
  140. package/src/types/boolean-logic/Or.ts +0 -12
  141. package/src/types/boolean-logic/StartsWith.ts +0 -42
  142. package/src/types/boolean-logic/TypeDefault.ts +0 -58
  143. package/src/types/boolean-logic/array.ts +0 -57
  144. package/src/types/boolean-logic/boolean.ts +0 -84
  145. package/src/types/boolean-logic/equivalency.ts +0 -15
  146. package/src/types/boolean-logic/index.ts +0 -14
  147. package/src/types/boolean-logic/object.ts +0 -30
  148. package/src/types/boolean-logic/string.ts +0 -21
  149. package/src/types/dictionary/DictChangeValue.ts +0 -34
  150. package/src/types/dictionary/DictPartialApplication.ts +0 -30
  151. package/src/types/dictionary/DictPrependWithFn.ts +0 -23
  152. package/src/types/dictionary/DictReturnValues.ts +0 -27
  153. package/src/types/dictionary/Get.ts +0 -14
  154. package/src/types/dictionary/MapTo.ts +0 -428
  155. package/src/types/dictionary/MutableProps.ts +0 -19
  156. package/src/types/dictionary/RequireProps.ts +0 -15
  157. package/src/types/dictionary/SameKeys.ts +0 -11
  158. package/src/types/dictionary/index.ts +0 -21
  159. package/src/types/dictionary/props.ts +0 -145
  160. package/src/types/fluent/fluent.ts +0 -61
  161. package/src/types/fluent/index.ts +0 -12
  162. package/src/types/functions/FinalReturn.ts +0 -12
  163. package/src/types/functions/LogicFunction.ts +0 -4
  164. package/src/types/functions/index.ts +0 -13
  165. package/src/types/index.ts +0 -49
  166. package/src/types/kv/DictFromKv.ts +0 -3
  167. package/src/types/kv/KeyValue.ts +0 -12
  168. package/src/types/kv/KvFrom.ts +0 -8
  169. package/src/types/kv/KvTuple.ts +0 -14
  170. package/src/types/kv/index.ts +0 -15
  171. package/src/types/lists/AfterFirst.ts +0 -10
  172. package/src/types/lists/ConvertAndMap.ts +0 -152
  173. package/src/types/lists/FilterTuple.ts +0 -20
  174. package/src/types/lists/First.ts +0 -8
  175. package/src/types/lists/FirstString.ts +0 -4
  176. package/src/types/lists/Split.ts +0 -21
  177. package/src/types/lists/UniqueForProp.ts +0 -18
  178. package/src/types/lists/index.ts +0 -18
  179. package/src/types/literal-unions/OptRequired.ts +0 -4
  180. package/src/types/literal-unions/index.ts +0 -1
  181. package/src/types/maybe.ts +0 -9
  182. package/src/types/ruleset-types.ts +0 -76
  183. package/src/types/runtime.ts +0 -39
  184. package/src/types/string-literals/Break.ts +0 -22
  185. package/src/types/string-literals/Concat.ts +0 -9
  186. package/src/types/string-literals/LeftWhitespace.ts +0 -13
  187. package/src/types/string-literals/Replace.ts +0 -17
  188. package/src/types/string-literals/RightWhitespace.ts +0 -13
  189. package/src/types/string-literals/StringLength.ts +0 -34
  190. package/src/types/string-literals/Trim.ts +0 -15
  191. package/src/types/string-literals/TrimLeft.ts +0 -14
  192. package/src/types/string-literals/TrimRight.ts +0 -14
  193. package/src/types/string-literals/form-fields.ts +0 -15
  194. package/src/types/string-literals/index.ts +0 -21
  195. package/src/types/tuples/DictArray.ts +0 -21
  196. package/src/types/tuples/FirstKey.ts +0 -10
  197. package/src/types/tuples/FirstKeyValue.ts +0 -9
  198. package/src/types/tuples/FirstOfEach.ts +0 -13
  199. package/src/types/tuples/FromDictArray.ts +0 -14
  200. package/src/types/tuples/SecondOfEach.ts +0 -13
  201. package/src/types/tuples/index.ts +0 -17
  202. package/src/types/type-conversion/TupleToUnion.ts +0 -9
  203. package/src/types/type-conversion/UnionToIntersection.ts +0 -9
  204. package/src/types/type-conversion/UnionToTuple.ts +0 -20
  205. package/src/types/type-conversion/Widen.ts +0 -22
  206. package/src/types/type-conversion/index.ts +0 -16
  207. package/src/types/type-testing.ts +0 -14
  208. package/tests/CamelCase-spec.ts +0 -20
  209. package/tests/Configurator-spec.hold +0 -106
  210. package/tests/ExplicitFunction-spec.ts +0 -50
  211. package/tests/IncludeAndRetain-spec.ts +0 -67
  212. package/tests/Includes-spec.ts +0 -36
  213. package/tests/KebabCase-spec.ts +0 -21
  214. package/tests/PascalCase-spec.ts +0 -22
  215. package/tests/Pluralize-spec.ts +0 -23
  216. package/tests/SnakeCase-spec.ts +0 -21
  217. package/tests/Where.spec.ts +0 -38
  218. package/tests/arrayToKeyLookup-spec.ts +0 -17
  219. package/tests/arrayToObject-spec.ts +0 -115
  220. package/tests/boolean-logic/Contains.test.ts +0 -55
  221. package/tests/boolean-logic/HasParameters.ts +0 -29
  222. package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
  223. package/tests/boolean-logic/boolean.spec.ts +0 -21
  224. package/tests/boolean-logic/filter.spec.ts +0 -52
  225. package/tests/constructor.spec.ts +0 -42
  226. package/tests/createFnWithProps.spec.ts +0 -14
  227. package/tests/data/SimpleTable.hold +0 -21
  228. package/tests/data/index.ts +0 -12
  229. package/tests/data/playlist.hold +0 -25
  230. package/tests/data/song.hold +0 -23
  231. package/tests/defineType-spec.ts +0 -57
  232. package/tests/dictionary/DictChangeValue.test.ts +0 -30
  233. package/tests/dictionary/DictPartialApplication.test.ts +0 -43
  234. package/tests/dictionary/DictReturnValues.test.ts +0 -36
  235. package/tests/dictionary/Get.spec.ts +0 -28
  236. package/tests/dictionary/IntersectingKeys.test.ts +0 -42
  237. package/tests/dictionary/MutableProps.test.ts +0 -30
  238. package/tests/dictionary/OptionalKeys.test.ts +0 -24
  239. package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
  240. package/tests/dictionary/RequireProps.test.ts +0 -21
  241. package/tests/dictionary/RequiredKeys.test.ts +0 -53
  242. package/tests/dictionary/TypeDefault.test.ts +0 -76
  243. package/tests/dictionary/mapTo.test.ts +0 -388
  244. package/tests/dictionary/merge.test.ts +0 -41
  245. package/tests/dictionaryTransform-spec.ts +0 -280
  246. package/tests/ifTypeOf-spec.ts +0 -191
  247. package/tests/kv/KeyValue-spec.ts +0 -22
  248. package/tests/kv/SameKeys-spec.ts +0 -35
  249. package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
  250. package/tests/kv/entries-spec.ts +0 -65
  251. package/tests/kv/keys.spec.ts +0 -66
  252. package/tests/kv/kv-spec.ts +0 -20
  253. package/tests/lists/First.test.ts +0 -43
  254. package/tests/lists/Length.test.ts +0 -19
  255. package/tests/lists/Split.test.ts +0 -29
  256. package/tests/lists/UniqueForProp.spec.ts +0 -59
  257. package/tests/lists/asArray.test.ts +0 -109
  258. package/tests/lists/dictArr.test.ts +0 -110
  259. package/tests/literal-spec.ts +0 -82
  260. package/tests/literals/AllCaps.spec.ts +0 -33
  261. package/tests/literals/CamelCase.spec.ts +0 -109
  262. package/tests/literals/Dasherize.spec.ts +0 -107
  263. package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
  264. package/tests/literals/HasUppercase.spec.ts +0 -33
  265. package/tests/literals/PascalCase.spec.ts +0 -109
  266. package/tests/literals/PathJoin.test.ts +0 -111
  267. package/tests/literals/SnakeCase.spec.ts +0 -109
  268. package/tests/literals/box.test.ts +0 -85
  269. package/tests/literals/whitespace-capture.spec.ts +0 -60
  270. package/tests/mapValues-spec.ts +0 -50
  271. package/tests/props-spec.ts +0 -234
  272. package/tests/runtime/condition.spec.ts +0 -19
  273. package/tests/runtime/if-is.spec.ts +0 -390
  274. package/tests/runtime/map-and-convert.test.ts +0 -31
  275. package/tests/runtime/type.spec.ts +0 -190
  276. package/tests/strArrayToDict-spec.ts +0 -40
  277. package/tests/tuples/TupleToUnion.spec.ts +0 -20
  278. package/tests/withValue.spec.ts +0 -173
  279. package/tsconfig.json +0 -36
  280. package/vitest.config.ts +0 -17
@@ -1,98 +0,0 @@
1
- import { AfterFirst, HasParameters, Narrowable } from "src/types";
2
- import { First } from "src/types/lists/First";
3
- import { keys } from "../keys";
4
- import { AnyFunction } from "../type-checks";
5
-
6
- export interface Box<T> {
7
- __kind: "box";
8
- value: T;
9
- /**
10
- * Unbox the boxed value in the narrowest possible type.
11
- *
12
- * **note:** if the boxed value is a function with parameters you
13
- * can pass the parameters directly into the `b.unbox(params)` call.
14
- */
15
- unbox: HasParameters<Box<T>["value"]> extends true
16
- ? Box<T>["value"] extends AnyFunction
17
- ? Box<T>["value"] extends (...args: infer A) => infer R
18
- ? <N extends A>(...args: N) => R
19
- : () => ReturnType<T>
20
- : () => T
21
- : () => T;
22
- }
23
-
24
- export type BoxValue<T extends Box<any>> = T extends Box<infer V> ? V : never;
25
-
26
- export type BoxedFnParams<T extends Box<any>> = T extends Box<infer V>
27
- ? V extends (...args: infer A) => any
28
- ? A
29
- : []
30
- : [];
31
-
32
- export type BoxedReturn<T extends Box<any>> = T extends Box<infer V>
33
- ? V extends Function
34
- ? ReturnType<T["value"]>
35
- : T["value"]
36
- : never;
37
-
38
- export type NarrowBox<T> = <
39
- N extends BoxedFnParams<Box<T>> | First<BoxedFnParams<Box<T>>>
40
- >() => N extends BoxedFnParams<Box<T>>
41
- ? T extends (...args: any[]) => any
42
- ? (...args: N) => Box<T>["unbox"]
43
- : never
44
- : (first: N, ...rest: AfterFirst<BoxedFnParams<Box<T>>>) => BoxedReturn<Box<T>>;
45
-
46
- /**
47
- * Allows a value with an inner-type to be boxed into a dictionary
48
- * so that this type inference is preserved with the help of
49
- * [instantiation expressions](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#instantiation-expressions).
50
- *
51
- * NOTE: this feature is immature at best right now
52
- */
53
- export function box<T extends Narrowable>(value: T): Box<T> {
54
- const rtn: Box<T> = {
55
- __kind: "box",
56
- value,
57
- unbox: (<P extends any[], R extends Narrowable>(...p: P): R => {
58
- return typeof value === "function" ? value(...p) : value;
59
- }) as Box<T>["unbox"],
60
- };
61
-
62
- return rtn;
63
- }
64
-
65
- export function isBox(thing: Narrowable): thing is Box<any> {
66
- return (
67
- typeof thing === "object" && "__kind" in (thing as object) && (thing as any).__kind === "box"
68
- );
69
- }
70
-
71
- /**
72
- * **boxDictionaryValues**(dict)
73
- *
74
- * Runtime utility which boxes each value in a dictionary
75
- */
76
- export function boxDictionaryValues<T extends {}>(dict: T) {
77
- return keys(dict).reduce(
78
- (acc, key) => ({ ...acc, [key]: box(dict[key]) }),
79
- {} as {
80
- [K in keyof T]: Box<T[K]>;
81
- }
82
- );
83
- }
84
-
85
- export type Unbox<T> = T extends Box<infer U> ? U : T;
86
-
87
- //TODO: it would make sense in the future to use `b.unbox` instead
88
- // of `b.value` to keep consistent but currently value behaves more
89
- // consistently and with somewhat stronger typing
90
-
91
- /**
92
- * **unbox**(maybeBox)
93
- *
94
- * Unboxes a value if it was a box; otherwise it leaves _as is_.
95
- */
96
- export function unbox<T>(val: T): Unbox<T> {
97
- return isBox(val) ? val.value : val;
98
- }
@@ -1,20 +0,0 @@
1
- import { ExpandRecursively } from "src/types/ExpandRecursively";
2
- import { Narrowable } from "src/types/Narrowable";
3
-
4
- /**
5
- * Build a _type_ from two run-time dictionaries.
6
- *
7
- * 1. The _first_ -- which is optional -- is interpreted as a _literal_ type definition
8
- * 2. The _second_ dictionary is interpreted as a "wide" definition of prop types
9
- */
10
- export function defineType<N extends Narrowable, TLiteral extends Record<string, N>>(
11
- literal: TLiteral = {} as TLiteral
12
- ) {
13
- /**
14
- * Add any key/value pairs which you want to have _wide_ types associated;
15
- * literal types are defined already and stated above.
16
- */
17
- return <TWide extends object>(wide: TWide = {} as TWide) => {
18
- return (literal ? { ...wide, ...literal } : wide) as ExpandRecursively<TWide & TLiteral>;
19
- };
20
- }
@@ -1,17 +0,0 @@
1
- import { EnsureLeading } from "src/types/alphabetic";
2
-
3
- /**
4
- * **ensureLeading**(content, strip)
5
- *
6
- * Runtime utility which ensures that last part of a string -- `content` -- has the
7
- * substring `ensure` at the end and adds it if not present.
8
- */
9
- export function ensureLeading<T extends string, U extends string>(
10
- content: T,
11
- ensure: U
12
- ): EnsureLeading<T, U> {
13
- return (
14
- //
15
- (content.startsWith(ensure) ? content : `${ensure}${content}`) as EnsureLeading<T, U>
16
- );
17
- }
@@ -1,17 +0,0 @@
1
- import { EnsureTrailing } from "../../types/alphabetic/EnsureTrailing";
2
-
3
- /**
4
- * **ensureTrailing**(content, strip)
5
- *
6
- * Runtime utility which ensures that last part of a string -- `content` -- has the
7
- * substring `ensure` at the end and adds it if not present.
8
- */
9
- export function ensureTrailing<T extends string, U extends string>(
10
- content: T,
11
- ensure: U
12
- ): EnsureTrailing<T, U> {
13
- return (
14
- //
15
- (content.endsWith(ensure) ? content : `${content}${ensure}`) as EnsureTrailing<T, U>
16
- );
17
- }
@@ -1,12 +0,0 @@
1
- import { Narrowable } from "src/types/Narrowable";
2
-
3
- /**
4
- * An identity function for any type, with the goal of preserving literal type information
5
- * whereever possible.
6
- */
7
- export const identity = <
8
- N extends Narrowable,
9
- T extends Record<any, N> | number | string | boolean | symbol | undefined | null
10
- >(
11
- v: T
12
- ) => v;
@@ -1,23 +0,0 @@
1
- // #autoindex
2
- // #region auto-indexed files
3
- // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
- // hash-code: 7a22bbbc
5
-
6
- // file exports
7
- export * from "./ExplicitFunction";
8
- export * from "./arrayToObject";
9
- export * from "./box";
10
- export * from "./defineType";
11
- export * from "./identity";
12
- export * from "./literal";
13
- export * from "./stripTrailing";
14
- export * from "./ensureTrailing";
15
- export * from "./ensureLeading";
16
- export * from "./pathJoin";
17
- export * from "./Suggest";
18
- export * from "./wide";
19
-
20
- // #endregion auto-indexed files
21
-
22
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
23
- // for more info
@@ -1,48 +0,0 @@
1
- /* eslint-disable no-use-before-define */
2
-
3
- import { Narrowable } from "src/types/Narrowable";
4
-
5
- /**
6
- * Takes an object as input --which has an `id` property and returns it as the same
7
- * run-time content but with the _type_ of the `id` property being forced to a literal type
8
- */
9
- export function idLiteral<T extends { id: I }, I extends PropertyKey>(o: T): T & { id: T["id"] } {
10
- return { ...o, id: o.id };
11
- }
12
-
13
- /**
14
- * Takes an object as input --which has an `name` property and returns it as the same
15
- * run-time content but with the _type_ of the `name` property being forced to a literal type
16
- */
17
- export function nameLiteral<T extends { name: I }, I extends PropertyKey>(
18
- o: T
19
- ): T & { name: T["name"] } {
20
- return o;
21
- }
22
-
23
- /**
24
- * Takes an object as input --which has an `kind` property and returns it as the same
25
- * run-time content but with the _type_ of the `kind` property being forced to a literal type
26
- */
27
- export function kindLiteral<T extends { kind: I }, I extends PropertyKey>(
28
- o: T
29
- ): T & { kind: T["kind"] } {
30
- return o;
31
- }
32
-
33
- export function idTypeGuard<T extends { id: I }, I extends PropertyKey>(
34
- _o: T
35
- ): _o is T & { id: I } {
36
- return true;
37
- }
38
-
39
- /**
40
- * Takes an object as input and infers the narrow literal types of the property
41
- * values on the object.
42
- *
43
- * > Note: this addresses this [a known TS gap](https://github.com/microsoft/TypeScript/issues/30680).
44
- * > Hopefully at some point this will be addressed in the language.
45
- */
46
- export function literal<N extends Narrowable, T extends Record<keyof T, N>>(obj: T) {
47
- return obj;
48
- }
@@ -1,33 +0,0 @@
1
- import { PathJoin } from "src/types/alphabetic/PathJoin";
2
- import { ensureLeading } from "./ensureLeading";
3
- import { ensureTrailing } from "./ensureTrailing";
4
- import { stripLeading } from "./stripLeading";
5
- import { stripTrailing } from "./stripTrailing";
6
-
7
- /**
8
- * **pathJoin**`<T,U>(begin, ...rest)`
9
- *
10
- * Run time utility which joins two strings together with
11
- * the intent to have them be divided by a Posix `/` character
12
- * appropriate for Unix file paths and URLs.
13
- *
14
- * **note:** to support more than two paths being joined there
15
- * is now the ability to add a tuple of paths into the _rest_
16
- * parameter
17
- */
18
- export function pathJoin<T extends string, U extends readonly string[]>(
19
- begin: T,
20
- ...rest: U
21
- ): PathJoin<T, U> {
22
- const start = rest.length > 0 ? ensureTrailing(begin, "/") : begin;
23
- const end = rest.length > 0 ? ensureLeading(rest.slice(-1)[0], "/") : "";
24
- const middle =
25
- rest.length > 1
26
- ? rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"'))
27
- : [];
28
- const midString = stripTrailing(stripLeading(middle.join("/"), "/"), "/");
29
-
30
- return (
31
- rest.length > 1 ? `${start}${midString}${end}` : `${start}${stripLeading(end, "/")}`
32
- ) as PathJoin<T, U>;
33
- }
@@ -1,15 +0,0 @@
1
- import { StripLeading } from "src/types/alphabetic/StripLeading";
2
-
3
- export function stripLeading<T extends string, U extends string>(
4
- content: T,
5
- strip: U
6
- ): StripLeading<T, U> {
7
- const re = new RegExp(`^${strip}(.*)`);
8
- return (
9
- content.startsWith(strip)
10
- ? // starts with
11
- content.replace(re, "$1")
12
- : // does not
13
- content
14
- ) as StripLeading<T, U>;
15
- }
@@ -1,15 +0,0 @@
1
- import { StripTrailing } from "src/types/alphabetic/StripTrailing";
2
-
3
- /**
4
- * **stripTrailing**(content, strip)
5
- *
6
- * Runtime utility which ensures that last part of a string has substring
7
- * removed if it exists and that strong typing is preserved.
8
- */
9
- export function stripTrailing<T extends string, U extends string>(
10
- content: T,
11
- strip: U
12
- ): StripTrailing<T, U> {
13
- const re = new RegExp(`(.*)${strip}$`);
14
- return (content.endsWith(strip) ? content.replace(re, "$1") : content) as StripTrailing<T, U>;
15
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * **wide**
3
- *
4
- * Provides a dictionary of _wide_ types
5
- */
6
- export const wide = {
7
- boolean: false as boolean,
8
- string: "" as string,
9
- number: 0 as number,
10
- symbol: Symbol() as Symbol,
11
- null: null,
12
- undefined: undefined,
13
- } as const;
@@ -1,42 +0,0 @@
1
- /* eslint-disable no-use-before-define */
2
-
3
- import { Narrowable } from "src/types/Narrowable";
4
-
5
- // TODO: get ruleset functionality working!
6
-
7
- // const dynamicRuleState = {
8
- // state: <TState extends any>() => {
9
- // return {
10
- // rules: <TRules extends DynamicRuleSet<TState, any>>(rules: TRules) => {
11
- // const dynRules = rules();
12
- // }
13
- // };
14
- // }
15
- // };
16
-
17
- /**
18
- * **ruleSet**
19
- *
20
- * Defines a ruleset composed of _dynamic_ and _static_ boolean operators.
21
- *
22
- * - the first function call defines _dynamic_ props (_optional_)
23
- * - the second function call defines static values
24
- *
25
- * ```ts
26
- * const rs = ruleSet(
27
- * r => r.state()( { maybe: r => r.extends({ foo: 1 }) })
28
- * )(
29
- * { color: true, age: false }
30
- * );
31
- * ```
32
- */
33
- export function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(
34
- defn?: TState
35
- ) {
36
- // return <
37
- // TStatic extends { [K in keyof TStatic]: Readonly<true | false> },
38
- // >(rules: TStatic) => {
39
- // return rules;
40
- // };
41
- return defn;
42
- }
@@ -1,3 +0,0 @@
1
- # Runtime Utilities
2
-
3
- A set of utilities which help to keep the runtime types and the _typings_ in step with one another.
@@ -1,13 +0,0 @@
1
- import { Narrowable } from "src/types/Narrowable";
2
-
3
- export type Condition<TInput extends Narrowable, TResult extends boolean> = (
4
- input: TInput
5
- ) => TResult;
6
-
7
- export const condition = <TInput extends Narrowable, C extends Condition<Narrowable, boolean>>(
8
- c: C,
9
- input: TInput
10
- ) => {
11
- // const v
12
- return c(input);
13
- };
@@ -1,16 +0,0 @@
1
- // #autoindex
2
- // #region auto-indexed files
3
- // index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
4
- // hash-code: 687852c8
5
-
6
- // file exports
7
- export * from "./condition";
8
- export * from "./type";
9
- export * from "./withValue";
10
- // directory exports
11
- export * from "../type-checks/index";
12
-
13
- // #endregion auto-indexed files
14
-
15
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
16
- // for more info
@@ -1,127 +0,0 @@
1
- import { FunctionType } from "src/types/FunctionType";
2
- import { Narrowable } from "src/types/Narrowable";
3
- import { TypeGuard } from "src/types/TypeGuard";
4
- import {
5
- isString,
6
- isBoolean,
7
- isNumber,
8
- isFunction,
9
- isSymbol,
10
- isNull,
11
- isTrue,
12
- isFalse,
13
- isUndefined,
14
- isObject,
15
- isArray,
16
- ObjectType,
17
- } from "../type-checks";
18
- // import { isLiteral } from "./conditions/isLiteral";
19
-
20
- export type Type<T extends any, V extends Function> = {
21
- name: string;
22
- type: T;
23
- typeGuard: TypeGuard<T>;
24
- is: V;
25
- };
26
-
27
- export const typeApi = () =>
28
- ({
29
- string: {
30
- name: "string",
31
- type: "" as string,
32
- typeGuard: (v: unknown): v is string => isString(v),
33
- is: isString,
34
- } as Type<string, typeof isString>,
35
- boolean: {
36
- name: "boolean",
37
- type: true as boolean,
38
- typeGuard: (v: unknown): v is boolean => isBoolean(v),
39
- is: isBoolean,
40
- } as Type<boolean, typeof isBoolean>,
41
- number: {
42
- name: "number",
43
- type: 1 as number,
44
- typeGuard: (v: unknown): v is number => isNumber(v),
45
- is: isNumber,
46
- } as Type<number, typeof isNumber>,
47
- function: {
48
- name: "function",
49
- type: Function as FunctionType,
50
- typeGuard: (v: unknown): v is FunctionType => isFunction(v),
51
- is: isFunction,
52
- } as Type<FunctionType, typeof isFunction>,
53
- null: {
54
- name: "null",
55
- type: null as null,
56
- typeGuard: (v: unknown): v is null => isNull(v),
57
- is: isNull,
58
- } as Type<null, typeof isNull>,
59
- symbol: {
60
- name: "symbol",
61
- type: Symbol() as Symbol,
62
- typeGuard: (v: unknown): v is Symbol => isSymbol(v),
63
- is: isSymbol,
64
- } as Type<symbol, typeof isSymbol>,
65
- undefined: {
66
- name: "undefined",
67
- type: undefined as undefined,
68
- typeGuard: (v: unknown): v is undefined => isUndefined(v),
69
- is: isUndefined,
70
- } as Type<undefined, typeof isUndefined>,
71
-
72
- true: {
73
- name: "true",
74
- type: true as true,
75
- typeGuard: (v: Narrowable): v is true => isTrue(v),
76
- is: isTrue,
77
- } as Type<true, typeof isTrue>,
78
- false: {
79
- name: "false",
80
- type: false as false,
81
- typeGuard: (v: unknown): v is false => isFalse(v),
82
- is: isFalse,
83
- } as Type<false, typeof isFalse>,
84
-
85
- object: {
86
- name: "object",
87
- type: {},
88
- typeGuard: (v: unknown): v is ObjectType => isObject(v),
89
- is: isObject,
90
- } as Type<ObjectType, typeof isObject>,
91
-
92
- array: {
93
- name: "array",
94
- type: {} as any[],
95
- typeGuard: (v: unknown): v is Object => isArray(v),
96
- is: isObject,
97
- } as Type<any[], typeof isArray>,
98
-
99
- // literal: <T extends Readonly<string>>(...literalValues: T[]) =>
100
- // ({
101
- // name: "literal",
102
- // type: v as T,
103
- // typeGuard: (v: unknown): v is T => isLiteral(...literalValues)(v),
104
- // is: isLiteral(...literalValues)(v),
105
- // } as Type<T, typeof isLiteral>),
106
- } as const);
107
-
108
- export type TypeApi = ReturnType<typeof typeApi>;
109
-
110
- export function isType<T extends any, V extends Function>(t: unknown): t is Type<T, V> {
111
- return (
112
- typeof t === "object" && ["name", "type", "is"].every((i) => Object.keys(t as {}).includes(i))
113
- );
114
- }
115
-
116
- export type TypeDefinition<T extends any, V extends Function> = (defn: TypeApi) => Type<T, V>;
117
-
118
- export function type<T extends any, V extends Function>(fn: TypeDefinition<T, V>) {
119
- const result = fn(typeApi());
120
- if (!isType(result)) {
121
- throw new Error(
122
- `When using type(), the callback passed in returned an invalid type! Value returned was: ${result}`
123
- );
124
- }
125
-
126
- return result;
127
- }
@@ -1,39 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
-
3
- import { WithValue } from "src/types/dictionary";
4
- import { ExpandRecursively } from "src/types/ExpandRecursively";
5
- import { Narrowable } from "src/types/Narrowable";
6
- import { entries } from "../dictionary/entries";
7
- import { type, TypeDefinition } from "./type";
8
-
9
- /**
10
- * **withValue**
11
- *
12
- * Reduces a dictionary object -- in both _type_ and _run-time_ structure -- to only those
13
- * key/value pairs which have a specified value. For instance:
14
- *
15
- * ```ts
16
- * const obj = { foo: 1, bar: 2, message: "hi there" };
17
- * // { message: "hi there" }
18
- * const onlyStrings = withValue(t => t.string)(obj);
19
- * // { foo: 1 }
20
- * const justOne = withValue(t => t.literal(1))(obj);
21
- * ```
22
- *
23
- * Note: _often useful to provide run-time type profiles with the_ `inferredType` _utility_
24
- */
25
- export function withValue<T extends any, V extends Function>(td: TypeDefinition<T, V>) {
26
- return <N extends Narrowable, R extends Record<string, N>>(obj: R) => {
27
- const t = type(td);
28
- // type Type = typeof t.type;
29
-
30
- return Object.fromEntries(
31
- [...entries(obj)].filter(([_key, value]) => {
32
- // runtime check
33
- // const tg = <X extends { [key]: any }>(value: X): value is Extract<X, { [key]: Type }> =>
34
- // t.is(value);
35
- return t.typeGuard(value);
36
- })
37
- ) as unknown as ExpandRecursively<WithValue<T, R>>;
38
- };
39
- }
@@ -1,76 +0,0 @@
1
- import { ExpandRecursively } from "src/types/ExpandRecursively";
2
-
3
- type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4
- function omit<T extends {}, K extends Array<keyof T>>(obj: T, ...removals: K) {
5
- const untyped = removals as Array<unknown>;
6
- return Object.fromEntries(Object.entries(obj).filter(([key]) => !untyped.includes(key))) as Omit<
7
- T,
8
- K[number]
9
- >;
10
- }
11
-
12
- export interface IConfigurator<C = {}> {
13
- set<V, K extends string, KV = { [U in K]: V }>(
14
- key: K,
15
- value: V
16
- ): asserts this is IConfigurator<ExpandRecursively<C & KV>>;
17
- remove<K extends string & keyof C>(
18
- key: K
19
- ): asserts this is IConfigurator<ExpandRecursively<Omit<C, K>>>;
20
- done(): C;
21
- }
22
-
23
- /**
24
- * **Configurator**
25
- *
26
- * This function provides a configurator which uses TypeScript assertions
27
- * to narrow the scope of variables. Using type assertions though means we
28
- * can't also return values and therefore a _fluent_ API style is not possible.
29
- *
30
- * Note: this approach does require, that you explicitly use the `IConfigurator`
31
- * interface exported by this library. Without it you'd getting annoying TS errors
32
- * on every call to `set()` but adding it is simple enough:
33
- *
34
- * ```ts
35
- * import { Configurator, IConfigurator } from "inferred-types";
36
- * const config: IConfigurator = Configurator();
37
- * ```
38
- *
39
- * If you want to specify some guideline params which you expect to be set, you
40
- * can add them like so:
41
- *
42
- * ```ts
43
- * export type IExpected = { foo: number, bar: string };
44
- * const config: IConfigurator<IExpected> = Configurator<IExpected>();
45
- * ```
46
- *
47
- * This configuration will ensure that `foo` and `bar` will be seen as optional
48
- * parameters. If you set them they will stop being optional.
49
- */
50
- export function Configurator() {
51
- let configuration = () => ({});
52
-
53
- const api = <C extends {}>(): IConfigurator<C> => {
54
- return {
55
- set<V, K extends string, KV = { [U in K]: V }>(key: K, value: V) {
56
- const keyValue = { [key]: value as V } as unknown as KV;
57
- const config = configuration() as C;
58
- const updated = { ...config, ...keyValue };
59
-
60
- configuration = (): C & KV => updated;
61
- return updated;
62
- },
63
- remove<K extends string & keyof C>(key: K) {
64
- const config = configuration() as C;
65
- const updated = omit(config, key) as ExpandRecursively<Omit<C, K>>;
66
- configuration = (): ExpandRecursively<Omit<C, K>> => updated;
67
- return updated;
68
- },
69
- done() {
70
- return configuration() as C;
71
- },
72
- };
73
- };
74
-
75
- return api();
76
- }