@ethlete/query 5.23.0 → 5.25.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/fesm2022/ethlete-query.mjs +611 -202
  3. package/fesm2022/ethlete-query.mjs.map +1 -1
  4. package/lib/experimental/{bearer-auth-provider-config.d.ts → auth/bearer-auth-provider-config.d.ts} +11 -3
  5. package/lib/experimental/{bearer-auth-provider.d.ts → auth/bearer-auth-provider.d.ts} +1 -1
  6. package/lib/experimental/auth/index.d.ts +2 -0
  7. package/lib/experimental/gql/gql-query-creator-templates.d.ts +11 -0
  8. package/lib/experimental/gql/gql-query-creator.d.ts +14 -0
  9. package/lib/experimental/gql/gql-query-execute.d.ts +11 -0
  10. package/lib/experimental/gql/gql-query.d.ts +12 -0
  11. package/lib/experimental/gql/index.d.ts +4 -0
  12. package/lib/experimental/http/index.d.ts +20 -0
  13. package/lib/experimental/http/paged-query-stack.d.ts +149 -0
  14. package/lib/experimental/http/query-client-config.d.ts +45 -0
  15. package/lib/experimental/{query-creator-templates.d.ts → http/query-creator-templates.d.ts} +11 -1
  16. package/lib/experimental/http/query-creator.d.ts +73 -0
  17. package/lib/experimental/{query-dependencies.d.ts → http/query-dependencies.d.ts} +5 -0
  18. package/lib/experimental/http/query-errors.d.ts +52 -0
  19. package/lib/experimental/{query-execute-utils.d.ts → http/query-execute-utils.d.ts} +15 -2
  20. package/lib/experimental/{query-execute.d.ts → http/query-execute.d.ts} +5 -3
  21. package/lib/experimental/http/query-features.d.ts +120 -0
  22. package/lib/experimental/{query-repository.d.ts → http/query-repository.d.ts} +3 -1
  23. package/lib/experimental/{query-snapshot.d.ts → http/query-snapshot.d.ts} +2 -2
  24. package/lib/experimental/http/query-stack.d.ts +101 -0
  25. package/lib/experimental/{query-state.d.ts → http/query-state.d.ts} +5 -1
  26. package/lib/experimental/{query-utils.d.ts → http/query-utils.d.ts} +25 -15
  27. package/lib/experimental/{query.d.ts → http/query.d.ts} +26 -2
  28. package/lib/experimental/{secure-query-creator.d.ts → http/secure-query-creator.d.ts} +1 -1
  29. package/lib/experimental/{secure-query-execute.d.ts → http/secure-query-execute.d.ts} +2 -2
  30. package/lib/experimental/index.d.ts +4 -22
  31. package/lib/experimental/ws/index.d.ts +2 -0
  32. package/lib/experimental/ws/web-socket-client-config.d.ts +14 -0
  33. package/lib/experimental/ws/web-socket-client.d.ts +37 -0
  34. package/lib/experimental/ws/web-socket-errors.d.ts +7 -0
  35. package/lib/gql/gql.d.ts +3 -2
  36. package/package.json +8 -7
  37. package/lib/experimental/paged-query.d.ts +0 -77
  38. package/lib/experimental/query-client-config.d.ts +0 -18
  39. package/lib/experimental/query-creator.d.ts +0 -39
  40. package/lib/experimental/query-errors.d.ts +0 -49
  41. package/lib/experimental/query-features.d.ts +0 -48
  42. package/lib/experimental/query-stack.d.ts +0 -48
  43. /package/lib/experimental/{http-request.d.ts → http/http-request.d.ts} +0 -0
  44. /package/lib/experimental/{query-client.d.ts → http/query-client.d.ts} +0 -0
  45. /package/lib/experimental/{secure-query.d.ts → http/secure-query.d.ts} +0 -0
@@ -1,8 +1,6 @@
1
1
  import { InjectionToken } from '@angular/core';
2
+ import { QueryArgs, QueryClientRef, QueryCreator, RequestArgs, ResponseType } from '../http';
2
3
  import { BearerAuthProvider } from './bearer-auth-provider';
3
- import { QueryArgs, RequestArgs, ResponseType } from './query';
4
- import { QueryClientRef } from './query-client-config';
5
- import { QueryCreator } from './query-creator';
6
4
  export type BearerAuthProviderTokens = {
7
5
  accessToken: string;
8
6
  refreshToken: string;
@@ -57,6 +55,16 @@ export type BearerAuthProviderCookieConfig<TTokenRefreshArgs extends QueryArgs>
57
55
  * @default (token) => ({ token })
58
56
  */
59
57
  refreshArgsTransformer?: (token: string) => RequestArgs<TTokenRefreshArgs>;
58
+ /**
59
+ * An array of routes where the auto login via cookie should not be triggered.
60
+ *
61
+ * This checks the current route against the array of routes using the `startsWith` method.
62
+ * Make sure to start each route with a `/`.
63
+ *
64
+ * @default []
65
+ * @example ['/login', '/register']
66
+ */
67
+ autoLoginExcludeRoutes?: string[];
60
68
  };
61
69
  export type CreateBearerAuthProviderConfigOptions<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = {
62
70
  /**
@@ -1,7 +1,7 @@
1
1
  import { HttpErrorResponse } from '@angular/common/http';
2
2
  import { Signal } from '@angular/core';
3
+ import { QueryArgs, QuerySnapshot, RequestArgs } from '../http';
3
4
  import { BearerAuthProviderConfig, BearerAuthProviderTokens } from './bearer-auth-provider-config';
4
- import { QueryArgs, QuerySnapshot, RequestArgs } from './query';
5
5
  type QuerySnapshotWithType<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = ({
6
6
  type: 'login';
7
7
  } & QuerySnapshot<TLoginArgs>) | ({
@@ -0,0 +1,2 @@
1
+ export * from './bearer-auth-provider';
2
+ export * from './bearer-auth-provider-config';
@@ -0,0 +1,11 @@
1
+ import { QueryClientConfig } from '../http';
2
+ import { GqlQueryArgs } from './gql-query';
3
+ import { CreateGqlQueryCreatorOptions } from './gql-query-creator';
4
+ /** A query creator that creates a GQL query where the payload is sent via GET (query params) */
5
+ export declare const createGqlQueryViaGet: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(creatorOptions: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
6
+ /** A query creator that creates a GQL query where the payload is sent via POST (body) */
7
+ export declare const createGqlQueryViaPost: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(creatorOptions: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
8
+ /** A query creator that creates a GQL mutation where the payload is sent via GET (query params) */
9
+ export declare const createGqlMutationViaGet: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(creatorOptions: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
10
+ /** A query creator that creates a GQL mutation where the payload is sent via POST (body) */
11
+ export declare const createGqlMutationViaPost: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(creatorOptions: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
@@ -0,0 +1,14 @@
1
+ import { CreateQueryCreatorOptions, QueryClientConfig, QueryCreator, RouteType } from '../http';
2
+ import { GqlQueryArgs } from './gql-query';
3
+ export type CreateGqlQueryCreatorOptions<TArgs extends GqlQueryArgs> = Omit<CreateQueryCreatorOptions<TArgs>, 'route'> & {
4
+ query: string;
5
+ route?: RouteType<TArgs>;
6
+ };
7
+ export type GqlQueryMethod = 'QUERY' | 'MUTATE';
8
+ export type GqlQueryTransport = 'GET' | 'POST';
9
+ export type InternalCreateGqlQueryCreatorOptions = {
10
+ method: GqlQueryMethod;
11
+ transport: GqlQueryTransport;
12
+ client: QueryClientConfig;
13
+ };
14
+ export declare const createGqlQueryCreator: <TArgs extends GqlQueryArgs>(options: CreateGqlQueryCreatorOptions<TArgs>, internals: InternalCreateGqlQueryCreatorOptions) => QueryCreator<TArgs>;
@@ -0,0 +1,11 @@
1
+ import { InternalQueryExecute, QueryArgs, QueryConfig, QueryDependencies, QueryState } from '../http';
2
+ import { GqlQueryArgs } from './gql-query';
3
+ import { CreateGqlQueryCreatorOptions, InternalCreateGqlQueryCreatorOptions } from './gql-query-creator';
4
+ export type CreateGqlQueryExecuteOptions<TArgs extends QueryArgs> = {
5
+ deps: QueryDependencies;
6
+ state: QueryState<TArgs>;
7
+ creator: CreateGqlQueryCreatorOptions<TArgs>;
8
+ creatorInternals: InternalCreateGqlQueryCreatorOptions;
9
+ queryConfig: QueryConfig;
10
+ };
11
+ export declare const createGqlExecuteFn: <TArgs extends GqlQueryArgs>(executeOptions: CreateGqlQueryExecuteOptions<TArgs>) => InternalQueryExecute<TArgs>;
@@ -0,0 +1,12 @@
1
+ import { CreateQueryOptions, QueryArgs } from '../http';
2
+ import { CreateGqlQueryCreatorOptions, InternalCreateGqlQueryCreatorOptions } from './gql-query-creator';
3
+ export type GqlQueryArgs = QueryArgs & {
4
+ variables?: Record<string, unknown>;
5
+ };
6
+ export type CreateGqlQueryOptions<TArgs extends GqlQueryArgs> = Omit<CreateQueryOptions<TArgs>, 'creator' | 'creatorInternals'> & {
7
+ creator: CreateGqlQueryCreatorOptions<TArgs>;
8
+ creatorInternals: InternalCreateGqlQueryCreatorOptions;
9
+ };
10
+ export type GqlVariablesType<T extends GqlQueryArgs | null> = T extends GqlQueryArgs ? T['variables'] : never;
11
+ export declare const isCreateGqlQueryOptions: <TArgs extends QueryArgs>(options: CreateQueryOptions<TArgs> | CreateGqlQueryOptions<TArgs>) => options is CreateGqlQueryOptions<TArgs>;
12
+ export declare const createGqlQuery: <TArgs extends GqlQueryArgs>(options: CreateGqlQueryOptions<TArgs>) => import("../http").Query<TArgs>;
@@ -0,0 +1,4 @@
1
+ export * from './gql-query';
2
+ export * from './gql-query-creator';
3
+ export * from './gql-query-creator-templates';
4
+ export * from './gql-query-execute';
@@ -0,0 +1,20 @@
1
+ export * from './http-request';
2
+ export * from './paged-query-stack';
3
+ export * from './query';
4
+ export * from './query-client';
5
+ export * from './query-client-config';
6
+ export * from './query-creator';
7
+ export * from './query-creator-templates';
8
+ export * from './query-dependencies';
9
+ export * from './query-errors';
10
+ export * from './query-execute';
11
+ export * from './query-execute-utils';
12
+ export * from './query-features';
13
+ export * from './query-repository';
14
+ export * from './query-snapshot';
15
+ export * from './query-stack';
16
+ export * from './query-state';
17
+ export * from './query-utils';
18
+ export * from './secure-query';
19
+ export * from './secure-query-creator';
20
+ export * from './secure-query-execute';
@@ -0,0 +1,149 @@
1
+ import { HttpErrorResponse } from '@angular/common/http';
2
+ import { Signal } from '@angular/core';
3
+ import { ContentfulGqlLikePaginated, DynLikePaginated, GgLikePaginated, NormalizedPagination, Paginated } from '@ethlete/types';
4
+ import { AnyQuery, Query, QueryArgs, RequestArgs, ResponseType } from './query';
5
+ import { AnyQueryCreator, QueryArgsOf, QueryCreator } from './query-creator';
6
+ import { QueryFeature } from './query-features';
7
+ export declare const ethletePaginationAdapter: <T>(response: Paginated<T>) => NormalizedPagination<T>;
8
+ export declare const ggLikePaginationAdapter: <T>(response: GgLikePaginated<T>) => NormalizedPagination<T>;
9
+ export declare const dynLikePaginationAdapter: <T>(response: DynLikePaginated<T>) => NormalizedPagination<T>;
10
+ export declare const contentfulGqlLikePaginationAdapter: <T>(response: ContentfulGqlLikePaginated<T>) => NormalizedPagination<T>;
11
+ export declare const fakePaginationAdapter: (totalHits?: number) => <T>(response: T) => NormalizedPagination<T>;
12
+ export type CreatePagedQueryStackOptions<TArgs extends QueryArgs> = {
13
+ /**
14
+ * The normalizer function that will be used to normalize the response to a format that the paged query can understand.
15
+ *
16
+ * There are some built-in normalizers that can be used:
17
+ * - `ethletePaginationAdapter`
18
+ * - `ggLikePaginationAdapter`
19
+ * - `dynLikePaginationAdapter`
20
+ * - `contentfulGqlLikePaginationAdapter`
21
+ * - `fakePaginationAdapter` (for testing purposes)
22
+ */
23
+ responseNormalizer: (response: ResponseType<TArgs>) => NormalizedPagination<ResponseType<TArgs>>;
24
+ /**
25
+ * The query creator function that will be used to create the paged query.
26
+ */
27
+ queryCreator: QueryCreator<TArgs>;
28
+ /**
29
+ * The arguments to create the query.
30
+ * The current page will be passed as an argument.
31
+ * This function can be treated like a computed function. It reacts to signal changes.
32
+ * If a signal changes, the paged query will be reset to the initial page.
33
+ *
34
+ * @example (page) => ({ queryParams: { page, limit:20 } }),
35
+ */
36
+ args: (page: number) => RequestArgs<TArgs>;
37
+ /**
38
+ * The features that should be used for all queries in the stack.
39
+ *
40
+ * @throws If the `withArgs` feature is used. This feature is internally used.
41
+ *
42
+ * @example
43
+ * // Due to limitations in TypeScript, you have to manually add the needed generic types if needed.
44
+ * features: [E.withSuccessHandling<GetPostQueryArgs>({ handler: (post) => console.log(post.title) })]
45
+ *
46
+ * @example
47
+ * // If typings are not needed, you can use the feature without generics.
48
+ * features: [E.withPolling({ interval: 5000 })]
49
+ */
50
+ features?: QueryFeature<any>[];
51
+ /**
52
+ * The page to start this paged query from.
53
+ * @default 1
54
+ */
55
+ initialPage?: number;
56
+ };
57
+ export type PagedQueryStackResetOptions = {
58
+ /**
59
+ * The page to reset this paged query to.
60
+ * This will clear everything and start from this page.
61
+ * @default 1 // or the value passed in the `initialPage` option when creating the paged query.
62
+ */
63
+ initialPage?: number;
64
+ };
65
+ export type PagedQueryStackExecuteOptions<TArgs extends QueryArgs> = {
66
+ /**
67
+ * If provided, only the queries that match the condition will be executed.
68
+ * This will also execute the previous and next query to the one that matched the condition.
69
+ * If not provided, all queries will be executed.
70
+ *
71
+ * @example
72
+ * myPagedQuery.execute({ where: (item) => item.id === 4 });
73
+ */
74
+ where?: (item: ResponseType<TArgs>, index: number, array: ResponseType<TArgs>[]) => boolean;
75
+ /**
76
+ * If true, the cache will be used (if not expired) and the request will not be made.
77
+ * @default false
78
+ */
79
+ allowCache?: boolean;
80
+ };
81
+ export type PagedQueryStackDirection = 'next' | 'previous';
82
+ export type AnyPagedQueryStack = PagedQueryStack<AnyQuery>;
83
+ export type PagedQueryStack<TQuery extends AnyQuery> = {
84
+ /**
85
+ * The current pagination state of the paged query.
86
+ */
87
+ pagination: Signal<NormalizedPagination<ResponseType<QueryArgsOf<TQuery>>> | null>;
88
+ /**
89
+ * Fetches the previous page of the paged query.
90
+ *
91
+ * @throws If the paged query is already at the first page.
92
+ */
93
+ fetchPreviousPage: () => void;
94
+ /**
95
+ * Fetches the next page of the paged query.
96
+ *
97
+ * @throws If the paged query is already at the last page.
98
+ */
99
+ fetchNextPage: () => void;
100
+ /**
101
+ * Whether the previous page can be fetched or not.
102
+ *
103
+ * This will be false if the paged query is already at the first page or if the paged query is loading.
104
+ */
105
+ canFetchPreviousPage: Signal<boolean>;
106
+ /**
107
+ * Whether the next page can be fetched or not.
108
+ *
109
+ * This will be false if the paged query is already at the last page or if the paged query is loading.
110
+ */
111
+ canFetchNextPage: Signal<boolean>;
112
+ /**
113
+ * The items of the paged query.
114
+ */
115
+ items: Signal<ResponseType<QueryArgsOf<TQuery>>[]>;
116
+ /**
117
+ * Whether the paged query is loading or not.
118
+ */
119
+ loading: Signal<boolean>;
120
+ /**
121
+ * The error that occurred during the last execution of the paged query.
122
+ */
123
+ error: Signal<HttpErrorResponse | null>;
124
+ /**
125
+ * The last query executed in the paged query.
126
+ */
127
+ lastQuery: Signal<Query<QueryArgsOf<TQuery>> | null>;
128
+ /**
129
+ * Whether the paged query is on its first load or not.
130
+ */
131
+ isFirstLoad: Signal<boolean>;
132
+ /**
133
+ * The queries in the paged query stack.
134
+ */
135
+ queries: Signal<TQuery[]>;
136
+ /**
137
+ * Resets the paged query to the initial page.
138
+ */
139
+ reset: (resetOptions?: PagedQueryStackResetOptions) => void;
140
+ /**
141
+ * Executes the paged query.
142
+ */
143
+ execute: (options?: PagedQueryStackExecuteOptions<QueryArgsOf<TQuery>>) => void;
144
+ /**
145
+ * The current direction of the paged query.
146
+ */
147
+ direction: Signal<PagedQueryStackDirection>;
148
+ };
149
+ export declare const createPagedQueryStack: <TCreator extends AnyQueryCreator, TArgs extends QueryArgsOf<TCreator>>(options: CreatePagedQueryStackOptions<TArgs>) => PagedQueryStack<Query<TArgs>>;
@@ -0,0 +1,45 @@
1
+ import { HttpHeaders } from '@angular/common/http';
2
+ import { InjectionToken } from '@angular/core';
3
+ import { BuildQueryStringConfig } from '../../request';
4
+ import { QueryClient } from './query-client';
5
+ import { ShouldRetryRequestFn } from './query-utils';
6
+ export type CacheAdapterFn = (headers: HttpHeaders) => number | null;
7
+ export type CreateQueryClientConfigOptions = {
8
+ /**
9
+ * The base URL of the client
10
+ * @example 'https://api.example.com/v1'
11
+ */
12
+ baseUrl: string;
13
+ /** Configuration for building query strings */
14
+ queryString?: BuildQueryStringConfig;
15
+ /** The name of the client */
16
+ name: string;
17
+ /**
18
+ * The cache adapter function to use for the client.
19
+ * It determines how long the response of a request can be cached.
20
+ *
21
+ * @default extractExpiresInSeconds()
22
+ */
23
+ cacheAdapter?: CacheAdapterFn;
24
+ /**
25
+ * The retry function to use for the client.
26
+ * It determines if a request should be retried after it failed.
27
+ *
28
+ * @default shouldRetryRequest()
29
+ */
30
+ retryFn?: ShouldRetryRequestFn;
31
+ };
32
+ export type QueryClientConfig = CreateQueryClientConfigOptions & {
33
+ /** A generated token for dependency injection */
34
+ token: QueryClientRef;
35
+ };
36
+ /**
37
+ * A token for a query client.
38
+ * This token can be used to inject a query client into a service.
39
+ */
40
+ export type QueryClientRef = InjectionToken<QueryClient>;
41
+ /**
42
+ * This function creates a query client config.
43
+ * The config is used to create a query client using the `provideQueryClient(myConfig)` function.
44
+ */
45
+ export declare const createQueryClientConfig: (options: CreateQueryClientConfigOptions) => QueryClientConfig;
@@ -1,14 +1,24 @@
1
- import { AnyBearerAuthProviderConfig } from './bearer-auth-provider-config';
1
+ import { AnyBearerAuthProviderConfig } from '../auth/bearer-auth-provider-config';
2
2
  import { QueryArgs } from './query';
3
3
  import { QueryClientConfig } from './query-client-config';
4
4
  import { CreateQueryCreatorOptions } from './query-creator';
5
+ /** A query creator that creates a GET query */
5
6
  export declare const createGetQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
7
+ /** A query creator that creates a secure GET query (requires authentication) */
6
8
  export declare const createSecureGetQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
9
+ /** A query creator that creates a POST query */
7
10
  export declare const createPostQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
11
+ /** A query creator that creates a secure POST query (requires authentication) */
8
12
  export declare const createSecurePostQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
13
+ /** A query creator that creates a PUT query */
9
14
  export declare const createPutQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
15
+ /** A query creator that creates a secure PUT query (requires authentication) */
10
16
  export declare const createSecurePutQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
17
+ /** A query creator that creates a DELETE query */
11
18
  export declare const createDeleteQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
19
+ /** A query creator that creates a secure DELETE query (requires authentication) */
12
20
  export declare const createSecureDeleteQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
21
+ /** A query creator that creates a PATCH query */
13
22
  export declare const createPatchQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
23
+ /** A query creator that creates a secure PATCH query (requires authentication) */
14
24
  export declare const createSecurePatchQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
@@ -0,0 +1,73 @@
1
+ import { HttpRequestResponseType, HttpRequestTransferCacheConfig } from './http-request';
2
+ import { AnyQuery, PathParamsType, Query, QueryArgs } from './query';
3
+ import { QueryClientConfig } from './query-client-config';
4
+ import { QueryFeature } from './query-features';
5
+ export type RouteType<TArgs extends QueryArgs> = PathParamsType<TArgs> extends {
6
+ [key: string]: unknown;
7
+ } ? (args: TArgs['pathParams']) => RouteString : RouteString;
8
+ export type RouteString = `/${string}`;
9
+ export type CreateQueryCreatorOptions<TArgs extends QueryArgs> = {
10
+ /**
11
+ * The route of the query.
12
+ * If the query has path params, the route should be a function that takes the path params as an argument.
13
+ * Otherwise, it should be a string.
14
+ */
15
+ route: RouteType<TArgs>;
16
+ /**
17
+ * If true, the query loading state will include progress information.
18
+ * This is useful for file uploads and downloads.
19
+ *
20
+ * **Warning**: Upload progress events are not supported by browsers when using the fetch API, such as with `provideHttpClient(withFetch())`.
21
+ * In this case, you should use the older XHR implementation by omitting `withFetch()`. But take into account that XHR is not supported in server-side rendering environments.
22
+ *
23
+ * @see https://angular.dev/guide/http/making-requests#receiving-raw-progress-events
24
+ *
25
+ * @default false
26
+ */
27
+ reportProgress?: boolean;
28
+ /**
29
+ * The response type of the query.
30
+ * @default 'json'
31
+ */
32
+ responseType?: HttpRequestResponseType;
33
+ /**
34
+ * Whether to include credentials (cookies) in the request or not.
35
+ * @default false
36
+ */
37
+ withCredentials?: boolean;
38
+ /**
39
+ * This property accepts either a boolean to enable/disable transferring cache for eligible
40
+ * requests performed using `HttpClient`, or an object, which allows to configure cache
41
+ * parameters, such as which headers should be included (no headers are included by default).
42
+ *
43
+ * Setting this property will override the options passed to `provideClientHydration()` for this
44
+ * particular request
45
+ */
46
+ transferCache?: HttpRequestTransferCacheConfig;
47
+ };
48
+ export type QueryCreator<TArgs extends QueryArgs> = {
49
+ (...features: QueryFeature<TArgs>[]): Query<TArgs>;
50
+ (queryConfig: QueryConfig, ...features: QueryFeature<TArgs>[]): Query<TArgs>;
51
+ };
52
+ export type AnyQueryCreator = QueryCreator<any>;
53
+ export type QueryArgsOf<T extends AnyQueryCreator | AnyQuery> = T extends QueryCreator<infer TArgs> ? TArgs : T extends Query<infer TArgs> ? TArgs : never;
54
+ export type RunQueryCreator<TCreator extends AnyQueryCreator> = ReturnType<TCreator>;
55
+ export type QueryMethod = 'GET' | 'OPTIONS' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'CONNECT';
56
+ export type InternalCreateQueryCreatorOptions = {
57
+ method: QueryMethod;
58
+ client: QueryClientConfig;
59
+ };
60
+ export type QueryConfig = {
61
+ /** A custom id to use for this query. Only affects queries that can be cached. */
62
+ key?: string;
63
+ /**
64
+ * If true, the query will not be executed automatically.
65
+ * Does not affect mutations such as POST, PUT etc. since those are never executed automatically.
66
+ */
67
+ onlyManualExecution?: boolean;
68
+ };
69
+ export declare const splitQueryConfig: <TArgs extends QueryArgs>(args: (QueryFeature<TArgs> | QueryConfig)[]) => {
70
+ features: QueryFeature<TArgs>[];
71
+ queryConfig: QueryConfig;
72
+ };
73
+ export declare const createQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions<TArgs>, internals: InternalCreateQueryCreatorOptions) => QueryCreator<TArgs>;
@@ -5,8 +5,13 @@ export type SetupQueryDependenciesOptions = {
5
5
  clientConfig: QueryClientConfig;
6
6
  };
7
7
  export type QueryDependencies = {
8
+ /** The destroy ref of the query. */
8
9
  destroyRef: DestroyRef;
10
+ /** The destroy ref of the scope the query is in (e.g. a component) */
11
+ scopeDestroyRef: DestroyRef;
12
+ /** The query client */
9
13
  client: QueryClient;
14
+ /** The injector of the query */
10
15
  injector: EnvironmentInjector;
11
16
  };
12
17
  export declare const setupQueryDependencies: (options: SetupQueryDependenciesOptions) => QueryDependencies;
@@ -0,0 +1,52 @@
1
+ import { RuntimeError } from '@ethlete/core';
2
+ import { QueryFeatureType } from './query-features';
3
+ export declare const enum QueryRuntimeErrorCode {
4
+ QUERY_FEATURE_USED_MULTIPLE_TIMES = 0,
5
+ WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION = 100,
6
+ WITH_POLLING_USED_ON_UNSUPPORTED_HTTP_METHOD = 101,
7
+ WITH_AUTO_REFRESH_USED_ON_UNSUPPORTED_HTTP_METHOD = 102,
8
+ WITH_AUTO_REFRESH_USED_IN_MANUAL_QUERY = 103,
9
+ COOKIE_LOGIN_TRIED_BUT_COOKIE_DISABLED = 200,
10
+ ENABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG = 201,
11
+ DISABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG = 202,
12
+ LOGIN_CALLED_WITHOUT_CONFIG = 203,
13
+ LOGIN_WITH_TOKEN_CALLED_WITHOUT_CONFIG = 204,
14
+ REFRESH_TOKEN_CALLED_WITHOUT_CONFIG = 205,
15
+ SELECT_ROLE_CALLED_WITHOUT_CONFIG = 206,
16
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_OBJECT = 207,
17
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN = 208,
18
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN = 209,
19
+ UNABLE_TO_DECRYPT_BEARER_TOKEN = 210,
20
+ BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER = 211,
21
+ UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM = 300,
22
+ UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM = 301,
23
+ PAGED_QUERY_STACK_PAGE_BIGGER_THAN_TOTAL_PAGES = 400,
24
+ PAGED_QUERY_STACK_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE = 401,
25
+ PAGED_QUERY_STACK_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE = 402,
26
+ QUERY_STACK_WITH_ARGS_USED = 500,
27
+ QUERY_STACK_WITH_RESPONSE_UPDATE_USED = 501
28
+ }
29
+ export declare const queryFeatureUsedMultipleTimes: (type: QueryFeatureType) => RuntimeError<QueryRuntimeErrorCode.QUERY_FEATURE_USED_MULTIPLE_TIMES>;
30
+ export declare const withArgsQueryFeatureMissingButRouteIsFunction: () => RuntimeError<QueryRuntimeErrorCode.WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION>;
31
+ export declare const withPollingUsedOnUnsupportedHttpMethod: (method: string) => RuntimeError<QueryRuntimeErrorCode.WITH_POLLING_USED_ON_UNSUPPORTED_HTTP_METHOD>;
32
+ export declare const withAutoRefreshUsedOnUnsupportedHttpMethod: (method: string) => RuntimeError<QueryRuntimeErrorCode.WITH_AUTO_REFRESH_USED_ON_UNSUPPORTED_HTTP_METHOD>;
33
+ export declare const withAutoRefreshUsedInManualQuery: () => RuntimeError<QueryRuntimeErrorCode.WITH_AUTO_REFRESH_USED_IN_MANUAL_QUERY>;
34
+ export declare const cookieLoginTriedButCookieDisabled: () => RuntimeError<QueryRuntimeErrorCode.COOKIE_LOGIN_TRIED_BUT_COOKIE_DISABLED>;
35
+ export declare const enableCookieCalledWithoutCookieConfig: () => RuntimeError<QueryRuntimeErrorCode.ENABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
36
+ export declare const disableCookieCalledWithoutCookieConfig: () => RuntimeError<QueryRuntimeErrorCode.DISABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
37
+ export declare const loginCalledWithoutConfig: () => RuntimeError<QueryRuntimeErrorCode.LOGIN_CALLED_WITHOUT_CONFIG>;
38
+ export declare const loginWithTokenCalledWithoutConfig: () => RuntimeError<QueryRuntimeErrorCode.LOGIN_WITH_TOKEN_CALLED_WITHOUT_CONFIG>;
39
+ export declare const refreshTokenCalledWithoutConfig: () => RuntimeError<QueryRuntimeErrorCode.REFRESH_TOKEN_CALLED_WITHOUT_CONFIG>;
40
+ export declare const selectRoleCalledWithoutConfig: () => RuntimeError<QueryRuntimeErrorCode.SELECT_ROLE_CALLED_WITHOUT_CONFIG>;
41
+ export declare const defaultResponseTransformerResponseNotObject: (currentType: string) => RuntimeError<QueryRuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_OBJECT>;
42
+ export declare const defaultResponseTransformerResponseNotContainingAccessToken: () => RuntimeError<QueryRuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN>;
43
+ export declare const defaultResponseTransformerResponseNotContainingRefreshToken: () => RuntimeError<QueryRuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN>;
44
+ export declare const unableToDecryptBearerToken: (token: string) => RuntimeError<QueryRuntimeErrorCode.UNABLE_TO_DECRYPT_BEARER_TOKEN>;
45
+ export declare const bearerExpiresInPropertyNotNumber: (expiresIn: unknown) => RuntimeError<QueryRuntimeErrorCode.BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER>;
46
+ export declare const uncacheableRequestHasCacheKeyParam: (key: string) => RuntimeError<QueryRuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM>;
47
+ export declare const uncacheableRequestHasAllowCacheParam: () => RuntimeError<QueryRuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM>;
48
+ export declare const pagedQueryStackPageBiggerThanTotalPages: (page: number, totalPages: number) => RuntimeError<QueryRuntimeErrorCode.PAGED_QUERY_STACK_PAGE_BIGGER_THAN_TOTAL_PAGES>;
49
+ export declare const pagedQueryStackNextPageCalledWithoutPreviousPage: () => RuntimeError<QueryRuntimeErrorCode.PAGED_QUERY_STACK_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE>;
50
+ export declare const pagedQueryStackPreviousPageCalledButAlreadyAtFirstPage: () => RuntimeError<QueryRuntimeErrorCode.PAGED_QUERY_STACK_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE>;
51
+ export declare const queryStackWithArgsUsed: () => RuntimeError<QueryRuntimeErrorCode.QUERY_STACK_WITH_ARGS_USED>;
52
+ export declare const queryStackWithResponseUpdateUsed: () => RuntimeError<QueryRuntimeErrorCode.QUERY_STACK_WITH_RESPONSE_UPDATE_USED>;
@@ -2,7 +2,7 @@ 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> = {
5
- executeOptions: CreateQueryExecuteOptions<TArgs>;
5
+ executeOptions: Pick<CreateQueryExecuteOptions<TArgs>, 'state' | 'deps'>;
6
6
  executeState: QueryExecuteState;
7
7
  };
8
8
  export declare const resetExecuteState: <TArgs extends QueryArgs>(options: ResetExecuteStateOptions<TArgs>) => void;
@@ -14,15 +14,28 @@ export declare const setupQueryExecuteState: () => QueryExecuteState;
14
14
  export type RunQueryExecuteOptions = {
15
15
  allowCache?: boolean;
16
16
  };
17
+ export type InternalRunQueryExecuteOptions = {
18
+ /**
19
+ * If true, the request will be forced to be cached (saved inside the query repository).
20
+ * Can be used to e.g. cache GQL queries transported via POST
21
+ *
22
+ * - `true` means the request will always be cached
23
+ * - `false` means the request will never be cached
24
+ * - `undefined` means the request will be cached if the method is GET, OPTIONS or HEAD
25
+ */
26
+ useQueryRepositoryCache?: boolean;
27
+ };
17
28
  export type QueryExecuteOptions<TArgs extends QueryArgs> = {
18
29
  executeOptions: CreateQueryExecuteOptions<TArgs>;
19
30
  executeState: QueryExecuteState;
20
31
  args: RequestArgs<TArgs> | null;
21
32
  options?: RunQueryExecuteOptions;
33
+ internalOptions?: InternalRunQueryExecuteOptions;
34
+ transformResponse?: (response: any) => any;
22
35
  };
23
36
  export declare const queryExecute: <TArgs extends QueryArgs>(options: QueryExecuteOptions<TArgs>) => void;
24
37
  export type CleanupPreviousExecuteOptions<TArgs extends QueryArgs> = {
25
- executeOptions: CreateQueryExecuteOptions<TArgs>;
38
+ executeOptions: Pick<CreateQueryExecuteOptions<TArgs>, 'state'>;
26
39
  executeState: QueryExecuteState;
27
40
  };
28
41
  export declare const cleanupPreviousExecute: <TArgs extends QueryArgs>(options: CleanupPreviousExecuteOptions<TArgs>) => void;
@@ -3,6 +3,7 @@ import { QueryArgs, RequestArgs } from './query';
3
3
  import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
4
4
  import { QueryDependencies } from './query-dependencies';
5
5
  import { RunQueryExecuteOptions } from './query-execute-utils';
6
+ import { QueryKeyOrNone } from './query-repository';
6
7
  import { QueryState } from './query-state';
7
8
  export type CreateQueryExecuteOptions<TArgs extends QueryArgs> = {
8
9
  deps: QueryDependencies;
@@ -15,9 +16,10 @@ export type QueryExecuteArgs<TArgs extends QueryArgs> = {
15
16
  args?: RequestArgs<TArgs> | null;
16
17
  options?: RunQueryExecuteOptions;
17
18
  };
18
- export type QueryExecute<TArgs extends QueryArgs> = {
19
+ export type InternalQueryExecute<TArgs extends QueryArgs> = {
19
20
  (executeArgs?: QueryExecuteArgs<TArgs>): void;
20
21
  reset: () => void;
21
- currentRepositoryKey: Signal<string | false>;
22
+ currentRepositoryKey: Signal<QueryKeyOrNone>;
22
23
  };
23
- export declare const createExecuteFn: <TArgs extends QueryArgs>(executeOptions: CreateQueryExecuteOptions<TArgs>) => QueryExecute<TArgs>;
24
+ export type QueryExecute<TArgs extends QueryArgs> = (executeArgs?: QueryExecuteArgs<TArgs>) => void;
25
+ export declare const createExecuteFn: <TArgs extends QueryArgs>(executeOptions: CreateQueryExecuteOptions<TArgs>) => InternalQueryExecute<TArgs>;