inferred-types 0.54.8 → 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/README.md +81 -36
- 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 +423 -24
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +19949 -19238
- package/modules/inferred-types/dist/index.js +403 -24
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +327 -23
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +5485 -5155
- package/modules/runtime/dist/index.js +312 -23
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +9680 -9327
- 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 = [
|
|
@@ -2197,6 +2235,18 @@ function narrowObjectToType() {
|
|
|
2197
2235
|
);
|
|
2198
2236
|
}
|
|
2199
2237
|
|
|
2238
|
+
// src/dictionary/objectValues.ts
|
|
2239
|
+
function objectValues(obj) {
|
|
2240
|
+
const tuple3 = Object.keys(obj).reduce(
|
|
2241
|
+
(acc, key) => [
|
|
2242
|
+
...acc,
|
|
2243
|
+
obj[key]
|
|
2244
|
+
],
|
|
2245
|
+
[]
|
|
2246
|
+
);
|
|
2247
|
+
return tuple3;
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2200
2250
|
// src/dictionary/omit.ts
|
|
2201
2251
|
function omit(obj, ...removeKeys) {
|
|
2202
2252
|
const keys = Object.keys(obj);
|
|
@@ -2263,13 +2313,115 @@ function withoutKeys(dict, ...exclude) {
|
|
|
2263
2313
|
return omit(dict, ...exclude);
|
|
2264
2314
|
}
|
|
2265
2315
|
|
|
2316
|
+
// src/runtime-types/doesExtend.ts
|
|
2317
|
+
function doesExtend(type) {
|
|
2318
|
+
return (val) => {
|
|
2319
|
+
let response = false;
|
|
2320
|
+
if (isString(val)) {
|
|
2321
|
+
if (type === "string") {
|
|
2322
|
+
response = true;
|
|
2323
|
+
}
|
|
2324
|
+
if (type.startsWith("string(")) {
|
|
2325
|
+
const literals = stripAfter(
|
|
2326
|
+
stripBefore(type, "string("),
|
|
2327
|
+
")"
|
|
2328
|
+
).split(/,\s*/);
|
|
2329
|
+
if (literals.includes(val)) {
|
|
2330
|
+
response = true;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
if (isNumber(val)) {
|
|
2335
|
+
if (type === "number") {
|
|
2336
|
+
response = true;
|
|
2337
|
+
}
|
|
2338
|
+
if (type.startsWith("number(")) {
|
|
2339
|
+
const literals = stripAfter(
|
|
2340
|
+
stripBefore(type, "number("),
|
|
2341
|
+
")"
|
|
2342
|
+
).split(/,\s*/).map(Number);
|
|
2343
|
+
if (literals.includes(val)) {
|
|
2344
|
+
response = true;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
if (isNull(val) && (type === "null" || type === "Opt<null>")) {
|
|
2349
|
+
response = true;
|
|
2350
|
+
}
|
|
2351
|
+
if (isUndefined(val) && (type === "undefined" || type.startsWith("Opt<"))) {
|
|
2352
|
+
response = true;
|
|
2353
|
+
}
|
|
2354
|
+
if (isBoolean(val)) {
|
|
2355
|
+
if (type === "boolean") {
|
|
2356
|
+
response = true;
|
|
2357
|
+
}
|
|
2358
|
+
if (type === "true" && val === true || type === "false" && val === false) {
|
|
2359
|
+
response = true;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
if (isNarrowableObject(val)) {
|
|
2363
|
+
if (type === "Dict" || type === "Dict<string, unknown>") {
|
|
2364
|
+
response = true;
|
|
2365
|
+
}
|
|
2366
|
+
if (startsWith("Dict<")(type)) {
|
|
2367
|
+
const match = infer("Dict<{{infer key}}, {{infer value}}>")(type);
|
|
2368
|
+
if (match) {
|
|
2369
|
+
const { value } = match;
|
|
2370
|
+
const isOpt = value.includes(`Opt<`);
|
|
2371
|
+
const values = objectValues(val);
|
|
2372
|
+
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>") {
|
|
2373
|
+
response = true;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
if (isArray(val)) {
|
|
2379
|
+
if (type === "Array" || type === "Array<unknown>") {
|
|
2380
|
+
return true;
|
|
2381
|
+
}
|
|
2382
|
+
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)) {
|
|
2383
|
+
response = true;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
if (isMap(val)) {
|
|
2387
|
+
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)) {
|
|
2388
|
+
response = true;
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
if (isSetContainer(val)) {
|
|
2392
|
+
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))) {
|
|
2393
|
+
response = true;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
return response;
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2266
2400
|
// src/dictionary/withoutValue.ts
|
|
2267
|
-
function withoutValue(
|
|
2401
|
+
function withoutValue(wo) {
|
|
2268
2402
|
return (obj) => {
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2403
|
+
const output = {};
|
|
2404
|
+
for (const key of keysOf(obj)) {
|
|
2405
|
+
const val = obj[key];
|
|
2406
|
+
if (!doesExtend(wo)(val)) {
|
|
2407
|
+
output[key] = val;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
return output;
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
// src/dictionary/withValue.ts
|
|
2415
|
+
function withValue(wo) {
|
|
2416
|
+
return (obj) => {
|
|
2417
|
+
const output = {};
|
|
2418
|
+
for (const key of keysOf(obj)) {
|
|
2419
|
+
const val = obj[key];
|
|
2420
|
+
if (doesExtend(wo)(val)) {
|
|
2421
|
+
output[key] = val;
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
return output;
|
|
2273
2425
|
};
|
|
2274
2426
|
}
|
|
2275
2427
|
|
|
@@ -2354,7 +2506,7 @@ var filter = "NOT READY";
|
|
|
2354
2506
|
function find(list2, deref = null) {
|
|
2355
2507
|
return (comparator) => {
|
|
2356
2508
|
return list2.find((i) => {
|
|
2357
|
-
const val = deref ?
|
|
2509
|
+
const val = deref ? isObject(i) || isArray(i) ? deref in i ? i[deref] : void 0 : i : i;
|
|
2358
2510
|
return val === comparator;
|
|
2359
2511
|
});
|
|
2360
2512
|
};
|
|
@@ -2544,6 +2696,9 @@ function isFunction(value) {
|
|
|
2544
2696
|
function isObject(value) {
|
|
2545
2697
|
return typeof value === "object" && value !== null && Array.isArray(value) === false;
|
|
2546
2698
|
}
|
|
2699
|
+
function isNarrowableObject(value) {
|
|
2700
|
+
return isObject(value) && Object.keys(value).every((key) => ["string", "number", "boolean", "symbol", "object", "undefined", "void", "null"].includes(typeof value[key]));
|
|
2701
|
+
}
|
|
2547
2702
|
|
|
2548
2703
|
// src/type-guards/api-tg.ts
|
|
2549
2704
|
function isEscapeFunction(val) {
|
|
@@ -3184,6 +3339,11 @@ function isCssAspectRatio(val) {
|
|
|
3184
3339
|
return isString(val) && val.split(/\s+/).every((i) => tokens.includes(i) || isRatio(i));
|
|
3185
3340
|
}
|
|
3186
3341
|
|
|
3342
|
+
// src/type-guards/isCsv.ts
|
|
3343
|
+
function isCsv(val) {
|
|
3344
|
+
return isString(val) && val.includes(",") && !val.startsWith(",");
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3187
3347
|
// src/type-guards/isDefined.ts
|
|
3188
3348
|
function isDefined(value) {
|
|
3189
3349
|
return typeof value !== "undefined";
|
|
@@ -3241,6 +3401,11 @@ function isInlineSvg(v) {
|
|
|
3241
3401
|
return isString(v) && v.trim().startsWith(`<svg`) && v.trim().endsWith(`</svg>`);
|
|
3242
3402
|
}
|
|
3243
3403
|
|
|
3404
|
+
// src/type-guards/isMap.ts
|
|
3405
|
+
function isMap(val) {
|
|
3406
|
+
return val instanceof Map;
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3244
3409
|
// src/type-guards/isNever.ts
|
|
3245
3410
|
function isNever(val) {
|
|
3246
3411
|
return isConstant(val) && val.kind === "never";
|
|
@@ -3261,7 +3426,7 @@ function isPhoneNumber(val) {
|
|
|
3261
3426
|
const svelte = String(val).trim();
|
|
3262
3427
|
const chars = svelte.split("");
|
|
3263
3428
|
const numeric = retainChars(svelte, ...NUMERIC_CHAR);
|
|
3264
|
-
const
|
|
3429
|
+
const valid2 = ["+", "(", ...NUMERIC_CHAR];
|
|
3265
3430
|
const nothing = stripChars(svelte, ...[
|
|
3266
3431
|
...NUMERIC_CHAR,
|
|
3267
3432
|
...WHITESPACE_CHARS,
|
|
@@ -3271,7 +3436,7 @@ function isPhoneNumber(val) {
|
|
|
3271
3436
|
".",
|
|
3272
3437
|
"-"
|
|
3273
3438
|
]);
|
|
3274
|
-
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 === "";
|
|
3275
3440
|
}
|
|
3276
3441
|
|
|
3277
3442
|
// src/type-guards/isReadonlyArray.ts
|
|
@@ -3303,6 +3468,16 @@ function isLikeRegExp(val) {
|
|
|
3303
3468
|
return false;
|
|
3304
3469
|
}
|
|
3305
3470
|
|
|
3471
|
+
// src/type-guards/isSet.ts
|
|
3472
|
+
function isSet(val) {
|
|
3473
|
+
return isObject(val) ? val.kind !== "Unset" : true;
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
// src/type-guards/isSetContainer.ts
|
|
3477
|
+
function isSetContainer(val) {
|
|
3478
|
+
return val instanceof Set;
|
|
3479
|
+
}
|
|
3480
|
+
|
|
3306
3481
|
// src/type-guards/isStringArray.ts
|
|
3307
3482
|
function isStringArray(val) {
|
|
3308
3483
|
return Array.isArray(val) && val.every((i) => isString(i));
|
|
@@ -3342,9 +3517,6 @@ function isTypeTuple(value) {
|
|
|
3342
3517
|
function isUnset(val) {
|
|
3343
3518
|
return isObject(val) && val.kind === "Unset";
|
|
3344
3519
|
}
|
|
3345
|
-
function isSet(val) {
|
|
3346
|
-
return isObject(val) ? val.kind !== "Unset" : true;
|
|
3347
|
-
}
|
|
3348
3520
|
|
|
3349
3521
|
// src/type-guards/isUrl.ts
|
|
3350
3522
|
function isUri(val, ...protocols) {
|
|
@@ -3356,6 +3528,21 @@ function isUrl(val, ...protocols) {
|
|
|
3356
3528
|
return isString(val) && p.some((i) => val.startsWith(`${i}://`));
|
|
3357
3529
|
}
|
|
3358
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
|
+
|
|
3359
3546
|
// src/type-guards/metrics/isMetric.ts
|
|
3360
3547
|
function separate(s) {
|
|
3361
3548
|
return stripWhile(s.toLowerCase(), ...NUMERIC_CHAR).trim();
|
|
@@ -3502,6 +3689,20 @@ function isNumericArray(val) {
|
|
|
3502
3689
|
return Array.isArray(val) && val.every((i) => isNumber(i));
|
|
3503
3690
|
}
|
|
3504
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
|
+
|
|
3505
3706
|
// src/type-guards/tokens/general.ts
|
|
3506
3707
|
function isTypeToken(val, kind) {
|
|
3507
3708
|
if (isString(val) && val.startsWith("<<") && val.endsWith(">>")) {
|
|
@@ -3796,28 +3997,28 @@ function isNewsUrl(val) {
|
|
|
3796
3997
|
|
|
3797
3998
|
// src/type-guards/urls/repos/bitbucket.ts
|
|
3798
3999
|
function isBitbucketUrl(val) {
|
|
3799
|
-
const
|
|
3800
|
-
return isString(val) &&
|
|
4000
|
+
const valid2 = REPO_SOURCE_LOOKUP.bitbucket;
|
|
4001
|
+
return isString(val) && valid2.some(
|
|
3801
4002
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3802
4003
|
);
|
|
3803
4004
|
}
|
|
3804
4005
|
|
|
3805
4006
|
// src/type-guards/urls/repos/codeCommit.ts
|
|
3806
4007
|
function isCodeCommitUrl(val) {
|
|
3807
|
-
const
|
|
3808
|
-
return isString(val) &&
|
|
4008
|
+
const valid2 = REPO_SOURCE_LOOKUP.codecommit;
|
|
4009
|
+
return isString(val) && valid2.some(
|
|
3809
4010
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3810
4011
|
);
|
|
3811
4012
|
}
|
|
3812
4013
|
|
|
3813
4014
|
// src/type-guards/urls/repos/github.ts
|
|
3814
4015
|
function isGithubUrl(val) {
|
|
3815
|
-
const
|
|
4016
|
+
const valid2 = [
|
|
3816
4017
|
"https://github.com",
|
|
3817
4018
|
"https://www.github.com",
|
|
3818
4019
|
"https://github.io"
|
|
3819
4020
|
];
|
|
3820
|
-
return isString(val) &&
|
|
4021
|
+
return isString(val) && valid2.some(
|
|
3821
4022
|
(i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
|
|
3822
4023
|
);
|
|
3823
4024
|
}
|
|
@@ -4455,16 +4656,77 @@ function getUrlQueryParams(url, specific = void 0) {
|
|
|
4455
4656
|
}
|
|
4456
4657
|
return qp === "" ? qp : `?${qp}`;
|
|
4457
4658
|
}
|
|
4458
|
-
function
|
|
4459
|
-
const
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
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;
|
|
4463
4667
|
}
|
|
4464
4668
|
function getUrlSource(url) {
|
|
4465
4669
|
const candidate = stripAfter(stripAfter(stripAfter(removeUrlProtocol(url), "/"), "?"), ":");
|
|
4466
4670
|
return isIpAddress(candidate) || isDomainName(candidate) ? candidate : Never;
|
|
4467
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
|
+
}
|
|
4468
4730
|
function urlMeta(url) {
|
|
4469
4731
|
return {
|
|
4470
4732
|
url,
|
|
@@ -4472,6 +4734,7 @@ function urlMeta(url) {
|
|
|
4472
4734
|
protocol: getUrlProtocol(url),
|
|
4473
4735
|
path: getUrlPath(url),
|
|
4474
4736
|
queryParameters: getUrlQueryParams(url),
|
|
4737
|
+
params: getUrlDynamics,
|
|
4475
4738
|
port: getUrlPort(url),
|
|
4476
4739
|
source: getUrlSource(url),
|
|
4477
4740
|
isIpAddress: isIpAddress(getUrlSource(url)),
|
|
@@ -4917,6 +5180,17 @@ function simpleType(token) {
|
|
|
4917
5180
|
return value;
|
|
4918
5181
|
}
|
|
4919
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
|
+
|
|
4920
5194
|
// src/sets/uniqueKeys.ts
|
|
4921
5195
|
function uniqueKeys(left, right) {
|
|
4922
5196
|
const isNumeric = !!(isArray(left) && isArray(right));
|
|
@@ -5005,6 +5279,9 @@ export {
|
|
|
5005
5279
|
getTokenKind,
|
|
5006
5280
|
getTomorrow,
|
|
5007
5281
|
getTypeSubtype,
|
|
5282
|
+
getUrlBase,
|
|
5283
|
+
getUrlDefaultPort,
|
|
5284
|
+
getUrlDynamics,
|
|
5008
5285
|
getUrlPath,
|
|
5009
5286
|
getUrlPort,
|
|
5010
5287
|
getUrlProtocol,
|
|
@@ -5017,6 +5294,9 @@ export {
|
|
|
5017
5294
|
hasDefaultValue,
|
|
5018
5295
|
hasIndexOf,
|
|
5019
5296
|
hasKeys,
|
|
5297
|
+
hasOverlappingKeys,
|
|
5298
|
+
hasProtocol,
|
|
5299
|
+
hasProtocolPrefix,
|
|
5020
5300
|
hasUrlPort,
|
|
5021
5301
|
hasUrlQueryParameter,
|
|
5022
5302
|
hasWhiteSpace,
|
|
@@ -5082,6 +5362,7 @@ export {
|
|
|
5082
5362
|
isCountryCode3,
|
|
5083
5363
|
isCountryName,
|
|
5084
5364
|
isCssAspectRatio,
|
|
5365
|
+
isCsv,
|
|
5085
5366
|
isCurrentMetric,
|
|
5086
5367
|
isCurrentUom,
|
|
5087
5368
|
isCvsUrl,
|
|
@@ -5158,12 +5439,14 @@ export {
|
|
|
5158
5439
|
isLuminosityUom,
|
|
5159
5440
|
isLuxonDateTime,
|
|
5160
5441
|
isMacysUrl,
|
|
5442
|
+
isMap,
|
|
5161
5443
|
isMapToken,
|
|
5162
5444
|
isMassMetric,
|
|
5163
5445
|
isMassUom,
|
|
5164
5446
|
isMetric,
|
|
5165
5447
|
isMexicanNewsUrl,
|
|
5166
5448
|
isMoment,
|
|
5449
|
+
isNarrowableObject,
|
|
5167
5450
|
isNever,
|
|
5168
5451
|
isNewsUrl,
|
|
5169
5452
|
isNikeUrl,
|
|
@@ -5183,6 +5466,8 @@ export {
|
|
|
5183
5466
|
isPowerUom,
|
|
5184
5467
|
isPressureMetric,
|
|
5185
5468
|
isPressureUom,
|
|
5469
|
+
isProtocol,
|
|
5470
|
+
isProtocolPrefix,
|
|
5186
5471
|
isReadonlyArray,
|
|
5187
5472
|
isRecordToken,
|
|
5188
5473
|
isRef,
|
|
@@ -5198,6 +5483,7 @@ export {
|
|
|
5198
5483
|
isSet,
|
|
5199
5484
|
isSetBasedKind,
|
|
5200
5485
|
isSetBasedToken,
|
|
5486
|
+
isSetContainer,
|
|
5201
5487
|
isSetToken,
|
|
5202
5488
|
isShape,
|
|
5203
5489
|
isShapeCallback,
|
|
@@ -5260,6 +5546,7 @@ export {
|
|
|
5260
5546
|
isUsNewsUrl,
|
|
5261
5547
|
isUsStateAbbreviation,
|
|
5262
5548
|
isUsStateName,
|
|
5549
|
+
isVariable,
|
|
5263
5550
|
isVoltageMetric,
|
|
5264
5551
|
isVoltageUom,
|
|
5265
5552
|
isVolumeMetric,
|
|
@@ -5307,6 +5594,7 @@ export {
|
|
|
5307
5594
|
narrowObjectToType,
|
|
5308
5595
|
never,
|
|
5309
5596
|
objectToApi,
|
|
5597
|
+
objectValues,
|
|
5310
5598
|
omit,
|
|
5311
5599
|
optional,
|
|
5312
5600
|
optionalOrNull,
|
|
@@ -5383,6 +5671,7 @@ export {
|
|
|
5383
5671
|
widen,
|
|
5384
5672
|
withDefaults,
|
|
5385
5673
|
withKeys,
|
|
5674
|
+
withValue,
|
|
5386
5675
|
withoutKeys,
|
|
5387
5676
|
withoutValue,
|
|
5388
5677
|
wrapFn,
|