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.
@@ -508,6 +508,73 @@ var HASH_TABLE_CHAR = {
508
508
  ...HASH_TABLE_SPECIAL
509
509
  };
510
510
  var HASH_TABLE_OTHER = "999";
511
+ var MIME_TYPES = [
512
+ // Application MIME Types
513
+ "application/json",
514
+ "application/xml",
515
+ "application/javascript",
516
+ "application/pdf",
517
+ "application/ld+json",
518
+ "application/octet-stream",
519
+ "application/x-www-form-urlencoded",
520
+ "application/vnd.api+json",
521
+ "application/msword",
522
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
523
+ "application/vnd.ms-excel",
524
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
525
+ "application/vnd.ms-powerpoint",
526
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
527
+ // Text MIME Types
528
+ "text/plain",
529
+ "text/html",
530
+ "text/css",
531
+ "text/csv",
532
+ "text/javascript",
533
+ "text/markdown",
534
+ // Image MIME Types
535
+ "image/jpeg",
536
+ "image/png",
537
+ "image/gif",
538
+ "image/bmp",
539
+ "image/webp",
540
+ "image/svg+xml",
541
+ "image/tiff",
542
+ // Audio MIME Types
543
+ "audio/mpeg",
544
+ "audio/ogg",
545
+ "audio/wav",
546
+ "audio/webm",
547
+ "audio/flac",
548
+ // Video MIME Types
549
+ "video/mp4",
550
+ "video/mpeg",
551
+ "video/ogg",
552
+ "video/webm",
553
+ "video/quicktime",
554
+ // Multipart MIME Types
555
+ "multipart/form-data",
556
+ "multipart/mixed",
557
+ "multipart/alternative",
558
+ "multipart/related",
559
+ // Font MIME Types
560
+ "font/woff",
561
+ "font/woff2",
562
+ "font/ttf",
563
+ "font/otf",
564
+ // Other Common MIME Types
565
+ "application/rss+xml",
566
+ "application/atom+xml",
567
+ "application/x-pkcs12",
568
+ "application/x-shockwave-flash",
569
+ "application/x-www-form-urlencoded",
570
+ "application/x-font-ttf",
571
+ "application/x-font-opentype",
572
+ "application/x-font-woff",
573
+ "application/x-font-woff2",
574
+ "application/vnd.rar",
575
+ "application/zip",
576
+ "application/x-7z-compressed"
577
+ ];
511
578
  var IMAGE_FORMAT_LOOKUP = [
512
579
  { ext: "jpg", webFormat: true, other_ext: ["jpeg"] },
513
580
  { ext: "png", webFormat: true, other_ext: [] },
@@ -848,13 +915,51 @@ var IPv6 = {
848
915
  var IPv4 = {
849
916
  Loopback: "127.0.0.1"
850
917
  };
918
+ var NETWORK_PROTOCOL_INSECURE = [
919
+ "http",
920
+ "ftp",
921
+ "ws",
922
+ "dns",
923
+ "telnet",
924
+ "imap",
925
+ "pop3",
926
+ "smtp"
927
+ ];
928
+ var NETWORK_PROTOCOL_SECURE = [
929
+ "https",
930
+ "sftp",
931
+ "wss",
932
+ "sdns",
933
+ "ssh"
934
+ ];
935
+ var NETWORK_PROTOCOL = [
936
+ ...NETWORK_PROTOCOL_INSECURE,
937
+ ...NETWORK_PROTOCOL_SECURE
938
+ ];
851
939
  var NETWORK_PROTOCOL_LOOKUP = {
852
940
  http: ["http", "https"],
853
941
  ftp: ["ftp", "sftp"],
854
942
  file: ["", "file"],
855
943
  ws: ["ws", "wss"],
856
944
  ssh: ["", "ssh"],
857
- scp: ["", "scp"]
945
+ scp: ["", "scp"],
946
+ telnet: ["telnet", ""],
947
+ dns: ["dns", "sdns"]
948
+ };
949
+ var PROTOCOL_DEFAULT_PORTS = {
950
+ http: 80,
951
+ https: 443,
952
+ ws: 80,
953
+ wss: 443,
954
+ ssh: 22,
955
+ telnet: 23,
956
+ dns: 53,
957
+ sdns: 853,
958
+ smtp: 25,
959
+ imap: 142,
960
+ pop3: 110,
961
+ ftp: 21,
962
+ sftp: 22
858
963
  };
859
964
  var TOP_LEVEL_DOMAINS = [
860
965
  "com",
@@ -3156,13 +3261,51 @@ var AREA_METRICS_LOOKUP2 = [
3156
3261
  { abbrev: "acre", name: "acre" },
3157
3262
  { abbrev: "ha", name: "hectare" }
3158
3263
  ];
3264
+ var NETWORK_PROTOCOL_INSECURE2 = [
3265
+ "http",
3266
+ "ftp",
3267
+ "ws",
3268
+ "dns",
3269
+ "telnet",
3270
+ "imap",
3271
+ "pop3",
3272
+ "smtp"
3273
+ ];
3274
+ var NETWORK_PROTOCOL_SECURE2 = [
3275
+ "https",
3276
+ "sftp",
3277
+ "wss",
3278
+ "sdns",
3279
+ "ssh"
3280
+ ];
3281
+ var NETWORK_PROTOCOL2 = [
3282
+ ...NETWORK_PROTOCOL_INSECURE2,
3283
+ ...NETWORK_PROTOCOL_SECURE2
3284
+ ];
3159
3285
  var NETWORK_PROTOCOL_LOOKUP2 = {
3160
3286
  http: ["http", "https"],
3161
3287
  ftp: ["ftp", "sftp"],
3162
3288
  file: ["", "file"],
3163
3289
  ws: ["ws", "wss"],
3164
3290
  ssh: ["", "ssh"],
3165
- scp: ["", "scp"]
3291
+ scp: ["", "scp"],
3292
+ telnet: ["telnet", ""],
3293
+ dns: ["dns", "sdns"]
3294
+ };
3295
+ var PROTOCOL_DEFAULT_PORTS2 = {
3296
+ http: 80,
3297
+ https: 443,
3298
+ ws: 80,
3299
+ wss: 443,
3300
+ ssh: 22,
3301
+ telnet: 23,
3302
+ dns: 53,
3303
+ sdns: 853,
3304
+ smtp: 25,
3305
+ imap: 142,
3306
+ pop3: 110,
3307
+ ftp: 21,
3308
+ sftp: 22
3166
3309
  };
3167
3310
  var Never2 = createConstant2("never");
3168
3311
  var US_NEWS2 = [
@@ -4823,7 +4966,7 @@ var filter = "NOT READY";
4823
4966
  function find(list2, deref = null) {
4824
4967
  return (comparator) => {
4825
4968
  return list2.find((i) => {
4826
- const val = deref ? isContainer(i) ? deref in i ? i[deref] : void 0 : i : i;
4969
+ const val = deref ? isObject(i) || isArray(i) ? deref in i ? i[deref] : void 0 : i : i;
4827
4970
  return val === comparator;
4828
4971
  });
4829
4972
  };
@@ -5497,6 +5640,9 @@ var isRatio = (val) => /\d{1,4}\s*\/\s*\d{1,4}/.test(val);
5497
5640
  function isCssAspectRatio(val) {
5498
5641
  return isString(val) && val.split(/\s+/).every((i) => tokens.includes(i) || isRatio(i));
5499
5642
  }
5643
+ function isCsv(val) {
5644
+ return isString(val) && val.includes(",") && !val.startsWith(",");
5645
+ }
5500
5646
  function isDefined(value) {
5501
5647
  return typeof value !== "undefined";
5502
5648
  }
@@ -5550,7 +5696,7 @@ function isPhoneNumber(val) {
5550
5696
  const svelte = String(val).trim();
5551
5697
  const chars = svelte.split("");
5552
5698
  const numeric = retainChars(svelte, ...NUMERIC_CHAR2);
5553
- const valid = ["+", "(", ...NUMERIC_CHAR2];
5699
+ const valid2 = ["+", "(", ...NUMERIC_CHAR2];
5554
5700
  const nothing = stripChars(svelte, ...[
5555
5701
  ...NUMERIC_CHAR2,
5556
5702
  ...WHITESPACE_CHARS2,
@@ -5560,7 +5706,7 @@ function isPhoneNumber(val) {
5560
5706
  ".",
5561
5707
  "-"
5562
5708
  ]);
5563
- return chars.every((i) => valid.includes(i)) && svelte.startsWith(`+`) ? numeric.length >= 8 : svelte.startsWith(`00`) ? numeric.length >= 10 : numeric.length >= 7 && nothing === "";
5709
+ return chars.every((i) => valid2.includes(i)) && svelte.startsWith(`+`) ? numeric.length >= 8 : svelte.startsWith(`00`) ? numeric.length >= 10 : numeric.length >= 7 && nothing === "";
5564
5710
  }
5565
5711
  function isReadonlyArray(value) {
5566
5712
  return Array.isArray(value) === true;
@@ -5623,6 +5769,19 @@ function isUrl(val, ...protocols) {
5623
5769
  const p = protocols.length === 0 ? ["http", "https"] : protocols;
5624
5770
  return isString(val) && p.some((i) => val.startsWith(`${i}://`));
5625
5771
  }
5772
+ var VALID = [
5773
+ ...ALPHA_CHARS2,
5774
+ ...NUMERIC_CHAR2,
5775
+ "_",
5776
+ "."
5777
+ ];
5778
+ var alpha = null;
5779
+ function valid(chars) {
5780
+ return chars.every((i) => VALID.includes(i));
5781
+ }
5782
+ function isVariable(val) {
5783
+ return isString(val) && startsWith(alpha)(val) && valid(asChars(val));
5784
+ }
5626
5785
  function separate(s) {
5627
5786
  return stripWhile(s.toLowerCase(), ...NUMERIC_CHAR2).trim();
5628
5787
  }
@@ -5761,6 +5920,18 @@ function hasUrlQueryParameter(val, prop) {
5761
5920
  function isNumericArray(val) {
5762
5921
  return Array.isArray(val) && val.every((i) => isNumber(i));
5763
5922
  }
5923
+ function hasProtocol(val, ...protocols) {
5924
+ return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL2.some((i) => val.startsWith(i)) : protocols.some((i) => val.startsWith(i));
5925
+ }
5926
+ function isProtocol(val, ...protocols) {
5927
+ return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL2.includes(val) : protocols.includes(val);
5928
+ }
5929
+ function hasProtocolPrefix(val, ...protocols) {
5930
+ return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL2.map((i) => `${i}://`).some((i) => val.startsWith(i)) : protocols.map((i) => `${i}://`).some((i) => val.startsWith(i));
5931
+ }
5932
+ function isProtocolPrefix(val, ...protocols) {
5933
+ return isString(val) && protocols.length === 0 ? NETWORK_PROTOCOL2.map((i) => `${i}://`).includes(val) : protocols.map((i) => `${i}://`).includes(val);
5934
+ }
5764
5935
  function isTypeToken(val, kind) {
5765
5936
  if (isString(val) && val.startsWith("<<") && val.endsWith(">>")) {
5766
5937
  const stripped = stripSurround("<<", ">>")(val);
@@ -5992,24 +6163,24 @@ function isNewsUrl(val) {
5992
6163
  return isAustralianNewsUrl(val) || isBelgiumNewsUrl(val) || isCanadianNewsUrl(val) || isDanishNewsUrl(val) || isDutchNewsUrl(val) || isFrenchNewsUrl(val) || isGermanNewsUrl(val) || isIndianNewsUrl(val) || isItalianNewsUrl(val) || isJapaneseNewsUrl(val) || isMexicanNewsUrl(val) || isNorwegianNewsUrl(val) || isSouthKoreanNewsUrl(val) || isSpanishNewsUrl(val) || isSwissNewsUrl(val) || isTurkishNewsUrl(val) || isUkNewsUrl(val) || isUsNewsUrl(val);
5993
6164
  }
5994
6165
  function isBitbucketUrl(val) {
5995
- const valid = REPO_SOURCE_LOOKUP2.bitbucket;
5996
- return isString(val) && valid.some(
6166
+ const valid2 = REPO_SOURCE_LOOKUP2.bitbucket;
6167
+ return isString(val) && valid2.some(
5997
6168
  (i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
5998
6169
  );
5999
6170
  }
6000
6171
  function isCodeCommitUrl(val) {
6001
- const valid = REPO_SOURCE_LOOKUP2.codecommit;
6002
- return isString(val) && valid.some(
6172
+ const valid2 = REPO_SOURCE_LOOKUP2.codecommit;
6173
+ return isString(val) && valid2.some(
6003
6174
  (i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
6004
6175
  );
6005
6176
  }
6006
6177
  function isGithubUrl(val) {
6007
- const valid = [
6178
+ const valid2 = [
6008
6179
  "https://github.com",
6009
6180
  "https://www.github.com",
6010
6181
  "https://github.io"
6011
6182
  ];
6012
- return isString(val) && valid.some(
6183
+ return isString(val) && valid2.some(
6013
6184
  (i) => val === i || val.startsWith(`${i}/`) || val.startsWith(`${i}?`)
6014
6185
  );
6015
6186
  }
@@ -6553,16 +6724,77 @@ function getUrlQueryParams(url, specific = void 0) {
6553
6724
  }
6554
6725
  return qp === "" ? qp : `?${qp}`;
6555
6726
  }
6556
- function getUrlPort(url) {
6557
- const candidate = takeNumericCharacters(
6558
- stripBefore(removeUrlProtocol(url), ":")
6559
- );
6560
- return candidate === "" ? "default" : Number(candidate);
6727
+ function getUrlDefaultPort(url) {
6728
+ const proto = getUrlProtocol(url);
6729
+ return proto in PROTOCOL_DEFAULT_PORTS2 ? PROTOCOL_DEFAULT_PORTS2[proto] : null;
6730
+ }
6731
+ function getUrlPort(url, resolve = false) {
6732
+ const re = /.*:(\d{2,3})/;
6733
+ const match = url.match(re);
6734
+ return re.test(url) && match && isNumberLike(Array.from(match)[1]) ? Number(Array.from(match)[1]) : resolve ? getUrlDefaultPort(url) : hasProtocol(url) ? `default` : null;
6561
6735
  }
6562
6736
  function getUrlSource(url) {
6563
6737
  const candidate = stripAfter(stripAfter(stripAfter(removeUrlProtocol(url), "/"), "?"), ":");
6564
6738
  return isIpAddress(candidate) || isDomainName(candidate) ? candidate : Never2;
6565
6739
  }
6740
+ function getUrlBase(url) {
6741
+ const path = getUrlPath(url);
6742
+ const remaining = stripAfter(url, path);
6743
+ return remaining;
6744
+ }
6745
+ function getUrlDynamics(url) {
6746
+ const path = getUrlPath(url);
6747
+ const qp = getUrlQueryParams(url);
6748
+ const pathParts = path.startsWith("<") ? path.split("<").map((i) => ensureLeading(i, "<")) : path.split("<").map((i) => ensureLeading(i, "<")).slice(1);
6749
+ const segmentTypes = [
6750
+ "string",
6751
+ "number",
6752
+ "boolean",
6753
+ "Opt<string>",
6754
+ "Opt<number>",
6755
+ "Opt<boolean>"
6756
+ ];
6757
+ const pathVars = {};
6758
+ const findPathTyped = infer(`<{{infer name}} as {{infer type}}>`);
6759
+ const findPathUnion = infer(`<{{infer name}} as string({{infer union}})>`);
6760
+ const findPathNamed = infer(`<{{infer name}}>`);
6761
+ for (const part of pathParts) {
6762
+ const union4 = findPathUnion(part);
6763
+ const typed = findPathTyped(part);
6764
+ const named = findPathNamed(part);
6765
+ if (union4) {
6766
+ if (isVariable(union4.name) && isCsv(union4.union)) {
6767
+ pathVars[union4.name] = `string(${union4.union})`;
6768
+ }
6769
+ } else if (typed && segmentTypes.includes(typed.type) && isVariable(typed.name)) {
6770
+ pathVars[typed.name] = typed.type;
6771
+ } else if (named && isVariable(named.name)) {
6772
+ pathVars[named.name] = "string";
6773
+ }
6774
+ }
6775
+ const qpVars = {};
6776
+ const qpParts = stripLeading(qp, "?").split("&");
6777
+ for (const p of qpParts) {
6778
+ const union4 = infer(`{{infer var}}=<string({{infer params}})>`)(p);
6779
+ const dynamic = infer(`{{infer var}}=<{{infer val}}>`)(p);
6780
+ const fixed = infer(`{{infer var}}={{infer val}}`)(p);
6781
+ if (union4 && isVariable(union4.var) && isCsv(union4.params)) {
6782
+ qpVars[union4.var] = `string(${union4.params})`;
6783
+ } else if (dynamic && isVariable(dynamic.var) && segmentTypes.includes(dynamic.val)) {
6784
+ qpVars[dynamic.var] = dynamic.val;
6785
+ } else if (fixed && isVariable(fixed.var)) {
6786
+ qpVars[fixed.var] = fixed.val;
6787
+ }
6788
+ }
6789
+ return {
6790
+ pathVars,
6791
+ qpVars,
6792
+ allVars: hasOverlappingKeys(pathVars, qpVars) ? null : {
6793
+ ...pathVars,
6794
+ ...qpVars
6795
+ }
6796
+ };
6797
+ }
6566
6798
  function urlMeta(url) {
6567
6799
  return {
6568
6800
  url,
@@ -6570,6 +6802,7 @@ function urlMeta(url) {
6570
6802
  protocol: getUrlProtocol(url),
6571
6803
  path: getUrlPath(url),
6572
6804
  queryParameters: getUrlQueryParams(url),
6805
+ params: getUrlDynamics,
6573
6806
  port: getUrlPort(url),
6574
6807
  source: getUrlSource(url),
6575
6808
  isIpAddress: isIpAddress(getUrlSource(url)),
@@ -6970,6 +7203,15 @@ function simpleType(token) {
6970
7203
  const value = isSimpleScalarToken(token) ? simpleScalarType(token) : isSimpleContainerToken(token) ? simpleContainerToken(token) : Never2;
6971
7204
  return value;
6972
7205
  }
7206
+ function hasOverlappingKeys(a, b) {
7207
+ const keys = Object.keys(a);
7208
+ for (const k of keys) {
7209
+ if (k in b) {
7210
+ return true;
7211
+ }
7212
+ }
7213
+ return false;
7214
+ }
6973
7215
  function uniqueKeys(left, right) {
6974
7216
  const isNumeric = !!(isArray(left) && isArray(right));
6975
7217
  if (isArray(left) && !isArray(right) || isArray(right) && !isArray(left)) {
@@ -7257,11 +7499,15 @@ export {
7257
7499
  MARKED,
7258
7500
  MASS_METRICS_LOOKUP,
7259
7501
  MEXICAN_NEWS,
7502
+ MIME_TYPES,
7260
7503
  MONTH_ABBR,
7261
7504
  MONTH_NAME,
7262
7505
  MapCardinality,
7263
7506
  NARROW_CONTAINER_TYPE_KINDS,
7507
+ NETWORK_PROTOCOL,
7508
+ NETWORK_PROTOCOL_INSECURE,
7264
7509
  NETWORK_PROTOCOL_LOOKUP,
7510
+ NETWORK_PROTOCOL_SECURE,
7265
7511
  NIKE_DNS,
7266
7512
  NON_ZERO_NUMERIC_CHAR,
7267
7513
  NORWEGIAN_NEWS,
@@ -7278,6 +7524,7 @@ export {
7278
7524
  PLURAL_EXCEPTIONS_OLD,
7279
7525
  POWER_METRICS_LOOKUP,
7280
7526
  PRESSURE_METRICS_LOOKUP,
7527
+ PROTOCOL_DEFAULT_PORTS,
7281
7528
  PROXMOX_CT_STATE,
7282
7529
  REPO_PAGE_TYPES,
7283
7530
  REPO_SOURCES,
@@ -7441,6 +7688,9 @@ export {
7441
7688
  getTokenKind,
7442
7689
  getTomorrow,
7443
7690
  getTypeSubtype,
7691
+ getUrlBase,
7692
+ getUrlDefaultPort,
7693
+ getUrlDynamics,
7444
7694
  getUrlPath,
7445
7695
  getUrlPort,
7446
7696
  getUrlProtocol,
@@ -7453,6 +7703,9 @@ export {
7453
7703
  hasDefaultValue,
7454
7704
  hasIndexOf,
7455
7705
  hasKeys,
7706
+ hasOverlappingKeys,
7707
+ hasProtocol,
7708
+ hasProtocolPrefix,
7456
7709
  hasUrlPort,
7457
7710
  hasUrlQueryParameter,
7458
7711
  hasWhiteSpace,
@@ -7518,6 +7771,7 @@ export {
7518
7771
  isCountryCode3,
7519
7772
  isCountryName,
7520
7773
  isCssAspectRatio,
7774
+ isCsv,
7521
7775
  isCurrentMetric,
7522
7776
  isCurrentUom,
7523
7777
  isCvsUrl,
@@ -7621,6 +7875,8 @@ export {
7621
7875
  isPowerUom,
7622
7876
  isPressureMetric,
7623
7877
  isPressureUom,
7878
+ isProtocol,
7879
+ isProtocolPrefix,
7624
7880
  isReadonlyArray,
7625
7881
  isRecordToken,
7626
7882
  isRef,
@@ -7699,6 +7955,7 @@ export {
7699
7955
  isUsNewsUrl,
7700
7956
  isUsStateAbbreviation,
7701
7957
  isUsStateName,
7958
+ isVariable,
7702
7959
  isVoltageMetric,
7703
7960
  isVoltageUom,
7704
7961
  isVolumeMetric,