@zimic/interceptor 0.17.0 → 0.17.1-canary.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/http.mjs CHANGED
@@ -142,11 +142,11 @@ var DisabledRequestSavingError = class extends TypeError {
142
142
  };
143
143
  var DisabledRequestSavingError_default = DisabledRequestSavingError;
144
144
 
145
- // ../zimic-utils/dist/chunk-PAWJFY3S.mjs
145
+ // ../zimic-utils/dist/chunk-6IEM75FG.mjs
146
146
  var __defProp2 = Object.defineProperty;
147
147
  var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
148
148
 
149
- // ../zimic-utils/dist/chunk-3O5CS47X.mjs
149
+ // ../zimic-utils/dist/chunk-INCJAGFR.mjs
150
150
  function isDefined(value) {
151
151
  return value !== void 0 && value !== null;
152
152
  }
@@ -423,28 +423,64 @@ var TimesCheckError = class extends TypeError {
423
423
  };
424
424
  var TimesCheckError_default = TimesCheckError;
425
425
 
426
- // ../zimic-utils/dist/data/blobContains.mjs
427
- async function blobContains(blob, otherBlob) {
428
- return blob.type === otherBlob.type && blob.size >= otherBlob.size && (await blob.text()).includes(await otherBlob.text());
429
- }
430
- __name(blobContains, "blobContains");
431
- __name2(blobContains, "blobContains");
432
- var blobContains_default = blobContains;
433
-
434
- // ../zimic-utils/dist/chunk-HVLEF6VF.mjs
426
+ // ../zimic-utils/dist/chunk-HBO3G76H.mjs
435
427
  async function blobEquals(blob, otherBlob) {
436
- return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
428
+ if (blob.type !== otherBlob.type || blob.size !== otherBlob.size) {
429
+ return false;
430
+ }
431
+ const reader = blob.stream().getReader();
432
+ const otherReader = otherBlob.stream().getReader();
433
+ let buffer = new Uint8Array(0);
434
+ let otherBuffer = new Uint8Array(0);
435
+ try {
436
+ while (true) {
437
+ await Promise.all([
438
+ buffer.length === 0 && reader.read().then((result) => {
439
+ if (!result.done) {
440
+ buffer = result.value;
441
+ }
442
+ }),
443
+ otherBuffer.length === 0 && otherReader.read().then((result) => {
444
+ if (!result.done) {
445
+ otherBuffer = result.value;
446
+ }
447
+ })
448
+ ]);
449
+ const streamsEndedTogether = buffer.length === 0 && otherBuffer.length === 0;
450
+ if (streamsEndedTogether) {
451
+ return true;
452
+ }
453
+ const oneStreamEndedBeforeTheOther = buffer.length === 0 && otherBuffer.length > 0 || buffer.length > 0 && otherBuffer.length === 0;
454
+ if (oneStreamEndedBeforeTheOther) {
455
+ return false;
456
+ }
457
+ const minimumByteLength = Math.min(buffer.length, otherBuffer.length);
458
+ for (let byteIndex = 0; byteIndex < minimumByteLength; byteIndex++) {
459
+ if (buffer[byteIndex] !== otherBuffer[byteIndex]) {
460
+ return false;
461
+ }
462
+ }
463
+ buffer = buffer.slice(minimumByteLength);
464
+ otherBuffer = otherBuffer.slice(minimumByteLength);
465
+ }
466
+ } finally {
467
+ reader.releaseLock();
468
+ otherReader.releaseLock();
469
+ }
437
470
  }
438
471
  __name(blobEquals, "blobEquals");
439
472
  __name2(blobEquals, "blobEquals");
440
473
  var blobEquals_default = blobEquals;
441
474
 
442
- // src/utils/json.ts
475
+ // ../zimic-utils/dist/chunk-C76RTUXI.mjs
443
476
  function isPrimitiveJSONValue(value) {
444
477
  return typeof value !== "object" || value === null;
445
478
  }
446
479
  __name(isPrimitiveJSONValue, "isPrimitiveJSONValue");
447
- function jsonEquals(value, otherValue) {
480
+ __name2(isPrimitiveJSONValue, "isPrimitiveJSONValue");
481
+
482
+ // ../zimic-utils/dist/data/jsonContains.mjs
483
+ function jsonContains(value, otherValue) {
448
484
  if (isPrimitiveJSONValue(value)) {
449
485
  return value === otherValue;
450
486
  }
@@ -455,27 +491,40 @@ function jsonEquals(value, otherValue) {
455
491
  if (!Array.isArray(otherValue)) {
456
492
  return false;
457
493
  }
458
- if (value.length !== otherValue.length) {
494
+ if (value.length < otherValue.length) {
459
495
  return false;
460
496
  }
461
- return value.every((item, index) => jsonEquals(item, otherValue[index]));
497
+ let lastMatchedIndex = -1;
498
+ return otherValue.every((otherItem) => {
499
+ for (let index = lastMatchedIndex + 1; index < value.length; index++) {
500
+ if (jsonContains(value[index], otherItem)) {
501
+ lastMatchedIndex = index;
502
+ return true;
503
+ }
504
+ }
505
+ return false;
506
+ });
462
507
  }
463
508
  if (Array.isArray(otherValue)) {
464
509
  return false;
465
510
  }
466
511
  const valueKeys = Object.keys(value);
467
512
  const otherValueKeys = Object.keys(otherValue);
468
- if (valueKeys.length !== otherValueKeys.length) {
513
+ if (valueKeys.length < otherValueKeys.length) {
469
514
  return false;
470
515
  }
471
- return valueKeys.every((key) => {
516
+ return otherValueKeys.every((key) => {
472
517
  const subValue = value[key];
473
518
  const subOtherValue = otherValue[key];
474
- return jsonEquals(subValue, subOtherValue);
519
+ return jsonContains(subValue, subOtherValue);
475
520
  });
476
521
  }
477
- __name(jsonEquals, "jsonEquals");
478
- function jsonContains(value, otherValue) {
522
+ __name(jsonContains, "jsonContains");
523
+ __name2(jsonContains, "jsonContains");
524
+ var jsonContains_default = jsonContains;
525
+
526
+ // ../zimic-utils/dist/data/jsonEquals.mjs
527
+ function jsonEquals(value, otherValue) {
479
528
  if (isPrimitiveJSONValue(value)) {
480
529
  return value === otherValue;
481
530
  }
@@ -486,35 +535,28 @@ function jsonContains(value, otherValue) {
486
535
  if (!Array.isArray(otherValue)) {
487
536
  return false;
488
537
  }
489
- if (value.length < otherValue.length) {
538
+ if (value.length !== otherValue.length) {
490
539
  return false;
491
540
  }
492
- let lastMatchedIndex = -1;
493
- return otherValue.every((otherItem) => {
494
- for (let index = lastMatchedIndex + 1; index < value.length; index++) {
495
- if (jsonContains(value[index], otherItem)) {
496
- lastMatchedIndex = index;
497
- return true;
498
- }
499
- }
500
- return false;
501
- });
541
+ return value.every((item, index) => jsonEquals(item, otherValue[index]));
502
542
  }
503
543
  if (Array.isArray(otherValue)) {
504
544
  return false;
505
545
  }
506
546
  const valueKeys = Object.keys(value);
507
547
  const otherValueKeys = Object.keys(otherValue);
508
- if (valueKeys.length < otherValueKeys.length) {
548
+ if (valueKeys.length !== otherValueKeys.length) {
509
549
  return false;
510
550
  }
511
- return otherValueKeys.every((key) => {
551
+ return valueKeys.every((key) => {
512
552
  const subValue = value[key];
513
553
  const subOtherValue = otherValue[key];
514
- return jsonContains(subValue, subOtherValue);
554
+ return jsonEquals(subValue, subOtherValue);
515
555
  });
516
556
  }
517
- __name(jsonContains, "jsonContains");
557
+ __name(jsonEquals, "jsonEquals");
558
+ __name2(jsonEquals, "jsonEquals");
559
+ var jsonEquals_default = jsonEquals;
518
560
 
519
561
  // src/http/requestHandler/errors/NoResponseDefinitionError.ts
520
562
  var NoResponseDefinitionError = class extends TypeError {
@@ -731,13 +773,13 @@ var HttpRequestHandlerClient = class {
731
773
  diff: { expected: restrictionBody, received: body }
732
774
  };
733
775
  }
734
- const matchesRestriction2 = restriction.exact ? await blobEquals_default(body, restrictionBody) : await blobContains_default(body, restrictionBody);
776
+ const matchesRestriction2 = await blobEquals_default(body, restrictionBody);
735
777
  return matchesRestriction2 ? { value: true } : {
736
778
  value: false,
737
779
  diff: { expected: restrictionBody, received: body }
738
780
  };
739
781
  }
740
- const matchesRestriction = restriction.exact ? jsonEquals(request.body, restriction.body) : jsonContains(request.body, restriction.body);
782
+ const matchesRestriction = restriction.exact ? jsonEquals_default(request.body, restriction.body) : jsonContains_default(request.body, restriction.body);
741
783
  return matchesRestriction ? { value: true } : {
742
784
  value: false,
743
785
  diff: { expected: restrictionBody, received: body }
@@ -832,7 +874,7 @@ var LocalHttpRequestHandler = class {
832
874
  };
833
875
  var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
834
876
 
835
- // ../zimic-utils/dist/chunk-RIVHLEFF.mjs
877
+ // ../zimic-utils/dist/chunk-PFX6YIKR.mjs
836
878
  var URL_PATH_PARAM_REGEX = /\/:([^/]+)/g;
837
879
  function createRegExpFromURL(url) {
838
880
  URL_PATH_PARAM_REGEX.lastIndex = 0;