inferred-types 0.16.0 → 0.18.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 (177) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/devops/build.js +1 -3
  3. package/dist/{types/utility/state/KeyStorage.d.ts → index.d.ts} +9767 -8195
  4. package/dist/index.js +659 -0
  5. package/dist/index.mjs +577 -0
  6. package/on-hold/tests/api-spec.ts +9 -15
  7. package/package.json +27 -39
  8. package/pnpm-lock.yaml +2807 -3858
  9. package/src/errors/InferenceError.ts +1 -1
  10. package/src/shared/randomString.ts +1 -1
  11. package/src/types/Constructor.ts +5 -0
  12. package/src/types/Not.ts +3 -1
  13. package/src/types/Transformer.ts +1 -2
  14. package/src/types/Where.ts +36 -0
  15. package/src/types/alphabetic/PascalCase.ts +5 -4
  16. package/src/types/alphabetic/index.ts +9 -5
  17. package/src/types/{fluent.ts → fluent/fluent.ts} +8 -9
  18. package/src/types/fluent/index.ts +42 -0
  19. package/src/types/index.ts +13 -7
  20. package/src/types/ruleset-types.ts +1 -1
  21. package/src/types/{SameKeys.ts → type-conversion/SameKeys.ts} +0 -0
  22. package/src/types/type-conversion/WrapValue.ts +15 -0
  23. package/src/types/type-conversion/index.ts +11 -4
  24. package/src/utility/dictionary/dictionaryTransform.ts +6 -7
  25. package/tests/Where.spec.ts +39 -0
  26. package/tests/constructor.spec.ts +40 -0
  27. package/tests/data/index.ts +8 -3
  28. package/tests/kv/dict-to-kv-and-back.spec.ts +2 -6
  29. package/tsconfig.json +4 -3
  30. package/dist/cjs/index.js +0 -21
  31. package/dist/es/index.js +0 -17
  32. package/dist/tsconfig.tsbuildinfo +0 -1
  33. package/dist/types/Mutation/MutationFunction.d.ts +0 -16
  34. package/dist/types/Mutation/MutationIdentity.d.ts +0 -30
  35. package/dist/types/Mutation/index.d.ts +0 -2
  36. package/dist/types/errors/InferenceError.d.ts +0 -1
  37. package/dist/types/errors/index.d.ts +0 -1
  38. package/dist/types/index.d.ts +0 -4
  39. package/dist/types/shared/index.d.ts +0 -3
  40. package/dist/types/shared/randomString.d.ts +0 -1
  41. package/dist/types/shared/uuid.d.ts +0 -1
  42. package/dist/types/shared/valueTypes.d.ts +0 -27
  43. package/dist/types/types/Api.d.ts +0 -10
  44. package/dist/types/types/EnumValues.d.ts +0 -14
  45. package/dist/types/types/ExpandRecursively.d.ts +0 -3
  46. package/dist/types/types/First.d.ts +0 -4
  47. package/dist/types/types/FunctionType.d.ts +0 -9
  48. package/dist/types/types/If.d.ts +0 -10
  49. package/dist/types/types/Include.d.ts +0 -16
  50. package/dist/types/types/Includes.d.ts +0 -5
  51. package/dist/types/types/KeyedRecord.d.ts +0 -22
  52. package/dist/types/types/Keys.d.ts +0 -17
  53. package/dist/types/types/Length.d.ts +0 -8
  54. package/dist/types/types/Mutable.d.ts +0 -6
  55. package/dist/types/types/Narrowable.d.ts +0 -5
  56. package/dist/types/types/Not.d.ts +0 -11
  57. package/dist/types/types/Numeric.d.ts +0 -14
  58. package/dist/types/types/Opaque.d.ts +0 -12
  59. package/dist/types/types/Retain.d.ts +0 -16
  60. package/dist/types/types/SameKeys.d.ts +0 -11
  61. package/dist/types/types/Transformer.d.ts +0 -11
  62. package/dist/types/types/TypeGuard.d.ts +0 -7
  63. package/dist/types/types/alphabetic/AllCaps.d.ts +0 -12
  64. package/dist/types/types/alphabetic/CamelCase.d.ts +0 -2
  65. package/dist/types/types/alphabetic/CapFirstAlpha.d.ts +0 -13
  66. package/dist/types/types/alphabetic/CapitalizeWords.d.ts +0 -4
  67. package/dist/types/types/alphabetic/DashToSnake.d.ts +0 -1
  68. package/dist/types/types/alphabetic/DashUppercase.d.ts +0 -14
  69. package/dist/types/types/alphabetic/Dasherize.d.ts +0 -15
  70. package/dist/types/types/alphabetic/HasUppercase.d.ts +0 -13
  71. package/dist/types/types/alphabetic/Intrinsic.d.ts +0 -4
  72. package/dist/types/types/alphabetic/IsCapitalized.d.ts +0 -15
  73. package/dist/types/types/alphabetic/KebabCase.d.ts +0 -12
  74. package/dist/types/types/alphabetic/LowerAllCaps.d.ts +0 -4
  75. package/dist/types/types/alphabetic/PascalCase.d.ts +0 -16
  76. package/dist/types/types/alphabetic/Pluralize.d.ts +0 -36
  77. package/dist/types/types/alphabetic/SnakeCase.d.ts +0 -14
  78. package/dist/types/types/alphabetic/alpha-characters.d.ts +0 -36
  79. package/dist/types/types/alphabetic/index.d.ts +0 -16
  80. package/dist/types/types/append-types.d.ts +0 -9
  81. package/dist/types/types/dictionary/Get.d.ts +0 -7
  82. package/dist/types/types/dictionary/index.d.ts +0 -1
  83. package/dist/types/types/fluent.d.ts +0 -51
  84. package/dist/types/types/index.d.ts +0 -34
  85. package/dist/types/types/kv/DictFromKv.d.ts +0 -6
  86. package/dist/types/types/kv/KeyValue.d.ts +0 -11
  87. package/dist/types/types/kv/KvFrom.d.ts +0 -13
  88. package/dist/types/types/kv/KvTuple.d.ts +0 -14
  89. package/dist/types/types/kv/index.d.ts +0 -4
  90. package/dist/types/types/lists/UniqueForProp.d.ts +0 -14
  91. package/dist/types/types/lists/index.d.ts +0 -1
  92. package/dist/types/types/maybe.d.ts +0 -8
  93. package/dist/types/types/props.d.ts +0 -100
  94. package/dist/types/types/ruleset-types.d.ts +0 -59
  95. package/dist/types/types/runtime.d.ts +0 -33
  96. package/dist/types/types/string-literals/Break.d.ts +0 -12
  97. package/dist/types/types/string-literals/Concat.d.ts +0 -8
  98. package/dist/types/types/string-literals/LeftWhitespace.d.ts +0 -9
  99. package/dist/types/types/string-literals/Replace.d.ts +0 -11
  100. package/dist/types/types/string-literals/RightWhitespace.d.ts +0 -9
  101. package/dist/types/types/string-literals/StringLength.d.ts +0 -10
  102. package/dist/types/types/string-literals/Trim.d.ts +0 -11
  103. package/dist/types/types/string-literals/TrimLeft.d.ts +0 -11
  104. package/dist/types/types/string-literals/TrimRight.d.ts +0 -11
  105. package/dist/types/types/string-literals/form-fields.d.ts +0 -12
  106. package/dist/types/types/string-literals/index.d.ts +0 -10
  107. package/dist/types/types/tuples/DictArray.d.ts +0 -19
  108. package/dist/types/types/tuples/FirstKey.d.ts +0 -8
  109. package/dist/types/types/tuples/FirstKeyValue.d.ts +0 -8
  110. package/dist/types/types/tuples/FirstOfEach.d.ts +0 -11
  111. package/dist/types/types/tuples/FromDictArray.d.ts +0 -10
  112. package/dist/types/types/tuples/SecondOfEach.d.ts +0 -10
  113. package/dist/types/types/tuples/index.d.ts +0 -6
  114. package/dist/types/types/type-conversion/TupleToUnion.d.ts +0 -10
  115. package/dist/types/types/type-conversion/UnionToIntersection.d.ts +0 -5
  116. package/dist/types/types/type-conversion/UnionToTuple.d.ts +0 -9
  117. package/dist/types/types/type-conversion/index.d.ts +0 -3
  118. package/dist/types/types/type-testing.d.ts +0 -13
  119. package/dist/types/utility/api/api.d.ts +0 -2
  120. package/dist/types/utility/api/index.d.ts +0 -1
  121. package/dist/types/utility/createFnWithProps.d.ts +0 -1
  122. package/dist/types/utility/dictionary/arrayToKeyLookup.d.ts +0 -9
  123. package/dist/types/utility/dictionary/dictFilter.d.ts +0 -8
  124. package/dist/types/utility/dictionary/dictionaryTransform.d.ts +0 -9
  125. package/dist/types/utility/dictionary/entries.d.ts +0 -17
  126. package/dist/types/utility/dictionary/index.d.ts +0 -8
  127. package/dist/types/utility/dictionary/kv/dictToKv.d.ts +0 -16
  128. package/dist/types/utility/dictionary/kv/filterDictArray.d.ts +0 -9
  129. package/dist/types/utility/dictionary/kv/index.d.ts +0 -4
  130. package/dist/types/utility/dictionary/kv/kv.d.ts +0 -10
  131. package/dist/types/utility/dictionary/kv/kvToDict.d.ts +0 -15
  132. package/dist/types/utility/dictionary/mapValues.d.ts +0 -13
  133. package/dist/types/utility/dictionary/strArrayToDict.d.ts +0 -6
  134. package/dist/types/utility/dictionary/valuesOfProp.d.ts +0 -1
  135. package/dist/types/utility/index.d.ts +0 -11
  136. package/dist/types/utility/keys.d.ts +0 -5
  137. package/dist/types/utility/lists/groupBy.d.ts +0 -12
  138. package/dist/types/utility/lists/index.d.ts +0 -1
  139. package/dist/types/utility/literals/ExplicitFunction.d.ts +0 -6
  140. package/dist/types/utility/literals/arrayToObject.d.ts +0 -41
  141. package/dist/types/utility/literals/defineType.d.ts +0 -8
  142. package/dist/types/utility/literals/identity.d.ts +0 -6
  143. package/dist/types/utility/literals/index.d.ts +0 -5
  144. package/dist/types/utility/literals/literal.d.ts +0 -41
  145. package/dist/types/utility/map-reduce/filter.d.ts +0 -26
  146. package/dist/types/utility/map-reduce/index.d.ts +0 -1
  147. package/dist/types/utility/modelling/IoModel.d.ts +0 -26
  148. package/dist/types/utility/modelling/Model.d.ts +0 -22
  149. package/dist/types/utility/modelling/index.d.ts +0 -1
  150. package/dist/types/utility/ruleset.d.ts +0 -18
  151. package/dist/types/utility/runtime/condition.d.ts +0 -3
  152. package/dist/types/utility/runtime/conditions/index.d.ts +0 -12
  153. package/dist/types/utility/runtime/conditions/isArray.d.ts +0 -2
  154. package/dist/types/utility/runtime/conditions/isBoolean.d.ts +0 -5
  155. package/dist/types/utility/runtime/conditions/isFalse.d.ts +0 -4
  156. package/dist/types/utility/runtime/conditions/isFunction.d.ts +0 -15
  157. package/dist/types/utility/runtime/conditions/isLiteral.d.ts +0 -2
  158. package/dist/types/utility/runtime/conditions/isNull.d.ts +0 -1
  159. package/dist/types/utility/runtime/conditions/isNumber.d.ts +0 -1
  160. package/dist/types/utility/runtime/conditions/isObject.d.ts +0 -10
  161. package/dist/types/utility/runtime/conditions/isString.d.ts +0 -2
  162. package/dist/types/utility/runtime/conditions/isSymbol.d.ts +0 -1
  163. package/dist/types/utility/runtime/conditions/isTrue.d.ts +0 -20
  164. package/dist/types/utility/runtime/conditions/isUndefined.d.ts +0 -1
  165. package/dist/types/utility/runtime/ifTypeOf.d.ts +0 -23
  166. package/dist/types/utility/runtime/index.d.ts +0 -5
  167. package/dist/types/utility/runtime/type.d.ts +0 -27
  168. package/dist/types/utility/runtime/withValue.d.ts +0 -19
  169. package/dist/types/utility/state/Configurator.d.ts +0 -36
  170. package/dist/types/utility/state/FluentConfigurator.d.ts +0 -27
  171. package/dist/types/utility/state/index.d.ts +0 -3
  172. package/src/types/alphabetic/Intrinsic.ts +0 -6
  173. package/src/utility/modelling/IoModel.ts +0 -38
  174. package/tests/FluentApi-spec.ts +0 -90
  175. package/tests/FluentConfigurator-spec.hold +0 -88
  176. package/tests/IoModel-spec.hold +0 -209
  177. package/tests/lists/groupBy.spec.ts +0 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,577 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/Mutation/MutationFunction.ts
22
+ function createMutationFunction(state) {
23
+ return (mutationIdentity) => {
24
+ return mutationIdentity(state);
25
+ };
26
+ }
27
+
28
+ // src/Mutation/MutationIdentity.ts
29
+ function MutationIdentity() {
30
+ return function(m) {
31
+ return m;
32
+ };
33
+ }
34
+
35
+ // src/errors/InferenceError.ts
36
+ import { createError } from "brilliant-errors";
37
+ var [InferenceError, isInferenceError] = createError("InferenceError", "inferred-types")()()()();
38
+
39
+ // src/utility/keys.ts
40
+ function keys(obj, ...without) {
41
+ const v = without.length > 0 ? Object.keys(obj).filter((k) => !without.includes(k)) : Object.keys(obj);
42
+ return v;
43
+ }
44
+
45
+ // src/utility/createFnWithProps.ts
46
+ function createFnWithProps(fn, props) {
47
+ return (() => {
48
+ let combined = fn;
49
+ for (const prop of keys(props)) {
50
+ combined[prop] = props[prop];
51
+ }
52
+ return combined;
53
+ })();
54
+ }
55
+
56
+ // src/utility/ruleset.ts
57
+ function ruleSet(defn) {
58
+ return defn;
59
+ }
60
+
61
+ // src/utility/api/api.ts
62
+ var api = (priv) => (pub) => {
63
+ const surface = () => pub;
64
+ surface.prototype.priv = () => priv;
65
+ return surface;
66
+ };
67
+
68
+ // src/utility/dictionary/arrayToKeyLookup.ts
69
+ function arrayToKeyLookup(...keys2) {
70
+ const obj = {};
71
+ for (const key of keys2) {
72
+ obj[key] = true;
73
+ }
74
+ return obj;
75
+ }
76
+
77
+ // src/utility/dictionary/dictFilter.ts
78
+ import { omit } from "native-dash";
79
+ function dictFilter(obj, cb) {
80
+ const remove = keys(obj).filter((k) => !cb(k, obj));
81
+ return omit(obj, ...keys(obj).filter((k) => !cb(k, obj)));
82
+ }
83
+
84
+ // src/utility/dictionary/dictionaryTransform.ts
85
+ function dictionaryTransform(input, transform) {
86
+ return keys(input).reduce((acc, i) => {
87
+ const key = i;
88
+ return __spreadProps(__spreadValues({}, acc), { [key]: transform(input, key) });
89
+ }, {});
90
+ }
91
+
92
+ // src/utility/dictionary/entries.ts
93
+ function entries(obj) {
94
+ const iterable = {
95
+ *[Symbol.iterator]() {
96
+ for (const k of keys(obj)) {
97
+ yield [k, obj[k]];
98
+ }
99
+ }
100
+ };
101
+ return iterable;
102
+ }
103
+
104
+ // src/utility/dictionary/mapValues.ts
105
+ function mapValues(obj, valueMapper) {
106
+ return Object.fromEntries([...entries(obj)].map(([k, v]) => [k, valueMapper(v)]));
107
+ }
108
+
109
+ // src/utility/dictionary/strArrayToDict.ts
110
+ function strArrayToDict(...strings) {
111
+ return strings.reduce((acc, str) => {
112
+ acc = __spreadProps(__spreadValues({}, acc), { [str]: true });
113
+ return acc;
114
+ }, {});
115
+ }
116
+
117
+ // src/utility/dictionary/valuesOfProp.ts
118
+ function valuesOfProp() {
119
+ }
120
+
121
+ // src/utility/dictionary/kv/dictToKv.ts
122
+ function dictToKv(obj, _makeTuple = false) {
123
+ return keys(obj).map((k) => {
124
+ return { key: k, value: obj[k] };
125
+ });
126
+ }
127
+
128
+ // src/utility/state/Configurator.ts
129
+ import { omit as omit2 } from "native-dash";
130
+ function Configurator() {
131
+ let configuration = () => ({});
132
+ const api2 = () => {
133
+ return {
134
+ set(key, value) {
135
+ const keyValue = { [key]: value };
136
+ const config = configuration();
137
+ const updated = __spreadValues(__spreadValues({}, config), keyValue);
138
+ configuration = () => updated;
139
+ return updated;
140
+ },
141
+ remove(key) {
142
+ const config = configuration();
143
+ const updated = omit2(config, key);
144
+ configuration = () => updated;
145
+ return updated;
146
+ },
147
+ done() {
148
+ return configuration();
149
+ }
150
+ };
151
+ };
152
+ return api2();
153
+ }
154
+
155
+ // src/utility/state/FluentConfigurator.ts
156
+ function FluentConfigurator(initial = {}) {
157
+ const api2 = (current) => {
158
+ return {
159
+ set(key, value) {
160
+ const keyValue = { [key]: value };
161
+ const updated = __spreadValues(__spreadValues({}, keyValue), current);
162
+ return api2(updated);
163
+ },
164
+ done() {
165
+ return current;
166
+ }
167
+ };
168
+ };
169
+ if (initial && typeof initial !== "object") {
170
+ throw new Error("The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed.");
171
+ }
172
+ return initial ? api2(initial) : api2({});
173
+ }
174
+
175
+ // src/utility/state/KeyStorage.ts
176
+ function KeyStorage() {
177
+ const api2 = (state) => ({
178
+ add: (...store) => {
179
+ return api2([...state, ...store]);
180
+ },
181
+ remove: (key) => api2(state.filter((i) => i !== key)),
182
+ done: () => state
183
+ });
184
+ return api2([]);
185
+ }
186
+
187
+ // src/utility/dictionary/kv/filterDictArray.ts
188
+ function filterDictArray(dictArr, cb) {
189
+ const state = Configurator();
190
+ const updated = dictArr.filter((i) => {
191
+ const [k, v] = i;
192
+ const keep = cb(k, v);
193
+ if (!keep) {
194
+ state.set(k, true);
195
+ }
196
+ return keep;
197
+ });
198
+ return updated;
199
+ }
200
+
201
+ // src/utility/dictionary/kv/kv.ts
202
+ function kv(key, value) {
203
+ return { [key]: value };
204
+ }
205
+
206
+ // src/utility/dictionary/kv/kvToDict.ts
207
+ function kvToDict(kvArr) {
208
+ const out = {};
209
+ for (const kv2 of kvArr) {
210
+ out[kv2.key] = kv2.value;
211
+ }
212
+ return out;
213
+ }
214
+
215
+ // src/utility/lists/groupBy.ts
216
+ function groupBy(_data) {
217
+ throw new Error("not implemented");
218
+ return (_groupBy) => {
219
+ };
220
+ }
221
+
222
+ // src/utility/literals/ExplicitFunction.ts
223
+ function ExplicitFunction(fn) {
224
+ return fn;
225
+ }
226
+
227
+ // src/utility/literals/arrayToObject.ts
228
+ function arrayToObject(prop, unique) {
229
+ const transform = (arr) => {
230
+ const result = unique !== false ? arr.reduce((acc, v) => __spreadProps(__spreadValues({}, acc), { [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
231
+ const existing = acc[v[prop]] || [];
232
+ return __spreadProps(__spreadValues({}, acc), { [v[prop]]: [...existing, v] });
233
+ }, {});
234
+ return result;
235
+ };
236
+ return transform;
237
+ }
238
+
239
+ // src/utility/literals/defineType.ts
240
+ function defineType(literal2 = {}) {
241
+ return (wide = {}) => {
242
+ return literal2 ? __spreadValues(__spreadValues({}, wide), literal2) : wide;
243
+ };
244
+ }
245
+
246
+ // src/utility/literals/identity.ts
247
+ var identity = (v) => v;
248
+
249
+ // src/utility/literals/literal.ts
250
+ function idLiteral(o) {
251
+ return __spreadProps(__spreadValues({}, o), { id: o.id });
252
+ }
253
+ function nameLiteral(o) {
254
+ return o;
255
+ }
256
+ function kindLiteral(o) {
257
+ return o;
258
+ }
259
+ function idTypeGuard(_o) {
260
+ return true;
261
+ }
262
+ function literal(obj) {
263
+ return obj;
264
+ }
265
+
266
+ // src/utility/map-reduce/filter.ts
267
+ var equals = (field, val) => ({
268
+ kind: "Equals",
269
+ field,
270
+ val
271
+ });
272
+ var greater = (field, val) => ({
273
+ kind: "Greater",
274
+ field,
275
+ val
276
+ });
277
+ var less = (field, val) => ({
278
+ kind: "Less",
279
+ field,
280
+ val
281
+ });
282
+ var and = (a, b) => ({
283
+ kind: "And",
284
+ a,
285
+ b
286
+ });
287
+ var or = (a, b) => ({
288
+ kind: "Or",
289
+ a,
290
+ b
291
+ });
292
+
293
+ // src/utility/modelling/Model.ts
294
+ function Model(name) {
295
+ return {
296
+ required(_prop) {
297
+ return Model(name);
298
+ },
299
+ optional(_prop) {
300
+ return Model(name);
301
+ },
302
+ done() {
303
+ return {
304
+ __model__: name,
305
+ __kind__: "model"
306
+ };
307
+ }
308
+ };
309
+ }
310
+
311
+ // src/utility/runtime/condition.ts
312
+ var condition = (c, input) => {
313
+ return c(input);
314
+ };
315
+
316
+ // src/utility/runtime/ifTypeOf.ts
317
+ function runtimeExtendsCheck(val, base, narrow = false) {
318
+ if (typeof val !== typeof base) {
319
+ return false;
320
+ }
321
+ switch (typeof val) {
322
+ case "boolean":
323
+ case "string":
324
+ case "number":
325
+ case "symbol":
326
+ case "bigint":
327
+ return narrow ? val === base : true;
328
+ case "undefined":
329
+ return true;
330
+ case "function":
331
+ if (narrow) {
332
+ throw new InferenceError(`Use of narrowlyExtends with a function is not possible!`, "ifTypeOf/not-allowed");
333
+ }
334
+ return true;
335
+ case "object":
336
+ if (val === null && base === null) {
337
+ return true;
338
+ }
339
+ return keys(base).every((i) => runtimeExtendsCheck(val[i], base[i], narrow));
340
+ }
341
+ }
342
+ var ifTypeOf = (val) => ({
343
+ extends: (base) => {
344
+ const valid = runtimeExtendsCheck(val, base, false);
345
+ const trueFalse = valid ? true : false;
346
+ return {
347
+ then: (then) => ({
348
+ else: (elseVal) => {
349
+ return valid ? typeof then === "undefined" ? val : then : elseVal;
350
+ }
351
+ }),
352
+ else: (elseVal) => valid ? val : elseVal
353
+ } && trueFalse;
354
+ },
355
+ narrowlyExtends: (base) => {
356
+ const valid = runtimeExtendsCheck(val, base, true);
357
+ const trueFalse = valid ? true : false;
358
+ return {
359
+ then: (then) => ({
360
+ else: (elseVal) => {
361
+ return valid ? typeof then === "undefined" ? val : then : elseVal;
362
+ }
363
+ }),
364
+ else: (elseVal) => valid ? val : elseVal
365
+ } && trueFalse;
366
+ }
367
+ });
368
+
369
+ // src/utility/runtime/conditions/isArray.ts
370
+ function isArray(i) {
371
+ return Array.isArray(i) === true;
372
+ }
373
+
374
+ // src/utility/runtime/conditions/isBoolean.ts
375
+ function isBoolean(i) {
376
+ return typeof i === "boolean";
377
+ }
378
+
379
+ // src/utility/runtime/conditions/isFalse.ts
380
+ function isFalse(i) {
381
+ return typeof i === "boolean" && !i;
382
+ }
383
+
384
+ // src/utility/runtime/conditions/isFunction.ts
385
+ function isFunction(input) {
386
+ return typeof input === "function";
387
+ }
388
+
389
+ // src/utility/runtime/conditions/isLiteral.ts
390
+ function isLiteral(...allowed) {
391
+ return (i) => {
392
+ return !allowed.every((v) => i !== v);
393
+ };
394
+ }
395
+
396
+ // src/utility/runtime/conditions/isNull.ts
397
+ function isNull(i) {
398
+ return i === null;
399
+ }
400
+
401
+ // src/utility/runtime/conditions/isNumber.ts
402
+ function isNumber(i) {
403
+ return typeof i === "number";
404
+ }
405
+
406
+ // src/utility/runtime/conditions/isObject.ts
407
+ function isObject(i) {
408
+ return typeof i === "object" && i !== null && Array.isArray(i) === false;
409
+ }
410
+
411
+ // src/utility/runtime/conditions/isString.ts
412
+ function isString(i) {
413
+ return typeof i === "string";
414
+ }
415
+
416
+ // src/utility/runtime/conditions/isSymbol.ts
417
+ function isSymbol(i) {
418
+ return typeof i === "symbol";
419
+ }
420
+
421
+ // src/utility/runtime/conditions/isTrue.ts
422
+ function isTrue(i) {
423
+ return typeof i === "boolean" && i;
424
+ }
425
+
426
+ // src/utility/runtime/conditions/isUndefined.ts
427
+ function isUndefined(i) {
428
+ return typeof i === "undefined";
429
+ }
430
+
431
+ // src/utility/runtime/type.ts
432
+ var typeApi = () => ({
433
+ string: {
434
+ name: "string",
435
+ type: "",
436
+ typeGuard: (v) => isString(v),
437
+ is: isString
438
+ },
439
+ boolean: {
440
+ name: "boolean",
441
+ type: true,
442
+ typeGuard: (v) => isBoolean(v),
443
+ is: isBoolean
444
+ },
445
+ number: {
446
+ name: "number",
447
+ type: 1,
448
+ typeGuard: (v) => isNumber(v),
449
+ is: isNumber
450
+ },
451
+ function: {
452
+ name: "function",
453
+ type: Function,
454
+ typeGuard: (v) => isFunction(v),
455
+ is: isFunction
456
+ },
457
+ null: {
458
+ name: "null",
459
+ type: null,
460
+ typeGuard: (v) => isNull(v),
461
+ is: isNull
462
+ },
463
+ symbol: {
464
+ name: "symbol",
465
+ type: Symbol(),
466
+ typeGuard: (v) => isSymbol(v),
467
+ is: isSymbol
468
+ },
469
+ undefined: {
470
+ name: "undefined",
471
+ type: void 0,
472
+ typeGuard: (v) => isUndefined(v),
473
+ is: isUndefined
474
+ },
475
+ true: {
476
+ name: "true",
477
+ type: true,
478
+ typeGuard: (v) => isTrue(v),
479
+ is: isTrue
480
+ },
481
+ false: {
482
+ name: "false",
483
+ type: false,
484
+ typeGuard: (v) => isFalse(v),
485
+ is: isFalse
486
+ },
487
+ object: {
488
+ name: "object",
489
+ type: {},
490
+ typeGuard: (v) => isObject(v),
491
+ is: isObject
492
+ },
493
+ array: {
494
+ name: "array",
495
+ type: {},
496
+ typeGuard: (v) => isArray(v),
497
+ is: isObject
498
+ }
499
+ });
500
+ function isType(t) {
501
+ return typeof t === "object" && ["name", "type", "is"].every((i) => Object.keys(t).includes(i));
502
+ }
503
+ function type(fn) {
504
+ const result = fn(typeApi());
505
+ if (!isType(result)) {
506
+ throw new Error(`When using type(), the callback passed in returned an invalid type! Value returned was: ${result}`);
507
+ }
508
+ return result;
509
+ }
510
+
511
+ // src/utility/runtime/withValue.ts
512
+ function withValue(td) {
513
+ return (obj) => {
514
+ const t = type(td);
515
+ return Object.fromEntries([...entries(obj)].filter(([_key, value]) => {
516
+ return t.typeGuard(value);
517
+ }));
518
+ };
519
+ }
520
+ export {
521
+ Configurator,
522
+ ExplicitFunction,
523
+ FluentConfigurator,
524
+ InferenceError,
525
+ KeyStorage,
526
+ Model,
527
+ MutationIdentity,
528
+ and,
529
+ api,
530
+ arrayToKeyLookup,
531
+ arrayToObject,
532
+ condition,
533
+ createFnWithProps,
534
+ createMutationFunction,
535
+ defineType,
536
+ dictFilter,
537
+ dictToKv,
538
+ dictionaryTransform,
539
+ entries,
540
+ equals,
541
+ filterDictArray,
542
+ greater,
543
+ groupBy,
544
+ idLiteral,
545
+ idTypeGuard,
546
+ identity,
547
+ ifTypeOf,
548
+ isArray,
549
+ isBoolean,
550
+ isFalse,
551
+ isFunction,
552
+ isInferenceError,
553
+ isLiteral,
554
+ isNull,
555
+ isNumber,
556
+ isObject,
557
+ isString,
558
+ isSymbol,
559
+ isTrue,
560
+ isType,
561
+ isUndefined,
562
+ keys,
563
+ kindLiteral,
564
+ kv,
565
+ kvToDict,
566
+ less,
567
+ literal,
568
+ mapValues,
569
+ nameLiteral,
570
+ or,
571
+ ruleSet,
572
+ strArrayToDict,
573
+ type,
574
+ typeApi,
575
+ valuesOfProp,
576
+ withValue
577
+ };
@@ -1,20 +1,15 @@
1
1
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { string } from "io-ts";
3
2
  import { Api, PrivateKeys, PublicKeys } from "~/types";
4
3
  import { defineType } from "~/utility";
5
4
  import { api } from "~/utility/api/api";
6
5
 
7
-
8
-
9
6
  describe("Api<T> type", () => {
10
-
11
7
  it("PublicKeys<T> and PrivateKeys<T> type utils extract the right keys", () => {
12
-
13
8
  const api = {
14
9
  _state: 123,
15
10
  _name: "hey ho",
16
11
  greet: "hi",
17
- age: 12
12
+ age: 12,
18
13
  };
19
14
 
20
15
  const f = string;
@@ -32,10 +27,11 @@ describe("Api<T> type", () => {
32
27
  });
33
28
 
34
29
  it.skip("privateApi() creates a definition for a private API", () => {
35
- const food = api({ _model: "food", _description: "let's eat" })({ category: string, stars: 5 as number });
30
+ const food = api({ _model: "food", _description: "let's eat" })({
31
+ category: string,
32
+ stars: 5 as number,
33
+ });
36
34
  const pub = food();
37
-
38
-
39
35
  });
40
36
 
41
37
  it("The Api<T> utility hides all private keys while preserving type info", () => {
@@ -43,7 +39,7 @@ describe("Api<T> type", () => {
43
39
  _state: 123,
44
40
  _name: "hey ho",
45
41
  greet: "hi",
46
- age: 12
42
+ age: 12,
47
43
  };
48
44
  type Simple = Api<typeof simple>;
49
45
 
@@ -51,7 +47,7 @@ describe("Api<T> type", () => {
51
47
  _state: 123,
52
48
  _name: "hey ho",
53
49
  greet: "hi",
54
- age: 12
50
+ age: 12,
55
51
  });
56
52
  type Midling = Api<typeof midling>;
57
53
 
@@ -65,7 +61,7 @@ describe("Api<T> type", () => {
65
61
  // if the public interface has type literals this is
66
62
  // accommodated without any special effort
67
63
  Expect<Equal<Midling, { greet: string; age: number; id: 123 }>>,
68
- Expect<Equal<Midling, { greet: string; age: number; id: 123 }>>,
64
+ Expect<Equal<Midling, { greet: string; age: number; id: 123 }>>
69
65
  // in the situation where the private members have
70
66
  // literals that need preservation, we need be assured
71
67
  // the API implementation can preserve this strong typing
@@ -73,7 +69,5 @@ describe("Api<T> type", () => {
73
69
  ];
74
70
  const cases: cases = [true, true];
75
71
  expect(cases).toBe(cases);
76
-
77
72
  });
78
-
79
- });
73
+ });