@tanstack/angular-query 0.0.0 → 5.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -36
  3. package/hydration-state-key.d.ts +4 -0
  4. package/hydration-state-key.mjs +14 -0
  5. package/hydration-state-key.mjs.map +1 -0
  6. package/index.d.ts +22 -0
  7. package/index.mjs +32 -0
  8. package/index.mjs.map +1 -0
  9. package/infinite-query-options.d.ts +216 -0
  10. package/infinite-query-options.mjs +7 -0
  11. package/infinite-query-options.mjs.map +1 -0
  12. package/inject-base-query.d.ts +5 -0
  13. package/inject-base-query.mjs +64 -0
  14. package/inject-base-query.mjs.map +1 -0
  15. package/inject-infinite-query.d.ts +67 -0
  16. package/inject-infinite-query.mjs +38 -0
  17. package/inject-infinite-query.mjs.map +1 -0
  18. package/inject-is-fetching.d.ts +11 -0
  19. package/inject-is-fetching.mjs +18 -0
  20. package/inject-is-fetching.mjs.map +1 -0
  21. package/inject-is-mutating.d.ts +11 -0
  22. package/inject-is-mutating.mjs +18 -0
  23. package/inject-is-mutating.mjs.map +1 -0
  24. package/inject-is-restoring.d.ts +13 -0
  25. package/inject-is-restoring.mjs +21 -0
  26. package/inject-is-restoring.mjs.map +1 -0
  27. package/inject-mutation-state.d.ts +16 -0
  28. package/inject-mutation-state.mjs +28 -0
  29. package/inject-mutation-state.mjs.map +1 -0
  30. package/inject-mutation.d.ts +32 -0
  31. package/inject-mutation.mjs +72 -0
  32. package/inject-mutation.mjs.map +1 -0
  33. package/inject-queries.d.ts +35 -0
  34. package/inject-queries.mjs +120 -0
  35. package/inject-queries.mjs.map +1 -0
  36. package/inject-queries.types.d.ts +109 -0
  37. package/inject-query.d.ts +127 -0
  38. package/inject-query.mjs +20 -0
  39. package/inject-query.mjs.map +1 -0
  40. package/internal.d.ts +8 -0
  41. package/internal.mjs +8 -0
  42. package/internal.mjs.map +1 -0
  43. package/mutation-options.d.ts +84 -0
  44. package/mutation-options.mjs +7 -0
  45. package/mutation-options.mjs.map +1 -0
  46. package/package.json +52 -4
  47. package/providers.d.ts +83 -0
  48. package/providers.mjs +89 -0
  49. package/providers.mjs.map +1 -0
  50. package/query-options.d.ts +208 -0
  51. package/query-options.mjs +7 -0
  52. package/query-options.mjs.map +1 -0
  53. package/query-resource.d.ts +36 -0
  54. package/query-resource.mjs +70 -0
  55. package/query-resource.mjs.map +1 -0
  56. package/schematics/collection.json +10 -0
  57. package/schematics/ng-add/index.js +96 -0
  58. package/schematics/ng-add/schema.js +2 -0
  59. package/schematics/ng-add/schema.json +17 -0
  60. package/schematics/package.json +3 -0
  61. package/types.d.ts +164 -0
  62. package/utils/inject-external-store.d.ts +33 -0
  63. package/utils/inject-external-store.mjs +41 -0
  64. package/utils/inject-external-store.mjs.map +1 -0
  65. package/utils/inject-pending-tasks-lifecycle.d.ts +6 -0
  66. package/utils/inject-pending-tasks-lifecycle.mjs +31 -0
  67. package/utils/inject-pending-tasks-lifecycle.mjs.map +1 -0
  68. package/utils/inject-query-zone.d.ts +2 -0
  69. package/utils/inject-query-zone.mjs +9 -0
  70. package/utils/inject-query-zone.mjs.map +1 -0
  71. package/utils/resource-types.d.ts +8 -0
  72. package/utils/result-fields.d.ts +80 -0
  73. package/utils/result-fields.mjs +65 -0
  74. package/utils/result-fields.mjs.map +1 -0
  75. package/utils/signal-proxy.d.ts +20 -0
  76. package/utils/signal-proxy.mjs +12 -0
  77. package/utils/signal-proxy.mjs.map +1 -0
package/types.d.ts ADDED
@@ -0,0 +1,164 @@
1
+ import { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, Override, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
2
+ import { Signal } from '@angular/core';
3
+ import { MapToSignals } from './utils/signal-proxy.js';
4
+ import { InfiniteQueryResultFields, MutationResultFields, QueryResultFields } from './utils/result-fields.js';
5
+ type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>;
6
+ export type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'>;
7
+ type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
8
+ status: TStatus;
9
+ }>;
10
+ type CreateStatusBasedDefinedQueryResult<TStatus extends DefinedQueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<DefinedQueryObserverResult<TData, TError>, {
11
+ status: TStatus;
12
+ }>;
13
+ type CreateStatusBasedInfiniteQueryResult<TStatus extends InfiniteQueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<InfiniteQueryObserverResult<TData, TError>, {
14
+ status: TStatus;
15
+ }>;
16
+ type CreateStatusBasedDefinedInfiniteQueryResult<TStatus extends DefinedInfiniteQueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<DefinedInfiniteQueryObserverResult<TData, TError>, {
17
+ status: TStatus;
18
+ }>;
19
+ export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
20
+ isSuccess: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>>;
21
+ isError: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>>;
22
+ isPending: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>>;
23
+ }
24
+ export interface DefinedQueryNarrowing<TData = unknown, TError = DefaultError> {
25
+ isSuccess: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'success', TData, TError>>>;
26
+ isError: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'error', TData, TError>>>;
27
+ isPending: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is never>;
28
+ }
29
+ export interface BaseInfiniteQueryNarrowing<TData = unknown, TError = DefaultError> {
30
+ isSuccess: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'success', TData, TError>>>;
31
+ isError: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'error', TData, TError>>>;
32
+ isPending: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'pending', TData, TError>>>;
33
+ }
34
+ export interface DefinedInfiniteQueryNarrowing<TData = unknown, TError = DefaultError> {
35
+ isSuccess: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is DefinedCreateInfiniteQueryResult<TData, TError, CreateStatusBasedDefinedInfiniteQueryResult<'success', TData, TError>>>;
36
+ isError: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is DefinedCreateInfiniteQueryResult<TData, TError, CreateStatusBasedDefinedInfiniteQueryResult<'error', TData, TError>>>;
37
+ isPending: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is never>;
38
+ }
39
+ export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'> {
40
+ }
41
+ /**
42
+ * The result of `injectQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
43
+ * `pending`. Same shape as {@link QueryObserverResult} from `@tanstack/query-core`, but value fields (like
44
+ * `data`, `error`, `status`) are exposed as a `Signal` — read them with `query.data()`, not `query.data` —
45
+ * while function fields (like `refetch`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`
46
+ * are {@link BaseQueryNarrowing} type-guard methods rather than plain booleans.
47
+ * `injectInfiniteQuery` returns {@link CreateInfiniteQueryResult} instead.
48
+ *
49
+ * @template TData - The type `data` ends up as after `select` runs.
50
+ * @template TError - The type of errors your `queryFn` may throw.
51
+ */
52
+ export type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState extends QueryObserverResult<TData, TError> = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>, QueryResultFields>;
53
+ /**
54
+ * The result of `injectQuery`. Same as {@link CreateBaseQueryResult}.
55
+ *
56
+ * @template TData - The type `data` ends up as after `select` runs.
57
+ * @template TError - The type of errors your `queryFn` may throw.
58
+ */
59
+ export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
60
+ /**
61
+ * The result of `injectQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
62
+ * {@link DefinedQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
63
+ * `Signal` while function fields are called directly, unchanged.
64
+ *
65
+ * @template TData - The type `data` ends up as after `select` runs.
66
+ * @template TError - The type of errors your `queryFn` may throw.
67
+ */
68
+ export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TState extends DefinedQueryObserverResult<TData, TError> = DefinedQueryObserverResult<TData, TError>> = DefinedQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof DefinedQueryNarrowing, 'safely'>, QueryResultFields>;
69
+ /**
70
+ * The result of `injectInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the
71
+ * query is `pending`. Same shape as {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, but
72
+ * value fields are exposed as a `Signal` while function fields (like `fetchNextPage`) are called directly,
73
+ * unchanged.
74
+ *
75
+ * @template TData - The type `data` ends up as after `select` runs.
76
+ * @template TError - The type of errors your `queryFn` may throw.
77
+ */
78
+ export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TState extends InfiniteQueryObserverResult<TData, TError> = InfiniteQueryObserverResult<TData, TError>> = BaseInfiniteQueryNarrowing<TData, TError> & MapToSignals<TState, InfiniteQueryResultFields>;
79
+ /**
80
+ * The result of `injectInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
81
+ * {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
82
+ * `Signal` while function fields are called directly, unchanged.
83
+ *
84
+ * @template TData - The type `data` ends up as after `select` runs.
85
+ * @template TError - The type of errors your `queryFn` may throw.
86
+ */
87
+ export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver extends DefinedInfiniteQueryObserverResult<TData, TError> = DefinedInfiniteQueryObserverResult<TData, TError>> = DefinedInfiniteQueryNarrowing<TData, TError> & MapToSignals<TDefinedInfiniteQueryObserver, InfiniteQueryResultFields>;
88
+ /**
89
+ * The options accepted by `injectMutation`. Same as {@link MutationObserverOptions} from
90
+ * `@tanstack/query-core`, minus the internal `_defaulted` flag.
91
+ *
92
+ * @template TData - The type your mutation function resolves to.
93
+ * @template TError - The type of errors your mutation function may throw.
94
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
95
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
96
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
97
+ */
98
+ export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>, '_defaulted' | 'throwOnError'> {
99
+ }
100
+ /**
101
+ * The type of `mutate`, as returned by `injectMutation`. Forwards the variables (and an optional per-call
102
+ * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
103
+ * through the mutation result, not thrown.
104
+ *
105
+ * @template TData - The type your mutation function resolves to.
106
+ * @template TError - The type of errors your mutation function may throw.
107
+ * @template TVariables - The type of the variable passed to `mutate`.
108
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
109
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
110
+ */
111
+ export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TOnMutateResult>>) => void;
112
+ /**
113
+ * The type of `mutateAsync`, as returned by `injectMutation`. Similar to {@link CreateMutateFunction}, but
114
+ * returns a promise which can be awaited.
115
+ *
116
+ * @template TData - The type your mutation function resolves to.
117
+ * @template TError - The type of errors your mutation function may throw.
118
+ * @template TVariables - The type of the variable passed to `mutateAsync`.
119
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
120
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
121
+ */
122
+ export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MutateFunction<TData, TError, TVariables, TOnMutateResult>;
123
+ /**
124
+ * The pre-`Signal` shape {@link CreateMutationResult} is built from — not what `injectMutation` actually
125
+ * returns. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with `mutate` narrowed to the
126
+ * fire-and-forget {@link CreateMutateFunction} signature, plus the added `mutateAsync`.
127
+ *
128
+ * @template TData - The type your mutation function resolves to.
129
+ * @template TError - The type of errors your mutation function may throw.
130
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
131
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
132
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
133
+ */
134
+ export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>, {
135
+ mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>;
136
+ }> & {
137
+ /**
138
+ * Similar to `mutate`, but returns a promise which can be awaited.
139
+ */
140
+ mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult>;
141
+ };
142
+ type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TOnMutateResult>, {
143
+ status: TStatus;
144
+ }>;
145
+ export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
146
+ isSuccess: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TOnMutateResult>>>;
147
+ isError: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TOnMutateResult>>>;
148
+ isPending: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TOnMutateResult>>>;
149
+ isIdle: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>) => this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TOnMutateResult>>>;
150
+ }
151
+ /**
152
+ * The result of `injectMutation`. Based on {@link CreateBaseMutationResult}, but value fields are exposed as
153
+ * a `Signal` — read them with `mutation.data()`, not `mutation.data` — while function fields (`mutate`,
154
+ * `mutateAsync`, `reset`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`/`isIdle` are
155
+ * {@link BaseMutationNarrowing} type-guard methods rather than plain booleans.
156
+ *
157
+ * @template TData - The type your mutation function resolves to.
158
+ * @template TError - The type of errors your mutation function may throw.
159
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
160
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
161
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
162
+ */
163
+ export type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown, TState = CreateStatusBasedMutationResult<CreateBaseMutationResult['status'], TData, TError, TVariables, TOnMutateResult>> = BaseMutationNarrowing<TData, TError, TVariables, TOnMutateResult> & MapToSignals<OmitKeyof<TState, keyof BaseMutationNarrowing, 'safely'>, MutationResultFields>;
164
+ export {};
@@ -0,0 +1,33 @@
1
+ import { Signal, ValueEqualityFn } from '@angular/core';
2
+ interface ExternalBinding<T> {
3
+ /** Synchronous snapshot. Angular signals read here are tracked dependencies. */
4
+ readonly getSnapshot: () => T;
5
+ /** Omit to pause observation; changing eligibility requires a new descriptor. */
6
+ readonly subscribe?: ((notify: () => void) => () => void) | undefined;
7
+ }
8
+ interface ExternalStoreOptions<T> {
9
+ /** Snapshot equality, defaulting to Object.is. Does not control connection identity. */
10
+ readonly equal?: ValueEqualityFn<T> | undefined;
11
+ }
12
+ /**
13
+ * Creates a readonly Angular signal backed by a synchronous external store.
14
+ *
15
+ * Store access, subscription setup, and cleanup run outside NgZone so background
16
+ * timers do not hold Angular stability open.
17
+ *
18
+ * Reads evaluate snapshots without subscribing. An effect owns the subscription
19
+ * and invalidates the snapshot after setup, closing the gap between an early
20
+ * read and connection. The next read recomputes the snapshot; equality prevents
21
+ * unchanged values from propagating. Unread snapshots stay lazy.
22
+ *
23
+ * Notifications invalidate snapshots synchronously once connected. Snapshot-only
24
+ * dependencies do not reinstall the subscription. Subscription setup and cleanup
25
+ * may read the returned signal; factories and snapshot readers must not recurse.
26
+ *
27
+ * Only factory/snapshot errors are exposed on reads. Subscription and cleanup
28
+ * errors follow Angular's normal effect error handling; the helper does not store
29
+ * them or implement retries. Destruction stops observation without changing the
30
+ * cached snapshot.
31
+ */
32
+ export declare function injectExternalStore<T>(binding: () => ExternalBinding<T>, options?: ExternalStoreOptions<T>): Signal<T>;
33
+ export {};
@@ -0,0 +1,41 @@
1
+ import { assertInInjectionContext, inject, DestroyRef, signal, computed, effect, untracked } from "@angular/core";
2
+ import { injectQueryZone } from "./inject-query-zone.mjs";
3
+ function injectExternalStore(binding, options) {
4
+ if (typeof ngDevMode === "undefined" || ngDevMode) {
5
+ assertInInjectionContext(injectExternalStore);
6
+ }
7
+ const owner = inject(DestroyRef);
8
+ const outsideZone = injectQueryZone();
9
+ const revision = signal(0);
10
+ const requested = computed(() => outsideZone(binding));
11
+ const invalidate = () => untracked(() => revision.update((n) => n + 1));
12
+ effect((onCleanup) => {
13
+ if (owner.destroyed) return;
14
+ const current = requested();
15
+ outsideZone(
16
+ () => untracked(() => {
17
+ var _a;
18
+ try {
19
+ const unsubscribe = (_a = current.subscribe) == null ? void 0 : _a.call(current, invalidate);
20
+ if (unsubscribe) {
21
+ if (owner.destroyed) unsubscribe();
22
+ else onCleanup(() => outsideZone(unsubscribe));
23
+ }
24
+ } finally {
25
+ invalidate();
26
+ }
27
+ })
28
+ );
29
+ });
30
+ return computed(
31
+ () => {
32
+ revision();
33
+ return outsideZone(() => requested().getSnapshot());
34
+ },
35
+ (options == null ? void 0 : options.equal) ? { equal: options.equal } : void 0
36
+ );
37
+ }
38
+ export {
39
+ injectExternalStore
40
+ };
41
+ //# sourceMappingURL=inject-external-store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-external-store.mjs","sources":["../../src/utils/inject-external-store.ts"],"sourcesContent":["import {\n DestroyRef,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport { injectQueryZone } from './inject-query-zone'\nimport type { Signal, ValueEqualityFn } from '@angular/core'\n\ninterface ExternalBinding<T> {\n /** Synchronous snapshot. Angular signals read here are tracked dependencies. */\n readonly getSnapshot: () => T\n /** Omit to pause observation; changing eligibility requires a new descriptor. */\n readonly subscribe?: ((notify: () => void) => () => void) | undefined\n}\n\ninterface ExternalStoreOptions<T> {\n /** Snapshot equality, defaulting to Object.is. Does not control connection identity. */\n readonly equal?: ValueEqualityFn<T> | undefined\n}\n\n/**\n * Creates a readonly Angular signal backed by a synchronous external store.\n *\n * Store access, subscription setup, and cleanup run outside NgZone so background\n * timers do not hold Angular stability open.\n *\n * Reads evaluate snapshots without subscribing. An effect owns the subscription\n * and invalidates the snapshot after setup, closing the gap between an early\n * read and connection. The next read recomputes the snapshot; equality prevents\n * unchanged values from propagating. Unread snapshots stay lazy.\n *\n * Notifications invalidate snapshots synchronously once connected. Snapshot-only\n * dependencies do not reinstall the subscription. Subscription setup and cleanup\n * may read the returned signal; factories and snapshot readers must not recurse.\n *\n * Only factory/snapshot errors are exposed on reads. Subscription and cleanup\n * errors follow Angular's normal effect error handling; the helper does not store\n * them or implement retries. Destruction stops observation without changing the\n * cached snapshot.\n */\nexport function injectExternalStore<T>(\n binding: () => ExternalBinding<T>,\n options?: ExternalStoreOptions<T>,\n): Signal<T> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectExternalStore)\n }\n const owner = inject(DestroyRef)\n const outsideZone = injectQueryZone()\n const revision = signal(0)\n const requested = computed(() => outsideZone(binding))\n const invalidate = () => untracked(() => revision.update((n) => n + 1))\n\n effect((onCleanup) => {\n // The previous subscription's cleanup may have destroyed the owner.\n if (owner.destroyed) return\n const current = requested()\n outsideZone(() =>\n untracked(() => {\n try {\n const unsubscribe = current.subscribe?.(invalidate)\n if (unsubscribe) {\n // subscribe() can trigger component/injector destruction before returning.\n // Registering cleanup afterward misses that destruction.\n if (owner.destroyed) unsubscribe()\n else onCleanup(() => outsideZone(unsubscribe))\n }\n } finally {\n // Invalidate after subscribing so an early cached snapshot cannot miss\n // changes before or during setup. Do not eagerly read the snapshot.\n invalidate()\n }\n }),\n )\n })\n\n return computed(\n () => {\n revision()\n return outsideZone(() => requested().getSnapshot())\n },\n options?.equal ? { equal: options.equal } : undefined,\n )\n}\n"],"names":[],"mappings":";;AA4CO,SAAS,oBACd,SACA,SACW;AACX,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,mBAAmB;AAAA,EAC9C;AACA,QAAM,QAAQ,OAAO,UAAU;AAC/B,QAAM,cAAc,gBAAA;AACpB,QAAM,WAAW,OAAO,CAAC;AACzB,QAAM,YAAY,SAAS,MAAM,YAAY,OAAO,CAAC;AACrD,QAAM,aAAa,MAAM,UAAU,MAAM,SAAS,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;AAEtE,SAAO,CAAC,cAAc;AAEpB,QAAI,MAAM,UAAW;AACrB,UAAM,UAAU,UAAA;AAChB;AAAA,MAAY,MACV,UAAU,MAAM;;AACd,YAAI;AACF,gBAAM,eAAc,aAAQ,cAAR,iCAAoB;AACxC,cAAI,aAAa;AAGf,gBAAI,MAAM,UAAW,aAAA;AAAA,gBAChB,WAAU,MAAM,YAAY,WAAW,CAAC;AAAA,UAC/C;AAAA,QACF,UAAA;AAGE,qBAAA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IAAA;AAAA,EAEL,CAAC;AAED,SAAO;AAAA,IACL,MAAM;AACJ,eAAA;AACA,aAAO,YAAY,MAAM,UAAA,EAAY,aAAa;AAAA,IACpD;AAAA,KACA,mCAAS,SAAQ,EAAE,OAAO,QAAQ,UAAU;AAAA,EAAA;AAEhD;"}
@@ -0,0 +1,6 @@
1
+ export interface QueryLifecycle {
2
+ readonly destroyed: boolean;
3
+ setPending: (pending: boolean) => void;
4
+ }
5
+ /** Tracks pending work for the lifetime of the current injection context. */
6
+ export declare function injectPendingTasksLifecycle(): QueryLifecycle;
@@ -0,0 +1,31 @@
1
+ import { inject, DestroyRef, PendingTasks, NgZone } from "@angular/core";
2
+ function injectPendingTasksLifecycle() {
3
+ const destroyRef = inject(DestroyRef);
4
+ const pendingTasks = inject(PendingTasks);
5
+ const ngZone = inject(NgZone);
6
+ let taskCleanup;
7
+ const lifecycle = {
8
+ get destroyed() {
9
+ return destroyRef.destroyed;
10
+ },
11
+ setPending(pending) {
12
+ if (pending) {
13
+ if (!destroyRef.destroyed && !taskCleanup) {
14
+ taskCleanup = pendingTasks.add();
15
+ }
16
+ return;
17
+ }
18
+ const cleanup = taskCleanup;
19
+ taskCleanup = void 0;
20
+ if (cleanup) ngZone.run(cleanup);
21
+ }
22
+ };
23
+ destroyRef.onDestroy(() => {
24
+ lifecycle.setPending(false);
25
+ });
26
+ return lifecycle;
27
+ }
28
+ export {
29
+ injectPendingTasksLifecycle
30
+ };
31
+ //# sourceMappingURL=inject-pending-tasks-lifecycle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-pending-tasks-lifecycle.mjs","sources":["../../src/utils/inject-pending-tasks-lifecycle.ts"],"sourcesContent":["import { DestroyRef, NgZone, PendingTasks, inject } from '@angular/core'\n\nexport interface QueryLifecycle {\n readonly destroyed: boolean\n setPending: (pending: boolean) => void\n}\n\n/** Tracks pending work for the lifetime of the current injection context. */\nexport function injectPendingTasksLifecycle(): QueryLifecycle {\n const destroyRef = inject(DestroyRef)\n const pendingTasks = inject(PendingTasks)\n const ngZone = inject(NgZone)\n let taskCleanup: (() => void) | undefined\n\n const lifecycle: QueryLifecycle = {\n get destroyed() {\n return destroyRef.destroyed\n },\n setPending(pending) {\n if (pending) {\n if (!destroyRef.destroyed && !taskCleanup) {\n taskCleanup = pendingTasks.add()\n }\n return\n }\n\n const cleanup = taskCleanup\n taskCleanup = undefined\n // Enter NgZone while our task is still held to avoid transient stability\n // before dependent queries are scheduled.\n // In zoneless apps, NgZone.run simply invokes the cleanup.\n if (cleanup) ngZone.run(cleanup)\n },\n }\n\n destroyRef.onDestroy(() => {\n lifecycle.setPending(false)\n })\n\n return lifecycle\n}\n"],"names":[],"mappings":";AAQO,SAAS,8BAA8C;AAC5D,QAAM,aAAa,OAAO,UAAU;AACpC,QAAM,eAAe,OAAO,YAAY;AACxC,QAAM,SAAS,OAAO,MAAM;AAC5B,MAAI;AAEJ,QAAM,YAA4B;AAAA,IAChC,IAAI,YAAY;AACd,aAAO,WAAW;AAAA,IACpB;AAAA,IACA,WAAW,SAAS;AAClB,UAAI,SAAS;AACX,YAAI,CAAC,WAAW,aAAa,CAAC,aAAa;AACzC,wBAAc,aAAa,IAAA;AAAA,QAC7B;AACA;AAAA,MACF;AAEA,YAAM,UAAU;AAChB,oBAAc;AAId,UAAI,QAAS,QAAO,IAAI,OAAO;AAAA,IACjC;AAAA,EAAA;AAGF,aAAW,UAAU,MAAM;AACzB,cAAU,WAAW,KAAK;AAAA,EAC5B,CAAC;AAED,SAAO;AACT;"}
@@ -0,0 +1,2 @@
1
+ /** Keep Query's background timers out of Angular's stability tracking. */
2
+ export declare function injectQueryZone(): <T>(fn: () => T) => T;
@@ -0,0 +1,9 @@
1
+ import { inject, NgZone } from "@angular/core";
2
+ function injectQueryZone() {
3
+ const ngZone = inject(NgZone);
4
+ return (fn) => ngZone.runOutsideAngular(fn);
5
+ }
6
+ export {
7
+ injectQueryZone
8
+ };
9
+ //# sourceMappingURL=inject-query-zone.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-query-zone.mjs","sources":["../../src/utils/inject-query-zone.ts"],"sourcesContent":["import { NgZone, inject } from '@angular/core'\n\n/** Keep Query's background timers out of Angular's stability tracking. */\nexport function injectQueryZone() {\n const ngZone = inject(NgZone)\n return <T>(fn: () => T): T => ngZone.runOutsideAngular(fn)\n}\n"],"names":[],"mappings":";AAGO,SAAS,kBAAkB;AAChC,QAAM,SAAS,OAAO,MAAM;AAC5B,SAAO,CAAI,OAAmB,OAAO,kBAAkB,EAAE;AAC3D;"}
@@ -0,0 +1,8 @@
1
+ import { ResourceStatus } from '@angular/core';
2
+ export type ResourceSnapshot<T> = {
3
+ readonly status: 'error';
4
+ readonly error: Error;
5
+ } | {
6
+ readonly status: Exclude<ResourceStatus, 'error'>;
7
+ readonly value: T;
8
+ };
@@ -0,0 +1,80 @@
1
+ declare const queryFields: {
2
+ data: true;
3
+ dataUpdatedAt: true;
4
+ error: true;
5
+ errorUpdatedAt: true;
6
+ failureCount: true;
7
+ failureReason: true;
8
+ errorUpdateCount: true;
9
+ isError: true;
10
+ isFetched: true;
11
+ isFetchedAfterMount: true;
12
+ isFetching: true;
13
+ isLoading: true;
14
+ isPending: true;
15
+ isLoadingError: true;
16
+ isInitialLoading: true;
17
+ isPaused: true;
18
+ isPlaceholderData: true;
19
+ isRefetchError: true;
20
+ isRefetching: true;
21
+ isStale: true;
22
+ isSuccess: true;
23
+ isEnabled: true;
24
+ status: true;
25
+ fetchStatus: true;
26
+ };
27
+ declare const infiniteQueryFields: {
28
+ hasNextPage: true;
29
+ hasPreviousPage: true;
30
+ isFetchNextPageError: true;
31
+ isFetchingNextPage: true;
32
+ isFetchPreviousPageError: true;
33
+ isFetchingPreviousPage: true;
34
+ data: true;
35
+ dataUpdatedAt: true;
36
+ error: true;
37
+ errorUpdatedAt: true;
38
+ failureCount: true;
39
+ failureReason: true;
40
+ errorUpdateCount: true;
41
+ isError: true;
42
+ isFetched: true;
43
+ isFetchedAfterMount: true;
44
+ isFetching: true;
45
+ isLoading: true;
46
+ isPending: true;
47
+ isLoadingError: true;
48
+ isInitialLoading: true;
49
+ isPaused: true;
50
+ isPlaceholderData: true;
51
+ isRefetchError: true;
52
+ isRefetching: true;
53
+ isStale: true;
54
+ isSuccess: true;
55
+ isEnabled: true;
56
+ status: true;
57
+ fetchStatus: true;
58
+ };
59
+ declare const mutationFields: {
60
+ context: true;
61
+ data: true;
62
+ error: true;
63
+ failureCount: true;
64
+ failureReason: true;
65
+ isPaused: true;
66
+ status: true;
67
+ variables: true;
68
+ submittedAt: true;
69
+ isError: true;
70
+ isIdle: true;
71
+ isPending: true;
72
+ isSuccess: true;
73
+ };
74
+ export declare const queryResultFields: Array<keyof typeof queryFields>;
75
+ export type QueryResultFields = (typeof queryResultFields)[number];
76
+ export declare const infiniteQueryResultFields: Array<keyof typeof infiniteQueryFields>;
77
+ export type InfiniteQueryResultFields = (typeof infiniteQueryResultFields)[number];
78
+ export declare const mutationResultFields: Array<keyof typeof mutationFields>;
79
+ export type MutationResultFields = (typeof mutationResultFields)[number];
80
+ export {};
@@ -0,0 +1,65 @@
1
+ const queryFields = {
2
+ data: true,
3
+ dataUpdatedAt: true,
4
+ error: true,
5
+ errorUpdatedAt: true,
6
+ failureCount: true,
7
+ failureReason: true,
8
+ errorUpdateCount: true,
9
+ isError: true,
10
+ isFetched: true,
11
+ isFetchedAfterMount: true,
12
+ isFetching: true,
13
+ isLoading: true,
14
+ isPending: true,
15
+ isLoadingError: true,
16
+ isInitialLoading: true,
17
+ isPaused: true,
18
+ isPlaceholderData: true,
19
+ isRefetchError: true,
20
+ isRefetching: true,
21
+ isStale: true,
22
+ isSuccess: true,
23
+ isEnabled: true,
24
+ status: true,
25
+ fetchStatus: true
26
+ };
27
+ const infiniteQueryFields = {
28
+ ...queryFields,
29
+ hasNextPage: true,
30
+ hasPreviousPage: true,
31
+ isFetchNextPageError: true,
32
+ isFetchingNextPage: true,
33
+ isFetchPreviousPageError: true,
34
+ isFetchingPreviousPage: true
35
+ };
36
+ const mutationFields = {
37
+ context: true,
38
+ data: true,
39
+ error: true,
40
+ failureCount: true,
41
+ failureReason: true,
42
+ isPaused: true,
43
+ status: true,
44
+ variables: true,
45
+ submittedAt: true,
46
+ isError: true,
47
+ isIdle: true,
48
+ isPending: true,
49
+ isSuccess: true
50
+ };
51
+ const queryResultFields = /* @__PURE__ */ Object.keys(
52
+ queryFields
53
+ );
54
+ const infiniteQueryResultFields = /* @__PURE__ */ Object.keys(
55
+ infiniteQueryFields
56
+ );
57
+ const mutationResultFields = /* @__PURE__ */ Object.keys(
58
+ mutationFields
59
+ );
60
+ export {
61
+ infiniteQueryResultFields,
62
+ mutationResultFields,
63
+ queryResultFields
64
+ };
65
+ //# sourceMappingURL=result-fields.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-fields.mjs","sources":["../../src/utils/result-fields.ts"],"sourcesContent":["import type {\n InfiniteQueryObserverResult,\n MutationObserverResult,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { MethodKeys } from './signal-proxy'\n\ntype Fields<T> = { [K in Exclude<keyof T, MethodKeys<T>>]: true }\n\n// Exhaustive maps keep the field surface aligned with query-core at compile time.\nconst queryFields = {\n data: true,\n dataUpdatedAt: true,\n error: true,\n errorUpdatedAt: true,\n failureCount: true,\n failureReason: true,\n errorUpdateCount: true,\n isError: true,\n isFetched: true,\n isFetchedAfterMount: true,\n isFetching: true,\n isLoading: true,\n isPending: true,\n isLoadingError: true,\n isInitialLoading: true,\n isPaused: true,\n isPlaceholderData: true,\n isRefetchError: true,\n isRefetching: true,\n isStale: true,\n isSuccess: true,\n isEnabled: true,\n status: true,\n fetchStatus: true,\n} satisfies Fields<QueryObserverResult>\n\nconst infiniteQueryFields = {\n ...queryFields,\n hasNextPage: true,\n hasPreviousPage: true,\n isFetchNextPageError: true,\n isFetchingNextPage: true,\n isFetchPreviousPageError: true,\n isFetchingPreviousPage: true,\n} satisfies Fields<InfiniteQueryObserverResult>\n\nconst mutationFields = {\n context: true,\n data: true,\n error: true,\n failureCount: true,\n failureReason: true,\n isPaused: true,\n status: true,\n variables: true,\n submittedAt: true,\n isError: true,\n isIdle: true,\n isPending: true,\n isSuccess: true,\n} satisfies Fields<MutationObserverResult>\n\nexport const queryResultFields = /* @__PURE__ */ Object.keys(\n queryFields,\n) as Array<keyof typeof queryFields>\nexport type QueryResultFields = (typeof queryResultFields)[number]\n\nexport const infiniteQueryResultFields = /* @__PURE__ */ Object.keys(\n infiniteQueryFields,\n) as Array<keyof typeof infiniteQueryFields>\nexport type InfiniteQueryResultFields =\n (typeof infiniteQueryResultFields)[number]\n\nexport const mutationResultFields = /* @__PURE__ */ Object.keys(\n mutationFields,\n) as Array<keyof typeof mutationFields>\nexport type MutationResultFields = (typeof mutationResultFields)[number]\n"],"names":[],"mappings":"AAUA,MAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,eAAe;AAAA,EACf,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,SAAS;AAAA,EACT,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,aAAa;AACf;AAEA,MAAM,sBAAsB;AAAA,EAC1B,GAAG;AAAA,EACH,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EACpB,0BAA0B;AAAA,EAC1B,wBAAwB;AAC1B;AAEA,MAAM,iBAAiB;AAAA,EACrB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,aAAa;AAAA,EACb,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,WAAW;AACb;AAEO,MAAM,oBAAoC,uBAAO;AAAA,EACtD;AACF;AAGO,MAAM,4BAA4C,uBAAO;AAAA,EAC9D;AACF;AAIO,MAAM,uBAAuC,uBAAO;AAAA,EACzD;AACF;"}
@@ -0,0 +1,20 @@
1
+ import { Signal } from '@angular/core';
2
+ export type MethodKeys<T> = {
3
+ [K in keyof T]: T[K] extends (...args: Array<any>) => any ? K : never;
4
+ }[keyof T];
5
+ export type MapToSignals<T, TSignalFields extends keyof any = never> = {
6
+ [K in keyof T as K extends TSignalFields ? K : never]: Signal<T[K]>;
7
+ } & {
8
+ [K in keyof T as K extends TSignalFields ? never : K]: T[K];
9
+ };
10
+ /**
11
+ * Maps known result fields to lazy computed signals on an ordinary object.
12
+ * Creating or enumerating the fields never evaluates the source. Imperative
13
+ * methods are defined by each adapter, outside this mapping.
14
+ * @param inputSignal - The source snapshot.
15
+ * @param fields - The fields exposed as signals.
16
+ * @returns An object containing one stable signal per field.
17
+ */
18
+ export declare function signalProxy<T, TField extends keyof T>(inputSignal: Signal<T>, fields: ReadonlyArray<TField>): {
19
+ [P in TField]: Signal<T[P]>;
20
+ };
@@ -0,0 +1,12 @@
1
+ import { computed } from "@angular/core";
2
+ function signalProxy(inputSignal, fields) {
3
+ const result = {};
4
+ for (const field of fields) {
5
+ result[field] = computed(() => inputSignal()[field]);
6
+ }
7
+ return result;
8
+ }
9
+ export {
10
+ signalProxy
11
+ };
12
+ //# sourceMappingURL=signal-proxy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-proxy.mjs","sources":["../../src/utils/signal-proxy.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\nexport type MethodKeys<T> = {\n [K in keyof T]: T[K] extends (...args: Array<any>) => any ? K : never\n}[keyof T]\n\nexport type MapToSignals<T, TSignalFields extends keyof any = never> = {\n [K in keyof T as K extends TSignalFields ? K : never]: Signal<T[K]>\n} & {\n [K in keyof T as K extends TSignalFields ? never : K]: T[K]\n}\n\n/**\n * Maps known result fields to lazy computed signals on an ordinary object.\n * Creating or enumerating the fields never evaluates the source. Imperative\n * methods are defined by each adapter, outside this mapping.\n * @param inputSignal - The source snapshot.\n * @param fields - The fields exposed as signals.\n * @returns An object containing one stable signal per field.\n */\nexport function signalProxy<T, TField extends keyof T>(\n inputSignal: Signal<T>,\n fields: ReadonlyArray<TField>,\n): { [P in TField]: Signal<T[P]> } {\n const result = {} as { [P in TField]: Signal<T[P]> }\n for (const field of fields) {\n result[field] = computed(() => inputSignal()[field])\n }\n return result\n}\n"],"names":[],"mappings":";AAqBO,SAAS,YACd,aACA,QACiC;AACjC,QAAM,SAAS,CAAA;AACf,aAAW,SAAS,QAAQ;AAC1B,WAAO,KAAK,IAAI,SAAS,MAAM,YAAA,EAAc,KAAK,CAAC;AAAA,EACrD;AACA,SAAO;AACT;"}