inferred-types 0.19.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/.eslintrc +36 -20
  2. package/.github/workflows/main.yml +34 -0
  3. package/.github/workflows/other.yml +15 -0
  4. package/.vscode/settings.json +10 -2
  5. package/dist/index.d.ts +403 -8538
  6. package/dist/index.js +35 -60
  7. package/dist/index.mjs +24 -48
  8. package/package.json +34 -23
  9. package/src/shared/valueTypes.ts +1 -1
  10. package/src/types/ExpandRecursively.ts +10 -1
  11. package/src/types/FunctionType.ts +1 -1
  12. package/src/types/SimplifyObject.ts +12 -0
  13. package/src/types/Transformer.ts +1 -1
  14. package/src/types/alphabetic/CamelCase.ts +1 -1
  15. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  16. package/src/types/alphabetic/Dasherize.ts +8 -5
  17. package/src/types/alphabetic/KebabCase.ts +1 -1
  18. package/src/types/alphabetic/PascalCase.ts +3 -1
  19. package/src/types/alphabetic/SnakeCase.ts +8 -3
  20. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  21. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  22. package/src/types/dictionary/DictReturnValues.ts +27 -0
  23. package/src/types/dictionary/RequireProps.ts +15 -0
  24. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  25. package/src/types/dictionary/index.ts +8 -3
  26. package/src/types/{props.ts → dictionary/props.ts} +1 -1
  27. package/src/types/functions/FinalReturn.ts +12 -0
  28. package/{on-hold/types → src/types/functions}/index.ts +4 -3
  29. package/src/types/index.ts +4 -3
  30. package/src/types/ruleset-types.ts +3 -3
  31. package/src/types/runtime.ts +18 -18
  32. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  33. package/src/types/string-literals/RightWhitespace.ts +5 -2
  34. package/src/types/tuples/FirstKey.ts +3 -3
  35. package/src/types/tuples/FromDictArray.ts +5 -4
  36. package/src/types/type-conversion/index.ts +2 -5
  37. package/src/utility/api/api.ts +8 -7
  38. package/src/utility/createFnWithProps.ts +26 -1
  39. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  40. package/src/utility/dictionary/entries.ts +9 -5
  41. package/src/utility/dictionary/index.ts +2 -3
  42. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  43. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  44. package/src/utility/dictionary/kv/kv.ts +8 -3
  45. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  46. package/src/utility/dictionary/mapValues.ts +8 -5
  47. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  48. package/src/utility/keys.ts +8 -4
  49. package/src/utility/lists/groupBy.ts +2 -9
  50. package/src/utility/literals/arrayToObject.ts +29 -29
  51. package/src/utility/literals/defineType.ts +6 -6
  52. package/src/utility/literals/identity.ts +5 -2
  53. package/src/utility/literals/literal.ts +3 -3
  54. package/src/utility/ruleset.ts +11 -9
  55. package/src/utility/runtime/condition.ts +1 -1
  56. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  57. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  58. package/src/utility/runtime/conditions/isObject.ts +4 -1
  59. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  60. package/src/utility/runtime/ifTypeOf.ts +1 -1
  61. package/src/utility/runtime/type.ts +3 -1
  62. package/src/utility/runtime/withValue.ts +5 -3
  63. package/src/utility/state/Configurator.ts +2 -2
  64. package/src/utility/state/FluentConfigurator.ts +2 -2
  65. package/src/utility/state/index.ts +2 -3
  66. package/tests/CamelCase-spec.ts +2 -0
  67. package/tests/ExplicitFunction-spec.ts +3 -2
  68. package/tests/IncludeAndRetain-spec.ts +7 -12
  69. package/tests/Includes-spec.ts +2 -0
  70. package/tests/KebabCase-spec.ts +2 -0
  71. package/tests/MutationIdentity-spec.ts +2 -1
  72. package/tests/PascalCase-spec.ts +2 -0
  73. package/tests/Pluralize-spec.ts +2 -0
  74. package/tests/SnakeCase-spec.ts +2 -0
  75. package/tests/Where.spec.ts +9 -10
  76. package/tests/arrayToKeyLookup-spec.ts +5 -5
  77. package/tests/arrayToObject-spec.ts +12 -8
  78. package/tests/constructor.spec.ts +2 -0
  79. package/tests/createFnWithProps.spec.ts +2 -2
  80. package/tests/defineType-spec.ts +17 -11
  81. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  82. package/tests/dictionary/DictReturnValues.test.ts +32 -0
  83. package/tests/dictionary/Get.spec.ts +5 -3
  84. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  85. package/tests/dictionary/RequireProps.test.ts +21 -0
  86. package/tests/dictionaryTransform-spec.ts +3 -3
  87. package/tests/ifTypeOf-spec.ts +31 -20
  88. package/tests/kv/KeyValue-spec.ts +4 -4
  89. package/tests/kv/SameKeys-spec.ts +6 -9
  90. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  91. package/tests/kv/entries-spec.ts +8 -9
  92. package/tests/kv/keys.spec.ts +9 -19
  93. package/tests/kv/kv-spec.ts +4 -4
  94. package/tests/lists/UniqueForProp.spec.ts +3 -1
  95. package/tests/literal-spec.ts +5 -3
  96. package/tests/mapValues-spec.ts +5 -3
  97. package/tests/props-spec.ts +3 -2
  98. package/tests/runtime/condition.spec.ts +2 -1
  99. package/tests/runtime/type.spec.ts +4 -3
  100. package/tests/strArrayToDict-spec.ts +6 -6
  101. package/tests/string-literals/AllCaps.spec.ts +6 -15
  102. package/tests/string-literals/CamelCase.spec.ts +13 -32
  103. package/tests/string-literals/Dasherize.spec.ts +13 -31
  104. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  105. package/tests/string-literals/PascalCase.spec.ts +13 -32
  106. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  107. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  108. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  109. package/tests/withValue.spec.ts +4 -3
  110. package/tsconfig.json +8 -19
  111. package/vitest.config.ts +13 -0
  112. package/jest.config.ts +0 -20
  113. package/on-hold/Builder/Builder.ts +0 -66
  114. package/on-hold/Builder/BuilderApi.ts +0 -21
  115. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  116. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  117. package/on-hold/Builder/index.ts +0 -35
  118. package/on-hold/tests/Builder-spec.ts +0 -310
  119. package/on-hold/tests/RuleSet-spec.ts +0 -59
  120. package/on-hold/tests/ToFluent-spec.ts +0 -60
  121. package/on-hold/tests/api-spec.ts +0 -73
  122. package/on-hold/tests/data/builder-data.ts +0 -53
  123. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  124. package/on-hold/tests/run-time-spec.ts +0 -44
  125. package/on-hold/type.ts +0 -20
  126. package/on-hold/types/object.ts +0 -19
  127. package/on-hold/types/prop.ts +0 -28
  128. package/on-hold/types/scalar.ts +0 -37
  129. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  130. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  131. package/src/types/type-conversion/WrapValue.ts +0 -15
  132. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  133. package/src/utility/state/KeyStorage.ts +0 -23
package/dist/index.js CHANGED
@@ -1,42 +1,21 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
23
6
  var __export = (target, all) => {
24
7
  for (var name in all)
25
8
  __defProp(target, name, { get: all[name], enumerable: true });
26
9
  };
27
- var __reExport = (target, module2, copyDefault, desc) => {
28
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
29
- for (let key of __getOwnPropNames(module2))
30
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
31
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
15
  }
33
- return target;
16
+ return to;
34
17
  };
35
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
36
- return (module2, temp) => {
37
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
38
- };
39
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
19
 
41
20
  // src/index.ts
42
21
  var src_exports = {};
@@ -44,7 +23,6 @@ __export(src_exports, {
44
23
  Configurator: () => Configurator,
45
24
  ExplicitFunction: () => ExplicitFunction,
46
25
  FluentConfigurator: () => FluentConfigurator,
47
- KeyStorage: () => KeyStorage,
48
26
  Model: () => Model,
49
27
  MutationIdentity: () => MutationIdentity,
50
28
  and: () => and,
@@ -60,6 +38,7 @@ __export(src_exports, {
60
38
  entries: () => entries,
61
39
  equals: () => equals,
62
40
  filterDictArray: () => filterDictArray,
41
+ fnWithProps: () => fnWithProps,
63
42
  greater: () => greater,
64
43
  groupBy: () => groupBy,
65
44
  idLiteral: () => idLiteral,
@@ -89,15 +68,16 @@ __export(src_exports, {
89
68
  nameLiteral: () => nameLiteral,
90
69
  or: () => or,
91
70
  randomString: () => randomString,
71
+ readonlyFnWithProps: () => readonlyFnWithProps,
92
72
  ruleSet: () => ruleSet,
93
73
  strArrayToDict: () => strArrayToDict,
94
74
  type: () => type,
95
75
  typeApi: () => typeApi,
96
76
  uuid: () => uuid,
97
77
  valueTypes: () => valueTypes,
98
- valuesOfProp: () => valuesOfProp,
99
78
  withValue: () => withValue
100
79
  });
80
+ module.exports = __toCommonJS(src_exports);
101
81
 
102
82
  // src/Mutation/MutationFunction.ts
103
83
  function createMutationFunction(state) {
@@ -158,6 +138,20 @@ function createFnWithProps(fn, props) {
158
138
  return combined;
159
139
  })();
160
140
  }
141
+ function fnWithProps(fn, props) {
142
+ let combined = fn;
143
+ for (const prop of keys(props)) {
144
+ combined[prop] = props[prop];
145
+ }
146
+ return combined;
147
+ }
148
+ function readonlyFnWithProps(fn, props) {
149
+ let combined = fn;
150
+ for (const prop of keys(props)) {
151
+ combined[prop] = props[prop];
152
+ }
153
+ return combined;
154
+ }
161
155
 
162
156
  // src/utility/ruleset.ts
163
157
  function ruleSet(defn) {
@@ -184,7 +178,7 @@ function arrayToKeyLookup(...keys2) {
184
178
  function dictionaryTransform(input, transform) {
185
179
  return keys(input).reduce((acc, i) => {
186
180
  const key = i;
187
- return __spreadProps(__spreadValues({}, acc), { [key]: transform(input, key) });
181
+ return { ...acc, [key]: transform(input, key) };
188
182
  }, {});
189
183
  }
190
184
 
@@ -208,15 +202,11 @@ function mapValues(obj, valueMapper) {
208
202
  // src/utility/dictionary/strArrayToDict.ts
209
203
  function strArrayToDict(...strings) {
210
204
  return strings.reduce((acc, str) => {
211
- acc = __spreadProps(__spreadValues({}, acc), { [str]: true });
205
+ acc = { ...acc, [str]: true };
212
206
  return acc;
213
207
  }, {});
214
208
  }
215
209
 
216
- // src/utility/dictionary/valuesOfProp.ts
217
- function valuesOfProp() {
218
- }
219
-
220
210
  // src/utility/dictionary/kv/dictToKv.ts
221
211
  function dictToKv(obj, _makeTuple = false) {
222
212
  return keys(obj).map((k) => {
@@ -236,7 +226,7 @@ function Configurator() {
236
226
  set(key, value) {
237
227
  const keyValue = { [key]: value };
238
228
  const config = configuration();
239
- const updated = __spreadValues(__spreadValues({}, config), keyValue);
229
+ const updated = { ...config, ...keyValue };
240
230
  configuration = () => updated;
241
231
  return updated;
242
232
  },
@@ -260,7 +250,7 @@ function FluentConfigurator(initial = {}) {
260
250
  return {
261
251
  set(key, value) {
262
252
  const keyValue = { [key]: value };
263
- const updated = __spreadValues(__spreadValues({}, keyValue), current);
253
+ const updated = { ...keyValue, ...current };
264
254
  return api2(updated);
265
255
  },
266
256
  done() {
@@ -274,18 +264,6 @@ function FluentConfigurator(initial = {}) {
274
264
  return initial ? api2(initial) : api2({});
275
265
  }
276
266
 
277
- // src/utility/state/KeyStorage.ts
278
- function KeyStorage() {
279
- const api2 = (state) => ({
280
- add: (...store) => {
281
- return api2([...state, ...store]);
282
- },
283
- remove: (key) => api2(state.filter((i) => i !== key)),
284
- done: () => state
285
- });
286
- return api2([]);
287
- }
288
-
289
267
  // src/utility/dictionary/kv/filterDictArray.ts
290
268
  function filterDictArray(dictArr, cb) {
291
269
  const state = Configurator();
@@ -317,8 +295,6 @@ function kvToDict(kvArr) {
317
295
  // src/utility/lists/groupBy.ts
318
296
  function groupBy(_data) {
319
297
  throw new Error("not implemented");
320
- return (_groupBy) => {
321
- };
322
298
  }
323
299
 
324
300
  // src/utility/literals/ExplicitFunction.ts
@@ -329,9 +305,9 @@ function ExplicitFunction(fn) {
329
305
  // src/utility/literals/arrayToObject.ts
330
306
  function arrayToObject(prop, unique) {
331
307
  const transform = (arr) => {
332
- const result = unique !== false ? arr.reduce((acc, v) => __spreadProps(__spreadValues({}, acc), { [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
308
+ const result = unique !== false ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
333
309
  const existing = acc[v[prop]] || [];
334
- return __spreadProps(__spreadValues({}, acc), { [v[prop]]: [...existing, v] });
310
+ return { ...acc, [v[prop]]: [...existing, v] };
335
311
  }, {});
336
312
  return result;
337
313
  };
@@ -341,7 +317,7 @@ function arrayToObject(prop, unique) {
341
317
  // src/utility/literals/defineType.ts
342
318
  function defineType(literal2 = {}) {
343
319
  return (wide = {}) => {
344
- return literal2 ? __spreadValues(__spreadValues({}, wide), literal2) : wide;
320
+ return literal2 ? { ...wide, ...literal2 } : wide;
345
321
  };
346
322
  }
347
323
 
@@ -350,7 +326,7 @@ var identity = (v) => v;
350
326
 
351
327
  // src/utility/literals/literal.ts
352
328
  function idLiteral(o) {
353
- return __spreadProps(__spreadValues({}, o), { id: o.id });
329
+ return { ...o, id: o.id };
354
330
  }
355
331
  function nameLiteral(o) {
356
332
  return o;
@@ -619,13 +595,11 @@ function withValue(td) {
619
595
  }));
620
596
  };
621
597
  }
622
- module.exports = __toCommonJS(src_exports);
623
598
  // Annotate the CommonJS export names for ESM import in node:
624
599
  0 && (module.exports = {
625
600
  Configurator,
626
601
  ExplicitFunction,
627
602
  FluentConfigurator,
628
- KeyStorage,
629
603
  Model,
630
604
  MutationIdentity,
631
605
  and,
@@ -641,6 +615,7 @@ module.exports = __toCommonJS(src_exports);
641
615
  entries,
642
616
  equals,
643
617
  filterDictArray,
618
+ fnWithProps,
644
619
  greater,
645
620
  groupBy,
646
621
  idLiteral,
@@ -670,12 +645,12 @@ module.exports = __toCommonJS(src_exports);
670
645
  nameLiteral,
671
646
  or,
672
647
  randomString,
648
+ readonlyFnWithProps,
673
649
  ruleSet,
674
650
  strArrayToDict,
675
651
  type,
676
652
  typeApi,
677
653
  uuid,
678
654
  valueTypes,
679
- valuesOfProp,
680
655
  withValue
681
656
  });
package/dist/index.mjs CHANGED
@@ -1,23 +1,3 @@
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
1
  // src/Mutation/MutationFunction.ts
22
2
  function createMutationFunction(state) {
23
3
  return (mutationIdentity) => {
@@ -77,6 +57,20 @@ function createFnWithProps(fn, props) {
77
57
  return combined;
78
58
  })();
79
59
  }
60
+ function fnWithProps(fn, props) {
61
+ let combined = fn;
62
+ for (const prop of keys(props)) {
63
+ combined[prop] = props[prop];
64
+ }
65
+ return combined;
66
+ }
67
+ function readonlyFnWithProps(fn, props) {
68
+ let combined = fn;
69
+ for (const prop of keys(props)) {
70
+ combined[prop] = props[prop];
71
+ }
72
+ return combined;
73
+ }
80
74
 
81
75
  // src/utility/ruleset.ts
82
76
  function ruleSet(defn) {
@@ -103,7 +97,7 @@ function arrayToKeyLookup(...keys2) {
103
97
  function dictionaryTransform(input, transform) {
104
98
  return keys(input).reduce((acc, i) => {
105
99
  const key = i;
106
- return __spreadProps(__spreadValues({}, acc), { [key]: transform(input, key) });
100
+ return { ...acc, [key]: transform(input, key) };
107
101
  }, {});
108
102
  }
109
103
 
@@ -127,15 +121,11 @@ function mapValues(obj, valueMapper) {
127
121
  // src/utility/dictionary/strArrayToDict.ts
128
122
  function strArrayToDict(...strings) {
129
123
  return strings.reduce((acc, str) => {
130
- acc = __spreadProps(__spreadValues({}, acc), { [str]: true });
124
+ acc = { ...acc, [str]: true };
131
125
  return acc;
132
126
  }, {});
133
127
  }
134
128
 
135
- // src/utility/dictionary/valuesOfProp.ts
136
- function valuesOfProp() {
137
- }
138
-
139
129
  // src/utility/dictionary/kv/dictToKv.ts
140
130
  function dictToKv(obj, _makeTuple = false) {
141
131
  return keys(obj).map((k) => {
@@ -155,7 +145,7 @@ function Configurator() {
155
145
  set(key, value) {
156
146
  const keyValue = { [key]: value };
157
147
  const config = configuration();
158
- const updated = __spreadValues(__spreadValues({}, config), keyValue);
148
+ const updated = { ...config, ...keyValue };
159
149
  configuration = () => updated;
160
150
  return updated;
161
151
  },
@@ -179,7 +169,7 @@ function FluentConfigurator(initial = {}) {
179
169
  return {
180
170
  set(key, value) {
181
171
  const keyValue = { [key]: value };
182
- const updated = __spreadValues(__spreadValues({}, keyValue), current);
172
+ const updated = { ...keyValue, ...current };
183
173
  return api2(updated);
184
174
  },
185
175
  done() {
@@ -193,18 +183,6 @@ function FluentConfigurator(initial = {}) {
193
183
  return initial ? api2(initial) : api2({});
194
184
  }
195
185
 
196
- // src/utility/state/KeyStorage.ts
197
- function KeyStorage() {
198
- const api2 = (state) => ({
199
- add: (...store) => {
200
- return api2([...state, ...store]);
201
- },
202
- remove: (key) => api2(state.filter((i) => i !== key)),
203
- done: () => state
204
- });
205
- return api2([]);
206
- }
207
-
208
186
  // src/utility/dictionary/kv/filterDictArray.ts
209
187
  function filterDictArray(dictArr, cb) {
210
188
  const state = Configurator();
@@ -236,8 +214,6 @@ function kvToDict(kvArr) {
236
214
  // src/utility/lists/groupBy.ts
237
215
  function groupBy(_data) {
238
216
  throw new Error("not implemented");
239
- return (_groupBy) => {
240
- };
241
217
  }
242
218
 
243
219
  // src/utility/literals/ExplicitFunction.ts
@@ -248,9 +224,9 @@ function ExplicitFunction(fn) {
248
224
  // src/utility/literals/arrayToObject.ts
249
225
  function arrayToObject(prop, unique) {
250
226
  const transform = (arr) => {
251
- const result = unique !== false ? arr.reduce((acc, v) => __spreadProps(__spreadValues({}, acc), { [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
227
+ const result = unique !== false ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
252
228
  const existing = acc[v[prop]] || [];
253
- return __spreadProps(__spreadValues({}, acc), { [v[prop]]: [...existing, v] });
229
+ return { ...acc, [v[prop]]: [...existing, v] };
254
230
  }, {});
255
231
  return result;
256
232
  };
@@ -260,7 +236,7 @@ function arrayToObject(prop, unique) {
260
236
  // src/utility/literals/defineType.ts
261
237
  function defineType(literal2 = {}) {
262
238
  return (wide = {}) => {
263
- return literal2 ? __spreadValues(__spreadValues({}, wide), literal2) : wide;
239
+ return literal2 ? { ...wide, ...literal2 } : wide;
264
240
  };
265
241
  }
266
242
 
@@ -269,7 +245,7 @@ var identity = (v) => v;
269
245
 
270
246
  // src/utility/literals/literal.ts
271
247
  function idLiteral(o) {
272
- return __spreadProps(__spreadValues({}, o), { id: o.id });
248
+ return { ...o, id: o.id };
273
249
  }
274
250
  function nameLiteral(o) {
275
251
  return o;
@@ -542,7 +518,6 @@ export {
542
518
  Configurator,
543
519
  ExplicitFunction,
544
520
  FluentConfigurator,
545
- KeyStorage,
546
521
  Model,
547
522
  MutationIdentity,
548
523
  and,
@@ -558,6 +533,7 @@ export {
558
533
  entries,
559
534
  equals,
560
535
  filterDictArray,
536
+ fnWithProps,
561
537
  greater,
562
538
  groupBy,
563
539
  idLiteral,
@@ -587,12 +563,12 @@ export {
587
563
  nameLiteral,
588
564
  or,
589
565
  randomString,
566
+ readonlyFnWithProps,
590
567
  ruleSet,
591
568
  strArrayToDict,
592
569
  type,
593
570
  typeApi,
594
571
  uuid,
595
572
  valueTypes,
596
- valuesOfProp,
597
573
  withValue
598
574
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.19.0",
3
+ "version": "0.22.0",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
@@ -13,39 +13,50 @@
13
13
  "autoindex": "npx dd autoindex",
14
14
  "build": "run-s clean autoindex lint build:bundle",
15
15
  "build:force": "run-s clean autoindex build:bundle",
16
- "build:bundle": "npx tsup src/index.ts --dts --format='esm,cjs'",
16
+ "build:bundle": "npx tsup src/index.ts --dts --format=esm,cjs --clean",
17
+ "watch": "run-p watch:*",
18
+ "watch:autoindex": "npx dd autoindex --watch",
19
+ "watch:bundle": "npx tsup src/index.ts --dts --format=esm,cjs --watch",
17
20
  "clean": "rimraf dist/**/*",
18
21
  "lint": "eslint src/**/*.ts --fix && tsc --noEmit ",
19
22
  "lint:full": "eslint src/**/*.ts && eslint test/**/*.ts && tsc --noEmit",
20
- "test": "jest"
23
+ "test": "vitest",
24
+ "test:ci": "vitest run",
25
+ "audit:fix": "pnpm audit --fix",
26
+ "release": "run-s lint release:latest test:ci audit:fix release:bump",
27
+ "release:latest": "pnpm install",
28
+ "release:bump": "bumpp"
21
29
  },
22
30
  "devDependencies": {
23
31
  "@type-challenges/utils": "~0.1.1",
24
- "@types/jest": "^27.4.0",
25
- "@types/node": "^14.18.5",
26
- "@typescript-eslint/eslint-plugin": "^5.9.1",
27
- "@typescript-eslint/parser": "^5.9.1",
32
+ "@types/node": "^16.11.45",
33
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
34
+ "@typescript-eslint/parser": "^5.30.7",
35
+ "bumpp": "^8.2.1",
28
36
  "common-types": "^1.30.0",
29
37
  "cross-env": "^7.0.3",
30
- "dd": "^0.18.0",
31
- "dotenv": "^10.0.0",
32
- "eslint": "^8.6.0",
33
- "eslint-config-prettier": "^8.3.0",
34
- "eslint-plugin-import": "^2.25.4",
35
- "eslint-plugin-prettier": "^4.0.0",
38
+ "dd": "^0.21.0",
39
+ "dotenv": "^16.0.1",
40
+ "eslint": "^8.20.0",
41
+ "eslint-config-prettier": "^8.5.0",
42
+ "eslint-plugin-import": "^2.26.0",
43
+ "eslint-plugin-prettier": "^4.2.1",
36
44
  "eslint-plugin-promise": "^6.0.0",
37
- "eslint-plugin-unicorn": "^40.0.0",
38
- "jest": "^27.4.7",
39
- "jest-extended": "~1.2.0",
40
45
  "npm-run-all": "~4.1.5",
41
- "prettier": "~2.5.1",
46
+ "prettier": "~2.7.1",
42
47
  "rimraf": "^3.0.2",
43
- "ts-jest": "^27.1.2",
44
- "ts-node": "^10.4.0",
45
- "tsup": "^5.11.11",
46
- "typescript": "^4.5.4"
48
+ "tsup": "^6.1.3",
49
+ "typescript": "^4.7.4",
50
+ "vite": "^3.0.2",
51
+ "vitest": "^0.19.0"
47
52
  },
48
53
  "dependencies": {
49
- "common-types": "^1.31.0"
54
+ "common-types": "^1.31.1"
55
+ },
56
+ "pnpm": {
57
+ "overrides": {
58
+ "simple-git@<3.3.0": ">=3.3.0",
59
+ "simple-git@<3.5.0": ">=3.5.0"
60
+ }
50
61
  }
51
- }
62
+ }
@@ -1,4 +1,4 @@
1
- import { Narrowable } from "~/types/Narrowable";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
 
3
3
  export type ValueTuple = [type: any, narrowable: boolean];
4
4
 
@@ -1,3 +1,12 @@
1
+
2
+ /**
3
+ * Recursively goes over an object based structure and tries to reduce
4
+ * it down to just a simple key/value type.
5
+ */
1
6
  export type ExpandRecursively<T> = T extends object
2
- ? { [K in keyof T]: ExpandRecursively<T[K]> }
7
+ ? T extends (...args: any[]) => any
8
+ // Functions should be treated like any other non-object value
9
+ // but will/can identify as an object in JS
10
+ ? T
11
+ : { [K in keyof T]: ExpandRecursively<T[K]> }
3
12
  : T;
@@ -6,4 +6,4 @@
6
6
  */
7
7
  export type FunctionType<T extends {} = {}> = {} extends T
8
8
  ? Function | (Function & { [key: string]: any })
9
- : Function | (Function & T);
9
+ : Function | (Function & T);
@@ -0,0 +1,12 @@
1
+ import { ExpandRecursively } from "./ExpandRecursively";
2
+ import { UnionToIntersection } from "./type-conversion/UnionToIntersection";
3
+
4
+ /**
5
+ * Often when mutating the shape of an object you will end up with the union of a number of
6
+ * `Record<string, x>` and `Record<string, y>` which is messy to look at and take away meaning.
7
+ *
8
+ * This type utility will cleanup an object and return a simple dictionary definition for it.
9
+ */
10
+ export type SimplifyObject<T extends {}> = ExpandRecursively<
11
+ UnionToIntersection<ExpandRecursively<T>>
12
+ >;
@@ -1,4 +1,4 @@
1
- import { SameKeys } from "./type-conversion/SameKeys";
1
+ import { SameKeys } from "./dictionary/SameKeys";
2
2
 
3
3
  /**
4
4
  * **Transformer**
@@ -1,3 +1,3 @@
1
- import { PascalCase } from "~/types/alphabetic";
1
+ import { PascalCase } from "./PascalCase";
2
2
 
3
3
  export type CamelCase<S extends string> = Uncapitalize<PascalCase<S>>;
@@ -1,9 +1,14 @@
1
- import type { NonAlpha, Replace } from "~/types";
1
+ import { Replace } from "../string-literals";
2
+ import { NonAlpha } from "./alpha-characters";
2
3
 
3
4
  /**
4
5
  * Strips the non-alpha characters that lead a string
5
6
  */
6
- export type StripLeftNonAlpha<S extends string> = S extends `${infer First}${infer Rest}` ? First extends NonAlpha ? StripLeftNonAlpha<Rest> : S : never;
7
+ export type StripLeftNonAlpha<S extends string> = S extends `${infer First}${infer Rest}`
8
+ ? First extends NonAlpha
9
+ ? StripLeftNonAlpha<Rest>
10
+ : S
11
+ : never;
7
12
 
8
13
  /**
9
14
  * identifies the leading characters which are _not_ alphabetical
@@ -16,4 +21,3 @@ export type LeadingNonAlpha<S extends string> = Replace<S, StripLeftNonAlpha<S>,
16
21
  export type CapFirstAlpha<T extends string> = LeadingNonAlpha<T> extends string
17
22
  ? `${LeadingNonAlpha<T>}${Capitalize<Replace<T, LeadingNonAlpha<T>, "">>}`
18
23
  : Capitalize<T>;
19
-
@@ -1,10 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { DashUppercase, LowerAllCaps } from "~/types";
2
+
3
3
  import { Trim } from "../string-literals";
4
+ import { DashUppercase } from "./DashUppercase";
5
+ import { LowerAllCaps } from "./LowerAllCaps";
4
6
 
5
7
  /**
6
- * Converts a string literal into a _dasherized_ format while ignoring _exterior_ whitepace.
7
- *
8
+ * Converts a string literal into a _dasherized_ format while ignoring _exterior_ whitespace.
9
+ *
8
10
  * ```ts
9
11
  * // "foo-bar"
10
12
  * type Dash = Dasherize<"foo_bar">;
@@ -14,7 +16,8 @@ import { Trim } from "../string-literals";
14
16
  * type Dash = Dasherize<"\n foo bar \t">;
15
17
  * ```
16
18
  */
17
- export type Dasherize<S extends string> = string extends S ? string :
18
- DashUppercase<Trim<LowerAllCaps<S>>> extends `${infer Begin}${"_" | " "}${infer Rest}`
19
+ export type Dasherize<S extends string> = string extends S
20
+ ? string
21
+ : DashUppercase<Trim<LowerAllCaps<S>>> extends `${infer Begin}${"_" | " "}${infer Rest}`
19
22
  ? Dasherize<`${Lowercase<Begin>}-${Rest}`>
20
23
  : Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
@@ -1,4 +1,4 @@
1
- import type { Dasherize } from "~/types/alphabetic";
1
+ import { Dasherize } from "./Dasherize";
2
2
 
3
3
  /**
4
4
  * **KebabCase<T>** is an _alias_ for **Dasherize<T>**.
@@ -1,5 +1,7 @@
1
1
  /* eslint @typescript-eslint/no-unused-vars: "off" */
2
- import type { LowerAllCaps, Trim } from "~/types";
2
+
3
+ import { Trim } from "../string-literals";
4
+ import { LowerAllCaps } from "./LowerAllCaps";
3
5
 
4
6
  type Delimiter = "_" | "-" | " ";
5
7
 
@@ -1,6 +1,8 @@
1
1
  /* eslint @typescript-eslint/no-unused-vars: "off" */
2
2
 
3
- import type { DashUppercase, LowerAllCaps, Trim } from "~/types";
3
+ import { Trim } from "../string-literals";
4
+ import { DashUppercase } from "./DashUppercase";
5
+ import { LowerAllCaps } from "./LowerAllCaps";
4
6
 
5
7
  /** convert space to dash */
6
8
  type SpaceToDash<T extends string> = T extends `${infer Begin}${" "}${infer Rest}`
@@ -16,7 +18,10 @@ type SpaceToDash<T extends string> = T extends `${infer Begin}${" "}${infer Rest
16
18
  * type T = SnakeCase<"foo-bar">;
17
19
  * type T = SnakeCase<"\n foo bar \t">;
18
20
  * ``` */
19
- export type SnakeCase<S extends string> = string extends S ? string :
20
- DashUppercase<Uncapitalize<SpaceToDash<Trim<LowerAllCaps<S>>>>> extends `${infer Begin}${"-"}${infer Rest}`
21
+ export type SnakeCase<S extends string> = string extends S
22
+ ? string
23
+ : DashUppercase<
24
+ Uncapitalize<SpaceToDash<Trim<LowerAllCaps<S>>>>
25
+ > extends `${infer Begin}${"-"}${infer Rest}`
21
26
  ? SnakeCase<`${Lowercase<Begin>}_${Rest}`>
22
27
  : Lowercase<DashUppercase<Uncapitalize<Trim<LowerAllCaps<S>>>>>;
@@ -0,0 +1,30 @@
1
+ import { SimplifyObject } from "../SimplifyObject";
2
+
3
+ /**
4
+ * Given a dictionary of key/values, where the value is a function, this
5
+ * type utility will maintain the keys but change the values to whatever
6
+ * the `ReturnType` of the function was.
7
+ * ```ts
8
+ * const api = {
9
+ * val: 42,
10
+ * hi: (name: string) => `hi ${name}`,
11
+ * bye: (name: string) => `bye ${name}`
12
+ * };
13
+ * // { hi: string; bye: string }
14
+ * type Test = UnwrapValue<typeof api>
15
+ * // { val: number; foo: string; bar: string }
16
+ * type Test2 = UnwrapValue<typeof api, false>
17
+ * ```
18
+ */
19
+ export type DictPartialApplication<
20
+ T extends Record<string, any>,
21
+ I extends boolean = true
22
+ > = SimplifyObject<
23
+ {
24
+ [K in keyof T]: T[K] extends (...args: any[]) => any
25
+ ? Record<K, ReturnType<T[K]>>
26
+ : true extends I
27
+ ? never
28
+ : Record<K, T[K]>;
29
+ }[keyof T]
30
+ >;