@tanstack/angular-query-experimental 5.94.4 → 5.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/create-base-query.d.ts +170 -0
- package/create-base-query.mjs +99 -0
- package/create-base-query.mjs.map +1 -0
- package/devtools/index.d.ts +2 -0
- package/devtools/index.mjs +5 -0
- package/devtools/index.mjs.map +1 -0
- package/devtools/production/index.d.ts +1 -0
- package/devtools/stub.d.ts +2 -0
- package/devtools/stub.mjs +8 -0
- package/devtools/stub.mjs.map +1 -0
- package/devtools/types.d.ts +95 -0
- package/devtools/with-devtools.d.ts +25 -0
- package/devtools/with-devtools.mjs +104 -0
- package/devtools/with-devtools.mjs.map +1 -0
- package/devtools-panel/index.d.ts +2 -0
- package/devtools-panel/index.mjs +5 -0
- package/devtools-panel/index.mjs.map +1 -0
- package/devtools-panel/inject-devtools-panel.d.ts +14 -0
- package/devtools-panel/inject-devtools-panel.mjs +72 -0
- package/devtools-panel/inject-devtools-panel.mjs.map +1 -0
- package/devtools-panel/production/index.d.ts +1 -0
- package/devtools-panel/stub.d.ts +2 -0
- package/devtools-panel/stub.mjs +8 -0
- package/devtools-panel/stub.mjs.map +1 -0
- package/devtools-panel/types.d.ts +48 -0
- package/index.d.ts +25 -0
- package/index.mjs +32 -0
- package/index.mjs.map +1 -0
- package/infinite-query-options.d.ts +41 -0
- package/infinite-query-options.mjs +7 -0
- package/infinite-query-options.mjs.map +1 -0
- package/inject-infinite-query.d.ts +36 -0
- package/inject-infinite-query.mjs +18 -0
- package/inject-infinite-query.mjs.map +1 -0
- package/inject-is-fetching.d.ts +20 -0
- package/inject-is-fetching.mjs +31 -0
- package/inject-is-fetching.mjs.map +1 -0
- package/inject-is-mutating.d.ts +19 -0
- package/inject-is-mutating.mjs +31 -0
- package/inject-is-mutating.mjs.map +1 -0
- package/inject-is-restoring.d.ts +22 -0
- package/inject-is-restoring.mjs +21 -0
- package/inject-is-restoring.mjs.map +1 -0
- package/inject-mutation-state.d.ts +22 -0
- package/inject-mutation-state.mjs +51 -0
- package/inject-mutation-state.mjs.map +1 -0
- package/inject-mutation.d.ts +20 -0
- package/inject-mutation.mjs +94 -0
- package/inject-mutation.mjs.map +1 -0
- package/inject-queries-experimental/index.d.ts +1 -0
- package/inject-queries-experimental/index.mjs +5 -0
- package/inject-queries-experimental/index.mjs.map +1 -0
- package/inject-queries.d.ts +81 -0
- package/inject-queries.mjs +82 -0
- package/inject-queries.mjs.map +1 -0
- package/inject-query-client.d.ts +18 -0
- package/inject-query-client.mjs +9 -0
- package/inject-query-client.mjs.map +1 -0
- package/inject-query.d.ts +123 -0
- package/inject-query.mjs +14 -0
- package/inject-query.mjs.map +1 -0
- package/mutation-options.d.ts +39 -0
- package/mutation-options.mjs +7 -0
- package/mutation-options.mjs.map +1 -0
- package/package.json +3 -3
- package/pending-tasks-compat.d.ts +7 -0
- package/pending-tasks-compat.mjs +19 -0
- package/pending-tasks-compat.mjs.map +1 -0
- package/providers.d.ts +132 -0
- package/providers.mjs +32 -0
- package/providers.mjs.map +1 -0
- package/query-options.d.ts +84 -0
- package/query-options.mjs +7 -0
- package/query-options.mjs.map +1 -0
- package/signal-proxy.d.ts +11 -0
- package/signal-proxy.mjs +29 -0
- package/signal-proxy.mjs.map +1 -0
- package/types.d.ts +43 -0
package/providers.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { InjectionToken, Provider } from '@angular/core';
|
|
2
|
+
import { QueryClient } from '@tanstack/query-core';
|
|
3
|
+
/**
|
|
4
|
+
* Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the
|
|
5
|
+
* {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}
|
|
6
|
+
* for the entire application. Internally it calls `provideQueryClient`.
|
|
7
|
+
* You can use `provideQueryClient` to provide a different `QueryClient` instance for a part
|
|
8
|
+
* of the application or for unit testing purposes.
|
|
9
|
+
* @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
|
|
10
|
+
* @returns a provider object that can be used to provide the `QueryClient` instance.
|
|
11
|
+
*/
|
|
12
|
+
export declare function provideQueryClient(queryClient: QueryClient | InjectionToken<QueryClient>): Provider;
|
|
13
|
+
/**
|
|
14
|
+
* Sets up providers necessary to enable TanStack Query functionality for Angular applications.
|
|
15
|
+
*
|
|
16
|
+
* Allows to configure a `QueryClient` and optional features such as developer tools.
|
|
17
|
+
*
|
|
18
|
+
* **Example - standalone**
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import {
|
|
22
|
+
* provideTanStackQuery,
|
|
23
|
+
* QueryClient,
|
|
24
|
+
* } from '@tanstack/angular-query-experimental'
|
|
25
|
+
*
|
|
26
|
+
* bootstrapApplication(AppComponent, {
|
|
27
|
+
* providers: [provideTanStackQuery(new QueryClient())],
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* **Example - NgModule-based**
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import {
|
|
35
|
+
* provideTanStackQuery,
|
|
36
|
+
* QueryClient,
|
|
37
|
+
* } from '@tanstack/angular-query-experimental'
|
|
38
|
+
*
|
|
39
|
+
* @NgModule({
|
|
40
|
+
* declarations: [AppComponent],
|
|
41
|
+
* imports: [BrowserModule],
|
|
42
|
+
* providers: [provideTanStackQuery(new QueryClient())],
|
|
43
|
+
* bootstrap: [AppComponent],
|
|
44
|
+
* })
|
|
45
|
+
* export class AppModule {}
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* You can also enable optional developer tools by adding `withDevtools`. By
|
|
49
|
+
* default the tools will then be loaded when your app is in development mode.
|
|
50
|
+
* ```ts
|
|
51
|
+
* import {
|
|
52
|
+
* provideTanStackQuery,
|
|
53
|
+
* withDevtools
|
|
54
|
+
* QueryClient,
|
|
55
|
+
* } from '@tanstack/angular-query-experimental'
|
|
56
|
+
*
|
|
57
|
+
* bootstrapApplication(AppComponent,
|
|
58
|
+
* {
|
|
59
|
+
* providers: [
|
|
60
|
+
* provideTanStackQuery(new QueryClient(), withDevtools())
|
|
61
|
+
* ]
|
|
62
|
+
* }
|
|
63
|
+
* )
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* **Example: using an InjectionToken**
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* export const MY_QUERY_CLIENT = new InjectionToken('', {
|
|
70
|
+
* factory: () => new QueryClient(),
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* // In a lazy loaded route or lazy loaded component's providers array:
|
|
74
|
+
* providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
|
|
75
|
+
* ```
|
|
76
|
+
* Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.
|
|
77
|
+
* This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.
|
|
78
|
+
*
|
|
79
|
+
* Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.
|
|
80
|
+
* @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
|
|
81
|
+
* @param features - Optional features to configure additional Query functionality.
|
|
82
|
+
* @returns A set of providers to set up TanStack Query.
|
|
83
|
+
* @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
|
|
84
|
+
* @see withDevtools
|
|
85
|
+
*/
|
|
86
|
+
export declare function provideTanStackQuery(queryClient: QueryClient | InjectionToken<QueryClient>, ...features: Array<QueryFeatures>): Array<Provider>;
|
|
87
|
+
/**
|
|
88
|
+
* Sets up providers necessary to enable TanStack Query functionality for Angular applications.
|
|
89
|
+
*
|
|
90
|
+
* Allows to configure a `QueryClient`.
|
|
91
|
+
* @param queryClient - A `QueryClient` instance.
|
|
92
|
+
* @returns A set of providers to set up TanStack Query.
|
|
93
|
+
* @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
|
|
94
|
+
* @deprecated Use `provideTanStackQuery` instead.
|
|
95
|
+
*/
|
|
96
|
+
export declare function provideAngularQuery(queryClient: QueryClient): Array<Provider>;
|
|
97
|
+
declare const queryFeatures: readonly ["Devtools", "PersistQueryClient"];
|
|
98
|
+
type QueryFeatureKind = (typeof queryFeatures)[number];
|
|
99
|
+
/**
|
|
100
|
+
* Helper type to represent a Query feature.
|
|
101
|
+
*/
|
|
102
|
+
export interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
|
|
103
|
+
ɵkind: TFeatureKind;
|
|
104
|
+
ɵproviders: Array<Provider>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Helper function to create an object that represents a Query feature.
|
|
108
|
+
* @param kind -
|
|
109
|
+
* @param providers -
|
|
110
|
+
* @returns A Query feature.
|
|
111
|
+
*/
|
|
112
|
+
export declare function queryFeature<TFeatureKind extends QueryFeatureKind>(kind: TFeatureKind, providers: Array<Provider>): QueryFeature<TFeatureKind>;
|
|
113
|
+
/**
|
|
114
|
+
* A type alias that represents a feature which enables developer tools.
|
|
115
|
+
* The type is used to describe the return value of the `withDevtools` function.
|
|
116
|
+
* @see {@link withDevtools}
|
|
117
|
+
*/
|
|
118
|
+
export type DevtoolsFeature = QueryFeature<'Devtools'>;
|
|
119
|
+
/**
|
|
120
|
+
* A type alias that represents a feature which enables persistence.
|
|
121
|
+
* The type is used to describe the return value of the `withPersistQueryClient` function.
|
|
122
|
+
*/
|
|
123
|
+
export type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
|
|
124
|
+
/**
|
|
125
|
+
* A type alias that represents all Query features available for use with `provideTanStackQuery`.
|
|
126
|
+
* Features can be enabled by adding special functions to the `provideTanStackQuery` call.
|
|
127
|
+
* See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery`
|
|
128
|
+
* documentation on how to use those functions.
|
|
129
|
+
* @see {@link provideTanStackQuery}
|
|
130
|
+
*/
|
|
131
|
+
export type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature;
|
|
132
|
+
export {};
|
package/providers.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InjectionToken, inject, DestroyRef } from "@angular/core";
|
|
2
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
+
function provideQueryClient(queryClient) {
|
|
4
|
+
return {
|
|
5
|
+
provide: QueryClient,
|
|
6
|
+
useFactory: () => {
|
|
7
|
+
const client = queryClient instanceof InjectionToken ? inject(queryClient) : queryClient;
|
|
8
|
+
inject(DestroyRef).onDestroy(() => client.unmount());
|
|
9
|
+
client.mount();
|
|
10
|
+
return client;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function provideTanStackQuery(queryClient, ...features) {
|
|
15
|
+
return [
|
|
16
|
+
provideQueryClient(queryClient),
|
|
17
|
+
features.map((feature) => feature.ɵproviders)
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
function provideAngularQuery(queryClient) {
|
|
21
|
+
return provideTanStackQuery(queryClient);
|
|
22
|
+
}
|
|
23
|
+
function queryFeature(kind, providers) {
|
|
24
|
+
return { ɵkind: kind, ɵproviders: providers };
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
provideAngularQuery,
|
|
28
|
+
provideQueryClient,
|
|
29
|
+
provideTanStackQuery,
|
|
30
|
+
queryFeature
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=providers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.mjs","sources":["../src/providers.ts"],"sourcesContent":["import { DestroyRef, InjectionToken, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport type { Provider } from '@angular/core'\n\n/**\n * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the\n * {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}\n * for the entire application. Internally it calls `provideQueryClient`.\n * You can use `provideQueryClient` to provide a different `QueryClient` instance for a part\n * of the application or for unit testing purposes.\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @returns a provider object that can be used to provide the `QueryClient` instance.\n */\nexport function provideQueryClient(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n): Provider {\n return {\n provide: QueryClient,\n useFactory: () => {\n const client =\n queryClient instanceof InjectionToken\n ? inject(queryClient)\n : queryClient\n // Unmount the query client on injector destroy\n inject(DestroyRef).onDestroy(() => client.unmount())\n client.mount()\n return client\n },\n }\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications.\n *\n * Allows to configure a `QueryClient` and optional features such as developer tools.\n *\n * **Example - standalone**\n *\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(new QueryClient())],\n * })\n * ```\n *\n * **Example - NgModule-based**\n *\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * @NgModule({\n * declarations: [AppComponent],\n * imports: [BrowserModule],\n * providers: [provideTanStackQuery(new QueryClient())],\n * bootstrap: [AppComponent],\n * })\n * export class AppModule {}\n * ```\n *\n * You can also enable optional developer tools by adding `withDevtools`. By\n * default the tools will then be loaded when your app is in development mode.\n * ```ts\n * import {\n * provideTanStackQuery,\n * withDevtools\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent,\n * {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * )\n * ```\n *\n * **Example: using an InjectionToken**\n *\n * ```ts\n * export const MY_QUERY_CLIENT = new InjectionToken('', {\n * factory: () => new QueryClient(),\n * })\n *\n * // In a lazy loaded route or lazy loaded component's providers array:\n * providers: [provideTanStackQuery(MY_QUERY_CLIENT)]\n * ```\n * Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.\n * This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.\n *\n * Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @param features - Optional features to configure additional Query functionality.\n * @returns A set of providers to set up TanStack Query.\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see withDevtools\n */\nexport function provideTanStackQuery(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n ...features: Array<QueryFeatures>\n): Array<Provider> {\n return [\n provideQueryClient(queryClient),\n features.map((feature) => feature.ɵproviders),\n ]\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications.\n *\n * Allows to configure a `QueryClient`.\n * @param queryClient - A `QueryClient` instance.\n * @returns A set of providers to set up TanStack Query.\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @deprecated Use `provideTanStackQuery` instead.\n */\nexport function provideAngularQuery(queryClient: QueryClient): Array<Provider> {\n return provideTanStackQuery(queryClient)\n}\n\nconst queryFeatures = ['Devtools', 'PersistQueryClient'] as const\n\ntype QueryFeatureKind = (typeof queryFeatures)[number]\n\n/**\n * Helper type to represent a Query feature.\n */\nexport interface QueryFeature<TFeatureKind extends QueryFeatureKind> {\n ɵkind: TFeatureKind\n ɵproviders: Array<Provider>\n}\n\n/**\n * Helper function to create an object that represents a Query feature.\n * @param kind -\n * @param providers -\n * @returns A Query feature.\n */\nexport function queryFeature<TFeatureKind extends QueryFeatureKind>(\n kind: TFeatureKind,\n providers: Array<Provider>,\n): QueryFeature<TFeatureKind> {\n return { ɵkind: kind, ɵproviders: providers }\n}\n\n/**\n * A type alias that represents a feature which enables developer tools.\n * The type is used to describe the return value of the `withDevtools` function.\n * @see {@link withDevtools}\n */\nexport type DevtoolsFeature = QueryFeature<'Devtools'>\n\n/**\n * A type alias that represents a feature which enables persistence.\n * The type is used to describe the return value of the `withPersistQueryClient` function.\n */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\n\n/**\n * A type alias that represents all Query features available for use with `provideTanStackQuery`.\n * Features can be enabled by adding special functions to the `provideTanStackQuery` call.\n * See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery`\n * documentation on how to use those functions.\n * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature\n"],"names":[],"mappings":";;AAaO,SAAS,mBACd,aACU;AACV,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,MAAM;AAChB,YAAM,SACJ,uBAAuB,iBACnB,OAAO,WAAW,IAClB;AAEN,aAAO,UAAU,EAAE,UAAU,MAAM,OAAO,SAAS;AACnD,aAAO,MAAA;AACP,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AA2EO,SAAS,qBACd,gBACG,UACc;AACjB,SAAO;AAAA,IACL,mBAAmB,WAAW;AAAA,IAC9B,SAAS,IAAI,CAAC,YAAY,QAAQ,UAAU;AAAA,EAAA;AAEhD;AAWO,SAAS,oBAAoB,aAA2C;AAC7E,SAAO,qBAAqB,WAAW;AACzC;AAoBO,SAAS,aACd,MACA,WAC4B;AAC5B,SAAO,EAAE,OAAO,MAAM,YAAY,UAAA;AACpC;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { DataTag, DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, SkipToken } from '@tanstack/query-core';
|
|
2
|
+
import { CreateQueryOptions } from './types.js';
|
|
3
|
+
export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
4
|
+
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
|
|
5
|
+
};
|
|
6
|
+
export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
|
|
7
|
+
queryFn?: Exclude<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
|
|
8
|
+
};
|
|
9
|
+
export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
|
|
10
|
+
initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
|
|
11
|
+
queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Allows to share and re-use query options in a type-safe way.
|
|
15
|
+
*
|
|
16
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
17
|
+
*
|
|
18
|
+
* **Example**
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { queryKey } = queryOptions({
|
|
22
|
+
* queryKey: ['key'],
|
|
23
|
+
* queryFn: () => Promise.resolve(5),
|
|
24
|
+
* // ^? Promise<number>
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* const queryClient = new QueryClient()
|
|
28
|
+
* const data = queryClient.getQueryData(queryKey)
|
|
29
|
+
* // ^? number | undefined
|
|
30
|
+
* ```
|
|
31
|
+
* @param options - The query options to tag with the type from `queryFn`.
|
|
32
|
+
* @returns The tagged query options.
|
|
33
|
+
*/
|
|
34
|
+
export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
35
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Allows to share and re-use query options in a type-safe way.
|
|
39
|
+
*
|
|
40
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
41
|
+
*
|
|
42
|
+
* **Example**
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const { queryKey } = queryOptions({
|
|
46
|
+
* queryKey: ['key'],
|
|
47
|
+
* queryFn: () => Promise.resolve(5),
|
|
48
|
+
* // ^? Promise<number>
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* const queryClient = new QueryClient()
|
|
52
|
+
* const data = queryClient.getQueryData(queryKey)
|
|
53
|
+
* // ^? number | undefined
|
|
54
|
+
* ```
|
|
55
|
+
* @param options - The query options to tag with the type from `queryFn`.
|
|
56
|
+
* @returns The tagged query options.
|
|
57
|
+
*/
|
|
58
|
+
export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
59
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Allows to share and re-use query options in a type-safe way.
|
|
63
|
+
*
|
|
64
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
65
|
+
*
|
|
66
|
+
* **Example**
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* const { queryKey } = queryOptions({
|
|
70
|
+
* queryKey: ['key'],
|
|
71
|
+
* queryFn: () => Promise.resolve(5),
|
|
72
|
+
* // ^? Promise<number>
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* const queryClient = new QueryClient()
|
|
76
|
+
* const data = queryClient.getQueryData(queryKey)
|
|
77
|
+
* // ^? number | undefined
|
|
78
|
+
* ```
|
|
79
|
+
* @param options - The query options to tag with the type from `queryFn`.
|
|
80
|
+
* @returns The tagged query options.
|
|
81
|
+
*/
|
|
82
|
+
export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
83
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
84
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-options.mjs","sources":["../src/query-options.ts"],"sourcesContent":["import type {\n DataTag,\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateQueryOptions } from './types'\n\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n */\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AA2KO,SAAS,aAAa,SAAkB;AAC7C,SAAO;AACT;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
export type MapToSignals<T> = {
|
|
3
|
+
[K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
|
|
7
|
+
* Functions on the object are passed through as-is.
|
|
8
|
+
* @param inputSignal - `Signal` that must return an object.
|
|
9
|
+
* @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
|
|
10
|
+
*/
|
|
11
|
+
export declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
|
package/signal-proxy.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { untracked, computed } from "@angular/core";
|
|
2
|
+
function signalProxy(inputSignal) {
|
|
3
|
+
const internalState = {};
|
|
4
|
+
return new Proxy(internalState, {
|
|
5
|
+
get(target, prop) {
|
|
6
|
+
const computedField = target[prop];
|
|
7
|
+
if (computedField) return computedField;
|
|
8
|
+
const targetField = untracked(inputSignal)[prop];
|
|
9
|
+
if (typeof targetField === "function") return targetField;
|
|
10
|
+
return target[prop] = computed(() => inputSignal()[prop]);
|
|
11
|
+
},
|
|
12
|
+
has(_, prop) {
|
|
13
|
+
return !!untracked(inputSignal)[prop];
|
|
14
|
+
},
|
|
15
|
+
ownKeys() {
|
|
16
|
+
return Reflect.ownKeys(untracked(inputSignal));
|
|
17
|
+
},
|
|
18
|
+
getOwnPropertyDescriptor() {
|
|
19
|
+
return {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
signalProxy
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=signal-proxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-proxy.mjs","sources":["../src/signal-proxy.ts"],"sourcesContent":["import { computed, untracked } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\nexport type MapToSignals<T> = {\n [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>\n}\n\n/**\n * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.\n * Functions on the object are passed through as-is.\n * @param inputSignal - `Signal` that must return an object.\n * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.\n */\nexport function signalProxy<TInput extends Record<string | symbol, any>>(\n inputSignal: Signal<TInput>,\n) {\n const internalState = {} as MapToSignals<TInput>\n\n return new Proxy<MapToSignals<TInput>>(internalState, {\n get(target, prop) {\n // first check if we have it in our internal state and return it\n const computedField = target[prop]\n if (computedField) return computedField\n\n // then, check if it's a function on the resultState and return it\n const targetField = untracked(inputSignal)[prop]\n if (typeof targetField === 'function') return targetField\n\n // finally, create a computed field, store it and return it\n // @ts-expect-error\n return (target[prop] = computed(() => inputSignal()[prop]))\n },\n has(_, prop) {\n return !!untracked(inputSignal)[prop]\n },\n ownKeys() {\n return Reflect.ownKeys(untracked(inputSignal))\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true,\n }\n },\n })\n}\n"],"names":[],"mappings":";AAaO,SAAS,YACd,aACA;AACA,QAAM,gBAAgB,CAAA;AAEtB,SAAO,IAAI,MAA4B,eAAe;AAAA,IACpD,IAAI,QAAQ,MAAM;AAEhB,YAAM,gBAAgB,OAAO,IAAI;AACjC,UAAI,cAAe,QAAO;AAG1B,YAAM,cAAc,UAAU,WAAW,EAAE,IAAI;AAC/C,UAAI,OAAO,gBAAgB,WAAY,QAAO;AAI9C,aAAQ,OAAO,IAAI,IAAI,SAAS,MAAM,YAAA,EAAc,IAAI,CAAC;AAAA,IAC3D;AAAA,IACA,IAAI,GAAG,MAAM;AACX,aAAO,CAAC,CAAC,UAAU,WAAW,EAAE,IAAI;AAAA,IACtC;AAAA,IACA,UAAU;AACR,aAAO,QAAQ,QAAQ,UAAU,WAAW,CAAC;AAAA,IAC/C;AAAA,IACA,2BAA2B;AACzB,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,cAAc;AAAA,MAAA;AAAA,IAElB;AAAA,EAAA,CACD;AACH;"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, Override, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
|
|
2
|
+
import { Signal } from '@angular/core';
|
|
3
|
+
import { MapToSignals } from './signal-proxy.js';
|
|
4
|
+
export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
|
|
5
|
+
}
|
|
6
|
+
export interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'suspense'> {
|
|
7
|
+
}
|
|
8
|
+
type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
|
|
9
|
+
status: TStatus;
|
|
10
|
+
}>;
|
|
11
|
+
export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
|
|
12
|
+
isSuccess: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>;
|
|
13
|
+
isError: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>;
|
|
14
|
+
isPending: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'suspense'> {
|
|
17
|
+
}
|
|
18
|
+
export type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>;
|
|
19
|
+
export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
|
|
20
|
+
export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TState = DefinedQueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>;
|
|
21
|
+
export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = BaseQueryNarrowing<TData, TError> & MapToSignals<InfiniteQueryObserverResult<TData, TError>>;
|
|
22
|
+
export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<TData, TError>> = MapToSignals<TDefinedInfiniteQueryObserver>;
|
|
23
|
+
export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>, '_defaulted'> {
|
|
24
|
+
}
|
|
25
|
+
export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TOnMutateResult>>) => void;
|
|
26
|
+
export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MutateFunction<TData, TError, TVariables, TOnMutateResult>;
|
|
27
|
+
export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, {
|
|
28
|
+
mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>;
|
|
29
|
+
}> & {
|
|
30
|
+
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult>;
|
|
31
|
+
};
|
|
32
|
+
type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TOnMutateResult>, {
|
|
33
|
+
status: TStatus;
|
|
34
|
+
}>;
|
|
35
|
+
type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>;
|
|
36
|
+
export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
|
|
37
|
+
isSuccess: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TOnMutateResult>>>;
|
|
38
|
+
isError: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TOnMutateResult>>>;
|
|
39
|
+
isPending: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TOnMutateResult>>>;
|
|
40
|
+
isIdle: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TOnMutateResult>>>;
|
|
41
|
+
}
|
|
42
|
+
export type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown, TState = CreateStatusBasedMutationResult<CreateBaseMutationResult['status'], TData, TError, TVariables, TOnMutateResult>> = BaseMutationNarrowing<TData, TError, TVariables, TOnMutateResult> & MapToSignals<OmitKeyof<TState, keyof BaseMutationNarrowing, 'safely'>>;
|
|
43
|
+
export {};
|