@ic-reactor/react 3.13.0 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +234 -787
  2. package/dist/index.d.ts +259 -16
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +470 -23
  5. package/dist/index.js.map +1 -1
  6. package/llms.txt +80 -278
  7. package/package.json +11 -39
  8. package/src/index.tsx +611 -0
  9. package/dist/auth/auth-client-compat.d.ts +0 -122
  10. package/dist/auth/auth-client-compat.d.ts.map +0 -1
  11. package/dist/auth/auth-client-compat.js +0 -162
  12. package/dist/auth/auth-client-compat.js.map +0 -1
  13. package/dist/auth/authentication-manager.d.ts +0 -405
  14. package/dist/auth/authentication-manager.d.ts.map +0 -1
  15. package/dist/auth/authentication-manager.js +0 -1537
  16. package/dist/auth/authentication-manager.js.map +0 -1
  17. package/dist/auth/constants.d.ts +0 -24
  18. package/dist/auth/constants.d.ts.map +0 -1
  19. package/dist/auth/constants.js +0 -24
  20. package/dist/auth/constants.js.map +0 -1
  21. package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
  22. package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
  23. package/dist/auth/createIdentityAttributeHooks.js +0 -122
  24. package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
  25. package/dist/auth/identity-attributes-manager.d.ts +0 -27
  26. package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
  27. package/dist/auth/identity-attributes-manager.js +0 -191
  28. package/dist/auth/identity-attributes-manager.js.map +0 -1
  29. package/dist/auth/identity-attributes.d.ts +0 -19
  30. package/dist/auth/identity-attributes.d.ts.map +0 -1
  31. package/dist/auth/identity-attributes.js +0 -227
  32. package/dist/auth/identity-attributes.js.map +0 -1
  33. package/dist/auth/index.d.ts +0 -8
  34. package/dist/auth/index.d.ts.map +0 -1
  35. package/dist/auth/index.js +0 -8
  36. package/dist/auth/index.js.map +0 -1
  37. package/dist/auth/local-ii-probe.d.ts +0 -57
  38. package/dist/auth/local-ii-probe.d.ts.map +0 -1
  39. package/dist/auth/local-ii-probe.js +0 -121
  40. package/dist/auth/local-ii-probe.js.map +0 -1
  41. package/dist/auth/types.d.ts +0 -222
  42. package/dist/auth/types.d.ts.map +0 -1
  43. package/dist/auth/types.js +0 -2
  44. package/dist/auth/types.js.map +0 -1
  45. package/dist/createActorHooks.d.ts +0 -41
  46. package/dist/createActorHooks.d.ts.map +0 -1
  47. package/dist/createActorHooks.js +0 -17
  48. package/dist/createActorHooks.js.map +0 -1
  49. package/dist/createInfiniteQuery.d.ts +0 -185
  50. package/dist/createInfiniteQuery.d.ts.map +0 -1
  51. package/dist/createInfiniteQuery.js +0 -198
  52. package/dist/createInfiniteQuery.js.map +0 -1
  53. package/dist/createMutation.d.ts +0 -33
  54. package/dist/createMutation.d.ts.map +0 -1
  55. package/dist/createMutation.js +0 -199
  56. package/dist/createMutation.js.map +0 -1
  57. package/dist/createQuery.d.ts +0 -63
  58. package/dist/createQuery.d.ts.map +0 -1
  59. package/dist/createQuery.js +0 -204
  60. package/dist/createQuery.js.map +0 -1
  61. package/dist/createReactorProvider.d.ts +0 -158
  62. package/dist/createReactorProvider.d.ts.map +0 -1
  63. package/dist/createReactorProvider.js +0 -256
  64. package/dist/createReactorProvider.js.map +0 -1
  65. package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
  66. package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
  67. package/dist/createSuspenseInfiniteQuery.js +0 -209
  68. package/dist/createSuspenseInfiniteQuery.js.map +0 -1
  69. package/dist/createSuspenseQuery.d.ts +0 -46
  70. package/dist/createSuspenseQuery.d.ts.map +0 -1
  71. package/dist/createSuspenseQuery.js +0 -158
  72. package/dist/createSuspenseQuery.js.map +0 -1
  73. package/dist/defineDisplayReactor.d.ts +0 -43
  74. package/dist/defineDisplayReactor.d.ts.map +0 -1
  75. package/dist/defineDisplayReactor.js +0 -42
  76. package/dist/defineDisplayReactor.js.map +0 -1
  77. package/dist/defineReactor.d.ts +0 -99
  78. package/dist/defineReactor.d.ts.map +0 -1
  79. package/dist/defineReactor.js +0 -15
  80. package/dist/defineReactor.js.map +0 -1
  81. package/dist/defineReactorShared.d.ts +0 -84
  82. package/dist/defineReactorShared.d.ts.map +0 -1
  83. package/dist/defineReactorShared.js +0 -139
  84. package/dist/defineReactorShared.js.map +0 -1
  85. package/dist/hooks/createAuthHooks.d.ts +0 -50
  86. package/dist/hooks/createAuthHooks.d.ts.map +0 -1
  87. package/dist/hooks/createAuthHooks.js +0 -291
  88. package/dist/hooks/createAuthHooks.js.map +0 -1
  89. package/dist/hooks/index.d.ts +0 -21
  90. package/dist/hooks/index.d.ts.map +0 -1
  91. package/dist/hooks/index.js +0 -24
  92. package/dist/hooks/index.js.map +0 -1
  93. package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
  94. package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
  95. package/dist/hooks/useActorInfiniteQuery.js +0 -89
  96. package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
  97. package/dist/hooks/useActorMethod.d.ts +0 -148
  98. package/dist/hooks/useActorMethod.d.ts.map +0 -1
  99. package/dist/hooks/useActorMethod.js +0 -394
  100. package/dist/hooks/useActorMethod.js.map +0 -1
  101. package/dist/hooks/useActorMutation.d.ts +0 -51
  102. package/dist/hooks/useActorMutation.d.ts.map +0 -1
  103. package/dist/hooks/useActorMutation.js +0 -70
  104. package/dist/hooks/useActorMutation.js.map +0 -1
  105. package/dist/hooks/useActorQuery.d.ts +0 -45
  106. package/dist/hooks/useActorQuery.d.ts.map +0 -1
  107. package/dist/hooks/useActorQuery.js +0 -67
  108. package/dist/hooks/useActorQuery.js.map +0 -1
  109. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
  110. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
  111. package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
  112. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
  113. package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
  114. package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
  115. package/dist/hooks/useActorSuspenseQuery.js +0 -58
  116. package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
  117. package/dist/ownedAuthentication.d.ts +0 -52
  118. package/dist/ownedAuthentication.d.ts.map +0 -1
  119. package/dist/ownedAuthentication.js +0 -49
  120. package/dist/ownedAuthentication.js.map +0 -1
  121. package/dist/server.d.ts +0 -21
  122. package/dist/server.d.ts.map +0 -1
  123. package/dist/server.js +0 -23
  124. package/dist/server.js.map +0 -1
  125. package/dist/testing.d.ts +0 -19
  126. package/dist/testing.d.ts.map +0 -1
  127. package/dist/testing.js +0 -19
  128. package/dist/testing.js.map +0 -1
  129. package/dist/types.d.ts +0 -671
  130. package/dist/types.d.ts.map +0 -1
  131. package/dist/types.js +0 -5
  132. package/dist/types.js.map +0 -1
  133. package/dist/utils.d.ts +0 -207
  134. package/dist/utils.d.ts.map +0 -1
  135. package/dist/utils.js +0 -405
  136. package/dist/utils.js.map +0 -1
  137. package/dist/validation.d.ts +0 -136
  138. package/dist/validation.d.ts.map +0 -1
  139. package/dist/validation.js +0 -144
  140. package/dist/validation.js.map +0 -1
  141. package/src/auth/auth-client-compat.ts +0 -273
  142. package/src/auth/authentication-manager.ts +0 -1682
  143. package/src/auth/constants.ts +0 -32
  144. package/src/auth/createIdentityAttributeHooks.ts +0 -169
  145. package/src/auth/identity-attributes-manager.ts +0 -226
  146. package/src/auth/identity-attributes.ts +0 -345
  147. package/src/auth/index.ts +0 -7
  148. package/src/auth/local-ii-probe.ts +0 -173
  149. package/src/auth/types.ts +0 -243
  150. package/src/createActorHooks.ts +0 -208
  151. package/src/createInfiniteQuery.ts +0 -670
  152. package/src/createMutation.ts +0 -324
  153. package/src/createQuery.ts +0 -369
  154. package/src/createReactorProvider.ts +0 -365
  155. package/src/createSuspenseInfiniteQuery.ts +0 -651
  156. package/src/createSuspenseQuery.ts +0 -304
  157. package/src/defineDisplayReactor.ts +0 -62
  158. package/src/defineReactor.ts +0 -142
  159. package/src/defineReactorShared.ts +0 -268
  160. package/src/hooks/createAuthHooks.ts +0 -371
  161. package/src/hooks/index.ts +0 -103
  162. package/src/hooks/useActorInfiniteQuery.ts +0 -278
  163. package/src/hooks/useActorMethod.ts +0 -710
  164. package/src/hooks/useActorMutation.ts +0 -205
  165. package/src/hooks/useActorQuery.ts +0 -157
  166. package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
  167. package/src/hooks/useActorSuspenseQuery.ts +0 -147
  168. package/src/index.ts +0 -31
  169. package/src/ownedAuthentication.ts +0 -81
  170. package/src/server.ts +0 -23
  171. package/src/testing.ts +0 -18
  172. package/src/types.ts +0 -948
  173. package/src/utils.ts +0 -505
  174. package/src/validation.ts +0 -226
@@ -1,198 +0,0 @@
1
- /**
2
- * Infinite Query Factory - Generic wrapper for React Query paginated canister data
3
- *
4
- * Creates unified fetch/hook/invalidate functions for any paginated canister method.
5
- * Works with any Reactor instance.
6
- *
7
- * @example
8
- * const postsQuery = createInfiniteQuery(reactor, {
9
- * functionName: "get_posts",
10
- * initialPageParam: 0,
11
- * getArgs: (cursor) => [{ cursor, limit: 10 }] as const,
12
- * getNextPageParam: (lastPage) => lastPage.nextCursor,
13
- * })
14
- *
15
- * // In component
16
- * const { data, fetchNextPage, hasNextPage } = postsQuery.useInfiniteQuery()
17
- *
18
- * // Flatten all pages
19
- * const allPosts = data?.pages.flatMap(page => page.posts)
20
- *
21
- * // Invalidate cache
22
- * postsQuery.invalidate()
23
- */
24
- import { useMemo } from "react";
25
- import { useInfiniteQuery, } from "@tanstack/react-query";
26
- import { buildChainedSelect, callConfigForKey, mergeFactoryQueryKey, normalizeQueryData, pickFetchOptions, queryCacheControls, retryOption, useMountQueryClient, withQueryFactoryMethods, } from "./utils.js";
27
- // ============================================================================
28
- // Internal Implementation
29
- // ============================================================================
30
- const createInfiniteQueryImpl = (reactor, config) => {
31
- const { functionName, callConfig, queryKey: customQueryKey, initialPageParam, getArgs, getKeyArgs, getNextPageParam, getPreviousPageParam, maxPages, staleTime = 5 * 60 * 1000, select, ...rest } = config;
32
- // Fold the call arguments into the key. Without them every infinite query on
33
- // a method shares one cache entry, so two lists with different `getArgs` (a
34
- // different page size, a different filter) serve each other's pages — the
35
- // arguments live in a closure, not in the config, so nothing else
36
- // distinguishes them.
37
- //
38
- // The first page's args stand for the query's identity; `getKeyArgs` lets a
39
- // caller drop the cursor field when it is part of those args.
40
- const getQueryKey = () => {
41
- const initialArgs = getArgs(initialPageParam);
42
- const keyArgs = getKeyArgs?.(initialArgs) ?? initialArgs;
43
- return reactor.generateQueryKey({
44
- functionName,
45
- queryKey: mergeFactoryQueryKey(customQueryKey, undefined, keyArgs),
46
- }, callConfig);
47
- };
48
- // Query function - accepts QueryFunctionContext
49
- const queryFn = async (context) => {
50
- // pageParam is typed as unknown in QueryFunctionContext, but we know its type
51
- const pageParam = context.pageParam;
52
- const args = getArgs(pageParam);
53
- const result = await reactor.callMethod({
54
- functionName,
55
- args,
56
- callConfig: callConfigForKey(context.queryKey, callConfig),
57
- });
58
- return normalizeQueryData(result);
59
- };
60
- // Get infinite query options for fetchInfiniteQuery
61
- const getInfiniteQueryOptions = () => {
62
- const queryKey = getQueryKey();
63
- return {
64
- // How the query function runs, shared with the hook; see
65
- // pickFetchOptions. An update method's `retry` defaults as
66
- // `Reactor.getQueryRetry` says.
67
- ...pickFetchOptions(rest),
68
- ...retryOption(rest.retry, reactor.getQueryRetry(functionName, queryKey)),
69
- queryKey,
70
- queryFn,
71
- initialPageParam,
72
- getNextPageParam,
73
- };
74
- };
75
- // Fetch function for loaders (cache-first, fetches first page)
76
- const fetch = async () => {
77
- // Check cache first
78
- const cachedData = reactor.queryClient.getQueryData(getQueryKey());
79
- if (cachedData !== undefined) {
80
- return select ? select(cachedData) : cachedData;
81
- }
82
- // Fetch if not in cache. A sign-in or sign-out while it is in flight
83
- // cancels it; it then runs again for the new identity rather than
84
- // rejecting with TanStack's CancelledError, as `reactor.fetchQuery` does.
85
- const result = await reactor.clientManager.fetchAcrossIdentitySwitch(() => reactor.queryClient.fetchInfiniteQuery(getInfiniteQueryOptions()));
86
- // Result is already InfiniteData format
87
- return select ? select(result) : result;
88
- };
89
- // Implementation
90
- const useInfiniteQueryHook = (options) => {
91
- useMountQueryClient(reactor.queryClient);
92
- // Memoized and identity-preserving; see buildChainedSelect for why the
93
- // function identity matters to the observer's select-result cache.
94
- const chainedSelect = useMemo(() => buildChainedSelect(select, options?.select), [options?.select]);
95
- const queryKey = getQueryKey();
96
- return useInfiniteQuery({
97
- queryKey,
98
- queryFn,
99
- initialPageParam,
100
- getNextPageParam,
101
- getPreviousPageParam,
102
- maxPages,
103
- staleTime,
104
- ...rest,
105
- ...options,
106
- select: chainedSelect,
107
- // The hook's `retry`, else the config's, else an update method's
108
- // default; see `Reactor.getQueryRetry`.
109
- ...retryOption(options?.retry ?? rest.retry, reactor.getQueryRetry(functionName, queryKey)),
110
- }, reactor.queryClient);
111
- };
112
- // Invalidate function
113
- const invalidate = async () => {
114
- const queryKey = getQueryKey();
115
- await reactor.queryClient.invalidateQueries({ queryKey });
116
- };
117
- // Get data from cache without fetching
118
- const getCacheData = (selectFn) => {
119
- const queryKey = getQueryKey();
120
- const cachedRawData = reactor.queryClient.getQueryData(queryKey);
121
- if (cachedRawData === undefined) {
122
- return undefined;
123
- }
124
- // Apply config.select to raw cache data
125
- const selectedData = (select ? select(cachedRawData) : cachedRawData);
126
- // Apply optional select parameter
127
- if (selectFn) {
128
- return selectFn(selectedData);
129
- }
130
- return selectedData;
131
- };
132
- return {
133
- fetch,
134
- useInfiniteQuery: useInfiniteQueryHook,
135
- invalidate,
136
- getQueryKey,
137
- getCacheData,
138
- ...queryCacheControls(reactor, getQueryKey),
139
- };
140
- };
141
- // ============================================================================
142
- // Factory Function
143
- // ============================================================================
144
- export function createInfiniteQuery(reactor, config) {
145
- return createInfiniteQueryImpl(reactor, config);
146
- }
147
- // ============================================================================
148
- // Factory with Dynamic Args
149
- // ============================================================================
150
- /**
151
- * Create an infinite query factory that accepts getArgs at call time.
152
- * Useful when pagination logic varies by context.
153
- *
154
- * @template Service - The actor interface type
155
- * @template Method - The method name on the actor
156
- * @template Transform - The transformation key (identity, display, etc.)
157
- * @template TPageParam - The page parameter type
158
- * @template Selected - The type returned after select transformation
159
- *
160
- * @param reactor - The Reactor instance
161
- * @param config - Infinite query configuration (without getArgs)
162
- * @returns A function that accepts getArgs and returns an InfiniteQueryResult
163
- *
164
- * @example
165
- * const getPostsQuery = createInfiniteQueryFactory(reactor, {
166
- * functionName: "get_posts",
167
- * initialPageParam: 0,
168
- * getKeyArgs: (args) => {
169
- * const [{ userId }] = args
170
- * return [{ userId }]
171
- * },
172
- * getNextPageParam: (lastPage) => lastPage.nextCursor,
173
- * })
174
- *
175
- * // Create query with specific args builder
176
- * const userPostsQuery = getPostsQuery((cursor) => [{ userId, cursor, limit: 10 }])
177
- * const { data, fetchNextPage } = userPostsQuery.useInfiniteQuery()
178
- *
179
- * // Every list this factory made, whatever its args and pages
180
- * await getPostsQuery.invalidate()
181
- */
182
- export function createInfiniteQueryFactory(reactor, config) {
183
- const factory = (getArgs) => {
184
- // `getKeyArgs` and the args-derived key segment are applied by the impl,
185
- // which now does it for every infinite query rather than only for factories.
186
- return createInfiniteQueryImpl(reactor, {
187
- ...config,
188
- getArgs,
189
- });
190
- };
191
- // What every instance's key starts with: the method, the `callConfig`
192
- // segments and the config `queryKey`. The args segment comes after them.
193
- return withQueryFactoryMethods(factory, reactor, () => reactor.generateQueryKey({
194
- functionName: config.functionName,
195
- queryKey: config.queryKey,
196
- }, config.callConfig));
197
- }
198
- //# sourceMappingURL=createInfiniteQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createInfiniteQuery.js","sourceRoot":"","sources":["../src/createInfiniteQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;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2
- * Mutation Factory - Generic wrapper for mutating canister data
3
- *
4
- * Creates unified mutation hooks for any canister method.
5
- * Works with any Reactor instance.
6
- * Use this when one mutation should support both React hooks and imperative
7
- * execution outside React.
8
- *
9
- * @example
10
- * const transferMutation = createMutation(reactor, {
11
- * functionName: "transfer",
12
- * // Refetched before onSuccess runs: a query factory covers every args
13
- * // instance, a `{ functionName }` every query of that method
14
- * invalidateQueries: [getBalance, { functionName: "get_history" }],
15
- * onSuccess: () => console.log("Success!"),
16
- * })
17
- *
18
- * // In component
19
- * const { mutate, isPending } = transferMutation.useMutation()
20
- *
21
- * @example
22
- * const transferMutation = createMutation(reactor, {
23
- * functionName: "transfer",
24
- * onCanisterError: (err) => console.error(err.code),
25
- * })
26
- *
27
- * // Outside React (loader/service/script)
28
- * await transferMutation.execute([{ to: "aaaaa-aa", amount: "1000" }])
29
- */
30
- import type { Reactor, FunctionName, TransformKey } from "@ic-reactor/core";
31
- import type { MutationConfig, MutationResult, NoInfer } from "./types.js";
32
- export declare function createMutation<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, TOnMutateResult = unknown>(reactor: Reactor<Service, Transform>, config: MutationConfig<NoInfer<Service>, Method, Transform, TOnMutateResult | undefined>): MutationResult<Service, Method, Transform>;
33
- //# sourceMappingURL=createMutation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMutation.d.ts","sourceRoot":"","sources":["../src/createMutation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAOH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EAEZ,YAAY,EAGb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEd,OAAO,EACR,MAAM,YAAY,CAAA;AAuPnB,wBAAgB,cAAc,CAC5B,OAAO,EACP,SAAS,SAAS,YAAY,EAC9B,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,EAC5D,eAAe,GAAG,OAAO,EAEzB,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EAKpC,MAAM,EAAE,cAAc,CACpB,OAAO,CAAC,OAAO,CAAC,EAChB,MAAM,EACN,SAAS,EACT,eAAe,GAAG,SAAS,CAC5B,GACA,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAU5C"}
@@ -1,199 +0,0 @@
1
- /**
2
- * Mutation Factory - Generic wrapper for mutating canister data
3
- *
4
- * Creates unified mutation hooks for any canister method.
5
- * Works with any Reactor instance.
6
- * Use this when one mutation should support both React hooks and imperative
7
- * execution outside React.
8
- *
9
- * @example
10
- * const transferMutation = createMutation(reactor, {
11
- * functionName: "transfer",
12
- * // Refetched before onSuccess runs: a query factory covers every args
13
- * // instance, a `{ functionName }` every query of that method
14
- * invalidateQueries: [getBalance, { functionName: "get_history" }],
15
- * onSuccess: () => console.log("Success!"),
16
- * })
17
- *
18
- * // In component
19
- * const { mutate, isPending } = transferMutation.useMutation()
20
- *
21
- * @example
22
- * const transferMutation = createMutation(reactor, {
23
- * functionName: "transfer",
24
- * onCanisterError: (err) => console.error(err.code),
25
- * })
26
- *
27
- * // Outside React (loader/service/script)
28
- * await transferMutation.execute([{ to: "aaaaa-aa", amount: "1000" }])
29
- */
30
- import { useMutation, } from "@tanstack/react-query";
31
- import { isCanisterError } from "@ic-reactor/core";
32
- import { invalidateTargets, useMountQueryClient } from "./utils.js";
33
- // ============================================================================
34
- // Internal Implementation
35
- // ============================================================================
36
- const createMutationImpl = (reactor, config) => {
37
- const { functionName, callConfig, invalidateQueries: factoryInvalidateQueries, onSuccess: factoryOnSuccess, onCanisterError: factoryOnCanisterError, onError: factoryOnError, onMutate: factoryOnMutate, onSettled: factoryOnSettled, ...factoryOptions } = config;
38
- /**
39
- * Raw call without any invalidation logic.
40
- * Used as mutationFn so that onSuccess handles all post-mutation work
41
- * and there is no double-invalidation.
42
- */
43
- const callFn = (args) => reactor.callMethod({ functionName, args, callConfig });
44
- /**
45
- * The factory's own `onMutate` result for each call.
46
- *
47
- * TanStack Query stores one `onMutate` result per mutation and hands it to
48
- * every callback. That slot holds the hook's result, which the mutation also
49
- * exposes as `context`, so this map holds the factory's. Each key is the
50
- * context object TanStack Query creates for a call and passes to every
51
- * callback of that call.
52
- */
53
- const factoryOnMutateResults = new WeakMap();
54
- /**
55
- * The `onMutate` result a factory callback receives. A factory without its
56
- * own `onMutate` gets the hook's, as it always has.
57
- */
58
- const factoryOnMutateResult = (onMutateResult, context) => (factoryOnMutate && context
59
- ? factoryOnMutateResults.get(context)
60
- : onMutateResult);
61
- /**
62
- * The options a mutation of this factory runs with, on both call paths: the
63
- * factory's config, the hook's options on top when there is a hook, and the
64
- * callbacks of both levels chained, factory first. `useMutation()` hands
65
- * them to TanStack Query's `useMutation`, and `execute()` builds a mutation
66
- * from them in the QueryClient's MutationCache.
67
- */
68
- const mutationOptions = (options) => {
69
- const { invalidateQueries: hookInvalidateQueries, onCanisterError: hookOnCanisterError, ...restOptions } = options ?? {};
70
- return {
71
- mutationKey: reactor.getQueryOptions({ functionName }).queryKey,
72
- ...factoryOptions,
73
- ...restOptions,
74
- // Use callFn (not execute) to avoid double-invalidation:
75
- // factoryInvalidateQueries are handled in onSuccess below.
76
- mutationFn: callFn,
77
- onSuccess: async (data, variables, onMutateResult, context) => {
78
- // 1. Factory-level invalidation
79
- await invalidateTargets(reactor, factoryInvalidateQueries, callConfig);
80
- // 2. Hook-level invalidation
81
- await invalidateTargets(reactor, hookInvalidateQueries, callConfig);
82
- // 3. Factory onSuccess
83
- await factoryOnSuccess?.(data, variables, factoryOnMutateResult(onMutateResult, context), context);
84
- // 4. Hook onSuccess
85
- await restOptions.onSuccess?.(data, variables, onMutateResult, context);
86
- },
87
- onError: async (error, variables, onMutateResult, context) => {
88
- if (isCanisterError(error)) {
89
- factoryOnCanisterError?.(error, variables);
90
- hookOnCanisterError?.(error, variables);
91
- }
92
- // Awaited in order, like `onSuccess`. TanStack Query holds
93
- // `onSettled` and the settled state until this promise resolves, so
94
- // an async `onError` must be part of it.
95
- await factoryOnError?.(error, variables, factoryOnMutateResult(onMutateResult, context), context);
96
- await restOptions.onError?.(error, variables, onMutateResult, context);
97
- },
98
- // `onMutate` and `onSettled` are composed like `onSuccess`/`onError`
99
- // above. They used to arrive through the `...restOptions` spread, so a
100
- // hook-level one silently replaced the factory's — factory teardown,
101
- // telemetry or logging simply vanished the moment any call site passed
102
- // its own, with no warning and no type error. Chaining is what a
103
- // reader who has seen `onSuccess` chain already expects.
104
- onMutate: async (variables, context) => {
105
- if (factoryOnMutate) {
106
- const result = await factoryOnMutate(variables, context);
107
- if (context)
108
- factoryOnMutateResults.set(context, result);
109
- }
110
- // Without a hook-level `onMutate` this is `undefined`, and
111
- // THookOnMutateResult is then `unknown`.
112
- return (await restOptions.onMutate?.(variables, context));
113
- },
114
- onSettled: async (data, error, variables, onMutateResult, context) => {
115
- await factoryOnSettled?.(data, error, variables, factoryOnMutateResult(onMutateResult, context), context);
116
- await restOptions.onSettled?.(data, error, variables, onMutateResult, context);
117
- },
118
- };
119
- };
120
- /**
121
- * Imperative execution for non-React usage.
122
- *
123
- * Builds the mutation in the QueryClient's MutationCache and runs it, as
124
- * TanStack Query's `useMutation` does, with the options the hook path uses
125
- * minus the hook's own. It used to call the canister and the factory's
126
- * callbacks itself, so the MutationCache never saw it: its global
127
- * `onError`, `onSuccess` and `onSettled` did not run, `useIsMutating` did
128
- * not count it, and neither the factory's `retry` or `networkMode` nor the
129
- * same options in the QueryClient's mutation defaults applied to the call.
130
- * The factory's `onMutate` and `onSettled` did not run either.
131
- *
132
- * Now the factory's chain runs as it does through `useMutation()`:
133
- * `onMutate`, then the factory's invalidation and `onSuccess`, or
134
- * `onCanisterError` and `onError` on failure, then `onSettled`. Each factory
135
- * callback gets the result of the factory's `onMutate` for this call. Only
136
- * hook-level callbacks are absent, because there is no hook here to supply
137
- * them.
138
- *
139
- * The QueryClient's mutation defaults apply as well, so a `mutations.retry`
140
- * there re-sends a failed call here too. Each retry of an update method is
141
- * a new call the canister runs; set `retry` on the factory (`false`, or
142
- * `reactorUpdateRetry` to retry only a SysTransient rejection) to decide it
143
- * per method.
144
- *
145
- * It resolves with the method's result. On failure it rejects with the
146
- * call's error once the callbacks have run, so `await execute(...)` still
147
- * rejects for the caller.
148
- *
149
- * Use this in route loaders, scripts, or server-side code.
150
- */
151
- const execute = async (args) => {
152
- const { queryClient } = reactor;
153
- const options = mutationOptions();
154
- const { onError } = options;
155
- // What the factory's `onError` or `onCanisterError` throws, if either
156
- // does. execute() has always rejected with it, and a TanStack Query
157
- // mutation at the 5.90.2 peer floor does too. Later releases reject with
158
- // the call's error and report the thrown one as an unhandled rejection,
159
- // which ends a Node script, so it is caught here and rethrown below.
160
- let thrownByOnError;
161
- const mutation = queryClient
162
- .getMutationCache()
163
- .build(queryClient, {
164
- ...options,
165
- onError: async (error, variables, onMutateResult, context) => {
166
- try {
167
- await onError?.(error, variables, onMutateResult, context);
168
- }
169
- catch (thrown) {
170
- thrownByOnError = { error: thrown };
171
- }
172
- },
173
- });
174
- try {
175
- return await mutation.execute(args);
176
- }
177
- catch (error) {
178
- throw thrownByOnError ? thrownByOnError.error : error;
179
- }
180
- };
181
- // Hook implementation
182
- const useMutationHook = (options) => {
183
- useMountQueryClient(reactor.queryClient);
184
- return useMutation(mutationOptions(options), reactor.queryClient);
185
- };
186
- return { useMutation: useMutationHook, execute };
187
- };
188
- // ============================================================================
189
- // Public Factory Function
190
- // ============================================================================
191
- export function createMutation(reactor,
192
- // A factory `onError` or `onSettled` gets no `onMutate` result when
193
- // `onMutate` throws, so the result can also be `undefined`. `onSuccess`
194
- // shares the type argument. It kept the `undefined` from when `execute()`
195
- // ran no `onMutate`, although it now always gets a result.
196
- config) {
197
- return createMutationImpl(reactor, config);
198
- }
199
- //# sourceMappingURL=createMutation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMutation.js","sourceRoot":"","sources":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KAAK,CAAqC,WAAW,EAAE;YACtD,GAAG,OAAO;YACV,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE;gBAC3D,IAAI,CAAC;oBACH,MAAM,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;gBAC5D,CAAC;gBAAC,OAAO,MAAM,EAAE,CAAC;oBAChB,eAAe,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;gBACrC,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QACJ,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;QACvD,CAAC;IACH,CAAC,CAAA;IAED,sBAAsB;IACtB,MAAM,eAAe,GAAG,CACtB,OAKC,EACD,EAAE;QACF,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACxC,OAAO,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IACnE,CAAC,CAAA;IAED,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,CAAA;AAClD,CAAC,CAAA;AAED,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,MAAM,UAAU,cAAc,CAM5B,OAAoC;AACpC,oEAAoE;AACpE,wEAAwE;AACxE,0EAA0E;AAC1E,2DAA2D;AAC3D,MAKC;IAED,OAAO,kBAAkB,CACvB,OAAO,EACP,MAKC,CACF,CAAA;AACH,CAAC"}
@@ -1,63 +0,0 @@
1
- /**
2
- * Query Factory - Generic wrapper for React Query-based canister data
3
- *
4
- * Creates unified fetch/hook/invalidate functions for any canister method.
5
- * Works with any Reactor instance.
6
- * Use this when the same read operation must work both inside React components
7
- * and outside React (loaders, actions, services, tests).
8
- *
9
- * @example
10
- * const userQuery = createQuery(todoManager, {
11
- * functionName: "get_user",
12
- * select: (result) => result.user,
13
- * })
14
- *
15
- * // In component
16
- * const { data: user } = userQuery.useQuery()
17
- *
18
- * @example
19
- * const userQuery = createQuery(todoManager, { functionName: "get_user", args: ["alice"] })
20
- *
21
- * // Outside React (loader/service/script)
22
- * await userQuery.fetch()
23
- * const cached = userQuery.getCacheData()
24
- * await userQuery.invalidate()
25
- */
26
- import type { Reactor, FunctionName, ReactorArgs, TransformKey } from "@ic-reactor/core";
27
- import type { QueryFnData, QueryError, QueryConfig, QueryResult, QueryFactoryConfig, SkippableQueryFactoryFn, NoInfer } from "./types.js";
28
- export declare function createQuery<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, Selected = QueryFnData<Service, Method, Transform>>(reactor: Reactor<Service, Transform>, config: QueryConfig<NoInfer<Service>, Method, Transform, Selected>): QueryResult<QueryFnData<Service, Method, Transform>, Selected, QueryError<Service, Method, Transform>>;
29
- /**
30
- * Create a query factory: a function that takes the method's args and returns
31
- * the query object for them, the same object for the same args.
32
- *
33
- * The function also has `getQueryKey()`, the key prefix every query it
34
- * returns shares, and `invalidate()`, which invalidates all of them whatever
35
- * their args. Pass the function itself to a mutation's `invalidateQueries` to
36
- * refresh every instance after the mutation.
37
- *
38
- * It also takes TanStack Query's `skipToken` in place of args, for a
39
- * component whose args are not known yet, and returns a query with only
40
- * `useQuery()`, which waits without fetching; see
41
- * {@link SkippableQueryFactoryFn}.
42
- *
43
- * @example
44
- * const getBalance = createQueryFactory(ledger, {
45
- * functionName: "icrc1_balance_of",
46
- * })
47
- *
48
- * // In a component
49
- * const { data } = getBalance([{ owner, subaccount: [] }]).useQuery()
50
- *
51
- * // In a component whose owner may not be known yet
52
- * const { data: maybe } = getBalance(
53
- * owner ? [{ owner, subaccount: [] }] : skipToken
54
- * ).useQuery()
55
- *
56
- * // Refetch every account's balance after a transfer
57
- * const transfer = createMutation(ledger, {
58
- * functionName: "icrc1_transfer",
59
- * invalidateQueries: [getBalance],
60
- * })
61
- */
62
- export declare function createQueryFactory<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, Selected = QueryFnData<Service, Method, Transform>>(reactor: Reactor<Service, Transform>, config: QueryFactoryConfig<NoInfer<Service>, Method, Transform, Selected>): SkippableQueryFactoryFn<ReactorArgs<Service, Method, Transform>, QueryResult<QueryFnData<Service, Method, Transform>, Selected, QueryError<Service, Method, Transform>>>;
63
- //# sourceMappingURL=createQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createQuery.d.ts","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,kBAAkB,CAAA;AAUzB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,WAAW,EAGX,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EAEvB,OAAO,EACR,MAAM,YAAY,CAAA;AAwLnB,wBAAgB,WAAW,CACzB,OAAO,EACP,SAAS,SAAS,YAAY,EAC9B,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,EAC5D,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAElD,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EACpC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,GACjE,WAAW,CACZ,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACvC,QAAQ,EACR,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CACvC,CAKA;AAMD;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