@zimic/interceptor 0.15.0-canary.0 → 0.15.0-canary.2

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 +10 -10
  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
@@ -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
  }
@@ -58,8 +58,7 @@ class HttpRequestHandlerClient<
58
58
 
59
59
  private numberOfMatchedRequests = 0;
60
60
  private unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[] = [];
61
- private interceptedRequests: InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] =
62
- [];
61
+ private _requests: InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] = [];
63
62
 
64
63
  private createResponseDeclaration?: HttpRequestHandlerResponseDeclarationFactory<
65
64
  Path,
@@ -69,19 +68,11 @@ class HttpRequestHandlerClient<
69
68
 
70
69
  constructor(
71
70
  private interceptor: HttpInterceptorClient<Schema>,
72
- private _method: Method,
73
- private _path: Path,
71
+ public method: Method,
72
+ public path: Path,
74
73
  private handler: InternalHttpRequestHandler<Schema, Method, Path, StatusCode>,
75
74
  ) {}
76
75
 
77
- method() {
78
- return this._method;
79
- }
80
-
81
- path() {
82
- return this._path;
83
- }
84
-
85
76
  with(restriction: HttpRequestHandlerRestriction<Schema, Method, Path>): this {
86
77
  this.restrictions.push(restriction);
87
78
  return this;
@@ -100,7 +91,7 @@ class HttpRequestHandlerClient<
100
91
 
101
92
  newThis.numberOfMatchedRequests = 0;
102
93
  newThis.unmatchedRequestGroups.length = 0;
103
- newThis.interceptedRequests.length = 0;
94
+ newThis._requests.length = 0;
104
95
 
105
96
  this.interceptor.registerRequestHandler(this.handler);
106
97
 
@@ -141,7 +132,7 @@ class HttpRequestHandlerClient<
141
132
  declarationPointer: this.timesDeclarationPointer,
142
133
  unmatchedRequestGroups: this.unmatchedRequestGroups,
143
134
  hasRestrictions: this.restrictions.length > 0,
144
- hasSavedRequests: this.interceptor.shouldSaveRequests(),
135
+ hasSavedRequests: this.interceptor.shouldSaveRequests,
145
136
  });
146
137
  }
147
138
  }
@@ -157,7 +148,7 @@ class HttpRequestHandlerClient<
157
148
 
158
149
  this.numberOfMatchedRequests = 0;
159
150
  this.unmatchedRequestGroups.length = 0;
160
- this.interceptedRequests.length = 0;
151
+ this._requests.length = 0;
161
152
 
162
153
  this.createResponseDeclaration = undefined;
163
154
 
@@ -177,7 +168,7 @@ class HttpRequestHandlerClient<
177
168
  this.numberOfMatchedRequests++;
178
169
  } else {
179
170
  const shouldSaveUnmatchedGroup =
180
- this.interceptor.shouldSaveRequests() &&
171
+ this.interceptor.shouldSaveRequests &&
181
172
  this.restrictions.length > 0 &&
182
173
  this.timesDeclarationPointer !== undefined;
183
174
 
@@ -388,7 +379,7 @@ class HttpRequestHandlerClient<
388
379
  response: HttpInterceptorResponse<Default<Schema[Path][Method]>, StatusCode>,
389
380
  ) {
390
381
  const interceptedRequest = this.createInterceptedRequest(request, response);
391
- this.interceptedRequests.push(interceptedRequest);
382
+ this._requests.push(interceptedRequest);
392
383
  }
393
384
 
394
385
  private createInterceptedRequest(
@@ -411,14 +402,12 @@ class HttpRequestHandlerClient<
411
402
  return interceptedRequest;
412
403
  }
413
404
 
414
- requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
415
- if (!this.interceptor.shouldSaveRequests()) {
405
+ get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
406
+ if (!this.interceptor.shouldSaveRequests) {
416
407
  throw new DisabledRequestSavingError();
417
408
  }
418
409
 
419
- const interceptedRequestsCopy = [...this.interceptedRequests];
420
- Object.freeze(interceptedRequestsCopy);
421
- return interceptedRequestsCopy;
410
+ return this._requests;
422
411
  }
423
412
  }
424
413
 
@@ -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 InterceptedHttpInterceptorRequest<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
 
@@ -27,7 +27,7 @@ class RemoteHttpRequestHandler<
27
27
  {
28
28
  readonly type = 'remote';
29
29
 
30
- private _client: HttpRequestHandlerClient<Schema, Method, Path, StatusCode>;
30
+ client: HttpRequestHandlerClient<Schema, Method, Path, StatusCode>;
31
31
 
32
32
  private syncPromises: Promise<unknown>[] = [];
33
33
 
@@ -35,7 +35,7 @@ class RemoteHttpRequestHandler<
35
35
  private synced: this;
36
36
 
37
37
  constructor(interceptor: HttpInterceptorClient<Schema, typeof RemoteHttpRequestHandler>, method: Method, path: Path) {
38
- this._client = new HttpRequestHandlerClient(interceptor, method, path, this);
38
+ this.client = new HttpRequestHandlerClient(interceptor, method, path, this);
39
39
  this.unsynced = this;
40
40
  this.synced = this.createSyncedProxy();
41
41
  }
@@ -62,20 +62,16 @@ class RemoteHttpRequestHandler<
62
62
  return PENDING_PROPERTIES.has(property);
63
63
  }
64
64
 
65
- client() {
66
- return this._client;
65
+ get method() {
66
+ return this.client.method;
67
67
  }
68
68
 
69
- method() {
70
- return this._client.method();
71
- }
72
-
73
- path() {
74
- return this._client.path();
69
+ get path() {
70
+ return this.client.path;
75
71
  }
76
72
 
77
73
  with(restriction: HttpRequestHandlerRestriction<Schema, Method, Path>): this {
78
- this._client.with(restriction);
74
+ this.client.with(restriction);
79
75
  return this.unsynced;
80
76
  }
81
77
 
@@ -85,19 +81,19 @@ class RemoteHttpRequestHandler<
85
81
  | HttpRequestHandlerResponseDeclarationFactory<Path, Default<Schema[Path][Method]>, NewStatusCode>,
86
82
  ): RemoteHttpRequestHandler<Schema, Method, Path, NewStatusCode> {
87
83
  const newUnsyncedThis = this.unsynced as unknown as RemoteHttpRequestHandler<Schema, Method, Path, NewStatusCode>;
88
- newUnsyncedThis._client.respond(declaration);
84
+ newUnsyncedThis.client.respond(declaration);
89
85
  return newUnsyncedThis;
90
86
  }
91
87
 
92
88
  times(minNumberOfRequests: number, maxNumberOfRequests?: number): this {
93
- this._client.times(minNumberOfRequests, maxNumberOfRequests);
89
+ this.client.times(minNumberOfRequests, maxNumberOfRequests);
94
90
  return this;
95
91
  }
96
92
 
97
93
  async checkTimes() {
98
94
  return new Promise<void>((resolve, reject) => {
99
95
  try {
100
- this._client.checkTimes();
96
+ this.client.checkTimes();
101
97
  resolve();
102
98
  } catch (error) {
103
99
  reject(error);
@@ -106,42 +102,36 @@ class RemoteHttpRequestHandler<
106
102
  }
107
103
 
108
104
  clear(): this {
109
- this._client.clear();
105
+ this.client.clear();
110
106
  return this.unsynced;
111
107
  }
112
108
 
113
- requests(): Promise<readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[]> {
114
- return new Promise((resolve, reject) => {
115
- try {
116
- resolve(this._client.requests());
117
- } catch (error) {
118
- reject(error);
119
- }
120
- });
109
+ get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[] {
110
+ return this.client.requests;
121
111
  }
122
112
 
123
113
  matchesRequest(request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>): Promise<boolean> {
124
- return this._client.matchesRequest(request);
114
+ return this.client.matchesRequest(request);
125
115
  }
126
116
 
127
117
  async applyResponseDeclaration(
128
118
  request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
129
119
  ): Promise<HttpRequestHandlerResponseDeclaration<Default<Schema[Path][Method]>, StatusCode>> {
130
- return this._client.applyResponseDeclaration(request);
120
+ return this.client.applyResponseDeclaration(request);
131
121
  }
132
122
 
133
123
  saveInterceptedRequest(
134
124
  request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
135
125
  response: HttpInterceptorResponse<Default<Schema[Path][Method]>, StatusCode>,
136
126
  ) {
137
- this._client.saveInterceptedRequest(request, response);
127
+ this.client.saveInterceptedRequest(request, response);
138
128
  }
139
129
 
140
130
  registerSyncPromise(promise: Promise<unknown>) {
141
131
  this.syncPromises.push(promise);
142
132
  }
143
133
 
144
- isSynced(): boolean {
134
+ get isSynced() {
145
135
  return this.syncPromises.length === 0;
146
136
  }
147
137
 
@@ -162,7 +152,7 @@ class RemoteHttpRequestHandler<
162
152
  .then(() => {
163
153
  this.syncPromises = this.syncPromises.filter((promise) => !promisesToWait.has(promise));
164
154
 
165
- return this.isSynced() ? this.synced : this.unsynced;
155
+ return this.isSynced ? this.synced : this.unsynced;
166
156
  })
167
157
  .then(onFulfilled, onRejected);
168
158
  }