@ethlete/query 0.1.0-next.21 → 0.1.0-next.23
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/esm2020/lib/directives/query.directive.mjs +4 -1
- package/esm2020/lib/query/query.mjs +76 -77
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query-form/query-form.mjs +2 -2
- package/esm2020/lib/request/request.mjs +168 -19
- package/esm2020/lib/request/request.types.mjs +1 -1
- package/esm2020/lib/request/request.util.mjs +66 -91
- package/fesm2015/ethlete-query.mjs +316 -191
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +309 -184
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/lib/directives/query.directive.d.ts +2 -1
- package/lib/query/query.d.ts +2 -4
- package/lib/query/query.types.d.ts +47 -29
- package/lib/request/request.d.ts +3 -9
- package/lib/request/request.types.d.ts +51 -7
- package/lib/request/request.util.d.ts +74 -7
- package/package.json +3 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCookie, setCookie, deleteCookie, DestroyService, equal, clone } from '@ethlete/core';
|
|
2
|
-
import { filter, takeWhile, switchMap, of, BehaviorSubject, Subject,
|
|
2
|
+
import { Observable, filter, takeWhile, switchMap, of, BehaviorSubject, Subject, takeUntil, interval, tap, timer, fromEvent, startWith, concat, take, debounceTime, combineLatest, map, distinctUntilChanged } from 'rxjs';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Directive, Input, InjectionToken, inject, ChangeDetectorRef, ViewContainerRef, TemplateRef, ErrorHandler, ElementRef } from '@angular/core';
|
|
5
5
|
import { FormGroup } from '@angular/forms';
|
|
@@ -72,7 +72,6 @@ const queryStateCannotTransformError = (data) => new QueryError('006', 'The quer
|
|
|
72
72
|
const invalidBodyError = (data) => new QueryError('007', 'The body is not valid or upsupported', data);
|
|
73
73
|
|
|
74
74
|
const isRequestError = (error) => error instanceof Object && 'code' in error && 'message' in error;
|
|
75
|
-
const isAbortRequestError = (error) => isRequestError(error) && error.code === -1;
|
|
76
75
|
const buildRoute = (options) => {
|
|
77
76
|
if (options.base.endsWith('/')) {
|
|
78
77
|
throw invalidBaseRouteError(options.base);
|
|
@@ -145,9 +144,9 @@ const isParamValid = (primitive) => {
|
|
|
145
144
|
return true;
|
|
146
145
|
};
|
|
147
146
|
const extractExpiresInSeconds = (headers) => {
|
|
148
|
-
const cacheControl = headers
|
|
149
|
-
const age = headers
|
|
150
|
-
const expires = headers
|
|
147
|
+
const cacheControl = headers['cache-control'];
|
|
148
|
+
const age = headers['age'];
|
|
149
|
+
const expires = headers['expires'];
|
|
151
150
|
// In seconds
|
|
152
151
|
let expiresIn = null;
|
|
153
152
|
let maxAge = null;
|
|
@@ -186,91 +185,21 @@ const buildTimestampFromSeconds = (seconds) => {
|
|
|
186
185
|
}
|
|
187
186
|
return new Date(Date.now() + seconds * 1000).getTime();
|
|
188
187
|
};
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
const err = {
|
|
192
|
-
code: -1,
|
|
193
|
-
message: 'Request aborted',
|
|
194
|
-
detail: null,
|
|
195
|
-
raw: error,
|
|
196
|
-
route,
|
|
197
|
-
requestInit,
|
|
198
|
-
};
|
|
199
|
-
return err;
|
|
200
|
-
}
|
|
201
|
-
if (error instanceof SyntaxError) {
|
|
202
|
-
const err = {
|
|
203
|
-
code: -3,
|
|
204
|
-
message: 'Syntax error',
|
|
205
|
-
detail: null,
|
|
206
|
-
raw: error,
|
|
207
|
-
route,
|
|
208
|
-
requestInit,
|
|
209
|
-
};
|
|
210
|
-
return err;
|
|
211
|
-
}
|
|
212
|
-
if (error instanceof Error) {
|
|
213
|
-
const err = {
|
|
214
|
-
code: -2,
|
|
215
|
-
message: `${error.name}: ${error.message}`,
|
|
216
|
-
detail: null,
|
|
217
|
-
raw: error,
|
|
218
|
-
route,
|
|
219
|
-
requestInit,
|
|
220
|
-
};
|
|
221
|
-
return err;
|
|
222
|
-
}
|
|
223
|
-
if (isFetchResponse(error)) {
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
let detail = null;
|
|
226
|
-
try {
|
|
227
|
-
detail = await error.json();
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
// noop
|
|
231
|
-
}
|
|
232
|
-
if (!detail) {
|
|
233
|
-
try {
|
|
234
|
-
detail = await error.text();
|
|
235
|
-
}
|
|
236
|
-
catch {
|
|
237
|
-
// noop
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const err = {
|
|
241
|
-
code: error.status,
|
|
242
|
-
message: error.statusText,
|
|
243
|
-
detail,
|
|
244
|
-
raw: error,
|
|
245
|
-
route,
|
|
246
|
-
requestInit,
|
|
247
|
-
};
|
|
248
|
-
return err;
|
|
249
|
-
}
|
|
250
|
-
const err = {
|
|
251
|
-
code: 0,
|
|
252
|
-
message: 'Unknown error',
|
|
253
|
-
detail: null,
|
|
254
|
-
raw: error,
|
|
255
|
-
route,
|
|
256
|
-
requestInit,
|
|
257
|
-
};
|
|
258
|
-
return err;
|
|
259
|
-
};
|
|
260
|
-
const buildBody = (body) => {
|
|
261
|
-
if (body === undefined || body === null) {
|
|
188
|
+
const serializeBody = (body) => {
|
|
189
|
+
if (body === null || body === undefined) {
|
|
262
190
|
return null;
|
|
263
191
|
}
|
|
264
|
-
if (
|
|
192
|
+
if (body instanceof ArrayBuffer ||
|
|
193
|
+
body instanceof Blob ||
|
|
194
|
+
body instanceof FormData ||
|
|
195
|
+
body instanceof URLSearchParams ||
|
|
196
|
+
typeof body === 'string') {
|
|
265
197
|
return body;
|
|
266
198
|
}
|
|
267
|
-
if (body
|
|
268
|
-
return body;
|
|
269
|
-
}
|
|
270
|
-
if (typeof body === 'object') {
|
|
199
|
+
if (typeof body === 'object' || typeof body === 'boolean' || Array.isArray(body)) {
|
|
271
200
|
return JSON.stringify(body);
|
|
272
201
|
}
|
|
273
|
-
|
|
202
|
+
return body.toString();
|
|
274
203
|
};
|
|
275
204
|
const transformMethod = (method) => {
|
|
276
205
|
if (method === 'GQL_QUERY' || method === 'GQL_MUTATE') {
|
|
@@ -278,40 +207,234 @@ const transformMethod = (method) => {
|
|
|
278
207
|
}
|
|
279
208
|
return method;
|
|
280
209
|
};
|
|
281
|
-
const
|
|
282
|
-
|
|
210
|
+
const detectContentTypeHeader = (body) => {
|
|
211
|
+
// An empty body has no content type.
|
|
212
|
+
if (body === null) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
// FormData bodies rely on the browser's content type assignment.
|
|
216
|
+
if (body instanceof FormData) {
|
|
283
217
|
return null;
|
|
284
218
|
}
|
|
219
|
+
// Blobs usually have their own content type. If it doesn't, then
|
|
220
|
+
// no type can be inferred.
|
|
221
|
+
if (body instanceof Blob) {
|
|
222
|
+
return body.type || null;
|
|
223
|
+
}
|
|
224
|
+
// Array buffers have unknown contents and thus no type can be inferred.
|
|
225
|
+
if (body instanceof ArrayBuffer) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
// Technically, strings could be a form of JSON data, but it's safe enough
|
|
229
|
+
// to assume they're plain strings.
|
|
285
230
|
if (typeof body === 'string') {
|
|
286
231
|
return 'text/plain';
|
|
287
232
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
if (typeof body === 'object') {
|
|
233
|
+
// Arrays, objects, boolean and numbers will be encoded as JSON.
|
|
234
|
+
if (typeof body === 'object' || typeof body === 'number' || typeof body === 'boolean') {
|
|
292
235
|
return 'application/json';
|
|
293
236
|
}
|
|
237
|
+
// No type could be inferred.
|
|
294
238
|
return null;
|
|
295
239
|
};
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
240
|
+
const hasHeader = (headers, header) => {
|
|
241
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === header.toLowerCase());
|
|
242
|
+
};
|
|
243
|
+
const forEachHeader = (headers, callback) => {
|
|
244
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
245
|
+
callback(key, value);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
const parseAllXhrResponseHeaders = (xhr) => {
|
|
249
|
+
const headers = xhr.getAllResponseHeaders();
|
|
250
|
+
const parsedHeaders = {};
|
|
251
|
+
for (const line of headers.split('\n')) {
|
|
252
|
+
const index = line.indexOf(':');
|
|
253
|
+
if (index > 0) {
|
|
254
|
+
const name = line.slice(0, index);
|
|
255
|
+
const key = name.toLowerCase();
|
|
256
|
+
const value = line.slice(index + 1).trim();
|
|
257
|
+
parsedHeaders[key] = value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return parsedHeaders;
|
|
261
|
+
};
|
|
262
|
+
const getResponseUrl = (xhr) => {
|
|
263
|
+
if ('responseURL' in xhr && xhr.responseURL) {
|
|
264
|
+
return xhr.responseURL;
|
|
311
265
|
}
|
|
312
|
-
|
|
313
|
-
|
|
266
|
+
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
|
267
|
+
return xhr.getResponseHeader('X-Request-URL');
|
|
314
268
|
}
|
|
269
|
+
return null;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const XSSI_PREFIX = /^\)\]\}',?\n/;
|
|
273
|
+
const request = (config) => {
|
|
274
|
+
const headers = config.headers || {};
|
|
275
|
+
const responseType = config.responseType || 'json';
|
|
276
|
+
const body = config.body || null;
|
|
277
|
+
const url = config.urlWithParams.split('?')[0];
|
|
278
|
+
return new Observable((observer) => {
|
|
279
|
+
const xhr = new XMLHttpRequest();
|
|
280
|
+
xhr.open(config.method, config.urlWithParams);
|
|
281
|
+
if (config.withCredentials) {
|
|
282
|
+
xhr.withCredentials = true;
|
|
283
|
+
}
|
|
284
|
+
forEachHeader(headers, (name, value) => xhr.setRequestHeader(name, value));
|
|
285
|
+
if (!hasHeader(headers, 'Accept')) {
|
|
286
|
+
xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
|
|
287
|
+
}
|
|
288
|
+
if (!hasHeader(headers, 'Content-Type')) {
|
|
289
|
+
const detectedType = detectContentTypeHeader(body);
|
|
290
|
+
if (detectedType) {
|
|
291
|
+
xhr.setRequestHeader('Content-Type', detectedType);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
xhr.responseType = responseType !== 'json' ? responseType : 'text';
|
|
295
|
+
const reqBody = serializeBody(body);
|
|
296
|
+
let headerResponse = null;
|
|
297
|
+
const partialFromXhr = () => {
|
|
298
|
+
if (headerResponse !== null) {
|
|
299
|
+
return headerResponse;
|
|
300
|
+
}
|
|
301
|
+
const statusText = xhr.statusText || 'OK';
|
|
302
|
+
const headers = parseAllXhrResponseHeaders(xhr);
|
|
303
|
+
const _url = getResponseUrl(xhr) || url;
|
|
304
|
+
headerResponse = { headers, status: xhr.status, statusText, url: _url };
|
|
305
|
+
return headerResponse;
|
|
306
|
+
};
|
|
307
|
+
const onLoad = () => {
|
|
308
|
+
const { headers, statusText, url } = partialFromXhr();
|
|
309
|
+
let { status } = partialFromXhr();
|
|
310
|
+
let body = null;
|
|
311
|
+
if (status !== 204 /* HttpStatusCode.NoContent */) {
|
|
312
|
+
body = typeof xhr.response === 'undefined' ? xhr.responseText : xhr.response;
|
|
313
|
+
}
|
|
314
|
+
if (status === 0) {
|
|
315
|
+
status = body ? 200 /* HttpStatusCode.Ok */ : 0;
|
|
316
|
+
}
|
|
317
|
+
let ok = status >= 200 && status < 300;
|
|
318
|
+
if (responseType === 'json' && typeof body === 'string') {
|
|
319
|
+
const originalBody = body;
|
|
320
|
+
body = body.replace(XSSI_PREFIX, '');
|
|
321
|
+
try {
|
|
322
|
+
body = body !== '' ? JSON.parse(body) : null;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
body = originalBody;
|
|
326
|
+
if (ok) {
|
|
327
|
+
ok = false;
|
|
328
|
+
body = { error, text: body };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (ok) {
|
|
333
|
+
const successEvent = {
|
|
334
|
+
type: 'success',
|
|
335
|
+
headers,
|
|
336
|
+
response: body,
|
|
337
|
+
};
|
|
338
|
+
const expiresInSeconds = config.cacheAdapter?.(headers) ?? extractExpiresInSeconds(headers);
|
|
339
|
+
const expiresInTimestamp = buildTimestampFromSeconds(expiresInSeconds);
|
|
340
|
+
if (expiresInTimestamp) {
|
|
341
|
+
successEvent.expiresInTimestamp = expiresInTimestamp;
|
|
342
|
+
}
|
|
343
|
+
observer.next(successEvent);
|
|
344
|
+
observer.complete();
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
observer.next({
|
|
348
|
+
type: 'failure',
|
|
349
|
+
headers,
|
|
350
|
+
error: {
|
|
351
|
+
url,
|
|
352
|
+
detail: body,
|
|
353
|
+
status,
|
|
354
|
+
statusText,
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
observer.complete();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const onError = (error) => {
|
|
361
|
+
const { url, headers } = partialFromXhr();
|
|
362
|
+
observer.next({
|
|
363
|
+
type: 'failure',
|
|
364
|
+
headers,
|
|
365
|
+
error: {
|
|
366
|
+
url,
|
|
367
|
+
detail: error,
|
|
368
|
+
status: xhr.status || 0,
|
|
369
|
+
statusText: xhr.statusText || 'Unknown Error',
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
observer.complete();
|
|
373
|
+
};
|
|
374
|
+
const onDownProgress = (event) => {
|
|
375
|
+
const { headers } = partialFromXhr();
|
|
376
|
+
const progress = {
|
|
377
|
+
type: 'download-progress',
|
|
378
|
+
headers,
|
|
379
|
+
progress: {
|
|
380
|
+
current: event.loaded,
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
if (event.lengthComputable) {
|
|
384
|
+
const progressPercent = (event.loaded / event.total) * 100;
|
|
385
|
+
progress.progress.percentage = Math.round(progressPercent * 100) / 100;
|
|
386
|
+
progress.progress.total = event.total;
|
|
387
|
+
}
|
|
388
|
+
if (responseType === 'text' && !!xhr.responseText) {
|
|
389
|
+
progress.partialText = xhr.responseText;
|
|
390
|
+
}
|
|
391
|
+
observer.next(progress);
|
|
392
|
+
};
|
|
393
|
+
const onUpProgress = (event) => {
|
|
394
|
+
const { headers } = partialFromXhr();
|
|
395
|
+
const progress = {
|
|
396
|
+
type: 'upload-progress',
|
|
397
|
+
headers,
|
|
398
|
+
progress: {
|
|
399
|
+
current: event.loaded,
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
if (event.lengthComputable) {
|
|
403
|
+
const progressPercent = (event.loaded / event.total) * 100;
|
|
404
|
+
progress.progress.percentage = Math.round(progressPercent * 100) / 100;
|
|
405
|
+
progress.progress.total = event.total;
|
|
406
|
+
}
|
|
407
|
+
observer.next(progress);
|
|
408
|
+
};
|
|
409
|
+
xhr.addEventListener('load', onLoad);
|
|
410
|
+
xhr.addEventListener('error', onError);
|
|
411
|
+
xhr.addEventListener('timeout', onError);
|
|
412
|
+
xhr.addEventListener('abort', onError);
|
|
413
|
+
if (config.reportProgress) {
|
|
414
|
+
xhr.addEventListener('progress', onDownProgress);
|
|
415
|
+
if (reqBody !== null && xhr.upload) {
|
|
416
|
+
xhr.upload.addEventListener('progress', onUpProgress);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
xhr.send(reqBody);
|
|
420
|
+
observer.next({ type: 'start', headers });
|
|
421
|
+
return () => {
|
|
422
|
+
xhr.removeEventListener('error', onError);
|
|
423
|
+
xhr.removeEventListener('abort', onError);
|
|
424
|
+
xhr.removeEventListener('load', onLoad);
|
|
425
|
+
xhr.removeEventListener('timeout', onError);
|
|
426
|
+
if (config.reportProgress) {
|
|
427
|
+
xhr.removeEventListener('progress', onDownProgress);
|
|
428
|
+
if (reqBody !== null && xhr.upload) {
|
|
429
|
+
xhr.upload.removeEventListener('progress', onUpProgress);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (xhr.readyState !== xhr.DONE) {
|
|
433
|
+
xhr.abort();
|
|
434
|
+
}
|
|
435
|
+
observer.next({ type: 'cancel', headers });
|
|
436
|
+
};
|
|
437
|
+
});
|
|
315
438
|
};
|
|
316
439
|
|
|
317
440
|
function filterSuccess() {
|
|
@@ -413,13 +536,12 @@ class Query {
|
|
|
413
536
|
}
|
|
414
537
|
return ts < Date.now();
|
|
415
538
|
}
|
|
416
|
-
constructor(_client, _queryConfig,
|
|
539
|
+
constructor(_client, _queryConfig, _routeWithParams, _args) {
|
|
417
540
|
this._client = _client;
|
|
418
541
|
this._queryConfig = _queryConfig;
|
|
419
|
-
this.
|
|
542
|
+
this._routeWithParams = _routeWithParams;
|
|
420
543
|
this._args = _args;
|
|
421
544
|
this._currentId = 0;
|
|
422
|
-
this._abortController = new AbortController();
|
|
423
545
|
this._pollingSubscription = null;
|
|
424
546
|
this._onAbort$ = new Subject();
|
|
425
547
|
this._state$ = new BehaviorSubject({
|
|
@@ -447,17 +569,14 @@ class Query {
|
|
|
447
569
|
meta,
|
|
448
570
|
});
|
|
449
571
|
this._updateUseResultInDependencies();
|
|
450
|
-
let body
|
|
451
|
-
let contentType = null;
|
|
572
|
+
let body;
|
|
452
573
|
if (isGqlQueryConfig(this._queryConfig)) {
|
|
453
574
|
const queryTemplate = this._queryConfig.query;
|
|
454
575
|
const query = transformGql(queryTemplate);
|
|
455
|
-
contentType = 'application/json';
|
|
456
576
|
body = query(this._args?.variables);
|
|
457
577
|
}
|
|
458
578
|
else {
|
|
459
|
-
body =
|
|
460
|
-
contentType = guessContentType(this._args?.body);
|
|
579
|
+
body = this._args?.body;
|
|
461
580
|
}
|
|
462
581
|
let authHeader = null;
|
|
463
582
|
if (this._queryConfig.secure) {
|
|
@@ -471,61 +590,82 @@ class Query {
|
|
|
471
590
|
authHeader = this._client.authProvider.header;
|
|
472
591
|
}
|
|
473
592
|
}
|
|
474
|
-
let headers = mergeHeaders(authHeader, this._args?.headers);
|
|
475
|
-
if (contentType && !headers?.['Content-Type'] && !headers?.['content-type']) {
|
|
476
|
-
if (headers) {
|
|
477
|
-
headers['Content-Type'] = contentType;
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
headers = {
|
|
481
|
-
'Content-Type': contentType,
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
// For form data we need to remove content type header because browser will set it automatically including boundary
|
|
486
|
-
if (headers && 'Content-Type' in headers && headers['Content-Type'] === 'multipart/form-data') {
|
|
487
|
-
delete headers['Content-Type'];
|
|
488
|
-
}
|
|
489
593
|
request({
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
body,
|
|
495
|
-
headers: headers || undefined,
|
|
496
|
-
},
|
|
594
|
+
urlWithParams: this._routeWithParams,
|
|
595
|
+
method: transformMethod(this._queryConfig.method),
|
|
596
|
+
body,
|
|
597
|
+
headers: mergeHeaders(authHeader, this._args?.headers) || undefined,
|
|
497
598
|
cacheAdapter: this._client.config.request?.cacheAdapter,
|
|
599
|
+
reportProgress: this._queryConfig.reportProgress,
|
|
600
|
+
responseType: this._queryConfig.responseType,
|
|
601
|
+
withCredentials: this._queryConfig.withCredentials,
|
|
498
602
|
})
|
|
499
|
-
.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
603
|
+
.pipe(takeUntil(this._onAbort$))
|
|
604
|
+
.subscribe({
|
|
605
|
+
next: (state) => {
|
|
606
|
+
if (state.type === 'start') {
|
|
607
|
+
this._state$.next({
|
|
608
|
+
type: "LOADING" /* QueryStateType.Loading */,
|
|
609
|
+
meta,
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
else if (state.type === 'download-progress') {
|
|
613
|
+
this._state$.next({
|
|
614
|
+
type: "LOADING" /* QueryStateType.Loading */,
|
|
615
|
+
progress: state.progress,
|
|
616
|
+
partialText: state.partialText,
|
|
617
|
+
meta,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
else if (state.type === 'upload-progress') {
|
|
621
|
+
this._state$.next({
|
|
622
|
+
type: "LOADING" /* QueryStateType.Loading */,
|
|
623
|
+
progress: state.progress,
|
|
624
|
+
meta,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
else if (state.type === 'success') {
|
|
628
|
+
const isResponseObject = typeof state.response === 'object';
|
|
629
|
+
const isGql = isGqlQueryConfig(this._queryConfig);
|
|
630
|
+
let responseData = null;
|
|
631
|
+
if (isGql &&
|
|
632
|
+
isResponseObject &&
|
|
633
|
+
!!state.response &&
|
|
634
|
+
typeof state.response === 'object' &&
|
|
635
|
+
'data' in state.response) {
|
|
636
|
+
responseData = state.response['data'];
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
responseData = state.response;
|
|
640
|
+
}
|
|
641
|
+
const transformedResponse = this._queryConfig.responseTransformer
|
|
642
|
+
? this._queryConfig.responseTransformer(responseData)
|
|
643
|
+
: responseData;
|
|
644
|
+
this._state$.next({
|
|
645
|
+
type: "SUCCESS" /* QueryStateType.Success */,
|
|
646
|
+
rawResponse: state.response,
|
|
647
|
+
response: transformedResponse,
|
|
648
|
+
meta: { ...meta, expiresAt: state.expiresInTimestamp },
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
else if (state.type === 'failure') {
|
|
652
|
+
this._state$.next({
|
|
653
|
+
type: "FAILURE" /* QueryStateType.Failure */,
|
|
654
|
+
error: state.error,
|
|
655
|
+
meta,
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
else if (state.type === 'cancel') {
|
|
659
|
+
this._state$.next({
|
|
660
|
+
type: "CANCELLED" /* QueryStateType.Cancelled */,
|
|
661
|
+
meta,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
});
|
|
524
666
|
return this;
|
|
525
667
|
}
|
|
526
668
|
abort() {
|
|
527
|
-
this._abortController.abort();
|
|
528
|
-
this._abortController = new AbortController();
|
|
529
669
|
this._onAbort$.next();
|
|
530
670
|
return this;
|
|
531
671
|
}
|
|
@@ -563,24 +703,6 @@ class Query {
|
|
|
563
703
|
}))
|
|
564
704
|
.subscribe();
|
|
565
705
|
}
|
|
566
|
-
_handleExecuteError(error, meta) {
|
|
567
|
-
if (isAbortRequestError(error)) {
|
|
568
|
-
this._state$.next({
|
|
569
|
-
type: "CANCELLED" /* QueryStateType.Cancelled */,
|
|
570
|
-
meta,
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
else if (isRequestError(error)) {
|
|
574
|
-
this._state$.next({
|
|
575
|
-
type: "FAILURE" /* QueryStateType.Failure */,
|
|
576
|
-
error,
|
|
577
|
-
meta,
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
throw error;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
706
|
}
|
|
585
707
|
|
|
586
708
|
const isBasicAuthProvider = (authProvider) => authProvider instanceof BasicAuthProvider;
|
|
@@ -768,6 +890,7 @@ class QueryDirective {
|
|
|
768
890
|
raw: null,
|
|
769
891
|
loading: false,
|
|
770
892
|
error: null,
|
|
893
|
+
progress: null,
|
|
771
894
|
};
|
|
772
895
|
this._cache = false;
|
|
773
896
|
}
|
|
@@ -793,9 +916,11 @@ class QueryDirective {
|
|
|
793
916
|
_updateView(state) {
|
|
794
917
|
if (isQueryStateLoading(state)) {
|
|
795
918
|
this._viewContext.loading = true;
|
|
919
|
+
this._viewContext.progress = state.progress ?? null;
|
|
796
920
|
}
|
|
797
921
|
else {
|
|
798
922
|
this._viewContext.loading = false;
|
|
923
|
+
this._viewContext.progress = null;
|
|
799
924
|
}
|
|
800
925
|
if (isQueryStateSuccess(state)) {
|
|
801
926
|
this._viewContext.query = state.response;
|
|
@@ -1467,7 +1592,7 @@ class QueryForm {
|
|
|
1467
1592
|
if (!this._router || !this._activatedRoute) {
|
|
1468
1593
|
return;
|
|
1469
1594
|
}
|
|
1470
|
-
const queryParams = clone(this._activatedRoute.snapshot.queryParams);
|
|
1595
|
+
const queryParams = { ...clone(this._activatedRoute.snapshot.queryParams) };
|
|
1471
1596
|
for (const [key, value] of Object.entries(values)) {
|
|
1472
1597
|
if (this._isDefaultValue(key, value) || this._fields[key].data.appendToUrl === false) {
|
|
1473
1598
|
delete queryParams[key];
|
|
@@ -1607,5 +1732,5 @@ const def = () => null;
|
|
|
1607
1732
|
* Generated bundle index. Do not edit.
|
|
1608
1733
|
*/
|
|
1609
1734
|
|
|
1610
|
-
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore,
|
|
1735
|
+
export { BasicAuthProvider, BearerAuthProvider, CustomHeaderAuthProvider, INFINITY_QUERY_TOKEN, InfinityQuery, InfinityQueryDirective, InfinityQueryTriggerDirective, Query, QueryClient, QueryDirective, QueryError, QueryField, QueryForm, QueryStore, buildErrorMessage, buildGqlCacheKey, buildQueryArrayString, buildQueryString, buildRoute, buildTimestampFromSeconds, createInfinityQueryConfig, createQueryCollection, decryptBearer, deepFreeze, def, detectContentTypeHeader, extractExpiresInSeconds, extractQuery, filterFailure, filterInvalidParams, filterNull, filterQueryStates, filterSuccess, forEachHeader, getResponseUrl, gql, hasHeader, invalidBaseRouteError, invalidBodyError, invalidRouteError, isBasicAuthProvider, isBearerAuthProvider, isCustomHeaderAuthProvider, isFetchResponse, isGqlQueryConfig, isParamValid, isQuery, isQueryStateCancelled, isQueryStateFailure, isQueryStateLoading, isQueryStatePrepared, isQueryStateSuccess, isRequestError, mergeHeaders, parseAllXhrResponseHeaders, pathParamsMissingInRouteFunctionError, queryStateAlreadyHasKeyError, queryStateCannotTransformError, queryStateDoesNotContainKeyError, request, serializeBody, shouldCacheQuery, skipPaginationPageParamCalculator, switchQueryCollectionState, switchQueryState, takeUntilResponse, transformGql, transformMethod, transformToBoolean, transformToBooleanArray, transformToDate, transformToDateArray, transformToNumber, transformToNumberArray, transformToSort, transformToSortQueryParam, transformToString, transformToStringArray };
|
|
1611
1736
|
//# sourceMappingURL=ethlete-query.mjs.map
|