@pactflow/openapi-pact-comparator 1.6.0 → 1.6.1

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/dist/cli.cjs CHANGED
@@ -11880,6 +11880,7 @@ const minimumSchema = (originalSchema, oas) => {
11880
11880
  const subschema = cloneDeep(get$1(oas, path, {}));
11881
11881
  delete subschema.description;
11882
11882
  delete subschema.example;
11883
+ traverse(schema, cleanupDiscriminators);
11883
11884
  traverse(subschema, collectReferences);
11884
11885
  traverse(subschema, handleNullableSchema);
11885
11886
  traverse(subschema, convertExclusiveMinMax);
@@ -23326,44 +23327,6 @@ var uri = {};
23326
23327
 
23327
23328
  var fastUri = {exports: {}};
23328
23329
 
23329
- var scopedChars;
23330
- var hasRequiredScopedChars;
23331
-
23332
- function requireScopedChars () {
23333
- if (hasRequiredScopedChars) return scopedChars;
23334
- hasRequiredScopedChars = 1;
23335
-
23336
- const HEX = {
23337
- 0: 0,
23338
- 1: 1,
23339
- 2: 2,
23340
- 3: 3,
23341
- 4: 4,
23342
- 5: 5,
23343
- 6: 6,
23344
- 7: 7,
23345
- 8: 8,
23346
- 9: 9,
23347
- a: 10,
23348
- A: 10,
23349
- b: 11,
23350
- B: 11,
23351
- c: 12,
23352
- C: 12,
23353
- d: 13,
23354
- D: 13,
23355
- e: 14,
23356
- E: 14,
23357
- f: 15,
23358
- F: 15
23359
- };
23360
-
23361
- scopedChars = {
23362
- HEX
23363
- };
23364
- return scopedChars;
23365
- }
23366
-
23367
23330
  var utils;
23368
23331
  var hasRequiredUtils;
23369
23332
 
@@ -23371,62 +23334,100 @@ function requireUtils () {
23371
23334
  if (hasRequiredUtils) return utils;
23372
23335
  hasRequiredUtils = 1;
23373
23336
 
23374
- const { HEX } = requireScopedChars();
23337
+ /** @type {(value: string) => boolean} */
23338
+ const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
23375
23339
 
23376
- const IPV4_REG = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u;
23340
+ /** @type {(value: string) => boolean} */
23341
+ const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
23377
23342
 
23378
- function normalizeIPv4 (host) {
23379
- if (findToken(host, '.') < 3) { return { host, isIPV4: false } }
23380
- const matches = host.match(IPV4_REG) || [];
23381
- const [address] = matches;
23382
- if (address) {
23383
- return { host: stripLeadingZeros(address, '.'), isIPV4: true }
23384
- } else {
23385
- return { host, isIPV4: false }
23343
+ /**
23344
+ * @param {Array<string>} input
23345
+ * @returns {string}
23346
+ */
23347
+ function stringArrayToHexStripped (input) {
23348
+ let acc = '';
23349
+ let code = 0;
23350
+ let i = 0;
23351
+
23352
+ for (i = 0; i < input.length; i++) {
23353
+ code = input[i].charCodeAt(0);
23354
+ if (code === 48) {
23355
+ continue
23356
+ }
23357
+ if (!((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))) {
23358
+ return ''
23359
+ }
23360
+ acc += input[i];
23361
+ break
23386
23362
  }
23363
+
23364
+ for (i += 1; i < input.length; i++) {
23365
+ code = input[i].charCodeAt(0);
23366
+ if (!((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))) {
23367
+ return ''
23368
+ }
23369
+ acc += input[i];
23370
+ }
23371
+ return acc
23387
23372
  }
23388
23373
 
23389
23374
  /**
23390
- * @param {string[]} input
23391
- * @param {boolean} [keepZero=false]
23392
- * @returns {string|undefined}
23375
+ * @typedef {Object} GetIPV6Result
23376
+ * @property {boolean} error - Indicates if there was an error parsing the IPv6 address.
23377
+ * @property {string} address - The parsed IPv6 address.
23378
+ * @property {string} [zone] - The zone identifier, if present.
23393
23379
  */
23394
- function stringArrayToHexStripped (input, keepZero = false) {
23395
- let acc = '';
23396
- let strip = true;
23397
- for (const c of input) {
23398
- if (HEX[c] === undefined) return undefined
23399
- if (c !== '0' && strip === true) strip = false;
23400
- if (!strip) acc += c;
23380
+
23381
+ /**
23382
+ * @param {string} value
23383
+ * @returns {boolean}
23384
+ */
23385
+ const nonSimpleDomain = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);
23386
+
23387
+ /**
23388
+ * @param {Array<string>} buffer
23389
+ * @returns {boolean}
23390
+ */
23391
+ function consumeIsZone (buffer) {
23392
+ buffer.length = 0;
23393
+ return true
23394
+ }
23395
+
23396
+ /**
23397
+ * @param {Array<string>} buffer
23398
+ * @param {Array<string>} address
23399
+ * @param {GetIPV6Result} output
23400
+ * @returns {boolean}
23401
+ */
23402
+ function consumeHextets (buffer, address, output) {
23403
+ if (buffer.length) {
23404
+ const hex = stringArrayToHexStripped(buffer);
23405
+ if (hex !== '') {
23406
+ address.push(hex);
23407
+ } else {
23408
+ output.error = true;
23409
+ return false
23410
+ }
23411
+ buffer.length = 0;
23401
23412
  }
23402
- if (keepZero && acc.length === 0) acc = '0';
23403
- return acc
23413
+ return true
23404
23414
  }
23405
23415
 
23416
+ /**
23417
+ * @param {string} input
23418
+ * @returns {GetIPV6Result}
23419
+ */
23406
23420
  function getIPV6 (input) {
23407
23421
  let tokenCount = 0;
23408
23422
  const output = { error: false, address: '', zone: '' };
23423
+ /** @type {Array<string>} */
23409
23424
  const address = [];
23425
+ /** @type {Array<string>} */
23410
23426
  const buffer = [];
23411
- let isZone = false;
23412
23427
  let endipv6Encountered = false;
23413
23428
  let endIpv6 = false;
23414
23429
 
23415
- function consume () {
23416
- if (buffer.length) {
23417
- if (isZone === false) {
23418
- const hex = stringArrayToHexStripped(buffer);
23419
- if (hex !== undefined) {
23420
- address.push(hex);
23421
- } else {
23422
- output.error = true;
23423
- return false
23424
- }
23425
- }
23426
- buffer.length = 0;
23427
- }
23428
- return true
23429
- }
23430
+ let consume = consumeHextets;
23430
23431
 
23431
23432
  for (let i = 0; i < input.length; i++) {
23432
23433
  const cursor = input[i];
@@ -23435,29 +23436,28 @@ function requireUtils () {
23435
23436
  if (endipv6Encountered === true) {
23436
23437
  endIpv6 = true;
23437
23438
  }
23438
- if (!consume()) { break }
23439
- tokenCount++;
23440
- address.push(':');
23441
- if (tokenCount > 7) {
23439
+ if (!consume(buffer, address, output)) { break }
23440
+ if (++tokenCount > 7) {
23442
23441
  // not valid
23443
23442
  output.error = true;
23444
23443
  break
23445
23444
  }
23446
- if (i - 1 >= 0 && input[i - 1] === ':') {
23445
+ if (i > 0 && input[i - 1] === ':') {
23447
23446
  endipv6Encountered = true;
23448
23447
  }
23448
+ address.push(':');
23449
23449
  continue
23450
23450
  } else if (cursor === '%') {
23451
- if (!consume()) { break }
23451
+ if (!consume(buffer, address, output)) { break }
23452
23452
  // switch to zone detection
23453
- isZone = true;
23453
+ consume = consumeIsZone;
23454
23454
  } else {
23455
23455
  buffer.push(cursor);
23456
23456
  continue
23457
23457
  }
23458
23458
  }
23459
23459
  if (buffer.length) {
23460
- if (isZone) {
23460
+ if (consume === consumeIsZone) {
23461
23461
  output.zone = buffer.join('');
23462
23462
  } else if (endIpv6) {
23463
23463
  address.push(buffer.join(''));
@@ -23469,6 +23469,17 @@ function requireUtils () {
23469
23469
  return output
23470
23470
  }
23471
23471
 
23472
+ /**
23473
+ * @typedef {Object} NormalizeIPv6Result
23474
+ * @property {string} host - The normalized host.
23475
+ * @property {string} [escapedHost] - The escaped host.
23476
+ * @property {boolean} isIPV6 - Indicates if the host is an IPv6 address.
23477
+ */
23478
+
23479
+ /**
23480
+ * @param {string} host
23481
+ * @returns {NormalizeIPv6Result}
23482
+ */
23472
23483
  function normalizeIPv6 (host) {
23473
23484
  if (findToken(host, ':') < 2) { return { host, isIPV6: false } }
23474
23485
  const ipv6 = getIPV6(host);
@@ -23480,35 +23491,17 @@ function requireUtils () {
23480
23491
  newHost += '%' + ipv6.zone;
23481
23492
  escapedHost += '%25' + ipv6.zone;
23482
23493
  }
23483
- return { host: newHost, escapedHost, isIPV6: true }
23494
+ return { host: newHost, isIPV6: true, escapedHost }
23484
23495
  } else {
23485
23496
  return { host, isIPV6: false }
23486
23497
  }
23487
23498
  }
23488
23499
 
23489
- function stripLeadingZeros (str, token) {
23490
- let out = '';
23491
- let skip = true;
23492
- const l = str.length;
23493
- for (let i = 0; i < l; i++) {
23494
- const c = str[i];
23495
- if (c === '0' && skip) {
23496
- if ((i + 1 <= l && str[i + 1] === token) || i + 1 === l) {
23497
- out += c;
23498
- skip = false;
23499
- }
23500
- } else {
23501
- if (c === token) {
23502
- skip = true;
23503
- } else {
23504
- skip = false;
23505
- }
23506
- out += c;
23507
- }
23508
- }
23509
- return out
23510
- }
23511
-
23500
+ /**
23501
+ * @param {string} str
23502
+ * @param {string} token
23503
+ * @returns {number}
23504
+ */
23512
23505
  function findToken (str, token) {
23513
23506
  let ind = 0;
23514
23507
  for (let i = 0; i < str.length; i++) {
@@ -23517,98 +23510,160 @@ function requireUtils () {
23517
23510
  return ind
23518
23511
  }
23519
23512
 
23520
- const RDS1 = /^\.\.?\//u;
23521
- const RDS2 = /^\/\.(?:\/|$)/u;
23522
- const RDS3 = /^\/\.\.(?:\/|$)/u;
23523
- const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u;
23524
-
23525
- function removeDotSegments (input) {
23513
+ /**
23514
+ * @param {string} path
23515
+ * @returns {string}
23516
+ *
23517
+ * @see https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
23518
+ */
23519
+ function removeDotSegments (path) {
23520
+ let input = path;
23526
23521
  const output = [];
23522
+ let nextSlash = -1;
23523
+ let len = 0;
23527
23524
 
23528
- while (input.length) {
23529
- if (input.match(RDS1)) {
23530
- input = input.replace(RDS1, '');
23531
- } else if (input.match(RDS2)) {
23532
- input = input.replace(RDS2, '/');
23533
- } else if (input.match(RDS3)) {
23534
- input = input.replace(RDS3, '/');
23535
- output.pop();
23536
- } else if (input === '.' || input === '..') {
23537
- input = '';
23538
- } else {
23539
- const im = input.match(RDS5);
23540
- if (im) {
23541
- const s = im[0];
23542
- input = input.slice(s.length);
23543
- output.push(s);
23525
+ // eslint-disable-next-line no-cond-assign
23526
+ while (len = input.length) {
23527
+ if (len === 1) {
23528
+ if (input === '.') {
23529
+ break
23530
+ } else if (input === '/') {
23531
+ output.push('/');
23532
+ break
23544
23533
  } else {
23545
- throw new Error('Unexpected dot segment condition')
23534
+ output.push(input);
23535
+ break
23536
+ }
23537
+ } else if (len === 2) {
23538
+ if (input[0] === '.') {
23539
+ if (input[1] === '.') {
23540
+ break
23541
+ } else if (input[1] === '/') {
23542
+ input = input.slice(2);
23543
+ continue
23544
+ }
23545
+ } else if (input[0] === '/') {
23546
+ if (input[1] === '.' || input[1] === '/') {
23547
+ output.push('/');
23548
+ break
23549
+ }
23550
+ }
23551
+ } else if (len === 3) {
23552
+ if (input === '/..') {
23553
+ if (output.length !== 0) {
23554
+ output.pop();
23555
+ }
23556
+ output.push('/');
23557
+ break
23558
+ }
23559
+ }
23560
+ if (input[0] === '.') {
23561
+ if (input[1] === '.') {
23562
+ if (input[2] === '/') {
23563
+ input = input.slice(3);
23564
+ continue
23565
+ }
23566
+ } else if (input[1] === '/') {
23567
+ input = input.slice(2);
23568
+ continue
23569
+ }
23570
+ } else if (input[0] === '/') {
23571
+ if (input[1] === '.') {
23572
+ if (input[2] === '/') {
23573
+ input = input.slice(2);
23574
+ continue
23575
+ } else if (input[2] === '.') {
23576
+ if (input[3] === '/') {
23577
+ input = input.slice(3);
23578
+ if (output.length !== 0) {
23579
+ output.pop();
23580
+ }
23581
+ continue
23582
+ }
23583
+ }
23546
23584
  }
23547
23585
  }
23586
+
23587
+ // Rule 2E: Move normal path segment to output
23588
+ if ((nextSlash = input.indexOf('/', 1)) === -1) {
23589
+ output.push(input);
23590
+ break
23591
+ } else {
23592
+ output.push(input.slice(0, nextSlash));
23593
+ input = input.slice(nextSlash);
23594
+ }
23548
23595
  }
23596
+
23549
23597
  return output.join('')
23550
23598
  }
23551
23599
 
23552
- function normalizeComponentEncoding (components, esc) {
23600
+ /**
23601
+ * @param {import('../types/index').URIComponent} component
23602
+ * @param {boolean} esc
23603
+ * @returns {import('../types/index').URIComponent}
23604
+ */
23605
+ function normalizeComponentEncoding (component, esc) {
23553
23606
  const func = esc !== true ? escape : unescape;
23554
- if (components.scheme !== undefined) {
23555
- components.scheme = func(components.scheme);
23607
+ if (component.scheme !== undefined) {
23608
+ component.scheme = func(component.scheme);
23556
23609
  }
23557
- if (components.userinfo !== undefined) {
23558
- components.userinfo = func(components.userinfo);
23610
+ if (component.userinfo !== undefined) {
23611
+ component.userinfo = func(component.userinfo);
23559
23612
  }
23560
- if (components.host !== undefined) {
23561
- components.host = func(components.host);
23613
+ if (component.host !== undefined) {
23614
+ component.host = func(component.host);
23562
23615
  }
23563
- if (components.path !== undefined) {
23564
- components.path = func(components.path);
23616
+ if (component.path !== undefined) {
23617
+ component.path = func(component.path);
23565
23618
  }
23566
- if (components.query !== undefined) {
23567
- components.query = func(components.query);
23619
+ if (component.query !== undefined) {
23620
+ component.query = func(component.query);
23568
23621
  }
23569
- if (components.fragment !== undefined) {
23570
- components.fragment = func(components.fragment);
23622
+ if (component.fragment !== undefined) {
23623
+ component.fragment = func(component.fragment);
23571
23624
  }
23572
- return components
23625
+ return component
23573
23626
  }
23574
23627
 
23575
- function recomposeAuthority (components) {
23628
+ /**
23629
+ * @param {import('../types/index').URIComponent} component
23630
+ * @returns {string|undefined}
23631
+ */
23632
+ function recomposeAuthority (component) {
23576
23633
  const uriTokens = [];
23577
23634
 
23578
- if (components.userinfo !== undefined) {
23579
- uriTokens.push(components.userinfo);
23635
+ if (component.userinfo !== undefined) {
23636
+ uriTokens.push(component.userinfo);
23580
23637
  uriTokens.push('@');
23581
23638
  }
23582
23639
 
23583
- if (components.host !== undefined) {
23584
- let host = unescape(components.host);
23585
- const ipV4res = normalizeIPv4(host);
23586
-
23587
- if (ipV4res.isIPV4) {
23588
- host = ipV4res.host;
23589
- } else {
23590
- const ipV6res = normalizeIPv6(ipV4res.host);
23640
+ if (component.host !== undefined) {
23641
+ let host = unescape(component.host);
23642
+ if (!isIPv4(host)) {
23643
+ const ipV6res = normalizeIPv6(host);
23591
23644
  if (ipV6res.isIPV6 === true) {
23592
23645
  host = `[${ipV6res.escapedHost}]`;
23593
23646
  } else {
23594
- host = components.host;
23647
+ host = component.host;
23595
23648
  }
23596
23649
  }
23597
23650
  uriTokens.push(host);
23598
23651
  }
23599
23652
 
23600
- if (typeof components.port === 'number' || typeof components.port === 'string') {
23653
+ if (typeof component.port === 'number' || typeof component.port === 'string') {
23601
23654
  uriTokens.push(':');
23602
- uriTokens.push(String(components.port));
23655
+ uriTokens.push(String(component.port));
23603
23656
  }
23604
23657
 
23605
23658
  return uriTokens.length ? uriTokens.join('') : undefined
23606
23659
  }
23607
23660
  utils = {
23661
+ nonSimpleDomain,
23608
23662
  recomposeAuthority,
23609
23663
  normalizeComponentEncoding,
23610
23664
  removeDotSegments,
23611
- normalizeIPv4,
23665
+ isIPv4,
23666
+ isUUID,
23612
23667
  normalizeIPv6,
23613
23668
  stringArrayToHexStripped
23614
23669
  };
@@ -23622,192 +23677,271 @@ function requireSchemes () {
23622
23677
  if (hasRequiredSchemes) return schemes;
23623
23678
  hasRequiredSchemes = 1;
23624
23679
 
23625
- const UUID_REG = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
23680
+ const { isUUID } = requireUtils();
23626
23681
  const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
23627
23682
 
23628
- function isSecure (wsComponents) {
23629
- return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === 'wss'
23683
+ const supportedSchemeNames = /** @type {const} */ (['http', 'https', 'ws',
23684
+ 'wss', 'urn', 'urn:uuid']);
23685
+
23686
+ /** @typedef {supportedSchemeNames[number]} SchemeName */
23687
+
23688
+ /**
23689
+ * @param {string} name
23690
+ * @returns {name is SchemeName}
23691
+ */
23692
+ function isValidSchemeName (name) {
23693
+ return supportedSchemeNames.indexOf(/** @type {*} */ (name)) !== -1
23630
23694
  }
23631
23695
 
23632
- function httpParse (components) {
23633
- if (!components.host) {
23634
- components.error = components.error || 'HTTP URIs must have a host.';
23696
+ /**
23697
+ * @callback SchemeFn
23698
+ * @param {import('../types/index').URIComponent} component
23699
+ * @param {import('../types/index').Options} options
23700
+ * @returns {import('../types/index').URIComponent}
23701
+ */
23702
+
23703
+ /**
23704
+ * @typedef {Object} SchemeHandler
23705
+ * @property {SchemeName} scheme - The scheme name.
23706
+ * @property {boolean} [domainHost] - Indicates if the scheme supports domain hosts.
23707
+ * @property {SchemeFn} parse - Function to parse the URI component for this scheme.
23708
+ * @property {SchemeFn} serialize - Function to serialize the URI component for this scheme.
23709
+ * @property {boolean} [skipNormalize] - Indicates if normalization should be skipped for this scheme.
23710
+ * @property {boolean} [absolutePath] - Indicates if the scheme uses absolute paths.
23711
+ * @property {boolean} [unicodeSupport] - Indicates if the scheme supports Unicode.
23712
+ */
23713
+
23714
+ /**
23715
+ * @param {import('../types/index').URIComponent} wsComponent
23716
+ * @returns {boolean}
23717
+ */
23718
+ function wsIsSecure (wsComponent) {
23719
+ if (wsComponent.secure === true) {
23720
+ return true
23721
+ } else if (wsComponent.secure === false) {
23722
+ return false
23723
+ } else if (wsComponent.scheme) {
23724
+ return (
23725
+ wsComponent.scheme.length === 3 &&
23726
+ (wsComponent.scheme[0] === 'w' || wsComponent.scheme[0] === 'W') &&
23727
+ (wsComponent.scheme[1] === 's' || wsComponent.scheme[1] === 'S') &&
23728
+ (wsComponent.scheme[2] === 's' || wsComponent.scheme[2] === 'S')
23729
+ )
23730
+ } else {
23731
+ return false
23635
23732
  }
23733
+ }
23636
23734
 
23637
- return components
23735
+ /** @type {SchemeFn} */
23736
+ function httpParse (component) {
23737
+ if (!component.host) {
23738
+ component.error = component.error || 'HTTP URIs must have a host.';
23739
+ }
23740
+
23741
+ return component
23638
23742
  }
23639
23743
 
23640
- function httpSerialize (components) {
23641
- const secure = String(components.scheme).toLowerCase() === 'https';
23744
+ /** @type {SchemeFn} */
23745
+ function httpSerialize (component) {
23746
+ const secure = String(component.scheme).toLowerCase() === 'https';
23642
23747
 
23643
23748
  // normalize the default port
23644
- if (components.port === (secure ? 443 : 80) || components.port === '') {
23645
- components.port = undefined;
23749
+ if (component.port === (secure ? 443 : 80) || component.port === '') {
23750
+ component.port = undefined;
23646
23751
  }
23647
23752
 
23648
23753
  // normalize the empty path
23649
- if (!components.path) {
23650
- components.path = '/';
23754
+ if (!component.path) {
23755
+ component.path = '/';
23651
23756
  }
23652
23757
 
23653
23758
  // NOTE: We do not parse query strings for HTTP URIs
23654
23759
  // as WWW Form Url Encoded query strings are part of the HTML4+ spec,
23655
23760
  // and not the HTTP spec.
23656
23761
 
23657
- return components
23762
+ return component
23658
23763
  }
23659
23764
 
23660
- function wsParse (wsComponents) {
23765
+ /** @type {SchemeFn} */
23766
+ function wsParse (wsComponent) {
23661
23767
  // indicate if the secure flag is set
23662
- wsComponents.secure = isSecure(wsComponents);
23768
+ wsComponent.secure = wsIsSecure(wsComponent);
23663
23769
 
23664
23770
  // construct resouce name
23665
- wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
23666
- wsComponents.path = undefined;
23667
- wsComponents.query = undefined;
23771
+ wsComponent.resourceName = (wsComponent.path || '/') + (wsComponent.query ? '?' + wsComponent.query : '');
23772
+ wsComponent.path = undefined;
23773
+ wsComponent.query = undefined;
23668
23774
 
23669
- return wsComponents
23775
+ return wsComponent
23670
23776
  }
23671
23777
 
23672
- function wsSerialize (wsComponents) {
23778
+ /** @type {SchemeFn} */
23779
+ function wsSerialize (wsComponent) {
23673
23780
  // normalize the default port
23674
- if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === '') {
23675
- wsComponents.port = undefined;
23781
+ if (wsComponent.port === (wsIsSecure(wsComponent) ? 443 : 80) || wsComponent.port === '') {
23782
+ wsComponent.port = undefined;
23676
23783
  }
23677
23784
 
23678
23785
  // ensure scheme matches secure flag
23679
- if (typeof wsComponents.secure === 'boolean') {
23680
- wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws');
23681
- wsComponents.secure = undefined;
23786
+ if (typeof wsComponent.secure === 'boolean') {
23787
+ wsComponent.scheme = (wsComponent.secure ? 'wss' : 'ws');
23788
+ wsComponent.secure = undefined;
23682
23789
  }
23683
23790
 
23684
23791
  // reconstruct path from resource name
23685
- if (wsComponents.resourceName) {
23686
- const [path, query] = wsComponents.resourceName.split('?');
23687
- wsComponents.path = (path && path !== '/' ? path : undefined);
23688
- wsComponents.query = query;
23689
- wsComponents.resourceName = undefined;
23792
+ if (wsComponent.resourceName) {
23793
+ const [path, query] = wsComponent.resourceName.split('?');
23794
+ wsComponent.path = (path && path !== '/' ? path : undefined);
23795
+ wsComponent.query = query;
23796
+ wsComponent.resourceName = undefined;
23690
23797
  }
23691
23798
 
23692
23799
  // forbid fragment component
23693
- wsComponents.fragment = undefined;
23800
+ wsComponent.fragment = undefined;
23694
23801
 
23695
- return wsComponents
23802
+ return wsComponent
23696
23803
  }
23697
23804
 
23698
- function urnParse (urnComponents, options) {
23699
- if (!urnComponents.path) {
23700
- urnComponents.error = 'URN can not be parsed';
23701
- return urnComponents
23805
+ /** @type {SchemeFn} */
23806
+ function urnParse (urnComponent, options) {
23807
+ if (!urnComponent.path) {
23808
+ urnComponent.error = 'URN can not be parsed';
23809
+ return urnComponent
23702
23810
  }
23703
- const matches = urnComponents.path.match(URN_REG);
23811
+ const matches = urnComponent.path.match(URN_REG);
23704
23812
  if (matches) {
23705
- const scheme = options.scheme || urnComponents.scheme || 'urn';
23706
- urnComponents.nid = matches[1].toLowerCase();
23707
- urnComponents.nss = matches[2];
23708
- const urnScheme = `${scheme}:${options.nid || urnComponents.nid}`;
23709
- const schemeHandler = SCHEMES[urnScheme];
23710
- urnComponents.path = undefined;
23813
+ const scheme = options.scheme || urnComponent.scheme || 'urn';
23814
+ urnComponent.nid = matches[1].toLowerCase();
23815
+ urnComponent.nss = matches[2];
23816
+ const urnScheme = `${scheme}:${options.nid || urnComponent.nid}`;
23817
+ const schemeHandler = getSchemeHandler(urnScheme);
23818
+ urnComponent.path = undefined;
23711
23819
 
23712
23820
  if (schemeHandler) {
23713
- urnComponents = schemeHandler.parse(urnComponents, options);
23821
+ urnComponent = schemeHandler.parse(urnComponent, options);
23714
23822
  }
23715
23823
  } else {
23716
- urnComponents.error = urnComponents.error || 'URN can not be parsed.';
23824
+ urnComponent.error = urnComponent.error || 'URN can not be parsed.';
23717
23825
  }
23718
23826
 
23719
- return urnComponents
23827
+ return urnComponent
23720
23828
  }
23721
23829
 
23722
- function urnSerialize (urnComponents, options) {
23723
- const scheme = options.scheme || urnComponents.scheme || 'urn';
23724
- const nid = urnComponents.nid.toLowerCase();
23830
+ /** @type {SchemeFn} */
23831
+ function urnSerialize (urnComponent, options) {
23832
+ if (urnComponent.nid === undefined) {
23833
+ throw new Error('URN without nid cannot be serialized')
23834
+ }
23835
+ const scheme = options.scheme || urnComponent.scheme || 'urn';
23836
+ const nid = urnComponent.nid.toLowerCase();
23725
23837
  const urnScheme = `${scheme}:${options.nid || nid}`;
23726
- const schemeHandler = SCHEMES[urnScheme];
23838
+ const schemeHandler = getSchemeHandler(urnScheme);
23727
23839
 
23728
23840
  if (schemeHandler) {
23729
- urnComponents = schemeHandler.serialize(urnComponents, options);
23841
+ urnComponent = schemeHandler.serialize(urnComponent, options);
23730
23842
  }
23731
23843
 
23732
- const uriComponents = urnComponents;
23733
- const nss = urnComponents.nss;
23734
- uriComponents.path = `${nid || options.nid}:${nss}`;
23844
+ const uriComponent = urnComponent;
23845
+ const nss = urnComponent.nss;
23846
+ uriComponent.path = `${nid || options.nid}:${nss}`;
23735
23847
 
23736
23848
  options.skipEscape = true;
23737
- return uriComponents
23849
+ return uriComponent
23738
23850
  }
23739
23851
 
23740
- function urnuuidParse (urnComponents, options) {
23741
- const uuidComponents = urnComponents;
23742
- uuidComponents.uuid = uuidComponents.nss;
23743
- uuidComponents.nss = undefined;
23852
+ /** @type {SchemeFn} */
23853
+ function urnuuidParse (urnComponent, options) {
23854
+ const uuidComponent = urnComponent;
23855
+ uuidComponent.uuid = uuidComponent.nss;
23856
+ uuidComponent.nss = undefined;
23744
23857
 
23745
- if (!options.tolerant && (!uuidComponents.uuid || !UUID_REG.test(uuidComponents.uuid))) {
23746
- uuidComponents.error = uuidComponents.error || 'UUID is not valid.';
23858
+ if (!options.tolerant && (!uuidComponent.uuid || !isUUID(uuidComponent.uuid))) {
23859
+ uuidComponent.error = uuidComponent.error || 'UUID is not valid.';
23747
23860
  }
23748
23861
 
23749
- return uuidComponents
23862
+ return uuidComponent
23750
23863
  }
23751
23864
 
23752
- function urnuuidSerialize (uuidComponents) {
23753
- const urnComponents = uuidComponents;
23865
+ /** @type {SchemeFn} */
23866
+ function urnuuidSerialize (uuidComponent) {
23867
+ const urnComponent = uuidComponent;
23754
23868
  // normalize UUID
23755
- urnComponents.nss = (uuidComponents.uuid || '').toLowerCase();
23756
- return urnComponents
23869
+ urnComponent.nss = (uuidComponent.uuid || '').toLowerCase();
23870
+ return urnComponent
23757
23871
  }
23758
23872
 
23759
- const http = {
23873
+ const http = /** @type {SchemeHandler} */ ({
23760
23874
  scheme: 'http',
23761
23875
  domainHost: true,
23762
23876
  parse: httpParse,
23763
23877
  serialize: httpSerialize
23764
- };
23878
+ });
23765
23879
 
23766
- const https = {
23880
+ const https = /** @type {SchemeHandler} */ ({
23767
23881
  scheme: 'https',
23768
23882
  domainHost: http.domainHost,
23769
23883
  parse: httpParse,
23770
23884
  serialize: httpSerialize
23771
- };
23885
+ });
23772
23886
 
23773
- const ws = {
23887
+ const ws = /** @type {SchemeHandler} */ ({
23774
23888
  scheme: 'ws',
23775
23889
  domainHost: true,
23776
23890
  parse: wsParse,
23777
23891
  serialize: wsSerialize
23778
- };
23892
+ });
23779
23893
 
23780
- const wss = {
23894
+ const wss = /** @type {SchemeHandler} */ ({
23781
23895
  scheme: 'wss',
23782
23896
  domainHost: ws.domainHost,
23783
23897
  parse: ws.parse,
23784
23898
  serialize: ws.serialize
23785
- };
23899
+ });
23786
23900
 
23787
- const urn = {
23901
+ const urn = /** @type {SchemeHandler} */ ({
23788
23902
  scheme: 'urn',
23789
23903
  parse: urnParse,
23790
23904
  serialize: urnSerialize,
23791
23905
  skipNormalize: true
23792
- };
23906
+ });
23793
23907
 
23794
- const urnuuid = {
23908
+ const urnuuid = /** @type {SchemeHandler} */ ({
23795
23909
  scheme: 'urn:uuid',
23796
23910
  parse: urnuuidParse,
23797
23911
  serialize: urnuuidSerialize,
23798
23912
  skipNormalize: true
23799
- };
23913
+ });
23800
23914
 
23801
- const SCHEMES = {
23915
+ const SCHEMES = /** @type {Record<SchemeName, SchemeHandler>} */ ({
23802
23916
  http,
23803
23917
  https,
23804
23918
  ws,
23805
23919
  wss,
23806
23920
  urn,
23807
23921
  'urn:uuid': urnuuid
23808
- };
23922
+ });
23923
+
23924
+ Object.setPrototypeOf(SCHEMES, null);
23925
+
23926
+ /**
23927
+ * @param {string|undefined} scheme
23928
+ * @returns {SchemeHandler|undefined}
23929
+ */
23930
+ function getSchemeHandler (scheme) {
23931
+ return (
23932
+ scheme && (
23933
+ SCHEMES[/** @type {SchemeName} */ (scheme)] ||
23934
+ SCHEMES[/** @type {SchemeName} */(scheme.toLowerCase())])
23935
+ ) ||
23936
+ undefined
23937
+ }
23809
23938
 
23810
- schemes = SCHEMES;
23939
+ schemes = {
23940
+ wsIsSecure,
23941
+ SCHEMES,
23942
+ isValidSchemeName,
23943
+ getSchemeHandler,
23944
+ };
23811
23945
  return schemes;
23812
23946
  }
23813
23947
 
@@ -23817,29 +23951,50 @@ function requireFastUri () {
23817
23951
  if (hasRequiredFastUri) return fastUri.exports;
23818
23952
  hasRequiredFastUri = 1;
23819
23953
 
23820
- const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = requireUtils();
23821
- const SCHEMES = requireSchemes();
23954
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = requireUtils();
23955
+ const { SCHEMES, getSchemeHandler } = requireSchemes();
23822
23956
 
23957
+ /**
23958
+ * @template {import('./types/index').URIComponent|string} T
23959
+ * @param {T} uri
23960
+ * @param {import('./types/index').Options} [options]
23961
+ * @returns {T}
23962
+ */
23823
23963
  function normalize (uri, options) {
23824
23964
  if (typeof uri === 'string') {
23825
- uri = serialize(parse(uri, options), options);
23965
+ uri = /** @type {T} */ (serialize(parse(uri, options), options));
23826
23966
  } else if (typeof uri === 'object') {
23827
- uri = parse(serialize(uri, options), options);
23967
+ uri = /** @type {T} */ (parse(serialize(uri, options), options));
23828
23968
  }
23829
23969
  return uri
23830
23970
  }
23831
23971
 
23972
+ /**
23973
+ * @param {string} baseURI
23974
+ * @param {string} relativeURI
23975
+ * @param {import('./types/index').Options} [options]
23976
+ * @returns {string}
23977
+ */
23832
23978
  function resolve (baseURI, relativeURI, options) {
23833
- const schemelessOptions = Object.assign({ scheme: 'null' }, options);
23834
- const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
23835
- return serialize(resolved, { ...schemelessOptions, skipEscape: true })
23979
+ const schemelessOptions = options ? Object.assign({ scheme: 'null' }, options) : { scheme: 'null' };
23980
+ const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true);
23981
+ schemelessOptions.skipEscape = true;
23982
+ return serialize(resolved, schemelessOptions)
23836
23983
  }
23837
23984
 
23838
- function resolveComponents (base, relative, options, skipNormalization) {
23985
+ /**
23986
+ * @param {import ('./types/index').URIComponent} base
23987
+ * @param {import ('./types/index').URIComponent} relative
23988
+ * @param {import('./types/index').Options} [options]
23989
+ * @param {boolean} [skipNormalization=false]
23990
+ * @returns {import ('./types/index').URIComponent}
23991
+ */
23992
+ function resolveComponent (base, relative, options, skipNormalization) {
23993
+ /** @type {import('./types/index').URIComponent} */
23839
23994
  const target = {};
23840
23995
  if (!skipNormalization) {
23841
- base = parse(serialize(base, options), options); // normalize base components
23842
- relative = parse(serialize(relative, options), options); // normalize relative components
23996
+ base = parse(serialize(base, options), options); // normalize base component
23997
+ relative = parse(serialize(relative, options), options); // normalize relative component
23843
23998
  }
23844
23999
  options = options || {};
23845
24000
 
@@ -23868,7 +24023,7 @@ function requireFastUri () {
23868
24023
  target.query = base.query;
23869
24024
  }
23870
24025
  } else {
23871
- if (relative.path.charAt(0) === '/') {
24026
+ if (relative.path[0] === '/') {
23872
24027
  target.path = removeDotSegments(relative.path);
23873
24028
  } else {
23874
24029
  if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
@@ -23895,6 +24050,12 @@ function requireFastUri () {
23895
24050
  return target
23896
24051
  }
23897
24052
 
24053
+ /**
24054
+ * @param {import ('./types/index').URIComponent|string} uriA
24055
+ * @param {import ('./types/index').URIComponent|string} uriB
24056
+ * @param {import ('./types/index').Options} options
24057
+ * @returns {boolean}
24058
+ */
23898
24059
  function equal (uriA, uriB, options) {
23899
24060
  if (typeof uriA === 'string') {
23900
24061
  uriA = unescape(uriA);
@@ -23913,8 +24074,13 @@ function requireFastUri () {
23913
24074
  return uriA.toLowerCase() === uriB.toLowerCase()
23914
24075
  }
23915
24076
 
24077
+ /**
24078
+ * @param {Readonly<import('./types/index').URIComponent>} cmpts
24079
+ * @param {import('./types/index').Options} [opts]
24080
+ * @returns {string}
24081
+ */
23916
24082
  function serialize (cmpts, opts) {
23917
- const components = {
24083
+ const component = {
23918
24084
  host: cmpts.host,
23919
24085
  scheme: cmpts.scheme,
23920
24086
  userinfo: cmpts.userinfo,
@@ -23934,28 +24100,28 @@ function requireFastUri () {
23934
24100
  const uriTokens = [];
23935
24101
 
23936
24102
  // find scheme handler
23937
- const schemeHandler = SCHEMES[(options.scheme || components.scheme || '').toLowerCase()];
24103
+ const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
23938
24104
 
23939
24105
  // perform scheme specific serialization
23940
- if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
24106
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
23941
24107
 
23942
- if (components.path !== undefined) {
24108
+ if (component.path !== undefined) {
23943
24109
  if (!options.skipEscape) {
23944
- components.path = escape(components.path);
24110
+ component.path = escape(component.path);
23945
24111
 
23946
- if (components.scheme !== undefined) {
23947
- components.path = components.path.split('%3A').join(':');
24112
+ if (component.scheme !== undefined) {
24113
+ component.path = component.path.split('%3A').join(':');
23948
24114
  }
23949
24115
  } else {
23950
- components.path = unescape(components.path);
24116
+ component.path = unescape(component.path);
23951
24117
  }
23952
24118
  }
23953
24119
 
23954
- if (options.reference !== 'suffix' && components.scheme) {
23955
- uriTokens.push(components.scheme, ':');
24120
+ if (options.reference !== 'suffix' && component.scheme) {
24121
+ uriTokens.push(component.scheme, ':');
23956
24122
  }
23957
24123
 
23958
- const authority = recomposeAuthority(components);
24124
+ const authority = recomposeAuthority(component);
23959
24125
  if (authority !== undefined) {
23960
24126
  if (options.reference !== 'suffix') {
23961
24127
  uriTokens.push('//');
@@ -23963,51 +24129,49 @@ function requireFastUri () {
23963
24129
 
23964
24130
  uriTokens.push(authority);
23965
24131
 
23966
- if (components.path && components.path.charAt(0) !== '/') {
24132
+ if (component.path && component.path[0] !== '/') {
23967
24133
  uriTokens.push('/');
23968
24134
  }
23969
24135
  }
23970
- if (components.path !== undefined) {
23971
- let s = components.path;
24136
+ if (component.path !== undefined) {
24137
+ let s = component.path;
23972
24138
 
23973
24139
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
23974
24140
  s = removeDotSegments(s);
23975
24141
  }
23976
24142
 
23977
- if (authority === undefined) {
23978
- s = s.replace(/^\/\//u, '/%2F'); // don't allow the path to start with "//"
24143
+ if (
24144
+ authority === undefined &&
24145
+ s[0] === '/' &&
24146
+ s[1] === '/'
24147
+ ) {
24148
+ // don't allow the path to start with "//"
24149
+ s = '/%2F' + s.slice(2);
23979
24150
  }
23980
24151
 
23981
24152
  uriTokens.push(s);
23982
24153
  }
23983
24154
 
23984
- if (components.query !== undefined) {
23985
- uriTokens.push('?', components.query);
24155
+ if (component.query !== undefined) {
24156
+ uriTokens.push('?', component.query);
23986
24157
  }
23987
24158
 
23988
- if (components.fragment !== undefined) {
23989
- uriTokens.push('#', components.fragment);
24159
+ if (component.fragment !== undefined) {
24160
+ uriTokens.push('#', component.fragment);
23990
24161
  }
23991
24162
  return uriTokens.join('')
23992
24163
  }
23993
24164
 
23994
- const hexLookUp = Array.from({ length: 127 }, (_v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)));
23995
-
23996
- function nonSimpleDomain (value) {
23997
- let code = 0;
23998
- for (let i = 0, len = value.length; i < len; ++i) {
23999
- code = value.charCodeAt(i);
24000
- if (code > 126 || hexLookUp[code]) {
24001
- return true
24002
- }
24003
- }
24004
- return false
24005
- }
24006
-
24007
24165
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
24008
24166
 
24167
+ /**
24168
+ * @param {string} uri
24169
+ * @param {import('./types/index').Options} [opts]
24170
+ * @returns
24171
+ */
24009
24172
  function parse (uri, opts) {
24010
24173
  const options = Object.assign({}, opts);
24174
+ /** @type {import('./types/index').URIComponent} */
24011
24175
  const parsed = {
24012
24176
  scheme: undefined,
24013
24177
  userinfo: undefined,
@@ -24017,9 +24181,15 @@ function requireFastUri () {
24017
24181
  query: undefined,
24018
24182
  fragment: undefined
24019
24183
  };
24020
- const gotEncoding = uri.indexOf('%') !== -1;
24184
+
24021
24185
  let isIP = false;
24022
- if (options.reference === 'suffix') uri = (options.scheme ? options.scheme + ':' : '') + '//' + uri;
24186
+ if (options.reference === 'suffix') {
24187
+ if (options.scheme) {
24188
+ uri = options.scheme + ':' + uri;
24189
+ } else {
24190
+ uri = '//' + uri;
24191
+ }
24192
+ }
24023
24193
 
24024
24194
  const matches = uri.match(URI_PARSE);
24025
24195
 
@@ -24038,13 +24208,12 @@ function requireFastUri () {
24038
24208
  parsed.port = matches[5];
24039
24209
  }
24040
24210
  if (parsed.host) {
24041
- const ipv4result = normalizeIPv4(parsed.host);
24042
- if (ipv4result.isIPV4 === false) {
24043
- const ipv6result = normalizeIPv6(ipv4result.host);
24211
+ const ipv4result = isIPv4(parsed.host);
24212
+ if (ipv4result === false) {
24213
+ const ipv6result = normalizeIPv6(parsed.host);
24044
24214
  parsed.host = ipv6result.host.toLowerCase();
24045
24215
  isIP = ipv6result.isIPV6;
24046
24216
  } else {
24047
- parsed.host = ipv4result.host;
24048
24217
  isIP = true;
24049
24218
  }
24050
24219
  }
@@ -24064,7 +24233,7 @@ function requireFastUri () {
24064
24233
  }
24065
24234
 
24066
24235
  // find scheme handler
24067
- const schemeHandler = SCHEMES[(options.scheme || parsed.scheme || '').toLowerCase()];
24236
+ const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
24068
24237
 
24069
24238
  // check if scheme can't handle IRIs
24070
24239
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
@@ -24081,11 +24250,13 @@ function requireFastUri () {
24081
24250
  }
24082
24251
 
24083
24252
  if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
24084
- if (gotEncoding && parsed.scheme !== undefined) {
24085
- parsed.scheme = unescape(parsed.scheme);
24086
- }
24087
- if (gotEncoding && parsed.host !== undefined) {
24088
- parsed.host = unescape(parsed.host);
24253
+ if (uri.indexOf('%') !== -1) {
24254
+ if (parsed.scheme !== undefined) {
24255
+ parsed.scheme = unescape(parsed.scheme);
24256
+ }
24257
+ if (parsed.host !== undefined) {
24258
+ parsed.host = unescape(parsed.host);
24259
+ }
24089
24260
  }
24090
24261
  if (parsed.path) {
24091
24262
  parsed.path = escape(unescape(parsed.path));
@@ -24109,7 +24280,7 @@ function requireFastUri () {
24109
24280
  SCHEMES,
24110
24281
  normalize,
24111
24282
  resolve,
24112
- resolveComponents,
24283
+ resolveComponent,
24113
24284
  equal,
24114
24285
  serialize,
24115
24286
  parse
@@ -32057,7 +32228,7 @@ class Comparator {
32057
32228
  }
32058
32229
  }
32059
32230
 
32060
- var version = "1.6.0";
32231
+ var version = "1.6.1";
32061
32232
  var packageJson = {
32062
32233
  version: version};
32063
32234