@blueprint-ts/core 4.1.0-beta.6 → 5.0.0

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 (62) hide show
  1. package/dist/bulkRequests/BulkRequestSender.js +81 -102
  2. package/dist/bulkRequests/BulkRequestWrapper.js +16 -26
  3. package/dist/laravel/pagination/dataDrivers/RequestDriver.js +1 -0
  4. package/dist/pagination/BasePaginator.js +4 -4
  5. package/dist/pagination/PageAwarePaginator.js +4 -1
  6. package/dist/pagination/StatePaginator.js +6 -3
  7. package/dist/pagination/dataDrivers/ArrayDriver.js +1 -0
  8. package/dist/pagination/dtos/PaginationDataDto.js +2 -0
  9. package/dist/pagination/dtos/StatePaginationDataDto.js +1 -0
  10. package/dist/pagination/frontendDrivers/VueBaseViewDriver.js +2 -0
  11. package/dist/pagination/frontendDrivers/VuePaginationDriver.js +6 -0
  12. package/dist/persistenceDrivers/LocalStorageDriver.js +1 -0
  13. package/dist/persistenceDrivers/MemoryPersistenceDriver.js +2 -1
  14. package/dist/persistenceDrivers/SessionStorageDriver.js +1 -0
  15. package/dist/requests/BaseRequest.js +93 -100
  16. package/dist/requests/ErrorHandler.js +21 -31
  17. package/dist/requests/RequestErrorRouter.js +12 -25
  18. package/dist/requests/bodies/BinaryBody.js +2 -0
  19. package/dist/requests/bodies/FormDataBody.js +1 -0
  20. package/dist/requests/bodies/JsonBody.js +1 -0
  21. package/dist/requests/drivers/fetch/FetchDriver.js +26 -26
  22. package/dist/requests/drivers/fetch/FetchResponse.js +7 -21
  23. package/dist/requests/drivers/mock/MockRequestDriver.js +190 -169
  24. package/dist/requests/drivers/mock/MockRequestTestHelpers.js +10 -4
  25. package/dist/requests/drivers/mock/MockResponseHandler.js +12 -23
  26. package/dist/requests/drivers/xhr/XMLHttpRequestDriver.js +68 -74
  27. package/dist/requests/drivers/xhr/XMLHttpRequestResponse.js +9 -21
  28. package/dist/requests/exceptions/InvalidJsonException.js +1 -0
  29. package/dist/requests/exceptions/ResponseBodyException.js +1 -0
  30. package/dist/requests/exceptions/ResponseException.js +1 -0
  31. package/dist/requests/exceptions/StaleResponseException.js +1 -0
  32. package/dist/requests/factories/BinaryBodyFactory.js +1 -0
  33. package/dist/requests/responses/BaseResponse.js +9 -21
  34. package/dist/requests/responses/BlobResponse.js +1 -0
  35. package/dist/support/DeferredPromise.js +5 -4
  36. package/dist/vue/composables/useConfirmDialog.js +7 -18
  37. package/dist/vue/composables/useGlobalCheckbox.js +55 -66
  38. package/dist/vue/forms/BaseForm.d.ts +11 -8
  39. package/dist/vue/forms/BaseForm.js +153 -149
  40. package/dist/vue/forms/PropertyAwareArray.js +0 -1
  41. package/dist/vue/forms/PropertyAwareObject.js +4 -2
  42. package/dist/vue/forms/index.d.ts +2 -2
  43. package/dist/vue/forms/persistence/types.d.ts +2 -0
  44. package/dist/vue/forms/validation/rules/BaseRule.js +3 -16
  45. package/dist/vue/forms/validation/rules/ConfirmedRule.js +2 -0
  46. package/dist/vue/forms/validation/rules/EmailRule.js +1 -0
  47. package/dist/vue/forms/validation/rules/JsonRule.js +2 -1
  48. package/dist/vue/forms/validation/rules/MinRule.js +2 -0
  49. package/dist/vue/forms/validation/rules/PrecognitiveRule.js +21 -31
  50. package/dist/vue/forms/validation/rules/RequiredRule.js +1 -0
  51. package/dist/vue/forms/validation/rules/UrlRule.js +2 -1
  52. package/dist/vue/requests/loaders/VueRequestBatchLoader.js +3 -3
  53. package/dist/vue/requests/loaders/VueRequestLoader.js +1 -0
  54. package/dist/vue/router/routeResourceBinding/RouteResourceBoundView.js +8 -18
  55. package/dist/vue/router/routeResourceBinding/RouteResourceRequestResolver.js +4 -14
  56. package/dist/vue/router/routeResourceBinding/defineRoute.js +8 -7
  57. package/dist/vue/router/routeResourceBinding/installRouteInjection.js +12 -21
  58. package/dist/vue/router/routeResourceBinding/useRouteResource.js +5 -17
  59. package/dist/vue/state/State.d.ts +2 -0
  60. package/dist/vue/state/State.js +24 -11
  61. package/dist/vue/state/index.d.ts +2 -1
  62. package/package.json +27 -27
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { ResponseException } from '../../exceptions/ResponseException';
11
2
  import { isEqual } from 'lodash-es';
12
3
  import { MockRequestAssertionError } from './MockRequestAssertionError';
@@ -45,8 +36,7 @@ function stringify(value) {
45
36
  return value === undefined ? 'undefined' : JSON.stringify(value, null, 2);
46
37
  }
47
38
  function getPredicateDescription(predicate) {
48
- var _a;
49
- return (_a = predicate.description) !== null && _a !== void 0 ? _a : '[custom matcher]';
39
+ return predicate.description ?? '[custom matcher]';
50
40
  }
51
41
  function getTextBody(body) {
52
42
  if (!body || body.kind !== 'text') {
@@ -62,7 +52,7 @@ function getJsonBody(body) {
62
52
  try {
63
53
  return JSON.parse(textBody);
64
54
  }
65
- catch (_a) {
55
+ catch {
66
56
  return undefined;
67
57
  }
68
58
  }
@@ -104,9 +94,11 @@ function isRecord(value) {
104
94
  return !!value && typeof value === 'object' && !Array.isArray(value);
105
95
  }
106
96
  export class MockRequestExpectationBuilder {
97
+ driver;
98
+ criteria;
107
99
  constructor(driver, criteria) {
108
100
  this.driver = driver;
109
- this.criteria = Object.assign({}, criteria);
101
+ this.criteria = { ...criteria };
110
102
  }
111
103
  withHeaders(headers) {
112
104
  this.criteria.headers = headers;
@@ -121,18 +113,22 @@ export class MockRequestExpectationBuilder {
121
113
  return this;
122
114
  }
123
115
  respond(response) {
124
- this.driver.expect(Object.assign(Object.assign({}, this.criteria), { response }));
116
+ this.driver.expect({
117
+ ...this.criteria,
118
+ response
119
+ });
125
120
  return this.driver;
126
121
  }
127
122
  }
128
123
  export class MockRequestDriver {
124
+ config;
125
+ expectations = [];
126
+ history = [];
127
+ matchMode;
129
128
  constructor(config, expectations = [], options = {}) {
130
- var _a;
131
129
  this.config = config;
132
- this.expectations = [];
133
- this.history = [];
134
130
  this.expectations.push(...expectations);
135
- this.matchMode = (_a = options.matchMode) !== null && _a !== void 0 ? _a : 'ordered';
131
+ this.matchMode = options.matchMode ?? 'ordered';
136
132
  }
137
133
  setMatchMode(mode) {
138
134
  this.matchMode = mode;
@@ -176,70 +172,63 @@ export class MockRequestDriver {
176
172
  `Next expected request: ${this.describeExpectation(nextExpectation)}`
177
173
  ].join('\n'));
178
174
  }
179
- send(url, method, headers, body, requestConfig) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- var _a;
182
- if ((_a = requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
183
- throw new DOMException('The operation was aborted.', 'AbortError');
184
- }
185
- const actualRequest = yield this.normalizeActualRequest(url, method, headers, body);
186
- const { index, expectation } = yield this.selectExpectation(actualRequest);
187
- this.expectations.splice(index, 1);
188
- this.history.push(this.toHistoryEntry(actualRequest));
189
- const response = new MockResponseHandler(expectation.response);
190
- if (!response.getRawResponse().ok) {
191
- throw new ResponseException(response);
192
- }
193
- return response;
194
- });
175
+ async send(url, method, headers, body, requestConfig) {
176
+ if (requestConfig?.abortSignal?.aborted) {
177
+ throw new DOMException('The operation was aborted.', 'AbortError');
178
+ }
179
+ const actualRequest = await this.normalizeActualRequest(url, method, headers, body);
180
+ const { index, expectation } = await this.selectExpectation(actualRequest);
181
+ this.expectations.splice(index, 1);
182
+ this.history.push(this.toHistoryEntry(actualRequest));
183
+ const response = new MockResponseHandler(expectation.response);
184
+ if (!response.getRawResponse().ok) {
185
+ throw new ResponseException(response);
186
+ }
187
+ return response;
195
188
  }
196
- selectExpectation(actualRequest) {
197
- return __awaiter(this, void 0, void 0, function* () {
198
- if (this.expectations.length === 0) {
189
+ async selectExpectation(actualRequest) {
190
+ if (this.expectations.length === 0) {
191
+ throw new MockRequestAssertionError(this.buildUnexpectedRequestMessage(actualRequest));
192
+ }
193
+ if (this.matchMode === 'ordered') {
194
+ const expectation = this.expectations[0];
195
+ if (!expectation) {
199
196
  throw new MockRequestAssertionError(this.buildUnexpectedRequestMessage(actualRequest));
200
197
  }
201
- if (this.matchMode === 'ordered') {
202
- const expectation = this.expectations[0];
203
- if (!expectation) {
204
- throw new MockRequestAssertionError(this.buildUnexpectedRequestMessage(actualRequest));
205
- }
206
- const failure = yield this.matchExpectation(expectation, actualRequest);
207
- if (failure) {
208
- throw new MockRequestAssertionError(this.buildMismatchMessage(failure, actualRequest));
209
- }
210
- return { index: 0, expectation };
198
+ const failure = await this.matchExpectation(expectation, actualRequest);
199
+ if (failure) {
200
+ throw new MockRequestAssertionError(this.buildMismatchMessage(failure, actualRequest));
211
201
  }
212
- const failures = [];
213
- for (const [index, expectation] of this.expectations.entries()) {
214
- const failure = yield this.matchExpectation(expectation, actualRequest);
215
- if (!failure) {
216
- return { index, expectation };
217
- }
218
- failures.push(failure);
202
+ return { index: 0, expectation };
203
+ }
204
+ const failures = [];
205
+ for (const [index, expectation] of this.expectations.entries()) {
206
+ const failure = await this.matchExpectation(expectation, actualRequest);
207
+ if (!failure) {
208
+ return { index, expectation };
219
209
  }
220
- throw new MockRequestAssertionError(this.buildUnorderedMismatchMessage(actualRequest, failures));
221
- });
210
+ failures.push(failure);
211
+ }
212
+ throw new MockRequestAssertionError(this.buildUnorderedMismatchMessage(actualRequest, failures));
222
213
  }
223
- matchExpectation(expectation, actualRequest) {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- const methodFailure = this.matchMethod(expectation.method, actualRequest, expectation);
226
- if (methodFailure) {
227
- return methodFailure;
228
- }
229
- const urlFailure = this.matchUrl(expectation, actualRequest);
230
- if (urlFailure) {
231
- return urlFailure;
232
- }
233
- const headersFailure = this.matchHeaders(expectation.headers, actualRequest, expectation);
234
- if (headersFailure) {
235
- return headersFailure;
236
- }
237
- const queryFailure = this.matchQuery(expectation.query, actualRequest, expectation);
238
- if (queryFailure) {
239
- return queryFailure;
240
- }
241
- return yield this.matchBody(expectation.body, actualRequest, expectation);
242
- });
214
+ async matchExpectation(expectation, actualRequest) {
215
+ const methodFailure = this.matchMethod(expectation.method, actualRequest, expectation);
216
+ if (methodFailure) {
217
+ return methodFailure;
218
+ }
219
+ const urlFailure = this.matchUrl(expectation, actualRequest);
220
+ if (urlFailure) {
221
+ return urlFailure;
222
+ }
223
+ const headersFailure = this.matchHeaders(expectation.headers, actualRequest, expectation);
224
+ if (headersFailure) {
225
+ return headersFailure;
226
+ }
227
+ const queryFailure = this.matchQuery(expectation.query, actualRequest, expectation);
228
+ if (queryFailure) {
229
+ return queryFailure;
230
+ }
231
+ return await this.matchBody(expectation.body, actualRequest, expectation);
243
232
  }
244
233
  matchMethod(method, actualRequest, expectation) {
245
234
  if (isPredicate(method)) {
@@ -347,46 +336,73 @@ export class MockRequestDriver {
347
336
  actualValue: actualRequest.query
348
337
  };
349
338
  }
350
- matchBody(body, actualRequest, expectation) {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- if (body === undefined) {
353
- return undefined;
354
- }
355
- if (isPredicate(body)) {
356
- const context = this.createBodyMatchContext(actualRequest);
357
- if (body(context)) {
358
- return undefined;
359
- }
360
- return {
361
- field: 'body',
362
- message: 'Body matcher returned false.',
363
- expectation,
364
- expectedValue: getPredicateDescription(body),
365
- actualValue: this.describeBodyForMessage(actualRequest.body)
366
- };
367
- }
368
- const expectedBody = yield this.normalizeBody(body);
369
- if (JSON.stringify(expectedBody) === JSON.stringify(actualRequest.body)) {
339
+ async matchBody(body, actualRequest, expectation) {
340
+ if (body === undefined) {
341
+ return undefined;
342
+ }
343
+ if (isPredicate(body)) {
344
+ const context = this.createBodyMatchContext(actualRequest);
345
+ if (body(context)) {
370
346
  return undefined;
371
347
  }
372
- const expectedJson = getJsonBody(expectedBody);
373
- const actualJson = getJsonBody(actualRequest.body);
374
- return Object.assign({ field: 'body', message: expectedJson !== undefined && actualJson !== undefined ? 'JSON body did not match.' : 'Body did not match exactly.', expectation, expectedValue: expectedJson !== null && expectedJson !== void 0 ? expectedJson : expectedBody, actualValue: actualJson !== null && actualJson !== void 0 ? actualJson : actualRequest.body }, (expectedJson !== undefined && actualJson !== undefined ? { diffPaths: collectJsonDiffPaths(expectedJson, actualJson) } : {}));
375
- });
348
+ return {
349
+ field: 'body',
350
+ message: 'Body matcher returned false.',
351
+ expectation,
352
+ expectedValue: getPredicateDescription(body),
353
+ actualValue: this.describeBodyForMessage(actualRequest.body)
354
+ };
355
+ }
356
+ const expectedBody = await this.normalizeBody(body);
357
+ if (JSON.stringify(expectedBody) === JSON.stringify(actualRequest.body)) {
358
+ return undefined;
359
+ }
360
+ const expectedJson = getJsonBody(expectedBody);
361
+ const actualJson = getJsonBody(actualRequest.body);
362
+ return {
363
+ field: 'body',
364
+ message: expectedJson !== undefined && actualJson !== undefined ? 'JSON body did not match.' : 'Body did not match exactly.',
365
+ expectation,
366
+ expectedValue: expectedJson ?? expectedBody,
367
+ actualValue: actualJson ?? actualRequest.body,
368
+ ...(expectedJson !== undefined && actualJson !== undefined ? { diffPaths: collectJsonDiffPaths(expectedJson, actualJson) } : {})
369
+ };
376
370
  }
377
371
  createBodyMatchContext(actualRequest) {
378
- return Object.assign(Object.assign({ method: actualRequest.method, url: actualRequest.url, headers: actualRequest.headers }, (actualRequest.body !== undefined ? { body: actualRequest.body } : {})), { getJson: () => getJsonBody(actualRequest.body), getText: () => getTextBody(actualRequest.body), getQuery: () => actualRequest.query });
379
- }
380
- normalizeActualRequest(url, method, headers, body) {
381
- return __awaiter(this, void 0, void 0, function* () {
382
- var _a;
383
- const resolvedUrl = parseUrl(url);
384
- const normalizedBody = yield this.normalizeBody(body === null || body === void 0 ? void 0 : body.getContent());
385
- return Object.assign({ method, url: this.normalizeUrl(url), urlWithoutQuery: buildUrlWithoutQuery(resolvedUrl), parsedUrl: resolvedUrl, headers: this.resolveHeaders(Object.assign(Object.assign(Object.assign({}, (_a = this.config) === null || _a === void 0 ? void 0 : _a.headers), headers), body === null || body === void 0 ? void 0 : body.getHeaders())), query: parseQuery(resolvedUrl) }, (normalizedBody !== undefined ? { body: normalizedBody } : {}));
386
- });
372
+ return {
373
+ method: actualRequest.method,
374
+ url: actualRequest.url,
375
+ headers: actualRequest.headers,
376
+ ...(actualRequest.body !== undefined ? { body: actualRequest.body } : {}),
377
+ getJson: () => getJsonBody(actualRequest.body),
378
+ getText: () => getTextBody(actualRequest.body),
379
+ getQuery: () => actualRequest.query
380
+ };
381
+ }
382
+ async normalizeActualRequest(url, method, headers, body) {
383
+ const resolvedUrl = parseUrl(url);
384
+ const normalizedBody = await this.normalizeBody(body?.getContent());
385
+ return {
386
+ method,
387
+ url: this.normalizeUrl(url),
388
+ urlWithoutQuery: buildUrlWithoutQuery(resolvedUrl),
389
+ parsedUrl: resolvedUrl,
390
+ headers: this.resolveHeaders({
391
+ ...this.config?.headers,
392
+ ...headers,
393
+ ...body?.getHeaders()
394
+ }),
395
+ query: parseQuery(resolvedUrl),
396
+ ...(normalizedBody !== undefined ? { body: normalizedBody } : {})
397
+ };
387
398
  }
388
399
  toHistoryEntry(request) {
389
- return Object.assign({ method: request.method, url: request.url, headers: request.headers }, (request.body !== undefined ? { body: request.body } : {}));
400
+ return {
401
+ method: request.method,
402
+ url: request.url,
403
+ headers: request.headers,
404
+ ...(request.body !== undefined ? { body: request.body } : {})
405
+ };
390
406
  }
391
407
  buildUnexpectedRequestMessage(actualRequest) {
392
408
  return ['Unexpected request received with no expectations left.', '', 'Actual request:', this.formatRequestSnapshot(actualRequest)].join('\n');
@@ -477,7 +493,7 @@ export class MockRequestDriver {
477
493
  }
478
494
  describeBodyForMessage(body) {
479
495
  const json = getJsonBody(body);
480
- return json !== null && json !== void 0 ? json : body;
496
+ return json ?? body;
481
497
  }
482
498
  normalizeUrl(url) {
483
499
  return parseUrl(url).toString();
@@ -493,51 +509,55 @@ export class MockRequestDriver {
493
509
  }
494
510
  return resolved;
495
511
  }
496
- normalizeBody(body) {
497
- return __awaiter(this, void 0, void 0, function* () {
498
- if (body === undefined) {
499
- return undefined;
500
- }
501
- if (body === null) {
502
- return { kind: 'null' };
503
- }
504
- if (typeof body === 'string') {
505
- return { kind: 'text', value: body };
506
- }
507
- if (body instanceof FormData) {
508
- return yield this.normalizeFormData(body);
509
- }
510
- if (body instanceof Blob) {
511
- const mimeType = body.type || undefined;
512
- return Object.assign(Object.assign({ kind: 'binary' }, (mimeType !== undefined ? { mimeType } : {})), { bytes: Array.from(new Uint8Array(yield this.readBlob(body))) });
513
- }
514
- if (this.isBufferSource(body)) {
515
- return {
516
- kind: 'binary',
517
- bytes: Array.from(new Uint8Array(this.toArrayBuffer(body)))
518
- };
519
- }
512
+ async normalizeBody(body) {
513
+ if (body === undefined) {
514
+ return undefined;
515
+ }
516
+ if (body === null) {
517
+ return { kind: 'null' };
518
+ }
519
+ if (typeof body === 'string') {
520
+ return { kind: 'text', value: body };
521
+ }
522
+ if (body instanceof FormData) {
523
+ return await this.normalizeFormData(body);
524
+ }
525
+ if (body instanceof Blob) {
526
+ const mimeType = body.type || undefined;
520
527
  return {
521
- kind: 'text',
522
- value: JSON.stringify(body)
528
+ kind: 'binary',
529
+ ...(mimeType !== undefined ? { mimeType } : {}),
530
+ bytes: Array.from(new Uint8Array(await this.readBlob(body)))
523
531
  };
524
- });
532
+ }
533
+ if (this.isBufferSource(body)) {
534
+ return {
535
+ kind: 'binary',
536
+ bytes: Array.from(new Uint8Array(this.toArrayBuffer(body)))
537
+ };
538
+ }
539
+ return {
540
+ kind: 'text',
541
+ value: JSON.stringify(body)
542
+ };
525
543
  }
526
- normalizeFormData(body) {
527
- return __awaiter(this, void 0, void 0, function* () {
528
- const entries = [];
529
- for (const [key, value] of body.entries()) {
530
- if (typeof value === 'string') {
531
- entries.push({ key, value: { kind: 'text', value } });
532
- continue;
533
- }
534
- entries.push({
535
- key,
536
- value: Object.assign(Object.assign({ kind: 'file' }, this.getOptionalBlobDetails(value)), { bytes: Array.from(new Uint8Array(yield this.readBlob(value))) })
537
- });
544
+ async normalizeFormData(body) {
545
+ const entries = [];
546
+ for (const [key, value] of body.entries()) {
547
+ if (typeof value === 'string') {
548
+ entries.push({ key, value: { kind: 'text', value } });
549
+ continue;
538
550
  }
539
- return { kind: 'form-data', entries };
540
- });
551
+ entries.push({
552
+ key,
553
+ value: {
554
+ kind: 'file',
555
+ ...this.getOptionalBlobDetails(value),
556
+ bytes: Array.from(new Uint8Array(await this.readBlob(value)))
557
+ }
558
+ });
559
+ }
560
+ return { kind: 'form-data', entries };
541
561
  }
542
562
  getBlobName(value) {
543
563
  if (typeof File !== 'undefined' && value instanceof File) {
@@ -548,24 +568,25 @@ export class MockRequestDriver {
548
568
  getOptionalBlobDetails(value) {
549
569
  const name = this.getBlobName(value);
550
570
  const mimeType = value.type || undefined;
551
- return Object.assign(Object.assign({}, (name !== undefined ? { name } : {})), (mimeType !== undefined ? { mimeType } : {}));
571
+ return {
572
+ ...(name !== undefined ? { name } : {}),
573
+ ...(mimeType !== undefined ? { mimeType } : {})
574
+ };
552
575
  }
553
- readBlob(value) {
554
- return __awaiter(this, void 0, void 0, function* () {
555
- const blobWithReader = value;
556
- if (typeof blobWithReader.arrayBuffer === 'function') {
557
- return yield blobWithReader.arrayBuffer();
558
- }
559
- if (typeof FileReader !== 'undefined') {
560
- return yield new Promise((resolve, reject) => {
561
- const reader = new FileReader();
562
- reader.onload = () => resolve(reader.result);
563
- reader.onerror = () => { var _a; return reject((_a = reader.error) !== null && _a !== void 0 ? _a : new Error('Failed to read Blob contents.')); };
564
- reader.readAsArrayBuffer(value);
565
- });
566
- }
567
- return yield new Response(value).arrayBuffer();
568
- });
576
+ async readBlob(value) {
577
+ const blobWithReader = value;
578
+ if (typeof blobWithReader.arrayBuffer === 'function') {
579
+ return await blobWithReader.arrayBuffer();
580
+ }
581
+ if (typeof FileReader !== 'undefined') {
582
+ return await new Promise((resolve, reject) => {
583
+ const reader = new FileReader();
584
+ reader.onload = () => resolve(reader.result);
585
+ reader.onerror = () => reject(reader.error ?? new Error('Failed to read Blob contents.'));
586
+ reader.readAsArrayBuffer(value);
587
+ });
588
+ }
589
+ return await new Response(value).arrayBuffer();
569
590
  }
570
591
  isBufferSource(value) {
571
592
  return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
@@ -40,7 +40,11 @@ export function expectJsonBody(expected, options = {}) {
40
40
  });
41
41
  }
42
42
  export function jsonResponse(status, body, headers) {
43
- return Object.assign(Object.assign({ status }, (headers !== undefined ? { headers } : {})), { body });
43
+ return {
44
+ status,
45
+ ...(headers !== undefined ? { headers } : {}),
46
+ body
47
+ };
44
48
  }
45
49
  export function validationError(errors, message = 'The given data was invalid.') {
46
50
  return jsonResponse(422, {
@@ -49,12 +53,14 @@ export function validationError(errors, message = 'The given data was invalid.')
49
53
  });
50
54
  }
51
55
  export function emptyResponse(status = 204, headers) {
52
- return Object.assign({ status }, (headers !== undefined ? { headers } : {}));
56
+ return {
57
+ status,
58
+ ...(headers !== undefined ? { headers } : {})
59
+ };
53
60
  }
54
61
  let installedMockRequestDriver;
55
62
  export function installMockRequestDriver(options = {}) {
56
- var _a;
57
- const driver = new MockRequestDriver(options.config, (_a = options.expectations) !== null && _a !== void 0 ? _a : [], options.matchMode !== undefined ? { matchMode: options.matchMode } : {});
63
+ const driver = new MockRequestDriver(options.config, options.expectations ?? [], options.matchMode !== undefined ? { matchMode: options.matchMode } : {});
58
64
  BaseRequest.setRequestDriver(driver);
59
65
  installedMockRequestDriver = driver;
60
66
  return driver;
@@ -1,18 +1,13 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class MockResponseHandler {
2
+ response;
11
3
  constructor(definition) {
12
- var _a;
13
4
  const headers = new Headers(definition.headers);
14
5
  const body = this.resolveBody(definition.body, headers);
15
- this.response = new Response(body, Object.assign({ status: (_a = definition.status) !== null && _a !== void 0 ? _a : 200, headers }, (definition.statusText !== undefined ? { statusText: definition.statusText } : {})));
6
+ this.response = new Response(body, {
7
+ status: definition.status ?? 200,
8
+ headers,
9
+ ...(definition.statusText !== undefined ? { statusText: definition.statusText } : {})
10
+ });
16
11
  }
17
12
  getStatusCode() {
18
13
  return this.response.status;
@@ -23,20 +18,14 @@ export class MockResponseHandler {
23
18
  getRawResponse() {
24
19
  return this.response;
25
20
  }
26
- json() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return yield this.response.clone().json();
29
- });
21
+ async json() {
22
+ return await this.response.clone().json();
30
23
  }
31
- text() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return yield this.response.clone().text();
34
- });
24
+ async text() {
25
+ return await this.response.clone().text();
35
26
  }
36
- blob() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- return yield this.response.clone().blob();
39
- });
27
+ async blob() {
28
+ return await this.response.clone().blob();
40
29
  }
41
30
  resolveBody(body, headers) {
42
31
  if (body === undefined || body === null) {