@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.
- package/dist/bulkRequests/BulkRequestSender.js +81 -102
- package/dist/bulkRequests/BulkRequestWrapper.js +16 -26
- package/dist/laravel/pagination/dataDrivers/RequestDriver.js +1 -0
- package/dist/pagination/BasePaginator.js +4 -4
- package/dist/pagination/PageAwarePaginator.js +4 -1
- package/dist/pagination/StatePaginator.js +6 -3
- package/dist/pagination/dataDrivers/ArrayDriver.js +1 -0
- package/dist/pagination/dtos/PaginationDataDto.js +2 -0
- package/dist/pagination/dtos/StatePaginationDataDto.js +1 -0
- package/dist/pagination/frontendDrivers/VueBaseViewDriver.js +2 -0
- package/dist/pagination/frontendDrivers/VuePaginationDriver.js +6 -0
- package/dist/persistenceDrivers/LocalStorageDriver.js +1 -0
- package/dist/persistenceDrivers/MemoryPersistenceDriver.js +2 -1
- package/dist/persistenceDrivers/SessionStorageDriver.js +1 -0
- package/dist/requests/BaseRequest.js +93 -100
- package/dist/requests/ErrorHandler.js +21 -31
- package/dist/requests/RequestErrorRouter.js +12 -25
- package/dist/requests/bodies/BinaryBody.js +2 -0
- package/dist/requests/bodies/FormDataBody.js +1 -0
- package/dist/requests/bodies/JsonBody.js +1 -0
- package/dist/requests/drivers/fetch/FetchDriver.js +26 -26
- package/dist/requests/drivers/fetch/FetchResponse.js +7 -21
- package/dist/requests/drivers/mock/MockRequestDriver.js +190 -169
- package/dist/requests/drivers/mock/MockRequestTestHelpers.js +10 -4
- package/dist/requests/drivers/mock/MockResponseHandler.js +12 -23
- package/dist/requests/drivers/xhr/XMLHttpRequestDriver.js +68 -74
- package/dist/requests/drivers/xhr/XMLHttpRequestResponse.js +9 -21
- package/dist/requests/exceptions/InvalidJsonException.js +1 -0
- package/dist/requests/exceptions/ResponseBodyException.js +1 -0
- package/dist/requests/exceptions/ResponseException.js +1 -0
- package/dist/requests/exceptions/StaleResponseException.js +1 -0
- package/dist/requests/factories/BinaryBodyFactory.js +1 -0
- package/dist/requests/responses/BaseResponse.js +9 -21
- package/dist/requests/responses/BlobResponse.js +1 -0
- package/dist/support/DeferredPromise.js +5 -4
- package/dist/vue/composables/useConfirmDialog.js +7 -18
- package/dist/vue/composables/useGlobalCheckbox.js +55 -66
- package/dist/vue/forms/BaseForm.d.ts +11 -8
- package/dist/vue/forms/BaseForm.js +153 -149
- package/dist/vue/forms/PropertyAwareArray.js +0 -1
- package/dist/vue/forms/PropertyAwareObject.js +4 -2
- package/dist/vue/forms/index.d.ts +2 -2
- package/dist/vue/forms/persistence/types.d.ts +2 -0
- package/dist/vue/forms/validation/rules/BaseRule.js +3 -16
- package/dist/vue/forms/validation/rules/ConfirmedRule.js +2 -0
- package/dist/vue/forms/validation/rules/EmailRule.js +1 -0
- package/dist/vue/forms/validation/rules/JsonRule.js +2 -1
- package/dist/vue/forms/validation/rules/MinRule.js +2 -0
- package/dist/vue/forms/validation/rules/PrecognitiveRule.js +21 -31
- package/dist/vue/forms/validation/rules/RequiredRule.js +1 -0
- package/dist/vue/forms/validation/rules/UrlRule.js +2 -1
- package/dist/vue/requests/loaders/VueRequestBatchLoader.js +3 -3
- package/dist/vue/requests/loaders/VueRequestLoader.js +1 -0
- package/dist/vue/router/routeResourceBinding/RouteResourceBoundView.js +8 -18
- package/dist/vue/router/routeResourceBinding/RouteResourceRequestResolver.js +4 -14
- package/dist/vue/router/routeResourceBinding/defineRoute.js +8 -7
- package/dist/vue/router/routeResourceBinding/installRouteInjection.js +12 -21
- package/dist/vue/router/routeResourceBinding/useRouteResource.js +5 -17
- package/dist/vue/state/State.d.ts +2 -0
- package/dist/vue/state/State.js +24 -11
- package/dist/vue/state/index.d.ts +2 -1
- 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
|
-
|
|
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
|
|
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 =
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
198
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
221
|
-
}
|
|
210
|
+
failures.push(failure);
|
|
211
|
+
}
|
|
212
|
+
throw new MockRequestAssertionError(this.buildUnorderedMismatchMessage(actualRequest, failures));
|
|
222
213
|
}
|
|
223
|
-
matchExpectation(expectation, actualRequest) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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: '
|
|
522
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
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
|
|
571
|
+
return {
|
|
572
|
+
...(name !== undefined ? { name } : {}),
|
|
573
|
+
...(mimeType !== undefined ? { mimeType } : {})
|
|
574
|
+
};
|
|
552
575
|
}
|
|
553
|
-
readBlob(value) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
|
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
|
|
56
|
+
return {
|
|
57
|
+
status,
|
|
58
|
+
...(headers !== undefined ? { headers } : {})
|
|
59
|
+
};
|
|
53
60
|
}
|
|
54
61
|
let installedMockRequestDriver;
|
|
55
62
|
export function installMockRequestDriver(options = {}) {
|
|
56
|
-
|
|
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,
|
|
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
|
|
28
|
-
return yield this.response.clone().json();
|
|
29
|
-
});
|
|
21
|
+
async json() {
|
|
22
|
+
return await this.response.clone().json();
|
|
30
23
|
}
|
|
31
|
-
text() {
|
|
32
|
-
return
|
|
33
|
-
return yield this.response.clone().text();
|
|
34
|
-
});
|
|
24
|
+
async text() {
|
|
25
|
+
return await this.response.clone().text();
|
|
35
26
|
}
|
|
36
|
-
blob() {
|
|
37
|
-
return
|
|
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) {
|