inferred-types 0.37.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/dist/index.d.ts +2745 -0
  2. package/dist/index.js +854 -0
  3. package/package.json +6 -12
  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,25 +0,0 @@
1
- export function Model<N extends string, _R extends {} = {}, _O extends {} = {}>(name: N) {
2
- // let tg: TypeGuard<any> = (_input: unknown) => {
3
- // throw new Error(`No typeguard was assigned to the model ${name}`);
4
- // };
5
-
6
- return {
7
- required<P extends string>(_prop: P) {
8
- return Model(name);
9
- },
10
- optional<P extends string>(_prop: P) {
11
- return Model(name);
12
- },
13
- // typeGuard<TG extends TypeGuard<any>>(typeguard: TG) {
14
- // tg = typeguard;
15
- // return Model(name);
16
- // },
17
- done() {
18
- return {
19
- __model__: name,
20
- __kind__: "model" as const,
21
- // __tg__: tg,
22
- };
23
- },
24
- };
25
- }
@@ -1,15 +0,0 @@
1
- import { DomainName, Ipv4, NetworkProtocol, RelativeUrl } from "src/types";
2
-
3
- export const url = <
4
- Proto extends NetworkProtocol,
5
- Site extends DomainName | Ipv4,
6
- Path extends RelativeUrl
7
- >(
8
- ...args: [Proto, Site, Path]
9
- ) => {
10
- if (args.length === 3) {
11
- return `${args[0]}://${args[1]}/${args[2]}`;
12
- } else {
13
- return args[0];
14
- }
15
- };
@@ -1,15 +0,0 @@
1
- import { LogicFunction } from "src/types/functions";
2
-
3
- /**
4
- * Groups a number of "logic functions" together by combining their results using
5
- * the logical **AND** operator.
6
- *
7
- * **Note:** a "logic function" is any function which returns a boolean
8
- */
9
- export const and = <T extends any[]>(...ops: readonly LogicFunction<T>[]): LogicFunction<T> => {
10
- const fn: LogicFunction<T> = (...args: T) => {
11
- return [...ops].every((i) => i(...args));
12
- };
13
-
14
- return fn;
15
- };
@@ -1,267 +0,0 @@
1
- import { asArray } from "../lists/asArray";
2
-
3
- // string filters
4
- export type FilterStarts = {
5
- /** one or more string which the value is allowed to start with */
6
- startsWith: string | string[];
7
- };
8
- export type FilterIs = {
9
- /** whether a string _**is**_ of a particular value */
10
- is: string | string[];
11
- };
12
- export type FilterEnds = { endsWith: string | string[] };
13
- export type FilterContains = {
14
- /** whether any of the strings specified are _contained_ in the value */
15
- contains: string | string[];
16
- };
17
-
18
- // numeric filters
19
- export type FilterEquals = {
20
- /** one or more values which _equal_ the value passed in */
21
- equals: number | number[];
22
- };
23
- export type FilterNotEqual = {
24
- /** one or more values which ALL _do not equal_ the value passed in */
25
- notEqual: number | number[];
26
- };
27
- export type FilterGreaterThan = {
28
- /** the incoming value is greater than this value */
29
- greaterThan: number;
30
- };
31
- export type FilterLessThan = {
32
- /** the incoming value is less than this value */
33
- lessThan: number;
34
- };
35
-
36
- export type StringFilter =
37
- | FilterIs
38
- | FilterStarts
39
- | FilterEnds
40
- | FilterContains
41
- | (FilterStarts & FilterEnds)
42
- | (FilterStarts & FilterContains)
43
- | (FilterEnds & FilterContains)
44
- | (FilterStarts & FilterEnds & FilterContains);
45
-
46
- export type NumericFilter =
47
- | FilterEquals
48
- | FilterNotEqual
49
- | FilterGreaterThan
50
- | FilterLessThan
51
- | (FilterEquals & FilterNotEqual)
52
- | (FilterEquals & FilterGreaterThan)
53
- | (FilterEquals & FilterLessThan)
54
- | (FilterNotEqual & FilterGreaterThan)
55
- | (FilterNotEqual & FilterLessThan)
56
- | (FilterGreaterThan & FilterLessThan)
57
- | (FilterEquals & FilterGreaterThan & FilterLessThan)
58
- | (FilterNotEqual & FilterGreaterThan & FilterLessThan)
59
- | (FilterEquals & FilterNotEqual & FilterGreaterThan & FilterLessThan);
60
-
61
- export type FilterDefn = StringFilter | NumericFilter;
62
-
63
- // NOT filter
64
- export type NotFilter = {
65
- /**
66
- * **not**
67
- *
68
- * If you want to build a filter who's conditions being met results in _filtering_
69
- * the value rather than accepting it then choose this.
70
- */
71
- not: FilterDefn;
72
- };
73
-
74
- export function isNotFilter(f: FilterDefn | NotFilter): f is NotFilter {
75
- return typeof f === "object" && "not" in f;
76
- }
77
-
78
- export type UnwrapNot<T extends FilterDefn | NotFilter> = T extends NotFilter
79
- ? T["not"] extends StringFilter
80
- ? StringFilter
81
- : NumericFilter
82
- : T;
83
-
84
- export function isNumericFilter(filter: FilterDefn): filter is NumericFilter {
85
- return "equals" in filter ||
86
- "notEqual" in filter ||
87
- "greaterThan" in filter ||
88
- "lessThan" in filter
89
- ? true
90
- : false;
91
- }
92
-
93
- export type UndefinedValue<U extends boolean> = true extends U
94
- ? "undefined treated as 'true'"
95
- : U extends "no-impact"
96
- ? "undefined treated in no-impact fashion"
97
- : "undefined treated as 'false'";
98
-
99
- export type UndefinedTreatment = "undefined treated as 'true'" | "undefined treated as 'false'";
100
-
101
- export type LogicalCombinator = "AND" | "OR";
102
-
103
- /**
104
- * **FilterFn**
105
- *
106
- * A filter function derived from the `filter()` configurator. This function is intended to provide a type-strong _filter_ function which can be used like so:
107
- * be used like:
108
- * ```ts
109
- * const onlyPrivate = filter({ startsWith: "_" });
110
- * const privateFiles = files.filter(onlyPrivate);
111
- * ```
112
- */
113
- export type FilterFn<T extends StringFilter | NumericFilter> = T extends StringFilter
114
- ? <V extends string | undefined>(input: V) => boolean
115
- : <V extends number | undefined>(input: V) => boolean;
116
-
117
- /**
118
- * Defines a logical function for each condition type
119
- */
120
- export type ConditionFilter<T extends StringFilter | NumericFilter> = T extends StringFilter
121
- ? (input: string) => boolean
122
- : (input: number) => boolean;
123
-
124
- /**
125
- * Wraps numeric filter's configuration into a logic filter
126
- */
127
- const numericOps = <L extends LogicalCombinator>(config: NumericFilter, boolLogic: L) => {
128
- const equals = (n: number | number[]): [ConditionFilter<NumericFilter>] | [] => {
129
- const f = asArray(n);
130
- return f.length === 0 ? [] : [(input?: number) => f.some((i) => i === input)];
131
- };
132
- const notEqual = (n: number | number[]): [ConditionFilter<NumericFilter>] | [] => {
133
- const f = asArray(n);
134
- return f.length === 0 ? [] : [(input?: number) => f.every((i) => i !== input)];
135
- };
136
-
137
- /** returns 1 FilterFn's */
138
- const greaterThan = <V extends number>(n: V) => {
139
- const val = [(input?: V) => input !== undefined && input > n] as [(input: V) => boolean];
140
- return val as [ConditionFilter<NumericFilter>];
141
- };
142
-
143
- /** returns 0 or 1 FilterFn's */
144
- const lessThan = <V extends number>(n: V) => {
145
- const val = [(input: V) => input !== undefined && input < n];
146
- return val as [ConditionFilter<NumericFilter>] | [];
147
- };
148
-
149
- const conditions = [
150
- //
151
- ...("equals" in config ? equals(config.equals) : []),
152
- ...("notEqual" in config ? notEqual(config.notEqual) : []),
153
- ...("greaterThan" in config ? greaterThan(config.greaterThan) : []),
154
- ...("lessThan" in config ? lessThan(config.lessThan) : []),
155
- ];
156
-
157
- const combined =
158
- boolLogic === "AND"
159
- ? <N extends number>(input: N) => conditions.every((c) => c(input))
160
- : <N extends number>(input: N) => conditions.some((c) => c(input));
161
-
162
- return combined;
163
- };
164
-
165
- /** wraps configuration along with boolean logic */
166
- const stringOps = <L extends LogicalCombinator>(
167
- config: StringFilter,
168
- boolLogic: L
169
- ): ConditionFilter<StringFilter> => {
170
- const startsWith = (n: string | string[]): [ConditionFilter<StringFilter>] | [] => {
171
- const f = asArray(n);
172
- return f.length === 0 ? [] : [(input?: string) => f.some((i) => input?.startsWith(i))];
173
- };
174
- const endsWith = (n: string | string[]): [ConditionFilter<StringFilter>] | [] => {
175
- const f = asArray(n);
176
- return f.length === 0 ? [] : [(input?: string) => f.some((i) => input?.endsWith(i))];
177
- };
178
- const contains = (n: string | string[]): [ConditionFilter<StringFilter>] | [] => {
179
- const f = asArray(n);
180
- return f.length === 0 ? [] : [(input: string) => f.some((i) => input?.includes(i))];
181
- };
182
-
183
- const conditions = [
184
- ...("startsWith" in config ? startsWith(config.startsWith) : []),
185
- ...("endsWith" in config ? endsWith(config.endsWith) : []),
186
- ...("contains" in config ? contains(config.contains) : []),
187
- ];
188
-
189
- const combined =
190
- boolLogic === "AND"
191
- ? (input: string) => conditions.every((c) => c(input))
192
- : (input: string) => conditions.some((c) => c(input));
193
-
194
- return combined as ConditionFilter<StringFilter>;
195
- };
196
-
197
- const filterFn = <
198
- F extends FilterDefn | NotFilter,
199
- C extends LogicalCombinator,
200
- U extends boolean | "no-impact"
201
- >(
202
- defn: F,
203
- logicCombinator: C,
204
- ifUndefined: U = "no-impact" as U
205
- ): FilterFn<UnwrapNot<F>> => {
206
- type D = UnwrapNot<F>;
207
- const config: D = isNotFilter(defn) ? (defn["not"] as D) : (defn as D);
208
-
209
- const filter: FilterFn<D> = (
210
- //
211
- input: Parameters<FilterFn<D>>[0]
212
- ) => {
213
- const undefValue =
214
- ifUndefined === "no-impact"
215
- ? logicCombinator === "AND"
216
- ? true
217
- : false
218
- : (ifUndefined as true | false);
219
-
220
- let flag: boolean;
221
-
222
- if (typeof input === "undefined") {
223
- flag = undefValue;
224
- } else if (isNumericFilter(config)) {
225
- const fn = numericOps(config, logicCombinator);
226
- flag = isNotFilter(defn) ? !fn(input as number) : fn(input as number);
227
- } else {
228
- const fn = stringOps(config, logicCombinator);
229
- flag = isNotFilter(defn) ? !fn(input as string) : fn(input as string);
230
- }
231
-
232
- return flag;
233
- };
234
-
235
- return filter;
236
- };
237
-
238
- /**
239
- * **filter**
240
- *
241
- * A higher order helper utility which builds a boolean _filter_ function based on a simple
242
- * configuration object. Support either _string_ or _numeric_ filters.
243
- *
244
- * ```ts
245
- * const str = filter({startsWith: ["_", "."], endsWith: ".md"});
246
- * const num = filter({ greaterThan: 55, notEqual: [66, 77]});
247
- * ```
248
- *
249
- * All conditions (e.g., `startsWith`, `contains`, `notEqual`, etc.) that a particular filter
250
- * is defined as having -- if there is more than one -- will be logically combined using AND
251
- * unless specified otherwise in the third parameter.
252
- *
253
- * How a value of _undefined_ will be treated is stated in the second parameter but defaults
254
- * to "no-impact" which means it's `false` when the logicCombinator is OR but defaults
255
- * to `true` when the logicCombinator is AND.
256
- */
257
- export const filter = <
258
- F extends FilterDefn | NotFilter,
259
- U extends boolean | "no-impact",
260
- C extends LogicalCombinator
261
- >(
262
- config: F,
263
- logicCombinator: C = "AND" as C,
264
- ifUndefined: U = "no-impact" as U
265
- ) => {
266
- return filterFn(config, logicCombinator, ifUndefined);
267
- };
@@ -1,4 +0,0 @@
1
- export * from "./and";
2
- export * from "./or";
3
- export * from "./not";
4
- export * from "./filter";
@@ -1,15 +0,0 @@
1
- import { LogicFunction } from "src/types/functions";
2
-
3
- /**
4
- * Groups a number of "logic functions" together by combining their results using
5
- * the logical **NOT** operator.
6
- *
7
- * **Note:** a "logic function" is any function which returns a boolean
8
- */
9
- export const not = <T extends any[]>(op: LogicFunction<T>): LogicFunction<T> => {
10
- const fn: LogicFunction<T> = (...args: T) => {
11
- return !op(...args);
12
- };
13
-
14
- return fn;
15
- };
@@ -1,5 +0,0 @@
1
- import { Or } from "src/types/boolean-logic/Or";
2
-
3
- export function or<O extends readonly boolean[]>(...conditions: O) {
4
- return (conditions.some((v) => v === true) ? true : false) as Or<O>;
5
- }
@@ -1,37 +0,0 @@
1
- import { Narrowable } from "../types/Narrowable";
2
- import { keys } from "./keys";
3
-
4
- export function createFnWithProps<F extends Function, P extends {}>(fn: F, props: P) {
5
- return (() => {
6
- // eslint-disable-next-line prefer-const
7
- let combined: any = fn;
8
- for (const prop of keys(props)) {
9
- combined[prop] = props[prop];
10
- }
11
- return combined;
12
- })() as unknown as F & P;
13
- }
14
-
15
- /**
16
- * Adds a dictionary of key/value pairs to a function.
17
- */
18
- export function fnWithProps<A extends any[], R extends any, P extends {}>(fn: ((...args: A) => R), props: P) {
19
- // eslint-disable-next-line prefer-const
20
- let combined: any = fn;
21
- for (const prop of keys(props)) {
22
- combined[prop] = props[prop];
23
- }
24
- return combined as ((...args: A) => R) & P;
25
- }
26
-
27
- /**
28
- * Adds read-only (and narrowly typed) key/value pairs to a function
29
- */
30
- export function readonlyFnWithProps<A extends any[], R extends any, N extends Narrowable, P extends Record<keyof P, N>>(fn: ((...args: A) => R), props: P) {
31
- // eslint-disable-next-line prefer-const
32
- let combined: any = fn;
33
- for (const prop of keys(props)) {
34
- combined[prop] = props[prop];
35
- }
36
- return combined as ((...args: A) => R) & Readonly<P>;
37
- }
@@ -1,19 +0,0 @@
1
- /**
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`.
4
- * ```ts
5
- * // { bar: true, bar: true } as const;
6
- * const d - dictArr(arr);
7
- *
8
- * const fooBar = arrayToKeyLookup("foo", "bar");
9
- * ```
10
- */
11
- export function arrayToKeyLookup<T extends readonly string[]>(...keys: T): Record<T[number], true> {
12
- const obj: Record<string, true> = {};
13
-
14
- for (const key of keys) {
15
- obj[key] = true;
16
- }
17
-
18
- return obj;
19
- }
@@ -1,35 +0,0 @@
1
- export interface DefinePropertiesApi<T extends {}> {
2
- /**
3
- * Makes a property on the object **readonly** on the Javascript runtime
4
- */
5
- ro<K extends keyof T>(
6
- prop: K,
7
- errorMsg?: (p: K, v: any) => string
8
- ): Omit<T, K> & Record<K, Readonly<T[K]>>;
9
- /**
10
- * Makes a property on the object **read/writeable** on the Javascript runtime;
11
- * this is the default so only use this where it is needed.
12
- */
13
- rw<K extends keyof T>(prop: K): Omit<T, K> & Record<K, Readonly<T[K]>>;
14
- }
15
-
16
- export function defineProperties<T extends {}>(obj: T) {
17
- return {
18
- ro(prop, errorMsg) {
19
- Object.defineProperty(obj, prop, {
20
- writable: false,
21
- set(v: any) {
22
- const message = errorMsg
23
- ? errorMsg(prop, v)
24
- : `The ${String(
25
- prop
26
- )} is readonly but an attempt was made to change it's value to "${JSON.stringify(
27
- v
28
- )}"!`;
29
- throw new Error(message);
30
- },
31
- });
32
- return obj;
33
- },
34
- } as DefinePropertiesApi<T>;
35
- }
@@ -1,69 +0,0 @@
1
- import { Keys, Narrowable, OptionalKeys, RequiredKeys, UniqueForProp } from "src/types";
2
-
3
- export interface Uniqueness<T> {
4
- /** boolean flag to indicate whether the property was unique across all records */
5
- isUnique: boolean;
6
- /** the overall number of records which contained the property */
7
- size: number;
8
- /** specifies if undefined values were encountered for this property */
9
- includedUndefined: boolean;
10
- /** the unique values for the property across all records */
11
- values: readonly T[];
12
- }
13
-
14
- export type DictArrApi<T extends Record<string, Narrowable>, A extends readonly T[]> = {
15
- length: number;
16
- toLookup<PL extends RequiredKeys<T, string> & keyof T & string>(
17
- prop: PL
18
- ): UniqueForProp<A, PL> extends string ? Record<UniqueForProp<A, PL>, T> : Record<string, T>;
19
- sum<PS extends RequiredKeys<T, number> | OptionalKeys<T, number>>(prop: PS): number;
20
- count<PC extends OptionalKeys<T>>(prop: PC): number;
21
- unique<PU extends Keys<T> & keyof T>(prop: PU): Uniqueness<T[PU]>;
22
- };
23
-
24
- /**
25
- * converts an array of objects to a dictionary with keys formed from a given property
26
- * of the object and the value being the object itself.
27
- */
28
- export const dictArr = <T extends Record<string, Narrowable>>(...dicts: readonly T[]) => {
29
- // build API
30
- const api: DictArrApi<T, typeof dicts> = {
31
- length: dicts.length,
32
- toLookup: (prop) => {
33
- let dict: Record<string, T> = {};
34
- for (const obj of dicts) {
35
- const key = obj[prop] as string;
36
- dict = { ...dict, [key]: obj };
37
- }
38
- return dict;
39
- },
40
- /**
41
- * The unique values of a given property
42
- */
43
- unique: (prop) => {
44
- type P = typeof prop;
45
- const v = new Set<T[P]>();
46
- dicts.forEach((i) => v.add(i[prop]));
47
- const size = dictArr(...dicts).count(prop as any);
48
- const values = Array.from(v);
49
- const u: Uniqueness<T[P]> = {
50
- isUnique: values.includes(undefined as any) ? size === v.size - 1 : size === v.size,
51
- includedUndefined: values.includes(undefined as any) ? true : false,
52
- size,
53
- values,
54
- };
55
- return u;
56
- },
57
- sum: (prop) => {
58
- return dicts.reduce((acc, obj) => (prop in obj ? acc + (obj[prop] as number) : acc), 0);
59
- },
60
- count: (prop) => {
61
- return dicts.reduce(
62
- (acc, obj) => (prop in obj && typeof obj[prop] !== "undefined" ? acc + 1 : acc),
63
- 0
64
- );
65
- },
66
- };
67
-
68
- return api;
69
- };
@@ -1,22 +0,0 @@
1
- /* eslint-disable no-use-before-define */
2
-
3
- import { SameKeys } from "src/types/dictionary";
4
- import { Transformer } from "src/types/Transformer";
5
- import { keys } from "../keys";
6
-
7
- /**
8
- * Takes a dictionary of type `I` and converts it to a dictionary of type `O` where
9
- * they _keys_ used in both dictionaries are the same.
10
- *
11
- * The _transform_ function passed in must be able to recieve the full input object
12
- * and key, and then return expected value of `O` for the given key.
13
- */
14
- export function dictionaryTransform<I extends object, O extends SameKeys<I>>(
15
- input: I,
16
- transform: Transformer<I, O>
17
- ) {
18
- return keys(input).reduce((acc, i) => {
19
- const key = i as string & keyof I;
20
- return { ...acc, [key]: transform(input, key) };
21
- }, {} as O);
22
- }
@@ -1,33 +0,0 @@
1
- import { KeyValue } from "src/types/kv";
2
- import { Narrowable } from "src/types/Narrowable";
3
- import { keys } from "../keys";
4
-
5
- /**
6
- * **entries**
7
- *
8
- * Provides an _iterable_ over the passed in dictionary object where each iteration
9
- * provides a tuple of `[ key, value ]` which preserve type literals.
10
- *
11
- * For example:
12
- * ```ts
13
- * const obj = { foo: 1, bar: "hi" };
14
- * // k type is "foo" then "bar"; v type is 1 then "hi"
15
- * for (const [k, v] of entries(obj)) { ... }
16
- * ```
17
- */
18
- export function entries<
19
- N extends Narrowable,
20
- T extends Record<string, N>,
21
- I extends KeyValue<T, keyof T>
22
- >(obj: T) {
23
- const iterable = {
24
- *[Symbol.iterator]() {
25
- for (const k of keys(obj)) {
26
- // const [k, v] = entry as KeyValue<T, First<typeof entry>>;
27
- yield [k, obj[k]] as KeyValue<T, typeof k> as I;
28
- }
29
- },
30
- };
31
-
32
- return iterable;
33
- }
@@ -1,21 +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: b0051c37
5
-
6
- // file exports
7
- export * from "./arrayToKeyLookup";
8
- export * from "./defineProperties";
9
- export * from "./dictionaryTransform";
10
- export * from "./dictArr";
11
- export * from "./entries";
12
- export * from "./mapValues";
13
- export * from "./mapTo";
14
- export * from "./strArrayToDict";
15
- // directory exports
16
- export * from "./kv/index";
17
-
18
- // #endregion auto-indexed files
19
-
20
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
21
- // for more info
@@ -1,21 +0,0 @@
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/runtime/keys";
6
-
7
- /**
8
- * Converts a dictionary object into an array of dictionaries with `key` and `value` properties
9
- * ```ts
10
- * // [ { key: "id", value: 123 }, { key: "foo", value: "bar" } ]
11
- * const arr = dictToKv({ id: 123, foo: "bar" });
12
- * ```
13
- */
14
- export function dictToKv<N extends Narrowable, T extends { [key: string]: N }, U extends boolean>(
15
- obj: T,
16
- _makeTuple: U = false as U
17
- ) {
18
- return keys(obj).map((k) => {
19
- return { key: k, value: obj[k] };
20
- }) as unknown as U extends true ? UnionToTuple<KvFrom<Mutable<T>>[0]> : KvFrom<Mutable<T>>;
21
- }
@@ -1,31 +0,0 @@
1
- import { DictArray, DictArrayFilterCallback } from "src/types/tuples";
2
- import { Configurator, IConfigurator } from "src/runtime/state";
3
-
4
- export interface Array<T> {
5
- filter<U extends T>(pred: (a: T) => a is U): U[];
6
- }
7
-
8
- /**
9
- * Accepts a `DictArray` and a callback which receives each key
10
- * value pair.
11
- */
12
- export function filterDictArray<
13
- T extends object,
14
- C extends DictArrayFilterCallback<keyof T, T, true | false>
15
- >(dictArr: DictArray<T>, cb: C) {
16
- const state: IConfigurator = Configurator();
17
-
18
- const updated = dictArr.filter((i) => {
19
- const [k, v] = i;
20
- const keep = cb(k, v);
21
- if (!keep) {
22
- state.set(k as string, true);
23
- }
24
-
25
- return keep;
26
- });
27
-
28
- // TODO: fix this so that typing is actualy working!
29
- type ExcludedKeys = "";
30
- return updated as unknown as DictArray<Omit<T, ExcludedKeys>>;
31
- }
@@ -1,15 +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: dd4e4592
5
-
6
- // file exports
7
- export * from "./dictToKv";
8
- export * from "./filterDictArray";
9
- export * from "./kv";
10
- export * from "./kvToDict";
11
-
12
- // #endregion auto-indexed files
13
-
14
- // see https://github.com/inocan-group/do-devops/docs/autoindex.md
15
- // for more info