@tanstack/angular-query-experimental 5.103.2 → 5.104.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/dist/create-base-query.d.mts +168 -0
- package/dist/create-base-query.d.mts.map +1 -0
- package/dist/create-base-query.mjs +91 -0
- package/dist/create-base-query.mjs.map +1 -0
- package/dist/devtools/index.d.mts +3 -0
- package/dist/devtools/index.mjs +2 -0
- package/dist/devtools/production/index.d.mts +4 -0
- package/dist/devtools/production/index.mjs +2 -0
- package/dist/devtools/stub.d.mts +5 -0
- package/dist/devtools/stub.d.mts.map +1 -0
- package/dist/devtools/stub.mjs +9 -0
- package/dist/devtools/stub.mjs.map +1 -0
- package/dist/devtools/types.d.mts +106 -0
- package/dist/devtools/types.d.mts.map +1 -0
- package/dist/devtools/types.mjs +1 -0
- package/{devtools/with-devtools.d.ts → dist/devtools/with-devtools.d.mts} +4 -1
- package/dist/devtools/with-devtools.d.mts.map +1 -0
- package/dist/devtools/with-devtools.mjs +110 -0
- package/dist/devtools/with-devtools.mjs.map +1 -0
- package/dist/devtools-panel/index.d.mts +3 -0
- package/dist/devtools-panel/index.mjs +2 -0
- package/{devtools-panel/inject-devtools-panel.d.ts → dist/devtools-panel/inject-devtools-panel.d.mts} +4 -1
- package/dist/devtools-panel/inject-devtools-panel.d.mts.map +1 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs +67 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs.map +1 -0
- package/dist/devtools-panel/production/index.d.mts +4 -0
- package/dist/devtools-panel/production/index.mjs +2 -0
- package/dist/devtools-panel/stub.d.mts +5 -0
- package/dist/devtools-panel/stub.d.mts.map +1 -0
- package/dist/devtools-panel/stub.mjs +7 -0
- package/dist/devtools-panel/stub.mjs.map +1 -0
- package/dist/devtools-panel/types.d.mts +51 -0
- package/dist/devtools-panel/types.d.mts.map +1 -0
- package/dist/devtools-panel/types.mjs +1 -0
- package/dist/index.d.mts +16 -0
- package/{index.mjs → dist/index.mjs} +8 -21
- package/dist/index.mjs.map +1 -0
- package/{infinite-query-options.d.ts → dist/infinite-query-options.d.mts} +28 -25
- package/dist/infinite-query-options.d.mts.map +1 -0
- package/dist/infinite-query-options.mjs +8 -0
- package/dist/infinite-query-options.mjs.map +1 -0
- package/{inject-infinite-query.d.ts → dist/inject-infinite-query.d.mts} +13 -10
- package/dist/inject-infinite-query.d.mts.map +1 -0
- package/dist/inject-infinite-query.mjs +13 -0
- package/dist/inject-infinite-query.mjs.map +1 -0
- package/{inject-is-fetching.d.ts → dist/inject-is-fetching.d.mts} +11 -8
- package/dist/inject-is-fetching.d.mts.map +1 -0
- package/dist/inject-is-fetching.mjs +69 -0
- package/dist/inject-is-fetching.mjs.map +1 -0
- package/{inject-is-mutating.d.ts → dist/inject-is-mutating.d.mts} +11 -8
- package/dist/inject-is-mutating.d.mts.map +1 -0
- package/dist/inject-is-mutating.mjs +52 -0
- package/dist/inject-is-mutating.mjs.map +1 -0
- package/{inject-is-restoring.d.ts → dist/inject-is-restoring.d.mts} +10 -8
- package/dist/inject-is-restoring.d.mts.map +1 -0
- package/dist/inject-is-restoring.mjs +35 -0
- package/dist/inject-is-restoring.mjs.map +1 -0
- package/{inject-mutation-state.d.ts → dist/inject-mutation-state.d.mts} +13 -11
- package/dist/inject-mutation-state.d.mts.map +1 -0
- package/dist/inject-mutation-state.mjs +103 -0
- package/dist/inject-mutation-state.mjs.map +1 -0
- package/{inject-mutation.d.ts → dist/inject-mutation.d.mts} +12 -9
- package/dist/inject-mutation.d.mts.map +1 -0
- package/dist/inject-mutation.mjs +226 -0
- package/dist/inject-mutation.mjs.map +1 -0
- package/dist/inject-queries-experimental/index.d.mts +2 -0
- package/dist/inject-queries-experimental/index.mjs +2 -0
- package/{inject-queries.d.ts → dist/inject-queries.d.mts} +33 -53
- package/dist/inject-queries.d.mts.map +1 -0
- package/dist/inject-queries.mjs +203 -0
- package/dist/inject-queries.mjs.map +1 -0
- package/{inject-query-client.d.ts → dist/inject-query-client.d.mts} +6 -3
- package/dist/inject-query-client.d.mts.map +1 -0
- package/dist/inject-query-client.mjs +23 -0
- package/dist/inject-query-client.mjs.map +1 -0
- package/{inject-query.d.ts → dist/inject-query.d.mts} +13 -10
- package/dist/inject-query.d.mts.map +1 -0
- package/dist/inject-query.mjs +12 -0
- package/dist/inject-query.mjs.map +1 -0
- package/{mutation-options.d.ts → dist/mutation-options.d.mts} +5 -2
- package/dist/mutation-options.d.mts.map +1 -0
- package/dist/mutation-options.mjs +8 -0
- package/dist/mutation-options.mjs.map +1 -0
- package/dist/pending-tasks-compat.d.mts +9 -0
- package/dist/pending-tasks-compat.d.mts.map +1 -0
- package/dist/pending-tasks-compat.mjs +13 -0
- package/dist/pending-tasks-compat.mjs.map +1 -0
- package/{providers.d.ts → dist/providers.d.mts} +7 -5
- package/dist/providers.d.mts.map +1 -0
- package/dist/providers.mjs +124 -0
- package/dist/providers.mjs.map +1 -0
- package/{query-options.d.ts → dist/query-options.d.mts} +34 -31
- package/dist/query-options.d.mts.map +1 -0
- package/dist/query-options.mjs +8 -0
- package/dist/query-options.mjs.map +1 -0
- package/{signal-proxy.d.ts → dist/signal-proxy.d.mts} +5 -4
- package/dist/signal-proxy.d.mts.map +1 -0
- package/dist/signal-proxy.mjs +35 -0
- package/dist/signal-proxy.mjs.map +1 -0
- package/{types.d.ts → dist/types.d.mts} +24 -26
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +50 -20
- package/src/__tests__/infinite-query-options.test-d.ts +314 -0
- package/src/__tests__/infinite-query-options.test.ts +19 -0
- package/src/__tests__/inject-devtools-panel.test.ts +196 -0
- package/src/__tests__/inject-infinite-query.test-d.ts +66 -0
- package/src/__tests__/inject-infinite-query.test.ts +227 -0
- package/src/__tests__/inject-is-fetching.test.ts +108 -0
- package/src/__tests__/inject-is-mutating.test.ts +113 -0
- package/src/__tests__/inject-is-restoring.test.ts +93 -0
- package/src/__tests__/inject-mutation-state.test-d.ts +22 -0
- package/src/__tests__/inject-mutation-state.test.ts +198 -0
- package/src/__tests__/inject-mutation.test-d.ts +158 -0
- package/src/__tests__/inject-mutation.test.ts +1161 -0
- package/src/__tests__/inject-queries.test-d.ts +196 -0
- package/src/__tests__/inject-queries.test.ts +240 -0
- package/src/__tests__/inject-query.test-d.ts +357 -0
- package/src/__tests__/inject-query.test.ts +700 -0
- package/src/__tests__/mutation-options.test-d.ts +234 -0
- package/src/__tests__/mutation-options.test.ts +344 -0
- package/src/__tests__/pending-tasks.test.ts +644 -0
- package/src/__tests__/provide-query-client.test.ts +38 -0
- package/src/__tests__/provide-tanstack-query.test.ts +38 -0
- package/src/__tests__/query-options.test-d.ts +262 -0
- package/src/__tests__/query-options.test.ts +14 -0
- package/src/__tests__/signal-proxy.test.ts +27 -0
- package/src/__tests__/test-utils.ts +77 -0
- package/src/__tests__/with-devtools.test.ts +674 -0
- package/src/create-base-query.ts +176 -0
- package/src/devtools/index.ts +8 -0
- package/src/devtools/production/index.ts +1 -0
- package/src/devtools/stub.ts +7 -0
- package/src/devtools/types.ts +116 -0
- package/src/devtools/with-devtools.ts +182 -0
- package/src/devtools-panel/index.ts +8 -0
- package/src/devtools-panel/inject-devtools-panel.ts +110 -0
- package/src/devtools-panel/production/index.ts +1 -0
- package/src/devtools-panel/stub.ts +7 -0
- package/src/devtools-panel/types.ts +57 -0
- package/src/index.ts +60 -0
- package/src/infinite-query-options.ts +354 -0
- package/src/inject-infinite-query.ts +296 -0
- package/src/inject-is-fetching.ts +97 -0
- package/src/inject-is-mutating.ts +80 -0
- package/src/inject-is-restoring.ts +53 -0
- package/src/inject-mutation-state.ts +167 -0
- package/src/inject-mutation.ts +328 -0
- package/src/inject-queries-experimental/index.ts +1 -0
- package/src/inject-queries.ts +480 -0
- package/src/inject-query-client.ts +22 -0
- package/src/inject-query.ts +208 -0
- package/src/mutation-options.ts +121 -0
- package/src/pending-tasks-compat.ts +27 -0
- package/src/providers.ts +170 -0
- package/src/query-options.ts +292 -0
- package/src/signal-proxy.ts +46 -0
- package/src/types.ts +429 -0
- package/create-base-query.d.ts +0 -164
- package/create-base-query.mjs +0 -99
- package/create-base-query.mjs.map +0 -1
- package/devtools/index.d.ts +0 -2
- package/devtools/index.mjs +0 -5
- package/devtools/index.mjs.map +0 -1
- package/devtools/production/index.d.ts +0 -1
- package/devtools/stub.d.ts +0 -2
- package/devtools/stub.mjs +0 -8
- package/devtools/stub.mjs.map +0 -1
- package/devtools/types.d.ts +0 -103
- package/devtools/with-devtools.mjs +0 -106
- package/devtools/with-devtools.mjs.map +0 -1
- package/devtools-panel/index.d.ts +0 -2
- package/devtools-panel/index.mjs +0 -5
- package/devtools-panel/index.mjs.map +0 -1
- package/devtools-panel/inject-devtools-panel.mjs +0 -72
- package/devtools-panel/inject-devtools-panel.mjs.map +0 -1
- package/devtools-panel/production/index.d.ts +0 -1
- package/devtools-panel/stub.d.ts +0 -2
- package/devtools-panel/stub.mjs +0 -8
- package/devtools-panel/stub.mjs.map +0 -1
- package/devtools-panel/types.d.ts +0 -48
- package/index.d.ts +0 -25
- package/index.mjs.map +0 -1
- package/infinite-query-options.mjs +0 -7
- package/infinite-query-options.mjs.map +0 -1
- package/inject-infinite-query.mjs +0 -18
- package/inject-infinite-query.mjs.map +0 -1
- package/inject-is-fetching.mjs +0 -31
- package/inject-is-fetching.mjs.map +0 -1
- package/inject-is-mutating.mjs +0 -31
- package/inject-is-mutating.mjs.map +0 -1
- package/inject-is-restoring.mjs +0 -21
- package/inject-is-restoring.mjs.map +0 -1
- package/inject-mutation-state.mjs +0 -51
- package/inject-mutation-state.mjs.map +0 -1
- package/inject-mutation.mjs +0 -94
- package/inject-mutation.mjs.map +0 -1
- package/inject-queries-experimental/index.d.ts +0 -1
- package/inject-queries-experimental/index.mjs +0 -5
- package/inject-queries-experimental/index.mjs.map +0 -1
- package/inject-queries.mjs +0 -82
- package/inject-queries.mjs.map +0 -1
- package/inject-query-client.mjs +0 -9
- package/inject-query-client.mjs.map +0 -1
- package/inject-query.mjs +0 -14
- package/inject-query.mjs.map +0 -1
- package/mutation-options.mjs +0 -7
- package/mutation-options.mjs.map +0 -1
- package/pending-tasks-compat.d.ts +0 -7
- package/pending-tasks-compat.mjs +0 -19
- package/pending-tasks-compat.mjs.map +0 -1
- package/providers.mjs +0 -32
- package/providers.mjs.map +0 -1
- package/query-options.mjs +0 -7
- package/query-options.mjs.map +0 -1
- package/signal-proxy.mjs +0 -29
- package/signal-proxy.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-base-query.mjs","sources":["../src/create-base-query.ts"],"sourcesContent":["import {\n NgZone,\n VERSION,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport {\n QueryClient,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { signalProxy } from './signal-proxy'\nimport { injectIsRestoring } from './inject-is-restoring'\nimport { PENDING_TASKS } from './pending-tasks-compat'\nimport type { PendingTaskRef } from './pending-tasks-compat'\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\n\n/**\n * Base implementation for `injectQuery` and `injectInfiniteQuery`.\n * @param optionsFn\n * @param Observer\n */\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n optionsFn: () => CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n) {\n const ngZone = inject(NgZone)\n const pendingTasks = inject(PENDING_TASKS)\n const queryClient = inject(QueryClient)\n const isRestoring = injectIsRestoring()\n\n /**\n * Signal that has the default options from query client applied\n * computed() is used so signals can be inserted into the options\n * making it reactive. Wrapping options in a function ensures embedded expressions\n * are preserved and can keep being applied after signal changes\n */\n const defaultedOptionsSignal = computed(() => {\n const defaultedOptions = queryClient.defaultQueryOptions(optionsFn())\n defaultedOptions._optimisticResults = isRestoring()\n ? 'isRestoring'\n : 'optimistic'\n return defaultedOptions\n })\n\n const observerSignal = (() => {\n let instance: QueryObserver<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > | null = null\n\n return computed(() => {\n return (instance ||= new Observer(queryClient, defaultedOptionsSignal()))\n })\n })()\n\n const optimisticResultSignal = computed(() =>\n observerSignal().getOptimisticResult(defaultedOptionsSignal()),\n )\n\n const resultFromSubscriberSignal = signal<QueryObserverResult<\n TData,\n TError\n > | null>(null)\n\n effect(\n (onCleanup) => {\n const observer = observerSignal()\n const defaultedOptions = defaultedOptionsSignal()\n\n untracked(() => {\n observer.setOptions(defaultedOptions)\n })\n onCleanup(() => {\n ngZone.run(() => resultFromSubscriberSignal.set(null))\n })\n },\n {\n // Set allowSignalWrites to support Angular < v19\n // Set to undefined to avoid warning on newer versions\n allowSignalWrites: VERSION.major < '19' || undefined,\n },\n )\n\n effect((onCleanup) => {\n // observer.trackResult is not used as this optimization is not needed for Angular\n const observer = observerSignal()\n let pendingTaskRef: PendingTaskRef | null = null\n\n const unsubscribe = isRestoring()\n ? () => undefined\n : untracked(() =>\n ngZone.runOutsideAngular(() => {\n return observer.subscribe(\n notifyManager.batchCalls((state) => {\n ngZone.run(() => {\n if (state.fetchStatus === 'fetching' && !pendingTaskRef) {\n pendingTaskRef = pendingTasks.add()\n }\n\n if (state.fetchStatus === 'idle' && pendingTaskRef) {\n pendingTaskRef()\n pendingTaskRef = null\n }\n\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.throwOnError, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n ngZone.onError.emit(state.error)\n throw state.error\n }\n resultFromSubscriberSignal.set(state)\n })\n }),\n )\n }),\n )\n\n onCleanup(() => {\n if (pendingTaskRef) {\n pendingTaskRef()\n pendingTaskRef = null\n }\n unsubscribe()\n })\n })\n\n return signalProxy(\n computed(() => {\n const subscriberResult = resultFromSubscriberSignal()\n const optimisticResult = optimisticResultSignal()\n const result = subscriberResult ?? optimisticResult\n\n // Wrap methods to ensure observer has latest options before execution\n const observer = observerSignal()\n\n const originalRefetch = result.refetch\n return {\n ...result,\n refetch: ((...args: Parameters<typeof originalRefetch>) => {\n observer.setOptions(defaultedOptionsSignal())\n return originalRefetch(...args)\n }) as typeof originalRefetch,\n }\n }),\n )\n}\n"],"names":[],"mappings":";;;;;AA8BO,SAAS,gBAOd,WAOA,UACA;AACA,QAAM,SAAS,OAAO,MAAM;AAC5B,QAAM,eAAe,OAAO,aAAa;AACzC,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,cAAc,kBAAA;AAQpB,QAAM,yBAAyB,SAAS,MAAM;AAC5C,UAAM,mBAAmB,YAAY,oBAAoB,UAAA,CAAW;AACpE,qBAAiB,qBAAqB,YAAA,IAClC,gBACA;AACJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,kBAAkB,MAAM;AAC5B,QAAI,WAMO;AAEX,WAAO,SAAS,MAAM;AACpB,aAAQ,wBAAa,IAAI,SAAS,aAAa,wBAAwB;AAAA,IACzE,CAAC;AAAA,EACH,GAAA;AAEA,QAAM,yBAAyB;AAAA,IAAS,MACtC,eAAA,EAAiB,oBAAoB,wBAAwB;AAAA,EAAA;AAG/D,QAAM,6BAA6B,OAGzB,IAAI;AAEd;AAAA,IACE,CAAC,cAAc;AACb,YAAM,WAAW,eAAA;AACjB,YAAM,mBAAmB,uBAAA;AAEzB,gBAAU,MAAM;AACd,iBAAS,WAAW,gBAAgB;AAAA,MACtC,CAAC;AACD,gBAAU,MAAM;AACd,eAAO,IAAI,MAAM,2BAA2B,IAAI,IAAI,CAAC;AAAA,MACvD,CAAC;AAAA,IACH;AAAA,IACA;AAAA;AAAA;AAAA,MAGE,mBAAmB,QAAQ,QAAQ,QAAQ;AAAA,IAAA;AAAA,EAC7C;AAGF,SAAO,CAAC,cAAc;AAEpB,UAAM,WAAW,eAAA;AACjB,QAAI,iBAAwC;AAE5C,UAAM,cAAc,gBAChB,MAAM,SACN;AAAA,MAAU,MACR,OAAO,kBAAkB,MAAM;AAC7B,eAAO,SAAS;AAAA,UACd,cAAc,WAAW,CAAC,UAAU;AAClC,mBAAO,IAAI,MAAM;AACf,kBAAI,MAAM,gBAAgB,cAAc,CAAC,gBAAgB;AACvD,iCAAiB,aAAa,IAAA;AAAA,cAChC;AAEA,kBAAI,MAAM,gBAAgB,UAAU,gBAAgB;AAClD,+BAAA;AACA,iCAAiB;AAAA,cACnB;AAEA,kBACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,SAAS,QAAQ,cAAc;AAAA,gBAC9C,MAAM;AAAA,gBACN,SAAS,gBAAA;AAAA,cAAgB,CAC1B,GACD;AACA,uBAAO,QAAQ,KAAK,MAAM,KAAK;AAC/B,sBAAM,MAAM;AAAA,cACd;AACA,yCAA2B,IAAI,KAAK;AAAA,YACtC,CAAC;AAAA,UACH,CAAC;AAAA,QAAA;AAAA,MAEL,CAAC;AAAA,IAAA;AAGP,cAAU,MAAM;AACd,UAAI,gBAAgB;AAClB,uBAAA;AACA,yBAAiB;AAAA,MACnB;AACA,kBAAA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AAAA,IACL,SAAS,MAAM;AACb,YAAM,mBAAmB,2BAAA;AACzB,YAAM,mBAAmB,uBAAA;AACzB,YAAM,SAAS,oBAAoB;AAGnC,YAAM,WAAW,eAAA;AAEjB,YAAM,kBAAkB,OAAO;AAC/B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,UAAU,IAAI,SAA6C;AACzD,mBAAS,WAAW,wBAAwB;AAC5C,iBAAO,gBAAgB,GAAG,IAAI;AAAA,QAChC;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EAAA;AAEL;"}
|
package/devtools/index.d.ts
DELETED
package/devtools/index.mjs
DELETED
package/devtools/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '..';
|
package/devtools/stub.d.ts
DELETED
package/devtools/stub.mjs
DELETED
package/devtools/stub.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stub.mjs","sources":["../../src/devtools/stub.ts"],"sourcesContent":["import type { WithDevtools } from './types'\n\n// Stub which replaces `withDevtools` in production builds\nexport const withDevtools: WithDevtools = () => ({\n ɵkind: 'Devtools',\n ɵproviders: [],\n})\n"],"names":[],"mappings":"AAGO,MAAM,eAA6B,OAAO;AAAA,EAC/C,OAAO;AAAA,EACP,YAAY,CAAA;AACd;"}
|
package/devtools/types.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/query-core';
|
|
2
|
-
import { DevtoolsButtonPosition, DevtoolsErrorType, DevtoolsPosition, Theme } from '@tanstack/query-devtools';
|
|
3
|
-
import { DevtoolsFeature } from '../providers.js';
|
|
4
|
-
/**
|
|
5
|
-
* Options for configuring withDevtools.
|
|
6
|
-
*/
|
|
7
|
-
export interface WithDevtoolsOptions {
|
|
8
|
-
/**
|
|
9
|
-
* An array of dependencies to be injected and passed to the `withDevtoolsFn` function.
|
|
10
|
-
*
|
|
11
|
-
* **Example**
|
|
12
|
-
* ```ts
|
|
13
|
-
* export const appConfig: ApplicationConfig = {
|
|
14
|
-
* providers: [
|
|
15
|
-
* provideTanStackQuery(
|
|
16
|
-
* new QueryClient(),
|
|
17
|
-
* withDevtools(
|
|
18
|
-
* (devToolsOptionsManager: DevtoolsOptionsManager) => ({
|
|
19
|
-
* loadDevtools: devToolsOptionsManager.loadDevtools(),
|
|
20
|
-
* }),
|
|
21
|
-
* {
|
|
22
|
-
* deps: [DevtoolsOptionsManager],
|
|
23
|
-
* },
|
|
24
|
-
* ),
|
|
25
|
-
* ),
|
|
26
|
-
* ],
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
deps?: Array<any>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Options for configuring the TanStack Query devtools.
|
|
34
|
-
*/
|
|
35
|
-
export interface DevtoolsOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Set this true if you want the devtools to default to being open
|
|
38
|
-
*/
|
|
39
|
-
initialIsOpen?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* The position of the TanStack logo to open and close the devtools panel.
|
|
42
|
-
* `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`
|
|
43
|
-
*
|
|
44
|
-
* @defaultValue bottom-right
|
|
45
|
-
*/
|
|
46
|
-
buttonPosition?: DevtoolsButtonPosition;
|
|
47
|
-
/**
|
|
48
|
-
* The position of the Angular Query devtools panel.
|
|
49
|
-
* `top` | `bottom` | `left` | `right`
|
|
50
|
-
*
|
|
51
|
-
* @defaultValue bottom
|
|
52
|
-
*/
|
|
53
|
-
position?: DevtoolsPosition;
|
|
54
|
-
/**
|
|
55
|
-
* Custom instance of QueryClient
|
|
56
|
-
*/
|
|
57
|
-
client?: QueryClient;
|
|
58
|
-
/**
|
|
59
|
-
* Use this so you can define custom errors that can be shown in the devtools.
|
|
60
|
-
*/
|
|
61
|
-
errorTypes?: Array<DevtoolsErrorType>;
|
|
62
|
-
/**
|
|
63
|
-
* 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.
|
|
64
|
-
*/
|
|
65
|
-
styleNonce?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Use this so you can attach the devtool's styles to a specific element in the DOM.
|
|
68
|
-
*/
|
|
69
|
-
shadowDOMTarget?: ShadowRoot;
|
|
70
|
-
/**
|
|
71
|
-
* Set this to true to hide disabled queries from the devtools panel.
|
|
72
|
-
*/
|
|
73
|
-
hideDisabledQueries?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
|
|
76
|
-
*
|
|
77
|
-
* @defaultValue system
|
|
78
|
-
*/
|
|
79
|
-
theme?: Theme;
|
|
80
|
-
/**
|
|
81
|
-
* Whether the developer tools should load.
|
|
82
|
-
* - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.
|
|
83
|
-
* - `true`- Always load the devtools, regardless of the environment.
|
|
84
|
-
* - `false`- Never load the devtools, regardless of the environment.
|
|
85
|
-
*
|
|
86
|
-
* You can use `true` and `false` to override loading developer tools from an environment file.
|
|
87
|
-
* For example, a test environment might run in production mode but you may want to load developer tools.
|
|
88
|
-
*
|
|
89
|
-
* Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example,
|
|
90
|
-
* a signal created from a RxJS observable that listens for a keyboard shortcut.
|
|
91
|
-
*
|
|
92
|
-
* **Example**
|
|
93
|
-
* ```ts
|
|
94
|
-
* withDevtools(() => ({
|
|
95
|
-
* initialIsOpen: true,
|
|
96
|
-
* loadDevtools: inject(ExampleService).loadDevtools()
|
|
97
|
-
* }))
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
loadDevtools?: 'auto' | boolean;
|
|
101
|
-
}
|
|
102
|
-
export type WithDevtoolsFn = (...deps: Array<any>) => DevtoolsOptions;
|
|
103
|
-
export type WithDevtools = (withDevtoolsFn?: WithDevtoolsFn, options?: WithDevtoolsOptions) => DevtoolsFeature;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { isPlatformBrowser } from "@angular/common";
|
|
2
|
-
import { InjectionToken, ENVIRONMENT_INITIALIZER, computed, inject, PLATFORM_ID, DestroyRef, Injector, isDevMode, effect } from "@angular/core";
|
|
3
|
-
import { noop, QueryClient, onlineManager } from "@tanstack/query-core";
|
|
4
|
-
import { queryFeature } from "../providers.mjs";
|
|
5
|
-
const DEVTOOLS_PROVIDED = new InjectionToken("", {
|
|
6
|
-
factory: () => ({
|
|
7
|
-
isProvided: false
|
|
8
|
-
})
|
|
9
|
-
});
|
|
10
|
-
const DEVTOOLS_OPTIONS_SIGNAL = new InjectionToken("");
|
|
11
|
-
const withDevtools = (withDevtoolsFn, options = {}) => queryFeature("Devtools", [
|
|
12
|
-
{
|
|
13
|
-
provide: DEVTOOLS_OPTIONS_SIGNAL,
|
|
14
|
-
useFactory: (...deps) => computed(() => (withDevtoolsFn == null ? void 0 : withDevtoolsFn(...deps)) ?? {}),
|
|
15
|
-
deps: options.deps || []
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
|
|
19
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
20
|
-
multi: true,
|
|
21
|
-
useFactory: () => {
|
|
22
|
-
const devtoolsProvided = inject(DEVTOOLS_PROVIDED);
|
|
23
|
-
if (!isPlatformBrowser(inject(PLATFORM_ID)) || devtoolsProvided.isProvided)
|
|
24
|
-
return noop;
|
|
25
|
-
devtoolsProvided.isProvided = true;
|
|
26
|
-
let injectorIsDestroyed = false;
|
|
27
|
-
inject(DestroyRef).onDestroy(() => injectorIsDestroyed = true);
|
|
28
|
-
return () => {
|
|
29
|
-
const injectedClient = inject(QueryClient, {
|
|
30
|
-
optional: true
|
|
31
|
-
});
|
|
32
|
-
const destroyRef = inject(DestroyRef);
|
|
33
|
-
const devtoolsOptions = inject(DEVTOOLS_OPTIONS_SIGNAL);
|
|
34
|
-
const injector = inject(Injector);
|
|
35
|
-
let devtools = null;
|
|
36
|
-
let el = null;
|
|
37
|
-
const shouldLoadToolsSignal = computed(() => {
|
|
38
|
-
const { loadDevtools } = devtoolsOptions();
|
|
39
|
-
return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
|
|
40
|
-
});
|
|
41
|
-
const getResolvedQueryClient = () => {
|
|
42
|
-
const client = devtoolsOptions().client ?? injectedClient;
|
|
43
|
-
if (!client) {
|
|
44
|
-
throw new Error("No QueryClient found");
|
|
45
|
-
}
|
|
46
|
-
return client;
|
|
47
|
-
};
|
|
48
|
-
const destroyDevtools = () => {
|
|
49
|
-
devtools == null ? void 0 : devtools.unmount();
|
|
50
|
-
el == null ? void 0 : el.remove();
|
|
51
|
-
devtools = null;
|
|
52
|
-
};
|
|
53
|
-
effect(
|
|
54
|
-
() => {
|
|
55
|
-
const shouldLoadTools = shouldLoadToolsSignal();
|
|
56
|
-
const {
|
|
57
|
-
client,
|
|
58
|
-
position,
|
|
59
|
-
errorTypes,
|
|
60
|
-
buttonPosition,
|
|
61
|
-
initialIsOpen,
|
|
62
|
-
theme
|
|
63
|
-
} = devtoolsOptions();
|
|
64
|
-
if (!shouldLoadTools) {
|
|
65
|
-
devtools && destroyDevtools();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (devtools) {
|
|
69
|
-
client && devtools.setClient(client);
|
|
70
|
-
position && devtools.setPosition(position);
|
|
71
|
-
errorTypes && devtools.setErrorTypes(errorTypes);
|
|
72
|
-
buttonPosition && devtools.setButtonPosition(buttonPosition);
|
|
73
|
-
typeof initialIsOpen === "boolean" && devtools.setInitialIsOpen(initialIsOpen);
|
|
74
|
-
theme && devtools.setTheme(theme);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
import("@tanstack/query-devtools").then((queryDevtools) => {
|
|
78
|
-
if (injectorIsDestroyed) return;
|
|
79
|
-
devtools = new queryDevtools.TanstackQueryDevtools({
|
|
80
|
-
...devtoolsOptions(),
|
|
81
|
-
client: getResolvedQueryClient(),
|
|
82
|
-
queryFlavor: "Angular Query",
|
|
83
|
-
version: "5",
|
|
84
|
-
onlineManager
|
|
85
|
-
});
|
|
86
|
-
el = document.body.appendChild(document.createElement("div"));
|
|
87
|
-
el.classList.add("tsqd-parent-container");
|
|
88
|
-
devtools.mount(el);
|
|
89
|
-
destroyRef.onDestroy(destroyDevtools);
|
|
90
|
-
}).catch((error) => {
|
|
91
|
-
console.error(
|
|
92
|
-
"Install @tanstack/query-devtools or reinstall without --omit=optional.",
|
|
93
|
-
error
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
{ injector }
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
]);
|
|
103
|
-
export {
|
|
104
|
-
withDevtools
|
|
105
|
-
};
|
|
106
|
-
//# sourceMappingURL=with-devtools.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-devtools.mjs","sources":["../../src/devtools/with-devtools.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n InjectionToken,\n Injector,\n PLATFORM_ID,\n computed,\n effect,\n inject,\n isDevMode,\n} from '@angular/core'\nimport { QueryClient, noop, onlineManager } from '@tanstack/query-core'\nimport { queryFeature } from '../providers'\nimport type { Signal } from '@angular/core'\nimport type {\n DevtoolsOptions,\n WithDevtools,\n WithDevtoolsFn,\n WithDevtoolsOptions,\n} from './types'\nimport type { TanstackQueryDevtools } from '@tanstack/query-devtools'\n\n/**\n * Internal token used to prevent double providing of devtools in child injectors\n */\nconst DEVTOOLS_PROVIDED = new InjectionToken('', {\n factory: () => ({\n isProvided: false,\n }),\n})\n\n/**\n * Internal token for providing devtools options\n */\nconst DEVTOOLS_OPTIONS_SIGNAL = new InjectionToken<Signal<DevtoolsOptions>>('')\n\n/**\n * Enables developer tools in Angular development builds.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * ```\n * The devtools will be rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option.\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 * @param options - Additional options for configuring `withDevtools`.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport const withDevtools: WithDevtools = (\n withDevtoolsFn?: WithDevtoolsFn,\n options: WithDevtoolsOptions = {},\n) =>\n queryFeature('Devtools', [\n {\n provide: DEVTOOLS_OPTIONS_SIGNAL,\n useFactory: (...deps: Array<any>) =>\n computed(() => withDevtoolsFn?.(...deps) ?? {}),\n deps: options.deps || [],\n },\n {\n // Do not use provideEnvironmentInitializer while Angular < v19 is supported\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: () => {\n const devtoolsProvided = inject(DEVTOOLS_PROVIDED)\n if (\n !isPlatformBrowser(inject(PLATFORM_ID)) ||\n devtoolsProvided.isProvided\n )\n return noop\n\n devtoolsProvided.isProvided = true\n let injectorIsDestroyed = false\n inject(DestroyRef).onDestroy(() => (injectorIsDestroyed = true))\n\n return () => {\n const injectedClient = inject(QueryClient, {\n optional: true,\n })\n const destroyRef = inject(DestroyRef)\n const devtoolsOptions = inject(DEVTOOLS_OPTIONS_SIGNAL)\n const injector = inject(Injector)\n\n let devtools: TanstackQueryDevtools | null = null\n let el: HTMLElement | null = null\n\n const shouldLoadToolsSignal = computed(() => {\n const { loadDevtools } = devtoolsOptions()\n return typeof loadDevtools === 'boolean'\n ? loadDevtools\n : isDevMode()\n })\n\n const getResolvedQueryClient = () => {\n const client = devtoolsOptions().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 effect(\n () => {\n const shouldLoadTools = shouldLoadToolsSignal()\n const {\n client,\n position,\n errorTypes,\n buttonPosition,\n initialIsOpen,\n theme,\n } = devtoolsOptions()\n\n if (!shouldLoadTools) {\n // Destroy or do nothing\n devtools && destroyDevtools()\n return\n }\n\n if (devtools) {\n // Update existing devtools config\n client && devtools.setClient(client)\n position && devtools.setPosition(position)\n errorTypes && devtools.setErrorTypes(errorTypes)\n buttonPosition && devtools.setButtonPosition(buttonPosition)\n typeof initialIsOpen === 'boolean' &&\n devtools.setInitialIsOpen(initialIsOpen)\n theme && devtools.setTheme(theme)\n return\n }\n\n // Create devtools\n import('@tanstack/query-devtools')\n .then((queryDevtools) => {\n // As this code runs async, the injector could have been destroyed\n if (injectorIsDestroyed) return\n\n devtools = new queryDevtools.TanstackQueryDevtools({\n ...devtoolsOptions(),\n client: getResolvedQueryClient(),\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n })\n\n el = document.body.appendChild(document.createElement('div'))\n el.classList.add('tsqd-parent-container')\n devtools.mount(el)\n\n destroyRef.onDestroy(destroyDevtools)\n })\n .catch((error) => {\n console.error(\n 'Install @tanstack/query-devtools or reinstall without --omit=optional.',\n error,\n )\n })\n },\n { injector },\n )\n }\n },\n },\n ])\n"],"names":[],"mappings":";;;;AA0BA,MAAM,oBAAoB,IAAI,eAAe,IAAI;AAAA,EAC/C,SAAS,OAAO;AAAA,IACd,YAAY;AAAA,EAAA;AAEhB,CAAC;AAKD,MAAM,0BAA0B,IAAI,eAAwC,EAAE;AAyBvE,MAAM,eAA6B,CACxC,gBACA,UAA+B,CAAA,MAE/B,aAAa,YAAY;AAAA,EACvB;AAAA,IACE,SAAS;AAAA,IACT,YAAY,IAAI,SACd,SAAS,OAAM,iDAAiB,GAAG,UAAS,EAAE;AAAA,IAChD,MAAM,QAAQ,QAAQ,CAAA;AAAA,EAAC;AAAA,EAEzB;AAAA;AAAA,IAEE,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY,MAAM;AAChB,YAAM,mBAAmB,OAAO,iBAAiB;AACjD,UACE,CAAC,kBAAkB,OAAO,WAAW,CAAC,KACtC,iBAAiB;AAEjB,eAAO;AAET,uBAAiB,aAAa;AAC9B,UAAI,sBAAsB;AAC1B,aAAO,UAAU,EAAE,UAAU,MAAO,sBAAsB,IAAK;AAE/D,aAAO,MAAM;AACX,cAAM,iBAAiB,OAAO,aAAa;AAAA,UACzC,UAAU;AAAA,QAAA,CACX;AACD,cAAM,aAAa,OAAO,UAAU;AACpC,cAAM,kBAAkB,OAAO,uBAAuB;AACtD,cAAM,WAAW,OAAO,QAAQ;AAEhC,YAAI,WAAyC;AAC7C,YAAI,KAAyB;AAE7B,cAAM,wBAAwB,SAAS,MAAM;AAC3C,gBAAM,EAAE,aAAA,IAAiB,gBAAA;AACzB,iBAAO,OAAO,iBAAiB,YAC3B,eACA,UAAA;AAAA,QACN,CAAC;AAED,cAAM,yBAAyB,MAAM;AACnC,gBAAM,SAAS,kBAAkB,UAAU;AAC3C,cAAI,CAAC,QAAQ;AACX,kBAAM,IAAI,MAAM,sBAAsB;AAAA,UACxC;AACA,iBAAO;AAAA,QACT;AAEA,cAAM,kBAAkB,MAAM;AAC5B,+CAAU;AACV,mCAAI;AACJ,qBAAW;AAAA,QACb;AAEA;AAAA,UACE,MAAM;AACJ,kBAAM,kBAAkB,sBAAA;AACxB,kBAAM;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA,IACE,gBAAA;AAEJ,gBAAI,CAAC,iBAAiB;AAEpB,0BAAY,gBAAA;AACZ;AAAA,YACF;AAEA,gBAAI,UAAU;AAEZ,wBAAU,SAAS,UAAU,MAAM;AACnC,0BAAY,SAAS,YAAY,QAAQ;AACzC,4BAAc,SAAS,cAAc,UAAU;AAC/C,gCAAkB,SAAS,kBAAkB,cAAc;AAC3D,qBAAO,kBAAkB,aACvB,SAAS,iBAAiB,aAAa;AACzC,uBAAS,SAAS,SAAS,KAAK;AAChC;AAAA,YACF;AAGA,mBAAO,0BAA0B,EAC9B,KAAK,CAAC,kBAAkB;AAEvB,kBAAI,oBAAqB;AAEzB,yBAAW,IAAI,cAAc,sBAAsB;AAAA,gBACjD,GAAG,gBAAA;AAAA,gBACH,QAAQ,uBAAA;AAAA,gBACR,aAAa;AAAA,gBACb,SAAS;AAAA,gBACT;AAAA,cAAA,CACD;AAED,mBAAK,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AAC5D,iBAAG,UAAU,IAAI,uBAAuB;AACxC,uBAAS,MAAM,EAAE;AAEjB,yBAAW,UAAU,eAAe;AAAA,YACtC,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,sBAAQ;AAAA,gBACN;AAAA,gBACA;AAAA,cAAA;AAAA,YAEJ,CAAC;AAAA,UACL;AAAA,UACA,EAAE,SAAA;AAAA,QAAS;AAAA,MAEf;AAAA,IACF;AAAA,EAAA;AAEJ,CAAC;"}
|
package/devtools-panel/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject, Injector, runInInjectionContext, DestroyRef, PLATFORM_ID, computed, effect, untracked } from "@angular/core";
|
|
2
|
-
import { QueryClient, onlineManager } from "@tanstack/query-core";
|
|
3
|
-
import { isPlatformBrowser } from "@angular/common";
|
|
4
|
-
const injectDevtoolsPanel = (injectDevtoolsPanelFn, options) => {
|
|
5
|
-
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectDevtoolsPanel);
|
|
6
|
-
const currentInjector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
7
|
-
return runInInjectionContext(currentInjector, () => {
|
|
8
|
-
const destroyRef = inject(DestroyRef);
|
|
9
|
-
const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
10
|
-
const injectedClient = inject(QueryClient, { optional: true });
|
|
11
|
-
const queryOptions = computed(injectDevtoolsPanelFn);
|
|
12
|
-
let devtools = null;
|
|
13
|
-
const destroy = () => {
|
|
14
|
-
devtools == null ? void 0 : devtools.unmount();
|
|
15
|
-
devtools = null;
|
|
16
|
-
};
|
|
17
|
-
if (!isBrowser)
|
|
18
|
-
return {
|
|
19
|
-
destroy
|
|
20
|
-
};
|
|
21
|
-
effect(() => {
|
|
22
|
-
const {
|
|
23
|
-
client = injectedClient,
|
|
24
|
-
errorTypes = [],
|
|
25
|
-
styleNonce,
|
|
26
|
-
shadowDOMTarget,
|
|
27
|
-
onClose,
|
|
28
|
-
hostElement
|
|
29
|
-
} = queryOptions();
|
|
30
|
-
untracked(() => {
|
|
31
|
-
if (!client) throw new Error("No QueryClient found");
|
|
32
|
-
if (!devtools && hostElement) {
|
|
33
|
-
import("@tanstack/query-devtools").then((queryDevtools) => {
|
|
34
|
-
devtools = new queryDevtools.TanstackQueryDevtoolsPanel({
|
|
35
|
-
client,
|
|
36
|
-
queryFlavor: "Angular Query",
|
|
37
|
-
version: "5",
|
|
38
|
-
buttonPosition: "bottom-left",
|
|
39
|
-
position: "bottom",
|
|
40
|
-
initialIsOpen: true,
|
|
41
|
-
errorTypes,
|
|
42
|
-
styleNonce,
|
|
43
|
-
shadowDOMTarget,
|
|
44
|
-
onClose,
|
|
45
|
-
onlineManager
|
|
46
|
-
});
|
|
47
|
-
devtools.mount(hostElement.nativeElement);
|
|
48
|
-
}).catch((error) => {
|
|
49
|
-
console.error(
|
|
50
|
-
"Install @tanstack/query-devtools or reinstall without --omit=optional.",
|
|
51
|
-
error
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
} else if (devtools && hostElement) {
|
|
55
|
-
devtools.setClient(client);
|
|
56
|
-
devtools.setErrorTypes(errorTypes);
|
|
57
|
-
onClose && devtools.setOnClose(onClose);
|
|
58
|
-
} else if (devtools && !hostElement) {
|
|
59
|
-
destroy();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
destroyRef.onDestroy(destroy);
|
|
64
|
-
return {
|
|
65
|
-
destroy
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
export {
|
|
70
|
-
injectDevtoolsPanel
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=inject-devtools-panel.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-devtools-panel.mjs","sources":["../../src/devtools-panel/inject-devtools-panel.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n PLATFORM_ID,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n runInInjectionContext,\n untracked,\n} from '@angular/core'\nimport { QueryClient, onlineManager } from '@tanstack/query-core'\nimport { isPlatformBrowser } from '@angular/common'\nimport type { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'\nimport type {\n DevtoolsPanelOptions,\n InjectDevtoolsPanel,\n InjectDevtoolsPanelOptions,\n} from './types'\n\n/**\n * Inject a TanStack Query devtools panel and render it in the DOM.\n *\n * Devtools panel allows programmatic control over the devtools, for example if you want to render\n * the devtools as part of your own devtools.\n *\n * Consider `withDevtools` instead if you don't need this.\n * @param injectDevtoolsPanelFn - A function that returns devtools panel options.\n * @param options - Additional configuration\n * @returns DevtoolsPanelRef\n * @see https://tanstack.com/query/v5/docs/framework/angular/devtools\n */\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = (\n injectDevtoolsPanelFn: () => DevtoolsPanelOptions,\n options?: InjectDevtoolsPanelOptions,\n) => {\n !options?.injector && assertInInjectionContext(injectDevtoolsPanel)\n const currentInjector = options?.injector ?? inject(Injector)\n\n return runInInjectionContext(currentInjector, () => {\n const destroyRef = inject(DestroyRef)\n const isBrowser = isPlatformBrowser(inject(PLATFORM_ID))\n const injectedClient = inject(QueryClient, { optional: true })\n\n const queryOptions = computed(injectDevtoolsPanelFn)\n let devtools: TanstackQueryDevtoolsPanel | null = null\n\n const destroy = () => {\n devtools?.unmount()\n devtools = null\n }\n\n if (!isBrowser)\n return {\n destroy,\n }\n\n effect(() => {\n const {\n client = injectedClient,\n errorTypes = [],\n styleNonce,\n shadowDOMTarget,\n onClose,\n hostElement,\n } = queryOptions()\n\n untracked(() => {\n if (!client) throw new Error('No QueryClient found')\n if (!devtools && hostElement) {\n import('@tanstack/query-devtools')\n .then((queryDevtools) => {\n devtools = new queryDevtools.TanstackQueryDevtoolsPanel({\n client,\n queryFlavor: 'Angular Query',\n version: '5',\n buttonPosition: 'bottom-left',\n position: 'bottom',\n initialIsOpen: true,\n errorTypes,\n styleNonce,\n shadowDOMTarget,\n onClose,\n onlineManager,\n })\n devtools.mount(hostElement.nativeElement)\n })\n .catch((error) => {\n console.error(\n 'Install @tanstack/query-devtools or reinstall without --omit=optional.',\n error,\n )\n })\n } else if (devtools && hostElement) {\n devtools.setClient(client)\n devtools.setErrorTypes(errorTypes)\n onClose && devtools.setOnClose(onClose)\n } else if (devtools && !hostElement) {\n destroy()\n }\n })\n })\n\n destroyRef.onDestroy(destroy)\n\n return {\n destroy,\n }\n })\n}\n"],"names":[],"mappings":";;;AAgCO,MAAM,sBAA2C,CACtD,uBACA,YACG;AACH,IAAC,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,mBAAkB,mCAAS,aAAY,OAAO,QAAQ;AAE5D,SAAO,sBAAsB,iBAAiB,MAAM;AAClD,UAAM,aAAa,OAAO,UAAU;AACpC,UAAM,YAAY,kBAAkB,OAAO,WAAW,CAAC;AACvD,UAAM,iBAAiB,OAAO,aAAa,EAAE,UAAU,MAAM;AAE7D,UAAM,eAAe,SAAS,qBAAqB;AACnD,QAAI,WAA8C;AAElD,UAAM,UAAU,MAAM;AACpB,2CAAU;AACV,iBAAW;AAAA,IACb;AAEA,QAAI,CAAC;AACH,aAAO;AAAA,QACL;AAAA,MAAA;AAGJ,WAAO,MAAM;AACX,YAAM;AAAA,QACJ,SAAS;AAAA,QACT,aAAa,CAAA;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA,IACE,aAAA;AAEJ,gBAAU,MAAM;AACd,YAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,sBAAsB;AACnD,YAAI,CAAC,YAAY,aAAa;AAC5B,iBAAO,0BAA0B,EAC9B,KAAK,CAAC,kBAAkB;AACvB,uBAAW,IAAI,cAAc,2BAA2B;AAAA,cACtD;AAAA,cACA,aAAa;AAAA,cACb,SAAS;AAAA,cACT,gBAAgB;AAAA,cAChB,UAAU;AAAA,cACV,eAAe;AAAA,cACf;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA,CACD;AACD,qBAAS,MAAM,YAAY,aAAa;AAAA,UAC1C,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,oBAAQ;AAAA,cACN;AAAA,cACA;AAAA,YAAA;AAAA,UAEJ,CAAC;AAAA,QACL,WAAW,YAAY,aAAa;AAClC,mBAAS,UAAU,MAAM;AACzB,mBAAS,cAAc,UAAU;AACjC,qBAAW,SAAS,WAAW,OAAO;AAAA,QACxC,WAAW,YAAY,CAAC,aAAa;AACnC,kBAAA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,eAAW,UAAU,OAAO;AAE5B,WAAO;AAAA,MACL;AAAA,IAAA;AAAA,EAEJ,CAAC;AACH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '..';
|
package/devtools-panel/stub.d.ts
DELETED
package/devtools-panel/stub.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stub.mjs","sources":["../../src/devtools-panel/stub.ts"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport type { InjectDevtoolsPanel } from './types'\n\n// Stub which replaces `injectDevtoolsPanel` in production builds\nexport const injectDevtoolsPanel: InjectDevtoolsPanel = () => ({\n destroy: noop,\n})\n"],"names":[],"mappings":";AAIO,MAAM,sBAA2C,OAAO;AAAA,EAC7D,SAAS;AACX;"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { DevtoolsErrorType } from '@tanstack/query-devtools';
|
|
2
|
-
import { ElementRef, Injector } from '@angular/core';
|
|
3
|
-
import { QueryClient } from '@tanstack/query-core';
|
|
4
|
-
export interface InjectDevtoolsPanelOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The `Injector` in which to create the devtools panel.
|
|
7
|
-
*
|
|
8
|
-
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
9
|
-
*/
|
|
10
|
-
injector?: Injector;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A devtools panel, which can be manually destroyed.
|
|
14
|
-
*/
|
|
15
|
-
export interface DevtoolsPanelRef {
|
|
16
|
-
/**
|
|
17
|
-
* Destroy the panel, removing it from the DOM and stops listening to signal changes.
|
|
18
|
-
*/
|
|
19
|
-
destroy: () => void;
|
|
20
|
-
}
|
|
21
|
-
export interface DevtoolsPanelOptions {
|
|
22
|
-
/**
|
|
23
|
-
* Custom instance of QueryClient
|
|
24
|
-
*/
|
|
25
|
-
client?: QueryClient;
|
|
26
|
-
/**
|
|
27
|
-
* Use this so you can define custom errors that can be shown in the devtools.
|
|
28
|
-
*/
|
|
29
|
-
errorTypes?: Array<DevtoolsErrorType>;
|
|
30
|
-
/**
|
|
31
|
-
* 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.
|
|
32
|
-
*/
|
|
33
|
-
styleNonce?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Use this so you can attach the devtool's styles to specific element in the DOM.
|
|
36
|
-
*/
|
|
37
|
-
shadowDOMTarget?: ShadowRoot;
|
|
38
|
-
/**
|
|
39
|
-
* Callback function that is called when the devtools panel is closed
|
|
40
|
-
*/
|
|
41
|
-
onClose?: () => void;
|
|
42
|
-
/**
|
|
43
|
-
* Element where to render the devtools panel. When set to undefined or null, the devtools panel will not be created, or destroyed if existing.
|
|
44
|
-
* If changed from undefined to a ElementRef, the devtools panel will be created.
|
|
45
|
-
*/
|
|
46
|
-
hostElement?: ElementRef;
|
|
47
|
-
}
|
|
48
|
-
export type InjectDevtoolsPanel = (injectDevtoolsPanelFn: () => DevtoolsPanelOptions, options?: InjectDevtoolsPanelOptions) => DevtoolsPanelRef;
|
package/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export * from './types.js';
|
|
3
|
-
export type { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, } from './query-options.js';
|
|
4
|
-
export { queryOptions } from './query-options.js';
|
|
5
|
-
export type { CreateMutationOptions } from './types.js';
|
|
6
|
-
export { mutationOptions } from './mutation-options.js';
|
|
7
|
-
export type { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, UnusedSkipTokenInfiniteOptions, } from './infinite-query-options.js';
|
|
8
|
-
export { infiniteQueryOptions } from './infinite-query-options.js';
|
|
9
|
-
export type { InjectInfiniteQueryOptions } from './inject-infinite-query.js';
|
|
10
|
-
export { injectInfiniteQuery } from './inject-infinite-query.js';
|
|
11
|
-
export type { InjectIsFetchingOptions } from './inject-is-fetching.js';
|
|
12
|
-
export { injectIsFetching } from './inject-is-fetching.js';
|
|
13
|
-
export type { InjectIsMutatingOptions } from './inject-is-mutating.js';
|
|
14
|
-
export { injectIsMutating } from './inject-is-mutating.js';
|
|
15
|
-
export { injectIsRestoring, provideIsRestoring } from './inject-is-restoring.js';
|
|
16
|
-
export type { InjectMutationOptions } from './inject-mutation.js';
|
|
17
|
-
export { injectMutation } from './inject-mutation.js';
|
|
18
|
-
export type { InjectMutationStateOptions } from './inject-mutation-state.js';
|
|
19
|
-
export { injectMutationState } from './inject-mutation-state.js';
|
|
20
|
-
export type { QueriesOptions, QueriesResults } from './inject-queries.js';
|
|
21
|
-
export type { InjectQueryOptions } from './inject-query.js';
|
|
22
|
-
export { injectQuery } from './inject-query.js';
|
|
23
|
-
export { injectQueryClient } from './inject-query-client.js';
|
|
24
|
-
export type { DevtoolsFeature, PersistQueryClientFeature, QueryFeature, QueryFeatures, } from './providers.js';
|
|
25
|
-
export { provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature, } from './providers.js';
|
package/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * This overload is selected when `initialData` is set.\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AA+VO,SAAS,qBAAqB,SAAkB;AACrD,SAAO;AACT;"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from "@tanstack/query-core";
|
|
2
|
-
import { assertInInjectionContext, inject, Injector, runInInjectionContext } from "@angular/core";
|
|
3
|
-
import { createBaseQuery } from "./create-base-query.mjs";
|
|
4
|
-
function injectInfiniteQuery(injectInfiniteQueryFn, options) {
|
|
5
|
-
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectInfiniteQuery);
|
|
6
|
-
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
7
|
-
return runInInjectionContext(
|
|
8
|
-
injector,
|
|
9
|
-
() => createBaseQuery(
|
|
10
|
-
injectInfiniteQueryFn,
|
|
11
|
-
InfiniteQueryObserver
|
|
12
|
-
)
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
injectInfiniteQuery
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=inject-infinite-query.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-infinite-query.mjs","sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport {\n Injector,\n assertInInjectionContext,\n inject,\n runInInjectionContext,\n} from '@angular/core'\nimport { createBaseQuery } from './create-base-query'\nimport type {\n DefaultError,\n InfiniteData,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\nexport interface InjectInfiniteQueryOptions {\n /**\n * The `Injector` in which to create the infinite query.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can\n * additively \"load more\" data onto an existing set of data, or \"infinite scroll\".\n *\n * This overload is selected when `initialData` is set on the options returned by `injectInfiniteQueryFn`,\n * so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage() && !isFetching()`.\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.fetchInfiniteQuery`.\n * @param injectInfiniteQueryFn - A function returning the {@link DefinedInitialDataInfiniteOptions} to use —\n * everything you can pass to `injectInfiniteQuery`, with `initialData` set. Similar to `computed` from\n * Angular, this function runs in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and\n * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * }))\n * }\n * ```\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): DefinedCreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a\n * unique key. Infinite queries can additively \"load more\" data onto an existing set of data, or\n * \"infinite scroll\".\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage() && !isFetching()`. This is the only overload that accepts\n * `queryFn: skipToken`, shown below.\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.fetchInfiniteQuery`.\n * @param injectInfiniteQueryFn - A function returning the {@link UndefinedInitialDataInfiniteOptions} to use\n * — everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs\n * in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and\n * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a button click:\n * ```angular-ts\n * @Component({\n * selector: 'projects-list',\n * template: `\n * <ul>\n * @for (page of projectsQuery.data()?.pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * <button\n * [disabled]=\"!projectsQuery.hasNextPage() || projectsQuery.isFetching()\"\n * (click)=\"projectsQuery.fetchNextPage()\"\n * >\n * Load More\n * </button>\n * `,\n * })\n * export class ProjectsList {\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel\n * element after the list:\n * ```angular-ts\n * @Component({\n * selector: 'projects-list',\n * template: `\n * <ul>\n * @for (page of projectsQuery.data()?.pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>\n * `,\n * })\n * export class ProjectsList {\n * readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')\n *\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n *\n * constructor() {\n * effect((onCleanup) => {\n * const sentinel = this.sentinel()?.nativeElement\n * if (\n * sentinel == null ||\n * !this.projectsQuery.hasNextPage() ||\n * this.projectsQuery.isFetching()\n * ) {\n * return\n * }\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * onCleanup(() => observer.disconnect())\n * })\n * }\n * }\n * ```\n *\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`:\n * ```angular-ts\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (postId() == null) {\n * Select a post\n * } @else if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal<string | undefined>(undefined)\n *\n * readonly commentsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['post', this.postId(), 'comments'],\n * queryFn:\n * this.postId() != null\n * ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n * }\n * ```\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the\n * `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site —\n * useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided\n * options.\n *\n * @param injectInfiniteQueryFn - A function that returns infinite query options. Similar to `computed` from\n * Angular, this function runs in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\nexport function injectInfiniteQuery(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,\n options?: InjectInfiniteQueryOptions,\n) {\n !options?.injector && assertInInjectionContext(injectInfiniteQuery)\n const injector = options?.injector ?? inject(Injector)\n return runInInjectionContext(injector, () =>\n createBaseQuery(\n injectInfiniteQueryFn,\n InfiniteQueryObserver as typeof QueryObserver,\n ),\n )\n}\n"],"names":[],"mappings":";;;AA2RO,SAAS,oBACd,uBACA,SACA;AACA,IAAC,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,SAAO;AAAA,IAAsB;AAAA,IAAU,MACrC;AAAA,MACE;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/inject-is-fetching.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject, Injector, DestroyRef, NgZone, signal } from "@angular/core";
|
|
2
|
-
import { QueryClient, notifyManager } from "@tanstack/query-core";
|
|
3
|
-
function injectIsFetching(filters, options) {
|
|
4
|
-
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectIsFetching);
|
|
5
|
-
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
6
|
-
const destroyRef = injector.get(DestroyRef);
|
|
7
|
-
const ngZone = injector.get(NgZone);
|
|
8
|
-
const queryClient = injector.get(QueryClient);
|
|
9
|
-
const cache = queryClient.getQueryCache();
|
|
10
|
-
let isFetching = queryClient.isFetching(filters);
|
|
11
|
-
const result = signal(isFetching);
|
|
12
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
13
|
-
() => cache.subscribe(
|
|
14
|
-
notifyManager.batchCalls(() => {
|
|
15
|
-
const newIsFetching = queryClient.isFetching(filters);
|
|
16
|
-
if (isFetching !== newIsFetching) {
|
|
17
|
-
isFetching = newIsFetching;
|
|
18
|
-
ngZone.run(() => {
|
|
19
|
-
result.set(isFetching);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
destroyRef.onDestroy(unsubscribe);
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
injectIsFetching
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=inject-is-fetching.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-is-fetching.mjs","sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { QueryClient, notifyManager } from '@tanstack/query-core'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\nexport interface InjectIsFetchingOptions {\n /**\n * The `Injector` in which to create the isFetching signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or fetching in the\n * background (useful for app-wide loading indicators).\n *\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param options - Additional configuration\n * @returns A `Signal` with the number of queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'posts-fetching-indicator',\n * template: `\n * @if (isFetchingPosts()) {\n * <span>Refreshing posts...</span>\n * }\n * `,\n * })\n * export class PostsFetchingIndicator {\n * // How many queries matching the posts prefix are fetching?\n * readonly isFetchingPosts = injectIsFetching({ queryKey: ['posts'] })\n * }\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```angular-ts\n * @Component({\n * selector: 'global-loading-indicator',\n * template: `\n * @if (isFetching()) {\n * <div>Queries are fetching in the background...</div>\n * }\n * `,\n * })\n * export class GlobalLoadingIndicator {\n * readonly isFetching = injectIsFetching()\n * }\n * ```\n */\nexport function injectIsFetching(\n filters?: QueryFilters,\n options?: InjectIsFetchingOptions,\n): Signal<number> {\n !options?.injector && assertInInjectionContext(injectIsFetching)\n const injector = options?.injector ?? inject(Injector)\n const destroyRef = injector.get(DestroyRef)\n const ngZone = injector.get(NgZone)\n const queryClient = injector.get(QueryClient)\n\n const cache = queryClient.getQueryCache()\n // isFetching is the prev value initialized on mount *\n let isFetching = queryClient.isFetching(filters)\n\n const result = signal(isFetching)\n\n const unsubscribe = ngZone.runOutsideAngular(() =>\n cache.subscribe(\n notifyManager.batchCalls(() => {\n const newIsFetching = queryClient.isFetching(filters)\n if (isFetching !== newIsFetching) {\n // * and update with each change\n isFetching = newIsFetching\n ngZone.run(() => {\n result.set(isFetching)\n })\n }\n }),\n ),\n )\n\n destroyRef.onDestroy(unsubscribe)\n\n return result\n}\n"],"names":[],"mappings":";;AA8DO,SAAS,iBACd,SACA,SACgB;AAChB,IAAC,mCAAS,aAAY,yBAAyB,gBAAgB;AAC/D,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,QAAM,aAAa,SAAS,IAAI,UAAU;AAC1C,QAAM,SAAS,SAAS,IAAI,MAAM;AAClC,QAAM,cAAc,SAAS,IAAI,WAAW;AAE5C,QAAM,QAAQ,YAAY,cAAA;AAE1B,MAAI,aAAa,YAAY,WAAW,OAAO;AAE/C,QAAM,SAAS,OAAO,UAAU;AAEhC,QAAM,cAAc,OAAO;AAAA,IAAkB,MAC3C,MAAM;AAAA,MACJ,cAAc,WAAW,MAAM;AAC7B,cAAM,gBAAgB,YAAY,WAAW,OAAO;AACpD,YAAI,eAAe,eAAe;AAEhC,uBAAa;AACb,iBAAO,IAAI,MAAM;AACf,mBAAO,IAAI,UAAU;AAAA,UACvB,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IAAA;AAAA,EACH;AAGF,aAAW,UAAU,WAAW;AAEhC,SAAO;AACT;"}
|