@ethlete/query 5.19.0 → 5.20.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/CHANGELOG.md +12 -0
- package/esm2022/lib/devtools/components/query-devtools/query-devtools.component.mjs +3 -3
- package/esm2022/lib/devtools/pipes/query-short-name.pipe.mjs +3 -3
- package/esm2022/lib/directives/infinity-query-trigger.directive.mjs +3 -3
- package/esm2022/lib/directives/infinity-query.directive.mjs +3 -3
- package/esm2022/lib/directives/query.directive.mjs +3 -3
- package/esm2022/lib/experimental/bearer-auth-provider-config.mjs +2 -2
- package/esm2022/lib/experimental/bearer-auth-provider.mjs +2 -2
- package/esm2022/lib/experimental/http-request.mjs +10 -9
- package/esm2022/lib/experimental/index.mjs +2 -1
- package/esm2022/lib/experimental/query-dependencies.mjs +6 -6
- package/esm2022/lib/experimental/query-errors.mjs +7 -1
- package/esm2022/lib/experimental/query-execute-utils.mjs +19 -22
- package/esm2022/lib/experimental/query-execute.mjs +9 -7
- package/esm2022/lib/experimental/query-features.mjs +13 -13
- package/esm2022/lib/experimental/query-repository.mjs +28 -22
- package/esm2022/lib/experimental/query-snapshot.mjs +2 -1
- package/esm2022/lib/experimental/query-stack.mjs +65 -0
- package/esm2022/lib/experimental/query-utils.mjs +32 -4
- package/esm2022/lib/experimental/query.mjs +6 -14
- package/esm2022/lib/experimental/secure-query-execute.mjs +9 -6
- package/esm2022/lib/experimental/secure-query.mjs +6 -14
- package/esm2022/lib/query-form/query-form.mjs +15 -6
- package/esm2022/lib/query-form/query-form.types.mjs +1 -1
- package/esm2022/lib/utils/data.utils.mjs +2 -2
- package/fesm2022/ethlete-query.mjs +230 -124
- package/fesm2022/ethlete-query.mjs.map +1 -1
- package/lib/experimental/http-request.d.ts +72 -14
- package/lib/experimental/index.d.ts +1 -0
- package/lib/experimental/query-dependencies.d.ts +2 -2
- package/lib/experimental/query-errors.d.ts +5 -1
- package/lib/experimental/query-execute-utils.d.ts +12 -4
- package/lib/experimental/query-execute.d.ts +9 -2
- package/lib/experimental/query-features.d.ts +4 -1
- package/lib/experimental/query-repository.d.ts +41 -20
- package/lib/experimental/query-snapshot.d.ts +2 -0
- package/lib/experimental/query-stack.d.ts +46 -0
- package/lib/experimental/query-utils.d.ts +10 -2
- package/lib/experimental/query.d.ts +8 -5
- package/lib/experimental/secure-query.d.ts +2 -2
- package/lib/query-form/query-form.types.d.ts +8 -0
- package/package.json +1 -1
|
@@ -1,30 +1,80 @@
|
|
|
1
|
-
import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent
|
|
1
|
+
import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent } from '@angular/common/http';
|
|
2
2
|
import { Signal } from '@angular/core';
|
|
3
|
-
import {
|
|
3
|
+
import { QueryArgs, RequestArgs, ResponseType } from './query';
|
|
4
4
|
import { CacheAdapterFn } from './query-client-config';
|
|
5
5
|
import { QueryMethod } from './query-creator';
|
|
6
6
|
import { ShouldRetryRequestFn } from './query-utils';
|
|
7
7
|
export declare const SPEED_BUFFER_TIME_IN_MS = 2000;
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export type HttpRequestTransferCacheConfig = boolean | {
|
|
9
|
+
includeHeaders?: string[];
|
|
10
|
+
};
|
|
11
|
+
export type HttpRequestResponseType = 'json' | 'text' | 'blob' | 'arraybuffer';
|
|
12
|
+
export type CreateHttpRequestDependencies = {
|
|
13
|
+
/** The http client instance to use for the request */
|
|
14
|
+
httpClient: HttpClient;
|
|
15
|
+
};
|
|
16
|
+
export type CreateHttpRequestClientOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Whether to report the progress of the request or not. If the fetch backend is used, this will only work for downloads.
|
|
19
|
+
* @see https://angular.dev/guide/http/making-requests#receiving-raw-progress-events
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
14
22
|
reportProgress?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to include credentials in the request or not
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
15
27
|
withCredentials?: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
/**
|
|
29
|
+
* This property accepts either a boolean to enable/disable transferring cache for eligible
|
|
30
|
+
* requests performed using `HttpClient`, or an object, which allows to configure cache
|
|
31
|
+
* parameters, such as which headers should be included (no headers are included by default).
|
|
32
|
+
*
|
|
33
|
+
* Setting this property will override the options passed to `provideClientHydration()` for this
|
|
34
|
+
* particular request
|
|
35
|
+
*/
|
|
36
|
+
transferCache?: HttpRequestTransferCacheConfig;
|
|
37
|
+
/**
|
|
38
|
+
* The response type of the request
|
|
39
|
+
* @default 'json'
|
|
40
|
+
*/
|
|
41
|
+
responseType?: HttpRequestResponseType;
|
|
42
|
+
/**
|
|
43
|
+
* The context of the request
|
|
44
|
+
* @default undefined
|
|
45
|
+
* @see https://angular.dev/guide/http/interceptors#request-and-response-metadata
|
|
46
|
+
*/
|
|
20
47
|
context?: HttpContext;
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
};
|
|
49
|
+
export type CreateHttpRequestOptions<TArgs extends QueryArgs> = {
|
|
50
|
+
/** The HTTP method of the request */
|
|
51
|
+
method: QueryMethod;
|
|
52
|
+
/**
|
|
53
|
+
* The full path of the request
|
|
54
|
+
* @example 'https://api.example.com/v1/users'
|
|
55
|
+
*/
|
|
56
|
+
fullPath: string;
|
|
57
|
+
/** The data of the request */
|
|
58
|
+
args?: RequestArgs<TArgs> | null;
|
|
59
|
+
/** The dependencies of the request */
|
|
60
|
+
dependencies: CreateHttpRequestDependencies;
|
|
61
|
+
/** The client options of the request */
|
|
62
|
+
clientOptions?: CreateHttpRequestClientOptions;
|
|
63
|
+
/**
|
|
64
|
+
* The cache adapter function to use for the request
|
|
65
|
+
* @default extractExpiresInSeconds()
|
|
66
|
+
*/
|
|
23
67
|
cacheAdapter?: CacheAdapterFn;
|
|
68
|
+
/**
|
|
69
|
+
* The retry function to use for the request
|
|
70
|
+
* @default shouldRetryRequest()
|
|
71
|
+
*/
|
|
24
72
|
retryFn?: ShouldRetryRequestFn;
|
|
25
73
|
};
|
|
26
74
|
export type HttpRequestLoadingState = {
|
|
75
|
+
/** The time when the request was executed in ms */
|
|
27
76
|
executeTime: number;
|
|
77
|
+
/** The progress of the request. Null if reportProgress is false or progress is not available / unsupported */
|
|
28
78
|
progress: HttpRequestLoadingProgressState | null;
|
|
29
79
|
};
|
|
30
80
|
export type HttpRequestLoadingProgressState = {
|
|
@@ -40,14 +90,22 @@ export type HttpRequestLoadingProgressState = {
|
|
|
40
90
|
remainingTime: number | null;
|
|
41
91
|
};
|
|
42
92
|
export type HttpRequest<TArgs extends QueryArgs> = {
|
|
93
|
+
/** Executes the request */
|
|
43
94
|
execute: () => boolean;
|
|
95
|
+
/** Destroys the request (cancels it if in progress) */
|
|
44
96
|
destroy: () => boolean;
|
|
97
|
+
/** The loading state of the request */
|
|
45
98
|
loading: Signal<HttpRequestLoadingState | null>;
|
|
99
|
+
/** The error state of the request */
|
|
46
100
|
error: Signal<HttpErrorResponse | null>;
|
|
101
|
+
/** The response state of the request */
|
|
47
102
|
response: Signal<ResponseType<TArgs> | null>;
|
|
103
|
+
/** The current event of the request */
|
|
48
104
|
currentEvent: Signal<HttpEvent<ResponseType<TArgs>> | HttpErrorEvent | null>;
|
|
105
|
+
/** Whether the request is stale or not aka the cache header has expired */
|
|
49
106
|
isStale: Signal<boolean>;
|
|
50
107
|
};
|
|
108
|
+
/** A custom error event since the Angular http client does not provide a specific event for errors */
|
|
51
109
|
export type HttpErrorEvent = {
|
|
52
110
|
type: 'error';
|
|
53
111
|
error: HttpErrorResponse;
|
|
@@ -13,6 +13,7 @@ export * from './query-execute-utils';
|
|
|
13
13
|
export * from './query-features';
|
|
14
14
|
export * from './query-repository';
|
|
15
15
|
export * from './query-snapshot';
|
|
16
|
+
export * from './query-stack';
|
|
16
17
|
export * from './query-state';
|
|
17
18
|
export * from './query-utils';
|
|
18
19
|
export * from './secure-query';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DestroyRef,
|
|
1
|
+
import { DestroyRef, EnvironmentInjector } from '@angular/core';
|
|
2
2
|
import { QueryClient } from './query-client';
|
|
3
3
|
import { QueryClientConfig } from './query-client-config';
|
|
4
4
|
export type SetupQueryDependenciesOptions = {
|
|
@@ -7,6 +7,6 @@ export type SetupQueryDependenciesOptions = {
|
|
|
7
7
|
export type QueryDependencies = {
|
|
8
8
|
destroyRef: DestroyRef;
|
|
9
9
|
client: QueryClient;
|
|
10
|
-
injector:
|
|
10
|
+
injector: EnvironmentInjector;
|
|
11
11
|
};
|
|
12
12
|
export declare const setupQueryDependencies: (options: SetupQueryDependenciesOptions) => QueryDependencies;
|
|
@@ -18,7 +18,9 @@ export declare const enum RuntimeErrorCode {
|
|
|
18
18
|
DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN = 208,
|
|
19
19
|
DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN = 209,
|
|
20
20
|
UNABLE_TO_DECRYPT_BEARER_TOKEN = 210,
|
|
21
|
-
BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER = 211
|
|
21
|
+
BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER = 211,
|
|
22
|
+
UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM = 300,
|
|
23
|
+
UNCACHEABLE_REQUEST_HAS_SKIP_CACHE_PARAM = 301
|
|
22
24
|
}
|
|
23
25
|
export declare const queryFeatureUsedMultipleTimes: (type: QueryFeatureType) => RuntimeError<RuntimeErrorCode.QUERY_FEATURE_USED_MULTIPLE_TIMES>;
|
|
24
26
|
export declare const withArgsQueryFeatureMissingButRouteIsFunction: () => RuntimeError<RuntimeErrorCode.WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION>;
|
|
@@ -37,3 +39,5 @@ export declare const defaultResponseTransformerResponseNotContainingAccessToken:
|
|
|
37
39
|
export declare const defaultResponseTransformerResponseNotContainingRefreshToken: () => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN>;
|
|
38
40
|
export declare const unableToDecryptBearerToken: (token: string) => RuntimeError<RuntimeErrorCode.UNABLE_TO_DECRYPT_BEARER_TOKEN>;
|
|
39
41
|
export declare const bearerExpiresInPropertyNotNumber: (expiresIn: unknown) => RuntimeError<RuntimeErrorCode.BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER>;
|
|
42
|
+
export declare const uncacheableRequestHasCacheKeyParam: (key: string) => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM>;
|
|
43
|
+
export declare const uncacheableRequestHasSkipCacheParam: () => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_SKIP_CACHE_PARAM>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EffectRef } from '@angular/core';
|
|
1
|
+
import { EffectRef, WritableSignal } from '@angular/core';
|
|
2
2
|
import { QueryArgs, RequestArgs } from './query';
|
|
3
3
|
import { CreateQueryExecuteOptions } from './query-execute';
|
|
4
4
|
export type ResetExecuteStateOptions<TArgs extends QueryArgs> = {
|
|
@@ -8,13 +8,21 @@ export type ResetExecuteStateOptions<TArgs extends QueryArgs> = {
|
|
|
8
8
|
export declare const resetExecuteState: <TArgs extends QueryArgs>(options: ResetExecuteStateOptions<TArgs>) => void;
|
|
9
9
|
export type QueryExecuteState = {
|
|
10
10
|
effectRefs: EffectRef[];
|
|
11
|
-
previousKey: string | false
|
|
11
|
+
previousKey: WritableSignal<string | false>;
|
|
12
12
|
};
|
|
13
13
|
export declare const setupQueryExecuteState: () => QueryExecuteState;
|
|
14
|
+
export type RunQueryExecuteOptions = {
|
|
15
|
+
skipCache?: boolean;
|
|
16
|
+
};
|
|
14
17
|
export type QueryExecuteOptions<TArgs extends QueryArgs> = {
|
|
15
18
|
executeOptions: CreateQueryExecuteOptions<TArgs>;
|
|
16
19
|
executeState: QueryExecuteState;
|
|
17
|
-
args
|
|
20
|
+
args: RequestArgs<TArgs> | null;
|
|
21
|
+
options?: RunQueryExecuteOptions;
|
|
18
22
|
};
|
|
19
23
|
export declare const queryExecute: <TArgs extends QueryArgs>(options: QueryExecuteOptions<TArgs>) => void;
|
|
20
|
-
export
|
|
24
|
+
export type CleanupPreviousExecuteOptions<TArgs extends QueryArgs> = {
|
|
25
|
+
executeOptions: CreateQueryExecuteOptions<TArgs>;
|
|
26
|
+
executeState: QueryExecuteState;
|
|
27
|
+
};
|
|
28
|
+
export declare const cleanupPreviousExecute: <TArgs extends QueryArgs>(options: CleanupPreviousExecuteOptions<TArgs>) => void;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
1
2
|
import { QueryArgs, RequestArgs } from './query';
|
|
2
3
|
import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
|
|
3
4
|
import { QueryDependencies } from './query-dependencies';
|
|
5
|
+
import { RunQueryExecuteOptions } from './query-execute-utils';
|
|
4
6
|
import { QueryState } from './query-state';
|
|
5
7
|
export type CreateQueryExecuteOptions<TArgs extends QueryArgs> = {
|
|
6
8
|
deps: QueryDependencies;
|
|
@@ -9,8 +11,13 @@ export type CreateQueryExecuteOptions<TArgs extends QueryArgs> = {
|
|
|
9
11
|
creatorInternals: InternalCreateQueryCreatorOptions;
|
|
10
12
|
queryConfig: QueryConfig;
|
|
11
13
|
};
|
|
14
|
+
export type QueryExecuteArgs<TArgs extends QueryArgs> = {
|
|
15
|
+
args?: RequestArgs<TArgs> | null;
|
|
16
|
+
options?: RunQueryExecuteOptions;
|
|
17
|
+
};
|
|
12
18
|
export type QueryExecute<TArgs extends QueryArgs> = {
|
|
13
|
-
(
|
|
19
|
+
(executeArgs?: QueryExecuteArgs<TArgs>): void;
|
|
14
20
|
reset: () => void;
|
|
21
|
+
currentRepositoryKey: Signal<string | false>;
|
|
15
22
|
};
|
|
16
|
-
export declare const createExecuteFn: <TArgs extends QueryArgs>(
|
|
23
|
+
export declare const createExecuteFn: <TArgs extends QueryArgs>(executeOptions: CreateQueryExecuteOptions<TArgs>) => QueryExecute<TArgs>;
|
|
@@ -2,6 +2,8 @@ import { HttpErrorResponse, HttpEvent } from '@angular/common/http';
|
|
|
2
2
|
import { Signal } from '@angular/core';
|
|
3
3
|
import { QueryArgs, RequestArgs, ResponseType } from './query';
|
|
4
4
|
import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
|
|
5
|
+
import { QueryDependencies } from './query-dependencies';
|
|
6
|
+
import { QueryExecute } from './query-execute';
|
|
5
7
|
import { QueryState } from './query-state';
|
|
6
8
|
import { QueryArgsReset, QueryFeatureFlags } from './query-utils';
|
|
7
9
|
export declare const enum QueryFeatureType {
|
|
@@ -17,7 +19,8 @@ export type QueryFeatureContext<TArgs extends QueryArgs> = {
|
|
|
17
19
|
queryConfig: QueryConfig;
|
|
18
20
|
creatorConfig: CreateQueryCreatorOptions<TArgs>;
|
|
19
21
|
creatorInternals: InternalCreateQueryCreatorOptions;
|
|
20
|
-
execute:
|
|
22
|
+
execute: QueryExecute<TArgs>;
|
|
23
|
+
deps: QueryDependencies;
|
|
21
24
|
flags: QueryFeatureFlags;
|
|
22
25
|
};
|
|
23
26
|
export type QueryFeatureFn<TArgs extends QueryArgs> = (context: QueryFeatureContext<TArgs>) => void;
|
|
@@ -1,31 +1,52 @@
|
|
|
1
|
-
import { HttpHeaders } from '@angular/common/http';
|
|
2
1
|
import { DestroyRef } from '@angular/core';
|
|
3
|
-
import { HttpRequest } from './http-request';
|
|
4
|
-
import {
|
|
2
|
+
import { CreateHttpRequestClientOptions, HttpRequest } from './http-request';
|
|
3
|
+
import { QueryArgs, RequestArgs } from './query';
|
|
5
4
|
import { QueryClientConfig } from './query-client-config';
|
|
6
5
|
import { QueryMethod, RouteType } from './query-creator';
|
|
6
|
+
import { RunQueryExecuteOptions } from './query-execute-utils';
|
|
7
7
|
export type QueryRepositoryRequestOptions<TArgs extends QueryArgs> = {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The route of the request.
|
|
10
|
+
* @example '/users'
|
|
11
|
+
* @example (args) => `/users/${args.userId}`
|
|
12
|
+
*/
|
|
9
13
|
route: RouteType<TArgs>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
includeHeaders?: string[];
|
|
18
|
-
};
|
|
19
|
-
responseType?: 'json';
|
|
14
|
+
/** The HTTP method of the request */
|
|
15
|
+
method: QueryMethod;
|
|
16
|
+
/** The data of the request */
|
|
17
|
+
args?: RequestArgs<TArgs> | null;
|
|
18
|
+
/** The client options of the request */
|
|
19
|
+
clientOptions?: CreateHttpRequestClientOptions;
|
|
20
|
+
/** If set, this request's cache key will be prefixed with this key */
|
|
20
21
|
key?: string;
|
|
21
|
-
|
|
22
|
+
/** The previous cache key of the request */
|
|
23
|
+
previousKey?: string | false;
|
|
24
|
+
/** The destroy ref to bind the request to. If the destroy ref is destroyed, the request will be destroyed as well. */
|
|
22
25
|
destroyRef: DestroyRef;
|
|
26
|
+
/** Configuration on how to run the query */
|
|
27
|
+
runQueryOptions?: RunQueryExecuteOptions;
|
|
28
|
+
};
|
|
29
|
+
export type QueryRepositoryItem<TArgs extends QueryArgs> = {
|
|
30
|
+
/** The key of the request. If the key is `false`, the request is not cached, otherwise it is. */
|
|
31
|
+
key: QueryKeyOrNone;
|
|
32
|
+
/** The request object */
|
|
33
|
+
request: HttpRequest<TArgs>;
|
|
23
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* The query repository is responsible for managing all requests and their consumers.
|
|
37
|
+
* It will cache requests if they can be cached and reuse them if they are already cached.
|
|
38
|
+
* It will also destroy requests if there are no more consumers left.
|
|
39
|
+
*/
|
|
24
40
|
export type QueryRepository = {
|
|
25
|
-
request
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
unbind: (key: string | false, destroyRef: DestroyRef) => void;
|
|
41
|
+
/** Creates a new request. If the request is already cached, it will be reused. */
|
|
42
|
+
request: <TArgs extends QueryArgs>(options: QueryRepositoryRequestOptions<TArgs>) => QueryRepositoryItem<TArgs>;
|
|
43
|
+
/** Removes a consumer from a request by its key. Destroys the request if there are no more consumers left. */
|
|
44
|
+
unbind: (key: QueryKeyOrNone, destroyRef: DestroyRef) => boolean;
|
|
30
45
|
};
|
|
46
|
+
/** The key of a query */
|
|
47
|
+
export type QueryKey = string;
|
|
48
|
+
/** A key that will not be cached */
|
|
49
|
+
export type QueryKeyNoCache = false;
|
|
50
|
+
/** A key that may or may not be cached */
|
|
51
|
+
export type QueryKeyOrNone = QueryKey | QueryKeyNoCache;
|
|
31
52
|
export declare const createQueryRepository: (config: QueryClientConfig) => QueryRepository;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { QueryArgs, QuerySnapshot } from './query';
|
|
2
2
|
import { QueryDependencies } from './query-dependencies';
|
|
3
|
+
import { QueryExecute } from './query-execute';
|
|
3
4
|
import { QueryState } from './query-state';
|
|
4
5
|
export type CreateQuerySnapshotOptions<TArgs extends QueryArgs> = {
|
|
5
6
|
state: QueryState<TArgs>;
|
|
6
7
|
deps: QueryDependencies;
|
|
8
|
+
execute: QueryExecute<TArgs>;
|
|
7
9
|
};
|
|
8
10
|
export declare const createQuerySnapshotFn: <TArgs extends QueryArgs>(options: CreateQuerySnapshotOptions<TArgs>) => () => QuerySnapshot<TArgs>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { HttpErrorResponse } from '@angular/common/http';
|
|
2
|
+
import { Signal } from '@angular/core';
|
|
3
|
+
import { AnyQuery } from './query';
|
|
4
|
+
export type QueryStack<T extends AnyQuery, J = ReturnType<T['response']>[]> = {
|
|
5
|
+
/** Contains all queries in the stack. */
|
|
6
|
+
queries: Signal<T[]>;
|
|
7
|
+
/** Contains the last query in the stack. Useful for getting current pagination values. */
|
|
8
|
+
lastQuery: Signal<T | null>;
|
|
9
|
+
/** True if any query in the stack is loading. */
|
|
10
|
+
loading: Signal<boolean>;
|
|
11
|
+
/** Contains the first error that occurred in the stack. */
|
|
12
|
+
error: Signal<HttpErrorResponse | null>;
|
|
13
|
+
/** Contains the responses of all queries in the stack. Will be `null` for queries that are loading or errored. */
|
|
14
|
+
response: Signal<J>;
|
|
15
|
+
/** Executes all queries in the stack. */
|
|
16
|
+
execute: () => void;
|
|
17
|
+
/** Destroys all queries in the stack and empties it. This should only be used if `append` is true. */
|
|
18
|
+
clear: () => void;
|
|
19
|
+
};
|
|
20
|
+
export type AnyQueryStack = QueryStack<AnyQuery>;
|
|
21
|
+
export type CreateQueryStackOptions<T extends AnyQuery, J = ReturnType<T['response']>[]> = {
|
|
22
|
+
/**
|
|
23
|
+
* If true, new queries will be appended to the existing ones. Otherwise, existing queries will be destroyed.
|
|
24
|
+
* This should be used for things like infinite scrolling where already fetched queries should not be destroyed.
|
|
25
|
+
*/
|
|
26
|
+
append?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* If append is true, this function will be called to merge the old and new queries.
|
|
29
|
+
* Useful if you want to append the new queries in a specific order (e.g. at the beginning).
|
|
30
|
+
*/
|
|
31
|
+
appendFn?: (oldQueries: T[], newQueries: T[]) => {
|
|
32
|
+
/** The new queries merged with the old ones. */
|
|
33
|
+
queries: T[];
|
|
34
|
+
/** The last query in the new queries. */
|
|
35
|
+
lastQuery: T | null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Transforms the responses of all queries in the stack. Useful for merging or filtering responses.
|
|
39
|
+
*/
|
|
40
|
+
transform?: (responses: ReturnType<T['response']>[]) => J;
|
|
41
|
+
};
|
|
42
|
+
export declare const transformArrayResponse: <T extends (unknown | null)[]>(responses: T) => NonNullable<T[0]>[];
|
|
43
|
+
export declare const transformPaginatedResponse: <T extends ({
|
|
44
|
+
items: unknown[];
|
|
45
|
+
} | null)[]>(responses: T) => NonNullable<NonNullable<T[0]>["items"]>;
|
|
46
|
+
export declare const createQueryStack: <T extends AnyQuery, J = ReturnType<T["response"]>[]>(computation: () => T | T[], options?: CreateQueryStackOptions<T, J>) => QueryStack<T, J>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
|
2
2
|
import { CreateEffectOptions } from '@angular/core';
|
|
3
|
-
import { CreateQueryOptions, QueryArgs } from './query';
|
|
3
|
+
import { CreateQueryOptions, Query, QueryArgs, QuerySnapshot } from './query';
|
|
4
4
|
import { QueryMethod } from './query-creator';
|
|
5
5
|
import { QueryExecute } from './query-execute';
|
|
6
6
|
import { QueryFeatureContext } from './query-features';
|
|
7
|
+
import { QueryState } from './query-state';
|
|
7
8
|
/**
|
|
8
9
|
* Returning this inside e.g. a withComputedArgs feature will reset the query args to null.
|
|
9
10
|
* This will also pause polling and auto refresh until new args are set.
|
|
@@ -12,7 +13,7 @@ export declare const QUERY_ARGS_RESET: unique symbol;
|
|
|
12
13
|
export type QueryArgsReset = typeof QUERY_ARGS_RESET;
|
|
13
14
|
export declare const QUERY_EFFECT_ERROR_MESSAGE = "Effect triggered too often. This is probably due to a circular dependency inside the query.";
|
|
14
15
|
/** A angular effect that will throw an error in dev mode if it is called too often. This indicates a circular dependency inside the effect. */
|
|
15
|
-
export declare const queryEffect: (fn: () => void, errorMessage: string, options?: CreateEffectOptions) =>
|
|
16
|
+
export declare const queryEffect: (fn: () => void, errorMessage: string, options?: CreateEffectOptions) => import("@angular/core").EffectRef;
|
|
16
17
|
export declare const shouldAutoExecuteQuery: (method: QueryMethod) => method is "GET" | "HEAD" | "OPTIONS";
|
|
17
18
|
export declare const extractExpiresInSeconds: (headers: HttpHeaders) => number | null;
|
|
18
19
|
export type ShouldRetryRequestOptions = {
|
|
@@ -39,3 +40,10 @@ export declare const maybeExecute: <TArgs extends QueryArgs>(options: {
|
|
|
39
40
|
flags: QueryFeatureFlags;
|
|
40
41
|
execute: QueryExecute<TArgs>;
|
|
41
42
|
}) => void;
|
|
43
|
+
export type CreateQueryObjectOptions<TArgs extends QueryArgs> = {
|
|
44
|
+
state: QueryState<TArgs>;
|
|
45
|
+
execute: QueryExecute<TArgs>;
|
|
46
|
+
createSnapshot: () => QuerySnapshot<TArgs>;
|
|
47
|
+
destroy: () => void;
|
|
48
|
+
};
|
|
49
|
+
export declare const createQueryObject: <TArgs extends QueryArgs>(options: CreateQueryObjectOptions<TArgs>) => Query<TArgs>;
|
|
@@ -11,11 +11,11 @@ export type QueryArgs = {
|
|
|
11
11
|
body?: any;
|
|
12
12
|
headers?: HttpHeaders;
|
|
13
13
|
};
|
|
14
|
-
export type ResponseType<T extends QueryArgs> = T['response'];
|
|
15
|
-
export type PathParamsType<T extends QueryArgs> = T['pathParams'];
|
|
16
|
-
export type QueryParamsType<T extends QueryArgs> = T['queryParams'];
|
|
17
|
-
export type BodyType<T extends QueryArgs> = T['body'];
|
|
18
|
-
export type RequestArgs<T extends QueryArgs> = Omit<T, 'response'
|
|
14
|
+
export type ResponseType<T extends QueryArgs | null> = T extends QueryArgs ? T['response'] : never;
|
|
15
|
+
export type PathParamsType<T extends QueryArgs | null> = T extends QueryArgs ? T['pathParams'] : never;
|
|
16
|
+
export type QueryParamsType<T extends QueryArgs | null> = T extends QueryArgs ? T['queryParams'] : never;
|
|
17
|
+
export type BodyType<T extends QueryArgs | null> = T extends QueryArgs ? T['body'] : never;
|
|
18
|
+
export type RequestArgs<T extends QueryArgs | null> = T extends QueryArgs ? Omit<T, 'response'> : never;
|
|
19
19
|
export type CreateQueryOptions<TArgs extends QueryArgs> = {
|
|
20
20
|
creator: CreateQueryCreatorOptions<TArgs>;
|
|
21
21
|
creatorInternals: InternalCreateQueryCreatorOptions;
|
|
@@ -29,13 +29,16 @@ export type QueryBase<TArgs extends QueryArgs> = {
|
|
|
29
29
|
loading: Signal<HttpRequestLoadingState | null>;
|
|
30
30
|
error: Signal<HttpErrorResponse | null>;
|
|
31
31
|
lastTimeExecutedAt: Signal<number | null>;
|
|
32
|
+
id: Signal<string | false>;
|
|
32
33
|
};
|
|
33
34
|
export type QuerySnapshot<TArgs extends QueryArgs> = QueryBase<TArgs> & {
|
|
34
35
|
isAlive: Signal<boolean>;
|
|
35
36
|
};
|
|
36
37
|
export type AnyQuerySnapshot = QuerySnapshot<any>;
|
|
38
|
+
export type AnyQuery = Query<any>;
|
|
37
39
|
export type Query<TArgs extends QueryArgs> = QueryBase<TArgs> & {
|
|
38
40
|
execute: QueryExecute<TArgs>;
|
|
39
41
|
createSnapshot: () => QuerySnapshot<TArgs>;
|
|
42
|
+
destroy: () => void;
|
|
40
43
|
};
|
|
41
44
|
export declare const createQuery: <TArgs extends QueryArgs>(options: CreateQueryOptions<TArgs>) => Query<TArgs>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CreateQueryOptions,
|
|
1
|
+
import { CreateQueryOptions, QueryArgs } from './query';
|
|
2
2
|
import { InternalSecureCreateQueryCreatorOptions } from './secure-query-creator';
|
|
3
3
|
export type CreateSecureQueryOptions<TArgs extends QueryArgs> = Omit<CreateQueryOptions<TArgs>, 'creatorInternals'> & {
|
|
4
4
|
creatorInternals: InternalSecureCreateQueryCreatorOptions;
|
|
5
5
|
};
|
|
6
|
-
export declare const createSecureQuery: <TArgs extends QueryArgs>(options: CreateSecureQueryOptions<TArgs>) => Query<TArgs>;
|
|
6
|
+
export declare const createSecureQuery: <TArgs extends QueryArgs>(options: CreateSecureQueryOptions<TArgs>) => import("./query").Query<TArgs>;
|
|
@@ -64,6 +64,14 @@ export interface QueryFieldOptions<T = unknown> {
|
|
|
64
64
|
* @default false
|
|
65
65
|
*/
|
|
66
66
|
skipInFilterCount?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* By default, the field's string value is transformed to it's matching primitive type.
|
|
69
|
+
* Meaning that a string `'true'` will be transformed to a boolean `true` and a string `'5'` will be transformed to a number `5`.
|
|
70
|
+
* If this is set to `true`, the field's value will not be transformed.
|
|
71
|
+
*
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
skipAutoTransform?: boolean;
|
|
67
75
|
/**
|
|
68
76
|
* A function that transforms the the value gotten from the url query params to a value required by the field.
|
|
69
77
|
* E.g. for a number field, the value from the url query params is a string, but the field requires a number.
|