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

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 +237 -787
  2. package/dist/index.d.ts +260 -16
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +471 -23
  5. package/dist/index.js.map +1 -1
  6. package/llms.txt +82 -278
  7. package/package.json +11 -39
  8. package/src/index.tsx +612 -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,291 +0,0 @@
1
- import { useSyncExternalStore, useEffect, useRef, useMemo } from "react";
2
- /**
3
- * The managers whose session a `useAuth()` has already started restoring.
4
- *
5
- * Restoring ends in `authenticate()`, which publishes `isAuthenticating: true`
6
- * and then the restored state. It used to run once per mounted `useAuth()`
7
- * rather than once per manager, so every consumer that mounted while signed out
8
- * flipped `isAuthenticating` for the whole app, and one that mounted while a
9
- * sign-in popup was open cleared `isAuthenticating` before the sign-in ended. A
10
- * component that hides a `useAuth()` consumer while `isAuthenticating` never
11
- * settled: each restore unmounted the consumer, and each remount restored
12
- * again. Both clients answer from memory once loaded, so that loop ran on the
13
- * microtask queue and the page never painted again.
14
- *
15
- * Keyed by manager rather than by `createAuthHooks` call, because reactors that
16
- * share one `AuthenticationManager` each build their own hooks.
17
- */
18
- const restoredSessions = new WeakSet();
19
- /**
20
- * How many `useAuth()` consumers of each manager are mounted, so that a
21
- * restore can tell a manager that was discarded from one StrictMode released
22
- * and mounted again; see `useAuth()`.
23
- */
24
- const mountedConsumers = new WeakMap();
25
- /**
26
- * The principal both hooks return.
27
- *
28
- * `authenticate()` and `logout()` leave the client's anonymous identity in
29
- * `authState.identity` with `isAuthenticated: false`, so deriving the principal
30
- * from the identity alone reported `2vxsx-fae` for a signed-out user, and
31
- * `principal ? <SignedIn /> : <SignedOut />` rendered the signed-in branch.
32
- * Memoized on the identity, because `getPrincipal()` may build a new object on
33
- * each call and the result is often a hook dependency.
34
- */
35
- function usePrincipal(isAuthenticated, identity) {
36
- return useMemo(() => (isAuthenticated && identity ? identity.getPrincipal() : null), [isAuthenticated, identity]);
37
- }
38
- /**
39
- * The auth state a server render shows, and so the one hydration shows.
40
- *
41
- * `useSyncExternalStore` renders `getServerSnapshot` on the server and again
42
- * while hydrating, and both renders have to produce the HTML the server sent.
43
- * The hooks passed the live state for both. A server holds no session, so its
44
- * HTML is signed out. A component that hydrates after the session is restored,
45
- * such as one inside a Suspense boundary whose code arrives later, read the
46
- * restored state and no longer matched that HTML. React then reported a
47
- * hydration error and threw the boundary's server HTML away to render it again
48
- * on the client. A constant also keeps a server render from showing whatever a
49
- * manager shared across requests happens to hold.
50
- *
51
- * It is the state the hooks report before the session has been checked: a
52
- * server cannot know the session, so it renders the "checking" state that a
53
- * browser shows until its restore settles. Once hydrated, React compares it
54
- * with the live state and renders again with that.
55
- */
56
- const SERVER_AUTH_STATE = Object.freeze({
57
- identity: null,
58
- isAuthenticating: true,
59
- isAuthenticated: false,
60
- error: undefined,
61
- });
62
- /**
63
- * Create authentication hooks for managing user sessions with Internet Identity.
64
- *
65
- * @example
66
- * const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(authentication)
67
- *
68
- * function App() {
69
- * const { login, logout, principal, isAuthenticated } = useAuth()
70
- *
71
- * return isAuthenticated
72
- * ? <button onClick={() => logout()}>Logout {principal?.toText()}</button>
73
- * : <button onClick={() => login()}>Login with II</button>
74
- * }
75
- */
76
- export const createAuthHooks = (authentication) => {
77
- // Passing a ClientManager here is the natural mistake — it is what
78
- // `AuthenticationManager` is built from, and the two are adjacent in every
79
- // setup snippet. TypeScript rejects it, but a JS caller got no error until
80
- // render, where it surfaced as "Cannot destructure property 'isAuthenticated'
81
- // of 'useAuthState(...)' as it is undefined" — which names neither the cause
82
- // nor this function.
83
- if (!authentication ||
84
- typeof authentication.subscribeAuthState !== "function") {
85
- throw new TypeError("[ic-reactor] createAuthHooks() expects an AuthenticationManager, not a " +
86
- "ClientManager. Build one first: " +
87
- "`new AuthenticationManager({ clientManager })`, or take it from " +
88
- "`defineReactor(...).authentication`.");
89
- }
90
- const { clientManager } = authentication;
91
- // The agent state a manager starts in, for the reason given at
92
- // SERVER_AUTH_STATE: `useAuth()` initializes the agent once hydrated, so a
93
- // component hydrating later read `isInitialized: true` against server HTML
94
- // rendered before any initialization. The network is kept: it comes from the
95
- // agent's host, which initialization does not change.
96
- const serverAgentState = Object.freeze({
97
- isInitialized: false,
98
- isInitializing: false,
99
- error: undefined,
100
- network: clientManager.network,
101
- isLocalhost: clientManager.isLocal,
102
- });
103
- // What every consumer hands `useSyncExternalStore`, built once rather than
104
- // on each render. React unsubscribes and subscribes again whenever the
105
- // subscribe function changes, and each unsubscribe filters the manager's
106
- // whole subscriber list. An auth state change re-renders every consumer, so
107
- // a function per render cost k re-subscriptions and about k²/2 subscriber
108
- // visits for k consumers: two million for 2,000 `useUserPrincipal()` rows.
109
- const subscribeAgentState = (callback) => clientManager.subscribeAgentState(callback);
110
- const getAgentState = () => clientManager.agentState;
111
- const getServerAgentState = () => serverAgentState;
112
- // Until the session has been checked, `authState` is the signed-out state
113
- // the manager starts in, and reporting it as the answer sent signed-in users
114
- // to the login page (#621). `useAuth()` starts the check from an effect, so
115
- // on the first render nothing had been checked, yet `isAuthenticating` was
116
- // false: a guard that redirects when `!isAuthenticating && !isAuthenticated`
117
- // redirected before the session was ever read. The hooks report
118
- // `isAuthenticating: true` until the check settles instead. The snapshot is
119
- // kept per source state, because `useSyncExternalStore` needs the same object
120
- // back until something changes.
121
- let unchecked;
122
- const subscribeAuthState = (callback) => {
123
- const unsubscribeState = authentication.subscribeAuthState(callback);
124
- const unsubscribeChecked = authentication.subscribeSessionChecked(callback);
125
- return () => {
126
- unsubscribeState();
127
- unsubscribeChecked();
128
- };
129
- };
130
- const getAuthState = () => {
131
- const state = authentication.authState;
132
- if (authentication.sessionChecked || state.isAuthenticating)
133
- return state;
134
- if (unchecked?.source !== state) {
135
- unchecked = {
136
- source: state,
137
- state: Object.freeze({ ...state, isAuthenticating: true }),
138
- };
139
- }
140
- return unchecked.state;
141
- };
142
- const getServerAuthState = () => SERVER_AUTH_STATE;
143
- /**
144
- * Subscribe to agent state changes.
145
- * Returns the current agent state (agent, isInitialized, etc.)
146
- */
147
- const useAgentState = () => useSyncExternalStore(subscribeAgentState, getAgentState, getServerAgentState);
148
- /**
149
- * Subscribe to authentication state changes.
150
- * Returns auth state (isAuthenticated, isAuthenticating, identity, error)
151
- */
152
- const useAuthState = () => useSyncExternalStore(subscribeAuthState, getAuthState, getServerAuthState);
153
- /**
154
- * Main authentication hook that provides login/logout methods and auth state.
155
- * Automatically initializes the session on first use, restoring any previous session.
156
- *
157
- * `isAuthenticating` is `true` until that restore has settled, including on
158
- * the first render and in a server render, so a guard that shows a spinner
159
- * while `isAuthenticating` never takes the state before the restore for a
160
- * signed-out user. A restore that fails settles it too.
161
- *
162
- * @example
163
- * function AuthButton() {
164
- * const { login, logout, isAuthenticated, isAuthenticating } = useAuth()
165
- *
166
- * if (isAuthenticated) {
167
- * return <button onClick={() => logout()}>Logout</button>
168
- * }
169
- * return (
170
- * <button onClick={() => login()} disabled={isAuthenticating}>
171
- * {isAuthenticating ? "Connecting..." : "Login"}
172
- * </button>
173
- * )
174
- * }
175
- */
176
- const useAuth = () => {
177
- const { login, logout, authenticate } = authentication;
178
- const { isAuthenticated, isAuthenticating, identity, error } = useAuthState();
179
- // Keeps a StrictMode re-run of the effect below from repeating it.
180
- const initializedRef = useRef(false);
181
- // Restore the previous session when the first consumer of this manager
182
- // mounts. `prepareClient` also warms up the AuthClient so a later
183
- // `login()` can open the identity provider window inside the click handler.
184
- useEffect(() => {
185
- mountedConsumers.set(authentication, (mountedConsumers.get(authentication) ?? 0) + 1);
186
- const unmount = () => {
187
- mountedConsumers.set(authentication, (mountedConsumers.get(authentication) ?? 1) - 1);
188
- };
189
- if (initializedRef.current && restoredSessions.has(authentication)) {
190
- return unmount;
191
- }
192
- const firstRun = !initializedRef.current;
193
- initializedRef.current = true;
194
- if (restoredSessions.has(authentication)) {
195
- // Restored already. A live session is still checked again, which
196
- // notices a delegation that has lapsed since and publishes nothing
197
- // while it is valid.
198
- if (firstRun && authentication.authState.isAuthenticated) {
199
- authentication.authenticate().catch(() => undefined);
200
- }
201
- return unmount;
202
- }
203
- restoredSessions.add(authentication);
204
- // A provider that builds its managers per mount disposes the manager
205
- // from its cleanup. One that unmounted before this restore had built
206
- // the client still got one, built after `dispose()` and never released,
207
- // so each quick remount left a live client listening to the page. The
208
- // restore stops instead once the manager has been disposed since it
209
- // began and no `useAuth()` of it is mounted, releasing what it built.
210
- // StrictMode's cleanup disposes the manager too, but mounts this
211
- // consumer again before the restore looks, and that restore goes on.
212
- // One that stopped counts as not having run, so a manager mounted again,
213
- // as `<Activity>` mounts a tree it showed again, restores.
214
- const releases = authentication.releaseCount;
215
- const abandoned = () => {
216
- if (authentication.releaseCount === releases ||
217
- (mountedConsumers.get(authentication) ?? 0) > 0) {
218
- return false;
219
- }
220
- authentication.dispose();
221
- restoredSessions.delete(authentication);
222
- return true;
223
- };
224
- void authentication
225
- .prepareClient()
226
- .catch(() => undefined)
227
- .then(async () => {
228
- if (abandoned())
229
- return false;
230
- await clientManager.initialize();
231
- if (abandoned())
232
- return false;
233
- // A check that has settled already and found no session, such as
234
- // the one a manager runs over a client handed to its constructor,
235
- // or a route loader's `authenticate()`, answered what this restore
236
- // would. Running it again only flashed `isAuthenticating`, and a
237
- // guard redirected a second time. A live session is still checked,
238
- // which publishes nothing while it is valid.
239
- const { isAuthenticated, error } = authentication.authState;
240
- if (authentication.sessionChecked && !isAuthenticated && !error) {
241
- return true;
242
- }
243
- await authentication.authenticate().catch(() => undefined);
244
- return !abandoned();
245
- })
246
- // Failures are already reflected in authState/agentState; without
247
- // this the rejection escapes as an unhandled promise rejection. A
248
- // restore that failed before it reached `authenticate()`, such as a
249
- // root key that could not be fetched, has settled all the same.
250
- .catch(() => true)
251
- .then((settled) => {
252
- if (settled)
253
- authentication.markSessionChecked();
254
- });
255
- return unmount;
256
- }, []);
257
- const principal = usePrincipal(isAuthenticated, identity);
258
- return {
259
- authenticate,
260
- login,
261
- logout,
262
- isAuthenticated,
263
- isAuthenticating,
264
- principal,
265
- identity,
266
- error,
267
- };
268
- };
269
- /**
270
- * Get the current user's Principal.
271
- * Returns null if not authenticated, including while the signed-out session
272
- * holds the anonymous identity.
273
- *
274
- * @example
275
- * function UserInfo() {
276
- * const principal = useUserPrincipal()
277
- * if (!principal) return null
278
- * return <span>Logged in as: {principal.toText()}</span>
279
- * }
280
- */
281
- const useUserPrincipal = () => {
282
- const { isAuthenticated, identity } = useAuthState();
283
- return usePrincipal(isAuthenticated, identity);
284
- };
285
- return {
286
- useAuth,
287
- useAgentState,
288
- useUserPrincipal,
289
- };
290
- };
291
- //# sourceMappingURL=createAuthHooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAuthHooks.js","sourceRoot":"","sources":["../../src/hooks/createAuthHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAoCxE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAyB,CAAA;AAE7D;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAiC,CAAA;AAErE;;;;;;;;;GASG;AACH,SAAS,YAAY,CACnB,eAAwB,EACxB,QAAyB;IAEzB,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,eAAe,IAAI,QAAQ,CAAC,CAAC,C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AAC,YAAY,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;gBAC1D,OAAO,CAAC,SAAS,EAAE,CAAA;YACrB,CAAC,CAAC;gBACF,kEAAkE;gBAClE,kEAAkE;gBAClE,oEAAoE;gBACpE,gEAAgE;iBAC/D,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;iBACjB,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBAChB,IAAI,OAAO;oBAAE,cAAc,CAAC,kBAAkB,EAAE,CAAA;YAClD,CAAC,CAAC,CAAA;YAEJ,OAAO,OAAO,CAAA;QAChB,CAAC,EAAE,EAAE,CAAC,CAAA;QAEN,MAAM,SAAS,GAAG,YAAY,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;QAEzD,OAAO;YACL,YAAY;YACZ,KAAK;YACL,MAAM;YACN,eAAe;YACf,gBAAgB;YAChB,SAAS;YACT,QAAQ;YACR,KAAK;SACN,CAAA;IACH,CAAC,CAAA;IAED;;;;;;;;;;;OAWG;IACH,MAAM,gBAAgB,GAAG,GAAqB,EAAE;QAC9C,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,CAAA;QACpD,OAAO,YAAY,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;IAChD,CAAC,CAAA;IAED,OAAO;QACL,OAAO;QACP,aAAa;QACb,gBAAgB;KACjB,CAAA;AACH,CAAC,CAAA"}
@@ -1,21 +0,0 @@
1
- export { useActorQuery as useReactorQuery } from "./useActorQuery.js";
2
- export { useActorMutation as useReactorMutation } from "./useActorMutation.js";
3
- export { useActorSuspenseQuery as useReactorSuspenseQuery } from "./useActorSuspenseQuery.js";
4
- export { useActorInfiniteQuery as useReactorInfiniteQuery } from "./useActorInfiniteQuery.js";
5
- export { useActorSuspenseInfiniteQuery as useReactorSuspenseInfiniteQuery } from "./useActorSuspenseInfiniteQuery.js";
6
- export { useActorMethod, useActorMethod as useReactorMethod, createActorMethodHooks, } from "./useActorMethod.js";
7
- export { createAuthHooks } from "./createAuthHooks.js";
8
- export type { CreateAuthHooksReturn, UseAuthReturn } from "./createAuthHooks.js";
9
- export type { UseActorQueryParameters as UseReactorQueryParameters, UseActorQueryResult as UseReactorQueryResult, } from "./useActorQuery.js";
10
- export type { UseActorMutationParameters as UseReactorMutationParameters, UseActorMutationResult as UseReactorMutationResult, } from "./useActorMutation.js";
11
- export type { UseActorSuspenseQueryParameters as UseReactorSuspenseQueryParameters, UseActorSuspenseQueryResult as UseReactorSuspenseQueryResult, } from "./useActorSuspenseQuery.js";
12
- export type { UseActorInfiniteQueryParameters as UseReactorInfiniteQueryParameters, UseActorInfiniteQueryResult as UseReactorInfiniteQueryResult, } from "./useActorInfiniteQuery.js";
13
- export type { UseActorSuspenseInfiniteQueryParameters as UseReactorSuspenseInfiniteQueryParameters, UseActorSuspenseInfiniteQueryResult as UseReactorSuspenseInfiniteQueryResult, } from "./useActorSuspenseInfiniteQuery.js";
14
- export type { UseActorMethodParameters as UseReactorMethodParameters, UseActorMethodResult as UseReactorMethodResult, } from "./useActorMethod.js";
15
- export type { UseActorQueryConfig as UseActorQueryParameters, UseActorQueryResult, } from "./useActorQuery.js";
16
- export type { UseActorMutationConfig as UseActorMutationParameters, UseActorMutationResult, } from "./useActorMutation.js";
17
- export type { UseActorSuspenseQueryConfig as UseActorSuspenseQueryParameters, UseActorSuspenseQueryResult, } from "./useActorSuspenseQuery.js";
18
- export type { UseActorInfiniteQueryConfig as UseActorInfiniteQueryParameters, UseActorInfiniteQueryResult, } from "./useActorInfiniteQuery.js";
19
- export type { UseActorSuspenseInfiniteQueryConfig as UseActorSuspenseInfiniteQueryParameters, UseActorSuspenseInfiniteQueryResult, } from "./useActorSuspenseInfiniteQuery.js";
20
- export type { UseActorMethodConfig as UseActorMethodParameters, UseActorMethodResult, } from "./useActorMethod.js";
21
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts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GACpB,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,sBAAsB,IAAI,0BAA0B,EACpD,sBAAsB,GACvB,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EACV,2BAA2B,IAAI,+BAA+B,EAC9D,2BAA2B,GAC5B,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,2BAA2B,IAAI,+BAA+B,EAC9D,2BAA2B,GAC5B,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,mCAAmC,IAAI,uCAAuC,EAC9E,mCAAmC,GACpC,MAAM,oCAAoC,CAAA;AAE3C,YAAY,EACV,oBAAoB,IAAI,wBAAwB,EAChD,oBAAoB,GACrB,MAAM,qBAAqB,CAAA"}
@@ -1,24 +0,0 @@
1
- // ============================================================================
2
- // Hooks
3
- //
4
- // These are the RAW hooks: they take the reactor as a property. They are
5
- // therefore exported as `useReactor*` only — the `useActor*` names belong to
6
- // the bound hooks `createActorHooks` returns, which take no reactor. Aliasing
7
- // the raw implementations under the bound names would hand a caller following
8
- // the documented `useActorQuery({ functionName })` shape an undefined reactor.
9
- // ============================================================================
10
- // useActorQuery / useReactorQuery
11
- export { useActorQuery as useReactorQuery } from "./useActorQuery.js";
12
- // useActorMutation / useReactorMutation
13
- export { useActorMutation as useReactorMutation } from "./useActorMutation.js";
14
- // useActorSuspenseQuery / useReactorSuspenseQuery
15
- export { useActorSuspenseQuery as useReactorSuspenseQuery } from "./useActorSuspenseQuery.js";
16
- // useActorInfiniteQuery / useReactorInfiniteQuery
17
- export { useActorInfiniteQuery as useReactorInfiniteQuery } from "./useActorInfiniteQuery.js";
18
- // useActorSuspenseInfiniteQuery / useReactorSuspenseInfiniteQuery
19
- export { useActorSuspenseInfiniteQuery as useReactorSuspenseInfiniteQuery } from "./useActorSuspenseInfiniteQuery.js";
20
- // useActorMethod / useReactorMethod
21
- export { useActorMethod, useActorMethod as useReactorMethod, createActorMethodHooks, } from "./useActorMethod.js";
22
- // createAuthHooks
23
- export { createAuthHooks } from "./createAuthHooks.js";
24
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,QAAQ;AACR,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAE/E,kCAAkC;AAClC,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAErE,wCAAwC;AACxC,OAAO,EAAE,gBAAgB,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE9E,kDAAkD;AAClD,OAAO,EAAE,qBAAqB,IAAI,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAE7F,kDAAkD;AAClD,OAAO,EAAE,qBAAqB,IAAI,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAE7F,kEAAkE;AAClE,OAAO,EAAE,6BAA6B,IAAI,+BAA+B,EAAE,MAAM,oCAAoC,CAAA;AAErH,oCAAoC;AACpC,OAAO,EACL,cAAc,EACd,cAAc,IAAI,gBAAgB,EAClC,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAE5B,kBAAkB;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
@@ -1,67 +0,0 @@
1
- import { QueryKey, UseInfiniteQueryResult, UseInfiniteQueryOptions, InfiniteData, type SkipToken } from "@tanstack/react-query";
2
- import { FunctionName, Reactor, TransformKey, ReactorArgs, ReactorReturnOk, ReactorQueryData, ReactorReturnErr } from "@ic-reactor/core";
3
- import { CallConfig } from "@icp-sdk/core/agent";
4
- /**
5
- * Parameters for useActorInfiniteQuery hook.
6
- * Extends react-query's UseInfiniteQueryOptions with custom reactor params.
7
- */
8
- export interface UseActorInfiniteQueryParameters<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>> extends Omit<UseInfiniteQueryOptions<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>, Selected, QueryKey, TPageParam>, "queryKey" | "queryFn" | "getNextPageParam" | "initialPageParam"> {
9
- /** The reactor instance to use for method calls */
10
- reactor: Reactor<Service, Transform>;
11
- /** The method name to call on the canister */
12
- functionName: Method;
13
- /**
14
- * Function to get args from page parameter, or TanStack Query's `skipToken`
15
- * while the args are not known: the query then waits without fetching, in
16
- * an entry of its own under its method and `queryKey`, which no call's key
17
- * shares, so it shows no data until the args arrive.
18
- */
19
- getArgs: ((pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>) | SkipToken;
20
- /**
21
- * Narrows what the cache key derives from the call arguments.
22
- *
23
- * By default the key is scoped by `getArgs(initialPageParam)`, so two
24
- * infinite queries on the same method with different arguments stay in
25
- * separate cache entries. Supply this when those args embed the cursor and
26
- * only part of them identifies the query — return the stable, serializable
27
- * portion (typically everything except the pagination field). It is required
28
- * when `initialPageParam` changes between renders, as `Date.now()` does:
29
- * without it every render keys a new query.
30
- */
31
- getKeyArgs?: (args: ReactorArgs<Service, Method, Transform>) => unknown;
32
- /** Agent call configuration (effectiveCanisterId, etc.) */
33
- callConfig?: CallConfig;
34
- /** Custom query key (auto-generated if not provided) */
35
- queryKey?: QueryKey;
36
- /** Initial page parameter */
37
- initialPageParam: TPageParam;
38
- /** Function to determine next page parameter */
39
- getNextPageParam: (lastPage: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, allPages: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined | null;
40
- }
41
- export type UseActorInfiniteQueryConfig<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>> = Omit<UseActorInfiniteQueryParameters<Service, Method, Transform, TPageParam, Selected>, "reactor">;
42
- export type UseActorInfiniteQueryResult<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>> = UseInfiniteQueryResult<Selected, ReactorReturnErr<Service, Method, Transform>>;
43
- /**
44
- * Hook for executing infinite/paginated query calls on a canister.
45
- *
46
- * @example
47
- * const { data, fetchNextPage, hasNextPage } = useReactorInfiniteQuery({
48
- * reactor,
49
- * functionName: "getItems",
50
- * getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }] as const,
51
- * initialPageParam: 0,
52
- * getNextPageParam: (lastPage) => lastPage.nextOffset,
53
- * })
54
- *
55
- * // Wait for the args: no fetch until userId is known
56
- * const { data } = useReactorInfiniteQuery({
57
- * reactor,
58
- * functionName: "getUserItems",
59
- * getArgs: userId
60
- * ? (pageParam) => [{ userId, offset: pageParam, limit: 10 }] as const
61
- * : skipToken,
62
- * initialPageParam: 0,
63
- * getNextPageParam: (lastPage) => lastPage.nextOffset,
64
- * })
65
- */
66
- export declare const useActorInfiniteQuery: <Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>>({ reactor, functionName, getArgs, getKeyArgs, callConfig, queryKey, ...options }: UseActorInfiniteQueryParameters<Service, Method, Transform, TPageParam, Selected>) => UseActorInfiniteQueryResult<Service, Method, Transform, TPageParam, Selected>;
67
- //# sourceMappingURL=useActorInfiniteQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useActorInfiniteQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorInfiniteQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAGR,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,Y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GAAG,YAAY,CACrB,gBAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,EAC7D,UAAU,CACX,EACD,kFAQC,+BAA+B,CAChC,OAAO,EACP,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,CACT,KAAG,2BAA2B,CAC7B,OAAO,EACP,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,CAoGT,CAAA"}
@@ -1,89 +0,0 @@
1
- import { useMemo } from "react";
2
- import { useInfiniteQuery, skipToken, } from "@tanstack/react-query";
3
- import { callConfigForKey, mergeFactoryQueryKey, normalizeQueryData, retryOption, skippedQueryKey, useMountQueryClient, } from "../utils.js";
4
- /**
5
- * Hook for executing infinite/paginated query calls on a canister.
6
- *
7
- * @example
8
- * const { data, fetchNextPage, hasNextPage } = useReactorInfiniteQuery({
9
- * reactor,
10
- * functionName: "getItems",
11
- * getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }] as const,
12
- * initialPageParam: 0,
13
- * getNextPageParam: (lastPage) => lastPage.nextOffset,
14
- * })
15
- *
16
- * // Wait for the args: no fetch until userId is known
17
- * const { data } = useReactorInfiniteQuery({
18
- * reactor,
19
- * functionName: "getUserItems",
20
- * getArgs: userId
21
- * ? (pageParam) => [{ userId, offset: pageParam, limit: 10 }] as const
22
- * : skipToken,
23
- * initialPageParam: 0,
24
- * getNextPageParam: (lastPage) => lastPage.nextOffset,
25
- * })
26
- */
27
- export const useActorInfiniteQuery = ({ reactor, functionName, getArgs, getKeyArgs, callConfig, queryKey, ...options }) => {
28
- useMountQueryClient(reactor.queryClient);
29
- // Always pass queryKey through generateQueryKey so it is merged with the
30
- // reactor/function identity. Using the custom key verbatim would cause cache
31
- // collisions if two different actors or methods share the same key string.
32
- const baseQueryKey = useMemo(() => {
33
- // Waiting for its args: an entry of its own under the method and the
34
- // custom key, which every key the args will give extends; see
35
- // skippedQueryKey.
36
- if (getArgs === skipToken) {
37
- return skippedQueryKey(reactor.generateQueryKey({ functionName, queryKey: mergeFactoryQueryKey(queryKey) }, callConfig), "infinite");
38
- }
39
- // Fold the call arguments into the key. They live in the `getArgs`
40
- // closure rather than in the config, so without this two hooks on the
41
- // same method with different arguments share one cache entry and serve
42
- // each other's pages. `getKeyArgs` narrows them exactly as it does for the
43
- // factories, which the bound hook's config type always accepted: it used
44
- // to be ignored here, so the cursor stayed in the key, and an
45
- // `initialPageParam` that changes every render (`Date.now()`) keyed a new
46
- // query on every render — an endless loop of first-page fetches.
47
- const initialArgs = getArgs(options.initialPageParam);
48
- const keyArgs = getKeyArgs?.(initialArgs) ?? initialArgs;
49
- return reactor.generateQueryKey({
50
- functionName,
51
- queryKey: mergeFactoryQueryKey(queryKey, undefined, keyArgs),
52
- }, callConfig);
53
- }, [
54
- queryKey,
55
- reactor,
56
- // `canisterId` is mutable reactor state that `setCanisterId` can change,
57
- // while `reactor` itself stays the same object — so it has to be a
58
- // dependency in its own right or the key stays pinned to the old canister
59
- // while the queryFn already calls the new one.
60
- reactor.canisterId?.toString(),
61
- functionName,
62
- callConfig,
63
- getArgs,
64
- getKeyArgs,
65
- options.initialPageParam,
66
- ]);
67
- // Memoize queryFn to prevent recreation on every render
68
- const queryFn = useMemo(() => getArgs === skipToken
69
- ? skipToken
70
- : async ({ pageParam, queryKey: fetchedKey, }) => {
71
- const args = getArgs(pageParam);
72
- const result = await reactor.callMethod({
73
- functionName,
74
- args,
75
- callConfig: callConfigForKey(fetchedKey, callConfig),
76
- });
77
- return normalizeQueryData(result);
78
- }, [reactor, functionName, getArgs, callConfig]);
79
- // The method's default `retry`: for an update method, only failures that
80
- // prove the canister never ran the call; see `Reactor.getQueryRetry`.
81
- const defaultRetry = useMemo(() => reactor.getQueryRetry(functionName, baseQueryKey), [reactor, functionName, baseQueryKey]);
82
- return useInfiniteQuery({
83
- queryKey: baseQueryKey,
84
- queryFn,
85
- ...options,
86
- ...retryOption(options.retry, defaultRetry),
87
- }, reactor.queryClient);
88
- };
89
- //# sourceMappingURL=useActorInfiniteQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useActorInfiniteQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorInfiniteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAEL,gBAAgB,EAChB,SAAS,GAKV,MAAM,uBAAuB,CAAA;AAW9B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAA;AAmGpB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CASnC,EACA,OAAO,EACP,YAAY,EACZ,OAAO,EACP,UAAU,EACV,UAAU,EACV,QAAQ,EACR,GAAG,OAAO,EAOX,EAMC,EAAE;IACF,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAExC,yEAAyE;IACzE,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE;QAChC,qEAAqE;QACrE,8DAA8D;QAC9D,mBAAmB;QACnB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,eAAe,CACpB,OAAO,CAAC,gBAAgB,CACtB,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,EAC1D,UAAU,CACX,EACD,UAAU,CACX,CAAA;QACH,CAAC;QACD,mEAAmE;QACnE,sEAAsE;QACtE,uEAAuE;QACvE,2EAA2E;QAC3E,yEAAyE;QACzE,8DAA8D;QAC9D,0EAA0E;QAC1E,iEAAiE;QACjE,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;QACrD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC,WAAW,CAAC,IAAI,WAAW,CAAA;QAExD,OAAO,OAAO,CAAC,gBAA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