@tanstack/angular-query-experimental 5.83.1 → 5.84.1

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 (70) hide show
  1. package/package.json +6 -42
  2. package/{dist/providers.d.ts → providers.d.ts} +4 -0
  3. package/providers.mjs.map +1 -0
  4. package/dist/providers.mjs.map +0 -1
  5. package/src/create-base-query.ts +0 -142
  6. package/src/index.ts +0 -64
  7. package/src/infinite-query-options.ts +0 -187
  8. package/src/inject-infinite-query.ts +0 -129
  9. package/src/inject-is-fetching.ts +0 -66
  10. package/src/inject-is-mutating.ts +0 -65
  11. package/src/inject-is-restoring.ts +0 -52
  12. package/src/inject-mutation-state.ts +0 -125
  13. package/src/inject-mutation.ts +0 -169
  14. package/src/inject-queries.ts +0 -271
  15. package/src/inject-query-client.ts +0 -23
  16. package/src/inject-query.ts +0 -230
  17. package/src/mutation-options.ts +0 -60
  18. package/src/providers.ts +0 -368
  19. package/src/query-options.ts +0 -178
  20. package/src/signal-proxy.ts +0 -46
  21. package/src/types.ts +0 -309
  22. package/src/util/is-dev-mode/is-dev-mode.ts +0 -3
  23. /package/{dist/create-base-query.d.ts → create-base-query.d.ts} +0 -0
  24. /package/{dist/create-base-query.mjs → create-base-query.mjs} +0 -0
  25. /package/{dist/create-base-query.mjs.map → create-base-query.mjs.map} +0 -0
  26. /package/{dist/index.d.ts → index.d.ts} +0 -0
  27. /package/{dist/index.mjs → index.mjs} +0 -0
  28. /package/{dist/index.mjs.map → index.mjs.map} +0 -0
  29. /package/{dist/infinite-query-options.d.ts → infinite-query-options.d.ts} +0 -0
  30. /package/{dist/infinite-query-options.mjs → infinite-query-options.mjs} +0 -0
  31. /package/{dist/infinite-query-options.mjs.map → infinite-query-options.mjs.map} +0 -0
  32. /package/{dist/inject-infinite-query.d.ts → inject-infinite-query.d.ts} +0 -0
  33. /package/{dist/inject-infinite-query.mjs → inject-infinite-query.mjs} +0 -0
  34. /package/{dist/inject-infinite-query.mjs.map → inject-infinite-query.mjs.map} +0 -0
  35. /package/{dist/inject-is-fetching.d.ts → inject-is-fetching.d.ts} +0 -0
  36. /package/{dist/inject-is-fetching.mjs → inject-is-fetching.mjs} +0 -0
  37. /package/{dist/inject-is-fetching.mjs.map → inject-is-fetching.mjs.map} +0 -0
  38. /package/{dist/inject-is-mutating.d.ts → inject-is-mutating.d.ts} +0 -0
  39. /package/{dist/inject-is-mutating.mjs → inject-is-mutating.mjs} +0 -0
  40. /package/{dist/inject-is-mutating.mjs.map → inject-is-mutating.mjs.map} +0 -0
  41. /package/{dist/inject-is-restoring.d.ts → inject-is-restoring.d.ts} +0 -0
  42. /package/{dist/inject-is-restoring.mjs → inject-is-restoring.mjs} +0 -0
  43. /package/{dist/inject-is-restoring.mjs.map → inject-is-restoring.mjs.map} +0 -0
  44. /package/{dist/inject-mutation-state.d.ts → inject-mutation-state.d.ts} +0 -0
  45. /package/{dist/inject-mutation-state.mjs → inject-mutation-state.mjs} +0 -0
  46. /package/{dist/inject-mutation-state.mjs.map → inject-mutation-state.mjs.map} +0 -0
  47. /package/{dist/inject-mutation.d.ts → inject-mutation.d.ts} +0 -0
  48. /package/{dist/inject-mutation.mjs → inject-mutation.mjs} +0 -0
  49. /package/{dist/inject-mutation.mjs.map → inject-mutation.mjs.map} +0 -0
  50. /package/{dist/inject-queries.d.ts → inject-queries.d.ts} +0 -0
  51. /package/{dist/inject-queries.mjs → inject-queries.mjs} +0 -0
  52. /package/{dist/inject-queries.mjs.map → inject-queries.mjs.map} +0 -0
  53. /package/{dist/inject-query-client.d.ts → inject-query-client.d.ts} +0 -0
  54. /package/{dist/inject-query-client.mjs → inject-query-client.mjs} +0 -0
  55. /package/{dist/inject-query-client.mjs.map → inject-query-client.mjs.map} +0 -0
  56. /package/{dist/inject-query.d.ts → inject-query.d.ts} +0 -0
  57. /package/{dist/inject-query.mjs → inject-query.mjs} +0 -0
  58. /package/{dist/inject-query.mjs.map → inject-query.mjs.map} +0 -0
  59. /package/{dist/mutation-options.d.ts → mutation-options.d.ts} +0 -0
  60. /package/{dist/mutation-options.mjs → mutation-options.mjs} +0 -0
  61. /package/{dist/mutation-options.mjs.map → mutation-options.mjs.map} +0 -0
  62. /package/{dist/providers.mjs → providers.mjs} +0 -0
  63. /package/{dist/query-options.d.ts → query-options.d.ts} +0 -0
  64. /package/{dist/query-options.mjs → query-options.mjs} +0 -0
  65. /package/{dist/query-options.mjs.map → query-options.mjs.map} +0 -0
  66. /package/{dist/signal-proxy.d.ts → signal-proxy.d.ts} +0 -0
  67. /package/{dist/signal-proxy.mjs → signal-proxy.mjs} +0 -0
  68. /package/{dist/signal-proxy.mjs.map → signal-proxy.mjs.map} +0 -0
  69. /package/{dist/types.d.ts → types.d.ts} +0 -0
  70. /package/{dist/util → util}/is-dev-mode/is-dev-mode.d.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-experimental",
3
- "version": "5.83.1",
3
+ "version": "5.84.1",
4
4
  "description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
5
5
  "author": "Arnoud de Vries",
6
6
  "license": "MIT",
@@ -27,59 +27,23 @@
27
27
  "tanstack"
28
28
  ],
29
29
  "type": "module",
30
- "types": "dist/index.d.ts",
31
- "module": "dist/index.mjs",
30
+ "types": "./index.d.ts",
31
+ "module": "./index.mjs",
32
32
  "exports": {
33
33
  ".": {
34
34
  "@tanstack/custom-condition": "./src/index.ts",
35
- "types": "./dist/index.d.ts",
36
- "default": "./dist/index.mjs"
35
+ "types": "./index.d.ts",
36
+ "default": "./index.mjs"
37
37
  },
38
38
  "./package.json": "./package.json"
39
39
  },
40
40
  "sideEffects": false,
41
- "files": [
42
- "dist",
43
- "src",
44
- "!src/__tests__"
45
- ],
46
41
  "dependencies": {
47
- "@tanstack/query-devtools": "5.83.1",
42
+ "@tanstack/query-devtools": "5.84.0",
48
43
  "@tanstack/query-core": "5.83.1"
49
44
  },
50
- "devDependencies": {
51
- "@angular/common": "^20.0.0",
52
- "@angular/compiler": "^20.0.0",
53
- "@angular/core": "^20.0.0",
54
- "@angular/platform-browser": "^20.0.0",
55
- "eslint-plugin-jsdoc": "^50.5.0",
56
- "npm-run-all2": "^5.0.0",
57
- "vite-plugin-dts": "4.2.3",
58
- "vite-plugin-externalize-deps": "^0.9.0",
59
- "vite-tsconfig-paths": "^5.1.4",
60
- "@tanstack/query-test-utils": "0.0.0"
61
- },
62
45
  "peerDependencies": {
63
46
  "@angular/common": ">=16.0.0",
64
47
  "@angular/core": ">=16.0.0"
65
- },
66
- "scripts": {
67
- "clean": "premove ./build ./dist ./coverage ./dist-ts",
68
- "compile": "tsc --build",
69
- "test:eslint": "eslint ./src",
70
- "test:types": "npm-run-all --serial test:types:*",
71
- "test:types:ts50": "node ../../node_modules/typescript50/lib/tsc.js --build",
72
- "test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build",
73
- "test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build",
74
- "test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build",
75
- "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build",
76
- "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build",
77
- "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build",
78
- "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build",
79
- "test:types:tscurrent": "tsc --build",
80
- "test:lib": "vitest",
81
- "test:lib:dev": "pnpm run test:lib --watch",
82
- "test:build": "publint --strict && attw --pack",
83
- "build": "vite build"
84
48
  }
85
49
  }
@@ -156,6 +156,10 @@ export interface DevtoolsOptions {
156
156
  * Use this so you can attach the devtool's styles to a specific element in the DOM.
157
157
  */
158
158
  shadowDOMTarget?: ShadowRoot;
159
+ /**
160
+ * Set this to true to hide disabled queries from the devtools panel.
161
+ */
162
+ hideDisabledQueries?: boolean;
159
163
  /**
160
164
  * Whether the developer tools should load.
161
165
  * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.mjs","sources":["../src/providers.ts"],"sourcesContent":["import {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n InjectionToken,\n PLATFORM_ID,\n computed,\n effect,\n inject,\n} from '@angular/core'\nimport { QueryClient, noop, onlineManager } from '@tanstack/query-core'\nimport { isPlatformBrowser } from '@angular/common'\nimport { isDevMode } from './util/is-dev-mode/is-dev-mode'\nimport type { Provider } from '@angular/core'\nimport type {\n DevtoolsButtonPosition,\n DevtoolsErrorType,\n DevtoolsPosition,\n TanstackQueryDevtools,\n} from '@tanstack/query-devtools'\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 * @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 * @public\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\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 * @public\n * @see {@link withDevtools}\n */\nexport type DeveloperToolsFeature = QueryFeature<'DeveloperTools'>\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 * @public\n */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\n\n/**\n * Options for configuring the TanStack Query devtools.\n * @public\n */\nexport interface DevtoolsOptions {\n /**\n * Set this true if you want the devtools to default to being open\n */\n initialIsOpen?: boolean\n /**\n * The position of the TanStack logo to open and close the devtools panel.\n * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`\n * Defaults to `bottom-right`.\n */\n buttonPosition?: DevtoolsButtonPosition\n /**\n * The position of the TanStack Query devtools panel.\n * `top` | `bottom` | `left` | `right`\n * Defaults to `bottom`.\n */\n position?: DevtoolsPosition\n /**\n * Custom instance of QueryClient\n */\n client?: QueryClient\n /**\n * Use this so you can define custom errors that can be shown in the devtools.\n */\n errorTypes?: Array<DevtoolsErrorType>\n /**\n * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.\n */\n styleNonce?: string\n /**\n * Use this so you can attach the devtool's styles to a specific element in the DOM.\n */\n shadowDOMTarget?: ShadowRoot\n /**\n * Set this to true to hide disabled queries from the devtools panel.\n */\n hideDisabledQueries?: boolean\n\n /**\n * Whether the developer tools should load.\n * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.\n * - `true`- Always load the devtools, regardless of the environment.\n * - `false`- Never load the devtools, regardless of the environment.\n *\n * You can use `true` and `false` to override loading developer tools from an environment file.\n * For example, a test environment might run in production mode but you may want to load developer tools.\n *\n * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example,\n * a signal created from a RxJS observable that listens for a keyboard shortcut.\n *\n * **Example**\n * ```ts\n * withDevtools(() => ({\n * initialIsOpen: true,\n * loadDevtools: inject(ExampleService).loadDevtools()\n * }))\n * ```\n */\n loadDevtools?: 'auto' | boolean\n}\n\n/**\n * Enables developer tools.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * ```\n * By default the devtools will be loaded when Angular runs in development mode and rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.\n *\n * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.\n * @param withDevtoolsFn - A function that returns `DevtoolsOptions`.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @public\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport function withDevtools(\n withDevtoolsFn?: () => DevtoolsOptions,\n): DeveloperToolsFeature {\n let providers: Array<Provider> = []\n if (!isDevMode() && !withDevtoolsFn) {\n providers = []\n } else {\n providers = [\n {\n // Do not use provideEnvironmentInitializer while Angular < v19 is supported\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: () => {\n if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop\n const injectedClient = inject(QueryClient, {\n optional: true,\n })\n const destroyRef = inject(DestroyRef)\n\n const options = computed(() => withDevtoolsFn?.() ?? {})\n\n let devtools: TanstackQueryDevtools | null = null\n let el: HTMLElement | null = null\n\n const shouldLoadToolsSignal = computed(() => {\n const { loadDevtools } = options()\n return typeof loadDevtools === 'boolean'\n ? loadDevtools\n : isDevMode()\n })\n\n const getResolvedQueryClient = () => {\n const client = options().client ?? injectedClient\n if (!client) {\n throw new Error('No QueryClient found')\n }\n return client\n }\n\n const destroyDevtools = () => {\n devtools?.unmount()\n el?.remove()\n devtools = null\n }\n\n return () =>\n effect(() => {\n const shouldLoadTools = shouldLoadToolsSignal()\n const {\n client,\n position,\n errorTypes,\n buttonPosition,\n initialIsOpen,\n } = options()\n\n if (devtools && !shouldLoadTools) {\n destroyDevtools()\n return\n } else if (devtools && shouldLoadTools) {\n client && devtools.setClient(client)\n position && devtools.setPosition(position)\n errorTypes && devtools.setErrorTypes(errorTypes)\n buttonPosition && devtools.setButtonPosition(buttonPosition)\n initialIsOpen && devtools.setInitialIsOpen(initialIsOpen)\n return\n } else if (!shouldLoadTools) {\n return\n }\n\n el = document.body.appendChild(document.createElement('div'))\n el.classList.add('tsqd-parent-container')\n\n import('@tanstack/query-devtools').then((queryDevtools) => {\n devtools = new queryDevtools.TanstackQueryDevtools({\n ...options(),\n client: getResolvedQueryClient(),\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n })\n\n el && devtools.mount(el)\n\n // Unmount the devtools on application destroy\n destroyRef.onDestroy(destroyDevtools)\n })\n })\n },\n },\n ]\n }\n return queryFeature('DeveloperTools', providers)\n}\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 * @public\n * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature\n\nexport const queryFeatures = ['DeveloperTools', 'PersistQueryClient'] as const\n\nexport type QueryFeatureKind = (typeof queryFeatures)[number]\n"],"names":[],"mappings":";;;AA6BO,SAAS,mBACd,aACU;AACH,SAAA;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,MAAM;AACN,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;AAuEgB,SAAA,qBACd,gBACG,UACc;AACV,SAAA;AAAA,IACL,mBAAmB,WAAW;AAAA,IAC9B,SAAS,IAAI,CAAC,YAAY,QAAQ,UAAU;AAAA,EAC9C;AACF;AA8BgB,SAAA,aACd,MACA,WAC4B;AAC5B,SAAO,EAAE,OAAO,MAAM,YAAY,UAAU;AAC9C;AAyGO,SAAS,aACd,gBACuB;AACvB,MAAI,YAA6B,CAAC;AAClC,MAAI,CAAC,eAAe,CAAC,gBAAgB;AACnC,gBAAY,CAAC;AAAA,EAAA,OACR;AACO,gBAAA;AAAA,MACV;AAAA;AAAA,QAEE,SAAS;AAAA,QACT,OAAO;AAAA,QACP,YAAY,MAAM;AAChB,cAAI,CAAC,kBAAkB,OAAO,WAAW,CAAC,EAAU,QAAA;AAC9C,gBAAA,iBAAiB,OAAO,aAAa;AAAA,YACzC,UAAU;AAAA,UAAA,CACX;AACK,gBAAA,aAAa,OAAO,UAAU;AAEpC,gBAAM,UAAU,SAAS,OAAM,uDAAsB,CAAA,CAAE;AAEvD,cAAI,WAAyC;AAC7C,cAAI,KAAyB;AAEvB,gBAAA,wBAAwB,SAAS,MAAM;AACrC,kBAAA,EAAE,aAAa,IAAI,QAAQ;AACjC,mBAAO,OAAO,iBAAiB,YAC3B,eACA,UAAU;AAAA,UAAA,CACf;AAED,gBAAM,yBAAyB,MAAM;AAC7B,kBAAA,SAAS,UAAU,UAAU;AACnC,gBAAI,CAAC,QAAQ;AACL,oBAAA,IAAI,MAAM,sBAAsB;AAAA,YAAA;AAEjC,mBAAA;AAAA,UACT;AAEA,gBAAM,kBAAkB,MAAM;AAC5B,iDAAU;AACV,qCAAI;AACO,uBAAA;AAAA,UACb;AAEO,iBAAA,MACL,OAAO,MAAM;AACX,kBAAM,kBAAkB,sBAAsB;AACxC,kBAAA;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,gBACE,QAAQ;AAER,gBAAA,YAAY,CAAC,iBAAiB;AAChB,8BAAA;AAChB;AAAA,YAAA,WACS,YAAY,iBAAiB;AAC5B,wBAAA,SAAS,UAAU,MAAM;AACvB,0BAAA,SAAS,YAAY,QAAQ;AAC3B,4BAAA,SAAS,cAAc,UAAU;AAC7B,gCAAA,SAAS,kBAAkB,cAAc;AAC1C,+BAAA,SAAS,iBAAiB,aAAa;AACxD;AAAA,YAAA,WACS,CAAC,iBAAiB;AAC3B;AAAA,YAAA;AAGF,iBAAK,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AACzD,eAAA,UAAU,IAAI,uBAAuB;AAExC,mBAAO,0BAA0B,EAAE,KAAK,CAAC,kBAAkB;AAC9C,yBAAA,IAAI,cAAc,sBAAsB;AAAA,gBACjD,GAAG,QAAQ;AAAA,gBACX,QAAQ,uBAAuB;AAAA,gBAC/B,aAAa;AAAA,gBACb,SAAS;AAAA,gBACT;AAAA,cAAA,CACD;AAEK,oBAAA,SAAS,MAAM,EAAE;AAGvB,yBAAW,UAAU,eAAe;AAAA,YAAA,CACrC;AAAA,UAAA,CACF;AAAA,QAAA;AAAA,MACL;AAAA,IAEJ;AAAA,EAAA;AAEK,SAAA,aAAa,kBAAkB,SAAS;AACjD;AAYa,MAAA,gBAAgB,CAAC,kBAAkB,oBAAoB;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"providers.mjs","sources":["../src/providers.ts"],"sourcesContent":["import {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n InjectionToken,\n PLATFORM_ID,\n computed,\n effect,\n inject,\n} from '@angular/core'\nimport { QueryClient, noop, onlineManager } from '@tanstack/query-core'\nimport { isPlatformBrowser } from '@angular/common'\nimport { isDevMode } from './util/is-dev-mode/is-dev-mode'\nimport type { Provider } from '@angular/core'\nimport type {\n DevtoolsButtonPosition,\n DevtoolsErrorType,\n DevtoolsPosition,\n TanstackQueryDevtools,\n} from '@tanstack/query-devtools'\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 * @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 * @public\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\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 * @public\n * @see {@link withDevtools}\n */\nexport type DeveloperToolsFeature = QueryFeature<'DeveloperTools'>\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 * @public\n */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\n\n/**\n * Options for configuring the TanStack Query devtools.\n * @public\n */\nexport interface DevtoolsOptions {\n /**\n * Set this true if you want the devtools to default to being open\n */\n initialIsOpen?: boolean\n /**\n * The position of the TanStack logo to open and close the devtools panel.\n * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`\n * Defaults to `bottom-right`.\n */\n buttonPosition?: DevtoolsButtonPosition\n /**\n * The position of the TanStack Query devtools panel.\n * `top` | `bottom` | `left` | `right`\n * Defaults to `bottom`.\n */\n position?: DevtoolsPosition\n /**\n * Custom instance of QueryClient\n */\n client?: QueryClient\n /**\n * Use this so you can define custom errors that can be shown in the devtools.\n */\n errorTypes?: Array<DevtoolsErrorType>\n /**\n * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.\n */\n styleNonce?: string\n /**\n * Use this so you can attach the devtool's styles to a specific element in the DOM.\n */\n shadowDOMTarget?: ShadowRoot\n\n /**\n * Whether the developer tools should load.\n * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.\n * - `true`- Always load the devtools, regardless of the environment.\n * - `false`- Never load the devtools, regardless of the environment.\n *\n * You can use `true` and `false` to override loading developer tools from an environment file.\n * For example, a test environment might run in production mode but you may want to load developer tools.\n *\n * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example,\n * a signal created from a RxJS observable that listens for a keyboard shortcut.\n *\n * **Example**\n * ```ts\n * withDevtools(() => ({\n * initialIsOpen: true,\n * loadDevtools: inject(ExampleService).loadDevtools()\n * }))\n * ```\n */\n loadDevtools?: 'auto' | boolean\n}\n\n/**\n * Enables developer tools.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * ```\n * By default the devtools will be loaded when Angular runs in development mode and rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.\n *\n * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.\n * @param withDevtoolsFn - A function that returns `DevtoolsOptions`.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @public\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport function withDevtools(\n withDevtoolsFn?: () => DevtoolsOptions,\n): DeveloperToolsFeature {\n let providers: Array<Provider> = []\n if (!isDevMode() && !withDevtoolsFn) {\n providers = []\n } else {\n providers = [\n {\n // Do not use provideEnvironmentInitializer while Angular < v19 is supported\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: () => {\n if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop\n const injectedClient = inject(QueryClient, {\n optional: true,\n })\n const destroyRef = inject(DestroyRef)\n\n const options = computed(() => withDevtoolsFn?.() ?? {})\n\n let devtools: TanstackQueryDevtools | null = null\n let el: HTMLElement | null = null\n\n const shouldLoadToolsSignal = computed(() => {\n const { loadDevtools } = options()\n return typeof loadDevtools === 'boolean'\n ? loadDevtools\n : isDevMode()\n })\n\n const getResolvedQueryClient = () => {\n const client = options().client ?? injectedClient\n if (!client) {\n throw new Error('No QueryClient found')\n }\n return client\n }\n\n const destroyDevtools = () => {\n devtools?.unmount()\n el?.remove()\n devtools = null\n }\n\n return () =>\n effect(() => {\n const shouldLoadTools = shouldLoadToolsSignal()\n const {\n client,\n position,\n errorTypes,\n buttonPosition,\n initialIsOpen,\n } = options()\n\n if (devtools && !shouldLoadTools) {\n destroyDevtools()\n return\n } else if (devtools && shouldLoadTools) {\n client && devtools.setClient(client)\n position && devtools.setPosition(position)\n errorTypes && devtools.setErrorTypes(errorTypes)\n buttonPosition && devtools.setButtonPosition(buttonPosition)\n initialIsOpen && devtools.setInitialIsOpen(initialIsOpen)\n return\n } else if (!shouldLoadTools) {\n return\n }\n\n el = document.body.appendChild(document.createElement('div'))\n el.classList.add('tsqd-parent-container')\n\n import('@tanstack/query-devtools').then((queryDevtools) => {\n devtools = new queryDevtools.TanstackQueryDevtools({\n ...options(),\n client: getResolvedQueryClient(),\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n })\n\n el && devtools.mount(el)\n\n // Unmount the devtools on application destroy\n destroyRef.onDestroy(destroyDevtools)\n })\n })\n },\n },\n ]\n }\n return queryFeature('DeveloperTools', providers)\n}\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 * @public\n * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature\n\nexport const queryFeatures = ['DeveloperTools', 'PersistQueryClient'] as const\n\nexport type QueryFeatureKind = (typeof queryFeatures)[number]\n"],"names":[],"mappings":";;;AA6BO,SAAS,mBACd,aACU;AACH,SAAA;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,MAAM;AACN,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;AAuEgB,SAAA,qBACd,gBACG,UACc;AACV,SAAA;AAAA,IACL,mBAAmB,WAAW;AAAA,IAC9B,SAAS,IAAI,CAAC,YAAY,QAAQ,UAAU;AAAA,EAC9C;AACF;AA8BgB,SAAA,aACd,MACA,WAC4B;AAC5B,SAAO,EAAE,OAAO,MAAM,YAAY,UAAU;AAC9C;AAqGO,SAAS,aACd,gBACuB;AACvB,MAAI,YAA6B,CAAC;AAClC,MAAI,CAAC,eAAe,CAAC,gBAAgB;AACnC,gBAAY,CAAC;AAAA,EAAA,OACR;AACO,gBAAA;AAAA,MACV;AAAA;AAAA,QAEE,SAAS;AAAA,QACT,OAAO;AAAA,QACP,YAAY,MAAM;AAChB,cAAI,CAAC,kBAAkB,OAAO,WAAW,CAAC,EAAU,QAAA;AAC9C,gBAAA,iBAAiB,OAAO,aAAa;AAAA,YACzC,UAAU;AAAA,UAAA,CACX;AACK,gBAAA,aAAa,OAAO,UAAU;AAEpC,gBAAM,UAAU,SAAS,OAAM,uDAAsB,CAAA,CAAE;AAEvD,cAAI,WAAyC;AAC7C,cAAI,KAAyB;AAEvB,gBAAA,wBAAwB,SAAS,MAAM;AACrC,kBAAA,EAAE,aAAa,IAAI,QAAQ;AACjC,mBAAO,OAAO,iBAAiB,YAC3B,eACA,UAAU;AAAA,UAAA,CACf;AAED,gBAAM,yBAAyB,MAAM;AAC7B,kBAAA,SAAS,UAAU,UAAU;AACnC,gBAAI,CAAC,QAAQ;AACL,oBAAA,IAAI,MAAM,sBAAsB;AAAA,YAAA;AAEjC,mBAAA;AAAA,UACT;AAEA,gBAAM,kBAAkB,MAAM;AAC5B,iDAAU;AACV,qCAAI;AACO,uBAAA;AAAA,UACb;AAEO,iBAAA,MACL,OAAO,MAAM;AACX,kBAAM,kBAAkB,sBAAsB;AACxC,kBAAA;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,gBACE,QAAQ;AAER,gBAAA,YAAY,CAAC,iBAAiB;AAChB,8BAAA;AAChB;AAAA,YAAA,WACS,YAAY,iBAAiB;AAC5B,wBAAA,SAAS,UAAU,MAAM;AACvB,0BAAA,SAAS,YAAY,QAAQ;AAC3B,4BAAA,SAAS,cAAc,UAAU;AAC7B,gCAAA,SAAS,kBAAkB,cAAc;AAC1C,+BAAA,SAAS,iBAAiB,aAAa;AACxD;AAAA,YAAA,WACS,CAAC,iBAAiB;AAC3B;AAAA,YAAA;AAGF,iBAAK,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AACzD,eAAA,UAAU,IAAI,uBAAuB;AAExC,mBAAO,0BAA0B,EAAE,KAAK,CAAC,kBAAkB;AAC9C,yBAAA,IAAI,cAAc,sBAAsB;AAAA,gBACjD,GAAG,QAAQ;AAAA,gBACX,QAAQ,uBAAuB;AAAA,gBAC/B,aAAa;AAAA,gBACb,SAAS;AAAA,gBACT;AAAA,cAAA,CACD;AAEK,oBAAA,SAAS,MAAM,EAAE;AAGvB,yBAAW,UAAU,eAAe;AAAA,YAAA,CACrC;AAAA,UAAA,CACF;AAAA,QAAA;AAAA,MACL;AAAA,IAEJ;AAAA,EAAA;AAEK,SAAA,aAAa,kBAAkB,SAAS;AACjD;AAYa,MAAA,gBAAgB,CAAC,kBAAkB,oBAAoB;"}
@@ -1,142 +0,0 @@
1
- import {
2
- NgZone,
3
- VERSION,
4
- computed,
5
- effect,
6
- inject,
7
- signal,
8
- untracked,
9
- } from '@angular/core'
10
- import {
11
- QueryClient,
12
- notifyManager,
13
- shouldThrowError,
14
- } from '@tanstack/query-core'
15
- import { signalProxy } from './signal-proxy'
16
- import { injectIsRestoring } from './inject-is-restoring'
17
- import type {
18
- QueryKey,
19
- QueryObserver,
20
- QueryObserverResult,
21
- } from '@tanstack/query-core'
22
- import type { CreateBaseQueryOptions } from './types'
23
-
24
- /**
25
- * Base implementation for `injectQuery` and `injectInfiniteQuery`.
26
- * @param optionsFn
27
- * @param Observer
28
- */
29
- export function createBaseQuery<
30
- TQueryFnData,
31
- TError,
32
- TData,
33
- TQueryData,
34
- TQueryKey extends QueryKey,
35
- >(
36
- optionsFn: () => CreateBaseQueryOptions<
37
- TQueryFnData,
38
- TError,
39
- TData,
40
- TQueryData,
41
- TQueryKey
42
- >,
43
- Observer: typeof QueryObserver,
44
- ) {
45
- const ngZone = inject(NgZone)
46
- const queryClient = inject(QueryClient)
47
- const isRestoring = injectIsRestoring()
48
-
49
- /**
50
- * Signal that has the default options from query client applied
51
- * computed() is used so signals can be inserted into the options
52
- * making it reactive. Wrapping options in a function ensures embedded expressions
53
- * are preserved and can keep being applied after signal changes
54
- */
55
- const defaultedOptionsSignal = computed(() => {
56
- const defaultedOptions = queryClient.defaultQueryOptions(optionsFn())
57
- defaultedOptions._optimisticResults = isRestoring()
58
- ? 'isRestoring'
59
- : 'optimistic'
60
- return defaultedOptions
61
- })
62
-
63
- const observerSignal = (() => {
64
- let instance: QueryObserver<
65
- TQueryFnData,
66
- TError,
67
- TData,
68
- TQueryData,
69
- TQueryKey
70
- > | null = null
71
-
72
- return computed(() => {
73
- return (instance ||= new Observer(queryClient, defaultedOptionsSignal()))
74
- })
75
- })()
76
-
77
- const optimisticResultSignal = computed(() =>
78
- observerSignal().getOptimisticResult(defaultedOptionsSignal()),
79
- )
80
-
81
- const resultFromSubscriberSignal = signal<QueryObserverResult<
82
- TData,
83
- TError
84
- > | null>(null)
85
-
86
- effect(
87
- (onCleanup) => {
88
- const observer = observerSignal()
89
- const defaultedOptions = defaultedOptionsSignal()
90
-
91
- untracked(() => {
92
- observer.setOptions(defaultedOptions)
93
- })
94
- onCleanup(() => {
95
- ngZone.run(() => resultFromSubscriberSignal.set(null))
96
- })
97
- },
98
- {
99
- // Set allowSignalWrites to support Angular < v19
100
- // Set to undefined to avoid warning on newer versions
101
- allowSignalWrites: VERSION.major < '19' || undefined,
102
- },
103
- )
104
-
105
- effect((onCleanup) => {
106
- // observer.trackResult is not used as this optimization is not needed for Angular
107
- const observer = observerSignal()
108
- const unsubscribe = isRestoring()
109
- ? () => undefined
110
- : untracked(() =>
111
- ngZone.runOutsideAngular(() =>
112
- observer.subscribe(
113
- notifyManager.batchCalls((state) => {
114
- ngZone.run(() => {
115
- if (
116
- state.isError &&
117
- !state.isFetching &&
118
- shouldThrowError(observer.options.throwOnError, [
119
- state.error,
120
- observer.getCurrentQuery(),
121
- ])
122
- ) {
123
- ngZone.onError.emit(state.error)
124
- throw state.error
125
- }
126
- resultFromSubscriberSignal.set(state)
127
- })
128
- }),
129
- ),
130
- ),
131
- )
132
- onCleanup(unsubscribe)
133
- })
134
-
135
- return signalProxy(
136
- computed(() => {
137
- const subscriberResult = resultFromSubscriberSignal()
138
- const optimisticResult = optimisticResultSignal()
139
- return subscriberResult ?? optimisticResult
140
- }),
141
- )
142
- }
package/src/index.ts DELETED
@@ -1,64 +0,0 @@
1
- /* istanbul ignore file */
2
-
3
- // Re-export core
4
- export * from '@tanstack/query-core'
5
-
6
- export * from './types'
7
-
8
- export type {
9
- DefinedInitialDataOptions,
10
- UndefinedInitialDataOptions,
11
- UnusedSkipTokenOptions,
12
- } from './query-options'
13
- export { queryOptions } from './query-options'
14
-
15
- export type { CreateMutationOptions } from './mutation-options'
16
- export { mutationOptions } from './mutation-options'
17
-
18
- export type {
19
- DefinedInitialDataInfiniteOptions,
20
- UndefinedInitialDataInfiniteOptions,
21
- UnusedSkipTokenInfiniteOptions,
22
- } from './infinite-query-options'
23
- export { infiniteQueryOptions } from './infinite-query-options'
24
-
25
- export type { InjectInfiniteQueryOptions } from './inject-infinite-query'
26
- export { injectInfiniteQuery } from './inject-infinite-query'
27
-
28
- export type { InjectIsFetchingOptions } from './inject-is-fetching'
29
- export { injectIsFetching } from './inject-is-fetching'
30
-
31
- export type { InjectIsMutatingOptions } from './inject-is-mutating'
32
- export { injectIsMutating } from './inject-is-mutating'
33
-
34
- export { injectIsRestoring, provideIsRestoring } from './inject-is-restoring'
35
-
36
- export type { InjectMutationOptions } from './inject-mutation'
37
- export { injectMutation } from './inject-mutation'
38
-
39
- export type { InjectMutationStateOptions } from './inject-mutation-state'
40
- export { injectMutationState } from './inject-mutation-state'
41
-
42
- export type { QueriesOptions, QueriesResults } from './inject-queries'
43
- export { injectQueries } from './inject-queries'
44
-
45
- export type { InjectQueryOptions } from './inject-query'
46
- export { injectQuery } from './inject-query'
47
-
48
- export { injectQueryClient } from './inject-query-client'
49
-
50
- export type {
51
- DeveloperToolsFeature,
52
- DevtoolsOptions,
53
- PersistQueryClientFeature,
54
- QueryFeature,
55
- QueryFeatureKind,
56
- QueryFeatures,
57
- } from './providers'
58
- export {
59
- provideQueryClient,
60
- provideTanStackQuery,
61
- queryFeature,
62
- queryFeatures,
63
- withDevtools,
64
- } from './providers'
@@ -1,187 +0,0 @@
1
- import type {
2
- DataTag,
3
- DefaultError,
4
- InfiniteData,
5
- InitialDataFunction,
6
- NonUndefinedGuard,
7
- OmitKeyof,
8
- QueryKey,
9
- SkipToken,
10
- } from '@tanstack/query-core'
11
- import type { CreateInfiniteQueryOptions } from './types'
12
-
13
- export type UndefinedInitialDataInfiniteOptions<
14
- TQueryFnData,
15
- TError = DefaultError,
16
- TData = InfiniteData<TQueryFnData>,
17
- TQueryKey extends QueryKey = QueryKey,
18
- TPageParam = unknown,
19
- > = CreateInfiniteQueryOptions<
20
- TQueryFnData,
21
- TError,
22
- TData,
23
- TQueryKey,
24
- TPageParam
25
- > & {
26
- initialData?:
27
- | undefined
28
- | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
29
- | InitialDataFunction<
30
- NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
31
- >
32
- }
33
-
34
- export type UnusedSkipTokenInfiniteOptions<
35
- TQueryFnData,
36
- TError = DefaultError,
37
- TData = InfiniteData<TQueryFnData>,
38
- TQueryKey extends QueryKey = QueryKey,
39
- TPageParam = unknown,
40
- > = OmitKeyof<
41
- CreateInfiniteQueryOptions<
42
- TQueryFnData,
43
- TError,
44
- TData,
45
- TQueryKey,
46
- TPageParam
47
- >,
48
- 'queryFn'
49
- > & {
50
- queryFn?: Exclude<
51
- CreateInfiniteQueryOptions<
52
- TQueryFnData,
53
- TError,
54
- TData,
55
- TQueryKey,
56
- TPageParam
57
- >['queryFn'],
58
- SkipToken | undefined
59
- >
60
- }
61
-
62
- export type DefinedInitialDataInfiniteOptions<
63
- TQueryFnData,
64
- TError = DefaultError,
65
- TData = InfiniteData<TQueryFnData>,
66
- TQueryKey extends QueryKey = QueryKey,
67
- TPageParam = unknown,
68
- > = CreateInfiniteQueryOptions<
69
- TQueryFnData,
70
- TError,
71
- TData,
72
- TQueryKey,
73
- TPageParam
74
- > & {
75
- initialData:
76
- | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
77
- | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
78
- | undefined
79
- }
80
-
81
- /**
82
- * Allows to share and re-use infinite query options in a type-safe way.
83
- *
84
- * The `queryKey` will be tagged with the type from `queryFn`.
85
- * @param options - The infinite query options to tag with the type from `queryFn`.
86
- * @returns The tagged infinite query options.
87
- * @public
88
- */
89
- export function infiniteQueryOptions<
90
- TQueryFnData,
91
- TError = DefaultError,
92
- TData = InfiniteData<TQueryFnData>,
93
- TQueryKey extends QueryKey = QueryKey,
94
- TPageParam = unknown,
95
- >(
96
- options: DefinedInitialDataInfiniteOptions<
97
- TQueryFnData,
98
- TError,
99
- TData,
100
- TQueryKey,
101
- TPageParam
102
- >,
103
- ): DefinedInitialDataInfiniteOptions<
104
- TQueryFnData,
105
- TError,
106
- TData,
107
- TQueryKey,
108
- TPageParam
109
- > & {
110
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
111
- }
112
-
113
- /**
114
- * Allows to share and re-use infinite query options in a type-safe way.
115
- *
116
- * The `queryKey` will be tagged with the type from `queryFn`.
117
- * @param options - The infinite query options to tag with the type from `queryFn`.
118
- * @returns The tagged infinite query options.
119
- * @public
120
- */
121
- export function infiniteQueryOptions<
122
- TQueryFnData,
123
- TError = DefaultError,
124
- TData = InfiniteData<TQueryFnData>,
125
- TQueryKey extends QueryKey = QueryKey,
126
- TPageParam = unknown,
127
- >(
128
- options: UnusedSkipTokenInfiniteOptions<
129
- TQueryFnData,
130
- TError,
131
- TData,
132
- TQueryKey,
133
- TPageParam
134
- >,
135
- ): UnusedSkipTokenInfiniteOptions<
136
- TQueryFnData,
137
- TError,
138
- TData,
139
- TQueryKey,
140
- TPageParam
141
- > & {
142
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
143
- }
144
-
145
- /**
146
- * Allows to share and re-use infinite query options in a type-safe way.
147
- *
148
- * The `queryKey` will be tagged with the type from `queryFn`.
149
- * @param options - The infinite query options to tag with the type from `queryFn`.
150
- * @returns The tagged infinite query options.
151
- * @public
152
- */
153
- export function infiniteQueryOptions<
154
- TQueryFnData,
155
- TError = DefaultError,
156
- TData = InfiniteData<TQueryFnData>,
157
- TQueryKey extends QueryKey = QueryKey,
158
- TPageParam = unknown,
159
- >(
160
- options: UndefinedInitialDataInfiniteOptions<
161
- TQueryFnData,
162
- TError,
163
- TData,
164
- TQueryKey,
165
- TPageParam
166
- >,
167
- ): UndefinedInitialDataInfiniteOptions<
168
- TQueryFnData,
169
- TError,
170
- TData,
171
- TQueryKey,
172
- TPageParam
173
- > & {
174
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
175
- }
176
-
177
- /**
178
- * Allows to share and re-use infinite query options in a type-safe way.
179
- *
180
- * The `queryKey` will be tagged with the type from `queryFn`.
181
- * @param options - The infinite query options to tag with the type from `queryFn`.
182
- * @returns The tagged infinite query options.
183
- * @public
184
- */
185
- export function infiniteQueryOptions(options: unknown) {
186
- return options
187
- }
@@ -1,129 +0,0 @@
1
- import { InfiniteQueryObserver } from '@tanstack/query-core'
2
- import {
3
- Injector,
4
- assertInInjectionContext,
5
- inject,
6
- runInInjectionContext,
7
- } from '@angular/core'
8
- import { createBaseQuery } from './create-base-query'
9
- import type {
10
- DefaultError,
11
- InfiniteData,
12
- QueryKey,
13
- QueryObserver,
14
- } from '@tanstack/query-core'
15
- import type {
16
- CreateInfiniteQueryOptions,
17
- CreateInfiniteQueryResult,
18
- DefinedCreateInfiniteQueryResult,
19
- } from './types'
20
- import type {
21
- DefinedInitialDataInfiniteOptions,
22
- UndefinedInitialDataInfiniteOptions,
23
- } from './infinite-query-options'
24
-
25
- export interface InjectInfiniteQueryOptions {
26
- /**
27
- * The `Injector` in which to create the infinite query.
28
- *
29
- * If this is not provided, the current injection context will be used instead (via `inject`).
30
- */
31
- injector?: Injector
32
- }
33
-
34
- /**
35
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
36
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
37
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
38
- * @param options - Additional configuration.
39
- * @returns The infinite query result.
40
- * @public
41
- */
42
- export function injectInfiniteQuery<
43
- TQueryFnData,
44
- TError = DefaultError,
45
- TData = InfiniteData<TQueryFnData>,
46
- TQueryKey extends QueryKey = QueryKey,
47
- TPageParam = unknown,
48
- >(
49
- injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<
50
- TQueryFnData,
51
- TError,
52
- TData,
53
- TQueryKey,
54
- TPageParam
55
- >,
56
- options?: InjectInfiniteQueryOptions,
57
- ): DefinedCreateInfiniteQueryResult<TData, TError>
58
-
59
- /**
60
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
61
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
62
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
63
- * @param options - Additional configuration.
64
- * @returns The infinite query result.
65
- * @public
66
- */
67
- export function injectInfiniteQuery<
68
- TQueryFnData,
69
- TError = DefaultError,
70
- TData = InfiniteData<TQueryFnData>,
71
- TQueryKey extends QueryKey = QueryKey,
72
- TPageParam = unknown,
73
- >(
74
- injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<
75
- TQueryFnData,
76
- TError,
77
- TData,
78
- TQueryKey,
79
- TPageParam
80
- >,
81
- options?: InjectInfiniteQueryOptions,
82
- ): CreateInfiniteQueryResult<TData, TError>
83
-
84
- /**
85
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
86
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
87
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
88
- * @param options - Additional configuration.
89
- * @returns The infinite query result.
90
- * @public
91
- */
92
- export function injectInfiniteQuery<
93
- TQueryFnData,
94
- TError = DefaultError,
95
- TData = InfiniteData<TQueryFnData>,
96
- TQueryKey extends QueryKey = QueryKey,
97
- TPageParam = unknown,
98
- >(
99
- injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<
100
- TQueryFnData,
101
- TError,
102
- TData,
103
- TQueryKey,
104
- TPageParam
105
- >,
106
- options?: InjectInfiniteQueryOptions,
107
- ): CreateInfiniteQueryResult<TData, TError>
108
-
109
- /**
110
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
111
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
112
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
113
- * @param options - Additional configuration.
114
- * @returns The infinite query result.
115
- * @public
116
- */
117
- export function injectInfiniteQuery(
118
- injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,
119
- options?: InjectInfiniteQueryOptions,
120
- ) {
121
- !options?.injector && assertInInjectionContext(injectInfiniteQuery)
122
- const injector = options?.injector ?? inject(Injector)
123
- return runInInjectionContext(injector, () =>
124
- createBaseQuery(
125
- injectInfiniteQueryFn,
126
- InfiniteQueryObserver as typeof QueryObserver,
127
- ),
128
- )
129
- }