@ethlete/query 5.22.0 → 5.23.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/CHANGELOG.md +10 -0
- package/fesm2022/ethlete-query.mjs +68 -46
- package/fesm2022/ethlete-query.mjs.map +1 -1
- package/lib/experimental/http-request.d.ts +1 -1
- package/lib/experimental/paged-query.d.ts +46 -4
- package/lib/experimental/query-errors.d.ts +2 -2
- package/lib/experimental/query-execute-utils.d.ts +1 -1
- package/lib/experimental/query-stack.d.ts +1 -1
- package/lib/experimental/query-utils.d.ts +1 -1
- package/lib/utils/data.utils.d.ts +5 -2
- package/package.json +1 -1
|
@@ -92,7 +92,7 @@ export type HttpRequestLoadingProgressState = {
|
|
|
92
92
|
export type HttpRequest<TArgs extends QueryArgs> = {
|
|
93
93
|
/** Executes the request */
|
|
94
94
|
execute: (options?: {
|
|
95
|
-
|
|
95
|
+
allowCache?: boolean;
|
|
96
96
|
}) => boolean;
|
|
97
97
|
/** Destroys the request (cancels it if in progress) */
|
|
98
98
|
destroy: () => boolean;
|
|
@@ -6,14 +6,59 @@ export declare const ggLikePaginationAdapter: <T>(response: GgLikePaginated<T>)
|
|
|
6
6
|
export declare const dynLikePaginationAdapter: <T>(response: DynLikePaginated<T>) => NormalizedPagination<T>;
|
|
7
7
|
export declare const contentfulGqlLikePaginationAdapter: <T>(response: ContentfulGqlLikePaginated<T>) => NormalizedPagination<T>;
|
|
8
8
|
export type CreatePagedQueryOptions<TArgs extends QueryArgs> = {
|
|
9
|
+
/**
|
|
10
|
+
* The normalizer function that will be used to normalize the response to a format that the paged query can understand.
|
|
11
|
+
*
|
|
12
|
+
* There are some built-in normalizers that can be used:
|
|
13
|
+
* - `ethletePaginationAdapter`
|
|
14
|
+
* - `ggLikePaginationAdapter`
|
|
15
|
+
* - `dynLikePaginationAdapter`
|
|
16
|
+
* - `contentfulGqlLikePaginationAdapter`
|
|
17
|
+
*/
|
|
9
18
|
responseNormalizer: (response: ResponseType<TArgs>) => NormalizedPagination<ResponseType<TArgs>>;
|
|
19
|
+
/**
|
|
20
|
+
* The query creator function that will be used to create the paged query.
|
|
21
|
+
*/
|
|
10
22
|
queryCreator: QueryCreator<TArgs>;
|
|
23
|
+
/**
|
|
24
|
+
* The arguments to create the query.
|
|
25
|
+
* The current page will be passed as an argument.
|
|
26
|
+
* This function can be treated like a computed function. It reacts to signal changes.
|
|
27
|
+
* If a signal changes, the paged query will be reset to the initial page.
|
|
28
|
+
*
|
|
29
|
+
* @example (page) => ({ queryParams: { page, limit:20 } }),
|
|
30
|
+
*/
|
|
11
31
|
args: (page: number) => RequestArgs<TArgs>;
|
|
32
|
+
/**
|
|
33
|
+
* The page to start this paged query from.
|
|
34
|
+
* @default 1
|
|
35
|
+
*/
|
|
12
36
|
initialPage?: number;
|
|
13
37
|
};
|
|
14
38
|
export type PagedQueryResetOptions = {
|
|
39
|
+
/**
|
|
40
|
+
* The page to reset this paged query to.
|
|
41
|
+
* This will clear everything and start from this page.
|
|
42
|
+
* @default 1 // or the value passed in the `initialPage` option when creating the paged query.
|
|
43
|
+
*/
|
|
15
44
|
initialPage?: number;
|
|
16
45
|
};
|
|
46
|
+
export type PagedQueryExecuteOptions<TArgs extends QueryArgs> = {
|
|
47
|
+
/**
|
|
48
|
+
* If provided, only the queries that match the condition will be executed.
|
|
49
|
+
* This will also execute the previous and next query to the one that matched the condition.
|
|
50
|
+
* If not provided, all queries will be executed.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* myPagedQuery.execute({ where: (item) => item.id === 4 });
|
|
54
|
+
*/
|
|
55
|
+
where?: (item: ResponseType<TArgs>, index: number, array: ResponseType<TArgs>[]) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* If true, the cache will be used (if not expired) and the request will not be made.
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
allowCache?: boolean;
|
|
61
|
+
};
|
|
17
62
|
export declare const createPagedQuery: <TArgs extends QueryArgs>(options: CreatePagedQueryOptions<TArgs>) => {
|
|
18
63
|
pagination: import("@angular/core").Signal<NormalizedPagination<ResponseType<TArgs>> | null>;
|
|
19
64
|
fetchPreviousPage: () => void;
|
|
@@ -28,8 +73,5 @@ export declare const createPagedQuery: <TArgs extends QueryArgs>(options: Create
|
|
|
28
73
|
isFirstLoad: import("@angular/core").Signal<boolean>;
|
|
29
74
|
queries: Query<TArgs>[];
|
|
30
75
|
reset: (resetOptions?: PagedQueryResetOptions) => void;
|
|
31
|
-
execute: (options?:
|
|
32
|
-
where?: (items: ResponseType<TArgs>) => boolean;
|
|
33
|
-
skipCache?: boolean;
|
|
34
|
-
}) => void;
|
|
76
|
+
execute: (options?: PagedQueryExecuteOptions<TArgs>) => void;
|
|
35
77
|
};
|
|
@@ -20,7 +20,7 @@ export declare const enum RuntimeErrorCode {
|
|
|
20
20
|
UNABLE_TO_DECRYPT_BEARER_TOKEN = 210,
|
|
21
21
|
BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER = 211,
|
|
22
22
|
UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM = 300,
|
|
23
|
-
|
|
23
|
+
UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM = 301,
|
|
24
24
|
PAGED_QUERY_PAGE_BIGGER_THAN_TOTAL_PAGES = 400,
|
|
25
25
|
PAGED_QUERY_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE = 401,
|
|
26
26
|
PAGED_QUERY_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE = 402
|
|
@@ -43,7 +43,7 @@ export declare const defaultResponseTransformerResponseNotContainingRefreshToken
|
|
|
43
43
|
export declare const unableToDecryptBearerToken: (token: string) => RuntimeError<RuntimeErrorCode.UNABLE_TO_DECRYPT_BEARER_TOKEN>;
|
|
44
44
|
export declare const bearerExpiresInPropertyNotNumber: (expiresIn: unknown) => RuntimeError<RuntimeErrorCode.BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER>;
|
|
45
45
|
export declare const uncacheableRequestHasCacheKeyParam: (key: string) => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM>;
|
|
46
|
-
export declare const
|
|
46
|
+
export declare const uncacheableRequestHasAllowCacheParam: () => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM>;
|
|
47
47
|
export declare const pagedQueryPageBiggerThanTotalPages: (page: number, totalPages: number) => RuntimeError<RuntimeErrorCode.PAGED_QUERY_PAGE_BIGGER_THAN_TOTAL_PAGES>;
|
|
48
48
|
export declare const pagedQueryNextPageCalledWithoutPreviousPage: () => RuntimeError<RuntimeErrorCode.PAGED_QUERY_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE>;
|
|
49
49
|
export declare const pagedQueryPreviousPageCalledButAlreadyAtFirstPage: () => RuntimeError<RuntimeErrorCode.PAGED_QUERY_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE>;
|
|
@@ -12,7 +12,7 @@ export type QueryExecuteState = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const setupQueryExecuteState: () => QueryExecuteState;
|
|
14
14
|
export type RunQueryExecuteOptions = {
|
|
15
|
-
|
|
15
|
+
allowCache?: boolean;
|
|
16
16
|
};
|
|
17
17
|
export type QueryExecuteOptions<TArgs extends QueryArgs> = {
|
|
18
18
|
executeOptions: CreateQueryExecuteOptions<TArgs>;
|
|
@@ -14,7 +14,7 @@ export type QueryStack<T extends AnyQuery, J = ReturnType<T['response']>[]> = {
|
|
|
14
14
|
response: Signal<J>;
|
|
15
15
|
/** Executes all queries in the stack. */
|
|
16
16
|
execute: (options?: {
|
|
17
|
-
|
|
17
|
+
allowCache?: boolean;
|
|
18
18
|
}) => void;
|
|
19
19
|
/** Destroys all queries in the stack and empties it. This should only be used if `append` is true. */
|
|
20
20
|
clear: () => void;
|
|
@@ -27,7 +27,7 @@ export type ShouldRetryRequestResult = {
|
|
|
27
27
|
delay: number;
|
|
28
28
|
};
|
|
29
29
|
export type ShouldRetryRequestFn = (options: ShouldRetryRequestOptions) => ShouldRetryRequestResult;
|
|
30
|
-
export declare const shouldRetryRequest: (options: ShouldRetryRequestOptions) => ShouldRetryRequestResult;
|
|
30
|
+
export declare const shouldRetryRequest: (options: ShouldRetryRequestOptions | HttpErrorResponse) => ShouldRetryRequestResult;
|
|
31
31
|
export type QueryFeatureFlags = {
|
|
32
32
|
hasWithArgsFeature: boolean;
|
|
33
33
|
shouldAutoExecuteMethod: boolean;
|
|
@@ -53,7 +53,10 @@ export declare function queryComputed<T extends AnyQuery | null>(computation: ()
|
|
|
53
53
|
export declare function queryComputedTillTruthy<T extends AnyQuery | null>(computation: () => T, options?: CreateComputedOptions<T> & QueryContainerConfig & ToObservableOptions): Signal<T | null>;
|
|
54
54
|
export declare function queryArrayComputed<T extends AnyQuery[] | null>(computation: () => T, options?: CreateComputedOptions<T> & QueryContainerConfig & ToObservableOptions): Signal<T>;
|
|
55
55
|
export declare function toQuerySubject<T extends AnyQuery | null>(source: Signal<T>, options?: ToObservableOptions & QueryContainerConfig): Observable<T>;
|
|
56
|
-
export declare function queryStateSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T, options?: QueryFilterConfig):
|
|
57
|
-
export
|
|
56
|
+
export declare function queryStateSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T, options?: QueryFilterConfig): import("@angular/core").WritableSignal<QueryState<QueryDataOf<QueryOf<ReturnType<T>>>> | null>;
|
|
57
|
+
export type QueryStateSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>> = Signal<QueryDataOf<QueryOf<ReturnType<T>>> | null> & {
|
|
58
|
+
reset: () => void;
|
|
59
|
+
};
|
|
60
|
+
export declare function queryStateResponseSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T, options?: QueryFilterConfig): QueryStateSignal<T>;
|
|
58
61
|
export declare function queryStateErrorSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T): Signal<import("@ethlete/query").RequestError<unknown> | null>;
|
|
59
62
|
export declare function queryStateLoadingSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T): Signal<import("../query").Loading | null>;
|