inferred-types 0.54.7 → 0.54.9
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/README.md +81 -36
- package/modules/inferred-types/dist/index.cjs +158 -33
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +22519 -22370
- package/modules/inferred-types/dist/index.js +153 -33
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +170 -33
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +7110 -6988
- package/modules/runtime/dist/index.js +165 -33
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +10080 -10053
- package/package.json +1 -1
|
@@ -233,12 +233,14 @@ __export(src_exports, {
|
|
|
233
233
|
isLuminosityUom: () => isLuminosityUom,
|
|
234
234
|
isLuxonDateTime: () => isLuxonDateTime,
|
|
235
235
|
isMacysUrl: () => isMacysUrl,
|
|
236
|
+
isMap: () => isMap,
|
|
236
237
|
isMapToken: () => isMapToken,
|
|
237
238
|
isMassMetric: () => isMassMetric,
|
|
238
239
|
isMassUom: () => isMassUom,
|
|
239
240
|
isMetric: () => isMetric,
|
|
240
241
|
isMexicanNewsUrl: () => isMexicanNewsUrl,
|
|
241
242
|
isMoment: () => isMoment,
|
|
243
|
+
isNarrowableObject: () => isNarrowableObject,
|
|
242
244
|
isNever: () => isNever,
|
|
243
245
|
isNewsUrl: () => isNewsUrl,
|
|
244
246
|
isNikeUrl: () => isNikeUrl,
|
|
@@ -273,6 +275,7 @@ __export(src_exports, {
|
|
|
273
275
|
isSet: () => isSet,
|
|
274
276
|
isSetBasedKind: () => isSetBasedKind,
|
|
275
277
|
isSetBasedToken: () => isSetBasedToken,
|
|
278
|
+
isSetContainer: () => isSetContainer,
|
|
276
279
|
isSetToken: () => isSetToken,
|
|
277
280
|
isShape: () => isShape,
|
|
278
281
|
isShapeCallback: () => isShapeCallback,
|
|
@@ -382,6 +385,7 @@ __export(src_exports, {
|
|
|
382
385
|
narrowObjectToType: () => narrowObjectToType,
|
|
383
386
|
never: () => never,
|
|
384
387
|
objectToApi: () => objectToApi,
|
|
388
|
+
objectValues: () => objectValues,
|
|
385
389
|
omit: () => omit,
|
|
386
390
|
optional: () => optional,
|
|
387
391
|
optionalOrNull: () => optionalOrNull,
|
|
@@ -458,6 +462,7 @@ __export(src_exports, {
|
|
|
458
462
|
widen: () => widen,
|
|
459
463
|
withDefaults: () => withDefaults,
|
|
460
464
|
withKeys: () => withKeys,
|
|
465
|
+
withValue: () => withValue,
|
|
461
466
|
withoutKeys: () => withoutKeys,
|
|
462
467
|
withoutValue: () => withoutValue,
|
|
463
468
|
wrapFn: () => wrapFn,
|
|
@@ -2665,6 +2670,18 @@ function narrowObjectToType() {
|
|
|
2665
2670
|
);
|
|
2666
2671
|
}
|
|
2667
2672
|
|
|
2673
|
+
// src/dictionary/objectValues.ts
|
|
2674
|
+
function objectValues(obj) {
|
|
2675
|
+
const tuple3 = Object.keys(obj).reduce(
|
|
2676
|
+
(acc, key) => [
|
|
2677
|
+
...acc,
|
|
2678
|
+
obj[key]
|
|
2679
|
+
],
|
|
2680
|
+
[]
|
|
2681
|
+
);
|
|
2682
|
+
return tuple3;
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2668
2685
|
// src/dictionary/omit.ts
|
|
2669
2686
|
function omit(obj, ...removeKeys) {
|
|
2670
2687
|
const keys = Object.keys(obj);
|
|
@@ -2731,13 +2748,115 @@ function withoutKeys(dict, ...exclude) {
|
|
|
2731
2748
|
return omit(dict, ...exclude);
|
|
2732
2749
|
}
|
|
2733
2750
|
|
|
2751
|
+
// src/runtime-types/doesExtend.ts
|
|
2752
|
+
function doesExtend(type) {
|
|
2753
|
+
return (val) => {
|
|
2754
|
+
let response = false;
|
|
2755
|
+
if (isString(val)) {
|
|
2756
|
+
if (type === "string") {
|
|
2757
|
+
response = true;
|
|
2758
|
+
}
|
|
2759
|
+
if (type.startsWith("string(")) {
|
|
2760
|
+
const literals = stripAfter(
|
|
2761
|
+
stripBefore(type, "string("),
|
|
2762
|
+
")"
|
|
2763
|
+
).split(/,\s*/);
|
|
2764
|
+
if (literals.includes(val)) {
|
|
2765
|
+
response = true;
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
if (isNumber(val)) {
|
|
2770
|
+
if (type === "number") {
|
|
2771
|
+
response = true;
|
|
2772
|
+
}
|
|
2773
|
+
if (type.startsWith("number(")) {
|
|
2774
|
+
const literals = stripAfter(
|
|
2775
|
+
stripBefore(type, "number("),
|
|
2776
|
+
")"
|
|
2777
|
+
).split(/,\s*/).map(Number);
|
|
2778
|
+
if (literals.includes(val)) {
|
|
2779
|
+
response = true;
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
if (isNull(val) && (type === "null" || type === "Opt<null>")) {
|
|
2784
|
+
response = true;
|
|
2785
|
+
}
|
|
2786
|
+
if (isUndefined(val) && (type === "undefined" || type.startsWith("Opt<"))) {
|
|
2787
|
+
response = true;
|
|
2788
|
+
}
|
|
2789
|
+
if (isBoolean(val)) {
|
|
2790
|
+
if (type === "boolean") {
|
|
2791
|
+
response = true;
|
|
2792
|
+
}
|
|
2793
|
+
if (type === "true" && val === true || type === "false" && val === false) {
|
|
2794
|
+
response = true;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
if (isNarrowableObject(val)) {
|
|
2798
|
+
if (type === "Dict" || type === "Dict<string, unknown>") {
|
|
2799
|
+
response = true;
|
|
2800
|
+
}
|
|
2801
|
+
if (startsWith("Dict<")(type)) {
|
|
2802
|
+
const match = infer("Dict<{{infer key}}, {{infer value}}>")(type);
|
|
2803
|
+
if (match) {
|
|
2804
|
+
const { value } = match;
|
|
2805
|
+
const isOpt = value.includes(`Opt<`);
|
|
2806
|
+
const values = objectValues(val);
|
|
2807
|
+
if (values.every((i) => isOpt ? isString(i) || isUndefined(i) : isString(i)) && type === "Dict<string, string>" || values.every((i) => isOpt ? isUndefined(i) || isNumber(i) : isNumber(i)) && type === "Dict<string, number>" || values.every((i) => isOpt ? isUndefined(i) || isBoolean(i) : isBoolean(i)) && type === "Dict<string, boolean>") {
|
|
2808
|
+
response = true;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
if (isArray(val)) {
|
|
2814
|
+
if (type === "Array" || type === "Array<unknown>") {
|
|
2815
|
+
return true;
|
|
2816
|
+
}
|
|
2817
|
+
if (type === "Array<Dict>" && val.every(isObject) || type === "Array<boolean>" && val.every(isBoolean) || type === "Array<string>" && val.every(isString) || type === "Array<number>" && val.every(isNumber) || type === "Array<Map>" && val.every(isMap) || type === "Array<Set>" && val.every(isSetContainer)) {
|
|
2818
|
+
response = true;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
if (isMap(val)) {
|
|
2822
|
+
if (type === "Map" || type === "Map<Dict, Array>" && Array.from(val.keys()).every(isObject) && Array.from(val.values()).every(isArray) || type === "Map<Dict, Dict>" && Array.from(val.keys()).every(isObject) && Array.from(val.values()).every(isObject) || type === "Map<Dict, boolean>" && Array.from(val.keys()).every(isObject) && Array.from(val.values()).every(isBoolean) || type === "Map<Dict, number>" && Array.from(val.keys()).every(isObject) && Array.from(val.values()).every(isNumber) || type === "Map<Dict, string>" && Array.from(val.keys()).every(isObject) && Array.from(val.values()).every(isString) || type === "Map<Dict, unknown>" && Array.from(val.keys()).every(isObject) || type === "Map<string, string>" && Array.from(val.keys()).every(isString) && Array.from(val.values()).every(isString) || type === "Map<string, number>" && Array.from(val.keys()).every(isString) && Array.from(val.values()).every(isNumber) || type === "Map<string, boolean>" && Array.from(val.keys()).every(isString) && Array.from(val.values()).every(isBoolean) || type === "Map<string, unknown>" && Array.from(val.keys()).every(isString) || type === "Map<number, string>" && Array.from(val.keys()).every(isNumber) && Array.from(val.values()).every(isString) || type === "Map<number, number>" && Array.from(val.keys()).every(isNumber) && Array.from(val.values()).every(isNumber) || type === "Map<number, boolean>" && Array.from(val.keys()).every(isNumber) && Array.from(val.values()).every(isBoolean) || type === "Map<number, unknown>" && Array.from(val.keys()).every(isNumber)) {
|
|
2823
|
+
response = true;
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
if (isSetContainer(val)) {
|
|
2827
|
+
if (type === "Set" || type === "Set<unknown>" || type === "Set<boolean>" && Array.from(val).every(isBoolean) || type === "Set<string>" && Array.from(val).every(isString) || type === "Set<number>" && Array.from(val).every(isNumber) || type === "Set<Opt<boolean>>" && Array.from(val).every((i) => isBoolean(i) || isUndefined(i)) || type === "Set<Opt<string>>" && Array.from(val).every((i) => isString(i) || isUndefined(i)) || type === "Set<Opt<number>>" && Array.from(val).every((i) => isNumber(i) || isUndefined(i))) {
|
|
2828
|
+
response = true;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
return response;
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2734
2835
|
// src/dictionary/withoutValue.ts
|
|
2735
|
-
function withoutValue(
|
|
2836
|
+
function withoutValue(wo) {
|
|
2736
2837
|
return (obj) => {
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2838
|
+
const output = {};
|
|
2839
|
+
for (const key of keysOf(obj)) {
|
|
2840
|
+
const val = obj[key];
|
|
2841
|
+
if (!doesExtend(wo)(val)) {
|
|
2842
|
+
output[key] = val;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
return output;
|
|
2846
|
+
};
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
// src/dictionary/withValue.ts
|
|
2850
|
+
function withValue(wo) {
|
|
2851
|
+
return (obj) => {
|
|
2852
|
+
const output = {};
|
|
2853
|
+
for (const key of keysOf(obj)) {
|
|
2854
|
+
const val = obj[key];
|
|
2855
|
+
if (doesExtend(wo)(val)) {
|
|
2856
|
+
output[key] = val;
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
return output;
|
|
2741
2860
|
};
|
|
2742
2861
|
}
|
|
2743
2862
|
|
|
@@ -3012,6 +3131,9 @@ function isFunction(value) {
|
|
|
3012
3131
|
function isObject(value) {
|
|
3013
3132
|
return typeof value === "object" && value !== null && Array.isArray(value) === false;
|
|
3014
3133
|
}
|
|
3134
|
+
function isNarrowableObject(value) {
|
|
3135
|
+
return isObject(value) && Object.keys(value).every((key) => ["string", "number", "boolean", "symbol", "object", "undefined", "void", "null"].includes(typeof value[key]));
|
|
3136
|
+
}
|
|
3015
3137
|
|
|
3016
3138
|
// src/type-guards/api-tg.ts
|
|
3017
3139
|
function isEscapeFunction(val) {
|
|
@@ -3709,6 +3831,11 @@ function isInlineSvg(v) {
|
|
|
3709
3831
|
return isString(v) && v.trim().startsWith(`<svg`) && v.trim().endsWith(`</svg>`);
|
|
3710
3832
|
}
|
|
3711
3833
|
|
|
3834
|
+
// src/type-guards/isMap.ts
|
|
3835
|
+
function isMap(val) {
|
|
3836
|
+
return val instanceof Map;
|
|
3837
|
+
}
|
|
3838
|
+
|
|
3712
3839
|
// src/type-guards/isNever.ts
|
|
3713
3840
|
function isNever(val) {
|
|
3714
3841
|
return isConstant(val) && val.kind === "never";
|
|
@@ -3771,6 +3898,16 @@ function isLikeRegExp(val) {
|
|
|
3771
3898
|
return false;
|
|
3772
3899
|
}
|
|
3773
3900
|
|
|
3901
|
+
// src/type-guards/isSet.ts
|
|
3902
|
+
function isSet(val) {
|
|
3903
|
+
return isObject(val) ? val.kind !== "Unset" : true;
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
// src/type-guards/isSetContainer.ts
|
|
3907
|
+
function isSetContainer(val) {
|
|
3908
|
+
return val instanceof Set;
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3774
3911
|
// src/type-guards/isStringArray.ts
|
|
3775
3912
|
function isStringArray(val) {
|
|
3776
3913
|
return Array.isArray(val) && val.every((i) => isString(i));
|
|
@@ -3810,9 +3947,6 @@ function isTypeTuple(value) {
|
|
|
3810
3947
|
function isUnset(val) {
|
|
3811
3948
|
return isObject(val) && val.kind === "Unset";
|
|
3812
3949
|
}
|
|
3813
|
-
function isSet(val) {
|
|
3814
|
-
return isObject(val) ? val.kind !== "Unset" : true;
|
|
3815
|
-
}
|
|
3816
3950
|
|
|
3817
3951
|
// src/type-guards/isUrl.ts
|
|
3818
3952
|
function isUri(val, ...protocols) {
|
|
@@ -4490,26 +4624,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
|
4490
4624
|
|
|
4491
4625
|
// src/literals/infer.ts
|
|
4492
4626
|
function parseTemplate(template) {
|
|
4493
|
-
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
4627
|
+
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
|
|
4494
4628
|
let lastIndex = 0;
|
|
4495
4629
|
let match;
|
|
4496
4630
|
const segments = [];
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
if (staticPart) {
|
|
4503
|
-
segments.push({ dynamic: false, text: staticPart });
|
|
4504
|
-
}
|
|
4505
|
-
segments.push({
|
|
4506
|
-
dynamic: true,
|
|
4507
|
-
varName,
|
|
4508
|
-
type: asType2 ? asType2 : "string"
|
|
4509
|
-
});
|
|
4510
|
-
lastIndex = match.index + fullMatch.length;
|
|
4631
|
+
while (match = pattern.exec(template)) {
|
|
4632
|
+
const [fullMatch, varName, asType2] = match;
|
|
4633
|
+
const staticPart = template.slice(lastIndex, match.index);
|
|
4634
|
+
if (staticPart) {
|
|
4635
|
+
segments.push({ dynamic: false, text: staticPart });
|
|
4511
4636
|
}
|
|
4512
|
-
|
|
4637
|
+
segments.push({
|
|
4638
|
+
dynamic: true,
|
|
4639
|
+
varName,
|
|
4640
|
+
type: asType2 ? asType2 : "string"
|
|
4641
|
+
});
|
|
4642
|
+
lastIndex = match.index + fullMatch.length;
|
|
4643
|
+
}
|
|
4513
4644
|
const remainder = template.slice(lastIndex);
|
|
4514
4645
|
if (remainder) {
|
|
4515
4646
|
segments.push({ dynamic: false, text: remainder });
|
|
@@ -4527,19 +4658,19 @@ function buildRegexPattern(segments) {
|
|
|
4527
4658
|
} else {
|
|
4528
4659
|
switch (seg.type) {
|
|
4529
4660
|
case "string":
|
|
4530
|
-
regexStr +=
|
|
4661
|
+
regexStr += "(.*?)";
|
|
4531
4662
|
break;
|
|
4532
4663
|
case "number":
|
|
4533
|
-
regexStr +=
|
|
4664
|
+
regexStr += "(\\d+)";
|
|
4534
4665
|
break;
|
|
4535
4666
|
case "boolean":
|
|
4536
|
-
regexStr +=
|
|
4667
|
+
regexStr += "(true|false)";
|
|
4537
4668
|
break;
|
|
4538
4669
|
}
|
|
4539
4670
|
}
|
|
4540
4671
|
}
|
|
4541
4672
|
regexStr += "$";
|
|
4542
|
-
return new RegExp(regexStr
|
|
4673
|
+
return new RegExp(regexStr);
|
|
4543
4674
|
}
|
|
4544
4675
|
function convertValue(type, value) {
|
|
4545
4676
|
switch (type) {
|
|
@@ -4551,19 +4682,20 @@ function convertValue(type, value) {
|
|
|
4551
4682
|
return value === "true";
|
|
4552
4683
|
}
|
|
4553
4684
|
}
|
|
4554
|
-
function matchTemplate(
|
|
4555
|
-
const segments = parseTemplate(
|
|
4685
|
+
function matchTemplate(template, test) {
|
|
4686
|
+
const segments = parseTemplate(template);
|
|
4556
4687
|
const regex = buildRegexPattern(segments);
|
|
4557
|
-
const match =
|
|
4688
|
+
const match = regex.exec(test);
|
|
4558
4689
|
if (!match)
|
|
4559
4690
|
return false;
|
|
4691
|
+
let captureIndex = 1;
|
|
4560
4692
|
const result2 = {};
|
|
4561
4693
|
for (const seg of segments) {
|
|
4562
4694
|
if (seg.dynamic) {
|
|
4563
|
-
const rawVal = match
|
|
4695
|
+
const rawVal = match[captureIndex++];
|
|
4564
4696
|
if (rawVal === void 0)
|
|
4565
4697
|
return false;
|
|
4566
|
-
result2[seg.varName
|
|
4698
|
+
result2[seg.varName] = convertValue(seg.type, rawVal);
|
|
4567
4699
|
}
|
|
4568
4700
|
}
|
|
4569
4701
|
return result2;
|
|
@@ -5629,12 +5761,14 @@ function asVueRef(value) {
|
|
|
5629
5761
|
isLuminosityUom,
|
|
5630
5762
|
isLuxonDateTime,
|
|
5631
5763
|
isMacysUrl,
|
|
5764
|
+
isMap,
|
|
5632
5765
|
isMapToken,
|
|
5633
5766
|
isMassMetric,
|
|
5634
5767
|
isMassUom,
|
|
5635
5768
|
isMetric,
|
|
5636
5769
|
isMexicanNewsUrl,
|
|
5637
5770
|
isMoment,
|
|
5771
|
+
isNarrowableObject,
|
|
5638
5772
|
isNever,
|
|
5639
5773
|
isNewsUrl,
|
|
5640
5774
|
isNikeUrl,
|
|
@@ -5669,6 +5803,7 @@ function asVueRef(value) {
|
|
|
5669
5803
|
isSet,
|
|
5670
5804
|
isSetBasedKind,
|
|
5671
5805
|
isSetBasedToken,
|
|
5806
|
+
isSetContainer,
|
|
5672
5807
|
isSetToken,
|
|
5673
5808
|
isShape,
|
|
5674
5809
|
isShapeCallback,
|
|
@@ -5778,6 +5913,7 @@ function asVueRef(value) {
|
|
|
5778
5913
|
narrowObjectToType,
|
|
5779
5914
|
never,
|
|
5780
5915
|
objectToApi,
|
|
5916
|
+
objectValues,
|
|
5781
5917
|
omit,
|
|
5782
5918
|
optional,
|
|
5783
5919
|
optionalOrNull,
|
|
@@ -5854,6 +5990,7 @@ function asVueRef(value) {
|
|
|
5854
5990
|
widen,
|
|
5855
5991
|
withDefaults,
|
|
5856
5992
|
withKeys,
|
|
5993
|
+
withValue,
|
|
5857
5994
|
withoutKeys,
|
|
5858
5995
|
withoutValue,
|
|
5859
5996
|
wrapFn,
|