@ethlete/query 2.9.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/index.mjs +2 -1
- package/esm2020/lib/auth/auth-provider.types.mjs +1 -1
- package/esm2020/lib/auth/auth-provider.utils.mjs +1 -1
- package/esm2020/lib/auth/bearer-auth-provider.mjs +2 -2
- package/esm2020/lib/directives/infinity-query-trigger.directive.mjs +4 -4
- package/esm2020/lib/directives/infinity-query.directive.mjs +18 -24
- package/esm2020/lib/directives/query.directive.mjs +9 -11
- package/esm2020/lib/entity/entity-store.mjs +73 -119
- package/esm2020/lib/entity/entity.types.mjs +1 -1
- package/esm2020/lib/entity/entity.utils.mjs +5 -0
- package/esm2020/lib/entity/index.mjs +2 -1
- package/esm2020/lib/infinite-query/infinity-query.mjs +47 -71
- package/esm2020/lib/infinite-query/infinity-query.types.mjs +1 -1
- package/esm2020/lib/infinite-query/infinity-query.utils.mjs +1 -1
- package/esm2020/lib/query/query.mjs +118 -211
- package/esm2020/lib/query/query.types.mjs +1 -1
- package/esm2020/lib/query/query.utils.mjs +1 -1
- package/esm2020/lib/query-client/query-client.mjs +3 -31
- package/esm2020/lib/query-client/query-client.types.mjs +1 -1
- package/esm2020/lib/query-creator/index.mjs +3 -0
- package/esm2020/lib/query-creator/query-creator.mjs +35 -0
- package/esm2020/lib/query-creator/query-creator.types.mjs +2 -0
- package/esm2020/lib/request/request.types.mjs +1 -1
- package/esm2020/lib/request/request.util.mjs +1 -7
- package/fesm2015/ethlete-query.mjs +314 -473
- package/fesm2015/ethlete-query.mjs.map +1 -1
- package/fesm2020/ethlete-query.mjs +308 -476
- package/fesm2020/ethlete-query.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/auth/auth-provider.types.d.ts +3 -4
- package/lib/auth/auth-provider.utils.d.ts +2 -2
- package/lib/auth/bearer-auth-provider.d.ts +1 -1
- package/lib/directives/infinity-query-trigger.directive.d.ts +1 -1
- package/lib/directives/infinity-query.directive.d.ts +6 -11
- package/lib/directives/query.directive.d.ts +7 -7
- package/lib/entity/entity-store.d.ts +13 -27
- package/lib/entity/entity.types.d.ts +0 -5
- package/lib/entity/entity.utils.d.ts +2 -0
- package/lib/entity/index.d.ts +1 -0
- package/lib/infinite-query/infinity-query.d.ts +10 -19
- package/lib/infinite-query/infinity-query.types.d.ts +4 -4
- package/lib/infinite-query/infinity-query.utils.d.ts +2 -3
- package/lib/query/query.d.ts +19 -12
- package/lib/query/query.types.d.ts +86 -51
- package/lib/query/query.utils.d.ts +16 -14
- package/lib/query-client/query-client.d.ts +12 -10
- package/lib/query-client/query-client.types.d.ts +2 -22
- package/lib/query-creator/index.d.ts +2 -0
- package/lib/query-creator/query-creator.d.ts +14 -0
- package/lib/query-creator/query-creator.types.d.ts +13 -0
- package/lib/request/request.types.d.ts +1 -1
- package/lib/request/request.util.d.ts +0 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './lib/infinite-query';
|
|
|
6
6
|
export * from './lib/logger';
|
|
7
7
|
export * from './lib/query';
|
|
8
8
|
export * from './lib/query-client';
|
|
9
|
+
export * from './lib/query-creator';
|
|
9
10
|
export * from './lib/query-form';
|
|
10
11
|
export * from './lib/query-store';
|
|
11
12
|
export * from './lib/request';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AnyQueryCreator, QueryCreatorArgs, QueryCreatorReturnType } from '../query-client';
|
|
1
|
+
import { AnyQueryCreator, QueryArgsOf, QueryResponseOf } from '../query-creator';
|
|
3
2
|
export interface AuthProvider {
|
|
4
3
|
/**
|
|
5
4
|
* The up to date auth header.
|
|
@@ -89,12 +88,12 @@ export interface BearerRefreshConfig<T extends AnyQueryCreator> {
|
|
|
89
88
|
requestArgsAdapter?: (tokens: {
|
|
90
89
|
token: string | null;
|
|
91
90
|
refreshToken: string;
|
|
92
|
-
}) =>
|
|
91
|
+
}) => QueryArgsOf<T>;
|
|
93
92
|
/**
|
|
94
93
|
* Adapter function used to extract the token and refreshToken from the response.
|
|
95
94
|
* @default { token: "token", refreshToken: "refreshToken" }
|
|
96
95
|
*/
|
|
97
|
-
responseAdapter?: (response: NonNullable<
|
|
96
|
+
responseAdapter?: (response: NonNullable<QueryResponseOf<T>>) => TokenResponse;
|
|
98
97
|
}
|
|
99
98
|
export declare const enum AuthBearerRefreshStrategy {
|
|
100
99
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AnyQueryCreator } from '../query-
|
|
1
|
+
import { AnyQueryCreator } from '../query-creator';
|
|
2
2
|
import { AuthProvider } from './auth-provider.types';
|
|
3
3
|
import { BasicAuthProvider } from './basic-auth-provider';
|
|
4
4
|
import { BearerAuthProvider } from './bearer-auth-provider';
|
|
5
5
|
import { CustomHeaderAuthProvider } from './custom-header-auth-provider';
|
|
6
6
|
export declare const isBasicAuthProvider: (authProvider: AuthProvider) => authProvider is BasicAuthProvider;
|
|
7
|
-
export declare const isBearerAuthProvider: <T extends AnyQueryCreator
|
|
7
|
+
export declare const isBearerAuthProvider: <T extends AnyQueryCreator>(authProvider: AuthProvider) => authProvider is BearerAuthProvider<T>;
|
|
8
8
|
export declare const isCustomHeaderAuthProvider: (authProvider: AuthProvider) => authProvider is CustomHeaderAuthProvider;
|
|
9
9
|
export declare const decryptBearer: <Result = Record<string, unknown>>(token: string) => Result | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyQueryCreator } from '../query-
|
|
1
|
+
import { AnyQueryCreator } from '../query-creator';
|
|
2
2
|
import { AuthProvider, AuthProviderBearerConfig, TokenResponse } from './auth-provider.types';
|
|
3
3
|
export declare class BearerAuthProvider<T extends AnyQueryCreator> implements AuthProvider {
|
|
4
4
|
private _config;
|
|
@@ -11,5 +11,5 @@ export declare class InfinityQueryTriggerDirective implements OnInit, OnDestroy
|
|
|
11
11
|
ngOnDestroy(): void;
|
|
12
12
|
private _setupIntersectionObserver;
|
|
13
13
|
static ɵfac: i0.ɵɵFactoryDeclaration<InfinityQueryTriggerDirective, never>;
|
|
14
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<InfinityQueryTriggerDirective, "[
|
|
14
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<InfinityQueryTriggerDirective, "[etInfinityQueryTrigger], et-infinity-query-trigger", never, { "scrollContainerSelector": "scrollContainerSelector"; }, {}, never, never, true, never>;
|
|
15
15
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { InjectionToken,
|
|
1
|
+
import { InjectionToken, OnInit } from '@angular/core';
|
|
2
2
|
import { InfinityQueryConfig, InfinityQueryOf } from '../infinite-query';
|
|
3
3
|
import { BaseArguments } from '../query';
|
|
4
|
-
import { AnyQueryCreator } from '../query-
|
|
4
|
+
import { AnyQueryCreator, ConstructQuery } from '../query-creator';
|
|
5
5
|
import { RequestError } from '../request';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
7
|
import * as i1 from "@ethlete/core";
|
|
8
8
|
interface InfinityQueryContext<Q extends InfinityQueryConfig<AnyQueryCreator, BaseArguments | undefined, any, unknown[]>> {
|
|
9
9
|
$implicit: Q['response']['arrayType'] | null;
|
|
10
|
-
|
|
10
|
+
etInfinityQuery: Q['response']['arrayType'] | null;
|
|
11
11
|
loading: boolean;
|
|
12
12
|
error: RequestError<unknown> | null;
|
|
13
13
|
isFirstLoad: boolean;
|
|
@@ -16,9 +16,10 @@ interface InfinityQueryContext<Q extends InfinityQueryConfig<AnyQueryCreator, Ba
|
|
|
16
16
|
currentCalculatedPage: number | null;
|
|
17
17
|
totalPages: number | null;
|
|
18
18
|
itemsPerPage: number | null;
|
|
19
|
+
currentQuery: ConstructQuery<Q['queryCreator']> | null;
|
|
19
20
|
}
|
|
20
21
|
export declare const INFINITY_QUERY_TOKEN: InjectionToken<InfinityQueryDirective<any>>;
|
|
21
|
-
export declare class InfinityQueryDirective<Q extends InfinityQueryConfig<AnyQueryCreator, BaseArguments | undefined, any, unknown[]>> implements OnInit
|
|
22
|
+
export declare class InfinityQueryDirective<Q extends InfinityQueryConfig<AnyQueryCreator, BaseArguments | undefined, any, unknown[]>> implements OnInit {
|
|
22
23
|
private readonly _queryConfigChanged$;
|
|
23
24
|
private readonly _viewContext;
|
|
24
25
|
private _infinityQueryInstance;
|
|
@@ -40,18 +41,12 @@ export declare class InfinityQueryDirective<Q extends InfinityQueryConfig<AnyQue
|
|
|
40
41
|
get data(): Q["response"]["arrayType"];
|
|
41
42
|
static ngTemplateContextGuard<Q extends InfinityQueryConfig<AnyQueryCreator, BaseArguments | undefined, any, unknown[]>>(dir: InfinityQueryDirective<Q>, ctx: unknown): ctx is InfinityQueryContext<Q>;
|
|
42
43
|
ngOnInit(): void;
|
|
43
|
-
ngOnDestroy(): void;
|
|
44
44
|
private _setupInfinityQuery;
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated Use `loadNextPage` instead
|
|
47
|
-
* @breaking 3.0.0
|
|
48
|
-
*/
|
|
49
|
-
_loadNextPage(): void;
|
|
50
45
|
loadNextPage(): void;
|
|
51
46
|
reset(newConfig?: Omit<Q, 'queryCreator' | 'response'>): void;
|
|
52
47
|
private _renderMainView;
|
|
53
48
|
private _cleanup;
|
|
54
49
|
static ɵfac: i0.ɵɵFactoryDeclaration<InfinityQueryDirective<any>, never>;
|
|
55
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<InfinityQueryDirective<any>, "[
|
|
50
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<InfinityQueryDirective<any>, "[etInfinityQuery]", ["etInfinityQuery"], { "infinityQuery": "etInfinityQuery"; }, {}, never, never, true, [{ directive: typeof i1.DelayableDirective; inputs: {}; outputs: {}; }]>;
|
|
56
51
|
}
|
|
57
52
|
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ChangeDetectorRef, ErrorHandler, OnDestroy, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
|
|
2
|
-
import { AnyQuery,
|
|
2
|
+
import { AnyQuery, AnyQueryCollection, QueryOf } from '../query';
|
|
3
|
+
import { QueryDataOf } from '../query-creator';
|
|
3
4
|
import { RequestError, RequestProgress } from '../request';
|
|
4
5
|
import * as i0 from "@angular/core";
|
|
5
6
|
interface QueryContext<Q extends AnyQuery | null> {
|
|
6
|
-
$implicit:
|
|
7
|
-
|
|
8
|
-
raw: QueryRawResponseType<Q>;
|
|
7
|
+
$implicit: QueryDataOf<Q>;
|
|
8
|
+
etQuery: QueryDataOf<Q>;
|
|
9
9
|
loading: boolean;
|
|
10
10
|
progress: RequestProgress | null;
|
|
11
11
|
error: RequestError<unknown> | null;
|
|
12
12
|
}
|
|
13
|
-
export declare class QueryDirective<Q extends AnyQuery |
|
|
13
|
+
export declare class QueryDirective<Q extends AnyQuery | AnyQueryCollection | null> implements OnInit, OnDestroy {
|
|
14
14
|
private _mainTemplateRef;
|
|
15
15
|
private _viewContainerRef;
|
|
16
16
|
private _errorHandler;
|
|
@@ -25,13 +25,13 @@ export declare class QueryDirective<Q extends AnyQuery | AnyQueryOfCreatorCollec
|
|
|
25
25
|
set cache(v: boolean);
|
|
26
26
|
private _cache;
|
|
27
27
|
constructor(_mainTemplateRef: TemplateRef<QueryContext<QueryOf<Q>>>, _viewContainerRef: ViewContainerRef, _errorHandler: ErrorHandler, _cdr: ChangeDetectorRef);
|
|
28
|
-
static ngTemplateContextGuard<Q extends AnyQuery |
|
|
28
|
+
static ngTemplateContextGuard<Q extends AnyQuery | AnyQueryCollection | null>(dir: QueryDirective<Q>, ctx: unknown): ctx is QueryContext<QueryOf<Q>>;
|
|
29
29
|
ngOnInit(): void;
|
|
30
30
|
ngOnDestroy(): void;
|
|
31
31
|
private _subscribeToQuery;
|
|
32
32
|
private _updateView;
|
|
33
33
|
private _renderMainView;
|
|
34
34
|
static ɵfac: i0.ɵɵFactoryDeclaration<QueryDirective<any>, never>;
|
|
35
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<QueryDirective<any>, "[
|
|
35
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<QueryDirective<any>, "[etQuery]", never, { "query": "etQuery"; "cache": "etQueryCache"; }, {}, never, never, true, never>;
|
|
36
36
|
}
|
|
37
37
|
export {};
|
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityKey, EntityStoreConfig } from './entity.types';
|
|
2
3
|
export declare class EntityStore<T> {
|
|
3
4
|
private readonly _config;
|
|
4
5
|
private readonly _dictionary;
|
|
5
|
-
private readonly
|
|
6
|
-
private readonly _events$;
|
|
7
|
-
get events$(): import("rxjs").Observable<EntityStoreActionResult>;
|
|
8
|
-
get keys(): EntityKey[];
|
|
9
|
-
get values(): T[];
|
|
10
|
-
get size(): number;
|
|
11
|
-
get isEmpty(): boolean;
|
|
12
|
-
get config(): EntityStoreConfig;
|
|
13
|
-
get idKey(): string;
|
|
14
|
-
readonly entities$: import("rxjs").Observable<{
|
|
15
|
-
keys: EntityKey[];
|
|
16
|
-
values: T[];
|
|
17
|
-
}>;
|
|
6
|
+
private readonly _change$;
|
|
18
7
|
constructor(_config: EntityStoreConfig);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setOne(value: T): EntityStoreActionResult;
|
|
26
|
-
setMany(values: T[]): EntityStoreActionResult[];
|
|
27
|
-
removeOne(key: EntityKey): EntityStoreActionResult | null;
|
|
28
|
-
removeMany(keys: EntityKey[]): (EntityStoreActionResult | null)[];
|
|
29
|
-
has(key: EntityKey): boolean;
|
|
30
|
-
clear(): void;
|
|
31
|
-
getKey(value: T): string | number;
|
|
8
|
+
select(key: EntityKey): Observable<T | null>;
|
|
9
|
+
select(keys: EntityKey[]): Observable<T[]>;
|
|
10
|
+
set(key: EntityKey, value: T): void;
|
|
11
|
+
set(keys: EntityKey[], values: T[]): void;
|
|
12
|
+
remove(key: EntityKey): void;
|
|
13
|
+
remove(keys: EntityKey[]): void;
|
|
32
14
|
logState(): void;
|
|
15
|
+
private _select;
|
|
16
|
+
private _selectMany;
|
|
17
|
+
private _set;
|
|
18
|
+
private _remove;
|
|
33
19
|
}
|
package/lib/entity/index.d.ts
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AnyQueryCreator, QueryCreatorArgs, QueryCreatorResponse, QueryCreatorReturnType } from '../query-client';
|
|
1
|
+
import { AnyQueryCreator, ConstructQuery, QueryArgsOf, QueryResponseOf } from '../query-creator';
|
|
3
2
|
import { InfinityQueryConfig } from './infinity-query.types';
|
|
4
|
-
export declare class InfinityQuery<QueryCreator extends AnyQueryCreator, Query extends
|
|
3
|
+
export declare class InfinityQuery<QueryCreator extends AnyQueryCreator, Query extends ConstructQuery<QueryCreator>, Args extends QueryArgsOf<QueryCreator>, QueryResponse extends QueryResponseOf<QueryCreator>, InfinityResponse extends unknown[]> {
|
|
5
4
|
private _config;
|
|
5
|
+
private readonly _queries$;
|
|
6
6
|
private readonly _currentPage$;
|
|
7
7
|
private readonly _currentCalculatedPage$;
|
|
8
8
|
private readonly _totalPages$;
|
|
9
9
|
private readonly _itemsPerPage$;
|
|
10
|
-
private readonly _currentQuery$;
|
|
11
10
|
private readonly _data$;
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
get currentPage$(): Observable<number | null>;
|
|
11
|
+
private readonly _lastQuery$;
|
|
12
|
+
get currentPage$(): import("rxjs").Observable<number | null>;
|
|
15
13
|
get currentPage(): number | null;
|
|
16
|
-
get currentCalculatedPage$(): Observable<number | null>;
|
|
14
|
+
get currentCalculatedPage$(): import("rxjs").Observable<number | null>;
|
|
17
15
|
get currentCalculatedPage(): number | null;
|
|
18
|
-
get totalPages$(): Observable<number | null>;
|
|
16
|
+
get totalPages$(): import("rxjs").Observable<number | null>;
|
|
19
17
|
get totalPages(): number | null;
|
|
20
|
-
get itemsPerPage$(): Observable<number>;
|
|
18
|
+
get itemsPerPage$(): import("rxjs").Observable<number>;
|
|
21
19
|
get itemsPerPage(): number;
|
|
22
|
-
get
|
|
23
|
-
get currentQuery(): Query
|
|
24
|
-
get data$(): Observable<InfinityResponse>;
|
|
25
|
-
get data(): InfinityResponse;
|
|
20
|
+
get data$(): import("rxjs").Observable<InfinityResponse>;
|
|
21
|
+
get currentQuery$(): import("rxjs").Observable<Query>;
|
|
26
22
|
constructor(_config: InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>);
|
|
27
23
|
nextPage(): void;
|
|
28
24
|
reset(newConfig?: Omit<InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>, 'queryCreator' | 'response'>): void;
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
_clearSubscriptions(): void;
|
|
33
|
-
private _handleNewQuery;
|
|
34
25
|
private _prepareArgs;
|
|
35
26
|
private _getPageParamLocation;
|
|
36
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseArguments
|
|
2
|
-
import { AnyQueryCreator,
|
|
1
|
+
import { BaseArguments } from '../query';
|
|
2
|
+
import { AnyQueryCreator, ConstructQuery, QueryArgsOf, QueryResponseOf } from '../query-creator';
|
|
3
3
|
import { InfinityQuery } from './infinity-query';
|
|
4
4
|
export type InfinityQueryParamLocation = 'path' | 'query' | 'body' | 'header' | 'variable';
|
|
5
5
|
export type AppendItemsLocation = 'start' | 'end';
|
|
@@ -93,6 +93,6 @@ export interface InfinityQueryConfig<QueryCreator extends AnyQueryCreator, Argum
|
|
|
93
93
|
type OmitUndefined<T> = T extends undefined ? never : T;
|
|
94
94
|
export type AnyInfinityQueryConfig = InfinityQueryConfig<any, any, any, any>;
|
|
95
95
|
export type AnyInfinityQuery = InfinityQuery<any, any, any, any, any>;
|
|
96
|
-
export type InfinityQueryConfigType<QueryCreator extends AnyQueryCreator, InfinityResponse extends unknown[]> = InfinityQueryConfig<QueryCreator, OmitUndefined<
|
|
97
|
-
export type InfinityQueryOf<Cfg extends AnyInfinityQueryConfig> = InfinityQuery<Cfg['queryCreator'],
|
|
96
|
+
export type InfinityQueryConfigType<QueryCreator extends AnyQueryCreator, InfinityResponse extends unknown[]> = InfinityQueryConfig<QueryCreator, OmitUndefined<QueryArgsOf<QueryCreator>>, QueryResponseOf<QueryCreator>, InfinityResponse>;
|
|
97
|
+
export type InfinityQueryOf<Cfg extends AnyInfinityQueryConfig> = InfinityQuery<Cfg['queryCreator'], ConstructQuery<Cfg['queryCreator']>, QueryArgsOf<Cfg['queryCreator']>, QueryResponseOf<Cfg['queryCreator']>, Cfg['response']['arrayType']>;
|
|
98
98
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AnyQueryCreator, QueryCreatorArgs } from '../query-client';
|
|
1
|
+
import { AnyQueryCreator, QueryArgsOf, QueryResponseOf } from '../query-creator';
|
|
3
2
|
import { InfinityQueryConfig, PageParamCalculatorOptions } from './infinity-query.types';
|
|
4
|
-
export declare const createInfinityQueryConfig: <QueryCreator extends AnyQueryCreator,
|
|
3
|
+
export declare const createInfinityQueryConfig: <QueryCreator extends AnyQueryCreator, Args extends QueryArgsOf<QueryCreator>, QueryResponse extends QueryResponseOf<QueryCreator>, InfinityResponse extends unknown[]>(config: InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>) => InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>;
|
|
5
4
|
export declare const skipPaginationPageParamCalculator: ({ page, itemsPerPage }: PageParamCalculatorOptions) => number;
|
package/lib/query/query.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityStore } from '../entity';
|
|
3
|
+
import { QueryClient } from '../query-client';
|
|
4
|
+
import { BaseArguments, ExecuteQueryOptions, GqlQueryConfig, PollConfig, QueryAutoRefreshConfig, QueryState, RestQueryConfig, RouteType } from './query.types';
|
|
5
|
+
export declare class Query<Response, Arguments extends BaseArguments | undefined, Route extends RouteType<Arguments>, Store extends EntityStore<unknown>, Data, Id> {
|
|
5
6
|
private _client;
|
|
6
7
|
private _queryConfig;
|
|
7
8
|
private _routeWithParams;
|
|
8
9
|
private _args;
|
|
9
10
|
private _currentId;
|
|
10
11
|
private _pollingSubscription;
|
|
11
|
-
private
|
|
12
|
+
private _requestSubscription;
|
|
12
13
|
private _onAbort$;
|
|
13
14
|
private _currentPollConfig;
|
|
14
15
|
/**
|
|
@@ -17,8 +18,14 @@ export declare class Query<Response, Arguments extends (BaseArguments & WithUseR
|
|
|
17
18
|
_isPollingPaused: boolean;
|
|
18
19
|
private readonly _state$;
|
|
19
20
|
private get _nextId();
|
|
20
|
-
get state$():
|
|
21
|
-
|
|
21
|
+
get state$(): Observable<QueryState<Data>>;
|
|
22
|
+
/**
|
|
23
|
+
* The current state of the query.
|
|
24
|
+
*
|
|
25
|
+
* **Warning!** This differs from the `state$` observable in that it does not use the query store. Thus, the response data might be outdated.
|
|
26
|
+
* Use `state$` (or `firstValueFrom(state$)`) the most up-to-date data.
|
|
27
|
+
*/
|
|
28
|
+
get rawState(): QueryState<Response>;
|
|
22
29
|
get isExpired(): boolean;
|
|
23
30
|
get isInUse(): boolean;
|
|
24
31
|
get isPolling(): boolean;
|
|
@@ -27,19 +34,19 @@ export declare class Query<Response, Arguments extends (BaseArguments & WithUseR
|
|
|
27
34
|
* @internal
|
|
28
35
|
*/
|
|
29
36
|
get _enableSmartPolling(): boolean;
|
|
30
|
-
get store():
|
|
31
|
-
constructor(_client: QueryClient, _queryConfig: RestQueryConfig<Route, Response, Arguments,
|
|
32
|
-
|
|
33
|
-
execute<ComputedResponse extends ReturnType<ResponseTransformer>, EntityResponse extends ResponseTransformer extends (response: Response) => infer R ? R : Response>(options?: RunQueryOptions): this;
|
|
37
|
+
get store(): Store | null;
|
|
38
|
+
constructor(_client: QueryClient, _queryConfig: RestQueryConfig<Route, Response, Arguments, Store, Data, Id> | GqlQueryConfig<Route, Response, Arguments, Store, Data, Id>, _routeWithParams: Route, _args: Arguments);
|
|
39
|
+
execute(options?: ExecuteQueryOptions): this;
|
|
34
40
|
abort(): this;
|
|
35
41
|
poll(config: PollConfig): this;
|
|
36
42
|
stopPolling(): this;
|
|
37
43
|
pausePolling(): this;
|
|
38
44
|
resumePolling(): this;
|
|
39
|
-
private _updateUseResultInDependencies;
|
|
40
45
|
/**
|
|
41
46
|
* @internal
|
|
42
47
|
*/
|
|
43
48
|
_destroy(): void;
|
|
44
49
|
private _getBearerAuthProvider;
|
|
50
|
+
private _updateEntityState;
|
|
51
|
+
private _transformState;
|
|
45
52
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { EntityStore
|
|
3
|
-
import { AnyQueryCreator,
|
|
2
|
+
import { EntityStore } from '../entity';
|
|
3
|
+
import { AnyQueryCreator, ConstructQuery, QueryResponseOf } from '../query-creator';
|
|
4
4
|
import { Method, PathParams, QueryParams, RequestError, RequestProgress } from '../request';
|
|
5
5
|
import { Query } from './query';
|
|
6
6
|
export interface QueryAutoRefreshConfig {
|
|
@@ -17,7 +17,71 @@ export interface QueryAutoRefreshConfig {
|
|
|
17
17
|
*/
|
|
18
18
|
windowFocus?: boolean;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export interface EntitySetParams<Store, Response, Arguments, Id> {
|
|
21
|
+
/**
|
|
22
|
+
* The response data.
|
|
23
|
+
*/
|
|
24
|
+
response: Response;
|
|
25
|
+
/**
|
|
26
|
+
* The id(s) returned by the `id` function.
|
|
27
|
+
*/
|
|
28
|
+
id: Id;
|
|
29
|
+
/**
|
|
30
|
+
* The arguments passed to the query.
|
|
31
|
+
*/
|
|
32
|
+
args: Arguments;
|
|
33
|
+
/**
|
|
34
|
+
* The entity store.
|
|
35
|
+
*/
|
|
36
|
+
store: Store;
|
|
37
|
+
}
|
|
38
|
+
export interface EntityGetParams<Store, Response, Arguments, Id> {
|
|
39
|
+
/**
|
|
40
|
+
* The response data.
|
|
41
|
+
*/
|
|
42
|
+
response: Response;
|
|
43
|
+
/**
|
|
44
|
+
* The id(s) returned by the `id` function.
|
|
45
|
+
*/
|
|
46
|
+
id: Id;
|
|
47
|
+
/**
|
|
48
|
+
* The arguments passed to the query.
|
|
49
|
+
*/
|
|
50
|
+
args: Arguments;
|
|
51
|
+
/**
|
|
52
|
+
* The entity store.
|
|
53
|
+
*/
|
|
54
|
+
store: Store;
|
|
55
|
+
}
|
|
56
|
+
export interface EntityIdParams<Response, Arguments> {
|
|
57
|
+
/**
|
|
58
|
+
* The response data.
|
|
59
|
+
*/
|
|
60
|
+
response: Response;
|
|
61
|
+
/**
|
|
62
|
+
* The arguments passed to the query.
|
|
63
|
+
*/
|
|
64
|
+
args: Arguments;
|
|
65
|
+
}
|
|
66
|
+
export interface QueryEntityConfig<Store, Data, Response, Arguments, Id> {
|
|
67
|
+
/**
|
|
68
|
+
* The entity store to use for the query.
|
|
69
|
+
*/
|
|
70
|
+
store: Store;
|
|
71
|
+
/**
|
|
72
|
+
* A function that returns the id of the entity. Can also return an array of ids.
|
|
73
|
+
*/
|
|
74
|
+
id: (data: EntityIdParams<Response, Arguments>) => Id;
|
|
75
|
+
/**
|
|
76
|
+
* A function that returns the response data (can be a subset of the response).
|
|
77
|
+
*/
|
|
78
|
+
get?: (data: EntityGetParams<Store, Response, Arguments, Id>) => Observable<Data>;
|
|
79
|
+
/**
|
|
80
|
+
* A function to update the entity store every time a new response is received.
|
|
81
|
+
*/
|
|
82
|
+
set?: (data: EntitySetParams<Store, Response, Arguments, Id>) => void;
|
|
83
|
+
}
|
|
84
|
+
export type QueryConfigBase<Response, Arguments extends BaseArguments | undefined, Store extends EntityStore<unknown>, Data, Id> = {
|
|
21
85
|
/**
|
|
22
86
|
* The http method to use for the query.
|
|
23
87
|
*/
|
|
@@ -27,11 +91,6 @@ export type QueryConfigBase<Response, Arguments extends BaseArguments | undefine
|
|
|
27
91
|
* The query **will throw** if the query client's auth provider is unset.
|
|
28
92
|
*/
|
|
29
93
|
secure?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* The response transformer to use for the query.
|
|
32
|
-
* A function that transforms the response to the desired type.
|
|
33
|
-
*/
|
|
34
|
-
responseTransformer?: ResponseTransformer;
|
|
35
94
|
/**
|
|
36
95
|
* Determines if the query should emit progress events.
|
|
37
96
|
*/
|
|
@@ -79,33 +138,19 @@ export type QueryConfigBase<Response, Arguments extends BaseArguments | undefine
|
|
|
79
138
|
*/
|
|
80
139
|
args?: Arguments;
|
|
81
140
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
response: ResponseTransformer extends (response: Response) => infer R ? R : Response;
|
|
87
|
-
args: Arguments;
|
|
88
|
-
store: EntityStore<Entity>;
|
|
89
|
-
}) => EntityStoreActionResult | null | Array<EntityStoreActionResult | null>;
|
|
90
|
-
valueUpdater?: (data: {
|
|
91
|
-
rawResponse: Response;
|
|
92
|
-
response: ResponseTransformer extends (response: Response) => infer R ? R : Response;
|
|
93
|
-
args: Arguments;
|
|
94
|
-
entity: Entity;
|
|
95
|
-
}) => {
|
|
96
|
-
rawResponse: Response;
|
|
97
|
-
response: ResponseTransformer extends (response: Response) => infer R ? R : Response;
|
|
98
|
-
} | null;
|
|
99
|
-
};
|
|
141
|
+
/**
|
|
142
|
+
* Object containing the query's entity store information.
|
|
143
|
+
*/
|
|
144
|
+
entity?: QueryEntityConfig<Store, Data, Response, Arguments, Id>;
|
|
100
145
|
};
|
|
101
|
-
export type RestQueryConfig<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined,
|
|
146
|
+
export type RestQueryConfig<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined, Store extends EntityStore<unknown>, Data, Id> = QueryConfigBase<Response, Arguments, Store, Data, Id> & {
|
|
102
147
|
/**
|
|
103
148
|
* The api route to use for the query.
|
|
104
149
|
*/
|
|
105
150
|
route: Route;
|
|
106
151
|
};
|
|
107
152
|
export type GqlTransferOption = 'GET' | 'POST';
|
|
108
|
-
export interface GqlQueryConfig<Route extends RouteType<Arguments> | undefined, Response, Arguments extends BaseArguments | undefined,
|
|
153
|
+
export interface GqlQueryConfig<Route extends RouteType<Arguments> | undefined, Response, Arguments extends BaseArguments | undefined, Store extends EntityStore<unknown>, Data, Id> extends QueryConfigBase<Response, Arguments, Store, Data, Id> {
|
|
109
154
|
/**
|
|
110
155
|
* The graphql query to use for the query.
|
|
111
156
|
*/
|
|
@@ -122,10 +167,10 @@ export interface GqlQueryConfig<Route extends RouteType<Arguments> | undefined,
|
|
|
122
167
|
*/
|
|
123
168
|
route?: Route;
|
|
124
169
|
}
|
|
125
|
-
export type AnyRestQueryConfig = RestQueryConfig<any, any, any, any, any>;
|
|
126
|
-
export type AnyGqlQueryConfig = GqlQueryConfig<any, any, any, any, any>;
|
|
127
|
-
export type QueryConfigWithoutMethod<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined,
|
|
128
|
-
export type GqlQueryConfigWithoutMethod<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined,
|
|
170
|
+
export type AnyRestQueryConfig = RestQueryConfig<any, any, any, any, any, any>;
|
|
171
|
+
export type AnyGqlQueryConfig = GqlQueryConfig<any, any, any, any, any, any>;
|
|
172
|
+
export type QueryConfigWithoutMethod<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined, Store extends EntityStore<unknown>, Data, Id> = Omit<RestQueryConfig<Route, Response, Arguments, Store, Data, Id>, 'method'>;
|
|
173
|
+
export type GqlQueryConfigWithoutMethod<Route extends RouteType<Arguments>, Response, Arguments extends BaseArguments | undefined, Store extends EntityStore<unknown>, Data, Id> = Omit<GqlQueryConfig<Route, Response, Arguments, Store, Data, Id>, 'method'>;
|
|
129
174
|
export type BaseArguments = WithHeaders & WithVariables & WithBody & WithQueryParams & WithPathParams;
|
|
130
175
|
export interface WithHeaders {
|
|
131
176
|
headers?: Record<string, string>;
|
|
@@ -142,12 +187,9 @@ export interface WithQueryParams {
|
|
|
142
187
|
export interface WithPathParams {
|
|
143
188
|
pathParams?: PathParams;
|
|
144
189
|
}
|
|
145
|
-
export type WithUseResultIn<Response, ResponseTransformer extends ResponseTransformerType<Response>> = {
|
|
146
|
-
useResultIn?: Query<Response, any, any, any, ResponseTransformer, any>[];
|
|
147
|
-
};
|
|
148
190
|
export type QueryTrigger = 'program' | 'poll' | 'auto';
|
|
149
191
|
export type EmptyObject = {};
|
|
150
|
-
export interface
|
|
192
|
+
export interface ExecuteQueryOptions {
|
|
151
193
|
/**
|
|
152
194
|
* Whether to skip the cache for this query. This will force the query to be executed. It might still be caught by the native browser cache.
|
|
153
195
|
* @default false
|
|
@@ -197,10 +239,9 @@ export interface Prepared {
|
|
|
197
239
|
type: QueryStateType.Prepared;
|
|
198
240
|
meta: QueryStateMeta;
|
|
199
241
|
}
|
|
200
|
-
export interface Success<Response = unknown
|
|
242
|
+
export interface Success<Response = unknown> {
|
|
201
243
|
type: QueryStateType.Success;
|
|
202
244
|
response: Response;
|
|
203
|
-
rawResponse: RawResponse;
|
|
204
245
|
meta: QueryStateSuccessMeta;
|
|
205
246
|
}
|
|
206
247
|
export interface Failure {
|
|
@@ -228,26 +269,20 @@ export interface QueryStateMeta {
|
|
|
228
269
|
export interface QueryStateSuccessMeta extends QueryStateMeta {
|
|
229
270
|
expiresAt?: number;
|
|
230
271
|
}
|
|
231
|
-
export type QueryState<Response = unknown
|
|
232
|
-
export type
|
|
233
|
-
export type QueryStateRawData<T extends QueryState = QueryState> = T extends Success<infer Response, infer RawResponse> ? RawResponse : never;
|
|
272
|
+
export type QueryState<Response = unknown> = Loading | Success<Response> | Failure | Cancelled | Prepared;
|
|
273
|
+
export type QueryStateResponseOf<T extends QueryState = QueryState> = T extends Success<infer Response> ? Response : never;
|
|
234
274
|
export type AnyQuery = Query<any, any, any, any, any, any>;
|
|
235
|
-
export type QueryType<T extends {
|
|
236
|
-
prepare: (args: any) => AnyQuery;
|
|
237
|
-
}> = T['prepare'] extends () => infer R ? R : T['prepare'] extends (args: any) => infer R ? R : never;
|
|
238
|
-
export type QueryResponseType<Q extends AnyQuery | null> = Q extends AnyQuery ? QueryStateData<Q['state']> | null : null;
|
|
239
|
-
export type QueryRawResponseType<Q extends AnyQuery | null> = Q extends AnyQuery ? QueryStateRawData<Q['state']> | null : null;
|
|
240
275
|
export type AnyQueryCreatorCollection = {
|
|
241
276
|
[name: string]: AnyQueryCreator;
|
|
242
277
|
};
|
|
243
|
-
export type
|
|
278
|
+
export type QueryCollectionOf<T extends {
|
|
244
279
|
[name: string]: AnyQueryCreator;
|
|
245
280
|
}> = {
|
|
246
281
|
[K in keyof T]: {
|
|
247
282
|
type: K;
|
|
248
|
-
query:
|
|
283
|
+
query: ConstructQuery<T[K]>;
|
|
249
284
|
};
|
|
250
285
|
}[keyof T];
|
|
251
|
-
export type
|
|
252
|
-
export type
|
|
253
|
-
export type
|
|
286
|
+
export type AnyQueryCollection = QueryCollectionOf<AnyQueryCreatorCollection>;
|
|
287
|
+
export type QueryOf<T extends AnyQueryCollection | AnyQuery | null> = T extends AnyQuery ? T : T extends AnyQueryCollection ? T['query'] : never;
|
|
288
|
+
export type AnyQueryCollectionResponse<T extends AnyQueryCollection> = QueryResponseOf<T['query']>;
|