inferred-types 0.20.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.
- package/.eslintrc +36 -20
- package/.github/workflows/main.yml +34 -0
- package/.github/workflows/other.yml +15 -0
- package/.vscode/settings.json +10 -2
- package/dist/index.d.ts +398 -8541
- package/dist/index.js +17 -60
- package/dist/index.mjs +8 -48
- package/package.json +32 -24
- package/src/shared/valueTypes.ts +1 -1
- package/src/types/ExpandRecursively.ts +10 -1
- package/src/types/SimplifyObject.ts +12 -0
- package/src/types/Transformer.ts +1 -1
- package/src/types/alphabetic/CamelCase.ts +1 -1
- package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
- package/src/types/alphabetic/Dasherize.ts +8 -5
- package/src/types/alphabetic/KebabCase.ts +1 -1
- package/src/types/alphabetic/PascalCase.ts +3 -1
- package/src/types/alphabetic/SnakeCase.ts +8 -3
- package/src/types/dictionary/DictPartialApplication.ts +30 -0
- package/src/types/dictionary/DictPrependWithFn.ts +23 -0
- package/src/types/dictionary/DictReturnValues.ts +27 -0
- package/src/types/dictionary/RequireProps.ts +15 -0
- package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
- package/src/types/dictionary/index.ts +8 -3
- package/src/types/{props.ts → dictionary/props.ts} +1 -1
- package/src/types/functions/FinalReturn.ts +12 -0
- package/{on-hold/types → src/types/functions}/index.ts +4 -3
- package/src/types/index.ts +4 -3
- package/src/types/ruleset-types.ts +3 -3
- package/src/types/runtime.ts +18 -18
- package/src/types/string-literals/LeftWhitespace.ts +5 -2
- package/src/types/string-literals/RightWhitespace.ts +5 -2
- package/src/types/tuples/FirstKey.ts +3 -3
- package/src/types/tuples/FromDictArray.ts +5 -4
- package/src/types/type-conversion/index.ts +2 -5
- package/src/utility/api/api.ts +8 -7
- package/src/utility/dictionary/dictionaryTransform.ts +5 -4
- package/src/utility/dictionary/entries.ts +9 -5
- package/src/utility/dictionary/index.ts +2 -3
- package/src/utility/dictionary/kv/dictToKv.ts +5 -3
- package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
- package/src/utility/dictionary/kv/kv.ts +8 -3
- package/src/utility/dictionary/kv/kvToDict.ts +3 -2
- package/src/utility/dictionary/mapValues.ts +8 -5
- package/src/utility/dictionary/strArrayToDict.ts +1 -2
- package/src/utility/keys.ts +8 -4
- package/src/utility/lists/groupBy.ts +2 -9
- package/src/utility/literals/arrayToObject.ts +29 -29
- package/src/utility/literals/defineType.ts +6 -6
- package/src/utility/literals/identity.ts +5 -2
- package/src/utility/literals/literal.ts +3 -3
- package/src/utility/ruleset.ts +11 -9
- package/src/utility/runtime/condition.ts +1 -1
- package/src/utility/runtime/conditions/isFalse.ts +2 -2
- package/src/utility/runtime/conditions/isFunction.ts +2 -2
- package/src/utility/runtime/conditions/isObject.ts +4 -1
- package/src/utility/runtime/conditions/isTrue.ts +1 -1
- package/src/utility/runtime/ifTypeOf.ts +1 -1
- package/src/utility/runtime/type.ts +3 -1
- package/src/utility/runtime/withValue.ts +5 -3
- package/src/utility/state/Configurator.ts +2 -2
- package/src/utility/state/FluentConfigurator.ts +2 -2
- package/src/utility/state/index.ts +2 -3
- package/tests/CamelCase-spec.ts +2 -0
- package/tests/ExplicitFunction-spec.ts +3 -2
- package/tests/IncludeAndRetain-spec.ts +7 -12
- package/tests/Includes-spec.ts +2 -0
- package/tests/KebabCase-spec.ts +2 -0
- package/tests/MutationIdentity-spec.ts +2 -1
- package/tests/PascalCase-spec.ts +2 -0
- package/tests/Pluralize-spec.ts +2 -0
- package/tests/SnakeCase-spec.ts +2 -0
- package/tests/Where.spec.ts +9 -10
- package/tests/arrayToKeyLookup-spec.ts +5 -5
- package/tests/arrayToObject-spec.ts +12 -8
- package/tests/constructor.spec.ts +2 -0
- package/tests/createFnWithProps.spec.ts +2 -2
- package/tests/defineType-spec.ts +17 -11
- package/tests/dictionary/DictPartialApplication.test.ts +43 -0
- package/tests/dictionary/DictReturnValues.test.ts +32 -0
- package/tests/dictionary/Get.spec.ts +5 -3
- package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
- package/tests/dictionary/RequireProps.test.ts +21 -0
- package/tests/dictionaryTransform-spec.ts +3 -3
- package/tests/ifTypeOf-spec.ts +31 -20
- package/tests/kv/KeyValue-spec.ts +4 -4
- package/tests/kv/SameKeys-spec.ts +6 -9
- package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
- package/tests/kv/entries-spec.ts +8 -9
- package/tests/kv/keys.spec.ts +9 -19
- package/tests/kv/kv-spec.ts +4 -4
- package/tests/lists/UniqueForProp.spec.ts +3 -1
- package/tests/literal-spec.ts +5 -3
- package/tests/mapValues-spec.ts +5 -3
- package/tests/props-spec.ts +3 -2
- package/tests/runtime/condition.spec.ts +2 -1
- package/tests/runtime/type.spec.ts +4 -3
- package/tests/strArrayToDict-spec.ts +6 -6
- package/tests/string-literals/AllCaps.spec.ts +6 -15
- package/tests/string-literals/CamelCase.spec.ts +13 -32
- package/tests/string-literals/Dasherize.spec.ts +13 -31
- package/tests/string-literals/HasUppercase.spec.ts +6 -15
- package/tests/string-literals/PascalCase.spec.ts +13 -32
- package/tests/string-literals/SnakeCase.spec.ts +13 -32
- package/tests/string-literals/whitespace-capture.spec.ts +10 -28
- package/tests/tuples/TupleToUnion.spec.ts +3 -1
- package/tests/withValue.spec.ts +4 -3
- package/tsconfig.json +8 -19
- package/vitest.config.ts +13 -0
- package/jest.config.ts +0 -20
- package/on-hold/Builder/Builder.ts +0 -66
- package/on-hold/Builder/BuilderApi.ts +0 -21
- package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
- package/on-hold/Builder/MutationToFluentApi.ts +0 -60
- package/on-hold/Builder/index.ts +0 -35
- package/on-hold/tests/Builder-spec.ts +0 -310
- package/on-hold/tests/RuleSet-spec.ts +0 -59
- package/on-hold/tests/ToFluent-spec.ts +0 -60
- package/on-hold/tests/api-spec.ts +0 -73
- package/on-hold/tests/data/builder-data.ts +0 -53
- package/on-hold/tests/filterDictArray-spec.ts +0 -50
- package/on-hold/tests/run-time-spec.ts +0 -44
- package/on-hold/type.ts +0 -20
- package/on-hold/types/object.ts +0 -19
- package/on-hold/types/prop.ts +0 -28
- package/on-hold/types/scalar.ts +0 -37
- package/src/types/dictionary/NotEmptyObject.ts +0 -9
- package/src/types/type-conversion/UnwrapValue.ts +0 -13
- package/src/types/type-conversion/WrapValue.ts +0 -15
- package/src/utility/dictionary/valuesOfProp.ts +0 -13
- 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
|
|
28
|
-
if (
|
|
29
|
-
for (let key of __getOwnPropNames(
|
|
30
|
-
if (!__hasOwnProp.call(
|
|
31
|
-
__defProp(
|
|
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
|
|
16
|
+
return to;
|
|
34
17
|
};
|
|
35
|
-
var __toCommonJS =
|
|
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,
|
|
@@ -97,9 +75,9 @@ __export(src_exports, {
|
|
|
97
75
|
typeApi: () => typeApi,
|
|
98
76
|
uuid: () => uuid,
|
|
99
77
|
valueTypes: () => valueTypes,
|
|
100
|
-
valuesOfProp: () => valuesOfProp,
|
|
101
78
|
withValue: () => withValue
|
|
102
79
|
});
|
|
80
|
+
module.exports = __toCommonJS(src_exports);
|
|
103
81
|
|
|
104
82
|
// src/Mutation/MutationFunction.ts
|
|
105
83
|
function createMutationFunction(state) {
|
|
@@ -200,7 +178,7 @@ function arrayToKeyLookup(...keys2) {
|
|
|
200
178
|
function dictionaryTransform(input, transform) {
|
|
201
179
|
return keys(input).reduce((acc, i) => {
|
|
202
180
|
const key = i;
|
|
203
|
-
return
|
|
181
|
+
return { ...acc, [key]: transform(input, key) };
|
|
204
182
|
}, {});
|
|
205
183
|
}
|
|
206
184
|
|
|
@@ -224,15 +202,11 @@ function mapValues(obj, valueMapper) {
|
|
|
224
202
|
// src/utility/dictionary/strArrayToDict.ts
|
|
225
203
|
function strArrayToDict(...strings) {
|
|
226
204
|
return strings.reduce((acc, str) => {
|
|
227
|
-
acc =
|
|
205
|
+
acc = { ...acc, [str]: true };
|
|
228
206
|
return acc;
|
|
229
207
|
}, {});
|
|
230
208
|
}
|
|
231
209
|
|
|
232
|
-
// src/utility/dictionary/valuesOfProp.ts
|
|
233
|
-
function valuesOfProp() {
|
|
234
|
-
}
|
|
235
|
-
|
|
236
210
|
// src/utility/dictionary/kv/dictToKv.ts
|
|
237
211
|
function dictToKv(obj, _makeTuple = false) {
|
|
238
212
|
return keys(obj).map((k) => {
|
|
@@ -252,7 +226,7 @@ function Configurator() {
|
|
|
252
226
|
set(key, value) {
|
|
253
227
|
const keyValue = { [key]: value };
|
|
254
228
|
const config = configuration();
|
|
255
|
-
const updated =
|
|
229
|
+
const updated = { ...config, ...keyValue };
|
|
256
230
|
configuration = () => updated;
|
|
257
231
|
return updated;
|
|
258
232
|
},
|
|
@@ -276,7 +250,7 @@ function FluentConfigurator(initial = {}) {
|
|
|
276
250
|
return {
|
|
277
251
|
set(key, value) {
|
|
278
252
|
const keyValue = { [key]: value };
|
|
279
|
-
const updated =
|
|
253
|
+
const updated = { ...keyValue, ...current };
|
|
280
254
|
return api2(updated);
|
|
281
255
|
},
|
|
282
256
|
done() {
|
|
@@ -290,18 +264,6 @@ function FluentConfigurator(initial = {}) {
|
|
|
290
264
|
return initial ? api2(initial) : api2({});
|
|
291
265
|
}
|
|
292
266
|
|
|
293
|
-
// src/utility/state/KeyStorage.ts
|
|
294
|
-
function KeyStorage() {
|
|
295
|
-
const api2 = (state) => ({
|
|
296
|
-
add: (...store) => {
|
|
297
|
-
return api2([...state, ...store]);
|
|
298
|
-
},
|
|
299
|
-
remove: (key) => api2(state.filter((i) => i !== key)),
|
|
300
|
-
done: () => state
|
|
301
|
-
});
|
|
302
|
-
return api2([]);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
267
|
// src/utility/dictionary/kv/filterDictArray.ts
|
|
306
268
|
function filterDictArray(dictArr, cb) {
|
|
307
269
|
const state = Configurator();
|
|
@@ -333,8 +295,6 @@ function kvToDict(kvArr) {
|
|
|
333
295
|
// src/utility/lists/groupBy.ts
|
|
334
296
|
function groupBy(_data) {
|
|
335
297
|
throw new Error("not implemented");
|
|
336
|
-
return (_groupBy) => {
|
|
337
|
-
};
|
|
338
298
|
}
|
|
339
299
|
|
|
340
300
|
// src/utility/literals/ExplicitFunction.ts
|
|
@@ -345,9 +305,9 @@ function ExplicitFunction(fn) {
|
|
|
345
305
|
// src/utility/literals/arrayToObject.ts
|
|
346
306
|
function arrayToObject(prop, unique) {
|
|
347
307
|
const transform = (arr) => {
|
|
348
|
-
const result = unique !== false ? arr.reduce((acc, v) =>
|
|
308
|
+
const result = unique !== false ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
|
|
349
309
|
const existing = acc[v[prop]] || [];
|
|
350
|
-
return
|
|
310
|
+
return { ...acc, [v[prop]]: [...existing, v] };
|
|
351
311
|
}, {});
|
|
352
312
|
return result;
|
|
353
313
|
};
|
|
@@ -357,7 +317,7 @@ function arrayToObject(prop, unique) {
|
|
|
357
317
|
// src/utility/literals/defineType.ts
|
|
358
318
|
function defineType(literal2 = {}) {
|
|
359
319
|
return (wide = {}) => {
|
|
360
|
-
return literal2 ?
|
|
320
|
+
return literal2 ? { ...wide, ...literal2 } : wide;
|
|
361
321
|
};
|
|
362
322
|
}
|
|
363
323
|
|
|
@@ -366,7 +326,7 @@ var identity = (v) => v;
|
|
|
366
326
|
|
|
367
327
|
// src/utility/literals/literal.ts
|
|
368
328
|
function idLiteral(o) {
|
|
369
|
-
return
|
|
329
|
+
return { ...o, id: o.id };
|
|
370
330
|
}
|
|
371
331
|
function nameLiteral(o) {
|
|
372
332
|
return o;
|
|
@@ -635,13 +595,11 @@ function withValue(td) {
|
|
|
635
595
|
}));
|
|
636
596
|
};
|
|
637
597
|
}
|
|
638
|
-
module.exports = __toCommonJS(src_exports);
|
|
639
598
|
// Annotate the CommonJS export names for ESM import in node:
|
|
640
599
|
0 && (module.exports = {
|
|
641
600
|
Configurator,
|
|
642
601
|
ExplicitFunction,
|
|
643
602
|
FluentConfigurator,
|
|
644
|
-
KeyStorage,
|
|
645
603
|
Model,
|
|
646
604
|
MutationIdentity,
|
|
647
605
|
and,
|
|
@@ -694,6 +652,5 @@ module.exports = __toCommonJS(src_exports);
|
|
|
694
652
|
typeApi,
|
|
695
653
|
uuid,
|
|
696
654
|
valueTypes,
|
|
697
|
-
valuesOfProp,
|
|
698
655
|
withValue
|
|
699
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) => {
|
|
@@ -117,7 +97,7 @@ function arrayToKeyLookup(...keys2) {
|
|
|
117
97
|
function dictionaryTransform(input, transform) {
|
|
118
98
|
return keys(input).reduce((acc, i) => {
|
|
119
99
|
const key = i;
|
|
120
|
-
return
|
|
100
|
+
return { ...acc, [key]: transform(input, key) };
|
|
121
101
|
}, {});
|
|
122
102
|
}
|
|
123
103
|
|
|
@@ -141,15 +121,11 @@ function mapValues(obj, valueMapper) {
|
|
|
141
121
|
// src/utility/dictionary/strArrayToDict.ts
|
|
142
122
|
function strArrayToDict(...strings) {
|
|
143
123
|
return strings.reduce((acc, str) => {
|
|
144
|
-
acc =
|
|
124
|
+
acc = { ...acc, [str]: true };
|
|
145
125
|
return acc;
|
|
146
126
|
}, {});
|
|
147
127
|
}
|
|
148
128
|
|
|
149
|
-
// src/utility/dictionary/valuesOfProp.ts
|
|
150
|
-
function valuesOfProp() {
|
|
151
|
-
}
|
|
152
|
-
|
|
153
129
|
// src/utility/dictionary/kv/dictToKv.ts
|
|
154
130
|
function dictToKv(obj, _makeTuple = false) {
|
|
155
131
|
return keys(obj).map((k) => {
|
|
@@ -169,7 +145,7 @@ function Configurator() {
|
|
|
169
145
|
set(key, value) {
|
|
170
146
|
const keyValue = { [key]: value };
|
|
171
147
|
const config = configuration();
|
|
172
|
-
const updated =
|
|
148
|
+
const updated = { ...config, ...keyValue };
|
|
173
149
|
configuration = () => updated;
|
|
174
150
|
return updated;
|
|
175
151
|
},
|
|
@@ -193,7 +169,7 @@ function FluentConfigurator(initial = {}) {
|
|
|
193
169
|
return {
|
|
194
170
|
set(key, value) {
|
|
195
171
|
const keyValue = { [key]: value };
|
|
196
|
-
const updated =
|
|
172
|
+
const updated = { ...keyValue, ...current };
|
|
197
173
|
return api2(updated);
|
|
198
174
|
},
|
|
199
175
|
done() {
|
|
@@ -207,18 +183,6 @@ function FluentConfigurator(initial = {}) {
|
|
|
207
183
|
return initial ? api2(initial) : api2({});
|
|
208
184
|
}
|
|
209
185
|
|
|
210
|
-
// src/utility/state/KeyStorage.ts
|
|
211
|
-
function KeyStorage() {
|
|
212
|
-
const api2 = (state) => ({
|
|
213
|
-
add: (...store) => {
|
|
214
|
-
return api2([...state, ...store]);
|
|
215
|
-
},
|
|
216
|
-
remove: (key) => api2(state.filter((i) => i !== key)),
|
|
217
|
-
done: () => state
|
|
218
|
-
});
|
|
219
|
-
return api2([]);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
186
|
// src/utility/dictionary/kv/filterDictArray.ts
|
|
223
187
|
function filterDictArray(dictArr, cb) {
|
|
224
188
|
const state = Configurator();
|
|
@@ -250,8 +214,6 @@ function kvToDict(kvArr) {
|
|
|
250
214
|
// src/utility/lists/groupBy.ts
|
|
251
215
|
function groupBy(_data) {
|
|
252
216
|
throw new Error("not implemented");
|
|
253
|
-
return (_groupBy) => {
|
|
254
|
-
};
|
|
255
217
|
}
|
|
256
218
|
|
|
257
219
|
// src/utility/literals/ExplicitFunction.ts
|
|
@@ -262,9 +224,9 @@ function ExplicitFunction(fn) {
|
|
|
262
224
|
// src/utility/literals/arrayToObject.ts
|
|
263
225
|
function arrayToObject(prop, unique) {
|
|
264
226
|
const transform = (arr) => {
|
|
265
|
-
const result = unique !== false ? arr.reduce((acc, v) =>
|
|
227
|
+
const result = unique !== false ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
|
|
266
228
|
const existing = acc[v[prop]] || [];
|
|
267
|
-
return
|
|
229
|
+
return { ...acc, [v[prop]]: [...existing, v] };
|
|
268
230
|
}, {});
|
|
269
231
|
return result;
|
|
270
232
|
};
|
|
@@ -274,7 +236,7 @@ function arrayToObject(prop, unique) {
|
|
|
274
236
|
// src/utility/literals/defineType.ts
|
|
275
237
|
function defineType(literal2 = {}) {
|
|
276
238
|
return (wide = {}) => {
|
|
277
|
-
return literal2 ?
|
|
239
|
+
return literal2 ? { ...wide, ...literal2 } : wide;
|
|
278
240
|
};
|
|
279
241
|
}
|
|
280
242
|
|
|
@@ -283,7 +245,7 @@ var identity = (v) => v;
|
|
|
283
245
|
|
|
284
246
|
// src/utility/literals/literal.ts
|
|
285
247
|
function idLiteral(o) {
|
|
286
|
-
return
|
|
248
|
+
return { ...o, id: o.id };
|
|
287
249
|
}
|
|
288
250
|
function nameLiteral(o) {
|
|
289
251
|
return o;
|
|
@@ -556,7 +518,6 @@ export {
|
|
|
556
518
|
Configurator,
|
|
557
519
|
ExplicitFunction,
|
|
558
520
|
FluentConfigurator,
|
|
559
|
-
KeyStorage,
|
|
560
521
|
Model,
|
|
561
522
|
MutationIdentity,
|
|
562
523
|
and,
|
|
@@ -609,6 +570,5 @@ export {
|
|
|
609
570
|
typeApi,
|
|
610
571
|
uuid,
|
|
611
572
|
valueTypes,
|
|
612
|
-
valuesOfProp,
|
|
613
573
|
withValue
|
|
614
574
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inferred-types",
|
|
3
|
-
"version": "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,42 +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=
|
|
16
|
+
"build:bundle": "npx tsup src/index.ts --dts --format=esm,cjs --clean",
|
|
17
17
|
"watch": "run-p watch:*",
|
|
18
18
|
"watch:autoindex": "npx dd autoindex --watch",
|
|
19
|
-
"watch:bundle": "npx tsup src/index.ts --dts --format=
|
|
19
|
+
"watch:bundle": "npx tsup src/index.ts --dts --format=esm,cjs --watch",
|
|
20
20
|
"clean": "rimraf dist/**/*",
|
|
21
21
|
"lint": "eslint src/**/*.ts --fix && tsc --noEmit ",
|
|
22
22
|
"lint:full": "eslint src/**/*.ts && eslint test/**/*.ts && tsc --noEmit",
|
|
23
|
-
"test": "
|
|
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"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@type-challenges/utils": "~0.1.1",
|
|
27
|
-
"@types/
|
|
28
|
-
"@
|
|
29
|
-
"@typescript-eslint/
|
|
30
|
-
"
|
|
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",
|
|
31
36
|
"common-types": "^1.30.0",
|
|
32
37
|
"cross-env": "^7.0.3",
|
|
33
|
-
"dd": "^0.
|
|
34
|
-
"dotenv": "^
|
|
35
|
-
"eslint": "^8.
|
|
36
|
-
"eslint-config-prettier": "^8.
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
38
|
-
"eslint-plugin-prettier": "^4.
|
|
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",
|
|
39
44
|
"eslint-plugin-promise": "^6.0.0",
|
|
40
|
-
"eslint-plugin-unicorn": "^40.0.0",
|
|
41
|
-
"jest": "^27.4.7",
|
|
42
|
-
"jest-extended": "~1.2.0",
|
|
43
45
|
"npm-run-all": "~4.1.5",
|
|
44
|
-
"prettier": "~2.
|
|
46
|
+
"prettier": "~2.7.1",
|
|
45
47
|
"rimraf": "^3.0.2",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
48
|
+
"tsup": "^6.1.3",
|
|
49
|
+
"typescript": "^4.7.4",
|
|
50
|
+
"vite": "^3.0.2",
|
|
51
|
+
"vitest": "^0.19.0"
|
|
50
52
|
},
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"common-types": "^1.31.
|
|
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
|
+
}
|
|
53
61
|
}
|
|
54
|
-
}
|
|
62
|
+
}
|
package/src/shared/valueTypes.ts
CHANGED
|
@@ -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
|
-
?
|
|
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;
|
|
@@ -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
|
+
>;
|
package/src/types/Transformer.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import
|
|
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}`
|
|
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
|
-
|
|
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_
|
|
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
|
|
18
|
-
|
|
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,6 +1,8 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
2
2
|
|
|
3
|
-
import
|
|
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
|
|
20
|
-
|
|
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
|
+
>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SimplifyObject } from "../SimplifyObject";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **DictPrependWithFn**
|
|
5
|
+
*
|
|
6
|
+
* Given a strongly typed object `<T>`, this utility will inject a function call with
|
|
7
|
+
* arguments `<A>` and then return what had subsequently been the value of the property.
|
|
8
|
+
*
|
|
9
|
+
* Should you only want to apply this treatment to _some_ of the properties you can
|
|
10
|
+
* pass in a value `<E>` which will ensure that only properties which _extend_ `E` will be
|
|
11
|
+
* modified.
|
|
12
|
+
*/
|
|
13
|
+
export type DictPrependWithFn<
|
|
14
|
+
T extends Record<string, any>,
|
|
15
|
+
A extends any[],
|
|
16
|
+
E extends any = any
|
|
17
|
+
> = SimplifyObject<
|
|
18
|
+
{
|
|
19
|
+
[K in keyof T]: T[K] extends E
|
|
20
|
+
? Record<K, (...args: A) => T[K]>
|
|
21
|
+
: Record<K, T[K]>;
|
|
22
|
+
}[keyof T]
|
|
23
|
+
>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SimplifyObject } from "../SimplifyObject";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **DictReturnValues**
|
|
5
|
+
*
|
|
6
|
+
* A type utility which receives an object `<T>` and then modifies
|
|
7
|
+
* the return type of any properties which are a function to have this
|
|
8
|
+
* new **ReturnType** `<R>`. Optionally you can specify a particular return type which
|
|
9
|
+
* you are targeting and then
|
|
10
|
+
*/
|
|
11
|
+
export type DictReturnValues<
|
|
12
|
+
/** the object which we expect to have props with function values */
|
|
13
|
+
T extends Record<string, any>,
|
|
14
|
+
/** the return type that functions should be modified to have */
|
|
15
|
+
R extends any,
|
|
16
|
+
/** optionally this utility can target only functions with a certain existing return value */
|
|
17
|
+
O extends (...args: any[]) => any = (...args: any[]) => any
|
|
18
|
+
> = SimplifyObject<
|
|
19
|
+
{
|
|
20
|
+
[K in keyof T]: T[K] extends O
|
|
21
|
+
? // it's a function (or at least the scoped down type of function we're looking for)
|
|
22
|
+
T[K] extends (...args: infer A) => any
|
|
23
|
+
? Record<K, (...args: A) => R>
|
|
24
|
+
: Record<K, T[K]>
|
|
25
|
+
: Record<K, T[K]>;
|
|
26
|
+
}[keyof T]
|
|
27
|
+
>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExpandRecursively } from "../ExpandRecursively";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Given a dictionary of type `<T>`, this utility function will
|
|
5
|
+
* make the `<R>` generic property _required_ (use a union to make
|
|
6
|
+
* more than one prop required).
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // { foo: string, bar?: number }
|
|
10
|
+
* type Example = RequireProps<{foo?: string, bar?: number}, "foo">;
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type RequireProps<T extends {}, R extends keyof T> = ExpandRecursively<
|
|
14
|
+
Required<Pick<T, R>> & T
|
|
15
|
+
>;
|
|
File without changes
|