inferred-types 0.54.9 → 0.55.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/modules/constants/dist/index.cjs +118 -1
- package/modules/constants/dist/index.cjs.map +1 -1
- package/modules/constants/dist/index.d.ts +29 -1
- package/modules/constants/dist/index.js +113 -1
- package/modules/constants/dist/index.js.map +1 -1
- package/modules/inferred-types/dist/index.cjs +288 -16
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +21421 -20785
- package/modules/inferred-types/dist/index.js +273 -16
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +180 -15
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +5406 -5142
- package/modules/runtime/dist/index.js +170 -15
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +9680 -9336
- package/package.json +3 -4
|
@@ -685,13 +685,51 @@ var AREA_METRICS_LOOKUP = [
|
|
|
685
685
|
{ abbrev: "acre", name: "acre" },
|
|
686
686
|
{ abbrev: "ha", name: "hectare" }
|
|
687
687
|
];
|
|
688
|
+
var NETWORK_PROTOCOL_INSECURE = [
|
|
689
|
+
"http",
|
|
690
|
+
"ftp",
|
|
691
|
+
"ws",
|
|
692
|
+
"dns",
|
|
693
|
+
"telnet",
|
|
694
|
+
"imap",
|
|
695
|
+
"pop3",
|
|
696
|
+
"smtp"
|
|
697
|
+
];
|
|
698
|
+
var NETWORK_PROTOCOL_SECURE = [
|
|
699
|
+
"https",
|
|
700
|
+
"sftp",
|
|
701
|
+
"wss",
|
|
702
|
+
"sdns",
|
|
703
|
+
"ssh"
|
|
704
|
+
];
|
|
705
|
+
var NETWORK_PROTOCOL = [
|
|
706
|
+
...NETWORK_PROTOCOL_INSECURE,
|
|
707
|
+
...NETWORK_PROTOCOL_SECURE
|
|
708
|
+
];
|
|
688
709
|
var NETWORK_PROTOCOL_LOOKUP = {
|
|
689
710
|
http: ["http", "https"],
|
|
690
711
|
ftp: ["ftp", "sftp"],
|
|
691
712
|
file: ["", "file"],
|
|
692
713
|
ws: ["ws", "wss"],
|
|
693
714
|
ssh: ["", "ssh"],
|
|
694
|
-
scp: ["", "scp"]
|
|
715
|
+
scp: ["", "scp"],
|
|
716
|
+
telnet: ["telnet", ""],
|
|
717
|
+
dns: ["dns", "sdns"]
|
|
718
|
+
};
|
|
719
|
+
var PROTOCOL_DEFAULT_PORTS = {
|
|
720
|
+
http: 80,
|
|
721
|
+
https: 443,
|
|
722
|
+
ws: 80,
|
|
723
|
+
wss: 443,
|
|
724
|
+
ssh: 22,
|
|
725
|
+
telnet: 23,
|
|
726
|
+
dns: 53,
|
|
727
|
+
sdns: 853,
|
|
728
|
+
smtp: 25,
|
|
729
|
+
imap: 142,
|
|
730
|
+
pop3: 110,
|
|
731
|
+
ftp: 21,
|
|
732
|
+
sftp: 22
|
|
695
733
|
};
|
|
696
734
|
var Never = createConstant("never");
|
|
697
735
|
var US_NEWS = [
|
|
@@ -2468,7 +2506,7 @@ var filter = "NOT READY";
|
|
|
2468
2506
|
function find(list2, deref = null) {
|
|
2469
2507
|
return (comparator) => {
|
|
2470
2508
|
return list2.find((i) => {
|
|
2471
|
-
const val = deref ?
|
|
2509
|
+
const val = deref ? isObject(i) || isArray(i) ? deref in i ? i[deref] : void 0 : i : i;
|
|
2472
2510
|
return val === comparator;
|
|
2473
2511
|
});
|
|
2474
2512
|
};
|
|
@@ -3301,6 +3339,11 @@ function isCssAspectRatio(val) {
|
|
|
3301
3339
|
return isString(val) && val.split(/\s+/).every((i) => tokens.includes(i) || isRatio(i));
|
|
3302
3340
|
}
|
|
3303
3341
|
|
|
3342
|
+
// src/type-guards/isCsv.ts
|
|
3343
|
+
function isCsv(val) {
|
|
3344
|
+
return isString(val) && val.includes(",") && !val.startsWith(",");
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3304
3347
|
// src/type-guards/isDefined.ts
|
|
3305
3348
|
function isDefined(value) {
|
|
3306
3349
|
return typeof value !== "undefined";
|
|
@@ -3383,7 +3426,7 @@ function isPhoneNumber(val) {
|
|
|
3383
3426
|
const svelte = String(val).trim();
|
|
3384
3427
|
const chars = svelte.split("");
|
|
3385
3428
|
const numeric = retainChars(svelte, ...NUMERIC_CHAR);
|
|
3386
|
-
const
|
|
3429
|
+
const valid2 = ["+", "(", ...NUMERIC_CHAR];
|
|
3387
3430
|
const nothing = stripChars(svelte, ...[
|
|
3388
3431
|
...NUMERIC_CHAR,
|
|
3389
3432
|
...WHITESPACE_CHARS,
|
|
@@ -3393,7 +3436,7 @@ function isPhoneNumber(val) {
|
|
|
3393
3436
|
".",
|
|
3394
3437
|
"-"
|
|
3395
3438
|
]);
|
|
3396
|
-
return chars.every((i) =>
|
|
3439
|
+
return chars.every((i) => valid2.includes(i)) && svelte.startsWith(`+`) ? numeric.length >= 8 : svelte.startsWith(`00`) ? numeric.length >= 10 : numeric.length >= 7 && nothing === "";
|
|
3397
3440
|
}
|
|
3398
3441
|
|
|
3399
3442
|
// src/type-guards/isReadonlyArray.ts
|
|
@@ -3485,6 +3528,21 @@ function isUrl(val, ...protocols) {
|
|
|
3485
3528
|
return isString(val) && p.some((i) => val.startsWith(`${i}://`));
|
|
3486
3529
|
}
|
|
3487
3530
|
|
|
3531
|
+
// src/type-guards/isVariable.ts
|
|
3532
|
+
var VALID = [
|
|
3533
|
+
...ALPHA_CHARS,
|
|
3534
|
+
...NUMERIC_CHAR,
|
|
3535
|
+
"_",
|
|
3536
|
+
"."
|
|
3537
|
+
];
|
|
3538
|
+
var alpha = null;
|
|
3539
|
+
function valid(chars) {
|
|
3540
|
+
return chars.every((i) => VALID.includes(i));
|
|
3541
|
+
}
|
|
3542
|
+
function isVariable(val) {
|
|
3543
|
+
return isString(val) && startsWith(alpha)(val) && valid(asChars(val));
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3488
3546
|
// src/type-guards/metrics/isMetric.ts
|
|
3489
3547
|
function separate(s) {
|
|
3490
3548
|
return stripWhile(s.toLowerCase(), ...NUMERIC_CHAR).trim();
|
|
@@ -3631,6 +3689,20 @@ function isNumericArray(val) {
|
|
|
3631
3689
|
return Array.isArray(val) && val.every((i) => isNumber(i));
|
|
3632
3690
|
}
|
|
3633
3691
|
|
|
3692
|
+
// src/type-guards/protocol.ts
|
|
3693
|
+
function hasProtocol(val, ...protocols) {
|
|
3694
|
+
return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL.some((i) => val.startsWith(i)) : protocols.some((i) => val.startsWith(i));
|
|
3695
|
+
}
|
|
3696
|
+
function isProtocol(val, ...protocols) {
|
|
3697
|
+
return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL.includes(val) : protocols.includes(val);
|
|
3698
|
+
}
|
|
3699
|
+
function hasProtocolPrefix(val, ...protocols) {
|
|
3700
|
+
return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL.map((i) => `${i}://`).some((i) => val.startsWith(i)) : protocols.map((i) => `${i}://`).some((i) => val.startsWith(i));
|
|
3701
|
+
}
|
|
3702
|
+
function isProtocolPrefix(val, ...protocols) {
|
|
3703
|
+
return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL.map((i) => `${i}://`).includes(val) : protocols.map((i) => `${i}://`).includes(val);
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3634
3706
|
// src/type-guards/tokens/general.ts
|
|
3635
3707
|
function isTypeToken(val, kind) {
|
|
3636
3708
|
if (isString(val) && val.startsWith("<<") && val.endsWith(">>")) {
|
|
@@ -3925,28 +3997,28 @@ function isNewsUrl(val) {
|
|
|
3925
3997
|
|
|
3926
3998
|
// src/type-guards/urls/repos/bitbucket.ts
|
|
3927
3999
|
function isBitbucketUrl(val) {
|
|
3928
|
-
const
|
|
3929
|
-
return isString(val) &&
|
|
4000
|
+
const valid2 = REPO_SOURCE_LOOKUP.bitbucket;
|
|
4001
|
+
return isString(val) && valid2.some(
|
|
3930
4002
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3931
4003
|
);
|
|
3932
4004
|
}
|
|
3933
4005
|
|
|
3934
4006
|
// src/type-guards/urls/repos/codeCommit.ts
|
|
3935
4007
|
function isCodeCommitUrl(val) {
|
|
3936
|
-
const
|
|
3937
|
-
return isString(val) &&
|
|
4008
|
+
const valid2 = REPO_SOURCE_LOOKUP.codecommit;
|
|
4009
|
+
return isString(val) && valid2.some(
|
|
3938
4010
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3939
4011
|
);
|
|
3940
4012
|
}
|
|
3941
4013
|
|
|
3942
4014
|
// src/type-guards/urls/repos/github.ts
|
|
3943
4015
|
function isGithubUrl(val) {
|
|
3944
|
-
const
|
|
4016
|
+
const valid2 = [
|
|
3945
4017
|
"https://github.com",
|
|
3946
4018
|
"https://www.github.com",
|
|
3947
4019
|
"https://github.io"
|
|
3948
4020
|
];
|
|
3949
|
-
return isString(val) &&
|
|
4021
|
+
return isString(val) && valid2.some(
|
|
3950
4022
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3951
4023
|
);
|
|
3952
4024
|
}
|
|
@@ -4584,16 +4656,77 @@ function getUrlQueryParams(url, specific = void 0) {
|
|
|
4584
4656
|
}
|
|
4585
4657
|
return qp === "" ? qp : `?${qp}`;
|
|
4586
4658
|
}
|
|
4587
|
-
function
|
|
4588
|
-
const
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4659
|
+
function getUrlDefaultPort(url) {
|
|
4660
|
+
const proto = getUrlProtocol(url);
|
|
4661
|
+
return proto in PROTOCOL_DEFAULT_PORTS ? PROTOCOL_DEFAULT_PORTS[proto] : null;
|
|
4662
|
+
}
|
|
4663
|
+
function getUrlPort(url, resolve = false) {
|
|
4664
|
+
const re = /.*:(\d{2,3})/;
|
|
4665
|
+
const match = url.match(re);
|
|
4666
|
+
return re.test(url) && match && isNumberLike(Array.from(match)[1]) ? Number(Array.from(match)[1]) : resolve ? getUrlDefaultPort(url) : hasProtocol(url) ? `default` : null;
|
|
4592
4667
|
}
|
|
4593
4668
|
function getUrlSource(url) {
|
|
4594
4669
|
const candidate = stripAfter(stripAfter(stripAfter(removeUrlProtocol(url), "/"), "?"), ":");
|
|
4595
4670
|
return isIpAddress(candidate) || isDomainName(candidate) ? candidate : Never;
|
|
4596
4671
|
}
|
|
4672
|
+
function getUrlBase(url) {
|
|
4673
|
+
const path = getUrlPath(url);
|
|
4674
|
+
const remaining = stripAfter(url, path);
|
|
4675
|
+
return remaining;
|
|
4676
|
+
}
|
|
4677
|
+
function getUrlDynamics(url) {
|
|
4678
|
+
const path = getUrlPath(url);
|
|
4679
|
+
const qp = getUrlQueryParams(url);
|
|
4680
|
+
const pathParts = path.startsWith("<") ? path.split("<").map((i) => ensureLeading(i, "<")) : path.split("<").map((i) => ensureLeading(i, "<")).slice(1);
|
|
4681
|
+
const segmentTypes = [
|
|
4682
|
+
"string",
|
|
4683
|
+
"number",
|
|
4684
|
+
"boolean",
|
|
4685
|
+
"Opt<string>",
|
|
4686
|
+
"Opt<number>",
|
|
4687
|
+
"Opt<boolean>"
|
|
4688
|
+
];
|
|
4689
|
+
const pathVars = {};
|
|
4690
|
+
const findPathTyped = infer(`<{{infer name}} as {{infer type}}>`);
|
|
4691
|
+
const findPathUnion = infer(`<{{infer name}} as string({{infer union}})>`);
|
|
4692
|
+
const findPathNamed = infer(`<{{infer name}}>`);
|
|
4693
|
+
for (const part of pathParts) {
|
|
4694
|
+
const union4 = findPathUnion(part);
|
|
4695
|
+
const typed = findPathTyped(part);
|
|
4696
|
+
const named = findPathNamed(part);
|
|
4697
|
+
if (union4) {
|
|
4698
|
+
if (isVariable(union4.name) && isCsv(union4.union)) {
|
|
4699
|
+
pathVars[union4.name] = `string(${union4.union})`;
|
|
4700
|
+
}
|
|
4701
|
+
} else if (typed && segmentTypes.includes(typed.type) && isVariable(typed.name)) {
|
|
4702
|
+
pathVars[typed.name] = typed.type;
|
|
4703
|
+
} else if (named && isVariable(named.name)) {
|
|
4704
|
+
pathVars[named.name] = "string";
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
const qpVars = {};
|
|
4708
|
+
const qpParts = stripLeading(qp, "?").split("&");
|
|
4709
|
+
for (const p of qpParts) {
|
|
4710
|
+
const union4 = infer(`{{infer var}}=<string({{infer params}})>`)(p);
|
|
4711
|
+
const dynamic = infer(`{{infer var}}=<{{infer val}}>`)(p);
|
|
4712
|
+
const fixed = infer(`{{infer var}}={{infer val}}`)(p);
|
|
4713
|
+
if (union4 && isVariable(union4.var) && isCsv(union4.params)) {
|
|
4714
|
+
qpVars[union4.var] = `string(${union4.params})`;
|
|
4715
|
+
} else if (dynamic && isVariable(dynamic.var) && segmentTypes.includes(dynamic.val)) {
|
|
4716
|
+
qpVars[dynamic.var] = dynamic.val;
|
|
4717
|
+
} else if (fixed && isVariable(fixed.var)) {
|
|
4718
|
+
qpVars[fixed.var] = fixed.val;
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
return {
|
|
4722
|
+
pathVars,
|
|
4723
|
+
qpVars,
|
|
4724
|
+
allVars: hasOverlappingKeys(pathVars, qpVars) ? null : {
|
|
4725
|
+
...pathVars,
|
|
4726
|
+
...qpVars
|
|
4727
|
+
}
|
|
4728
|
+
};
|
|
4729
|
+
}
|
|
4597
4730
|
function urlMeta(url) {
|
|
4598
4731
|
return {
|
|
4599
4732
|
url,
|
|
@@ -4601,6 +4734,7 @@ function urlMeta(url) {
|
|
|
4601
4734
|
protocol: getUrlProtocol(url),
|
|
4602
4735
|
path: getUrlPath(url),
|
|
4603
4736
|
queryParameters: getUrlQueryParams(url),
|
|
4737
|
+
params: getUrlDynamics,
|
|
4604
4738
|
port: getUrlPort(url),
|
|
4605
4739
|
source: getUrlSource(url),
|
|
4606
4740
|
isIpAddress: isIpAddress(getUrlSource(url)),
|
|
@@ -5046,6 +5180,17 @@ function simpleType(token) {
|
|
|
5046
5180
|
return value;
|
|
5047
5181
|
}
|
|
5048
5182
|
|
|
5183
|
+
// src/sets/hasOverlappingKeys.ts
|
|
5184
|
+
function hasOverlappingKeys(a, b) {
|
|
5185
|
+
const keys = Object.keys(a);
|
|
5186
|
+
for (const k of keys) {
|
|
5187
|
+
if (k in b) {
|
|
5188
|
+
return true;
|
|
5189
|
+
}
|
|
5190
|
+
}
|
|
5191
|
+
return false;
|
|
5192
|
+
}
|
|
5193
|
+
|
|
5049
5194
|
// src/sets/uniqueKeys.ts
|
|
5050
5195
|
function uniqueKeys(left, right) {
|
|
5051
5196
|
const isNumeric = !!(isArray(left) && isArray(right));
|
|
@@ -5134,6 +5279,9 @@ export {
|
|
|
5134
5279
|
getTokenKind,
|
|
5135
5280
|
getTomorrow,
|
|
5136
5281
|
getTypeSubtype,
|
|
5282
|
+
getUrlBase,
|
|
5283
|
+
getUrlDefaultPort,
|
|
5284
|
+
getUrlDynamics,
|
|
5137
5285
|
getUrlPath,
|
|
5138
5286
|
getUrlPort,
|
|
5139
5287
|
getUrlProtocol,
|
|
@@ -5146,6 +5294,9 @@ export {
|
|
|
5146
5294
|
hasDefaultValue,
|
|
5147
5295
|
hasIndexOf,
|
|
5148
5296
|
hasKeys,
|
|
5297
|
+
hasOverlappingKeys,
|
|
5298
|
+
hasProtocol,
|
|
5299
|
+
hasProtocolPrefix,
|
|
5149
5300
|
hasUrlPort,
|
|
5150
5301
|
hasUrlQueryParameter,
|
|
5151
5302
|
hasWhiteSpace,
|
|
@@ -5211,6 +5362,7 @@ export {
|
|
|
5211
5362
|
isCountryCode3,
|
|
5212
5363
|
isCountryName,
|
|
5213
5364
|
isCssAspectRatio,
|
|
5365
|
+
isCsv,
|
|
5214
5366
|
isCurrentMetric,
|
|
5215
5367
|
isCurrentUom,
|
|
5216
5368
|
isCvsUrl,
|
|
@@ -5314,6 +5466,8 @@ export {
|
|
|
5314
5466
|
isPowerUom,
|
|
5315
5467
|
isPressureMetric,
|
|
5316
5468
|
isPressureUom,
|
|
5469
|
+
isProtocol,
|
|
5470
|
+
isProtocolPrefix,
|
|
5317
5471
|
isReadonlyArray,
|
|
5318
5472
|
isRecordToken,
|
|
5319
5473
|
isRef,
|
|
@@ -5392,6 +5546,7 @@ export {
|
|
|
5392
5546
|
isUsNewsUrl,
|
|
5393
5547
|
isUsStateAbbreviation,
|
|
5394
5548
|
isUsStateName,
|
|
5549
|
+
isVariable,
|
|
5395
5550
|
isVoltageMetric,
|
|
5396
5551
|
isVoltageUom,
|
|
5397
5552
|
isVolumeMetric,
|