@ic-reactor/react 3.12.5 → 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 +236 -423
- package/dist/index.d.ts +259 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -17
- package/dist/index.js.map +1 -1
- package/llms.txt +82 -54
- package/package.json +12 -28
- package/src/index.tsx +611 -0
- package/dist/auth/authentication-manager.d.ts +0 -123
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -767
- 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 -106
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -26
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -107
- 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 -170
- 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 -46
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -102
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -179
- 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 -52
- 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 -144
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -174
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -30
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -192
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -30
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -117
- package/dist/createQuery.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -147
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -177
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -25
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -111
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -125
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -180
- package/dist/defineReactor.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -43
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -131
- 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 -39
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -56
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -115
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -250
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -48
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -69
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -32
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -46
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -39
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -56
- 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 -47
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/types.d.ts +0 -270
- 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 -51
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -131
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -125
- package/dist/validation.js.map +0 -1
- package/src/auth/authentication-manager.ts +0 -860
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -143
- package/src/auth/identity-attributes-manager.ts +0 -131
- package/src/auth/identity-attributes.ts +0 -270
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -147
- package/src/auth/types.ts +0 -200
- package/src/createActorHooks.ts +0 -220
- package/src/createInfiniteQuery.ts +0 -578
- package/src/createMutation.ts +0 -341
- package/src/createQuery.ts +0 -237
- package/src/createSuspenseInfiniteQuery.ts +0 -601
- package/src/createSuspenseQuery.ts +0 -234
- package/src/defineReactor.ts +0 -324
- package/src/hooks/createAuthHooks.ts +0 -189
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -205
- package/src/hooks/useActorMethod.ts +0 -507
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -124
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -205
- package/src/hooks/useActorSuspenseQuery.ts +0 -132
- package/src/index.ts +0 -23
- package/src/types.ts +0 -499
- package/src/utils.ts +0 -121
- package/src/validation.ts +0 -202
package/dist/defineReactor.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* defineReactor - One-call bootstrap for a canister reactor + its React hooks.
|
|
3
|
-
*
|
|
4
|
-
* Collapses the four manual steps (QueryClient → ClientManager → Reactor →
|
|
5
|
-
* createActorHooks) into a single call, and turns the Reactor / DisplayReactor
|
|
6
|
-
* choice into a `display` flag.
|
|
7
|
-
* Use this when one-call bootstrap is enough. If you need reusable
|
|
8
|
-
* method-specific operations outside React, compose with query/mutation
|
|
9
|
-
* factories after setup.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { defineReactor } from "@ic-reactor/react"
|
|
14
|
-
* import { idlFactory, type _SERVICE } from "./declarations/backend"
|
|
15
|
-
*
|
|
16
|
-
* const { reactor, useActorQuery, useActorMutation } = defineReactor<_SERVICE>({
|
|
17
|
-
* name: "backend",
|
|
18
|
-
* idlFactory,
|
|
19
|
-
* canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
20
|
-
* display: true, // ⇒ DisplayReactor (string principals/bigints)
|
|
21
|
-
* })
|
|
22
|
-
*
|
|
23
|
-
* function Profile() {
|
|
24
|
-
* const { data } = useActorQuery({ functionName: "get_profile" })
|
|
25
|
-
* return <div>{data?.name}</div>
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example Reuse an existing ClientManager (multiple canisters share one agent)
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const ledger = defineReactor<_LEDGER>({ name: "ledger", idlFactory: ledgerIdl })
|
|
32
|
-
* const index = defineReactor<_INDEX>({
|
|
33
|
-
* name: "index",
|
|
34
|
-
* idlFactory: indexIdl,
|
|
35
|
-
* clientManager: ledger.clientManager,
|
|
36
|
-
* authentication: ledger.authentication, // one Internet Identity session
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example Internet Identity is wired up out of the box
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const { useAuth, useIdentityAttributes } = defineReactor<_SERVICE>({
|
|
43
|
-
* name: "backend",
|
|
44
|
-
* idlFactory,
|
|
45
|
-
* // Needed when the app is served from more than one origin.
|
|
46
|
-
* auth: { derivationOrigin: "https://app.example.com" },
|
|
47
|
-
* })
|
|
48
|
-
*
|
|
49
|
-
* function LoginButton() {
|
|
50
|
-
* const { login, logout, isAuthenticated, principal } = useAuth()
|
|
51
|
-
* return isAuthenticated
|
|
52
|
-
* ? <button onClick={() => logout()}>{principal?.toText()}</button>
|
|
53
|
-
* : <button onClick={() => login()}>Sign in</button>
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
import { ClientManager, Reactor, DisplayReactor, reactorRetry, } from "@ic-reactor/core";
|
|
58
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
59
|
-
import { createActorHooks } from "./createActorHooks.js";
|
|
60
|
-
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
61
|
-
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
62
|
-
import { createIdentityAttributeHooks } from "./auth/createIdentityAttributeHooks.js";
|
|
63
|
-
import { createAuthHooks } from "./hooks/createAuthHooks.js";
|
|
64
|
-
/**
|
|
65
|
-
* The QueryClient this module creates when the caller does not supply one.
|
|
66
|
-
*
|
|
67
|
-
* React Query retries every failure three times by default, which for canister
|
|
68
|
-
* calls means four attempts and several seconds of backoff on outcomes that
|
|
69
|
-
* cannot change — a canister `Err`, a validation failure, a Candid encode
|
|
70
|
-
* error that never reached the network. `reactorRetry` keeps the same three
|
|
71
|
-
* attempts for transport failures and stops immediately on the rest.
|
|
72
|
-
*
|
|
73
|
-
* A caller-supplied `queryClient` is left exactly as given; opt in there with
|
|
74
|
-
* `defaultOptions: { queries: { retry: reactorRetry } }`.
|
|
75
|
-
*/
|
|
76
|
-
const createDefaultQueryClient = () => new QueryClient({
|
|
77
|
-
defaultOptions: { queries: { retry: reactorRetry } },
|
|
78
|
-
});
|
|
79
|
-
export function defineReactor(params) {
|
|
80
|
-
const { clientManager: providedClientManager, queryClient: providedQueryClient, authentication: providedAuthentication, auth, display, agentOptions, allowEnvConfig, allowEnvRootKey, name, idlFactory, canisterId, pollingOptions, } = params;
|
|
81
|
-
// A shared AuthenticationManager updates the identity on its own
|
|
82
|
-
// ClientManager. Giving this reactor a different one would leave its calls
|
|
83
|
-
// anonymous after sign-in, so adopt the manager's rather than building a new
|
|
84
|
-
// one, and refuse an explicit mismatch instead of splitting them silently.
|
|
85
|
-
if (providedClientManager &&
|
|
86
|
-
providedAuthentication &&
|
|
87
|
-
providedAuthentication.clientManager !== providedClientManager) {
|
|
88
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received an \`authentication\` manager bound to a different \`clientManager\`. ` +
|
|
89
|
-
`Sign-in would update the authentication manager's agent while this reactor calls through another one, ` +
|
|
90
|
-
`leaving its calls anonymous. Pass \`clientManager: authentication.clientManager\`, or omit \`clientManager\` to adopt it.`);
|
|
91
|
-
}
|
|
92
|
-
// `auth` configures a manager this call would build; an existing one is
|
|
93
|
-
// already constructed, so these options could only be dropped on the floor.
|
|
94
|
-
if (providedAuthentication && auth) {
|
|
95
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received both \`authentication\` and \`auth\`. ` +
|
|
96
|
-
`The supplied manager is already configured, so \`auth\` (${Object.keys(auth).join(", ")}) would be ignored. ` +
|
|
97
|
-
`Pass those options where that AuthenticationManager is created, or drop \`authentication\` to build one here.`);
|
|
98
|
-
}
|
|
99
|
-
// Same reasoning as `auth`, and it matters more here: an ignored
|
|
100
|
-
// `allowEnvConfig: false` reads as "I locked the cookie out" while the
|
|
101
|
-
// supplied manager carries whatever decision it was built with.
|
|
102
|
-
if ((providedClientManager || providedAuthentication) &&
|
|
103
|
-
(allowEnvConfig !== undefined || allowEnvRootKey !== undefined)) {
|
|
104
|
-
const passed = [
|
|
105
|
-
allowEnvConfig !== undefined && "allowEnvConfig",
|
|
106
|
-
allowEnvRootKey !== undefined && "allowEnvRootKey",
|
|
107
|
-
]
|
|
108
|
-
.filter(Boolean)
|
|
109
|
-
.join(", ");
|
|
110
|
-
throw new Error(`[ic-reactor] defineReactor("${name}") received both a ClientManager and \`${passed}\`. ` +
|
|
111
|
-
`That option is resolved when a ClientManager is constructed, so the supplied one already carries its own ` +
|
|
112
|
-
`decision and this would be ignored — silently changing nothing about whether the ic_env cookie is trusted. ` +
|
|
113
|
-
`Pass it where that ClientManager is created, or drop \`clientManager\` to build one here.`);
|
|
114
|
-
}
|
|
115
|
-
const clientManager = providedClientManager ??
|
|
116
|
-
providedAuthentication?.clientManager ??
|
|
117
|
-
new ClientManager({
|
|
118
|
-
queryClient: providedQueryClient ?? createDefaultQueryClient(),
|
|
119
|
-
agentOptions,
|
|
120
|
-
// Forwarded, not dropped: the type has always accepted these (it extends
|
|
121
|
-
// ClientManagerParameters) while the call ignored them, so the one
|
|
122
|
-
// documented setup path silently discarded the ic_env opt-in it advertised.
|
|
123
|
-
allowEnvConfig,
|
|
124
|
-
allowEnvRootKey,
|
|
125
|
-
});
|
|
126
|
-
// Always report the QueryClient actually in use: when a ClientManager is
|
|
127
|
-
// supplied or adopted, its own QueryClient is the one queries run against.
|
|
128
|
-
const queryClient = clientManager.queryClient;
|
|
129
|
-
const reactorConfig = {
|
|
130
|
-
clientManager,
|
|
131
|
-
name,
|
|
132
|
-
idlFactory,
|
|
133
|
-
canisterId,
|
|
134
|
-
pollingOptions,
|
|
135
|
-
};
|
|
136
|
-
// The Reactor / DisplayReactor union cannot be expressed through the shared
|
|
137
|
-
// implementation signature, so the body is intentionally untyped here; the
|
|
138
|
-
// public overloads above carry the precise types for callers.
|
|
139
|
-
const reactor = display
|
|
140
|
-
? new DisplayReactor({
|
|
141
|
-
...reactorConfig,
|
|
142
|
-
validators: params
|
|
143
|
-
.validators,
|
|
144
|
-
})
|
|
145
|
-
: new Reactor(reactorConfig);
|
|
146
|
-
// `reactor` is `any` above, which would let the overloads infer `Service`
|
|
147
|
-
// as `unknown` and type every hook's arguments as `never`.
|
|
148
|
-
const hooks = createActorHooks(reactor);
|
|
149
|
-
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
150
|
-
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|
|
151
|
-
// that never touch authentication should not pay for that.
|
|
152
|
-
let authenticationInstance;
|
|
153
|
-
const getAuthentication = () => (authenticationInstance ?? (authenticationInstance = providedAuthentication ??
|
|
154
|
-
new AuthenticationManager({ ...auth, clientManager })));
|
|
155
|
-
let identityAttributesInstance;
|
|
156
|
-
const getIdentityAttributes = () => (identityAttributesInstance ?? (identityAttributesInstance = new IdentityAttributesManager(getAuthentication())));
|
|
157
|
-
let authHooks;
|
|
158
|
-
const getAuthHooks = () => (authHooks ?? (authHooks = createAuthHooks(getAuthentication())));
|
|
159
|
-
let attributeHooks;
|
|
160
|
-
const getAttributeHooks = () => (attributeHooks ?? (attributeHooks = createIdentityAttributeHooks(getIdentityAttributes())));
|
|
161
|
-
return {
|
|
162
|
-
...hooks,
|
|
163
|
-
reactor,
|
|
164
|
-
clientManager,
|
|
165
|
-
queryClient,
|
|
166
|
-
// Stable wrappers: the hook call order inside them never changes, so the
|
|
167
|
-
// rules of hooks still hold.
|
|
168
|
-
useAuth: () => getAuthHooks().useAuth(),
|
|
169
|
-
useAgentState: () => getAuthHooks().useAgentState(),
|
|
170
|
-
useUserPrincipal: () => getAuthHooks().useUserPrincipal(),
|
|
171
|
-
useIdentityAttributes: () => getAttributeHooks().useIdentityAttributes(),
|
|
172
|
-
get authentication() {
|
|
173
|
-
return getAuthentication();
|
|
174
|
-
},
|
|
175
|
-
get identityAttributes() {
|
|
176
|
-
return getIdentityAttributes();
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=defineReactor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactor.js","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EACL,aAAa,EACb,OAAO,EACP,cAAc,EACd,YAAY,GACb,MAAM,kBAAkB,CAAA;AAQzB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAc,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAA;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AA2E5D;;;;;;;;;;;GAWG;AACH,MAAM,wBAAwB,GAAG,GAAG,EAAE,CACpC,IAAI,WAAW,CAAC;IACd,cAAc,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;CACrD,CAAC,CAAA;AAUJ,MAAM,UAAU,aAAa,CAC3B,MAAyE;IAEzE,MAAM,EACJ,aAAa,EAAE,qBAAqB,EACpC,WAAW,EAAE,mBAAmB,EAChC,cAAc,EAAE,sBAAsB,E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c,GAAK,4BAA4B,CAAC,qBAAqB,EAAE,CAAC,EAAC,CAAA;IAE5E,OAAO;QACL,GAAG,KAAK;QACR,OAAO;QACP,aAAa;QACb,WAAW;QACX,yEAAyE;QACzE,6BAA6B;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE;QACvC,aAAa,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE;QACnD,gBAAgB,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,gBAAgB,EAAE;QACzD,qBAAqB,EAAE,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,qBAAqB,EAAE;QACxE,IAAI,cAAc;YAChB,OAAO,iBAAiB,EAAE,CAAA;QAC5B,CAAC;QACD,IAAI,kBAAkB;YACpB,OAAO,qBAAqB,EAAE,CAAA;QAChC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { AuthenticationManager } from "../auth/authentication-manager.js";
|
|
2
|
-
import type { AuthenticationSignInOptions } from "../auth/types.js";
|
|
3
|
-
import type { AgentState } from "@ic-reactor/core";
|
|
4
|
-
import type { Principal } from "@icp-sdk/core/principal";
|
|
5
|
-
import type { Identity } from "@icp-sdk/core/agent";
|
|
6
|
-
export interface UseAuthReturn {
|
|
7
|
-
authenticate: () => Promise<Identity | undefined>;
|
|
8
|
-
login: (options?: AuthenticationSignInOptions) => Promise<void>;
|
|
9
|
-
logout: (options?: {
|
|
10
|
-
returnTo?: string;
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
isAuthenticated: boolean;
|
|
13
|
-
isAuthenticating: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The signed-in user's principal, or `null` while signed out. A signed-out
|
|
16
|
-
* session still holds an anonymous `identity`, and its principal is not
|
|
17
|
-
* returned here.
|
|
18
|
-
*/
|
|
19
|
-
principal: Principal | null;
|
|
20
|
-
identity: Identity | null;
|
|
21
|
-
error: Error | undefined;
|
|
22
|
-
}
|
|
23
|
-
export interface CreateAuthHooksReturn {
|
|
24
|
-
useAgentState: () => AgentState;
|
|
25
|
-
useUserPrincipal: () => Principal | null;
|
|
26
|
-
useAuth: () => UseAuthReturn;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Create authentication hooks for managing user sessions with Internet Identity.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(authentication)
|
|
33
|
-
*
|
|
34
|
-
* function App() {
|
|
35
|
-
* const { login, logout, principal, isAuthenticated } = useAuth()
|
|
36
|
-
*
|
|
37
|
-
* return isAuthenticated
|
|
38
|
-
* ? <button onClick={() => logout()}>Logout {principal?.toText()}</button>
|
|
39
|
-
* : <button onClick={() => login()}>Login with II</button>
|
|
40
|
-
* }
|
|
41
|
-
*/
|
|
42
|
-
export declare const createAuthHooks: (authentication: AuthenticationManager) => CreateAuthHooksReturn;
|
|
43
|
-
//# sourceMappingURL=createAuthHooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/createAuthHooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAa,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACjD,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,2BAA2B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D,eAAe,EAAE,OAAO,CAAA;IACxB,gBAAgB,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,UAAU,CAAA;IAC/B,gBAAgB,EAAE,MAAM,SAAS,GAAG,IAAI,CAAA;IACxC,OAAO,EAAE,MAAM,aAAa,CAAA;CAC7B;AAsBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,qBAAqB,KACpC,qBA2HF,CAAA"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore, useEffect, useRef, useMemo } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* The principal both hooks return.
|
|
4
|
-
*
|
|
5
|
-
* `authenticate()` and `logout()` leave the client's anonymous identity in
|
|
6
|
-
* `authState.identity` with `isAuthenticated: false`, so deriving the principal
|
|
7
|
-
* from the identity alone reported `2vxsx-fae` for a signed-out user, and
|
|
8
|
-
* `principal ? <SignedIn /> : <SignedOut />` rendered the signed-in branch.
|
|
9
|
-
* Memoized on the identity, because `getPrincipal()` may build a new object on
|
|
10
|
-
* each call and the result is often a hook dependency.
|
|
11
|
-
*/
|
|
12
|
-
function usePrincipal(isAuthenticated, identity) {
|
|
13
|
-
return useMemo(() => (isAuthenticated && identity ? identity.getPrincipal() : null), [isAuthenticated, identity]);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create authentication hooks for managing user sessions with Internet Identity.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(authentication)
|
|
20
|
-
*
|
|
21
|
-
* function App() {
|
|
22
|
-
* const { login, logout, principal, isAuthenticated } = useAuth()
|
|
23
|
-
*
|
|
24
|
-
* return isAuthenticated
|
|
25
|
-
* ? <button onClick={() => logout()}>Logout {principal?.toText()}</button>
|
|
26
|
-
* : <button onClick={() => login()}>Login with II</button>
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
|
-
export const createAuthHooks = (authentication) => {
|
|
30
|
-
// Passing a ClientManager here is the natural mistake — it is what
|
|
31
|
-
// `AuthenticationManager` is built from, and the two are adjacent in every
|
|
32
|
-
// setup snippet. TypeScript rejects it, but a JS caller got no error until
|
|
33
|
-
// render, where it surfaced as "Cannot destructure property 'isAuthenticated'
|
|
34
|
-
// of 'useAuthState(...)' as it is undefined" — which names neither the cause
|
|
35
|
-
// nor this function.
|
|
36
|
-
if (!authentication ||
|
|
37
|
-
typeof authentication.subscribeAuthState !== "function") {
|
|
38
|
-
throw new TypeError("[ic-reactor] createAuthHooks() expects an AuthenticationManager, not a " +
|
|
39
|
-
"ClientManager. Build one first: " +
|
|
40
|
-
"`new AuthenticationManager({ clientManager })`, or take it from " +
|
|
41
|
-
"`defineReactor(...).authentication`.");
|
|
42
|
-
}
|
|
43
|
-
const { clientManager } = authentication;
|
|
44
|
-
/**
|
|
45
|
-
* Subscribe to agent state changes.
|
|
46
|
-
* Returns the current agent state (agent, isInitialized, etc.)
|
|
47
|
-
*/
|
|
48
|
-
const useAgentState = () => useSyncExternalStore((callback) => clientManager.subscribeAgentState(callback), () => clientManager.agentState,
|
|
49
|
-
// Server snapshot - provide initial state for SSR
|
|
50
|
-
() => clientManager.agentState);
|
|
51
|
-
/**
|
|
52
|
-
* Subscribe to authentication state changes.
|
|
53
|
-
* Returns auth state (isAuthenticated, isAuthenticating, identity, error)
|
|
54
|
-
*/
|
|
55
|
-
const useAuthState = () => useSyncExternalStore((callback) => authentication.subscribeAuthState(callback), () => authentication.authState,
|
|
56
|
-
// Server snapshot - provide initial state for SSR
|
|
57
|
-
() => authentication.authState);
|
|
58
|
-
/**
|
|
59
|
-
* Main authentication hook that provides login/logout methods and auth state.
|
|
60
|
-
* Automatically initializes the session on first use, restoring any previous session.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* function AuthButton() {
|
|
64
|
-
* const { login, logout, isAuthenticated, isAuthenticating } = useAuth()
|
|
65
|
-
*
|
|
66
|
-
* if (isAuthenticated) {
|
|
67
|
-
* return <button onClick={() => logout()}>Logout</button>
|
|
68
|
-
* }
|
|
69
|
-
* return (
|
|
70
|
-
* <button onClick={() => login()} disabled={isAuthenticating}>
|
|
71
|
-
* {isAuthenticating ? "Connecting..." : "Login"}
|
|
72
|
-
* </button>
|
|
73
|
-
* )
|
|
74
|
-
* }
|
|
75
|
-
*/
|
|
76
|
-
const useAuth = () => {
|
|
77
|
-
const { login, logout, authenticate } = authentication;
|
|
78
|
-
const { isAuthenticated, isAuthenticating, identity, error } = useAuthState();
|
|
79
|
-
// Track if we've already initialized to avoid duplicate calls
|
|
80
|
-
const initializedRef = useRef(false);
|
|
81
|
-
// Auto-initialize on first mount to restore previous session.
|
|
82
|
-
// `prepareClient` also warms up the AuthClient so a later `login()` can
|
|
83
|
-
// open the identity provider window inside the click handler.
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if (!initializedRef.current) {
|
|
86
|
-
initializedRef.current = true;
|
|
87
|
-
authentication
|
|
88
|
-
.prepareClient()
|
|
89
|
-
.catch(() => undefined)
|
|
90
|
-
.then(() => clientManager.initialize())
|
|
91
|
-
.then(() => authentication.authenticate())
|
|
92
|
-
// Failures are already reflected in authState/agentState; without
|
|
93
|
-
// this the rejection escapes as an unhandled promise rejection.
|
|
94
|
-
.catch(() => undefined);
|
|
95
|
-
}
|
|
96
|
-
}, []);
|
|
97
|
-
const principal = usePrincipal(isAuthenticated, identity);
|
|
98
|
-
return {
|
|
99
|
-
authenticate,
|
|
100
|
-
login,
|
|
101
|
-
logout,
|
|
102
|
-
isAuthenticated,
|
|
103
|
-
isAuthenticating,
|
|
104
|
-
principal,
|
|
105
|
-
identity,
|
|
106
|
-
error,
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Get the current user's Principal.
|
|
111
|
-
* Returns null if not authenticated, including while the signed-out session
|
|
112
|
-
* holds the anonymous identity.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* function UserInfo() {
|
|
116
|
-
* const principal = useUserPrincipal()
|
|
117
|
-
* if (!principal) return null
|
|
118
|
-
* return <span>Logged in as: {principal.toText()}</span>
|
|
119
|
-
* }
|
|
120
|
-
*/
|
|
121
|
-
const useUserPrincipal = () => {
|
|
122
|
-
const { isAuthenticated, identity } = useAuthState();
|
|
123
|
-
return usePrincipal(isAuthenticated, identity);
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
useAuth,
|
|
127
|
-
useAgentState,
|
|
128
|
-
useUserPrincipal,
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
//# 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;AA6BxE;;;;;;;;;GASG;AACH,SAAS,YAAY,CACnB,eAAwB,EACxB,QAAyB;IAEzB,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,eAAe,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EACpE,CAAC,eAAe,EAAE,QAAQ,CAAC,CAC5B,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,e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AC,GAAG,EAAE;YACb,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;gBAC5B,cAAc,CAAC,OAAO,GAAG,IAAI,CAAA;gBAC7B,cAAc;qBACX,aAAa,EAAE;qBACf,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;qBACtB,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;qBACtC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;oBAC1C,kEAAkE;oBAClE,gEAAgE;qBAC/D,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;YAC3B,CAAC;QACH,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"}
|
package/dist/hooks/index.d.ts
DELETED
|
@@ -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","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGrE,OAAO,EAAE,gBAAgB,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG9E,OAAO,EAAE,qBAAqB,IAAI,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAG7F,OAAO,EAAE,qBAAqB,IAAI,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAG7F,OAAO,EAAE,6BAA6B,IAAI,+BAA+B,EAAE,MAAM,oCAAoC,CAAA;AAGrH,OAAO,EACL,cAAc,EACd,cAAc,IAAI,gBAAgB,EAClC,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,YAAY,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAMhF,YAAY,EACV,uBAAuB,IAAI,yBAAyB,EACpD,mBAAmB,IAAI,qBAAqB,GAC7C,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,0BAA0B,IAAI,4BAA4B,EAC1D,sBAAsB,IAAI,wBAAwB,GACnD,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EACV,+BAA+B,IAAI,iCAAiC,EACpE,2BAA2B,IAAI,6BAA6B,GAC7D,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,+BAA+B,IAAI,iCAAiC,EACpE,2BAA2B,IAAI,6BAA6B,GAC7D,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EACV,uCAAuC,IAAI,yCAAyC,EACpF,mCAAmC,IAAI,qCAAqC,GAC7E,MAAM,oCAAoC,CAAA;AAE3C,YAAY,EACV,wBAAwB,IAAI,0BAA0B,EACtD,oBAAoB,IAAI,sBAAsB,GAC/C,MAAM,qBAAqB,CAAA;AAM5B,YAAY,EACV,mBAAmB,IAAI,uBAAuB,EAC9C,mBAAmB,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"}
|
package/dist/hooks/index.js
DELETED
|
@@ -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
|
package/dist/hooks/index.js.map
DELETED
|
@@ -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,39 +0,0 @@
|
|
|
1
|
-
import { QueryKey, UseInfiniteQueryResult, UseInfiniteQueryOptions, InfiniteData } 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
|
-
/** Function to get args from page parameter */
|
|
14
|
-
getArgs: (pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>;
|
|
15
|
-
/** Agent call configuration (effectiveCanisterId, etc.) */
|
|
16
|
-
callConfig?: CallConfig;
|
|
17
|
-
/** Custom query key (auto-generated if not provided) */
|
|
18
|
-
queryKey?: QueryKey;
|
|
19
|
-
/** Initial page parameter */
|
|
20
|
-
initialPageParam: TPageParam;
|
|
21
|
-
/** Function to determine next page parameter */
|
|
22
|
-
getNextPageParam: (lastPage: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, allPages: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined | null;
|
|
23
|
-
}
|
|
24
|
-
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">;
|
|
25
|
-
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>>;
|
|
26
|
-
/**
|
|
27
|
-
* Hook for executing infinite/paginated query calls on a canister.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const { data, fetchNextPage, hasNextPage } = useActorInfiniteQuery({
|
|
31
|
-
* reactor,
|
|
32
|
-
* functionName: "getItems",
|
|
33
|
-
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }],
|
|
34
|
-
* initialPageParam: 0,
|
|
35
|
-
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
36
|
-
* })
|
|
37
|
-
*/
|
|
38
|
-
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, callConfig, queryKey, ...options }: UseActorInfiniteQueryParameters<Service, Method, Transform, TPageParam, Selected>) => UseActorInfiniteQueryResult<Service, Method, Transform, TPageParam, Selected>;
|
|
39
|
-
//# sourceMappingURL=useActorInfiniteQuery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3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,GAAG,OAAO,EACpB,QAAQ,GAAG,YAAY,CACrB,gBAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,EAC7D,UAAU,CACX,EACD,sEAOC,+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,CAmET,CAAA"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { useMemo, useCallback } from "react";
|
|
2
|
-
import { useInfiniteQuery, } from "@tanstack/react-query";
|
|
3
|
-
import { mergeFactoryQueryKey, normalizeQueryData } from "../utils.js";
|
|
4
|
-
/**
|
|
5
|
-
* Hook for executing infinite/paginated query calls on a canister.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const { data, fetchNextPage, hasNextPage } = useActorInfiniteQuery({
|
|
9
|
-
* reactor,
|
|
10
|
-
* functionName: "getItems",
|
|
11
|
-
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }],
|
|
12
|
-
* initialPageParam: 0,
|
|
13
|
-
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
14
|
-
* })
|
|
15
|
-
*/
|
|
16
|
-
export const useActorInfiniteQuery = ({ reactor, functionName, getArgs, callConfig, queryKey, ...options }) => {
|
|
17
|
-
// Always pass queryKey through generateQueryKey so it is merged with the
|
|
18
|
-
// reactor/function identity. Using the custom key verbatim would cause cache
|
|
19
|
-
// collisions if two different actors or methods share the same key string.
|
|
20
|
-
const baseQueryKey = useMemo(() => reactor.generateQueryKey({
|
|
21
|
-
functionName,
|
|
22
|
-
// Fold the call arguments into the key. They live in the `getArgs`
|
|
23
|
-
// closure rather than in the config, so without this two hooks on the
|
|
24
|
-
// same method with different arguments share one cache entry and
|
|
25
|
-
// serve each other's pages.
|
|
26
|
-
queryKey: mergeFactoryQueryKey(queryKey, undefined, getArgs(options.initialPageParam)),
|
|
27
|
-
}, callConfig), [
|
|
28
|
-
queryKey,
|
|
29
|
-
reactor,
|
|
30
|
-
// `canisterId` is mutable reactor state that `setCanisterId` can change,
|
|
31
|
-
// while `reactor` itself stays the same object — so it has to be a
|
|
32
|
-
// dependency in its own right or the key stays pinned to the old canister
|
|
33
|
-
// while the queryFn already calls the new one.
|
|
34
|
-
reactor.canisterId?.toString(),
|
|
35
|
-
functionName,
|
|
36
|
-
callConfig,
|
|
37
|
-
getArgs,
|
|
38
|
-
options.initialPageParam,
|
|
39
|
-
]);
|
|
40
|
-
// Memoize queryFn to prevent recreation on every render
|
|
41
|
-
const queryFn = useCallback(async ({ pageParam }) => {
|
|
42
|
-
const args = getArgs(pageParam);
|
|
43
|
-
const result = await reactor.callMethod({
|
|
44
|
-
functionName,
|
|
45
|
-
args,
|
|
46
|
-
callConfig,
|
|
47
|
-
});
|
|
48
|
-
return normalizeQueryData(result);
|
|
49
|
-
}, [reactor, functionName, getArgs, callConfig]);
|
|
50
|
-
return useInfiniteQuery({
|
|
51
|
-
queryKey: baseQueryKey,
|
|
52
|
-
queryFn,
|
|
53
|
-
...options,
|
|
54
|
-
}, reactor.queryClient);
|
|
55
|
-
};
|
|
56
|
-
//# 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,WAAW,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAEL,gBAAgB,GAIjB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAgFtE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CASnC,EACA,OAAO,EACP,YAAY,EACZ,OAAO,EACP,UAAU,EACV,QAAQ,EACR,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