@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.
- package/README.md +234 -787
- package/dist/index.d.ts +259 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -23
- package/dist/index.js.map +1 -1
- package/llms.txt +80 -278
- package/package.json +11 -39
- package/src/index.tsx +611 -0
- package/dist/auth/auth-client-compat.d.ts +0 -122
- package/dist/auth/auth-client-compat.d.ts.map +0 -1
- package/dist/auth/auth-client-compat.js +0 -162
- package/dist/auth/auth-client-compat.js.map +0 -1
- package/dist/auth/authentication-manager.d.ts +0 -405
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -1537
- package/dist/auth/authentication-manager.js.map +0 -1
- package/dist/auth/constants.d.ts +0 -24
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -24
- package/dist/auth/constants.js.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.js +0 -122
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -27
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -191
- package/dist/auth/identity-attributes-manager.js.map +0 -1
- package/dist/auth/identity-attributes.d.ts +0 -19
- package/dist/auth/identity-attributes.d.ts.map +0 -1
- package/dist/auth/identity-attributes.js +0 -227
- package/dist/auth/identity-attributes.js.map +0 -1
- package/dist/auth/index.d.ts +0 -8
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/local-ii-probe.d.ts +0 -57
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -121
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -222
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/createActorHooks.d.ts +0 -41
- package/dist/createActorHooks.d.ts.map +0 -1
- package/dist/createActorHooks.js +0 -17
- package/dist/createActorHooks.js.map +0 -1
- package/dist/createInfiniteQuery.d.ts +0 -185
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -198
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -33
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -199
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -63
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -204
- package/dist/createQuery.js.map +0 -1
- package/dist/createReactorProvider.d.ts +0 -158
- package/dist/createReactorProvider.d.ts.map +0 -1
- package/dist/createReactorProvider.js +0 -256
- package/dist/createReactorProvider.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -209
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -46
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -158
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineDisplayReactor.d.ts +0 -43
- package/dist/defineDisplayReactor.d.ts.map +0 -1
- package/dist/defineDisplayReactor.js +0 -42
- package/dist/defineDisplayReactor.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -99
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -15
- package/dist/defineReactor.js.map +0 -1
- package/dist/defineReactorShared.d.ts +0 -84
- package/dist/defineReactorShared.d.ts.map +0 -1
- package/dist/defineReactorShared.js +0 -139
- package/dist/defineReactorShared.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -50
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -291
- package/dist/hooks/createAuthHooks.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -21
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -24
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -89
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -148
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -394
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -51
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -70
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -45
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -67
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.js +0 -58
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/ownedAuthentication.d.ts +0 -52
- package/dist/ownedAuthentication.d.ts.map +0 -1
- package/dist/ownedAuthentication.js +0 -49
- package/dist/ownedAuthentication.js.map +0 -1
- package/dist/server.d.ts +0 -21
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -23
- package/dist/server.js.map +0 -1
- package/dist/testing.d.ts +0 -19
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -19
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -671
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -207
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -405
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -136
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -144
- package/dist/validation.js.map +0 -1
- package/src/auth/auth-client-compat.ts +0 -273
- package/src/auth/authentication-manager.ts +0 -1682
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -169
- package/src/auth/identity-attributes-manager.ts +0 -226
- package/src/auth/identity-attributes.ts +0 -345
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -173
- package/src/auth/types.ts +0 -243
- package/src/createActorHooks.ts +0 -208
- package/src/createInfiniteQuery.ts +0 -670
- package/src/createMutation.ts +0 -324
- package/src/createQuery.ts +0 -369
- package/src/createReactorProvider.ts +0 -365
- package/src/createSuspenseInfiniteQuery.ts +0 -651
- package/src/createSuspenseQuery.ts +0 -304
- package/src/defineDisplayReactor.ts +0 -62
- package/src/defineReactor.ts +0 -142
- package/src/defineReactorShared.ts +0 -268
- package/src/hooks/createAuthHooks.ts +0 -371
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -278
- package/src/hooks/useActorMethod.ts +0 -710
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -157
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
- package/src/hooks/useActorSuspenseQuery.ts +0 -147
- package/src/index.ts +0 -31
- package/src/ownedAuthentication.ts +0 -81
- package/src/server.ts +0 -23
- package/src/testing.ts +0 -18
- package/src/types.ts +0 -948
- package/src/utils.ts +0 -505
- package/src/validation.ts +0 -226
package/src/auth/types.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import type { Identity, SignIdentity } from "@icp-sdk/core/agent"
|
|
2
|
-
import type { PartialIdentity } from "@icp-sdk/core/identity"
|
|
3
|
-
import type { Principal } from "@icp-sdk/core/principal"
|
|
4
|
-
|
|
5
|
-
export interface SignedIdentityAttributes {
|
|
6
|
-
data: Uint8Array
|
|
7
|
-
signature: Uint8Array
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The 32-byte nonce issued by the relying-party canister.
|
|
12
|
-
*
|
|
13
|
-
* A function (or promise) lets the Internet Identity window open while the
|
|
14
|
-
* nonce is still being fetched, so the popup is opened inside the user gesture
|
|
15
|
-
* instead of after it. Every supported `@icp-sdk/auth` requires the function form, and
|
|
16
|
-
* IC Reactor normalizes whichever of these you pass into that thunk.
|
|
17
|
-
*/
|
|
18
|
-
export type IdentityAttributeNonce =
|
|
19
|
-
Uint8Array | Promise<Uint8Array> | (() => Uint8Array | Promise<Uint8Array>)
|
|
20
|
-
|
|
21
|
-
export interface IdentityAttributeRequest {
|
|
22
|
-
keys: string[]
|
|
23
|
-
nonce: IdentityAttributeNonce
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IdentityAttributeValues {
|
|
27
|
-
email?: string
|
|
28
|
-
name?: string
|
|
29
|
-
verified_email?: string
|
|
30
|
-
[key: string]: string | undefined
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface IdentityAttributeResult {
|
|
34
|
-
principal: string
|
|
35
|
-
requestedKeys: string[]
|
|
36
|
-
signedAttributes: SignedIdentityAttributes
|
|
37
|
-
decodedAttributes: IdentityAttributeValues
|
|
38
|
-
completedAt: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The providers that Internet Identity supports for one-click sign-in. Only
|
|
43
|
-
* these three reach the underlying auth client.
|
|
44
|
-
*/
|
|
45
|
-
type IdentityAttributeOpenIdProviderAlias = "google" | "apple" | "microsoft"
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* An OpenID provider, either as a well-known alias or as a raw issuer URL.
|
|
49
|
-
*
|
|
50
|
-
* The two forms are **not** interchangeable, and what each one does depends on
|
|
51
|
-
* where it is passed:
|
|
52
|
-
*
|
|
53
|
-
* - An alias (`"google" | "apple" | "microsoft"`) is forwarded to the auth
|
|
54
|
-
* client, which adds an `openid` search param to the identity provider URL so
|
|
55
|
-
* the user signs in through that provider directly.
|
|
56
|
-
* - Any other string is treated as a raw issuer URL and is **never** forwarded
|
|
57
|
-
* to the auth client, so it never affects how the user signs in. It is only
|
|
58
|
-
* meaningful when passed to {@link IdentityAttributesManager.requestOpenId}
|
|
59
|
-
* (or `identityAttributeKeys`), which scopes the requested keys to
|
|
60
|
-
* `openid:<issuer>:<key>`. Passed anywhere else it has no effect at all.
|
|
61
|
-
*/
|
|
62
|
-
export type IdentityAttributeOpenIdProvider =
|
|
63
|
-
IdentityAttributeOpenIdProviderAlias | (string & {})
|
|
64
|
-
|
|
65
|
-
/** Session key algorithm used for each sign-in. */
|
|
66
|
-
export type AuthClientKeyType = "ECDSA" | "Ed25519"
|
|
67
|
-
|
|
68
|
-
/** Structural shape of an `@icp-sdk/auth` `AuthClientStorage`. */
|
|
69
|
-
export interface AuthClientStorageLike {
|
|
70
|
-
get(key: string): Promise<string | CryptoKeyPair | null>
|
|
71
|
-
set(key: string, value: string | CryptoKeyPair): Promise<void>
|
|
72
|
-
remove(key: string): Promise<void>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Idle-session configuration forwarded to the underlying AuthClient.
|
|
77
|
-
* `@icp-sdk/auth` v8 only; see {@link AuthenticationClientOptions.idleOptions}.
|
|
78
|
-
*/
|
|
79
|
-
export interface AuthClientIdleOptions {
|
|
80
|
-
/** Called once the user has been idle for `idleTimeout` ms. */
|
|
81
|
-
onIdle?: () => unknown
|
|
82
|
-
/** Idle timeout in ms. @default 600_000 (10 minutes) */
|
|
83
|
-
idleTimeout?: number
|
|
84
|
-
/** Treat scroll events as activity. @default false */
|
|
85
|
-
captureScroll?: boolean
|
|
86
|
-
/** Scroll debounce in ms. @default 100 */
|
|
87
|
-
scrollDebounce?: number
|
|
88
|
-
/** Disable idle detection entirely. @default false */
|
|
89
|
-
disableIdle?: boolean
|
|
90
|
-
/**
|
|
91
|
-
* Disable the built-in idle callback, which signs the user out and reloads
|
|
92
|
-
* the page. @default false
|
|
93
|
-
*/
|
|
94
|
-
disableDefaultIdleCallback?: boolean
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface AuthenticationClientOptions {
|
|
98
|
-
/** Identity provider URL. @default "https://id.ai/authorize" */
|
|
99
|
-
identityProvider?: string | URL
|
|
100
|
-
/** `window.open` features string for the identity provider popup. */
|
|
101
|
-
windowOpenerFeatures?: string
|
|
102
|
-
/**
|
|
103
|
-
* Provider for one-click sign-in.
|
|
104
|
-
*
|
|
105
|
-
* Only the `"google" | "apple" | "microsoft"` aliases reach the auth client.
|
|
106
|
-
* Any other value is dropped here and has **no effect** — raw issuer URLs are
|
|
107
|
-
* only meaningful on `requestOpenId`, where they scope the requested keys.
|
|
108
|
-
* @see {@link IdentityAttributeOpenIdProvider}
|
|
109
|
-
*/
|
|
110
|
-
openIdProvider?: IdentityAttributeOpenIdProvider
|
|
111
|
-
/**
|
|
112
|
-
* Derivation origin for the identity provider.
|
|
113
|
-
*
|
|
114
|
-
* Required when the app is served from more than one origin (e.g. a custom
|
|
115
|
-
* domain plus `<canisterId>.icp0.io`) and every origin must resolve to the
|
|
116
|
-
* same principal.
|
|
117
|
-
* @see https://github.com/dfinity/internet-identity/blob/main/docs/internet-identity-spec.adoc
|
|
118
|
-
*/
|
|
119
|
-
derivationOrigin?: string | URL
|
|
120
|
-
/**
|
|
121
|
-
* Persistent storage backend. `@icp-sdk/auth` v8 only: v10 drops it with a
|
|
122
|
-
* one-time warning. @default IndexedDB
|
|
123
|
-
*/
|
|
124
|
-
storage?: AuthClientStorageLike
|
|
125
|
-
/**
|
|
126
|
-
* Session key algorithm. Use `"Ed25519"` when the storage backend cannot
|
|
127
|
-
* hold a `CryptoKey`. `@icp-sdk/auth` v8 only: v10 drops it with a one-time
|
|
128
|
-
* warning. @default "ECDSA"
|
|
129
|
-
*/
|
|
130
|
-
keyType?: AuthClientKeyType
|
|
131
|
-
/**
|
|
132
|
-
* Idle timeout configuration. Pass `{ disableIdle: true }` to opt out of the
|
|
133
|
-
* default behaviour, which signs the user out and reloads after 10 minutes.
|
|
134
|
-
*
|
|
135
|
-
* `@icp-sdk/auth` v8 only. v10 has no equivalent, so IC Reactor drops it
|
|
136
|
-
* there with a one-time warning: on v10 the identity provider enforces the
|
|
137
|
-
* idle limit, so pass `maxTimeToIdle` to `login()` and set
|
|
138
|
-
* `disableBrowserActivity` instead.
|
|
139
|
-
*/
|
|
140
|
-
idleOptions?: AuthClientIdleOptions
|
|
141
|
-
/**
|
|
142
|
-
* An existing identity to authenticate via delegation. `@icp-sdk/auth` v8
|
|
143
|
-
* only: v10 drops it with a one-time warning.
|
|
144
|
-
*/
|
|
145
|
-
identity?: SignIdentity | PartialIdentity
|
|
146
|
-
/**
|
|
147
|
-
* How the client talks to the identity provider. `"redirect"` requires
|
|
148
|
-
* `@icp-sdk/auth` v8 or later and is ignored by older versions.
|
|
149
|
-
* @default "window"
|
|
150
|
-
*/
|
|
151
|
-
transport?: "window" | "redirect"
|
|
152
|
-
/**
|
|
153
|
-
* Stops a v10 client from watching the page for signs of activity, so only
|
|
154
|
-
* requests keep the session in use.
|
|
155
|
-
*
|
|
156
|
-
* `@icp-sdk/auth` v10 only. v8 has no equivalent, so IC Reactor drops it
|
|
157
|
-
* there with a one-time warning. On v8, `idleOptions` controls idle handling.
|
|
158
|
-
* @default false
|
|
159
|
-
*/
|
|
160
|
-
disableBrowserActivity?: boolean
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface AuthClientSignInOptions {
|
|
164
|
-
/** The longest the delegation may last, in nanoseconds. */
|
|
165
|
-
maxTimeToLive?: bigint
|
|
166
|
-
/**
|
|
167
|
-
* How long a signed-in user may be idle before the sign-in ends, in
|
|
168
|
-
* nanoseconds.
|
|
169
|
-
*
|
|
170
|
-
* `@icp-sdk/auth` v10 only. v8's sign-in has no idle limit, so IC Reactor
|
|
171
|
-
* drops it there with a one-time warning. On v8, set `idleOptions` instead.
|
|
172
|
-
*/
|
|
173
|
-
maxTimeToIdle?: bigint
|
|
174
|
-
/**
|
|
175
|
-
* Canisters the delegation is restricted to. `@icp-sdk/auth` v8 only: v10
|
|
176
|
-
* ignores it, and IC Reactor warns when it is set for a v10 client.
|
|
177
|
-
*/
|
|
178
|
-
targets?: Principal[]
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface AuthenticationSignInOptions
|
|
182
|
-
extends AuthClientSignInOptions, AuthenticationClientOptions {
|
|
183
|
-
onSuccess?: () => void | Promise<void>
|
|
184
|
-
onError?: (error?: string) => void | Promise<void>
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export interface RequestIdentityAttributesParameters extends AuthenticationClientOptions {
|
|
188
|
-
keys: string[]
|
|
189
|
-
nonce: IdentityAttributeNonce
|
|
190
|
-
/**
|
|
191
|
-
* Sign in as part of the same identity-provider interaction.
|
|
192
|
-
* @default true
|
|
193
|
-
*/
|
|
194
|
-
signIn?: boolean
|
|
195
|
-
maxTimeToLive?: bigint
|
|
196
|
-
maxTimeToIdle?: bigint
|
|
197
|
-
targets?: Principal[]
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export interface RequestOpenIdIdentityAttributesParameters extends Omit<
|
|
201
|
-
RequestIdentityAttributesParameters,
|
|
202
|
-
"openIdProvider"
|
|
203
|
-
> {
|
|
204
|
-
/**
|
|
205
|
-
* Provider the requested `keys` are scoped to, producing
|
|
206
|
-
* `openid:<issuer>:<key>`.
|
|
207
|
-
*
|
|
208
|
-
* Passing one of the `"google" | "apple" | "microsoft"` aliases additionally
|
|
209
|
-
* routes sign-in through that provider, so the user grants attribute access
|
|
210
|
-
* in the same step. A raw issuer URL only scopes the keys.
|
|
211
|
-
* @see {@link IdentityAttributeOpenIdProvider}
|
|
212
|
-
*/
|
|
213
|
-
openIdProvider: IdentityAttributeOpenIdProvider
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Structural subset of `@icp-sdk/auth`'s `AuthClient` that IC Reactor relies
|
|
218
|
-
* on. Declared locally so `@icp-sdk/auth` stays an optional peer dependency.
|
|
219
|
-
*
|
|
220
|
-
* Every method here is identical across the supported majors (v8 and v10) --
|
|
221
|
-
* only the option objects handed to the constructor and to `signIn` diverge,
|
|
222
|
-
* and `auth-client-compat.ts` translates those. That is what lets one interface
|
|
223
|
-
* describe both.
|
|
224
|
-
*/
|
|
225
|
-
export interface AuthClientLike {
|
|
226
|
-
getIdentity(): Promise<Identity> | Identity
|
|
227
|
-
isAuthenticated(): Promise<boolean> | boolean
|
|
228
|
-
signIn(options?: AuthClientSignInOptions): Promise<Identity>
|
|
229
|
-
signOut(options?: { returnTo?: string }): Promise<void>
|
|
230
|
-
requestAttributes(params: {
|
|
231
|
-
keys: string[]
|
|
232
|
-
// Every supported `@icp-sdk/auth` takes a thunk, so it can journal the value and replay
|
|
233
|
-
// the same bytes through a redirect flow.
|
|
234
|
-
nonce: () => Promise<Uint8Array>
|
|
235
|
-
}): Promise<SignedIdentityAttributes>
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export interface AuthState {
|
|
239
|
-
identity: Identity | null
|
|
240
|
-
isAuthenticating: boolean
|
|
241
|
-
isAuthenticated: boolean
|
|
242
|
-
error: Error | undefined
|
|
243
|
-
}
|
package/src/createActorHooks.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Actor Hooks Factory - Creates a full set of React hooks for a reactor instance.
|
|
3
|
-
*
|
|
4
|
-
* This is the primary entry point for using the library in React applications.
|
|
5
|
-
* It generates type-safe hooks for:
|
|
6
|
-
* - Queries (useActorQuery)
|
|
7
|
-
* - Suspense Queries (useActorSuspenseQuery)
|
|
8
|
-
* - Infinite Queries (useActorInfiniteQuery)
|
|
9
|
-
* - Suspense Infinite Queries (useActorSuspenseInfiniteQuery)
|
|
10
|
-
* - Mutations (useActorMutation)
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const { useActorQuery, useActorMutation } = createActorHooks(reactor)
|
|
14
|
-
*
|
|
15
|
-
* // In component
|
|
16
|
-
* const { data } = useActorQuery({ functionName: 'get_user' })
|
|
17
|
-
* const { mutate } = useActorMutation({ functionName: 'update_user' })
|
|
18
|
-
*/
|
|
19
|
-
import {
|
|
20
|
-
Reactor,
|
|
21
|
-
DisplayReactor,
|
|
22
|
-
ReactorReturnErr,
|
|
23
|
-
ReactorReturnOk,
|
|
24
|
-
ReactorQueryData,
|
|
25
|
-
BaseActor,
|
|
26
|
-
FunctionName,
|
|
27
|
-
ReactorArgs,
|
|
28
|
-
TransformKey,
|
|
29
|
-
} from "@ic-reactor/core"
|
|
30
|
-
import {
|
|
31
|
-
UseQueryResult,
|
|
32
|
-
UseSuspenseQueryResult,
|
|
33
|
-
UseInfiniteQueryResult,
|
|
34
|
-
UseSuspenseInfiniteQueryResult,
|
|
35
|
-
UseMutationResult,
|
|
36
|
-
InfiniteData,
|
|
37
|
-
} from "@tanstack/react-query"
|
|
38
|
-
import { useActorQuery } from "./hooks/useActorQuery.js"
|
|
39
|
-
import { useActorSuspenseQuery } from "./hooks/useActorSuspenseQuery.js"
|
|
40
|
-
import { useActorInfiniteQuery } from "./hooks/useActorInfiniteQuery.js"
|
|
41
|
-
import { useActorSuspenseInfiniteQuery } from "./hooks/useActorSuspenseInfiniteQuery.js"
|
|
42
|
-
import { useActorMutation } from "./hooks/useActorMutation.js"
|
|
43
|
-
import {
|
|
44
|
-
useActorMethod,
|
|
45
|
-
UseActorMethodParameters,
|
|
46
|
-
} from "./hooks/useActorMethod.js"
|
|
47
|
-
import { SkippableInfiniteQueryConfig } from "./createInfiniteQuery.js"
|
|
48
|
-
import { SuspenseInfiniteQueryConfig } from "./createSuspenseInfiniteQuery.js"
|
|
49
|
-
import {
|
|
50
|
-
SkippableQueryConfig,
|
|
51
|
-
SuspenseQueryConfig,
|
|
52
|
-
MutationConfig,
|
|
53
|
-
} from "./types.js"
|
|
54
|
-
|
|
55
|
-
export type ActorHooks<Service, Transform extends TransformKey> = {
|
|
56
|
-
// `args` may be `skipToken` here, and not in the suspense hooks below.
|
|
57
|
-
useActorQuery: {
|
|
58
|
-
<Method extends FunctionName<Service>>(
|
|
59
|
-
config: SkippableQueryConfig<
|
|
60
|
-
Service,
|
|
61
|
-
Method,
|
|
62
|
-
Transform,
|
|
63
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
64
|
-
>
|
|
65
|
-
): UseQueryResult<
|
|
66
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
67
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
68
|
-
>
|
|
69
|
-
<Method extends FunctionName<Service>, TData>(
|
|
70
|
-
config: SkippableQueryConfig<Service, Method, Transform, TData>
|
|
71
|
-
): UseQueryResult<TData, ReactorReturnErr<Service, Method, Transform>>
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
useActorSuspenseQuery: {
|
|
75
|
-
<Method extends FunctionName<Service>>(
|
|
76
|
-
config: SuspenseQueryConfig<
|
|
77
|
-
Service,
|
|
78
|
-
Method,
|
|
79
|
-
Transform,
|
|
80
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
81
|
-
>
|
|
82
|
-
): UseSuspenseQueryResult<
|
|
83
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
84
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
85
|
-
>
|
|
86
|
-
<Method extends FunctionName<Service>, TData>(
|
|
87
|
-
config: SuspenseQueryConfig<Service, Method, Transform, TData>
|
|
88
|
-
): UseSuspenseQueryResult<
|
|
89
|
-
TData,
|
|
90
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
91
|
-
>
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// `Selected` is what `select` returns, so `select` can reshape the pages the
|
|
95
|
-
// way `createInfiniteQuery` allows. Without `select` it stays `InfiniteData`.
|
|
96
|
-
useActorInfiniteQuery: <
|
|
97
|
-
Method extends FunctionName<Service>,
|
|
98
|
-
TPageParam = unknown,
|
|
99
|
-
Selected = InfiniteData<
|
|
100
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
101
|
-
TPageParam
|
|
102
|
-
>,
|
|
103
|
-
>(
|
|
104
|
-
config: SkippableInfiniteQueryConfig<
|
|
105
|
-
Service,
|
|
106
|
-
Method,
|
|
107
|
-
Transform,
|
|
108
|
-
TPageParam,
|
|
109
|
-
Selected
|
|
110
|
-
>
|
|
111
|
-
) => UseInfiniteQueryResult<
|
|
112
|
-
Selected,
|
|
113
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
114
|
-
>
|
|
115
|
-
|
|
116
|
-
useActorSuspenseInfiniteQuery: <
|
|
117
|
-
Method extends FunctionName<Service>,
|
|
118
|
-
TPageParam = unknown,
|
|
119
|
-
Selected = InfiniteData<
|
|
120
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
121
|
-
TPageParam
|
|
122
|
-
>,
|
|
123
|
-
>(
|
|
124
|
-
config: SuspenseInfiniteQueryConfig<
|
|
125
|
-
Service,
|
|
126
|
-
Method,
|
|
127
|
-
Transform,
|
|
128
|
-
TPageParam,
|
|
129
|
-
Selected
|
|
130
|
-
>
|
|
131
|
-
) => UseSuspenseInfiniteQueryResult<
|
|
132
|
-
Selected,
|
|
133
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
134
|
-
>
|
|
135
|
-
|
|
136
|
-
useActorMutation: <
|
|
137
|
-
Method extends FunctionName<Service>,
|
|
138
|
-
TOnMutateResult = unknown,
|
|
139
|
-
>(
|
|
140
|
-
config: MutationConfig<Service, Method, Transform, TOnMutateResult>
|
|
141
|
-
) => UseMutationResult<
|
|
142
|
-
ReactorReturnOk<Service, Method, Transform>,
|
|
143
|
-
ReactorReturnErr<Service, Method, Transform>,
|
|
144
|
-
// Without this TVariables defaults to `unknown` and mutate/mutateAsync
|
|
145
|
-
// accept anything; the standalone hook and createMutation both pass it.
|
|
146
|
-
ReactorArgs<Service, Method, Transform>,
|
|
147
|
-
TOnMutateResult
|
|
148
|
-
>
|
|
149
|
-
|
|
150
|
-
useActorMethod: <Method extends FunctionName<Service>>(
|
|
151
|
-
config: Omit<
|
|
152
|
-
UseActorMethodParameters<Service, Method, Transform>,
|
|
153
|
-
"reactor"
|
|
154
|
-
>
|
|
155
|
-
) => ReturnType<typeof useActorMethod<Service, Method, Transform>>
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function createActorHooks<Service>(
|
|
159
|
-
reactor: DisplayReactor<Service>
|
|
160
|
-
): ActorHooks<Service, "display">
|
|
161
|
-
|
|
162
|
-
export function createActorHooks<
|
|
163
|
-
Service = BaseActor,
|
|
164
|
-
Transform extends TransformKey = "candid",
|
|
165
|
-
>(reactor: Reactor<Service, Transform>): ActorHooks<Service, Transform>
|
|
166
|
-
|
|
167
|
-
export function createActorHooks<Service, Transform extends TransformKey>(
|
|
168
|
-
reactor: Reactor<Service, Transform>
|
|
169
|
-
): ActorHooks<Service, Transform> {
|
|
170
|
-
return {
|
|
171
|
-
useActorQuery: ((config: any) =>
|
|
172
|
-
useActorQuery({ ...config, reactor })) as ActorHooks<
|
|
173
|
-
Service,
|
|
174
|
-
Transform
|
|
175
|
-
>["useActorQuery"],
|
|
176
|
-
|
|
177
|
-
useActorSuspenseQuery: ((config: any) =>
|
|
178
|
-
useActorSuspenseQuery({ ...config, reactor })) as ActorHooks<
|
|
179
|
-
Service,
|
|
180
|
-
Transform
|
|
181
|
-
>["useActorSuspenseQuery"],
|
|
182
|
-
|
|
183
|
-
useActorInfiniteQuery: ((config: any) =>
|
|
184
|
-
useActorInfiniteQuery({ ...config, reactor })) as ActorHooks<
|
|
185
|
-
Service,
|
|
186
|
-
Transform
|
|
187
|
-
>["useActorInfiniteQuery"],
|
|
188
|
-
|
|
189
|
-
useActorSuspenseInfiniteQuery: ((config: any) =>
|
|
190
|
-
useActorSuspenseInfiniteQuery({ ...config, reactor })) as ActorHooks<
|
|
191
|
-
Service,
|
|
192
|
-
Transform
|
|
193
|
-
>["useActorSuspenseInfiniteQuery"],
|
|
194
|
-
|
|
195
|
-
useActorMutation: ((config: any) =>
|
|
196
|
-
useActorMutation({ ...config, reactor })) as ActorHooks<
|
|
197
|
-
Service,
|
|
198
|
-
Transform
|
|
199
|
-
>["useActorMutation"],
|
|
200
|
-
|
|
201
|
-
useActorMethod: (config) =>
|
|
202
|
-
useActorMethod({ ...config, reactor } as UseActorMethodParameters<
|
|
203
|
-
Service,
|
|
204
|
-
any,
|
|
205
|
-
Transform
|
|
206
|
-
>),
|
|
207
|
-
}
|
|
208
|
-
}
|