@ethlete/query 5.25.0 → 5.26.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.
@@ -1,11 +1,12 @@
1
+ import { GQL } from '../../gql';
1
2
  import { QueryClientConfig } from '../http';
2
3
  import { GqlQueryArgs } from './gql-query';
3
4
  import { CreateGqlQueryCreatorOptions } from './gql-query-creator';
4
5
  /** 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
+ export declare const createGqlQueryViaGet: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(query: GQL, creatorOptions?: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
6
7
  /** 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
+ export declare const createGqlQueryViaPost: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(query: GQL, creatorOptions?: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
8
9
  /** 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
+ export declare const createGqlMutationViaGet: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(query: GQL, creatorOptions?: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
10
11
  /** 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>;
12
+ export declare const createGqlMutationViaPost: (client: QueryClientConfig) => <TArgs extends GqlQueryArgs>(query: GQL, creatorOptions?: CreateGqlQueryCreatorOptions<TArgs>) => import("../http").QueryCreator<TArgs>;
@@ -1,7 +1,6 @@
1
1
  import { CreateQueryCreatorOptions, QueryClientConfig, QueryCreator, RouteType } from '../http';
2
2
  import { GqlQueryArgs } from './gql-query';
3
- export type CreateGqlQueryCreatorOptions<TArgs extends GqlQueryArgs> = Omit<CreateQueryCreatorOptions<TArgs>, 'route'> & {
4
- query: string;
3
+ export type CreateGqlQueryCreatorOptions<TArgs extends GqlQueryArgs> = Omit<CreateQueryCreatorOptions, 'route'> & {
5
4
  route?: RouteType<TArgs>;
6
5
  };
7
6
  export type GqlQueryMethod = 'QUERY' | 'MUTATE';
@@ -10,5 +9,6 @@ export type InternalCreateGqlQueryCreatorOptions = {
10
9
  method: GqlQueryMethod;
11
10
  transport: GqlQueryTransport;
12
11
  client: QueryClientConfig;
12
+ query: string;
13
13
  };
14
- export declare const createGqlQueryCreator: <TArgs extends GqlQueryArgs>(options: CreateGqlQueryCreatorOptions<TArgs>, internals: InternalCreateGqlQueryCreatorOptions) => QueryCreator<TArgs>;
14
+ export declare const createGqlQueryCreator: <TArgs extends GqlQueryArgs>(options: CreateGqlQueryCreatorOptions<TArgs> | undefined, internals: InternalCreateGqlQueryCreatorOptions) => QueryCreator<TArgs>;
@@ -4,7 +4,7 @@ import { CreateGqlQueryCreatorOptions, InternalCreateGqlQueryCreatorOptions } fr
4
4
  export type CreateGqlQueryExecuteOptions<TArgs extends QueryArgs> = {
5
5
  deps: QueryDependencies;
6
6
  state: QueryState<TArgs>;
7
- creator: CreateGqlQueryCreatorOptions<TArgs>;
7
+ creator?: CreateGqlQueryCreatorOptions<TArgs>;
8
8
  creatorInternals: InternalCreateGqlQueryCreatorOptions;
9
9
  queryConfig: QueryConfig;
10
10
  };
@@ -4,7 +4,7 @@ export type GqlQueryArgs = QueryArgs & {
4
4
  variables?: Record<string, unknown>;
5
5
  };
6
6
  export type CreateGqlQueryOptions<TArgs extends GqlQueryArgs> = Omit<CreateQueryOptions<TArgs>, 'creator' | 'creatorInternals'> & {
7
- creator: CreateGqlQueryCreatorOptions<TArgs>;
7
+ creator?: CreateGqlQueryCreatorOptions<TArgs>;
8
8
  creatorInternals: InternalCreateGqlQueryCreatorOptions;
9
9
  };
10
10
  export type GqlVariablesType<T extends GqlQueryArgs | null> = T extends GqlQueryArgs ? T['variables'] : never;
@@ -9,7 +9,7 @@ export declare const ggLikePaginationAdapter: <T>(response: GgLikePaginated<T>)
9
9
  export declare const dynLikePaginationAdapter: <T>(response: DynLikePaginated<T>) => NormalizedPagination<T>;
10
10
  export declare const contentfulGqlLikePaginationAdapter: <T>(response: ContentfulGqlLikePaginated<T>) => NormalizedPagination<T>;
11
11
  export declare const fakePaginationAdapter: (totalHits?: number) => <T>(response: T) => NormalizedPagination<T>;
12
- export type CreatePagedQueryStackOptions<TArgs extends QueryArgs> = {
12
+ export type CreatePagedQueryStackOptions<TArgs extends QueryArgs, TNormPagination extends NormalizedPagination<unknown>> = {
13
13
  /**
14
14
  * The normalizer function that will be used to normalize the response to a format that the paged query can understand.
15
15
  *
@@ -20,7 +20,7 @@ export type CreatePagedQueryStackOptions<TArgs extends QueryArgs> = {
20
20
  * - `contentfulGqlLikePaginationAdapter`
21
21
  * - `fakePaginationAdapter` (for testing purposes)
22
22
  */
23
- responseNormalizer: (response: ResponseType<TArgs>) => NormalizedPagination<ResponseType<TArgs>>;
23
+ responseNormalizer: (response: ResponseType<TArgs>) => TNormPagination;
24
24
  /**
25
25
  * The query creator function that will be used to create the paged query.
26
26
  */
@@ -62,7 +62,7 @@ export type PagedQueryStackResetOptions = {
62
62
  */
63
63
  initialPage?: number;
64
64
  };
65
- export type PagedQueryStackExecuteOptions<TArgs extends QueryArgs> = {
65
+ export type PagedQueryStackExecuteOptions<TNormPagination extends NormalizedPagination<unknown>> = {
66
66
  /**
67
67
  * If provided, only the queries that match the condition will be executed.
68
68
  * This will also execute the previous and next query to the one that matched the condition.
@@ -71,7 +71,7 @@ export type PagedQueryStackExecuteOptions<TArgs extends QueryArgs> = {
71
71
  * @example
72
72
  * myPagedQuery.execute({ where: (item) => item.id === 4 });
73
73
  */
74
- where?: (item: ResponseType<TArgs>, index: number, array: ResponseType<TArgs>[]) => boolean;
74
+ where?: (item: TNormPagination['items'][number], index: number, array: TNormPagination['items']) => boolean;
75
75
  /**
76
76
  * If true, the cache will be used (if not expired) and the request will not be made.
77
77
  * @default false
@@ -79,12 +79,12 @@ export type PagedQueryStackExecuteOptions<TArgs extends QueryArgs> = {
79
79
  allowCache?: boolean;
80
80
  };
81
81
  export type PagedQueryStackDirection = 'next' | 'previous';
82
- export type AnyPagedQueryStack = PagedQueryStack<AnyQuery>;
83
- export type PagedQueryStack<TQuery extends AnyQuery> = {
82
+ export type AnyPagedQueryStack = PagedQueryStack<AnyQuery, NormalizedPagination<unknown>>;
83
+ export type PagedQueryStack<TQuery extends AnyQuery, TNormPagination extends NormalizedPagination<unknown>> = {
84
84
  /**
85
85
  * The current pagination state of the paged query.
86
86
  */
87
- pagination: Signal<NormalizedPagination<ResponseType<QueryArgsOf<TQuery>>> | null>;
87
+ pagination: Signal<TNormPagination | null>;
88
88
  /**
89
89
  * Fetches the previous page of the paged query.
90
90
  *
@@ -112,7 +112,7 @@ export type PagedQueryStack<TQuery extends AnyQuery> = {
112
112
  /**
113
113
  * The items of the paged query.
114
114
  */
115
- items: Signal<ResponseType<QueryArgsOf<TQuery>>[]>;
115
+ items: Signal<TNormPagination['items']>;
116
116
  /**
117
117
  * Whether the paged query is loading or not.
118
118
  */
@@ -140,10 +140,10 @@ export type PagedQueryStack<TQuery extends AnyQuery> = {
140
140
  /**
141
141
  * Executes the paged query.
142
142
  */
143
- execute: (options?: PagedQueryStackExecuteOptions<QueryArgsOf<TQuery>>) => void;
143
+ execute: (options?: PagedQueryStackExecuteOptions<TNormPagination>) => void;
144
144
  /**
145
145
  * The current direction of the paged query.
146
146
  */
147
147
  direction: Signal<PagedQueryStackDirection>;
148
148
  };
149
- export declare const createPagedQueryStack: <TCreator extends AnyQueryCreator, TArgs extends QueryArgsOf<TCreator>>(options: CreatePagedQueryStackOptions<TArgs>) => PagedQueryStack<Query<TArgs>>;
149
+ export declare const createPagedQueryStack: <TCreator extends AnyQueryCreator, TArgs extends QueryArgsOf<TCreator>, TNormPagination extends NormalizedPagination<unknown>>(options: CreatePagedQueryStackOptions<TArgs, TNormPagination>) => PagedQueryStack<Query<TArgs>, TNormPagination>;
@@ -1,24 +1,24 @@
1
1
  import { AnyBearerAuthProviderConfig } from '../auth/bearer-auth-provider-config';
2
2
  import { QueryArgs } from './query';
3
3
  import { QueryClientConfig } from './query-client-config';
4
- import { CreateQueryCreatorOptions } from './query-creator';
4
+ import { CreateQueryCreatorOptions, RouteType } from './query-creator';
5
5
  /** A query creator that creates a GET query */
6
- export declare const createGetQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
6
+ export declare const createGetQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
7
7
  /** A query creator that creates a secure GET query (requires authentication) */
8
- export declare const createSecureGetQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
8
+ export declare const createSecureGetQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
9
9
  /** A query creator that creates a POST query */
10
- export declare const createPostQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
10
+ export declare const createPostQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
11
11
  /** A query creator that creates a secure POST query (requires authentication) */
12
- export declare const createSecurePostQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
12
+ export declare const createSecurePostQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
13
13
  /** A query creator that creates a PUT query */
14
- export declare const createPutQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
14
+ export declare const createPutQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
15
15
  /** A query creator that creates a secure PUT query (requires authentication) */
16
- export declare const createSecurePutQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
16
+ export declare const createSecurePutQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
17
17
  /** A query creator that creates a DELETE query */
18
- export declare const createDeleteQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
18
+ export declare const createDeleteQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
19
19
  /** A query creator that creates a secure DELETE query (requires authentication) */
20
- export declare const createSecureDeleteQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
20
+ export declare const createSecureDeleteQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
21
21
  /** A query creator that creates a PATCH query */
22
- export declare const createPatchQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
22
+ export declare const createPatchQuery: (client: QueryClientConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
23
23
  /** A query creator that creates a secure PATCH query (requires authentication) */
24
- export declare const createSecurePatchQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(creatorOptions: CreateQueryCreatorOptions<TArgs>) => import("./query-creator").QueryCreator<TArgs>;
24
+ export declare const createSecurePatchQuery: (client: QueryClientConfig, authProvider: AnyBearerAuthProviderConfig) => <TArgs extends QueryArgs>(route: RouteType<TArgs>, creatorOptions?: CreateQueryCreatorOptions) => import("./query-creator").QueryCreator<TArgs>;
@@ -6,13 +6,7 @@ export type RouteType<TArgs extends QueryArgs> = PathParamsType<TArgs> extends {
6
6
  [key: string]: unknown;
7
7
  } ? (args: TArgs['pathParams']) => RouteString : RouteString;
8
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>;
9
+ export type CreateQueryCreatorOptions = {
16
10
  /**
17
11
  * If true, the query loading state will include progress information.
18
12
  * This is useful for file uploads and downloads.
@@ -53,7 +47,13 @@ export type AnyQueryCreator = QueryCreator<any>;
53
47
  export type QueryArgsOf<T extends AnyQueryCreator | AnyQuery> = T extends QueryCreator<infer TArgs> ? TArgs : T extends Query<infer TArgs> ? TArgs : never;
54
48
  export type RunQueryCreator<TCreator extends AnyQueryCreator> = ReturnType<TCreator>;
55
49
  export type QueryMethod = 'GET' | 'OPTIONS' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'CONNECT';
56
- export type InternalCreateQueryCreatorOptions = {
50
+ export type InternalCreateQueryCreatorOptions<TArgs extends QueryArgs> = {
51
+ /**
52
+ * The route of the query.
53
+ * If the query has path params, the route should be a function that takes the path params as an argument.
54
+ * Otherwise, it should be a string.
55
+ */
56
+ route: RouteType<TArgs>;
57
57
  method: QueryMethod;
58
58
  client: QueryClientConfig;
59
59
  };
@@ -70,4 +70,4 @@ export declare const splitQueryConfig: <TArgs extends QueryArgs>(args: (QueryFea
70
70
  features: QueryFeature<TArgs>[];
71
71
  queryConfig: QueryConfig;
72
72
  };
73
- export declare const createQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions<TArgs>, internals: InternalCreateQueryCreatorOptions) => QueryCreator<TArgs>;
73
+ export declare const createQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions | undefined, internals: InternalCreateQueryCreatorOptions<TArgs>) => QueryCreator<TArgs>;
@@ -8,8 +8,8 @@ import { QueryState } from './query-state';
8
8
  export type CreateQueryExecuteOptions<TArgs extends QueryArgs> = {
9
9
  deps: QueryDependencies;
10
10
  state: QueryState<TArgs>;
11
- creator: CreateQueryCreatorOptions<TArgs>;
12
- creatorInternals: InternalCreateQueryCreatorOptions;
11
+ creator?: CreateQueryCreatorOptions;
12
+ creatorInternals: InternalCreateQueryCreatorOptions<TArgs>;
13
13
  queryConfig: QueryConfig;
14
14
  };
15
15
  export type QueryExecuteArgs<TArgs extends QueryArgs> = {
@@ -17,8 +17,8 @@ export type QueryParamsType<T extends QueryArgs | null> = T extends QueryArgs ?
17
17
  export type BodyType<T extends QueryArgs | null> = T extends QueryArgs ? T['body'] : never;
18
18
  export type RequestArgs<T extends QueryArgs | null> = T extends QueryArgs ? Omit<T, 'response'> : never;
19
19
  export type CreateQueryOptions<TArgs extends QueryArgs> = {
20
- creator: CreateQueryCreatorOptions<TArgs>;
21
- creatorInternals: InternalCreateQueryCreatorOptions;
20
+ creator?: CreateQueryCreatorOptions;
21
+ creatorInternals: InternalCreateQueryCreatorOptions<TArgs>;
22
22
  features: QueryFeature<TArgs>[];
23
23
  queryConfig: QueryConfig;
24
24
  };
@@ -1,7 +1,7 @@
1
1
  import { AnyBearerAuthProviderConfig } from '../auth/bearer-auth-provider-config';
2
2
  import { QueryArgs } from './query';
3
3
  import { CreateQueryCreatorOptions, InternalCreateQueryCreatorOptions, QueryCreator } from './query-creator';
4
- export type InternalSecureCreateQueryCreatorOptions = InternalCreateQueryCreatorOptions & {
4
+ export type InternalSecureCreateQueryCreatorOptions<TArgs extends QueryArgs> = InternalCreateQueryCreatorOptions<TArgs> & {
5
5
  authProvider: AnyBearerAuthProviderConfig;
6
6
  };
7
- export declare const createSecureQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions<TArgs>, internals: InternalSecureCreateQueryCreatorOptions) => QueryCreator<TArgs>;
7
+ export declare const createSecureQueryCreator: <TArgs extends QueryArgs>(options: CreateQueryCreatorOptions | undefined, internals: InternalSecureCreateQueryCreatorOptions<TArgs>) => QueryCreator<TArgs>;
@@ -2,6 +2,6 @@ import { QueryArgs } from './query';
2
2
  import { CreateQueryExecuteOptions, InternalQueryExecute } from './query-execute';
3
3
  import { InternalSecureCreateQueryCreatorOptions } from './secure-query-creator';
4
4
  export type CreateSecureQueryExecuteOptions<TArgs extends QueryArgs> = Omit<CreateQueryExecuteOptions<TArgs>, 'creatorInternals'> & {
5
- creatorInternals: InternalSecureCreateQueryCreatorOptions;
5
+ creatorInternals: InternalSecureCreateQueryCreatorOptions<TArgs>;
6
6
  };
7
7
  export declare const createSecureExecuteFn: <TArgs extends QueryArgs>(options: CreateSecureQueryExecuteOptions<TArgs>) => InternalQueryExecute<TArgs>;
@@ -1,6 +1,6 @@
1
1
  import { CreateQueryOptions, QueryArgs } from './query';
2
2
  import { InternalSecureCreateQueryCreatorOptions } from './secure-query-creator';
3
3
  export type CreateSecureQueryOptions<TArgs extends QueryArgs> = Omit<CreateQueryOptions<TArgs>, 'creatorInternals'> & {
4
- creatorInternals: InternalSecureCreateQueryCreatorOptions;
4
+ creatorInternals: InternalSecureCreateQueryCreatorOptions<TArgs>;
5
5
  };
6
6
  export declare const createSecureQuery: <TArgs extends QueryArgs>(options: CreateSecureQueryOptions<TArgs>) => import("./query").Query<TArgs>;
package/lib/gql/gql.d.ts CHANGED
@@ -4,4 +4,7 @@ export type TransformedGqlQuery = {
4
4
  operationName?: string;
5
5
  };
6
6
  export declare const transformGql: (str: string) => (variables: Record<string, unknown> | null | undefined) => TransformedGqlQuery;
7
- export declare const gql: (strings: TemplateStringsArray, ...values: string[]) => string;
7
+ export type GQL = string & {
8
+ gql: 'tag';
9
+ };
10
+ export declare const gql: (strings: TemplateStringsArray, ...values: string[]) => GQL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/query",
3
- "version": "5.25.0",
3
+ "version": "5.26.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@angular/common": "19.1.4",