@zimic/interceptor 0.15.0-canary.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 (41) hide show
  1. package/README.md +6 -7
  2. package/dist/{chunk-YGJD3JT6.mjs → chunk-3O3YPVEG.mjs} +69 -104
  3. package/dist/chunk-3O3YPVEG.mjs.map +1 -0
  4. package/dist/{chunk-L6Y4EV6T.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 +38 -35
  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 +2 -2
  19. package/src/cli/server/start.ts +1 -1
  20. package/src/http/interceptor/HttpInterceptorClient.ts +23 -34
  21. package/src/http/interceptor/HttpInterceptorStore.ts +2 -2
  22. package/src/http/interceptor/LocalHttpInterceptor.ts +22 -25
  23. package/src/http/interceptor/RemoteHttpInterceptor.ts +22 -25
  24. package/src/http/interceptor/errors/NotStartedHttpInterceptorError.ts +1 -1
  25. package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
  26. package/src/http/interceptor/types/options.ts +3 -3
  27. package/src/http/interceptor/types/public.ts +12 -9
  28. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +10 -28
  29. package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +21 -25
  30. package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +22 -26
  31. package/src/http/requestHandler/HttpRequestHandlerClient.ts +11 -22
  32. package/src/http/requestHandler/LocalHttpRequestHandler.ts +16 -20
  33. package/src/http/requestHandler/RemoteHttpRequestHandler.ts +18 -28
  34. package/src/http/requestHandler/types/public.ts +22 -24
  35. package/src/server/InterceptorServer.ts +45 -68
  36. package/src/server/types/public.ts +15 -10
  37. package/src/webSocket/WebSocketClient.ts +1 -1
  38. package/src/webSocket/WebSocketHandler.ts +11 -19
  39. package/src/webSocket/WebSocketServer.ts +4 -4
  40. package/dist/chunk-L6Y4EV6T.js.map +0 -1
  41. package/dist/chunk-YGJD3JT6.mjs.map +0 -1
package/dist/http.mjs CHANGED
@@ -400,10 +400,10 @@ var DEFAULT_NUMBER_OF_REQUEST_LIMITS = Object.freeze({
400
400
  max: Infinity
401
401
  });
402
402
  var HttpRequestHandlerClient = class {
403
- constructor(interceptor, _method, _path, handler) {
403
+ constructor(interceptor, method, path, handler) {
404
404
  this.interceptor = interceptor;
405
- this._method = _method;
406
- this._path = _path;
405
+ this.method = method;
406
+ this.path = path;
407
407
  this.handler = handler;
408
408
  }
409
409
  static {
@@ -416,14 +416,8 @@ var HttpRequestHandlerClient = class {
416
416
  timesDeclarationPointer;
417
417
  numberOfMatchedRequests = 0;
418
418
  unmatchedRequestGroups = [];
419
- interceptedRequests = [];
419
+ _requests = [];
420
420
  createResponseDeclaration;
421
- method() {
422
- return this._method;
423
- }
424
- path() {
425
- return this._path;
426
- }
427
421
  with(restriction) {
428
422
  this.restrictions.push(restriction);
429
423
  return this;
@@ -433,7 +427,7 @@ var HttpRequestHandlerClient = class {
433
427
  newThis.createResponseDeclaration = this.isResponseDeclarationFactory(declaration) ? declaration : () => declaration;
434
428
  newThis.numberOfMatchedRequests = 0;
435
429
  newThis.unmatchedRequestGroups.length = 0;
436
- newThis.interceptedRequests.length = 0;
430
+ newThis._requests.length = 0;
437
431
  this.interceptor.registerRequestHandler(this.handler);
438
432
  return newThis;
439
433
  }
@@ -457,7 +451,7 @@ var HttpRequestHandlerClient = class {
457
451
  declarationPointer: this.timesDeclarationPointer,
458
452
  unmatchedRequestGroups: this.unmatchedRequestGroups,
459
453
  hasRestrictions: this.restrictions.length > 0,
460
- hasSavedRequests: this.interceptor.shouldSaveRequests()
454
+ hasSavedRequests: this.interceptor.shouldSaveRequests
461
455
  });
462
456
  }
463
457
  }
@@ -469,7 +463,7 @@ var HttpRequestHandlerClient = class {
469
463
  this.timesDeclarationPointer = void 0;
470
464
  this.numberOfMatchedRequests = 0;
471
465
  this.unmatchedRequestGroups.length = 0;
472
- this.interceptedRequests.length = 0;
466
+ this._requests.length = 0;
473
467
  this.createResponseDeclaration = void 0;
474
468
  return this;
475
469
  }
@@ -482,7 +476,7 @@ var HttpRequestHandlerClient = class {
482
476
  if (restrictionsMatch.value) {
483
477
  this.numberOfMatchedRequests++;
484
478
  } else {
485
- const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests() && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
479
+ const shouldSaveUnmatchedGroup = this.interceptor.shouldSaveRequests && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
486
480
  if (shouldSaveUnmatchedGroup) {
487
481
  this.unmatchedRequestGroups.push({ request, diff: restrictionsMatch.diff });
488
482
  }
@@ -615,7 +609,7 @@ var HttpRequestHandlerClient = class {
615
609
  }
616
610
  saveInterceptedRequest(request, response) {
617
611
  const interceptedRequest = this.createInterceptedRequest(request, response);
618
- this.interceptedRequests.push(interceptedRequest);
612
+ this._requests.push(interceptedRequest);
619
613
  }
620
614
  createInterceptedRequest(request, response) {
621
615
  const interceptedRequest = request;
@@ -627,13 +621,11 @@ var HttpRequestHandlerClient = class {
627
621
  });
628
622
  return interceptedRequest;
629
623
  }
630
- requests() {
631
- if (!this.interceptor.shouldSaveRequests()) {
624
+ get requests() {
625
+ if (!this.interceptor.shouldSaveRequests) {
632
626
  throw new DisabledRequestSavingError_default();
633
627
  }
634
- const interceptedRequestsCopy = [...this.interceptedRequests];
635
- Object.freeze(interceptedRequestsCopy);
636
- return interceptedRequestsCopy;
628
+ return this._requests;
637
629
  }
638
630
  };
639
631
  var HttpRequestHandlerClient_default = HttpRequestHandlerClient;
@@ -644,50 +636,47 @@ var LocalHttpRequestHandler = class {
644
636
  __name(this, "LocalHttpRequestHandler");
645
637
  }
646
638
  type = "local";
647
- _client;
639
+ client;
648
640
  constructor(interceptor, method, path) {
649
- this._client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
650
- }
651
- client() {
652
- return this._client;
641
+ this.client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
653
642
  }
654
- method() {
655
- return this._client.method();
643
+ get method() {
644
+ return this.client.method;
656
645
  }
657
- path() {
658
- return this._client.path();
646
+ get path() {
647
+ return this.client.path;
659
648
  }
660
649
  with(restriction) {
661
- this._client.with(restriction);
650
+ this.client.with(restriction);
662
651
  return this;
663
652
  }
664
653
  respond(declaration) {
665
- this._client.respond(declaration);
654
+ this.client.respond(declaration);
666
655
  const newThis = this;
667
656
  return newThis;
668
657
  }
669
658
  times(minNumberOfRequests, maxNumberOfRequests) {
670
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
659
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
671
660
  return this;
672
661
  }
673
662
  checkTimes() {
674
- this._client.checkTimes();
663
+ this.client.checkTimes();
675
664
  }
676
665
  clear() {
677
- this._client.clear();
666
+ this.client.clear();
678
667
  return this;
679
668
  }
680
- requests() {
681
- return this._client.requests();
669
+ get requests() {
670
+ return this.client.requests;
682
671
  }
683
672
  matchesRequest(request) {
684
- return this._client.matchesRequest(request);
673
+ return this.client.matchesRequest(request);
685
674
  }
686
675
  async applyResponseDeclaration(request) {
687
- return this._client.applyResponseDeclaration(request);
676
+ return this.client.applyResponseDeclaration(request);
688
677
  }
689
678
  saveInterceptedRequest(request, response) {
690
- this._client.saveInterceptedRequest(request, response);
679
+ this.client.saveInterceptedRequest(request, response);
691
680
  }
692
681
  };
693
682
  var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
@@ -823,26 +812,14 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
823
812
  static {
824
813
  __name(this, "HttpInterceptorWorker");
825
814
  }
826
- _platform = null;
827
- _isRunning = false;
815
+ platform = null;
816
+ isRunning = false;
828
817
  startingPromise;
829
818
  stoppingPromise;
830
819
  store = new HttpInterceptorWorkerStore_default();
831
820
  runningInterceptors = [];
832
- platform() {
833
- return this._platform;
834
- }
835
- setPlatform(platform) {
836
- this._platform = platform;
837
- }
838
- isRunning() {
839
- return this._isRunning;
840
- }
841
- setIsRunning(isRunning) {
842
- this._isRunning = isRunning;
843
- }
844
821
  async sharedStart(internalStart) {
845
- if (this.isRunning()) {
822
+ if (this.isRunning) {
846
823
  return;
847
824
  }
848
825
  if (this.startingPromise) {
@@ -861,7 +838,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
861
838
  }
862
839
  }
863
840
  async sharedStop(internalStop) {
864
- if (!this.isRunning()) {
841
+ if (!this.isRunning) {
865
842
  return;
866
843
  }
867
844
  if (this.stoppingPromise) {
@@ -926,8 +903,7 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
926
903
  }
927
904
  findInterceptorByRequestBaseURL(request) {
928
905
  const interceptor = this.runningInterceptors.findLast((interceptor2) => {
929
- const baseURL = interceptor2.baseURL();
930
- return request.url.startsWith(baseURL);
906
+ return request.url.startsWith(interceptor2.baseURLAsString);
931
907
  });
932
908
  return interceptor;
933
909
  }
@@ -943,12 +919,11 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
943
919
  return defaultStrategyOrFactory;
944
920
  }
945
921
  async getInterceptorUnhandledRequestStrategy(request, interceptor) {
946
- const interceptorStrategyOrFactory = interceptor.onUnhandledRequest();
947
- if (typeof interceptorStrategyOrFactory === "function") {
922
+ if (typeof interceptor.onUnhandledRequest === "function") {
948
923
  const parsedRequest = await _HttpInterceptorWorker.parseRawUnhandledRequest(request);
949
- return interceptorStrategyOrFactory(parsedRequest);
924
+ return interceptor.onUnhandledRequest(parsedRequest);
950
925
  }
951
- return interceptorStrategyOrFactory;
926
+ return interceptor.onUnhandledRequest;
952
927
  }
953
928
  static createResponseFromDeclaration(request, declaration) {
954
929
  const headers = new HttpHeaders(declaration.headers);
@@ -1261,7 +1236,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1261
1236
  __name(this, "LocalHttpInterceptorWorker");
1262
1237
  }
1263
1238
  type;
1264
- _internalWorker;
1239
+ internalWorker;
1265
1240
  defaultHttpHandler;
1266
1241
  httpHandlerGroups = [];
1267
1242
  constructor(options) {
@@ -1272,17 +1247,17 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1272
1247
  return this.bypassOrRejectUnhandledRequest(request);
1273
1248
  });
1274
1249
  }
1275
- internalWorkerOrThrow() {
1276
- if (!this._internalWorker) {
1250
+ get internalWorkerOrThrow() {
1251
+ if (!this.internalWorker) {
1277
1252
  throw new NotStartedHttpInterceptorError_default();
1278
1253
  }
1279
- return this._internalWorker;
1254
+ return this.internalWorker;
1280
1255
  }
1281
- internalWorkerOrCreate() {
1282
- if (!this._internalWorker) {
1283
- this._internalWorker = this.createInternalWorker();
1256
+ get internalWorkerOrCreate() {
1257
+ if (!this.internalWorker) {
1258
+ this.internalWorker = this.createInternalWorker();
1284
1259
  }
1285
- return this._internalWorker;
1260
+ return this.internalWorker;
1286
1261
  }
1287
1262
  createInternalWorker() {
1288
1263
  if (isServerSide() && "setupServer" in mswNode) {
@@ -1295,18 +1270,18 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1295
1270
  }
1296
1271
  async start() {
1297
1272
  await super.sharedStart(async () => {
1298
- const internalWorker = this.internalWorkerOrCreate();
1273
+ const internalWorker = this.internalWorkerOrCreate;
1299
1274
  const sharedOptions = {
1300
1275
  onUnhandledRequest: "bypass"
1301
1276
  };
1302
1277
  if (this.isInternalBrowserWorker(internalWorker)) {
1303
- super.setPlatform("browser");
1278
+ this.platform = "browser";
1304
1279
  await this.startInBrowser(internalWorker, sharedOptions);
1305
1280
  } else {
1306
- super.setPlatform("node");
1281
+ this.platform = "node";
1307
1282
  this.startInNode(internalWorker, sharedOptions);
1308
1283
  }
1309
- super.setIsRunning(true);
1284
+ this.isRunning = true;
1310
1285
  });
1311
1286
  }
1312
1287
  async startInBrowser(internalWorker, sharedOptions) {
@@ -1327,15 +1302,15 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1327
1302
  }
1328
1303
  async stop() {
1329
1304
  await super.sharedStop(() => {
1330
- const internalWorker = this.internalWorkerOrCreate();
1305
+ const internalWorker = this.internalWorkerOrCreate;
1331
1306
  if (this.isInternalBrowserWorker(internalWorker)) {
1332
1307
  this.stopInBrowser(internalWorker);
1333
1308
  } else {
1334
1309
  this.stopInNode(internalWorker);
1335
1310
  }
1336
1311
  this.clearHandlers();
1337
- this._internalWorker = void 0;
1338
- super.setIsRunning(false);
1312
+ this.internalWorker = void 0;
1313
+ this.isRunning = false;
1339
1314
  });
1340
1315
  }
1341
1316
  stopInBrowser(internalWorker) {
@@ -1348,13 +1323,12 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1348
1323
  return "start" in worker && "stop" in worker;
1349
1324
  }
1350
1325
  hasInternalBrowserWorker() {
1351
- return this.isInternalBrowserWorker(this.internalWorkerOrThrow());
1326
+ return this.isInternalBrowserWorker(this.internalWorkerOrThrow);
1352
1327
  }
1353
1328
  hasInternalNodeWorker() {
1354
1329
  return !this.hasInternalBrowserWorker();
1355
1330
  }
1356
1331
  use(interceptor, method, rawURL, createResponse) {
1357
- const internalWorker = this.internalWorkerOrThrow();
1358
1332
  const lowercaseMethod = method.toLowerCase();
1359
1333
  const url = new URL(rawURL);
1360
1334
  excludeURLParams_default(url);
@@ -1380,7 +1354,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1380
1354
  }
1381
1355
  return response;
1382
1356
  });
1383
- internalWorker.use(httpHandler);
1357
+ this.internalWorkerOrThrow.use(httpHandler);
1384
1358
  this.httpHandlerGroups.push({ interceptor, httpHandler });
1385
1359
  }
1386
1360
  async bypassOrRejectUnhandledRequest(request) {
@@ -1394,20 +1368,18 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1394
1368
  }
1395
1369
  }
1396
1370
  clearHandlers() {
1397
- const internalWorker = this.internalWorkerOrThrow();
1398
- internalWorker.resetHandlers();
1371
+ this.internalWorkerOrThrow.resetHandlers();
1399
1372
  this.httpHandlerGroups = [];
1400
1373
  }
1401
1374
  clearInterceptorHandlers(interceptor) {
1402
- const internalWorker = this.internalWorkerOrThrow();
1403
1375
  const groupToRemoveIndex = this.httpHandlerGroups.findIndex((group) => group.interceptor === interceptor);
1404
1376
  removeArrayIndex(this.httpHandlerGroups, groupToRemoveIndex);
1405
- internalWorker.resetHandlers();
1377
+ this.internalWorkerOrThrow.resetHandlers();
1406
1378
  for (const { httpHandler } of this.httpHandlerGroups) {
1407
- internalWorker.use(httpHandler);
1379
+ this.internalWorkerOrThrow.use(httpHandler);
1408
1380
  }
1409
1381
  }
1410
- interceptorsWithHandlers() {
1382
+ get interceptorsWithHandlers() {
1411
1383
  return this.httpHandlerGroups.map((group) => group.interceptor);
1412
1384
  }
1413
1385
  };
@@ -1420,12 +1392,12 @@ var RemoteHttpRequestHandler = class {
1420
1392
  __name(this, "RemoteHttpRequestHandler");
1421
1393
  }
1422
1394
  type = "remote";
1423
- _client;
1395
+ client;
1424
1396
  syncPromises = [];
1425
1397
  unsynced;
1426
1398
  synced;
1427
1399
  constructor(interceptor, method, path) {
1428
- this._client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
1400
+ this.client = new HttpRequestHandlerClient_default(interceptor, method, path, this);
1429
1401
  this.unsynced = this;
1430
1402
  this.synced = this.createSyncedProxy();
1431
1403
  }
@@ -1448,32 +1420,29 @@ var RemoteHttpRequestHandler = class {
1448
1420
  isHiddenPropertyWhenSynced(property) {
1449
1421
  return PENDING_PROPERTIES.has(property);
1450
1422
  }
1451
- client() {
1452
- return this._client;
1453
- }
1454
- method() {
1455
- return this._client.method();
1423
+ get method() {
1424
+ return this.client.method;
1456
1425
  }
1457
- path() {
1458
- return this._client.path();
1426
+ get path() {
1427
+ return this.client.path;
1459
1428
  }
1460
1429
  with(restriction) {
1461
- this._client.with(restriction);
1430
+ this.client.with(restriction);
1462
1431
  return this.unsynced;
1463
1432
  }
1464
1433
  respond(declaration) {
1465
1434
  const newUnsyncedThis = this.unsynced;
1466
- newUnsyncedThis._client.respond(declaration);
1435
+ newUnsyncedThis.client.respond(declaration);
1467
1436
  return newUnsyncedThis;
1468
1437
  }
1469
1438
  times(minNumberOfRequests, maxNumberOfRequests) {
1470
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
1439
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
1471
1440
  return this;
1472
1441
  }
1473
1442
  async checkTimes() {
1474
1443
  return new Promise((resolve, reject) => {
1475
1444
  try {
1476
- this._client.checkTimes();
1445
+ this.client.checkTimes();
1477
1446
  resolve();
1478
1447
  } catch (error) {
1479
1448
  reject(error);
@@ -1481,38 +1450,32 @@ var RemoteHttpRequestHandler = class {
1481
1450
  });
1482
1451
  }
1483
1452
  clear() {
1484
- this._client.clear();
1453
+ this.client.clear();
1485
1454
  return this.unsynced;
1486
1455
  }
1487
- requests() {
1488
- return new Promise((resolve, reject) => {
1489
- try {
1490
- resolve(this._client.requests());
1491
- } catch (error) {
1492
- reject(error);
1493
- }
1494
- });
1456
+ get requests() {
1457
+ return this.client.requests;
1495
1458
  }
1496
1459
  matchesRequest(request) {
1497
- return this._client.matchesRequest(request);
1460
+ return this.client.matchesRequest(request);
1498
1461
  }
1499
1462
  async applyResponseDeclaration(request) {
1500
- return this._client.applyResponseDeclaration(request);
1463
+ return this.client.applyResponseDeclaration(request);
1501
1464
  }
1502
1465
  saveInterceptedRequest(request, response) {
1503
- this._client.saveInterceptedRequest(request, response);
1466
+ this.client.saveInterceptedRequest(request, response);
1504
1467
  }
1505
1468
  registerSyncPromise(promise) {
1506
1469
  this.syncPromises.push(promise);
1507
1470
  }
1508
- isSynced() {
1471
+ get isSynced() {
1509
1472
  return this.syncPromises.length === 0;
1510
1473
  }
1511
1474
  then(onFulfilled, onRejected) {
1512
1475
  const promisesToWait = new Set(this.syncPromises);
1513
1476
  return Promise.all(promisesToWait).then(() => {
1514
1477
  this.syncPromises = this.syncPromises.filter((promise) => !promisesToWait.has(promise));
1515
- return this.isSynced() ? this.synced : this.unsynced;
1478
+ return this.isSynced ? this.synced : this.unsynced;
1516
1479
  }).then(onFulfilled, onRejected);
1517
1480
  }
1518
1481
  catch(onRejected) {
@@ -1533,9 +1496,9 @@ var HttpInterceptorClient = class {
1533
1496
  worker;
1534
1497
  store;
1535
1498
  _baseURL;
1536
- _isRunning = false;
1537
- _onUnhandledRequest;
1538
- _shouldSaveRequests = false;
1499
+ isRunning = false;
1500
+ onUnhandledRequest;
1501
+ shouldSaveRequests = false;
1539
1502
  Handler;
1540
1503
  handlerClientsByMethod = {
1541
1504
  GET: /* @__PURE__ */ new Map(),
@@ -1551,27 +1514,18 @@ var HttpInterceptorClient = class {
1551
1514
  this.store = options.store;
1552
1515
  this._baseURL = options.baseURL;
1553
1516
  this.Handler = options.Handler;
1554
- this._onUnhandledRequest = options.onUnhandledRequest;
1555
- this._shouldSaveRequests = options.saveRequests ?? false;
1517
+ this.onUnhandledRequest = options.onUnhandledRequest;
1518
+ this.shouldSaveRequests = options.saveRequests ?? false;
1556
1519
  }
1557
- baseURL() {
1520
+ get baseURLAsString() {
1558
1521
  const baseURL = this._baseURL;
1559
1522
  if (baseURL.href === `${baseURL.origin}/`) {
1560
1523
  return baseURL.origin;
1561
1524
  }
1562
- return baseURL.toString();
1563
- }
1564
- platform() {
1565
- return this.worker.platform();
1566
- }
1567
- onUnhandledRequest() {
1568
- return this._onUnhandledRequest;
1569
- }
1570
- isRunning() {
1571
- return this.worker.isRunning() && this._isRunning;
1525
+ return baseURL.href;
1572
1526
  }
1573
- shouldSaveRequests() {
1574
- return this._shouldSaveRequests;
1527
+ get platform() {
1528
+ return this.worker.platform;
1575
1529
  }
1576
1530
  async start() {
1577
1531
  await this.worker.start();
@@ -1592,11 +1546,11 @@ var HttpInterceptorClient = class {
1592
1546
  } else {
1593
1547
  this.store.markRemoteInterceptorAsRunning(this, isRunning, this._baseURL);
1594
1548
  }
1595
- this._isRunning = isRunning;
1549
+ this.isRunning = isRunning;
1596
1550
  }
1597
1551
  numberOfRunningInterceptors() {
1598
1552
  if (this.worker instanceof LocalHttpInterceptorWorker_default) {
1599
- return this.store.numberOfRunningLocalInterceptors();
1553
+ return this.store.numberOfRunningLocalInterceptors;
1600
1554
  } else {
1601
1555
  return this.store.numberOfRunningRemoteInterceptors(this._baseURL);
1602
1556
  }
@@ -1623,7 +1577,7 @@ var HttpInterceptorClient = class {
1623
1577
  return this.createHttpRequestHandler("OPTIONS", path);
1624
1578
  }
1625
1579
  createHttpRequestHandler(method, path) {
1626
- if (!this.isRunning()) {
1580
+ if (!this.isRunning) {
1627
1581
  throw new NotStartedHttpInterceptorError_default();
1628
1582
  }
1629
1583
  const handler = new this.Handler(this, method, path);
@@ -1631,24 +1585,24 @@ var HttpInterceptorClient = class {
1631
1585
  return handler;
1632
1586
  }
1633
1587
  registerRequestHandler(handler) {
1634
- const handlerClients = this.handlerClientsByMethod[handler.method()].get(handler.path()) ?? [];
1635
- const isAlreadyRegistered = handlerClients.includes(handler.client());
1588
+ const handlerClients = this.handlerClientsByMethod[handler.method].get(handler.path) ?? [];
1589
+ const isAlreadyRegistered = handlerClients.includes(handler.client);
1636
1590
  if (isAlreadyRegistered) {
1637
1591
  return;
1638
1592
  }
1639
- handlerClients.push(handler.client());
1593
+ handlerClients.push(handler.client);
1640
1594
  const isFirstHandlerForMethodPath = handlerClients.length === 1;
1641
1595
  if (!isFirstHandlerForMethodPath) {
1642
1596
  return;
1643
1597
  }
1644
- this.handlerClientsByMethod[handler.method()].set(handler.path(), handlerClients);
1645
- const url = joinURL_default(this.baseURL(), handler.path());
1598
+ this.handlerClientsByMethod[handler.method].set(handler.path, handlerClients);
1599
+ const url = joinURL_default(this.baseURLAsString, handler.path);
1646
1600
  const urlRegex = createRegExpFromURL_default(url);
1647
- const registrationResult = this.worker.use(this, handler.method(), url, async (context) => {
1601
+ const registrationResult = this.worker.use(this, handler.method, url, async (context) => {
1648
1602
  const response = await this.handleInterceptedRequest(
1649
1603
  urlRegex,
1650
- handler.method(),
1651
- handler.path(),
1604
+ handler.method,
1605
+ handler.path,
1652
1606
  context
1653
1607
  );
1654
1608
  return response;
@@ -1667,7 +1621,7 @@ var HttpInterceptorClient = class {
1667
1621
  }
1668
1622
  const responseDeclaration = await matchedHandler.applyResponseDeclaration(parsedRequest);
1669
1623
  const response = HttpInterceptorWorker_default.createResponseFromDeclaration(request, responseDeclaration);
1670
- if (this.shouldSaveRequests()) {
1624
+ if (this.shouldSaveRequests) {
1671
1625
  const responseClone = response.clone();
1672
1626
  const parsedResponse = await HttpInterceptorWorker_default.parseRawResponse(responseClone);
1673
1627
  matchedHandler.saveInterceptedRequest(parsedRequest, parsedResponse);
@@ -1695,7 +1649,7 @@ var HttpInterceptorClient = class {
1695
1649
  }
1696
1650
  }
1697
1651
  clear(options = {}) {
1698
- if (!this.isRunning()) {
1652
+ if (!this.isRunning) {
1699
1653
  throw new NotStartedHttpInterceptorError_default();
1700
1654
  }
1701
1655
  const clearResults = [];
@@ -1919,24 +1873,18 @@ var WebSocketHandler = class {
1919
1873
  __name(this, "WebSocketHandler");
1920
1874
  }
1921
1875
  sockets = /* @__PURE__ */ new Set();
1922
- _socketTimeout;
1923
- _messageTimeout;
1876
+ socketTimeout;
1877
+ messageTimeout;
1924
1878
  channelListeners = {};
1925
1879
  socketListeners = {
1926
1880
  messageAbort: /* @__PURE__ */ new Map()
1927
1881
  };
1928
1882
  constructor(options) {
1929
- this._socketTimeout = options.socketTimeout ?? DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT;
1930
- this._messageTimeout = options.messageTimeout ?? DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT;
1931
- }
1932
- socketTimeout() {
1933
- return this._socketTimeout;
1934
- }
1935
- messageTimeout() {
1936
- return this._messageTimeout;
1883
+ this.socketTimeout = options.socketTimeout ?? DEFAULT_WEB_SOCKET_LIFECYCLE_TIMEOUT;
1884
+ this.messageTimeout = options.messageTimeout ?? DEFAULT_WEB_SOCKET_MESSAGE_TIMEOUT;
1937
1885
  }
1938
1886
  async registerSocket(socket) {
1939
- const openPromise = waitForOpenClientSocket(socket, { timeout: this._socketTimeout });
1887
+ const openPromise = waitForOpenClientSocket(socket, { timeout: this.socketTimeout });
1940
1888
  const handleSocketMessage = /* @__PURE__ */ __name(async (rawMessage) => {
1941
1889
  await this.handleSocketMessage(socket, rawMessage);
1942
1890
  }, "handleSocketMessage");
@@ -2023,7 +1971,7 @@ var WebSocketHandler = class {
2023
1971
  }
2024
1972
  async closeClientSockets(sockets = this.sockets) {
2025
1973
  const closingPromises = Array.from(sockets, async (socket) => {
2026
- await closeClientSocket(socket, { timeout: this._socketTimeout });
1974
+ await closeClientSocket(socket, { timeout: this.socketTimeout });
2027
1975
  });
2028
1976
  await Promise.all(closingPromises);
2029
1977
  }
@@ -2055,9 +2003,9 @@ var WebSocketHandler = class {
2055
2003
  const replyTimeout = setTimeout(() => {
2056
2004
  this.offReply(channel, replyListener);
2057
2005
  this.offAbortSocketMessages(sockets, abortListener);
2058
- const timeoutError = new WebSocketMessageTimeoutError(this._messageTimeout);
2006
+ const timeoutError = new WebSocketMessageTimeoutError(this.messageTimeout);
2059
2007
  reject(timeoutError);
2060
- }, this._messageTimeout);
2008
+ }, this.messageTimeout);
2061
2009
  const abortListener = this.onAbortSocketMessages(sockets, (error) => {
2062
2010
  clearTimeout(replyTimeout);
2063
2011
  this.offReply(channel, replyListener);
@@ -2079,7 +2027,7 @@ var WebSocketHandler = class {
2079
2027
  }
2080
2028
  async reply(request, replyData, options) {
2081
2029
  const reply = await this.createReplyMessage(request, replyData);
2082
- if (this.isRunning()) {
2030
+ if (this.isRunning) {
2083
2031
  this.sendMessage(reply, options.sockets);
2084
2032
  }
2085
2033
  }
@@ -2094,7 +2042,7 @@ var WebSocketHandler = class {
2094
2042
  return replyMessage;
2095
2043
  }
2096
2044
  sendMessage(message, sockets = this.sockets) {
2097
- if (!this.isRunning()) {
2045
+ if (!this.isRunning) {
2098
2046
  throw new NotStartedWebSocketHandlerError_default();
2099
2047
  }
2100
2048
  const stringifiedMessage = JSON.stringify(message);
@@ -2175,7 +2123,7 @@ var WebSocketClient = class extends WebSocketHandler_default {
2175
2123
  this.url = new URL(options.url);
2176
2124
  validateURLProtocol_default(this.url, SUPPORTED_WEB_SOCKET_PROTOCOLS);
2177
2125
  }
2178
- isRunning() {
2126
+ get isRunning() {
2179
2127
  return this.socket !== void 0 && this.socket.readyState === this.socket.OPEN;
2180
2128
  }
2181
2129
  async start() {
@@ -2203,13 +2151,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2203
2151
  __name(this, "RemoteHttpInterceptorWorker");
2204
2152
  }
2205
2153
  type;
2206
- _webSocketClient;
2154
+ webSocketClient;
2207
2155
  httpHandlers = /* @__PURE__ */ new Map();
2208
2156
  constructor(options) {
2209
2157
  super();
2210
2158
  this.type = options.type;
2211
2159
  const webSocketServerURL = this.deriveWebSocketServerURL(options.serverURL);
2212
- this._webSocketClient = new WebSocketClient_default({
2160
+ this.webSocketClient = new WebSocketClient_default({
2213
2161
  url: webSocketServerURL.toString()
2214
2162
  });
2215
2163
  }
@@ -2218,17 +2166,13 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2218
2166
  webSocketServerURL.protocol = serverURL.protocol.replace(/^http(s)?:$/, "ws$1:");
2219
2167
  return webSocketServerURL;
2220
2168
  }
2221
- webSocketClient() {
2222
- return this._webSocketClient;
2223
- }
2224
2169
  async start() {
2225
2170
  await super.sharedStart(async () => {
2226
- await this._webSocketClient.start();
2227
- this._webSocketClient.onEvent("interceptors/responses/create", this.createResponse);
2228
- this._webSocketClient.onEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2229
- const platform = this.readPlatform();
2230
- super.setPlatform(platform);
2231
- super.setIsRunning(true);
2171
+ await this.webSocketClient.start();
2172
+ this.webSocketClient.onEvent("interceptors/responses/create", this.createResponse);
2173
+ this.webSocketClient.onEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2174
+ this.platform = this.readPlatform();
2175
+ this.isRunning = true;
2232
2176
  });
2233
2177
  }
2234
2178
  createResponse = /* @__PURE__ */ __name(async (message) => {
@@ -2267,14 +2211,14 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2267
2211
  async stop() {
2268
2212
  await super.sharedStop(async () => {
2269
2213
  await this.clearHandlers();
2270
- this._webSocketClient.offEvent("interceptors/responses/create", this.createResponse);
2271
- this._webSocketClient.offEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2272
- await this._webSocketClient.stop();
2273
- super.setIsRunning(false);
2214
+ this.webSocketClient.offEvent("interceptors/responses/create", this.createResponse);
2215
+ this.webSocketClient.offEvent("interceptors/responses/unhandled", this.handleUnhandledServerRequest);
2216
+ await this.webSocketClient.stop();
2217
+ this.isRunning = false;
2274
2218
  });
2275
2219
  }
2276
2220
  async use(interceptor, method, rawURL, createResponse) {
2277
- if (!super.isRunning()) {
2221
+ if (!this.isRunning) {
2278
2222
  throw new NotStartedHttpInterceptorError_default();
2279
2223
  }
2280
2224
  const crypto = await importCrypto();
@@ -2284,7 +2228,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2284
2228
  const handler = {
2285
2229
  id: crypto.randomUUID(),
2286
2230
  url: {
2287
- base: interceptor.baseURL(),
2231
+ base: interceptor.baseURLAsString,
2288
2232
  full: url.toString()
2289
2233
  },
2290
2234
  method,
@@ -2295,23 +2239,23 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2295
2239
  }
2296
2240
  };
2297
2241
  this.httpHandlers.set(handler.id, handler);
2298
- await this._webSocketClient.request("interceptors/workers/use/commit", {
2242
+ await this.webSocketClient.request("interceptors/workers/use/commit", {
2299
2243
  id: handler.id,
2300
2244
  url: handler.url,
2301
2245
  method
2302
2246
  });
2303
2247
  }
2304
2248
  async clearHandlers() {
2305
- if (!super.isRunning()) {
2249
+ if (!this.isRunning) {
2306
2250
  throw new NotStartedHttpInterceptorError_default();
2307
2251
  }
2308
2252
  this.httpHandlers.clear();
2309
- if (this._webSocketClient.isRunning()) {
2310
- await this._webSocketClient.request("interceptors/workers/use/reset", void 0);
2253
+ if (this.webSocketClient.isRunning) {
2254
+ await this.webSocketClient.request("interceptors/workers/use/reset", void 0);
2311
2255
  }
2312
2256
  }
2313
2257
  async clearInterceptorHandlers(interceptor) {
2314
- if (!super.isRunning()) {
2258
+ if (!this.isRunning) {
2315
2259
  throw new NotStartedHttpInterceptorError_default();
2316
2260
  }
2317
2261
  for (const handler of this.httpHandlers.values()) {
@@ -2319,16 +2263,16 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2319
2263
  this.httpHandlers.delete(handler.id);
2320
2264
  }
2321
2265
  }
2322
- if (this._webSocketClient.isRunning()) {
2266
+ if (this.webSocketClient.isRunning) {
2323
2267
  const groupsToRecommit = Array.from(this.httpHandlers.values(), (handler) => ({
2324
2268
  id: handler.id,
2325
2269
  url: handler.url,
2326
2270
  method: handler.method
2327
2271
  }));
2328
- await this._webSocketClient.request("interceptors/workers/use/reset", groupsToRecommit);
2272
+ await this.webSocketClient.request("interceptors/workers/use/reset", groupsToRecommit);
2329
2273
  }
2330
2274
  }
2331
- interceptorsWithHandlers() {
2275
+ get interceptorsWithHandlers() {
2332
2276
  const interceptors = Array.from(this.httpHandlers.values(), (handler) => handler.interceptor);
2333
2277
  return interceptors;
2334
2278
  }
@@ -2355,13 +2299,13 @@ var HttpInterceptorStore = class _HttpInterceptorStore {
2355
2299
  static remoteWorkers = /* @__PURE__ */ new Map();
2356
2300
  static runningRemoteInterceptors = /* @__PURE__ */ new Map();
2357
2301
  class = _HttpInterceptorStore;
2358
- localWorker() {
2302
+ get localWorker() {
2359
2303
  return this.class._localWorker;
2360
2304
  }
2361
2305
  remoteWorker(baseURL) {
2362
2306
  return this.class.remoteWorkers.get(baseURL.origin);
2363
2307
  }
2364
- numberOfRunningLocalInterceptors() {
2308
+ get numberOfRunningLocalInterceptors() {
2365
2309
  return this.class.runningLocalInterceptors.size;
2366
2310
  }
2367
2311
  numberOfRunningRemoteInterceptors(baseURL) {
@@ -2422,14 +2366,14 @@ var LocalHttpInterceptor = class {
2422
2366
  }
2423
2367
  type;
2424
2368
  store = new HttpInterceptorStore_default();
2425
- _client;
2369
+ client;
2426
2370
  constructor(options) {
2427
2371
  this.type = options.type;
2428
2372
  const baseURL = new URL(options.baseURL);
2429
2373
  validateURLProtocol_default(baseURL, SUPPORTED_BASE_URL_PROTOCOLS);
2430
2374
  excludeURLParams_default(baseURL);
2431
2375
  const worker = this.store.getOrCreateLocalWorker({});
2432
- this._client = new HttpInterceptorClient_default({
2376
+ this.client = new HttpInterceptorClient_default({
2433
2377
  worker,
2434
2378
  store: this.store,
2435
2379
  baseURL,
@@ -2438,57 +2382,54 @@ var LocalHttpInterceptor = class {
2438
2382
  saveRequests: options.saveRequests
2439
2383
  });
2440
2384
  }
2441
- client() {
2442
- return this._client;
2385
+ get baseURL() {
2386
+ return this.client.baseURLAsString;
2443
2387
  }
2444
- baseURL() {
2445
- return this._client.baseURL();
2388
+ get platform() {
2389
+ return this.client.platform;
2446
2390
  }
2447
- platform() {
2448
- return this._client.platform();
2449
- }
2450
- isRunning() {
2451
- return this._client.isRunning();
2391
+ get isRunning() {
2392
+ return this.client.isRunning;
2452
2393
  }
2453
2394
  async start() {
2454
- if (this.isRunning()) {
2395
+ if (this.isRunning) {
2455
2396
  return;
2456
2397
  }
2457
- await this._client.start();
2398
+ await this.client.start();
2458
2399
  }
2459
2400
  async stop() {
2460
- if (!this.isRunning()) {
2401
+ if (!this.isRunning) {
2461
2402
  return;
2462
2403
  }
2463
2404
  this.clear();
2464
- await this._client.stop();
2405
+ await this.client.stop();
2465
2406
  }
2466
2407
  get = /* @__PURE__ */ __name((path) => {
2467
- return this._client.get(path);
2408
+ return this.client.get(path);
2468
2409
  }, "get");
2469
2410
  post = /* @__PURE__ */ __name((path) => {
2470
- return this._client.post(path);
2411
+ return this.client.post(path);
2471
2412
  }, "post");
2472
2413
  patch = /* @__PURE__ */ __name((path) => {
2473
- return this._client.patch(path);
2414
+ return this.client.patch(path);
2474
2415
  }, "patch");
2475
2416
  put = /* @__PURE__ */ __name((path) => {
2476
- return this._client.put(path);
2417
+ return this.client.put(path);
2477
2418
  }, "put");
2478
2419
  delete = /* @__PURE__ */ __name((path) => {
2479
- return this._client.delete(path);
2420
+ return this.client.delete(path);
2480
2421
  }, "delete");
2481
2422
  head = /* @__PURE__ */ __name((path) => {
2482
- return this._client.head(path);
2423
+ return this.client.head(path);
2483
2424
  }, "head");
2484
2425
  options = /* @__PURE__ */ __name((path) => {
2485
- return this._client.options(path);
2426
+ return this.client.options(path);
2486
2427
  }, "options");
2487
2428
  checkTimes() {
2488
- this._client.checkTimes();
2429
+ this.client.checkTimes();
2489
2430
  }
2490
2431
  clear() {
2491
- this._client.clear();
2432
+ this.client.clear();
2492
2433
  }
2493
2434
  };
2494
2435
  var LocalHttpInterceptor_default = LocalHttpInterceptor;
@@ -2500,7 +2441,7 @@ var RemoteHttpInterceptor = class {
2500
2441
  }
2501
2442
  type;
2502
2443
  store = new HttpInterceptorStore_default();
2503
- _client;
2444
+ client;
2504
2445
  constructor(options) {
2505
2446
  this.type = options.type;
2506
2447
  const baseURL = new URL(options.baseURL);
@@ -2508,7 +2449,7 @@ var RemoteHttpInterceptor = class {
2508
2449
  excludeURLParams_default(baseURL);
2509
2450
  const serverURL = new URL(baseURL.origin);
2510
2451
  const worker = this.store.getOrCreateRemoteWorker({ serverURL });
2511
- this._client = new HttpInterceptorClient_default({
2452
+ this.client = new HttpInterceptorClient_default({
2512
2453
  worker,
2513
2454
  store: this.store,
2514
2455
  baseURL,
@@ -2517,56 +2458,53 @@ var RemoteHttpInterceptor = class {
2517
2458
  saveRequests: options.saveRequests
2518
2459
  });
2519
2460
  }
2520
- client() {
2521
- return this._client;
2522
- }
2523
- baseURL() {
2524
- return this._client.baseURL();
2461
+ get baseURL() {
2462
+ return this.client.baseURLAsString;
2525
2463
  }
2526
- platform() {
2527
- return this._client.platform();
2464
+ get platform() {
2465
+ return this.client.platform;
2528
2466
  }
2529
- isRunning() {
2530
- return this._client.isRunning();
2467
+ get isRunning() {
2468
+ return this.client.isRunning;
2531
2469
  }
2532
2470
  async start() {
2533
- if (this.isRunning()) {
2471
+ if (this.isRunning) {
2534
2472
  return;
2535
2473
  }
2536
- await this._client.start();
2474
+ await this.client.start();
2537
2475
  }
2538
2476
  async stop() {
2539
- if (!this.isRunning()) {
2477
+ if (!this.isRunning) {
2540
2478
  return;
2541
2479
  }
2542
2480
  await this.clear();
2543
- await this._client.stop();
2481
+ await this.client.stop();
2544
2482
  }
2545
2483
  get = /* @__PURE__ */ __name((path) => {
2546
- return this._client.get(path);
2484
+ return this.client.get(path);
2547
2485
  }, "get");
2548
2486
  post = /* @__PURE__ */ __name((path) => {
2549
- return this._client.post(path);
2487
+ return this.client.post(path);
2550
2488
  }, "post");
2551
2489
  patch = /* @__PURE__ */ __name((path) => {
2552
- return this._client.patch(path);
2490
+ return this.client.patch(path);
2553
2491
  }, "patch");
2554
2492
  put = /* @__PURE__ */ __name((path) => {
2555
- return this._client.put(path);
2493
+ return this.client.put(path);
2556
2494
  }, "put");
2557
2495
  delete = /* @__PURE__ */ __name((path) => {
2558
- return this._client.delete(path);
2496
+ return this.client.delete(path);
2559
2497
  }, "delete");
2560
2498
  head = /* @__PURE__ */ __name((path) => {
2561
- return this._client.head(path);
2499
+ return this.client.head(path);
2562
2500
  }, "head");
2563
2501
  options = /* @__PURE__ */ __name((path) => {
2564
- return this._client.options(path);
2502
+ return this.client.options(path);
2565
2503
  }, "options");
2566
2504
  checkTimes() {
2567
2505
  return new Promise((resolve, reject) => {
2568
2506
  try {
2569
- this._client.checkTimes();
2507
+ this.client.checkTimes();
2570
2508
  resolve();
2571
2509
  } catch (error) {
2572
2510
  reject(error);
@@ -2575,7 +2513,7 @@ var RemoteHttpInterceptor = class {
2575
2513
  }
2576
2514
  async clear() {
2577
2515
  await new Promise((resolve, reject) => {
2578
- this._client.clear({
2516
+ this.client.clear({
2579
2517
  onCommitSuccess: resolve,
2580
2518
  onCommitError: reject
2581
2519
  });