@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
@@ -41,8 +41,9 @@ import { HttpResponseFactory } from './types/requests';
41
41
  abstract class HttpInterceptorWorker {
42
42
  abstract readonly type: 'local' | 'remote';
43
43
 
44
- private _platform: HttpInterceptorPlatform | null = null;
45
- private _isRunning = false;
44
+ platform: HttpInterceptorPlatform | null = null;
45
+ isRunning = false;
46
+
46
47
  private startingPromise?: Promise<void>;
47
48
  private stoppingPromise?: Promise<void>;
48
49
 
@@ -50,26 +51,10 @@ abstract class HttpInterceptorWorker {
50
51
 
51
52
  private runningInterceptors: AnyHttpInterceptorClient[] = [];
52
53
 
53
- platform() {
54
- return this._platform;
55
- }
56
-
57
- protected setPlatform(platform: HttpInterceptorPlatform) {
58
- this._platform = platform;
59
- }
60
-
61
- isRunning() {
62
- return this._isRunning;
63
- }
64
-
65
- protected setIsRunning(isRunning: boolean) {
66
- this._isRunning = isRunning;
67
- }
68
-
69
54
  abstract start(): Promise<void>;
70
55
 
71
56
  protected async sharedStart(internalStart: () => Promise<void>) {
72
- if (this.isRunning()) {
57
+ if (this.isRunning) {
73
58
  return;
74
59
  }
75
60
 
@@ -98,7 +83,7 @@ abstract class HttpInterceptorWorker {
98
83
  abstract stop(): Promise<void>;
99
84
 
100
85
  protected async sharedStop(internalStop: () => PossiblePromise<void>) {
101
- if (!this.isRunning()) {
86
+ if (!this.isRunning) {
102
87
  return;
103
88
  }
104
89
  if (this.stoppingPromise) {
@@ -194,8 +179,7 @@ abstract class HttpInterceptorWorker {
194
179
 
195
180
  private findInterceptorByRequestBaseURL(request: Request) {
196
181
  const interceptor = this.runningInterceptors.findLast((interceptor) => {
197
- const baseURL = interceptor.baseURL();
198
- return request.url.startsWith(baseURL);
182
+ return request.url.startsWith(interceptor.baseURLAsString);
199
183
  });
200
184
 
201
185
  return interceptor;
@@ -217,14 +201,12 @@ abstract class HttpInterceptorWorker {
217
201
  }
218
202
 
219
203
  private async getInterceptorUnhandledRequestStrategy(request: Request, interceptor: AnyHttpInterceptorClient) {
220
- const interceptorStrategyOrFactory = interceptor.onUnhandledRequest();
221
-
222
- if (typeof interceptorStrategyOrFactory === 'function') {
204
+ if (typeof interceptor.onUnhandledRequest === 'function') {
223
205
  const parsedRequest = await HttpInterceptorWorker.parseRawUnhandledRequest(request);
224
- return interceptorStrategyOrFactory(parsedRequest);
206
+ return interceptor.onUnhandledRequest(parsedRequest);
225
207
  }
226
208
 
227
- return interceptorStrategyOrFactory;
209
+ return interceptor.onUnhandledRequest;
228
210
  }
229
211
 
230
212
  abstract clearHandlers(): PossiblePromise<void>;
@@ -233,7 +215,7 @@ abstract class HttpInterceptorWorker {
233
215
  interceptor: HttpInterceptorClient<Schema>,
234
216
  ): PossiblePromise<void>;
235
217
 
236
- abstract interceptorsWithHandlers(): AnyHttpInterceptorClient[];
218
+ abstract get interceptorsWithHandlers(): AnyHttpInterceptorClient[];
237
219
 
238
220
  static createResponseFromDeclaration(
239
221
  request: Request,
@@ -19,7 +19,7 @@ import { BrowserHttpWorker, HttpResponseFactory, HttpWorker, NodeHttpWorker } fr
19
19
  class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
20
20
  readonly type: 'local';
21
21
 
22
- private _internalWorker?: HttpWorker;
22
+ private internalWorker?: HttpWorker;
23
23
 
24
24
  private defaultHttpHandler: MSWHttpHandler;
25
25
 
@@ -38,18 +38,18 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
38
38
  });
39
39
  }
40
40
 
41
- internalWorkerOrThrow() {
42
- if (!this._internalWorker) {
41
+ get internalWorkerOrThrow() {
42
+ if (!this.internalWorker) {
43
43
  throw new NotStartedHttpInterceptorError();
44
44
  }
45
- return this._internalWorker;
45
+ return this.internalWorker;
46
46
  }
47
47
 
48
- internalWorkerOrCreate() {
49
- if (!this._internalWorker) {
50
- this._internalWorker = this.createInternalWorker();
48
+ get internalWorkerOrCreate() {
49
+ if (!this.internalWorker) {
50
+ this.internalWorker = this.createInternalWorker();
51
51
  }
52
- return this._internalWorker;
52
+ return this.internalWorker;
53
53
  }
54
54
 
55
55
  private createInternalWorker() {
@@ -67,21 +67,21 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
67
67
 
68
68
  async start() {
69
69
  await super.sharedStart(async () => {
70
- const internalWorker = this.internalWorkerOrCreate();
70
+ const internalWorker = this.internalWorkerOrCreate;
71
71
 
72
72
  const sharedOptions: MSWWorkerSharedOptions = {
73
73
  onUnhandledRequest: 'bypass',
74
74
  };
75
75
 
76
76
  if (this.isInternalBrowserWorker(internalWorker)) {
77
- super.setPlatform('browser');
77
+ this.platform = 'browser';
78
78
  await this.startInBrowser(internalWorker, sharedOptions);
79
79
  } else {
80
- super.setPlatform('node');
80
+ this.platform = 'node';
81
81
  this.startInNode(internalWorker, sharedOptions);
82
82
  }
83
83
 
84
- super.setIsRunning(true);
84
+ this.isRunning = true;
85
85
  });
86
86
  }
87
87
 
@@ -106,7 +106,7 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
106
106
 
107
107
  async stop() {
108
108
  await super.sharedStop(() => {
109
- const internalWorker = this.internalWorkerOrCreate();
109
+ const internalWorker = this.internalWorkerOrCreate;
110
110
 
111
111
  if (this.isInternalBrowserWorker(internalWorker)) {
112
112
  this.stopInBrowser(internalWorker);
@@ -115,8 +115,8 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
115
115
  }
116
116
  this.clearHandlers();
117
117
 
118
- this._internalWorker = undefined;
119
- super.setIsRunning(false);
118
+ this.internalWorker = undefined;
119
+ this.isRunning = false;
120
120
  });
121
121
  }
122
122
 
@@ -133,7 +133,7 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
133
133
  }
134
134
 
135
135
  hasInternalBrowserWorker() {
136
- return this.isInternalBrowserWorker(this.internalWorkerOrThrow());
136
+ return this.isInternalBrowserWorker(this.internalWorkerOrThrow);
137
137
  }
138
138
 
139
139
  hasInternalNodeWorker() {
@@ -146,7 +146,6 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
146
146
  rawURL: string | URL,
147
147
  createResponse: HttpResponseFactory,
148
148
  ) {
149
- const internalWorker = this.internalWorkerOrThrow();
150
149
  const lowercaseMethod = method.toLowerCase<typeof method>();
151
150
 
152
151
  const url = new URL(rawURL);
@@ -180,7 +179,7 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
180
179
  return response;
181
180
  });
182
181
 
183
- internalWorker.use(httpHandler);
182
+ this.internalWorkerOrThrow.use(httpHandler);
184
183
 
185
184
  this.httpHandlerGroups.push({ interceptor, httpHandler });
186
185
  }
@@ -199,25 +198,22 @@ class LocalHttpInterceptorWorker extends HttpInterceptorWorker {
199
198
  }
200
199
 
201
200
  clearHandlers() {
202
- const internalWorker = this.internalWorkerOrThrow();
203
- internalWorker.resetHandlers();
201
+ this.internalWorkerOrThrow.resetHandlers();
204
202
  this.httpHandlerGroups = [];
205
203
  }
206
204
 
207
205
  clearInterceptorHandlers<Schema extends HttpSchema>(interceptor: HttpInterceptorClient<Schema>) {
208
- const internalWorker = this.internalWorkerOrThrow();
209
-
210
206
  const groupToRemoveIndex = this.httpHandlerGroups.findIndex((group) => group.interceptor === interceptor);
211
207
  removeArrayIndex(this.httpHandlerGroups, groupToRemoveIndex);
212
208
 
213
- internalWorker.resetHandlers();
209
+ this.internalWorkerOrThrow.resetHandlers();
214
210
 
215
211
  for (const { httpHandler } of this.httpHandlerGroups) {
216
- internalWorker.use(httpHandler);
212
+ this.internalWorkerOrThrow.use(httpHandler);
217
213
  }
218
214
  }
219
215
 
220
- interceptorsWithHandlers() {
216
+ get interceptorsWithHandlers() {
221
217
  return this.httpHandlerGroups.map((group) => group.interceptor);
222
218
  }
223
219
  }
@@ -28,7 +28,8 @@ interface HttpHandler {
28
28
  class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
29
29
  readonly type: 'remote';
30
30
 
31
- private _webSocketClient: WebSocketClient<InterceptorServerWebSocketSchema>;
31
+ webSocketClient: WebSocketClient<InterceptorServerWebSocketSchema>;
32
+
32
33
  private httpHandlers = new Map<HttpHandler['id'], HttpHandler>();
33
34
 
34
35
  constructor(options: RemoteHttpInterceptorWorkerOptions) {
@@ -36,7 +37,7 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
36
37
  this.type = options.type;
37
38
 
38
39
  const webSocketServerURL = this.deriveWebSocketServerURL(options.serverURL);
39
- this._webSocketClient = new WebSocketClient({
40
+ this.webSocketClient = new WebSocketClient({
40
41
  url: webSocketServerURL.toString(),
41
42
  });
42
43
  }
@@ -47,20 +48,15 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
47
48
  return webSocketServerURL;
48
49
  }
49
50
 
50
- webSocketClient() {
51
- return this._webSocketClient;
52
- }
53
-
54
51
  async start() {
55
52
  await super.sharedStart(async () => {
56
- await this._webSocketClient.start();
53
+ await this.webSocketClient.start();
57
54
 
58
- this._webSocketClient.onEvent('interceptors/responses/create', this.createResponse);
59
- this._webSocketClient.onEvent('interceptors/responses/unhandled', this.handleUnhandledServerRequest);
55
+ this.webSocketClient.onEvent('interceptors/responses/create', this.createResponse);
56
+ this.webSocketClient.onEvent('interceptors/responses/unhandled', this.handleUnhandledServerRequest);
60
57
 
61
- const platform = this.readPlatform();
62
- super.setPlatform(platform);
63
- super.setIsRunning(true);
58
+ this.platform = this.readPlatform();
59
+ this.isRunning = true;
64
60
  });
65
61
  }
66
62
 
@@ -118,12 +114,12 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
118
114
  await super.sharedStop(async () => {
119
115
  await this.clearHandlers();
120
116
 
121
- this._webSocketClient.offEvent('interceptors/responses/create', this.createResponse);
122
- this._webSocketClient.offEvent('interceptors/responses/unhandled', this.handleUnhandledServerRequest);
117
+ this.webSocketClient.offEvent('interceptors/responses/create', this.createResponse);
118
+ this.webSocketClient.offEvent('interceptors/responses/unhandled', this.handleUnhandledServerRequest);
123
119
 
124
- await this._webSocketClient.stop();
120
+ await this.webSocketClient.stop();
125
121
 
126
- super.setIsRunning(false);
122
+ this.isRunning = false;
127
123
  });
128
124
  }
129
125
 
@@ -133,7 +129,7 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
133
129
  rawURL: string | URL,
134
130
  createResponse: HttpResponseFactory,
135
131
  ) {
136
- if (!super.isRunning()) {
132
+ if (!this.isRunning) {
137
133
  throw new NotStartedHttpInterceptorError();
138
134
  }
139
135
 
@@ -146,7 +142,7 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
146
142
  const handler: HttpHandler = {
147
143
  id: crypto.randomUUID(),
148
144
  url: {
149
- base: interceptor.baseURL(),
145
+ base: interceptor.baseURLAsString,
150
146
  full: url.toString(),
151
147
  },
152
148
  method,
@@ -159,7 +155,7 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
159
155
 
160
156
  this.httpHandlers.set(handler.id, handler);
161
157
 
162
- await this._webSocketClient.request('interceptors/workers/use/commit', {
158
+ await this.webSocketClient.request('interceptors/workers/use/commit', {
163
159
  id: handler.id,
164
160
  url: handler.url,
165
161
  method,
@@ -167,19 +163,19 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
167
163
  }
168
164
 
169
165
  async clearHandlers() {
170
- if (!super.isRunning()) {
166
+ if (!this.isRunning) {
171
167
  throw new NotStartedHttpInterceptorError();
172
168
  }
173
169
 
174
170
  this.httpHandlers.clear();
175
171
 
176
- if (this._webSocketClient.isRunning()) {
177
- await this._webSocketClient.request('interceptors/workers/use/reset', undefined);
172
+ if (this.webSocketClient.isRunning) {
173
+ await this.webSocketClient.request('interceptors/workers/use/reset', undefined);
178
174
  }
179
175
  }
180
176
 
181
177
  async clearInterceptorHandlers<Schema extends HttpSchema>(interceptor: HttpInterceptorClient<Schema>) {
182
- if (!super.isRunning()) {
178
+ if (!this.isRunning) {
183
179
  throw new NotStartedHttpInterceptorError();
184
180
  }
185
181
 
@@ -189,18 +185,18 @@ class RemoteHttpInterceptorWorker extends HttpInterceptorWorker {
189
185
  }
190
186
  }
191
187
 
192
- if (this._webSocketClient.isRunning()) {
188
+ if (this.webSocketClient.isRunning) {
193
189
  const groupsToRecommit = Array.from<HttpHandler, HttpHandlerCommit>(this.httpHandlers.values(), (handler) => ({
194
190
  id: handler.id,
195
191
  url: handler.url,
196
192
  method: handler.method,
197
193
  }));
198
194
 
199
- await this._webSocketClient.request('interceptors/workers/use/reset', groupsToRecommit);
195
+ await this.webSocketClient.request('interceptors/workers/use/reset', groupsToRecommit);
200
196
  }
201
197
  }
202
198
 
203
- interceptorsWithHandlers() {
199
+ get interceptorsWithHandlers() {
204
200
  const interceptors = Array.from(this.httpHandlers.values(), (handler) => handler.interceptor);
205
201
  return interceptors;
206
202
  }
@@ -26,7 +26,7 @@ import {
26
26
  HttpInterceptorResponse,
27
27
  HttpRequestHandlerResponseDeclaration,
28
28
  HttpRequestHandlerResponseDeclarationFactory,
29
- TrackedHttpInterceptorRequest,
29
+ InterceptedHttpInterceptorRequest,
30
30
  } from './types/requests';
31
31
  import {
32
32
  HttpRequestHandlerRestriction,
@@ -58,7 +58,7 @@ class HttpRequestHandlerClient<
58
58
 
59
59
  private numberOfMatchedRequests = 0;
60
60
  private unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[] = [];
61
- private interceptedRequests: TrackedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] = [];
61
+ private _requests: InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] = [];
62
62
 
63
63
  private createResponseDeclaration?: HttpRequestHandlerResponseDeclarationFactory<
64
64
  Path,
@@ -68,19 +68,11 @@ class HttpRequestHandlerClient<
68
68
 
69
69
  constructor(
70
70
  private interceptor: HttpInterceptorClient<Schema>,
71
- private _method: Method,
72
- private _path: Path,
71
+ public method: Method,
72
+ public path: Path,
73
73
  private handler: InternalHttpRequestHandler<Schema, Method, Path, StatusCode>,
74
74
  ) {}
75
75
 
76
- method() {
77
- return this._method;
78
- }
79
-
80
- path() {
81
- return this._path;
82
- }
83
-
84
76
  with(restriction: HttpRequestHandlerRestriction<Schema, Method, Path>): this {
85
77
  this.restrictions.push(restriction);
86
78
  return this;
@@ -99,7 +91,7 @@ class HttpRequestHandlerClient<
99
91
 
100
92
  newThis.numberOfMatchedRequests = 0;
101
93
  newThis.unmatchedRequestGroups.length = 0;
102
- newThis.interceptedRequests.length = 0;
94
+ newThis._requests.length = 0;
103
95
 
104
96
  this.interceptor.registerRequestHandler(this.handler);
105
97
 
@@ -140,7 +132,7 @@ class HttpRequestHandlerClient<
140
132
  declarationPointer: this.timesDeclarationPointer,
141
133
  unmatchedRequestGroups: this.unmatchedRequestGroups,
142
134
  hasRestrictions: this.restrictions.length > 0,
143
- hasSavedRequests: this.interceptor.shouldSaveRequests(),
135
+ hasSavedRequests: this.interceptor.shouldSaveRequests,
144
136
  });
145
137
  }
146
138
  }
@@ -156,7 +148,7 @@ class HttpRequestHandlerClient<
156
148
 
157
149
  this.numberOfMatchedRequests = 0;
158
150
  this.unmatchedRequestGroups.length = 0;
159
- this.interceptedRequests.length = 0;
151
+ this._requests.length = 0;
160
152
 
161
153
  this.createResponseDeclaration = undefined;
162
154
 
@@ -176,7 +168,7 @@ class HttpRequestHandlerClient<
176
168
  this.numberOfMatchedRequests++;
177
169
  } else {
178
170
  const shouldSaveUnmatchedGroup =
179
- this.interceptor.shouldSaveRequests() &&
171
+ this.interceptor.shouldSaveRequests &&
180
172
  this.restrictions.length > 0 &&
181
173
  this.timesDeclarationPointer !== undefined;
182
174
 
@@ -387,14 +379,14 @@ class HttpRequestHandlerClient<
387
379
  response: HttpInterceptorResponse<Default<Schema[Path][Method]>, StatusCode>,
388
380
  ) {
389
381
  const interceptedRequest = this.createInterceptedRequest(request, response);
390
- this.interceptedRequests.push(interceptedRequest);
382
+ this._requests.push(interceptedRequest);
391
383
  }
392
384
 
393
385
  private createInterceptedRequest(
394
386
  request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
395
387
  response: HttpInterceptorResponse<Default<Schema[Path][Method]>, StatusCode>,
396
388
  ) {
397
- const interceptedRequest = request as unknown as TrackedHttpInterceptorRequest<
389
+ const interceptedRequest = request as unknown as InterceptedHttpInterceptorRequest<
398
390
  Path,
399
391
  Default<Schema[Path][Method]>,
400
392
  StatusCode
@@ -410,14 +402,12 @@ class HttpRequestHandlerClient<
410
402
  return interceptedRequest;
411
403
  }
412
404
 
413
- requests(): readonly TrackedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
414
- if (!this.interceptor.shouldSaveRequests()) {
405
+ get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
406
+ if (!this.interceptor.shouldSaveRequests) {
415
407
  throw new DisabledRequestSavingError();
416
408
  }
417
409
 
418
- const interceptedRequestsCopy = [...this.interceptedRequests];
419
- Object.freeze(interceptedRequestsCopy);
420
- return interceptedRequestsCopy;
410
+ return this._requests;
421
411
  }
422
412
  }
423
413
 
@@ -9,7 +9,7 @@ import {
9
9
  HttpInterceptorResponse,
10
10
  HttpRequestHandlerResponseDeclaration,
11
11
  HttpRequestHandlerResponseDeclarationFactory,
12
- TrackedHttpInterceptorRequest,
12
+ InterceptedHttpInterceptorRequest,
13
13
  } from './types/requests';
14
14
  import { HttpRequestHandlerRestriction } from './types/restrictions';
15
15
 
@@ -22,26 +22,22 @@ class LocalHttpRequestHandler<
22
22
  {
23
23
  readonly type = 'local';
24
24
 
25
- private _client: HttpRequestHandlerClient<Schema, Method, Path, StatusCode>;
25
+ client: HttpRequestHandlerClient<Schema, Method, Path, StatusCode>;
26
26
 
27
27
  constructor(interceptor: HttpInterceptorClient<Schema>, method: Method, path: Path) {
28
- this._client = new HttpRequestHandlerClient(interceptor, method, path, this);
28
+ this.client = new HttpRequestHandlerClient(interceptor, method, path, this);
29
29
  }
30
30
 
31
- client() {
32
- return this._client;
31
+ get method() {
32
+ return this.client.method;
33
33
  }
34
34
 
35
- method() {
36
- return this._client.method();
37
- }
38
-
39
- path() {
40
- return this._client.path();
35
+ get path() {
36
+ return this.client.path;
41
37
  }
42
38
 
43
39
  with(restriction: HttpRequestHandlerRestriction<Schema, Method, Path>): this {
44
- this._client.with(restriction);
40
+ this.client.with(restriction);
45
41
  return this;
46
42
  }
47
43
 
@@ -50,45 +46,45 @@ class LocalHttpRequestHandler<
50
46
  | HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, NewStatusCode>
51
47
  | HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>,
52
48
  ): LocalHttpRequestHandler<Schema, Method, Path, NewStatusCode> {
53
- this._client.respond(declaration);
49
+ this.client.respond(declaration);
54
50
 
55
51
  const newThis = this as unknown as LocalHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
56
52
  return newThis;
57
53
  }
58
54
 
59
55
  times(minNumberOfRequests: number, maxNumberOfRequests?: number): this {
60
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
56
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
61
57
  return this;
62
58
  }
63
59
 
64
60
  checkTimes() {
65
- this._client.checkTimes();
61
+ this.client.checkTimes();
66
62
  }
67
63
 
68
64
  clear(): this {
69
- this._client.clear();
65
+ this.client.clear();
70
66
  return this;
71
67
  }
72
68
 
73
- requests(): readonly TrackedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
74
- return this._client.requests();
69
+ get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
70
+ return this.client.requests;
75
71
  }
76
72
 
77
73
  matchesRequest(request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>): Promise<boolean> {
78
- return this._client.matchesRequest(request);
74
+ return this.client.matchesRequest(request);
79
75
  }
80
76
 
81
77
  async applyResponseDeclaration(
82
78
  request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
83
79
  ): Promise<HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, StatusCode>> {
84
- return this._client.applyResponseDeclaration(request);
80
+ return this.client.applyResponseDeclaration(request);
85
81
  }
86
82
 
87
83
  saveInterceptedRequest(
88
84
  request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
89
85
  response: HttpInterceptorResponse<Default<Schema[Path][Method]>, StatusCode>,
90
86
  ) {
91
- this._client.saveInterceptedRequest(request, response);
87
+ this.client.saveInterceptedRequest(request, response);
92
88
  }
93
89
  }
94
90