@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,39 +0,0 @@
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>;
@@ -1,49 +0,0 @@
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
- UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM = 300,
23
- UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM = 301,
24
- PAGED_QUERY_PAGE_BIGGER_THAN_TOTAL_PAGES = 400,
25
- PAGED_QUERY_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE = 401,
26
- PAGED_QUERY_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE = 402
27
- }
28
- export declare const queryFeatureUsedMultipleTimes: (type: QueryFeatureType) => RuntimeError<RuntimeErrorCode.QUERY_FEATURE_USED_MULTIPLE_TIMES>;
29
- export declare const withArgsQueryFeatureMissingButRouteIsFunction: () => RuntimeError<RuntimeErrorCode.WITH_ARGS_QUERY_FEATURE_MISSING_BUT_ROUTE_IS_FUNCTION>;
30
- export declare const withPollingUsedOnUnsupportedHttpMethod: (method: QueryMethod) => RuntimeError<RuntimeErrorCode.WITH_POLLING_USED_ON_UNSUPPORTED_HTTP_METHOD>;
31
- export declare const withAutoRefreshUsedOnUnsupportedHttpMethod: (method: QueryMethod) => RuntimeError<RuntimeErrorCode.WITH_AUTO_REFRESH_USED_ON_UNSUPPORTED_HTTP_METHOD>;
32
- export declare const withAutoRefreshUsedInManualQuery: () => RuntimeError<RuntimeErrorCode.WITH_AUTO_REFRESH_USED_IN_MANUAL_QUERY>;
33
- export declare const cookieLoginTriedButCookieDisabled: () => RuntimeError<RuntimeErrorCode.COOKIE_LOGIN_TRIED_BUT_COOKIE_DISABLED>;
34
- export declare const enableCookieCalledWithoutCookieConfig: () => RuntimeError<RuntimeErrorCode.ENABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
35
- export declare const disableCookieCalledWithoutCookieConfig: () => RuntimeError<RuntimeErrorCode.DISABLE_COOKIE_CALLED_WITHOUT_COOKIE_CONFIG>;
36
- export declare const loginCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.LOGIN_CALLED_WITHOUT_CONFIG>;
37
- export declare const loginWithTokenCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.LOGIN_WITH_TOKEN_CALLED_WITHOUT_CONFIG>;
38
- export declare const refreshTokenCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.REFRESH_TOKEN_CALLED_WITHOUT_CONFIG>;
39
- export declare const selectRoleCalledWithoutConfig: () => RuntimeError<RuntimeErrorCode.SELECT_ROLE_CALLED_WITHOUT_CONFIG>;
40
- export declare const defaultResponseTransformerResponseNotObject: (currentType: string) => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_OBJECT>;
41
- export declare const defaultResponseTransformerResponseNotContainingAccessToken: () => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_ACCESS_TOKEN>;
42
- export declare const defaultResponseTransformerResponseNotContainingRefreshToken: () => RuntimeError<RuntimeErrorCode.DEFAULT_RESPONSE_TRANSFORMER_RESPONSE_NOT_CONTAINING_REFRESH_TOKEN>;
43
- export declare const unableToDecryptBearerToken: (token: string) => RuntimeError<RuntimeErrorCode.UNABLE_TO_DECRYPT_BEARER_TOKEN>;
44
- export declare const bearerExpiresInPropertyNotNumber: (expiresIn: unknown) => RuntimeError<RuntimeErrorCode.BEARER_EXPIRES_IN_PROPERTY_NOT_NUMBER>;
45
- export declare const uncacheableRequestHasCacheKeyParam: (key: string) => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_CACHE_KEY_PARAM>;
46
- export declare const uncacheableRequestHasAllowCacheParam: () => RuntimeError<RuntimeErrorCode.UNCACHEABLE_REQUEST_HAS_ALLOW_CACHE_PARAM>;
47
- export declare const pagedQueryPageBiggerThanTotalPages: (page: number, totalPages: number) => RuntimeError<RuntimeErrorCode.PAGED_QUERY_PAGE_BIGGER_THAN_TOTAL_PAGES>;
48
- export declare const pagedQueryNextPageCalledWithoutPreviousPage: () => RuntimeError<RuntimeErrorCode.PAGED_QUERY_NEXT_PAGE_CALLED_WITHOUT_PREVIOUS_PAGE>;
49
- export declare const pagedQueryPreviousPageCalledButAlreadyAtFirstPage: () => RuntimeError<RuntimeErrorCode.PAGED_QUERY_PREVIOUS_PAGE_CALLED_BUT_ALREADY_AT_FIRST_PAGE>;
@@ -1,48 +0,0 @@
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 { QueryDependencies } from './query-dependencies';
6
- import { QueryExecute } from './query-execute';
7
- import { QueryState } from './query-state';
8
- import { QueryArgsReset, QueryFeatureFlags } from './query-utils';
9
- export declare const enum QueryFeatureType {
10
- WithArgs = "withArgs",
11
- WithLogging = "withLogging",
12
- WithErrorHandling = "withErrorHandling",
13
- WithSuccessHandling = "withSuccessHandling",
14
- WithPolling = "withPolling",
15
- WithAutoRefresh = "withAutoRefresh"
16
- }
17
- export type QueryFeatureContext<TArgs extends QueryArgs> = {
18
- state: QueryState<TArgs>;
19
- queryConfig: QueryConfig;
20
- creatorConfig: CreateQueryCreatorOptions<TArgs>;
21
- creatorInternals: InternalCreateQueryCreatorOptions;
22
- execute: QueryExecute<TArgs>;
23
- deps: QueryDependencies;
24
- flags: QueryFeatureFlags;
25
- };
26
- export type QueryFeatureFn<TArgs extends QueryArgs> = (context: QueryFeatureContext<TArgs>) => void;
27
- export type QueryFeature<TArgs extends QueryArgs> = {
28
- type: QueryFeatureType;
29
- fn: (context: QueryFeatureContext<TArgs>) => void;
30
- };
31
- export declare const withArgs: <TArgs extends QueryArgs>(args: () => NoInfer<RequestArgs<TArgs>> | QueryArgsReset | null) => QueryFeature<TArgs>;
32
- export declare const withPolling: <TArgs extends QueryArgs>(options: {
33
- interval: number;
34
- executeInitially?: boolean;
35
- }) => QueryFeature<TArgs>;
36
- export declare const withLogging: <TArgs extends QueryArgs>(options: {
37
- logFn: (v: HttpEvent<ResponseType<TArgs>> | null) => void;
38
- }) => QueryFeature<TArgs>;
39
- export declare const withErrorHandling: <TArgs extends QueryArgs>(options: {
40
- handler: (e: HttpErrorResponse) => void;
41
- }) => QueryFeature<TArgs>;
42
- export declare const withSuccessHandling: <TArgs extends QueryArgs>(options: {
43
- handler: (data: NonNullable<ResponseType<TArgs>>) => void;
44
- }) => QueryFeature<TArgs>;
45
- export declare const withAutoRefresh: <TArgs extends QueryArgs>(options: {
46
- signalChanges: Signal<unknown>[];
47
- ignoreOnlyManualExecution?: boolean;
48
- }) => QueryFeature<TArgs>;
@@ -1,48 +0,0 @@
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: (options?: {
17
- allowCache?: boolean;
18
- }) => void;
19
- /** Destroys all queries in the stack and empties it. This should only be used if `append` is true. */
20
- clear: () => void;
21
- };
22
- export type AnyQueryStack = QueryStack<AnyQuery>;
23
- export type CreateQueryStackOptions<T extends AnyQuery, J = ReturnType<T['response']>[]> = {
24
- /**
25
- * If true, new queries will be appended to the existing ones. Otherwise, existing queries will be destroyed.
26
- * This should be used for things like infinite scrolling where already fetched queries should not be destroyed.
27
- */
28
- append?: boolean;
29
- /**
30
- * If append is true, this function will be called to merge the old and new queries.
31
- * Useful if you want to append the new queries in a specific order (e.g. at the beginning).
32
- */
33
- appendFn?: (oldQueries: T[], newQueries: T[]) => {
34
- /** The new queries merged with the old ones. */
35
- queries: T[];
36
- /** The last query in the new queries. */
37
- lastQuery: T | null;
38
- };
39
- /**
40
- * Transforms the responses of all queries in the stack. Useful for merging or filtering responses.
41
- */
42
- transform?: (responses: ReturnType<T['response']>[]) => J;
43
- };
44
- export declare const transformArrayResponse: <T extends (unknown | null)[]>(responses: T) => NonNullable<T[0]>[];
45
- export declare const transformPaginatedResponse: <T extends ({
46
- items: unknown[];
47
- } | null)[]>(responses: T) => NonNullable<NonNullable<T[0]>["items"]>;
48
- export declare const createQueryStack: <T extends AnyQuery, J = ReturnType<T["response"]>[]>(computation: () => T | T[] | null, options?: CreateQueryStackOptions<T, J>) => QueryStack<T, J>;