@zimic/interceptor 0.14.0 → 0.15.0-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.
Files changed (43) hide show
  1. package/README.md +7 -8
  2. package/dist/{chunk-FEGMEAEO.mjs → chunk-3O3YPVEG.mjs} +69 -104
  3. package/dist/chunk-3O3YPVEG.mjs.map +1 -0
  4. package/dist/{chunk-3623PRKE.js → chunk-CWBDZYUG.js} +69 -104
  5. package/dist/chunk-CWBDZYUG.js.map +1 -0
  6. package/dist/cli.js +7 -7
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cli.mjs +3 -3
  9. package/dist/cli.mjs.map +1 -1
  10. package/dist/http.d.ts +47 -38
  11. package/dist/http.js +173 -235
  12. package/dist/http.js.map +1 -1
  13. package/dist/http.mjs +173 -235
  14. package/dist/http.mjs.map +1 -1
  15. package/dist/server.d.ts +15 -10
  16. package/dist/server.js +5 -5
  17. package/dist/server.mjs +1 -1
  18. package/package.json +3 -3
  19. package/src/cli/server/start.ts +1 -1
  20. package/src/http/index.ts +14 -1
  21. package/src/http/interceptor/HttpInterceptorClient.ts +23 -34
  22. package/src/http/interceptor/HttpInterceptorStore.ts +2 -2
  23. package/src/http/interceptor/LocalHttpInterceptor.ts +22 -25
  24. package/src/http/interceptor/RemoteHttpInterceptor.ts +22 -25
  25. package/src/http/interceptor/errors/NotStartedHttpInterceptorError.ts +1 -1
  26. package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
  27. package/src/http/interceptor/types/options.ts +3 -3
  28. package/src/http/interceptor/types/public.ts +12 -9
  29. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +10 -28
  30. package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +21 -25
  31. package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +22 -26
  32. package/src/http/requestHandler/HttpRequestHandlerClient.ts +13 -23
  33. package/src/http/requestHandler/LocalHttpRequestHandler.ts +17 -21
  34. package/src/http/requestHandler/RemoteHttpRequestHandler.ts +19 -29
  35. package/src/http/requestHandler/types/public.ts +23 -23
  36. package/src/http/requestHandler/types/requests.ts +1 -1
  37. package/src/server/InterceptorServer.ts +45 -68
  38. package/src/server/types/public.ts +15 -10
  39. package/src/webSocket/WebSocketClient.ts +1 -1
  40. package/src/webSocket/WebSocketHandler.ts +11 -19
  41. package/src/webSocket/WebSocketServer.ts +4 -4
  42. package/dist/chunk-3623PRKE.js.map +0 -1
  43. package/dist/chunk-FEGMEAEO.mjs.map +0 -1
package/dist/http.js CHANGED
@@ -427,10 +427,10 @@ var DEFAULT_NUMBER_OF_REQUEST_LIMITS = Object.freeze({
427
427
  max: Infinity
428
428
  });
429
429
  var HttpRequestHandlerClient = class {
430
- constructor(interceptor, _method, _path, handler) {
430
+ constructor(interceptor, method, path, handler) {
431
431
  this.interceptor = interceptor;
432
- this._method = _method;
433
- this._path = _path;
432
+ this.method = method;
433
+ this.path = path;
434
434
  this.handler = handler;
435
435
  }
436
436
  static {
@@ -443,14 +443,8 @@ var HttpRequestHandlerClient = class {
443
443
  timesDeclarationPointer;
444
444
  numberOfMatchedRequests = 0;
445
445
  unmatchedRequestGroups = [];
446
- interceptedRequests = [];
446
+ _requests = [];
447
447
  createResponseDeclaration;
448
- method() {
449
- return this._method;
450
- }
451
- path() {
452
- return this._path;
453
- }
454
448
  with(restriction) {
455
449
  this.restrictions.push(restriction);
456
450
  return this;
@@ -460,7 +454,7 @@ var HttpRequestHandlerClient = class {
460
454
  newThis.createResponseDeclaration = this.isResponseDeclarationFactory(declaration) ? declaration : () => declaration;
461
455
  newThis.numberOfMatchedRequests = 0;
462
456
  newThis.unmatchedRequestGroups.length = 0;
463
- newThis.interceptedRequests.length = 0;
457
+ newThis._requests.length = 0;
464
458
  this.interceptor.registerRequestHandler(this.handler);
465
459
  return newThis;
466
460
  }
@@ -484,7 +478,7 @@ var HttpRequestHandlerClient = class {
484
478
  declarationPointer: this.timesDeclarationPointer,
485
479
  unmatchedRequestGroups: this.unmatchedRequestGroups,
486
480
  hasRestrictions: this.restrictions.length > 0,
487
- hasSavedRequests: this.interceptor.shouldSaveRequests()
481
+ hasSavedRequests: this.interceptor.shouldSaveRequests
488
482
  });
489
483
  }
490
484
  }
@@ -496,7 +490,7 @@ var HttpRequestHandlerClient = class {
496
490
  this.timesDeclarationPointer = void 0;
497
491
  this.numberOfMatchedRequests = 0;
498
492
  this.unmatchedRequestGroups.length = 0;
499
- this.interceptedRequests.length = 0;
493
+ this._requests.length = 0;
500
494
  this.createResponseDeclaration = void 0;
501
495
  return this;
502
496
  }
@@ -509,7 +503,7 @@ var HttpRequestHandlerClient = class {
509
503
  if (restrictionsMatch.value) {
510
504
  this.numberOfMatchedRequests++;
511
505
  } else {
512
- const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests() && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
506
+ const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
513
507
  if (shouldSaveUnmatchedGroup) {
514
508
  this.unmatchedRequestGroups.push({ request, diff: restrictionsMatch.diff });
515
509
  }
@@ -642,7 +636,7 @@ var HttpRequestHandlerClient = class {
642
636
  }
643
637
  saveInterceptedRequest(request, response) {
644
638
  const interceptedRequest = this.createInterceptedRequest(request, response);
645
- this.interceptedRequests.push(interceptedRequest);
639
+ this._requests.push(interceptedRequest);
646
640
  }
647
641
  createInterceptedRequest(request, response) {
648
642
  const interceptedRequest = request;
@@ -654,13 +648,11 @@ var HttpRequestHandlerClient = class {
654
648
  });
655
649
  return interceptedRequest;
656
650
  }
657
- requests() {
658
- if (!this.interceptor.shouldSaveRequests()) {
651
+ get requests() {
652
+ if (!this.interceptor.shouldSaveRequests) {
659
653
  throw new DisabledRequestSavingError_default();
660
654
  }
661
- const interceptedRequestsCopy = [...this.interceptedRequests];
662
- Object.freeze(interceptedRequestsCopy);
663
- return interceptedRequestsCopy;
655
+ return this._requests;
664
656
  }
665
657
  };
666
658
  var HttpRequestHandlerClient_default = HttpRequestHandlerClient;
@@ -671,50 +663,47 @@ var LocalHttpRequestHandler = class {
671
663
  __name(this, "LocalHttpRequestHandler");
672
664
  }
673
665
  type = "local";
674
- _client;
666
+ client;
675
667
  constructor(interceptor, method, path) {
676
- this._client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
677
- }
678
- client() {
679
- return this._client;
668
+ this.client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
680
669
  }
681
- method() {
682
- return this._client.method();
670
+ get method() {
671
+ return this.client.method;
683
672
  }
684
- path() {
685
- return this._client.path();
673
+ get path() {
674
+ return this.client.path;
686
675
  }
687
676
  with(restriction) {
688
- this._client.with(restriction);
677
+ this.client.with(restriction);
689
678
  return this;
690
679
  }
691
680
  respond(declaration) {
692
- this._client.respond(declaration);
681
+ this.client.respond(declaration);
693
682
  const newThis = this;
694
683
  return newThis;
695
684
  }
696
685
  times(minNumberOfRequests, maxNumberOfRequests) {
697
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
686
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
698
687
  return this;
699
688
  }
700
689
  checkTimes() {
701
- this._client.checkTimes();
690
+ this.client.checkTimes();
702
691
  }
703
692
  clear() {
704
- this._client.clear();
693
+ this.client.clear();
705
694
  return this;
706
695
  }
707
- requests() {
708
- return this._client.requests();
696
+ get requests() {
697
+ return this.client.requests;
709
698
  }
710
699
  matchesRequest(request) {
711
- return this._client.matchesRequest(request);
700
+ return this.client.matchesRequest(request);
712
701
  }
713
702
  async applyResponseDeclaration(request) {
714
- return this._client.applyResponseDeclaration(request);
703
+ return this.client.applyResponseDeclaration(request);
715
704
  }
716
705
  saveInterceptedRequest(request, response) {
717
- this._client.saveInterceptedRequest(request, response);
706
+ this.client.saveInterceptedRequest(request, response);
718
707
  }
719
708
  };
720
709
  var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
@@ -850,26 +839,14 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
850
839
  static {
851
840
  __name(this, "HttpInterceptorWorker");
852
841
  }
853
- _platform = null;
854
- _isRunning = false;
842
+ platform = null;
843
+ isRunning = false;
855
844
  startingPromise;
856
845
  stoppingPromise;
857
846
  store = new HttpInterceptorWorkerStore_default();
858
847
  runningInterceptors = [];
859
- platform() {
860
- return this._platform;
861
- }
862
- setPlatform(platform) {
863
- this._platform = platform;
864
- }
865
- isRunning() {
866
- return this._isRunning;
867
- }
868
- setIsRunning(isRunning) {
869
- this._isRunning = isRunning;
870
- }
871
848
  async sharedStart(internalStart) {
872
- if (this.isRunning()) {
849
+ if (this.isRunning) {
873
850
  return;
874
851
  }
875
852
  if (this.startingPromise) {
@@ -888,7 +865,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
888
865
  }
889
866
  }
890
867
  async sharedStop(internalStop) {
891
- if (!this.isRunning()) {
868
+ if (!this.isRunning) {
892
869
  return;
893
870
  }
894
871
  if (this.stoppingPromise) {
@@ -953,8 +930,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
953
930
  }
954
931
  findInterceptorByRequestBaseURL(request) {
955
932
  const interceptor = this.runningInterceptors.findLast((interceptor2) => {
956
- const baseURL = interceptor2.baseURL();
957
- return request.url.startsWith(baseURL);
933
+ return request.url.startsWith(interceptor2.baseURLAsString);
958
934
  });
959
935
  return interceptor;
960
936
  }
@@ -970,12 +946,11 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
970
946
  return defaultStrategyOrFactory;
971
947
  }
972
948
  async getInterceptorUnhandledRequestStrategy(request, interceptor) {
973
- const interceptorStrategyOrFactory = interceptor.onUnhandledRequest();
974
- if (typeof interceptorStrategyOrFactory === "function") {
949
+ if (typeof interceptor.onUnhandledRequest === "function") {
975
950
  const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
976
- return interceptorStrategyOrFactory(parsedRequest);
951
+ return interceptor.onUnhandledRequest(parsedRequest);
977
952
  }
978
- return interceptorStrategyOrFactory;
953
+ return interceptor.onUnhandledRequest;
979
954
  }
980
955
  static createResponseFromDeclaration(request, declaration) {
981
956
  const headers = new http.HttpHeaders(declaration.headers);
@@ -1288,7 +1263,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1288
1263
  __name(this, "LocalHttpInterceptorWorker");
1289
1264
  }
1290
1265
  type;
1291
- _internalWorker;
1266
+ internalWorker;
1292
1267
  defaultHttpHandler;
1293
1268
  httpHandlerGroups = [];
1294
1269
  constructor(options) {
@@ -1299,17 +1274,17 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1299
1274
  return this.bypassOrRejectUnhandledRequest(request);
1300
1275
  });
1301
1276
  }
1302
- internalWorkerOrThrow() {
1303
- if (!this._internalWorker) {
1277
+ get internalWorkerOrThrow() {
1278
+ if (!this.internalWorker) {
1304
1279
  throw new NotStartedHttpInterceptorError_default();
1305
1280
  }
1306
- return this._internalWorker;
1281
+ return this.internalWorker;
1307
1282
  }
1308
- internalWorkerOrCreate() {
1309
- if (!this._internalWorker) {
1310
- this._internalWorker = this.createInternalWorker();
1283
+ get internalWorkerOrCreate() {
1284
+ if (!this.internalWorker) {
1285
+ this.internalWorker = this.createInternalWorker();
1311
1286
  }
1312
- return this._internalWorker;
1287
+ return this.internalWorker;
1313
1288
  }
1314
1289
  createInternalWorker() {
1315
1290
  if (isServerSide() && "setupServer" in mswNode__namespace) {
@@ -1322,18 +1297,18 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1322
1297
  }
1323
1298
  async start() {
1324
1299
  await super.sharedStart(async () => {
1325
- const internalWorker = this.internalWorkerOrCreate();
1300
+ const internalWorker = this.internalWorkerOrCreate;
1326
1301
  const sharedOptions = {
1327
1302
  onUnhandledRequest: "bypass"
1328
1303
  };
1329
1304
  if (this.isInternalBrowserWorker(internalWorker)) {
1330
- super.setPlatform("browser");
1305
+ this.platform = "browser";
1331
1306
  await this.startInBrowser(internalWorker, sharedOptions);
1332
1307
  } else {
1333
- super.setPlatform("node");
1308
+ this.platform = "node";
1334
1309
  this.startInNode(internalWorker, sharedOptions);
1335
1310
  }
1336
- super.setIsRunning(true);
1311
+ this.isRunning = true;
1337
1312
  });
1338
1313
  }
1339
1314
  async startInBrowser(internalWorker, sharedOptions) {
@@ -1354,15 +1329,15 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1354
1329
  }
1355
1330
  async stop() {
1356
1331
  await super.sharedStop(() => {
1357
- const internalWorker = this.internalWorkerOrCreate();
1332
+ const internalWorker = this.internalWorkerOrCreate;
1358
1333
  if (this.isInternalBrowserWorker(internalWorker)) {
1359
1334
  this.stopInBrowser(internalWorker);
1360
1335
  } else {
1361
1336
  this.stopInNode(internalWorker);
1362
1337
  }
1363
1338
  this.clearHandlers();
1364
- this._internalWorker = void 0;
1365
- super.setIsRunning(false);
1339
+ this.internalWorker = void 0;
1340
+ this.isRunning = false;
1366
1341
  });
1367
1342
  }
1368
1343
  stopInBrowser(internalWorker) {
@@ -1375,13 +1350,12 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1375
1350
  return "start" in worker && "stop" in worker;
1376
1351
  }
1377
1352
  hasInternalBrowserWorker() {
1378
- return this.isInternalBrowserWorker(this.internalWorkerOrThrow());
1353
+ return this.isInternalBrowserWorker(this.internalWorkerOrThrow);
1379
1354
  }
1380
1355
  hasInternalNodeWorker() {
1381
1356
  return !this.hasInternalBrowserWorker();
1382
1357
  }
1383
1358
  use(interceptor, method, rawURL, createResponse) {
1384
- const internalWorker = this.internalWorkerOrThrow();
1385
1359
  const lowercaseMethod = method.toLowerCase();
1386
1360
  const url = new URL(rawURL);
1387
1361
  excludeURLParams_default(url);
@@ -1407,7 +1381,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1407
1381
  }
1408
1382
  return response;
1409
1383
  });
1410
- internalWorker.use(httpHandler);
1384
+ this.internalWorkerOrThrow.use(httpHandler);
1411
1385
  this.httpHandlerGroups.push({ interceptor, httpHandler });
1412
1386
  }
1413
1387
  async bypassOrRejectUnhandledRequest(request) {
@@ -1421,20 +1395,18 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1421
1395
  }
1422
1396
  }
1423
1397
  clearHandlers() {
1424
- const internalWorker = this.internalWorkerOrThrow();
1425
- internalWorker.resetHandlers();
1398
+ this.internalWorkerOrThrow.resetHandlers();
1426
1399
  this.httpHandlerGroups = [];
1427
1400
  }
1428
1401
  clearInterceptorHandlers(interceptor) {
1429
- const internalWorker = this.internalWorkerOrThrow();
1430
1402
  const groupToRemoveIndex = this.httpHandlerGroups.findIndex((group) => group.interceptor === interceptor);
1431
1403
  removeArrayIndex(this.httpHandlerGroups, groupToRemoveIndex);
1432
- internalWorker.resetHandlers();
1404
+ this.internalWorkerOrThrow.resetHandlers();
1433
1405
  for (const { httpHandler } of this.httpHandlerGroups) {
1434
- internalWorker.use(httpHandler);
1406
+ this.internalWorkerOrThrow.use(httpHandler);
1435
1407
  }
1436
1408
  }
1437
- interceptorsWithHandlers() {
1409
+ get interceptorsWithHandlers() {
1438
1410
  return this.httpHandlerGroups.map((group) => group.interceptor);
1439
1411
  }
1440
1412
  };
@@ -1447,12 +1419,12 @@ var RemoteHttpRequestHandler = class {
1447
1419
  __name(this, "RemoteHttpRequestHandler");
1448
1420
  }
1449
1421
  type = "remote";
1450
- _client;
1422
+ client;
1451
1423
  syncPromises = [];
1452
1424
  unsynced;
1453
1425
  synced;
1454
1426
  constructor(interceptor, method, path) {
1455
- this._client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
1427
+ this.client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
1456
1428
  this.unsynced = this;
1457
1429
  this.synced = this.createSyncedProxy();
1458
1430
  }
@@ -1475,32 +1447,29 @@ var RemoteHttpRequestHandler = class {
1475
1447
  isHiddenPropertyWhenSynced(property) {
1476
1448
  return PENDING_PROPERTIES.has(property);
1477
1449
  }
1478
- client() {
1479
- return this._client;
1480
- }
1481
- method() {
1482
- return this._client.method();
1450
+ get method() {
1451
+ return this.client.method;
1483
1452
  }
1484
- path() {
1485
- return this._client.path();
1453
+ get path() {
1454
+ return this.client.path;
1486
1455
  }
1487
1456
  with(restriction) {
1488
- this._client.with(restriction);
1457
+ this.client.with(restriction);
1489
1458
  return this.unsynced;
1490
1459
  }
1491
1460
  respond(declaration) {
1492
1461
  const newUnsyncedThis = this.unsynced;
1493
- newUnsyncedThis._client.respond(declaration);
1462
+ newUnsyncedThis.client.respond(declaration);
1494
1463
  return newUnsyncedThis;
1495
1464
  }
1496
1465
  times(minNumberOfRequests, maxNumberOfRequests) {
1497
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
1466
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
1498
1467
  return this;
1499
1468
  }
1500
1469
  async checkTimes() {
1501
1470
  return new Promise((resolve, reject) => {
1502
1471
  try {
1503
- this._client.checkTimes();
1472
+ this.client.checkTimes();
1504
1473
  resolve();
1505
1474
  } catch (error) {
1506
1475
  reject(error);
@@ -1508,38 +1477,32 @@ var RemoteHttpRequestHandler = class {
1508
1477
  });
1509
1478
  }
1510
1479
  clear() {
1511
- this._client.clear();
1480
+ this.client.clear();
1512
1481
  return this.unsynced;
1513
1482
  }
1514
- requests() {
1515
- return new Promise((resolve, reject) => {
1516
- try {
1517
- resolve(this._client.requests());
1518
- } catch (error) {
1519
- reject(error);
1520
- }
1521
- });
1483
+ get requests() {
1484
+ return this.client.requests;
1522
1485
  }
1523
1486
  matchesRequest(request) {
1524
- return this._client.matchesRequest(request);
1487
+ return this.client.matchesRequest(request);
1525
1488
  }
1526
1489
  async applyResponseDeclaration(request) {
1527
- return this._client.applyResponseDeclaration(request);
1490
+ return this.client.applyResponseDeclaration(request);
1528
1491
  }
1529
1492
  saveInterceptedRequest(request, response) {
1530
- this._client.saveInterceptedRequest(request, response);
1493
+ this.client.saveInterceptedRequest(request, response);
1531
1494
  }
1532
1495
  registerSyncPromise(promise) {
1533
1496
  this.syncPromises.push(promise);
1534
1497
  }
1535
- isSynced() {
1498
+ get isSynced() {
1536
1499
  return this.syncPromises.length === 0;
1537
1500
  }
1538
1501
  then(onFulfilled, onRejected) {
1539
1502
  const promisesToWait = new Set(this.syncPromises);
1540
1503
  return Promise.all(promisesToWait).then(() => {
1541
1504
  this.syncPromises = this.syncPromises.filter((promise) => !promisesToWait.has(promise));
1542
- return this.isSynced() ? this.synced : this.unsynced;
1505
+ return this.isSynced ? this.synced : this.unsynced;
1543
1506
  }).then(onFulfilled, onRejected);
1544
1507
  }
1545
1508
  catch(onRejected) {
@@ -1560,9 +1523,9 @@ var HttpInterceptorClient = class {
1560
1523
  worker;
1561
1524
  store;
1562
1525
  _baseURL;
1563
- _isRunning = false;
1564
- _onUnhandledRequest;
1565
- _shouldSaveRequests = false;
1526
+ isRunning = false;
1527
+ onUnhandledRequest;
1528
+ shouldSaveRequests = false;
1566
1529
  Handler;
1567
1530
  handlerClientsByMethod = {
1568
1531
  GET: /* @__PURE__ */ new Map(),
@@ -1578,27 +1541,18 @@ var HttpInterceptorClient = class {
1578
1541
  this.store = options.store;
1579
1542
  this._baseURL = options.baseURL;
1580
1543
  this.Handler = options.Handler;
1581
- this._onUnhandledRequest = options.onUnhandledRequest;
1582
- this._shouldSaveRequests = options.saveRequests ?? false;
1544
+ this.onUnhandledRequest = options.onUnhandledRequest;
1545
+ this.shouldSaveRequests = options.saveRequests ?? false;
1583
1546
  }
1584
- baseURL() {
1547
+ get baseURLAsString() {
1585
1548
  const baseURL = this._baseURL;
1586
1549
  if (baseURL.href === `${baseURL.origin}/`) {
1587
1550
  return baseURL.origin;
1588
1551
  }
1589
- return baseURL.toString();
1590
- }
1591
- platform() {
1592
- return this.worker.platform();
1593
- }
1594
- onUnhandledRequest() {
1595
- return this._onUnhandledRequest;
1596
- }
1597
- isRunning() {
1598
- return this.worker.isRunning() && this._isRunning;
1552
+ return baseURL.href;
1599
1553
  }
1600
- shouldSaveRequests() {
1601
- return this._shouldSaveRequests;
1554
+ get platform() {
1555
+ return this.worker.platform;
1602
1556
  }
1603
1557
  async start() {
1604
1558
  await this.worker.start();
@@ -1619,11 +1573,11 @@ var HttpInterceptorClient = class {
1619
1573
  } else {
1620
1574
  this.store.markRemoteInterceptorAsRunning(this, isRunning, this._baseURL);
1621
1575
  }
1622
- this._isRunning = isRunning;
1576
+ this.isRunning = isRunning;
1623
1577
  }
1624
1578
  numberOfRunningInterceptors() {
1625
1579
  if (this.worker instanceof LocalHttpInterceptorWorker_default) {
1626
- return this.store.numberOfRunningLocalInterceptors();
1580
+ return this.store.numberOfRunningLocalInterceptors;
1627
1581
  } else {
1628
1582
  return this.store.numberOfRunningRemoteInterceptors(this._baseURL);
1629
1583
  }
@@ -1650,7 +1604,7 @@ var HttpInterceptorClient = class {
1650
1604
  return this.createHttpRequestHandler("OPTIONS", path);
1651
1605
  }
1652
1606
  createHttpRequestHandler(method, path) {
1653
- if (!this.isRunning()) {
1607
+ if (!this.isRunning) {
1654
1608
  throw new NotStartedHttpInterceptorError_default();
1655
1609
  }
1656
1610
  const handler = new this.Handler(this, method, path);
@@ -1658,24 +1612,24 @@ var HttpInterceptorClient = class {
1658
1612
  return handler;
1659
1613
  }
1660
1614
  registerRequestHandler(handler) {
1661
- const handlerClients = this.handlerClientsByMethod[handler.method()].get(handler.path()) ?? [];
1662
- const isAlreadyRegistered = handlerClients.includes(handler.client());
1615
+ const handlerClients = this.handlerClientsByMethod[handler.method].get(handler.path) ?? [];
1616
+ const isAlreadyRegistered = handlerClients.includes(handler.client);
1663
1617
  if (isAlreadyRegistered) {
1664
1618
  return;
1665
1619
  }
1666
- handlerClients.push(handler.client());
1620
+ handlerClients.push(handler.client);
1667
1621
  const isFirstHandlerForMethodPath = handlerClients.length === 1;
1668
1622
  if (!isFirstHandlerForMethodPath) {
1669
1623
  return;
1670
1624
  }
1671
- this.handlerClientsByMethod[handler.method()].set(handler.path(), handlerClients);
1672
- const url = joinURL_default(this.baseURL(), handler.path());
1625
+ this.handlerClientsByMethod[handler.method].set(handler.path, handlerClients);
1626
+ const url = joinURL_default(this.baseURLAsString, handler.path);
1673
1627
  const urlRegex = createRegExpFromURL_default(url);
1674
- const registrationResult = this.worker.use(this, handler.method(), url, async (context) => {
1628
+ const registrationResult = this.worker.use(this, handler.method, url, async (context) => {
1675
1629
  const response = await this.handleInterceptedRequest(
1676
1630
  urlRegex,
1677
- handler.method(),
1678
- handler.path(),
1631
+ handler.method,
1632
+ handler.path,
1679
1633
  context
1680
1634
  );
1681
1635
  return response;
@@ -1694,7 +1648,7 @@ var HttpInterceptorClient = class {
1694
1648
  }
1695
1649
  const responseDeclaration = await matchedHandler.applyResponseDeclaration(parsedRequest);
1696
1650
  const response = HttpInterceptorWorker_default.createResponseFromDeclaration(request, responseDeclaration);
1697
- if (this.shouldSaveRequests()) {
1651
+ if (this.shouldSaveRequests) {
1698
1652
  const responseClone = response.clone();
1699
1653
  const parsedResponse = await HttpInterceptorWorker_default.parseRawResponse(responseClone);
1700
1654
  matchedHandler.saveInterceptedRequest(parsedRequest, parsedResponse);
@@ -1722,7 +1676,7 @@ var HttpInterceptorClient = class {
1722
1676
  }
1723
1677
  }
1724
1678
  clear(options = {}) {
1725
- if (!this.isRunning()) {
1679
+ if (!this.isRunning) {
1726
1680
  throw new NotStartedHttpInterceptorError_default();
1727
1681
  }
1728
1682
  const clearResults = [];
@@ -1946,24 +1900,18 @@ var WebSocketHandler = class {
1946
1900
  __name(this, "WebSocketHandler");
1947
1901
  }
1948
1902
  sockets = /* @__PURE__ */ new Set();
1949
- _socketTimeout;
1950
- _messageTimeout;
1903
+ socketTimeout;
1904
+ messageTimeout;
1951
1905
  channelListeners = {};
1952
1906
  socketListeners = {
1953
1907
  messageAbort: /* @__PURE__ */ new Map()
1954
1908
  };
1955
1909
  constructor(options) {
1956
- this._socketTimeout = options.socketTimeout ?? DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT;
1957
- this._messageTimeout = options.messageTimeout ?? DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT;
1958
- }
1959
- socketTimeout() {
1960
- return this._socketTimeout;
1961
- }
1962
- messageTimeout() {
1963
- return this._messageTimeout;
1910
+ this.socketTimeout = options.socketTimeout ?? DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT;
1911
+ this.messageTimeout = options.messageTimeout ?? DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT;
1964
1912
  }
1965
1913
  async registerSocket(socket) {
1966
- const openPromise = waitForOpenClientSocket(socket, { timeout: this._socketTimeout });
1914
+ const openPromise = waitForOpenClientSocket(socket, { timeout: this.socketTimeout });
1967
1915
  const handleSocketMessage = /* @__PURE__ */ __name(async (rawMessage) => {
1968
1916
  await this.handleSocketMessage(socket, rawMessage);
1969
1917
  }, "handleSocketMessage");
@@ -2050,7 +1998,7 @@ var WebSocketHandler = class {
2050
1998
  }
2051
1999
  async closeClientSockets(sockets = this.sockets) {
2052
2000
  const closingPromises = Array.from(sockets, async (socket) => {
2053
- await closeClientSocket(socket, { timeout: this._socketTimeout });
2001
+ await closeClientSocket(socket, { timeout: this.socketTimeout });
2054
2002
  });
2055
2003
  await Promise.all(closingPromises);
2056
2004
  }
@@ -2082,9 +2030,9 @@ var WebSocketHandler = class {
2082
2030
  const replyTimeout = setTimeout(() => {
2083
2031
  this.offReply(channel, replyListener);
2084
2032
  this.offAbortSocketMessages(sockets, abortListener);
2085
- const timeoutError = new WebSocketMessageTimeoutError(this._messageTimeout);
2033
+ const timeoutError = new WebSocketMessageTimeoutError(this.messageTimeout);
2086
2034
  reject(timeoutError);
2087
- }, this._messageTimeout);
2035
+ }, this.messageTimeout);
2088
2036
  const abortListener = this.onAbortSocketMessages(sockets, (error) => {
2089
2037
  clearTimeout(replyTimeout);
2090
2038
  this.offReply(channel, replyListener);
@@ -2106,7 +2054,7 @@ var WebSocketHandler = class {
2106
2054
  }
2107
2055
  async reply(request, replyData, options) {
2108
2056
  const reply = await this.createReplyMessage(request, replyData);
2109
- if (this.isRunning()) {
2057
+ if (this.isRunning) {
2110
2058
  this.sendMessage(reply, options.sockets);
2111
2059
  }
2112
2060
  }
@@ -2121,7 +2069,7 @@ var WebSocketHandler = class {
2121
2069
  return replyMessage;
2122
2070
  }
2123
2071
  sendMessage(message, sockets = this.sockets) {
2124
- if (!this.isRunning()) {
2072
+ if (!this.isRunning) {
2125
2073
  throw new NotStartedWebSocketHandlerError_default();
2126
2074
  }
2127
2075
  const stringifiedMessage = JSON.stringify(message);
@@ -2202,7 +2150,7 @@ var WebSocketClient = class extends WebSocketHandler_default {
2202
2150
  this.url = new URL(options.url);
2203
2151
  validateURLProtocol_default(this.url, SUPPORTED_WEB_SOCKET_PROTOCOLS);
2204
2152
  }
2205
- isRunning() {
2153
+ get isRunning() {
2206
2154
  return this.socket !== void 0 && this.socket.readyState === this.socket.OPEN;
2207
2155
  }
2208
2156
  async start() {
@@ -2230,13 +2178,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2230
2178
  __name(this, "RemoteHttpInterceptorWorker");
2231
2179
  }
2232
2180
  type;
2233
- _webSocketClient;
2181
+ webSocketClient;
2234
2182
  httpHandlers = /* @__PURE__ */ new Map();
2235
2183
  constructor(options) {
2236
2184
  super();
2237
2185
  this.type = options.type;
2238
2186
  const webSocketServerURL = this.deriveWebSocketServerURL(options.serverURL);
2239
- this._webSocketClient = new WebSocketClient_default({
2187
+ this.webSocketClient = new WebSocketClient_default({
2240
2188
  url: webSocketServerURL.toString()
2241
2189
  });
2242
2190
  }
@@ -2245,17 +2193,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2245
2193
  webSocketServerURL.protocol = serverURL.protocol.replace(/^http(s)?:$/, "ws$1:");
2246
2194
  return webSocketServerURL;
2247
2195
  }
2248
- webSocketClient() {
2249
- return this._webSocketClient;
2250
- }
2251
2196
  async start() {
2252
2197
  await super.sharedStart(async () => {
2253
- await this._webSocketClient.start();
2254
- this._webSocketClient.onEvent("interceptors/responses/create", this.createResponse);
2255
- this._webSocketClient.onEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2256
- const platform = this.readPlatform();
2257
- super.setPlatform(platform);
2258
- super.setIsRunning(true);
2198
+ await this.webSocketClient.start();
2199
+ this.webSocketClient.onEvent("interceptors/responses/create", this.createResponse);
2200
+ this.webSocketClient.onEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2201
+ this.platform = this.readPlatform();
2202
+ this.isRunning = true;
2259
2203
  });
2260
2204
  }
2261
2205
  createResponse = /* @__PURE__ */ __name(async (message) => {
@@ -2294,14 +2238,14 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2294
2238
  async stop() {
2295
2239
  await super.sharedStop(async () => {
2296
2240
  await this.clearHandlers();
2297
- this._webSocketClient.offEvent("interceptors/responses/create", this.createResponse);
2298
- this._webSocketClient.offEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2299
- await this._webSocketClient.stop();
2300
- super.setIsRunning(false);
2241
+ this.webSocketClient.offEvent("interceptors/responses/create", this.createResponse);
2242
+ this.webSocketClient.offEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2243
+ await this.webSocketClient.stop();
2244
+ this.isRunning = false;
2301
2245
  });
2302
2246
  }
2303
2247
  async use(interceptor, method, rawURL, createResponse) {
2304
- if (!super.isRunning()) {
2248
+ if (!this.isRunning) {
2305
2249
  throw new NotStartedHttpInterceptorError_default();
2306
2250
  }
2307
2251
  const crypto = await importCrypto();
@@ -2311,7 +2255,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2311
2255
  const handler = {
2312
2256
  id: crypto.randomUUID(),
2313
2257
  url: {
2314
- base: interceptor.baseURL(),
2258
+ base: interceptor.baseURLAsString,
2315
2259
  full: url.toString()
2316
2260
  },
2317
2261
  method,
@@ -2322,23 +2266,23 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2322
2266
  }
2323
2267
  };
2324
2268
  this.httpHandlers.set(handler.id, handler);
2325
- await this._webSocketClient.request("interceptors/workers/use/commit", {
2269
+ await this.webSocketClient.request("interceptors/workers/use/commit", {
2326
2270
  id: handler.id,
2327
2271
  url: handler.url,
2328
2272
  method
2329
2273
  });
2330
2274
  }
2331
2275
  async clearHandlers() {
2332
- if (!super.isRunning()) {
2276
+ if (!this.isRunning) {
2333
2277
  throw new NotStartedHttpInterceptorError_default();
2334
2278
  }
2335
2279
  this.httpHandlers.clear();
2336
- if (this._webSocketClient.isRunning()) {
2337
- await this._webSocketClient.request("interceptors/workers/use/reset", void 0);
2280
+ if (this.webSocketClient.isRunning) {
2281
+ await this.webSocketClient.request("interceptors/workers/use/reset", void 0);
2338
2282
  }
2339
2283
  }
2340
2284
  async clearInterceptorHandlers(interceptor) {
2341
- if (!super.isRunning()) {
2285
+ if (!this.isRunning) {
2342
2286
  throw new NotStartedHttpInterceptorError_default();
2343
2287
  }
2344
2288
  for (const handler of this.httpHandlers.values()) {
@@ -2346,16 +2290,16 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2346
2290
  this.httpHandlers.delete(handler.id);
2347
2291
  }
2348
2292
  }
2349
- if (this._webSocketClient.isRunning()) {
2293
+ if (this.webSocketClient.isRunning) {
2350
2294
  const groupsToRecommit = Array.from(this.httpHandlers.values(), (handler) => ({
2351
2295
  id: handler.id,
2352
2296
  url: handler.url,
2353
2297
  method: handler.method
2354
2298
  }));
2355
- await this._webSocketClient.request("interceptors/workers/use/reset", groupsToRecommit);
2299
+ await this.webSocketClient.request("interceptors/workers/use/reset", groupsToRecommit);
2356
2300
  }
2357
2301
  }
2358
- interceptorsWithHandlers() {
2302
+ get interceptorsWithHandlers() {
2359
2303
  const interceptors = Array.from(this.httpHandlers.values(), (handler) => handler.interceptor);
2360
2304
  return interceptors;
2361
2305
  }
@@ -2382,13 +2326,13 @@ var HttpInterceptorStore = class _HttpInterceptorStore {
2382
2326
  static remoteWorkers = /* @__PURE__ */ new Map();
2383
2327
  static runningRemoteInterceptors = /* @__PURE__ */ new Map();
2384
2328
  class = _HttpInterceptorStore;
2385
- localWorker() {
2329
+ get localWorker() {
2386
2330
  return this.class._localWorker;
2387
2331
  }
2388
2332
  remoteWorker(baseURL) {
2389
2333
  return this.class.remoteWorkers.get(baseURL.origin);
2390
2334
  }
2391
- numberOfRunningLocalInterceptors() {
2335
+ get numberOfRunningLocalInterceptors() {
2392
2336
  return this.class.runningLocalInterceptors.size;
2393
2337
  }
2394
2338
  numberOfRunningRemoteInterceptors(baseURL) {
@@ -2449,14 +2393,14 @@ var LocalHttpInterceptor = class {
2449
2393
  }
2450
2394
  type;
2451
2395
  store = new HttpInterceptorStore_default();
2452
- _client;
2396
+ client;
2453
2397
  constructor(options) {
2454
2398
  this.type = options.type;
2455
2399
  const baseURL = new URL(options.baseURL);
2456
2400
  validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
2457
2401
  excludeURLParams_default(baseURL);
2458
2402
  const worker = this.store.getOrCreateLocalWorker({});
2459
- this._client = new HttpInterceptorClient_default({
2403
+ this.client = new HttpInterceptorClient_default({
2460
2404
  worker,
2461
2405
  store: this.store,
2462
2406
  baseURL,
@@ -2465,57 +2409,54 @@ var LocalHttpInterceptor = class {
2465
2409
  saveRequests: options.saveRequests
2466
2410
  });
2467
2411
  }
2468
- client() {
2469
- return this._client;
2412
+ get baseURL() {
2413
+ return this.client.baseURLAsString;
2470
2414
  }
2471
- baseURL() {
2472
- return this._client.baseURL();
2415
+ get platform() {
2416
+ return this.client.platform;
2473
2417
  }
2474
- platform() {
2475
- return this._client.platform();
2476
- }
2477
- isRunning() {
2478
- return this._client.isRunning();
2418
+ get isRunning() {
2419
+ return this.client.isRunning;
2479
2420
  }
2480
2421
  async start() {
2481
- if (this.isRunning()) {
2422
+ if (this.isRunning) {
2482
2423
  return;
2483
2424
  }
2484
- await this._client.start();
2425
+ await this.client.start();
2485
2426
  }
2486
2427
  async stop() {
2487
- if (!this.isRunning()) {
2428
+ if (!this.isRunning) {
2488
2429
  return;
2489
2430
  }
2490
2431
  this.clear();
2491
- await this._client.stop();
2432
+ await this.client.stop();
2492
2433
  }
2493
2434
  get = /* @__PURE__ */ __name((path) => {
2494
- return this._client.get(path);
2435
+ return this.client.get(path);
2495
2436
  }, "get");
2496
2437
  post = /* @__PURE__ */ __name((path) => {
2497
- return this._client.post(path);
2438
+ return this.client.post(path);
2498
2439
  }, "post");
2499
2440
  patch = /* @__PURE__ */ __name((path) => {
2500
- return this._client.patch(path);
2441
+ return this.client.patch(path);
2501
2442
  }, "patch");
2502
2443
  put = /* @__PURE__ */ __name((path) => {
2503
- return this._client.put(path);
2444
+ return this.client.put(path);
2504
2445
  }, "put");
2505
2446
  delete = /* @__PURE__ */ __name((path) => {
2506
- return this._client.delete(path);
2447
+ return this.client.delete(path);
2507
2448
  }, "delete");
2508
2449
  head = /* @__PURE__ */ __name((path) => {
2509
- return this._client.head(path);
2450
+ return this.client.head(path);
2510
2451
  }, "head");
2511
2452
  options = /* @__PURE__ */ __name((path) => {
2512
- return this._client.options(path);
2453
+ return this.client.options(path);
2513
2454
  }, "options");
2514
2455
  checkTimes() {
2515
- this._client.checkTimes();
2456
+ this.client.checkTimes();
2516
2457
  }
2517
2458
  clear() {
2518
- this._client.clear();
2459
+ this.client.clear();
2519
2460
  }
2520
2461
  };
2521
2462
  var LocalHttpInterceptor_default = LocalHttpInterceptor;
@@ -2527,7 +2468,7 @@ var RemoteHttpInterceptor = class {
2527
2468
  }
2528
2469
  type;
2529
2470
  store = new HttpInterceptorStore_default();
2530
- _client;
2471
+ client;
2531
2472
  constructor(options) {
2532
2473
  this.type = options.type;
2533
2474
  const baseURL = new URL(options.baseURL);
@@ -2535,7 +2476,7 @@ var RemoteHttpInterceptor = class {
2535
2476
  excludeURLParams_default(baseURL);
2536
2477
  const serverURL = new URL(baseURL.origin);
2537
2478
  const worker = this.store.getOrCreateRemoteWorker({ serverURL });
2538
- this._client = new HttpInterceptorClient_default({
2479
+ this.client = new HttpInterceptorClient_default({
2539
2480
  worker,
2540
2481
  store: this.store,
2541
2482
  baseURL,
@@ -2544,56 +2485,53 @@ var RemoteHttpInterceptor = class {
2544
2485
  saveRequests: options.saveRequests
2545
2486
  });
2546
2487
  }
2547
- client() {
2548
- return this._client;
2549
- }
2550
- baseURL() {
2551
- return this._client.baseURL();
2488
+ get baseURL() {
2489
+ return this.client.baseURLAsString;
2552
2490
  }
2553
- platform() {
2554
- return this._client.platform();
2491
+ get platform() {
2492
+ return this.client.platform;
2555
2493
  }
2556
- isRunning() {
2557
- return this._client.isRunning();
2494
+ get isRunning() {
2495
+ return this.client.isRunning;
2558
2496
  }
2559
2497
  async start() {
2560
- if (this.isRunning()) {
2498
+ if (this.isRunning) {
2561
2499
  return;
2562
2500
  }
2563
- await this._client.start();
2501
+ await this.client.start();
2564
2502
  }
2565
2503
  async stop() {
2566
- if (!this.isRunning()) {
2504
+ if (!this.isRunning) {
2567
2505
  return;
2568
2506
  }
2569
2507
  await this.clear();
2570
- await this._client.stop();
2508
+ await this.client.stop();
2571
2509
  }
2572
2510
  get = /* @__PURE__ */ __name((path) => {
2573
- return this._client.get(path);
2511
+ return this.client.get(path);
2574
2512
  }, "get");
2575
2513
  post = /* @__PURE__ */ __name((path) => {
2576
- return this._client.post(path);
2514
+ return this.client.post(path);
2577
2515
  }, "post");
2578
2516
  patch = /* @__PURE__ */ __name((path) => {
2579
- return this._client.patch(path);
2517
+ return this.client.patch(path);
2580
2518
  }, "patch");
2581
2519
  put = /* @__PURE__ */ __name((path) => {
2582
- return this._client.put(path);
2520
+ return this.client.put(path);
2583
2521
  }, "put");
2584
2522
  delete = /* @__PURE__ */ __name((path) => {
2585
- return this._client.delete(path);
2523
+ return this.client.delete(path);
2586
2524
  }, "delete");
2587
2525
  head = /* @__PURE__ */ __name((path) => {
2588
- return this._client.head(path);
2526
+ return this.client.head(path);
2589
2527
  }, "head");
2590
2528
  options = /* @__PURE__ */ __name((path) => {
2591
- return this._client.options(path);
2529
+ return this.client.options(path);
2592
2530
  }, "options");
2593
2531
  checkTimes() {
2594
2532
  return new Promise((resolve, reject) => {
2595
2533
  try {
2596
- this._client.checkTimes();
2534
+ this.client.checkTimes();
2597
2535
  resolve();
2598
2536
  } catch (error) {
2599
2537
  reject(error);
@@ -2602,7 +2540,7 @@ var RemoteHttpInterceptor = class {
2602
2540
  }
2603
2541
  async clear() {
2604
2542
  await new Promise((resolve, reject) => {
2605
- this._client.clear({
2543
+ this.client.clear({
2606
2544
  onCommitSuccess: resolve,
2607
2545
  onCommitError: reject
2608
2546
  });