inferred-types 0.54.8 → 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 +135 -8
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +95 -20
- package/modules/inferred-types/dist/index.js +130 -8
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +147 -8
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +86 -20
- package/modules/runtime/dist/index.js +142 -8
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +10 -1
- 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) {
|
|
@@ -5627,12 +5761,14 @@ function asVueRef(value) {
|
|
|
5627
5761
|
isLuminosityUom,
|
|
5628
5762
|
isLuxonDateTime,
|
|
5629
5763
|
isMacysUrl,
|
|
5764
|
+
isMap,
|
|
5630
5765
|
isMapToken,
|
|
5631
5766
|
isMassMetric,
|
|
5632
5767
|
isMassUom,
|
|
5633
5768
|
isMetric,
|
|
5634
5769
|
isMexicanNewsUrl,
|
|
5635
5770
|
isMoment,
|
|
5771
|
+
isNarrowableObject,
|
|
5636
5772
|
isNever,
|
|
5637
5773
|
isNewsUrl,
|
|
5638
5774
|
isNikeUrl,
|
|
@@ -5667,6 +5803,7 @@ function asVueRef(value) {
|
|
|
5667
5803
|
isSet,
|
|
5668
5804
|
isSetBasedKind,
|
|
5669
5805
|
isSetBasedToken,
|
|
5806
|
+
isSetContainer,
|
|
5670
5807
|
isSetToken,
|
|
5671
5808
|
isShape,
|
|
5672
5809
|
isShapeCallback,
|
|
@@ -5776,6 +5913,7 @@ function asVueRef(value) {
|
|
|
5776
5913
|
narrowObjectToType,
|
|
5777
5914
|
never,
|
|
5778
5915
|
objectToApi,
|
|
5916
|
+
objectValues,
|
|
5779
5917
|
omit,
|
|
5780
5918
|
optional,
|
|
5781
5919
|
optionalOrNull,
|
|
@@ -5852,6 +5990,7 @@ function asVueRef(value) {
|
|
|
5852
5990
|
widen,
|
|
5853
5991
|
withDefaults,
|
|
5854
5992
|
withKeys,
|
|
5993
|
+
withValue,
|
|
5855
5994
|
withoutKeys,
|
|
5856
5995
|
withoutValue,
|
|
5857
5996
|
wrapFn,
|