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
|
@@ -4593,6 +4593,16 @@ function narrowObjectToType() {
|
|
|
4593
4593
|
}
|
|
4594
4594
|
);
|
|
4595
4595
|
}
|
|
4596
|
+
function objectValues(obj) {
|
|
4597
|
+
const tuple3 = Object.keys(obj).reduce(
|
|
4598
|
+
(acc, key) => [
|
|
4599
|
+
...acc,
|
|
4600
|
+
obj[key]
|
|
4601
|
+
],
|
|
4602
|
+
[]
|
|
4603
|
+
);
|
|
4604
|
+
return tuple3;
|
|
4605
|
+
}
|
|
4596
4606
|
function omit(obj, ...removeKeys) {
|
|
4597
4607
|
const keys = Object.keys(obj);
|
|
4598
4608
|
return keys.reduce(
|
|
@@ -4643,12 +4653,110 @@ function withKeys(dict, ...keys) {
|
|
|
4643
4653
|
function withoutKeys(dict, ...exclude) {
|
|
4644
4654
|
return omit(dict, ...exclude);
|
|
4645
4655
|
}
|
|
4646
|
-
function
|
|
4656
|
+
function doesExtend(type) {
|
|
4657
|
+
return (val) => {
|
|
4658
|
+
let response = false;
|
|
4659
|
+
if (isString(val)) {
|
|
4660
|
+
if (type === "string") {
|
|
4661
|
+
response = true;
|
|
4662
|
+
}
|
|
4663
|
+
if (type.startsWith("string(")) {
|
|
4664
|
+
const literals = stripAfter(
|
|
4665
|
+
stripBefore(type, "string("),
|
|
4666
|
+
")"
|
|
4667
|
+
).split(/,\s*/);
|
|
4668
|
+
if (literals.includes(val)) {
|
|
4669
|
+
response = true;
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
if (isNumber(val)) {
|
|
4674
|
+
if (type === "number") {
|
|
4675
|
+
response = true;
|
|
4676
|
+
}
|
|
4677
|
+
if (type.startsWith("number(")) {
|
|
4678
|
+
const literals = stripAfter(
|
|
4679
|
+
stripBefore(type, "number("),
|
|
4680
|
+
")"
|
|
4681
|
+
).split(/,\s*/).map(Number);
|
|
4682
|
+
if (literals.includes(val)) {
|
|
4683
|
+
response = true;
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
4687
|
+
if (isNull(val) && (type === "null" || type === "Opt<null>")) {
|
|
4688
|
+
response = true;
|
|
4689
|
+
}
|
|
4690
|
+
if (isUndefined(val) && (type === "undefined" || type.startsWith("Opt<"))) {
|
|
4691
|
+
response = true;
|
|
4692
|
+
}
|
|
4693
|
+
if (isBoolean(val)) {
|
|
4694
|
+
if (type === "boolean") {
|
|
4695
|
+
response = true;
|
|
4696
|
+
}
|
|
4697
|
+
if (type === "true" && val === true || type === "false" && val === false) {
|
|
4698
|
+
response = true;
|
|
4699
|
+
}
|
|
4700
|
+
}
|
|
4701
|
+
if (isNarrowableObject(val)) {
|
|
4702
|
+
if (type === "Dict" || type === "Dict<string, unknown>") {
|
|
4703
|
+
response = true;
|
|
4704
|
+
}
|
|
4705
|
+
if (startsWith("Dict<")(type)) {
|
|
4706
|
+
const match = infer("Dict<{{infer key}}, {{infer value}}>")(type);
|
|
4707
|
+
if (match) {
|
|
4708
|
+
const { value } = match;
|
|
4709
|
+
const isOpt = value.includes(`Opt<`);
|
|
4710
|
+
const values = objectValues(val);
|
|
4711
|
+
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>") {
|
|
4712
|
+
response = true;
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
if (isArray(val)) {
|
|
4718
|
+
if (type === "Array" || type === "Array<unknown>") {
|
|
4719
|
+
return true;
|
|
4720
|
+
}
|
|
4721
|
+
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)) {
|
|
4722
|
+
response = true;
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
if (isMap(val)) {
|
|
4726
|
+
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)) {
|
|
4727
|
+
response = true;
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
if (isSetContainer(val)) {
|
|
4731
|
+
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))) {
|
|
4732
|
+
response = true;
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4735
|
+
return response;
|
|
4736
|
+
};
|
|
4737
|
+
}
|
|
4738
|
+
function withoutValue(wo) {
|
|
4647
4739
|
return (obj) => {
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4740
|
+
const output = {};
|
|
4741
|
+
for (const key of keysOf(obj)) {
|
|
4742
|
+
const val = obj[key];
|
|
4743
|
+
if (!doesExtend(wo)(val)) {
|
|
4744
|
+
output[key] = val;
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
return output;
|
|
4748
|
+
};
|
|
4749
|
+
}
|
|
4750
|
+
function withValue(wo) {
|
|
4751
|
+
return (obj) => {
|
|
4752
|
+
const output = {};
|
|
4753
|
+
for (const key of keysOf(obj)) {
|
|
4754
|
+
const val = obj[key];
|
|
4755
|
+
if (doesExtend(wo)(val)) {
|
|
4756
|
+
output[key] = val;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
return output;
|
|
4652
4760
|
};
|
|
4653
4761
|
}
|
|
4654
4762
|
function createErrorCondition(kind, msg = "", utility = "") {
|
|
@@ -4867,6 +4975,9 @@ function isFunction(value) {
|
|
|
4867
4975
|
function isObject(value) {
|
|
4868
4976
|
return typeof value === "object" && value !== null && Array.isArray(value) === false;
|
|
4869
4977
|
}
|
|
4978
|
+
function isNarrowableObject(value) {
|
|
4979
|
+
return isObject(value) && Object.keys(value).every((key) => ["string", "number", "boolean", "symbol", "object", "undefined", "void", "null"].includes(typeof value[key]));
|
|
4980
|
+
}
|
|
4870
4981
|
function isEscapeFunction(val) {
|
|
4871
4982
|
return isFunction(val) && "escape" in val && val.escape === true;
|
|
4872
4983
|
}
|
|
@@ -5423,6 +5534,9 @@ function isIndexable(value) {
|
|
|
5423
5534
|
function isInlineSvg(v) {
|
|
5424
5535
|
return isString(v) && v.trim().startsWith(`<svg`) && v.trim().endsWith(`</svg>`);
|
|
5425
5536
|
}
|
|
5537
|
+
function isMap(val) {
|
|
5538
|
+
return val instanceof Map;
|
|
5539
|
+
}
|
|
5426
5540
|
function isNever(val) {
|
|
5427
5541
|
return isConstant(val) && val.kind === "never";
|
|
5428
5542
|
}
|
|
@@ -5471,6 +5585,12 @@ function isLikeRegExp(val) {
|
|
|
5471
5585
|
}
|
|
5472
5586
|
return false;
|
|
5473
5587
|
}
|
|
5588
|
+
function isSet(val) {
|
|
5589
|
+
return isObject(val) ? val.kind !== "Unset" : true;
|
|
5590
|
+
}
|
|
5591
|
+
function isSetContainer(val) {
|
|
5592
|
+
return val instanceof Set;
|
|
5593
|
+
}
|
|
5474
5594
|
function isStringArray(val) {
|
|
5475
5595
|
return Array.isArray(val) && val.every((i) => isString(i));
|
|
5476
5596
|
}
|
|
@@ -5495,9 +5615,6 @@ function isTypeTuple(value) {
|
|
|
5495
5615
|
function isUnset(val) {
|
|
5496
5616
|
return isObject(val) && val.kind === "Unset";
|
|
5497
5617
|
}
|
|
5498
|
-
function isSet(val) {
|
|
5499
|
-
return isObject(val) ? val.kind !== "Unset" : true;
|
|
5500
|
-
}
|
|
5501
5618
|
function isUri(val, ...protocols) {
|
|
5502
5619
|
const p = protocols.length === 0 ? valuesOf(NETWORK_PROTOCOL_LOOKUP2).flat().filter((i) => i) : protocols;
|
|
5503
5620
|
return isString(val) && p.some((i) => val.startsWith(`${i}://`));
|
|
@@ -6077,26 +6194,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
|
6077
6194
|
return LOWER_ALPHA_CHARS2.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
6078
6195
|
}
|
|
6079
6196
|
function parseTemplate(template) {
|
|
6080
|
-
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
6197
|
+
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
|
|
6081
6198
|
let lastIndex = 0;
|
|
6082
6199
|
let match;
|
|
6083
6200
|
const segments = [];
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
if (staticPart) {
|
|
6090
|
-
segments.push({ dynamic: false, text: staticPart });
|
|
6091
|
-
}
|
|
6092
|
-
segments.push({
|
|
6093
|
-
dynamic: true,
|
|
6094
|
-
varName,
|
|
6095
|
-
type: asType2 ? asType2 : "string"
|
|
6096
|
-
});
|
|
6097
|
-
lastIndex = match.index + fullMatch.length;
|
|
6201
|
+
while (match = pattern.exec(template)) {
|
|
6202
|
+
const [fullMatch, varName, asType2] = match;
|
|
6203
|
+
const staticPart = template.slice(lastIndex, match.index);
|
|
6204
|
+
if (staticPart) {
|
|
6205
|
+
segments.push({ dynamic: false, text: staticPart });
|
|
6098
6206
|
}
|
|
6099
|
-
|
|
6207
|
+
segments.push({
|
|
6208
|
+
dynamic: true,
|
|
6209
|
+
varName,
|
|
6210
|
+
type: asType2 ? asType2 : "string"
|
|
6211
|
+
});
|
|
6212
|
+
lastIndex = match.index + fullMatch.length;
|
|
6213
|
+
}
|
|
6100
6214
|
const remainder = template.slice(lastIndex);
|
|
6101
6215
|
if (remainder) {
|
|
6102
6216
|
segments.push({ dynamic: false, text: remainder });
|
|
@@ -6114,19 +6228,19 @@ function buildRegexPattern(segments) {
|
|
|
6114
6228
|
} else {
|
|
6115
6229
|
switch (seg.type) {
|
|
6116
6230
|
case "string":
|
|
6117
|
-
regexStr +=
|
|
6231
|
+
regexStr += "(.*?)";
|
|
6118
6232
|
break;
|
|
6119
6233
|
case "number":
|
|
6120
|
-
regexStr +=
|
|
6234
|
+
regexStr += "(\\d+)";
|
|
6121
6235
|
break;
|
|
6122
6236
|
case "boolean":
|
|
6123
|
-
regexStr +=
|
|
6237
|
+
regexStr += "(true|false)";
|
|
6124
6238
|
break;
|
|
6125
6239
|
}
|
|
6126
6240
|
}
|
|
6127
6241
|
}
|
|
6128
6242
|
regexStr += "$";
|
|
6129
|
-
return new RegExp(regexStr
|
|
6243
|
+
return new RegExp(regexStr);
|
|
6130
6244
|
}
|
|
6131
6245
|
function convertValue(type, value) {
|
|
6132
6246
|
switch (type) {
|
|
@@ -6138,19 +6252,20 @@ function convertValue(type, value) {
|
|
|
6138
6252
|
return value === "true";
|
|
6139
6253
|
}
|
|
6140
6254
|
}
|
|
6141
|
-
function matchTemplate(
|
|
6142
|
-
const segments = parseTemplate(
|
|
6255
|
+
function matchTemplate(template, test) {
|
|
6256
|
+
const segments = parseTemplate(template);
|
|
6143
6257
|
const regex = buildRegexPattern(segments);
|
|
6144
|
-
const match =
|
|
6258
|
+
const match = regex.exec(test);
|
|
6145
6259
|
if (!match)
|
|
6146
6260
|
return false;
|
|
6261
|
+
let captureIndex = 1;
|
|
6147
6262
|
const result2 = {};
|
|
6148
6263
|
for (const seg of segments) {
|
|
6149
6264
|
if (seg.dynamic) {
|
|
6150
|
-
const rawVal = match
|
|
6265
|
+
const rawVal = match[captureIndex++];
|
|
6151
6266
|
if (rawVal === void 0)
|
|
6152
6267
|
return false;
|
|
6153
|
-
result2[seg.varName
|
|
6268
|
+
result2[seg.varName] = convertValue(seg.type, rawVal);
|
|
6154
6269
|
}
|
|
6155
6270
|
}
|
|
6156
6271
|
return result2;
|
|
@@ -7479,12 +7594,14 @@ export {
|
|
|
7479
7594
|
isLuminosityUom,
|
|
7480
7595
|
isLuxonDateTime,
|
|
7481
7596
|
isMacysUrl,
|
|
7597
|
+
isMap,
|
|
7482
7598
|
isMapToken,
|
|
7483
7599
|
isMassMetric,
|
|
7484
7600
|
isMassUom,
|
|
7485
7601
|
isMetric,
|
|
7486
7602
|
isMexicanNewsUrl,
|
|
7487
7603
|
isMoment,
|
|
7604
|
+
isNarrowableObject,
|
|
7488
7605
|
isNever,
|
|
7489
7606
|
isNewsUrl,
|
|
7490
7607
|
isNikeUrl,
|
|
@@ -7519,6 +7636,7 @@ export {
|
|
|
7519
7636
|
isSet,
|
|
7520
7637
|
isSetBasedKind,
|
|
7521
7638
|
isSetBasedToken,
|
|
7639
|
+
isSetContainer,
|
|
7522
7640
|
isSetToken,
|
|
7523
7641
|
isShape,
|
|
7524
7642
|
isShapeCallback,
|
|
@@ -7628,6 +7746,7 @@ export {
|
|
|
7628
7746
|
narrowObjectToType,
|
|
7629
7747
|
never,
|
|
7630
7748
|
objectToApi,
|
|
7749
|
+
objectValues,
|
|
7631
7750
|
omit,
|
|
7632
7751
|
optional,
|
|
7633
7752
|
optionalOrNull,
|
|
@@ -7704,6 +7823,7 @@ export {
|
|
|
7704
7823
|
widen,
|
|
7705
7824
|
withDefaults,
|
|
7706
7825
|
withKeys,
|
|
7826
|
+
withValue,
|
|
7707
7827
|
withoutKeys,
|
|
7708
7828
|
withoutValue,
|
|
7709
7829
|
wrapFn,
|