@ethlete/query 5.16.2 → 5.18.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 (58) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/esm2022/index.mjs +2 -1
  3. package/esm2022/lib/devtools/components/query-devtools/query-devtools.component.mjs +3 -3
  4. package/esm2022/lib/devtools/pipes/query-short-name.pipe.mjs +3 -3
  5. package/esm2022/lib/directives/infinity-query-trigger.directive.mjs +3 -3
  6. package/esm2022/lib/directives/infinity-query.directive.mjs +3 -3
  7. package/esm2022/lib/directives/query.directive.mjs +3 -3
  8. package/esm2022/lib/experimental/bearer-auth-provider-config.mjs +19 -0
  9. package/esm2022/lib/experimental/bearer-auth-provider.mjs +245 -0
  10. package/esm2022/lib/experimental/http-request.mjs +153 -0
  11. package/esm2022/lib/experimental/index.mjs +21 -0
  12. package/esm2022/lib/experimental/query-client-config.mjs +13 -0
  13. package/esm2022/lib/experimental/query-client.mjs +16 -0
  14. package/esm2022/lib/experimental/query-creator-templates.mjs +33 -0
  15. package/esm2022/lib/experimental/query-creator.mjs +28 -0
  16. package/esm2022/lib/experimental/query-dependencies.mjs +14 -0
  17. package/esm2022/lib/experimental/query-errors.mjs +55 -0
  18. package/esm2022/lib/experimental/query-execute-utils.mjs +57 -0
  19. package/esm2022/lib/experimental/query-execute.mjs +12 -0
  20. package/esm2022/lib/experimental/query-features.mjs +126 -0
  21. package/esm2022/lib/experimental/query-repository.mjs +91 -0
  22. package/esm2022/lib/experimental/query-snapshot.mjs +44 -0
  23. package/esm2022/lib/experimental/query-state.mjs +20 -0
  24. package/esm2022/lib/experimental/query-utils.mjs +148 -0
  25. package/esm2022/lib/experimental/query.mjs +37 -0
  26. package/esm2022/lib/experimental/secure-query-creator.mjs +15 -0
  27. package/esm2022/lib/experimental/secure-query-execute.mjs +77 -0
  28. package/esm2022/lib/experimental/secure-query.mjs +41 -0
  29. package/esm2022/lib/query/query.mjs +3 -2
  30. package/esm2022/lib/query/query.types.mjs +1 -1
  31. package/esm2022/lib/query-form/query-form.mjs +32 -11
  32. package/fesm2022/ethlete-query.mjs +1313 -31
  33. package/fesm2022/ethlete-query.mjs.map +1 -1
  34. package/index.d.ts +1 -0
  35. package/lib/experimental/bearer-auth-provider-config.d.ts +111 -0
  36. package/lib/experimental/bearer-auth-provider.d.ts +63 -0
  37. package/lib/experimental/http-request.d.ts +55 -0
  38. package/lib/experimental/index.d.ts +20 -0
  39. package/lib/experimental/query-client-config.d.ts +18 -0
  40. package/lib/experimental/query-client.d.ts +10 -0
  41. package/lib/experimental/query-creator-templates.d.ts +14 -0
  42. package/lib/experimental/query-creator.d.ts +39 -0
  43. package/lib/experimental/query-dependencies.d.ts +12 -0
  44. package/lib/experimental/query-errors.d.ts +39 -0
  45. package/lib/experimental/query-execute-utils.d.ts +20 -0
  46. package/lib/experimental/query-execute.d.ts +16 -0
  47. package/lib/experimental/query-features.d.ts +45 -0
  48. package/lib/experimental/query-repository.d.ts +31 -0
  49. package/lib/experimental/query-snapshot.d.ts +8 -0
  50. package/lib/experimental/query-state.d.ts +14 -0
  51. package/lib/experimental/query-utils.d.ts +41 -0
  52. package/lib/experimental/query.d.ts +41 -0
  53. package/lib/experimental/secure-query-creator.d.ts +7 -0
  54. package/lib/experimental/secure-query-execute.d.ts +7 -0
  55. package/lib/experimental/secure-query.d.ts +6 -0
  56. package/lib/query/query.types.d.ts +2 -1
  57. package/lib/query-form/query-form.d.ts +3 -1
  58. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './lib/devtools/pipes';
5
5
  export * from './lib/devtools/utils';
6
6
  export * from './lib/directives';
7
7
  export * from './lib/entity';
8
+ export * as ExperimentalQuery from './lib/experimental';
8
9
  export * from './lib/gql';
9
10
  export * from './lib/infinite-query';
10
11
  export * from './lib/logger';
@@ -0,0 +1,111 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ 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
+ export type BearerAuthProviderTokens = {
7
+ accessToken: string;
8
+ refreshToken: string;
9
+ };
10
+ export type BearerAuthProviderRouteConfig<TArgs extends QueryArgs> = {
11
+ queryCreator: QueryCreator<TArgs>;
12
+ /**
13
+ * A function that transforms the response into the format that the auth provider expects
14
+ *
15
+ * The expected format is an object with the `accessToken` and `refreshToken` properties.
16
+ *
17
+ * @default (response) => response
18
+ */
19
+ responseTransformer?: (response: ResponseType<TArgs>) => BearerAuthProviderTokens;
20
+ };
21
+ export type BearerAuthProviderCookieConfig<TTokenRefreshArgs extends QueryArgs> = {
22
+ /**
23
+ * The cookie name where the refresh token is stored
24
+ * @default 'etAuth'
25
+ */
26
+ name?: string;
27
+ /**
28
+ * The domain of the cookie. If not set, the current origin will be used.
29
+ *
30
+ * @example
31
+ * "https://example.com" -> "example.com"
32
+ * "https://sub.example.com" -> "example.com"
33
+ */
34
+ domain?: string;
35
+ /**
36
+ * The days until the cookie expires
37
+ * @default 30
38
+ */
39
+ expiresInDays?: number;
40
+ /**
41
+ * The path of the cookie
42
+ * @default '/'
43
+ */
44
+ path?: string;
45
+ /**
46
+ * Enable or disable the cookie
47
+ * @default true
48
+ */
49
+ enabled?: boolean;
50
+ /**
51
+ * The same site property of the cookie
52
+ * @default 'lax'
53
+ */
54
+ sameSite?: 'strict' | 'none' | 'lax';
55
+ /**
56
+ * A function that turns the token gotten from the cookie into the body for the refresh token request
57
+ * @default (token) => ({ token })
58
+ */
59
+ refreshArgsTransformer?: (token: string) => RequestArgs<TTokenRefreshArgs>;
60
+ };
61
+ export type CreateBearerAuthProviderConfigOptions<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = {
62
+ /**
63
+ * The name of the auth provider
64
+ */
65
+ name: string;
66
+ /**
67
+ * The query client reference
68
+ */
69
+ queryClientRef: QueryClientRef;
70
+ /**
71
+ * The login route configuration
72
+ */
73
+ login?: BearerAuthProviderRouteConfig<TLoginArgs>;
74
+ /**
75
+ * The token login route configuration
76
+ */
77
+ tokenLogin?: BearerAuthProviderRouteConfig<TTokenLoginArgs>;
78
+ /**
79
+ * The token refresh route configuration
80
+ */
81
+ tokenRefresh?: BearerAuthProviderRouteConfig<TTokenRefreshArgs>;
82
+ /**
83
+ * The select role route configuration
84
+ */
85
+ selectRole?: BearerAuthProviderRouteConfig<TSelectRoleArgs>;
86
+ /**
87
+ * The cookie configuration for the auth provider
88
+ */
89
+ cookie?: BearerAuthProviderCookieConfig<TTokenRefreshArgs>;
90
+ /**
91
+ * The time in milliseconds before the token expires when the refresh should be triggered.
92
+ * @default 300000 // (5 minutes)
93
+ */
94
+ refreshBuffer?: number;
95
+ /**
96
+ * The expires in property name inside the jwt body
97
+ * @default 'exp'
98
+ */
99
+ expiresInPropertyName?: string;
100
+ /**
101
+ * Determines if the token should be refreshed if **any** query returns a 401 response.
102
+ * @default true
103
+ */
104
+ refreshOnUnauthorizedResponse?: boolean;
105
+ };
106
+ export type BearerAuthProviderConfig<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = CreateBearerAuthProviderConfigOptions<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs> & {
107
+ token: BearerAuthProviderRef<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>;
108
+ };
109
+ export type AnyBearerAuthProviderConfig = BearerAuthProviderConfig<any, any, any, any>;
110
+ export type BearerAuthProviderRef<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = InjectionToken<BearerAuthProvider<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>>;
111
+ export declare const createBearerAuthProviderConfig: <TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs>(options: CreateBearerAuthProviderConfigOptions<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>) => BearerAuthProviderConfig<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>;
@@ -0,0 +1,63 @@
1
+ import { HttpErrorResponse } from '@angular/common/http';
2
+ import { Signal } from '@angular/core';
3
+ import { BearerAuthProviderConfig, BearerAuthProviderTokens } from './bearer-auth-provider-config';
4
+ import { QueryArgs, QuerySnapshot, RequestArgs } from './query';
5
+ type QuerySnapshotWithType<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = ({
6
+ type: 'login';
7
+ } & QuerySnapshot<TLoginArgs>) | ({
8
+ type: 'tokenLogin';
9
+ } & QuerySnapshot<TTokenLoginArgs>) | ({
10
+ type: 'tokenRefresh';
11
+ } & QuerySnapshot<TTokenRefreshArgs>) | ({
12
+ type: 'selectRole';
13
+ } & QuerySnapshot<TSelectRoleArgs>);
14
+ export type BearerAuthProvider<TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs> = {
15
+ /**
16
+ * Logs in the user with the given args.
17
+ */
18
+ login: (args: RequestArgs<TLoginArgs>) => QuerySnapshot<TLoginArgs>;
19
+ /**
20
+ * Logs in the user with the given token.
21
+ */
22
+ loginWithToken: (args: RequestArgs<TTokenLoginArgs>) => QuerySnapshot<TTokenLoginArgs>;
23
+ /**
24
+ * Refreshes the token with the given refresh token.
25
+ */
26
+ refreshToken: (args: RequestArgs<TTokenRefreshArgs>) => QuerySnapshot<TTokenRefreshArgs>;
27
+ /**
28
+ * Selects the role for the user.
29
+ */
30
+ selectRole: (args: RequestArgs<TSelectRoleArgs>) => QuerySnapshot<TSelectRoleArgs>;
31
+ /**
32
+ * Logs out the user and removes the cookie.
33
+ */
34
+ logout: () => void;
35
+ /**
36
+ * Enables cookie usage for the auth provider.
37
+ */
38
+ enableCookie: () => void;
39
+ /**
40
+ * Disables cookie usage for the auth provider and removes the cookie.
41
+ */
42
+ disableCookie: () => void;
43
+ /**
44
+ * Tries to login with the given cookie config.
45
+ * Returns `true` if a cookie was found, `false` otherwise.
46
+ */
47
+ tryLoginWithCookie: () => boolean;
48
+ /**
49
+ * The latest executed query that was not triggered internally.
50
+ */
51
+ latestExecutedQuery: Signal<QuerySnapshotWithType<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs> | null>;
52
+ onRefreshFailure?: (callback: (error: HttpErrorResponse) => void) => void;
53
+ /**
54
+ * A signal that contains the current access and refresh tokens.
55
+ */
56
+ tokens: Signal<BearerAuthProviderTokens | null>;
57
+ };
58
+ export declare const createBearerAuthProvider: <TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs>(options: BearerAuthProviderConfig<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>) => BearerAuthProvider<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>;
59
+ export declare const provideBearerAuthProvider: <TLoginArgs extends QueryArgs, TTokenLoginArgs extends QueryArgs, TTokenRefreshArgs extends QueryArgs, TSelectRoleArgs extends QueryArgs>(config: BearerAuthProviderConfig<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>) => {
60
+ provide: import("./bearer-auth-provider-config").BearerAuthProviderRef<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>;
61
+ useFactory: () => BearerAuthProvider<TLoginArgs, TTokenLoginArgs, TTokenRefreshArgs, TSelectRoleArgs>;
62
+ };
63
+ export {};
@@ -0,0 +1,55 @@
1
+ import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders } from '@angular/common/http';
2
+ import { Signal } from '@angular/core';
3
+ import { BodyType, PathParamsType, QueryArgs, QueryParamsType, ResponseType } from './query';
4
+ import { CacheAdapterFn } from './query-client-config';
5
+ import { QueryMethod } from './query-creator';
6
+ import { ShouldRetryRequestFn } from './query-utils';
7
+ export declare const SPEED_BUFFER_TIME_IN_MS = 2000;
8
+ export type CreateHttpRequestOptions<TArgs extends QueryArgs> = {
9
+ method: QueryMethod;
10
+ fullPath: string;
11
+ pathParams?: PathParamsType<TArgs>;
12
+ queryParams?: QueryParamsType<TArgs>;
13
+ body?: BodyType<TArgs>;
14
+ reportProgress?: boolean;
15
+ withCredentials?: boolean;
16
+ transferCache?: boolean | {
17
+ includeHeaders?: string[];
18
+ };
19
+ responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
20
+ context?: HttpContext;
21
+ headers?: HttpHeaders;
22
+ httpClient: HttpClient;
23
+ cacheAdapter?: CacheAdapterFn;
24
+ retryFn?: ShouldRetryRequestFn;
25
+ };
26
+ export type HttpRequestLoadingState = {
27
+ executeTime: number;
28
+ progress: HttpRequestLoadingProgressState | null;
29
+ };
30
+ export type HttpRequestLoadingProgressState = {
31
+ /** The total number of bytes to be transferred */
32
+ total: number;
33
+ /** The number of bytes transferred */
34
+ loaded: number;
35
+ /** The percentage of the transfer that is completed */
36
+ percentage: number;
37
+ /** The speed of the transfer in bytes per millisecond */
38
+ speed: number | null;
39
+ /** The estimated remaining time in milliseconds */
40
+ remainingTime: number | null;
41
+ };
42
+ export type HttpRequest<TArgs extends QueryArgs> = {
43
+ execute: () => boolean;
44
+ destroy: () => boolean;
45
+ loading: Signal<HttpRequestLoadingState | null>;
46
+ error: Signal<HttpErrorResponse | null>;
47
+ response: Signal<ResponseType<TArgs> | null>;
48
+ currentEvent: Signal<HttpEvent<ResponseType<TArgs>> | HttpErrorEvent | null>;
49
+ isStale: Signal<boolean>;
50
+ };
51
+ export type HttpErrorEvent = {
52
+ type: 'error';
53
+ error: HttpErrorResponse;
54
+ };
55
+ export declare const createHttpRequest: <TArgs extends QueryArgs>(options: CreateHttpRequestOptions<TArgs>) => HttpRequest<TArgs>;
@@ -0,0 +1,20 @@
1
+ export * from './bearer-auth-provider';
2
+ export * from './bearer-auth-provider-config';
3
+ export * from './http-request';
4
+ export * from './query';
5
+ export * from './query-client';
6
+ export * from './query-client-config';
7
+ export * from './query-creator';
8
+ export * from './query-creator-templates';
9
+ export * from './query-dependencies';
10
+ export * from './query-errors';
11
+ export * from './query-execute';
12
+ export * from './query-execute-utils';
13
+ export * from './query-features';
14
+ export * from './query-repository';
15
+ export * from './query-snapshot';
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,18 @@
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
+ baseUrl: string;
9
+ queryString?: BuildQueryStringConfig;
10
+ name: string;
11
+ cacheAdapter?: CacheAdapterFn;
12
+ retryFn?: ShouldRetryRequestFn;
13
+ };
14
+ export type QueryClientConfig = CreateQueryClientConfigOptions & {
15
+ token: QueryClientRef;
16
+ };
17
+ export type QueryClientRef = InjectionToken<QueryClient>;
18
+ export declare const createQueryClientConfig: (options: CreateQueryClientConfigOptions) => QueryClientConfig;
@@ -0,0 +1,10 @@
1
+ import { QueryClientConfig } from './query-client-config';
2
+ import { QueryRepository } from './query-repository';
3
+ export type QueryClient = {
4
+ repository: QueryRepository;
5
+ };
6
+ export declare const createQueryClient: (config: QueryClientConfig) => QueryClient;
7
+ export declare const provideQueryClient: (config: QueryClientConfig) => {
8
+ provide: import("./query-client-config").QueryClientRef;
9
+ useFactory: () => QueryClient;
10
+ };
@@ -0,0 +1,14 @@
1
+ import { AnyBearerAuthProviderConfig } from './bearer-auth-provider-config';
2
+ import { QueryArgs } from './query';
3
+ import { QueryClientConfig } from './query-client-config';
4
+ import { CreateQueryCreatorOptions } from './query-creator';
5
+ export declare const createGetQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
6
+ export declare const createSecureGetQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
7
+ export declare const createPostQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
8
+ export declare const createSecurePostQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
9
+ export declare const createPutQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
10
+ export declare const createSecurePutQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
11
+ export declare const createDeleteQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
12
+ export declare const createSecureDeleteQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
13
+ export declare const createPatchQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
14
+ export declare const createSecurePatchQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
@@ -0,0 +1,39 @@
1
+ import { PathParamsType, Query, QueryArgs } from './query';
2
+ import { QueryClientConfig } from './query-client-config';
3
+ import { QueryFeature } from './query-features';
4
+ export type RouteType<TArgs extends QueryArgs> = PathParamsType<TArgs> extends {
5
+ [key: string]: string;
6
+ } ? (args: TArgs['pathParams']) => RouteString : RouteString;
7
+ export type RouteString = `/${string}`;
8
+ export type CreateQueryCreatorOptions<TArgs extends QueryArgs> = {
9
+ route: RouteType<TArgs>;
10
+ reportProgress?: boolean;
11
+ responseType?: 'json';
12
+ withCredentials?: boolean;
13
+ transferCache?: {
14
+ includeHeaders?: string[];
15
+ } | boolean;
16
+ };
17
+ export type QueryCreator<TArgs extends QueryArgs> = {
18
+ (...features: QueryFeature<TArgs>[]): Query<TArgs>;
19
+ (queryConfig: QueryConfig, ...features: QueryFeature<TArgs>[]): Query<TArgs>;
20
+ };
21
+ export type QueryMethod = 'GET' | 'OPTIONS' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'CONNECT';
22
+ export type InternalCreateQueryCreatorOptions = {
23
+ method: QueryMethod;
24
+ client: QueryClientConfig;
25
+ };
26
+ export type QueryConfig = {
27
+ /** A custom id to use for this query. Only affects queries that can be cached. */
28
+ key?: string;
29
+ /**
30
+ * If true, the query will not be executed automatically.
31
+ * Does not affect mutations such as POST, PUT etc. since those are never executed automatically.
32
+ */
33
+ onlyManualExecution?: boolean;
34
+ };
35
+ export declare const splitQueryConfig: <TArgs extends QueryArgs>(args: (QueryFeature<TArgs> | QueryConfig)[]) => {
36
+ features: QueryFeature<TArgs>[];
37
+ queryConfig: QueryConfig;
38
+ };
39
+ export declare const createQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions<TArgs>, internals: InternalCreateQueryCreatorOptions) => QueryCreator<TArgs>;
@@ -0,0 +1,12 @@
1
+ import { DestroyRef, Injector } from '@angular/core';
2
+ import { QueryClient } from './query-client';
3
+ import { QueryClientConfig } from './query-client-config';
4
+ export type SetupQueryDependenciesOptions = {
5
+ clientConfig: QueryClientConfig;
6
+ };
7
+ export type QueryDependencies = {
8
+ destroyRef: DestroyRef;
9
+ client: QueryClient;
10
+ injector: Injector;
11
+ };
12
+ export declare const setupQueryDependencies: (options: SetupQueryDependenciesOptions) => QueryDependencies;
@@ -0,0 +1,39 @@
1
+ import { RuntimeError } from '@ethlete/core';
2
+ import { QueryMethod } from './query-creator';
3
+ import { QueryFeatureType } from './query-features';
4
+ export declare const enum RuntimeErrorCode {
5
+ QUERY_FEATURE_USED_MULTIPLE_TIMES = 0,
6
+ WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION = 100,
7
+ WITH_POLLING_USED_ON_UNSUPPORTED_HTTP_METHOD = 101,
8
+ WITH_AUTO_REFRESH_USED_ON_UNSUPPORTED_HTTP_METHOD = 102,
9
+ WITH_AUTO_REFRESH_USED_IN_MANUAL_QUERY = 103,
10
+ COOKIE_LOGIN_TRIED_BUT_COOKIE_DISABLED = 200,
11
+ ENABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG = 201,
12
+ DISABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG = 202,
13
+ LOGIN_CALLED_WITHOUT_CONFIG = 203,
14
+ LOGIN_WITH_TOKEN_CALLED_WITHOUT_CONFIG = 204,
15
+ REFRESH_TOKEN_CALLED_WITHOUT_CONFIG = 205,
16
+ SELECT_ROLE_CALLED_WITHOUT_CONFIG = 206,
17
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_OBJECT = 207,
18
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN = 208,
19
+ DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN = 209,
20
+ UNABLE_TO_DECRYPT_BEARER_TOKEN = 210,
21
+ BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER = 211
22
+ }
23
+ export declare const queryFeatureUsedMultipleTimes: (type: QueryFeatureType) => RuntimeError<RuntimeErrorCode.QUERY_FEATURE_USED_MULTIPLE_TIMES>;
24
+ export declare const withArgsQueryFeatureMissingButRouteIsFunction: () => RuntimeError<RuntimeErrorCode.WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION>;
25
+ export declare const withPollingUsedOnUnsupportedHttpMethod: (method: QueryMethod) => RuntimeError<RuntimeErrorCode.WITH_POLLING_USED_ON_UNSUPPORTED_HTTP_METHOD>;
26
+ export declare const withAutoRefreshUsedOnUnsupportedHttpMethod: (method: QueryMethod) => RuntimeError<RuntimeErrorCode.WITH_AUTO_REFRESH_USED_ON_UNSUPPORTED_HTTP_METHOD>;
27
+ export declare const withAutoRefreshUsedInManualQuery: () => RuntimeError<RuntimeErrorCode.WITH_AUTO_REFRESH_USED_IN_MANUAL_QUERY>;
28
+ export declare const cookieLoginTriedButCookieDisabled: () => RuntimeError<RuntimeErrorCode.COOKIE_LOGIN_TRIED_BUT_COOKIE_DISABLED>;
29
+ export declare const enableCookieCalledWithoutCookieConfig: () => RuntimeError<RuntimeErrorCode.ENABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
30
+ export declare const disableCookieCalledWithoutCookieConfig: () => RuntimeError<RuntimeErrorCode.DISABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
31
+ export declare const loginCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.LOGIN_CALLED_WITHOUT_CONFIG>;
32
+ export declare const loginWithTokenCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.LOGIN_WITH_TOKEN_CALLED_WITHOUT_CONFIG>;
33
+ export declare const refreshTokenCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.REFRESH_TOKEN_CALLED_WITHOUT_CONFIG>;
34
+ export declare const selectRoleCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.SELECT_ROLE_CALLED_WITHOUT_CONFIG>;
35
+ export declare const defaultResponseTransformerResponseNotObject: (currentType: string) => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_OBJECT>;
36
+ export declare const defaultResponseTransformerResponseNotContainingAccessToken: () => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN>;
37
+ export declare const defaultResponseTransformerResponseNotContainingRefreshToken: () => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN>;
38
+ export declare const unableToDecryptBearerToken: (token: string) => RuntimeError<RuntimeErrorCode.UNABLE_TO_DECRYPT_BEARER_TOKEN>;
39
+ export declare const bearerExpiresInPropertyNotNumber: (expiresIn: unknown) => RuntimeError<RuntimeErrorCode.BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER>;
@@ -0,0 +1,20 @@
1
+ import { EffectRef } from '@angular/core';
2
+ import { QueryArgs, RequestArgs } from './query';
3
+ import { CreateQueryExecuteOptions } from './query-execute';
4
+ export type ResetExecuteStateOptions<TArgs extends QueryArgs> = {
5
+ executeOptions: CreateQueryExecuteOptions<TArgs>;
6
+ executeState: QueryExecuteState;
7
+ };
8
+ export declare const resetExecuteState: <TArgs extends QueryArgs>(options: ResetExecuteStateOptions<TArgs>) => void;
9
+ export type QueryExecuteState = {
10
+ effectRefs: EffectRef[];
11
+ previousKey: string | false;
12
+ };
13
+ export declare const setupQueryExecuteState: () => QueryExecuteState;
14
+ export type QueryExecuteOptions<TArgs extends QueryArgs> = {
15
+ executeOptions: CreateQueryExecuteOptions<TArgs>;
16
+ executeState: QueryExecuteState;
17
+ args?: RequestArgs<TArgs> | null;
18
+ };
19
+ export declare const queryExecute: <TArgs extends QueryArgs>(options: QueryExecuteOptions<TArgs>) => void;
20
+ export declare const cleanupPreviousExecute: <TArgs extends QueryArgs>(options: QueryExecuteOptions<TArgs>) => void;
@@ -0,0 +1,16 @@
1
+ import { QueryArgs, RequestArgs } from './query';
2
+ import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
3
+ import { QueryDependencies } from './query-dependencies';
4
+ import { QueryState } from './query-state';
5
+ export type CreateQueryExecuteOptions<TArgs extends QueryArgs> = {
6
+ deps: QueryDependencies;
7
+ state: QueryState<TArgs>;
8
+ creator: CreateQueryCreatorOptions<TArgs>;
9
+ creatorInternals: InternalCreateQueryCreatorOptions;
10
+ queryConfig: QueryConfig;
11
+ };
12
+ export type QueryExecute<TArgs extends QueryArgs> = {
13
+ (args?: RequestArgs<TArgs> | null): void;
14
+ reset: () => void;
15
+ };
16
+ export declare const createExecuteFn: <TArgs extends QueryArgs>(options: CreateQueryExecuteOptions<TArgs>) => QueryExecute<TArgs>;
@@ -0,0 +1,45 @@
1
+ import { HttpErrorResponse, HttpEvent } from '@angular/common/http';
2
+ import { Signal } from '@angular/core';
3
+ import { QueryArgs, RequestArgs, ResponseType } from './query';
4
+ import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
5
+ import { QueryState } from './query-state';
6
+ import { QueryArgsReset, QueryFeatureFlags } from './query-utils';
7
+ export declare const enum QueryFeatureType {
8
+ WithArgs = "withArgs",
9
+ WithLogging = "withLogging",
10
+ WithErrorHandling = "withErrorHandling",
11
+ WithSuccessHandling = "withSuccessHandling",
12
+ WithPolling = "withPolling",
13
+ WithAutoRefresh = "withAutoRefresh"
14
+ }
15
+ export type QueryFeatureContext<TArgs extends QueryArgs> = {
16
+ state: QueryState<TArgs>;
17
+ queryConfig: QueryConfig;
18
+ creatorConfig: CreateQueryCreatorOptions<TArgs>;
19
+ creatorInternals: InternalCreateQueryCreatorOptions;
20
+ execute: (args: RequestArgs<TArgs>) => void;
21
+ flags: QueryFeatureFlags;
22
+ };
23
+ export type QueryFeatureFn<TArgs extends QueryArgs> = (context: QueryFeatureContext<TArgs>) => void;
24
+ export type QueryFeature<TArgs extends QueryArgs> = {
25
+ type: QueryFeatureType;
26
+ fn: (context: QueryFeatureContext<TArgs>) => void;
27
+ };
28
+ export declare const withArgs: <TArgs extends QueryArgs>(args: () => NoInfer<RequestArgs<TArgs>> | QueryArgsReset | null) => QueryFeature<TArgs>;
29
+ export declare const withPolling: <TArgs extends QueryArgs>(options: {
30
+ interval: number;
31
+ executeInitially?: boolean;
32
+ }) => QueryFeature<TArgs>;
33
+ export declare const withLogging: <TArgs extends QueryArgs>(options: {
34
+ logFn: (v: HttpEvent<ResponseType<TArgs>> | null) => void;
35
+ }) => QueryFeature<TArgs>;
36
+ export declare const withErrorHandling: <TArgs extends QueryArgs>(options: {
37
+ handler: (e: HttpErrorResponse) => void;
38
+ }) => QueryFeature<TArgs>;
39
+ export declare const withSuccessHandling: <TArgs extends QueryArgs>(options: {
40
+ handler: (data: NonNullable<ResponseType<TArgs>>) => void;
41
+ }) => QueryFeature<TArgs>;
42
+ export declare const withAutoRefresh: <TArgs extends QueryArgs>(options: {
43
+ signalChanges: Signal<unknown>[];
44
+ ignoreOnlyManualExecution?: boolean;
45
+ }) => QueryFeature<TArgs>;
@@ -0,0 +1,31 @@
1
+ import { HttpHeaders } from '@angular/common/http';
2
+ import { DestroyRef } from '@angular/core';
3
+ import { HttpRequest } from './http-request';
4
+ import { BodyType, PathParamsType, QueryArgs, QueryParamsType } from './query';
5
+ import { QueryClientConfig } from './query-client-config';
6
+ import { QueryMethod, RouteType } from './query-creator';
7
+ export type QueryRepositoryRequestOptions<TArgs extends QueryArgs> = {
8
+ method: QueryMethod;
9
+ route: RouteType<TArgs>;
10
+ pathParams?: PathParamsType<TArgs>;
11
+ queryParams?: QueryParamsType<TArgs>;
12
+ body?: BodyType<TArgs>;
13
+ headers?: HttpHeaders;
14
+ reportProgress?: boolean;
15
+ withCredentials?: boolean;
16
+ transferCache?: boolean | {
17
+ includeHeaders?: string[];
18
+ };
19
+ responseType?: 'json';
20
+ key?: string;
21
+ skipExecution?: boolean;
22
+ destroyRef: DestroyRef;
23
+ };
24
+ export type QueryRepository = {
25
+ request: <TArgs extends QueryArgs>(options: QueryRepositoryRequestOptions<TArgs>) => {
26
+ key: string | false;
27
+ request: HttpRequest<TArgs>;
28
+ };
29
+ unbind: (key: string | false, destroyRef: DestroyRef) => void;
30
+ };
31
+ export declare const createQueryRepository: (config: QueryClientConfig) => QueryRepository;
@@ -0,0 +1,8 @@
1
+ import { QueryArgs, QuerySnapshot } from './query';
2
+ import { QueryDependencies } from './query-dependencies';
3
+ import { QueryState } from './query-state';
4
+ export type CreateQuerySnapshotOptions<TArgs extends QueryArgs> = {
5
+ state: QueryState<TArgs>;
6
+ deps: QueryDependencies;
7
+ };
8
+ export declare const createQuerySnapshotFn: <TArgs extends QueryArgs>(options: CreateQuerySnapshotOptions<TArgs>) => () => QuerySnapshot<TArgs>;
@@ -0,0 +1,14 @@
1
+ import { HttpErrorResponse, HttpEvent } from '@angular/common/http';
2
+ import { WritableSignal } from '@angular/core';
3
+ import { HttpRequestLoadingState } from './http-request';
4
+ import { QueryArgs, RequestArgs, ResponseType } from './query';
5
+ export type SetupQueryStateOptions = {};
6
+ export type QueryState<TArgs extends QueryArgs> = {
7
+ response: WritableSignal<ResponseType<TArgs> | null>;
8
+ args: WritableSignal<RequestArgs<TArgs> | null>;
9
+ latestHttpEvent: WritableSignal<HttpEvent<ResponseType<TArgs>> | null>;
10
+ loading: WritableSignal<HttpRequestLoadingState | null>;
11
+ error: WritableSignal<HttpErrorResponse | null>;
12
+ lastTimeExecutedAt: WritableSignal<number | null>;
13
+ };
14
+ export declare const setupQueryState: <TArgs extends QueryArgs>(options: SetupQueryStateOptions) => QueryState<TArgs>;
@@ -0,0 +1,41 @@
1
+ import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
2
+ import { CreateEffectOptions } from '@angular/core';
3
+ import { CreateQueryOptions, QueryArgs } from './query';
4
+ import { QueryMethod } from './query-creator';
5
+ import { QueryExecute } from './query-execute';
6
+ import { QueryFeatureContext } from './query-features';
7
+ /**
8
+ * Returning this inside e.g. a withComputedArgs feature will reset the query args to null.
9
+ * This will also pause polling and auto refresh until new args are set.
10
+ */
11
+ export declare const QUERY_ARGS_RESET: unique symbol;
12
+ export type QueryArgsReset = typeof QUERY_ARGS_RESET;
13
+ export declare const QUERY_EFFECT_ERROR_MESSAGE = "Effect triggered too often. This is probably due to a circular dependency inside the query.";
14
+ /** 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) => void;
16
+ export declare const shouldAutoExecuteQuery: (method: QueryMethod) => method is "GET" | "HEAD" | "OPTIONS";
17
+ export declare const extractExpiresInSeconds: (headers: HttpHeaders) => number | null;
18
+ export type ShouldRetryRequestOptions = {
19
+ retryCount: number;
20
+ error: HttpErrorResponse;
21
+ };
22
+ export type ShouldRetryRequestResult = {
23
+ retry: false;
24
+ } | {
25
+ retry: true;
26
+ delay: number;
27
+ };
28
+ export type ShouldRetryRequestFn = (options: ShouldRetryRequestOptions) => ShouldRetryRequestResult;
29
+ export declare const shouldRetryRequest: (options: ShouldRetryRequestOptions) => ShouldRetryRequestResult;
30
+ export type QueryFeatureFlags = {
31
+ hasWithArgsFeature: boolean;
32
+ shouldAutoExecuteMethod: boolean;
33
+ shouldAutoExecute: boolean;
34
+ hasRouteFunction: boolean;
35
+ };
36
+ export declare const getQueryFeatureUsage: <TArgs extends QueryArgs>(options: CreateQueryOptions<TArgs>) => QueryFeatureFlags;
37
+ export declare const applyQueryFeatures: <TArgs extends QueryArgs>(options: CreateQueryOptions<TArgs>, context: QueryFeatureContext<TArgs>) => void;
38
+ export declare const maybeExecute: <TArgs extends QueryArgs>(options: {
39
+ flags: QueryFeatureFlags;
40
+ execute: QueryExecute<TArgs>;
41
+ }) => void;
@@ -0,0 +1,41 @@
1
+ import { HttpErrorResponse, HttpEvent, HttpHeaders } from '@angular/common/http';
2
+ import { Signal } from '@angular/core';
3
+ import { HttpRequestLoadingState } from './http-request';
4
+ import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryConfig } from './query-creator';
5
+ import { QueryExecute } from './query-execute';
6
+ import { QueryFeature } from './query-features';
7
+ export type QueryArgs = {
8
+ response?: any;
9
+ pathParams?: Record<string, string | number>;
10
+ queryParams?: any;
11
+ body?: any;
12
+ headers?: HttpHeaders;
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'>;
19
+ export type CreateQueryOptions<TArgs extends QueryArgs> = {
20
+ creator: CreateQueryCreatorOptions<TArgs>;
21
+ creatorInternals: InternalCreateQueryCreatorOptions;
22
+ features: QueryFeature<TArgs>[];
23
+ queryConfig: QueryConfig;
24
+ };
25
+ export type QueryBase<TArgs extends QueryArgs> = {
26
+ args: Signal<RequestArgs<TArgs> | null>;
27
+ response: Signal<ResponseType<TArgs> | null>;
28
+ latestHttpEvent: Signal<HttpEvent<ResponseType<TArgs>> | null>;
29
+ loading: Signal<HttpRequestLoadingState | null>;
30
+ error: Signal<HttpErrorResponse | null>;
31
+ lastTimeExecutedAt: Signal<number | null>;
32
+ };
33
+ export type QuerySnapshot<TArgs extends QueryArgs> = QueryBase<TArgs> & {
34
+ isAlive: Signal<boolean>;
35
+ };
36
+ export type AnyQuerySnapshot = QuerySnapshot<any>;
37
+ export type Query<TArgs extends QueryArgs> = QueryBase<TArgs> & {
38
+ execute: QueryExecute<TArgs>;
39
+ createSnapshot: () => QuerySnapshot<TArgs>;
40
+ };
41
+ export declare const createQuery: <TArgs extends QueryArgs>(options: CreateQueryOptions<TArgs>) => Query<TArgs>;
@@ -0,0 +1,7 @@
1
+ import { AnyBearerAuthProviderConfig } from './bearer-auth-provider-config';
2
+ import { QueryArgs } from './query';
3
+ import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryCreator } from './query-creator';
4
+ export type InternalSecureCreateQueryCreatorOptions = InternalCreateQueryCreatorOptions & {
5
+ authProvider: AnyBearerAuthProviderConfig;
6
+ };
7
+ export declare const createSecureQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions<TArgs>, internals: InternalSecureCreateQueryCreatorOptions) => QueryCreator<TArgs>;