@ic-reactor/react 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -13
- package/dist/auth/authentication-manager.d.ts +98 -0
- package/dist/auth/authentication-manager.d.ts.map +1 -0
- package/dist/auth/authentication-manager.js +532 -0
- package/dist/auth/authentication-manager.js.map +1 -0
- package/dist/auth/constants.d.ts +18 -0
- package/dist/auth/constants.d.ts.map +1 -0
- package/dist/auth/constants.js +18 -0
- package/dist/auth/constants.js.map +1 -0
- package/dist/auth/createIdentityAttributeHooks.d.ts +14 -0
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +1 -0
- package/dist/auth/createIdentityAttributeHooks.js +54 -0
- package/dist/auth/createIdentityAttributeHooks.js.map +1 -0
- package/dist/auth/identity-attributes-manager.d.ts +26 -0
- package/dist/auth/identity-attributes-manager.d.ts.map +1 -0
- package/dist/auth/identity-attributes-manager.js +108 -0
- package/dist/auth/identity-attributes-manager.js.map +1 -0
- package/dist/auth/identity-attributes.d.ts +19 -0
- package/dist/auth/identity-attributes.d.ts.map +1 -0
- package/dist/auth/identity-attributes.js +170 -0
- package/dist/auth/identity-attributes.js.map +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +182 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/createActorHooks.d.ts +16 -16
- package/dist/createActorHooks.d.ts.map +1 -1
- package/dist/createActorHooks.js +6 -6
- package/dist/createActorHooks.js.map +1 -1
- package/dist/createInfiniteQuery.d.ts +33 -33
- package/dist/createInfiniteQuery.d.ts.map +1 -1
- package/dist/createInfiniteQuery.js +6 -6
- package/dist/createInfiniteQuery.js.map +1 -1
- package/dist/createMutation.d.ts +13 -2
- package/dist/createMutation.d.ts.map +1 -1
- package/dist/createMutation.js +11 -0
- package/dist/createMutation.js.map +1 -1
- package/dist/createQuery.d.ts +13 -3
- package/dist/createQuery.d.ts.map +1 -1
- package/dist/createQuery.js +16 -6
- package/dist/createQuery.js.map +1 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +32 -32
- package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/createSuspenseInfiniteQuery.js +6 -6
- package/dist/createSuspenseInfiniteQuery.js.map +1 -1
- package/dist/createSuspenseQuery.d.ts +3 -3
- package/dist/createSuspenseQuery.d.ts.map +1 -1
- package/dist/createSuspenseQuery.js +1 -1
- package/dist/createSuspenseQuery.js.map +1 -1
- package/dist/defineReactor.d.ts +124 -0
- package/dist/defineReactor.d.ts.map +1 -0
- package/dist/defineReactor.js +145 -0
- package/dist/defineReactor.js.map +1 -0
- package/dist/{createAuthHooks.d.ts → hooks/createAuthHooks.d.ts} +6 -13
- package/dist/hooks/createAuthHooks.d.ts.map +1 -0
- package/dist/{createAuthHooks.js → hooks/createAuthHooks.js} +18 -58
- package/dist/hooks/createAuthHooks.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +9 -9
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.js +3 -1
- package/dist/hooks/useActorInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorMethod.d.ts +17 -17
- package/dist/hooks/useActorMethod.d.ts.map +1 -1
- package/dist/hooks/useActorMethod.js.map +1 -1
- package/dist/hooks/useActorMutation.d.ts +18 -7
- package/dist/hooks/useActorMutation.d.ts.map +1 -1
- package/dist/hooks/useActorMutation.js +11 -0
- package/dist/hooks/useActorMutation.js.map +1 -1
- package/dist/hooks/useActorQuery.d.ts +8 -8
- package/dist/hooks/useActorQuery.d.ts.map +1 -1
- package/dist/hooks/useActorQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +9 -9
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +3 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +8 -8
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.js.map +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -2
- package/dist/utils.js.map +1 -1
- package/llms.txt +48 -0
- package/package.json +34 -23
- package/src/auth/authentication-manager.ts +591 -0
- package/src/auth/constants.ts +25 -0
- package/src/auth/createIdentityAttributeHooks.ts +83 -0
- package/src/auth/identity-attributes-manager.ts +136 -0
- package/src/auth/identity-attributes.ts +270 -0
- package/src/auth/index.ts +7 -0
- package/src/auth/types.ts +204 -0
- package/src/createActorHooks.ts +90 -58
- package/src/createInfiniteQuery.ts +154 -98
- package/src/createMutation.ts +35 -19
- package/src/createQuery.ts +94 -50
- package/src/createSuspenseInfiniteQuery.ts +166 -115
- package/src/createSuspenseQuery.ts +69 -43
- package/src/defineReactor.ts +272 -0
- package/src/{createAuthHooks.ts → hooks/createAuthHooks.ts} +23 -99
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useActorInfiniteQuery.ts +44 -30
- package/src/hooks/useActorMethod.ts +62 -53
- package/src/hooks/useActorMutation.ts +47 -30
- package/src/hooks/useActorQuery.ts +36 -32
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +56 -30
- package/src/hooks/useActorSuspenseQuery.ts +42 -32
- package/src/index.ts +12 -10
- package/src/types.ts +76 -71
- package/src/utils.ts +15 -2
- package/dist/createAuthHooks.d.ts.map +0 -1
- package/dist/createAuthHooks.js.map +0 -1
- package/src/hooks/useActorInfiniteQuery.test.tsx +0 -457
- package/src/hooks/useActorMethod.test.tsx +0 -798
- package/src/hooks/useActorMutation.test.tsx +0 -220
- package/src/hooks/useActorQuery.test.tsx +0 -287
- package/src/hooks/useActorSuspenseInfiniteQuery.test.tsx +0 -472
- package/src/hooks/useActorSuspenseQuery.test.tsx +0 -254
|
@@ -23,60 +23,60 @@
|
|
|
23
23
|
* // Flatten all pages
|
|
24
24
|
* const allPosts = data.pages.flatMap(page => page.posts)
|
|
25
25
|
*/
|
|
26
|
-
import type { Reactor, FunctionName, ReactorArgs, BaseActor, TransformKey, ReactorReturnOk, ReactorReturnErr } from "@ic-reactor/core";
|
|
26
|
+
import type { Reactor, FunctionName, ReactorArgs, BaseActor, TransformKey, ReactorReturnOk, ReactorQueryData, ReactorReturnErr } from "@ic-reactor/core";
|
|
27
27
|
import { QueryKey, InfiniteData, UseSuspenseInfiniteQueryResult, UseSuspenseInfiniteQueryOptions, InfiniteQueryObserverOptions } from "@tanstack/react-query";
|
|
28
28
|
import { CallConfig } from "@icp-sdk/core/agent";
|
|
29
|
-
import { NoInfer } from "./types";
|
|
29
|
+
import { NoInfer } from "./types.js";
|
|
30
30
|
type SuspenseInfiniteFactoryCallOptions = {
|
|
31
31
|
queryKey?: QueryKey;
|
|
32
32
|
};
|
|
33
|
-
type SuspenseInfiniteQueryFactoryFn<
|
|
34
|
-
(getArgs: (pageParam: TPageParam) => ReactorArgs<
|
|
35
|
-
(getArgs: (pageParam: TPageParam) => ReactorArgs<
|
|
33
|
+
type SuspenseInfiniteQueryFactoryFn<Service, Method extends FunctionName<Service>, Transform extends TransformKey, TPageParam, Selected> = {
|
|
34
|
+
(getArgs: (pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>): SuspenseInfiniteQueryResult<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam, Selected, SuspenseInfiniteQueryError<Service, Method, Transform>>;
|
|
35
|
+
(getArgs: (pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>, options?: SuspenseInfiniteFactoryCallOptions): SuspenseInfiniteQueryResult<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam, Selected, SuspenseInfiniteQueryError<Service, Method, Transform>>;
|
|
36
36
|
};
|
|
37
37
|
/** The raw page data type returned by the query function */
|
|
38
|
-
export type SuspenseInfiniteQueryPageData<
|
|
38
|
+
export type SuspenseInfiniteQueryPageData<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> = ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>;
|
|
39
39
|
/** The error type for infinite queries */
|
|
40
|
-
export type SuspenseInfiniteQueryError<
|
|
40
|
+
export type SuspenseInfiniteQueryError<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> = ReactorReturnErr<Service, Method, Transform>;
|
|
41
41
|
/**
|
|
42
42
|
* Configuration for createActorSuspenseInfiniteQuery.
|
|
43
43
|
* Extends InfiniteQueryObserverOptions to accept all React Query options at the create level.
|
|
44
44
|
*
|
|
45
|
-
* @template
|
|
46
|
-
* @template
|
|
47
|
-
* @template
|
|
45
|
+
* @template Service - The actor interface type
|
|
46
|
+
* @template Method - The method name on the actor
|
|
47
|
+
* @template Transform - The transformation key (identity, display, etc.)
|
|
48
48
|
* @template TPageParam - The type of the page parameter
|
|
49
|
-
* @template
|
|
49
|
+
* @template Selected - The type returned after select transformation
|
|
50
50
|
*/
|
|
51
|
-
export interface SuspenseInfiniteQueryConfig<
|
|
51
|
+
export interface SuspenseInfiniteQueryConfig<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam>> extends Omit<InfiniteQueryObserverOptions<SuspenseInfiniteQueryPageData<Service, Method, Transform>, SuspenseInfiniteQueryError<Service, Method, Transform>, Selected, QueryKey, TPageParam>, "queryKey" | "queryFn"> {
|
|
52
52
|
/** The method to call on the canister */
|
|
53
|
-
functionName:
|
|
53
|
+
functionName: Method;
|
|
54
54
|
/** Call configuration for the actor method */
|
|
55
55
|
callConfig?: CallConfig;
|
|
56
56
|
/** Custom query key (optional, auto-generated if not provided) */
|
|
57
57
|
queryKey?: QueryKey;
|
|
58
58
|
/** Function to get args from page parameter */
|
|
59
|
-
getArgs: (pageParam: TPageParam) => ReactorArgs<
|
|
59
|
+
getArgs: (pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Configuration for createActorSuspenseInfiniteQueryFactory (without getArgs; provided at call time).
|
|
63
63
|
*/
|
|
64
|
-
export type SuspenseInfiniteQueryFactoryConfig<
|
|
64
|
+
export type SuspenseInfiniteQueryFactoryConfig<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam>> = Omit<SuspenseInfiniteQueryConfig<Service, Method, Transform, TPageParam, Selected>, "getArgs"> & {
|
|
65
65
|
/**
|
|
66
66
|
* Optional key-args derivation for factory calls.
|
|
67
67
|
* Receives the resolved args from `getArgs(initialPageParam)` and should return
|
|
68
68
|
* a stable serializable representation of the logical query identity
|
|
69
69
|
* (typically excluding pagination/cursor fields).
|
|
70
70
|
*/
|
|
71
|
-
getKeyArgs?: (args: ReactorArgs<
|
|
71
|
+
getKeyArgs?: (args: ReactorArgs<Service, Method, Transform>) => unknown;
|
|
72
72
|
};
|
|
73
73
|
/**
|
|
74
74
|
* useSuspenseInfiniteQuery hook with chained select support.
|
|
75
75
|
*/
|
|
76
|
-
export interface UseSuspenseInfiniteQueryWithSelect<TPageData, TPageParam,
|
|
77
|
-
(options?: Omit<UseSuspenseInfiniteQueryOptions<TPageData, TError,
|
|
78
|
-
<TFinal =
|
|
79
|
-
select: (data:
|
|
76
|
+
export interface UseSuspenseInfiniteQueryWithSelect<TPageData, TPageParam, Selected = InfiniteData<TPageData, TPageParam>, TError = Error> {
|
|
77
|
+
(options?: Omit<UseSuspenseInfiniteQueryOptions<TPageData, TError, Selected, QueryKey, TPageParam>, "select" | "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam" | "getPreviousPageParam">): UseSuspenseInfiniteQueryResult<Selected, TError>;
|
|
78
|
+
<TFinal = Selected>(options: Omit<UseSuspenseInfiniteQueryOptions<TPageData, TError, TFinal, QueryKey, TPageParam>, "queryKey" | "queryFn" | "select" | "initialPageParam" | "getNextPageParam" | "getPreviousPageParam"> & {
|
|
79
|
+
select: (data: Selected) => TFinal;
|
|
80
80
|
}): UseSuspenseInfiniteQueryResult<TFinal, TError>;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
@@ -84,14 +84,14 @@ export interface UseSuspenseInfiniteQueryWithSelect<TPageData, TPageParam, TSele
|
|
|
84
84
|
*
|
|
85
85
|
* @template TPageData - The raw page data type
|
|
86
86
|
* @template TPageParam - The page parameter type
|
|
87
|
-
* @template
|
|
87
|
+
* @template Selected - The type after select transformation
|
|
88
88
|
* @template TError - The error type
|
|
89
89
|
*/
|
|
90
|
-
export interface SuspenseInfiniteQueryResult<TPageData, TPageParam,
|
|
90
|
+
export interface SuspenseInfiniteQueryResult<TPageData, TPageParam, Selected = InfiniteData<TPageData, TPageParam>, TError = Error> {
|
|
91
91
|
/** Fetch first page in loader (uses ensureInfiniteQueryData for cache-first) */
|
|
92
|
-
fetch: () => Promise<
|
|
92
|
+
fetch: () => Promise<Selected>;
|
|
93
93
|
/** React hook for components - supports pagination */
|
|
94
|
-
useSuspenseInfiniteQuery: UseSuspenseInfiniteQueryWithSelect<TPageData, TPageParam,
|
|
94
|
+
useSuspenseInfiniteQuery: UseSuspenseInfiniteQueryWithSelect<TPageData, TPageParam, Selected, TError>;
|
|
95
95
|
/** Invalidate the cache (refetches if query is active) */
|
|
96
96
|
invalidate: () => Promise<void>;
|
|
97
97
|
/** Get query key (for advanced React Query usage) */
|
|
@@ -101,20 +101,20 @@ export interface SuspenseInfiniteQueryResult<TPageData, TPageParam, TSelected =
|
|
|
101
101
|
* Returns undefined if data is not in cache.
|
|
102
102
|
*/
|
|
103
103
|
getCacheData: {
|
|
104
|
-
():
|
|
105
|
-
<TFinal>(select: (data:
|
|
104
|
+
(): Selected | undefined;
|
|
105
|
+
<TFinal>(select: (data: Selected) => TFinal): TFinal | undefined;
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
export declare function createSuspenseInfiniteQuery<
|
|
108
|
+
export declare function createSuspenseInfiniteQuery<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, TPageParam = unknown, Selected = InfiniteData<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam>>(reactor: Reactor<Service, Transform>, config: SuspenseInfiniteQueryConfig<NoInfer<Service>, Method, Transform, TPageParam, Selected>): SuspenseInfiniteQueryResult<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam, Selected, SuspenseInfiniteQueryError<Service, Method, Transform>>;
|
|
109
109
|
/**
|
|
110
110
|
* Create a suspense infinite query factory that accepts getArgs at call time.
|
|
111
111
|
* Useful when pagination logic varies by context.
|
|
112
112
|
*
|
|
113
|
-
* @template
|
|
114
|
-
* @template
|
|
115
|
-
* @template
|
|
113
|
+
* @template Service - The actor interface type
|
|
114
|
+
* @template Method - The method name on the actor
|
|
115
|
+
* @template Transform - The transformation key (identity, display, etc.)
|
|
116
116
|
* @template TPageParam - The page parameter type
|
|
117
|
-
* @template
|
|
117
|
+
* @template Selected - The type returned after select transformation
|
|
118
118
|
*
|
|
119
119
|
* @param reactor - The Reactor instance
|
|
120
120
|
* @param config - Suspense infinite query configuration (without getArgs)
|
|
@@ -141,6 +141,6 @@ export declare function createSuspenseInfiniteQuery<A, T extends TransformKey, M
|
|
|
141
141
|
* { queryKey: ["v2"] }
|
|
142
142
|
* )
|
|
143
143
|
*/
|
|
144
|
-
export declare function createSuspenseInfiniteQueryFactory<
|
|
144
|
+
export declare function createSuspenseInfiniteQueryFactory<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, TPageParam = unknown, Selected = InfiniteData<SuspenseInfiniteQueryPageData<Service, Method, Transform>, TPageParam>>(reactor: Reactor<Service, Transform>, config: SuspenseInfiniteQueryFactoryConfig<NoInfer<Service>, Method, Transform, TPageParam, Selected>): SuspenseInfiniteQueryFactoryFn<Service, Method, Transform, TPageParam, Selected>;
|
|
145
145
|
export {};
|
|
146
146
|
//# sourceMappingURL=createSuspenseInfiniteQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/createSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,QAAQ,EAER,YAAY,EACZ,8BAA8B,EAC9B,+BAA+B,EAG/B,4BAA4B,EAC7B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createSuspenseInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/createSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,C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,YAAY,CAAC,OAAO,CAAC,EAC5D,UAAU,GAAG,OAAO,EACpB,QAAQ,GAAG,YAAY,CACrB,6BAA6B,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACzD,UAAU,CACX,EAED,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EACpC,MAAM,EAAE,kCAAkC,CACxC,OAAO,CAAC,OAAO,CAAC,EAChB,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,CACT,GACA,8BAA8B,CAC/B,OAAO,EACP,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,CACT,CA+CA"}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* const allPosts = data.pages.flatMap(page => page.posts)
|
|
25
25
|
*/
|
|
26
26
|
import { useSuspenseInfiniteQuery, } from "@tanstack/react-query";
|
|
27
|
-
import { mergeFactoryQueryKey } from "./utils";
|
|
27
|
+
import { mergeFactoryQueryKey, normalizeQueryData } from "./utils.js";
|
|
28
28
|
// ============================================================================
|
|
29
29
|
// Internal Implementation
|
|
30
30
|
// ============================================================================
|
|
@@ -47,7 +47,7 @@ const createSuspenseInfiniteQueryImpl = (reactor, config) => {
|
|
|
47
47
|
args,
|
|
48
48
|
callConfig,
|
|
49
49
|
});
|
|
50
|
-
return result;
|
|
50
|
+
return normalizeQueryData(result);
|
|
51
51
|
};
|
|
52
52
|
// Get infinite query options for fetchInfiniteQuery
|
|
53
53
|
const getInfiniteQueryOptions = () => ({
|
|
@@ -128,11 +128,11 @@ export function createSuspenseInfiniteQuery(reactor, config) {
|
|
|
128
128
|
* Create a suspense infinite query factory that accepts getArgs at call time.
|
|
129
129
|
* Useful when pagination logic varies by context.
|
|
130
130
|
*
|
|
131
|
-
* @template
|
|
132
|
-
* @template
|
|
133
|
-
* @template
|
|
131
|
+
* @template Service - The actor interface type
|
|
132
|
+
* @template Method - The method name on the actor
|
|
133
|
+
* @template Transform - The transformation key (identity, display, etc.)
|
|
134
134
|
* @template TPageParam - The page parameter type
|
|
135
|
-
* @template
|
|
135
|
+
* @template Selected - The type returned after select transformation
|
|
136
136
|
*
|
|
137
137
|
* @param reactor - The Reactor instance
|
|
138
138
|
* @param config - Suspense infinite query configuration (without getArgs)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseInfiniteQuery.js","sourceRoot":"","sources":["../src/createSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"createSuspenseInfiniteQuery.js","sourceRoot":"","sources":["../src/createSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAYH,OAAO,EAEL,wBAAwB,GAOzB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAyNrE,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,MAAM,+BAA+B,GAAG,CAUtC,OAAoC,EACpC,MAMC,EAMD,EAAE;IAKF,MAAM,EACJ,YAAY,EACZ,UAAU,EACV,QAAQ,EAAE,cAAc,EACxB,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EACR,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,EACzB,MAAM,EACN,GAAG,IAAI,EACR,GAAG,MAAM,CAAA;IAEV,mCAAmC;IACnC,MAAM,WAAW,GAAG,GAAa,EAAE;QACjC,OAAO,OAAO,CAAC,gBAAgB,CAC7B;YACE,YAAY;YACZ,QAAQ,EAAE,cAAc;SACzB,EACD,UAAU,CACX,CAAA;IACH,CAAC,CAAA;IAED,gDAAgD;IAChD,MAAM,OAAO,GAAG,KAAK,EACnB,OAAmD,EAC/B,EAAE;QACtB,8EAA8E;QAC9E,MAAM,SAAS,GAAG,OAAO,CAAC,SAAuB,CAAA;QACjD,MA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,MAMC;IAQD,MAAM,OAAO,GAMT,CACF,OAA2E,EAC3E,OAA4C,EAC5C,EAAE;QACF,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;QACpD,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,WAAW,CAAC,IAAI,WAAW,CAAA;QAC/D,MAAM,QAAQ,GAAG,oBAAoB,CACnC,MAAM,CAAC,QAAQ,EACf,OAAO,EAAE,QAAQ,EACjB,OAAO,CACR,CAAA;QAED,OAAO,+BAA+B,CAMpC,OAAO,EAAE;YACT,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CACjD,MAMC,CACF;YACD,QAAQ;YACR,OAAO;SAOR,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* const { data: user } = userQuery.useSuspenseQuery() // data is never undefined!
|
|
20
20
|
*/
|
|
21
21
|
import type { Reactor, FunctionName, ReactorArgs, TransformKey } from "@ic-reactor/core";
|
|
22
|
-
import type { QueryFnData, QueryError, SuspenseQueryConfig, SuspenseQueryResult, SuspenseQueryFactoryConfig, NoInfer } from "./types";
|
|
23
|
-
export declare function createSuspenseQuery<
|
|
24
|
-
export declare function createSuspenseQueryFactory<
|
|
22
|
+
import type { QueryFnData, QueryError, SuspenseQueryConfig, SuspenseQueryResult, SuspenseQueryFactoryConfig, NoInfer } from "./types.js";
|
|
23
|
+
export declare function createSuspenseQuery<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, Selected = QueryFnData<Service, Method, Transform>>(reactor: Reactor<Service, Transform>, config: SuspenseQueryConfig<NoInfer<Service>, Method, Transform, Selected>): SuspenseQueryResult<QueryFnData<Service, Method, Transform>, Selected, QueryError<Service, Method, Transform>>;
|
|
24
|
+
export declare function createSuspenseQueryFactory<Service, Transform extends TransformKey, Method extends FunctionName<Service> = FunctionName<Service>, Selected = QueryFnData<Service, Method, Transform>>(reactor: Reactor<Service, Transform>, config: SuspenseQueryFactoryConfig<NoInfer<Service>, Method, Transform, Selected>): (args: ReactorArgs<Service, Method, Transform>) => SuspenseQueryResult<QueryFnData<Service, Method, Transform>, Selected, QueryError<Service, Method, Transform>>;
|
|
25
25
|
//# sourceMappingURL=createSuspenseQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseQuery.d.ts","sourceRoot":"","sources":["../src/createSuspenseQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,mBAAmB,EAEnB,mBAAmB,EACnB,0BAA0B,EAC1B,OAAO,EACR,MAAM,
|
|
1
|
+
{"version":3,"file":"createSuspenseQuery.d.ts","sourceRoot":"","sources":["../src/createSuspenseQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,mBAAmB,EAEnB,mBAAmB,EACnB,0BAA0B,EAC1B,OAAO,EACR,MAAM,YAAY,CAAA;AA+GnB,wBAAgB,mBAAmB,CACjC,OAAO,EACP,SAAS,SAAS,YAAY,EAC9B,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,EAC5D,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAElD,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EACpC,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,GACzE,mBAAmB,CACpB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACvC,QAAQ,EACR,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CACvC,CAKA;AAMD,wBAAgB,0BAA0B,CACxC,OAAO,EACP,SAAS,SAAS,YAAY,EAC9B,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,EAC5D,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAElD,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EACpC,MAAM,EAAE,0BAA0B,CAChC,OAAO,CAAC,OAAO,CAAC,EAChB,MAAM,EACN,SAAS,EACT,QAAQ,CACT,GACA,CACD,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,KAC1C,mBAAmB,CACtB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACvC,QAAQ,EACR,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CACvC,CAqCA"}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* const { data: user } = userQuery.useSuspenseQuery() // data is never undefined!
|
|
20
20
|
*/
|
|
21
21
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
|
22
|
-
import { buildChainedSelect } from "./utils";
|
|
22
|
+
import { buildChainedSelect } from "./utils.js";
|
|
23
23
|
// ============================================================================
|
|
24
24
|
// Internal Implementation
|
|
25
25
|
// ============================================================================
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseQuery.js","sourceRoot":"","sources":["../src/createSuspenseQuery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAQH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AAgB,EAAE,oBAAoB;QACtC,UAAU;QACV,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAA;AACH,CAAC,CAAA;AAED,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,MAAM,UAAU,mBAAmB,CAMjC,OAAoC,EACpC,MAA0E;IAM1E,OAAO,uBAAuB,CAC5B,OAAO,EACP,MAAmE,CACpE,CAAA;AACH,CAAC;AAED,+EAA+E;AAC/E,uDAAuD;AACvD,+EAA+E;AAE/E,MAAM,UAAU,0BAA0B,CAMxC,OAAoC,EACpC,MAKC;IAQD,MAAM,KAAK,GAAG,IAAI,GAAG,EAOlB,CAAA;IAEH,OAAO,CAAC,IAA6C,EAAE,EAAE;QACvD,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC;YACnC,YAAY,EAAE,MAAM,CAAC,YAAsB;YAC3C,IAAI;SACL,CAAC,CAAA;QACF,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAEpC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACpC,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAA;QAE7B,MAAM,MAAM,GAAG,uBAAuB,CAKpC,OAAO,EAAE;YACT,GAAI,MAKF;YACF,IAAI;SACL,CAAC,CAAA;QACF,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC3B,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 } from "@ic-reactor/core";
|
|
58
|
+
import type { BaseActor, TransformKey, ReactorParameters, ClientManagerParameters, DisplayReactorParameters } from "@ic-reactor/core";
|
|
59
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
60
|
+
import { ActorHooks } from "./createActorHooks.js";
|
|
61
|
+
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
62
|
+
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
63
|
+
import type { UseIdentityAttributesReturn } from "./auth/createIdentityAttributeHooks.js";
|
|
64
|
+
import type { CreateAuthHooksReturn } from "./hooks/createAuthHooks.js";
|
|
65
|
+
import type { AuthenticationManagerParameters } from "./auth/authentication-manager.js";
|
|
66
|
+
/** Options shared by both the standard and display variants of defineReactor. */
|
|
67
|
+
export interface DefineReactorSharedParameters extends Omit<ReactorParameters, "clientManager">, Omit<ClientManagerParameters, "queryClient"> {
|
|
68
|
+
/**
|
|
69
|
+
* Reuse an existing ClientManager (e.g. to share one agent across canisters).
|
|
70
|
+
* When omitted, a ClientManager is created from the agent options below.
|
|
71
|
+
*
|
|
72
|
+
* A supplied or adopted manager brings its own agent and QueryClient, so
|
|
73
|
+
* `agentOptions` and `queryClient` apply only when this call creates one.
|
|
74
|
+
*/
|
|
75
|
+
clientManager?: ClientManager;
|
|
76
|
+
/**
|
|
77
|
+
* QueryClient for a ClientManager created by this call.
|
|
78
|
+
*
|
|
79
|
+
* Ignored when `clientManager` or `authentication` is supplied — queries run
|
|
80
|
+
* against that manager's own QueryClient, which is what is returned.
|
|
81
|
+
*/
|
|
82
|
+
queryClient?: QueryClient;
|
|
83
|
+
/**
|
|
84
|
+
* Reuse an existing AuthenticationManager, so several reactors share one
|
|
85
|
+
* Internet Identity session. When omitted, one is created for this reactor.
|
|
86
|
+
*
|
|
87
|
+
* Its `clientManager` is adopted for this reactor, so sign-in updates the
|
|
88
|
+
* same agent the reactor calls through. Supplying a different `clientManager`
|
|
89
|
+
* alongside it is rejected.
|
|
90
|
+
*/
|
|
91
|
+
authentication?: AuthenticationManager;
|
|
92
|
+
/**
|
|
93
|
+
* Internet Identity options forwarded to the AuthenticationManager
|
|
94
|
+
* (`identityProvider`, `derivationOrigin`, `idleOptions`, `storage`, …).
|
|
95
|
+
*
|
|
96
|
+
* Mutually exclusive with `authentication`: a manager built elsewhere is
|
|
97
|
+
* already configured, so these could not be applied to it.
|
|
98
|
+
*/
|
|
99
|
+
auth?: Omit<AuthenticationManagerParameters, "clientManager">;
|
|
100
|
+
}
|
|
101
|
+
/** Parameters for a standard (raw Candid types) reactor. */
|
|
102
|
+
export interface DefineReactorParameters extends DefineReactorSharedParameters {
|
|
103
|
+
display?: false;
|
|
104
|
+
}
|
|
105
|
+
/** Parameters for a DisplayReactor (UI-friendly string principals/bigints). */
|
|
106
|
+
export interface DefineDisplayReactorParameters<Service> extends DefineReactorSharedParameters {
|
|
107
|
+
display: true;
|
|
108
|
+
/** Optional initial argument validators (receive display types). */
|
|
109
|
+
validators?: DisplayReactorParameters<Service>["validators"];
|
|
110
|
+
}
|
|
111
|
+
/** The reactor instance plus its bound hooks and shared infrastructure. */
|
|
112
|
+
export type DefineReactorResult<Service, Transform extends TransformKey, R extends Reactor<Service, Transform>> = ActorHooks<Service, Transform> & CreateAuthHooksReturn & {
|
|
113
|
+
reactor: R;
|
|
114
|
+
clientManager: ClientManager;
|
|
115
|
+
queryClient: QueryClient;
|
|
116
|
+
/** Internet Identity session manager backing `useAuth`. */
|
|
117
|
+
authentication: AuthenticationManager;
|
|
118
|
+
/** Signed identity attribute requests backing `useIdentityAttributes`. */
|
|
119
|
+
identityAttributes: IdentityAttributesManager;
|
|
120
|
+
useIdentityAttributes: () => UseIdentityAttributesReturn;
|
|
121
|
+
};
|
|
122
|
+
export declare function defineReactor<Service = BaseActor>(params: DefineDisplayReactorParameters<Service>): DefineReactorResult<Service, "display", DisplayReactor<Service>>;
|
|
123
|
+
export declare function defineReactor<Service = BaseActor>(params: DefineReactorParameters): DefineReactorResult<Service, "candid", Reactor<Service, "candid">>;
|
|
124
|
+
//# sourceMappingURL=defineReactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineReactor.d.ts","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAoB,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AAEzF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAEvF,iFAAiF;AACjF,MAAM,WAAW,6BACf,SACE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACxC,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC;IAC9C;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,WAAW,CA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}
|
|
@@ -0,0 +1,145 @@
|
|
|
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 } 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
|
+
export function defineReactor(params
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
) {
|
|
67
|
+
const { clientManager: providedClientManager, queryClient: providedQueryClient, authentication: providedAuthentication, auth, display, agentOptions, name, idlFactory, canisterId, pollingOptions, } = params;
|
|
68
|
+
// A shared AuthenticationManager updates the identity on its own
|
|
69
|
+
// ClientManager. Giving this reactor a different one would leave its calls
|
|
70
|
+
// anonymous after sign-in, so adopt the manager's rather than building a new
|
|
71
|
+
// one, and refuse an explicit mismatch instead of splitting them silently.
|
|
72
|
+
if (providedClientManager &&
|
|
73
|
+
providedAuthentication &&
|
|
74
|
+
providedAuthentication.clientManager !== providedClientManager) {
|
|
75
|
+
throw new Error(`[ic-reactor] defineReactor("${name}") received an \`authentication\` manager bound to a different \`clientManager\`. ` +
|
|
76
|
+
`Sign-in would update the authentication manager's agent while this reactor calls through another one, ` +
|
|
77
|
+
`leaving its calls anonymous. Pass \`clientManager: authentication.clientManager\`, or omit \`clientManager\` to adopt it.`);
|
|
78
|
+
}
|
|
79
|
+
// `auth` configures a manager this call would build; an existing one is
|
|
80
|
+
// already constructed, so these options could only be dropped on the floor.
|
|
81
|
+
if (providedAuthentication && auth) {
|
|
82
|
+
throw new Error(`[ic-reactor] defineReactor("${name}") received both \`authentication\` and \`auth\`. ` +
|
|
83
|
+
`The supplied manager is already configured, so \`auth\` (${Object.keys(auth).join(", ")}) would be ignored. ` +
|
|
84
|
+
`Pass those options where that AuthenticationManager is created, or drop \`authentication\` to build one here.`);
|
|
85
|
+
}
|
|
86
|
+
const clientManager = providedClientManager ??
|
|
87
|
+
providedAuthentication?.clientManager ??
|
|
88
|
+
new ClientManager({
|
|
89
|
+
queryClient: providedQueryClient ?? new QueryClient(),
|
|
90
|
+
agentOptions,
|
|
91
|
+
});
|
|
92
|
+
// Always report the QueryClient actually in use: when a ClientManager is
|
|
93
|
+
// supplied or adopted, its own QueryClient is the one queries run against.
|
|
94
|
+
const queryClient = clientManager.queryClient;
|
|
95
|
+
const reactorConfig = {
|
|
96
|
+
clientManager,
|
|
97
|
+
name,
|
|
98
|
+
idlFactory,
|
|
99
|
+
canisterId,
|
|
100
|
+
pollingOptions,
|
|
101
|
+
};
|
|
102
|
+
// The Reactor / DisplayReactor union cannot be expressed through the shared
|
|
103
|
+
// implementation signature, so the body is intentionally untyped here; the
|
|
104
|
+
// public overloads above carry the precise types for callers.
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
+
const reactor = display
|
|
107
|
+
? new DisplayReactor({
|
|
108
|
+
...reactorConfig,
|
|
109
|
+
validators: params
|
|
110
|
+
.validators,
|
|
111
|
+
})
|
|
112
|
+
: new Reactor(reactorConfig);
|
|
113
|
+
const hooks = createActorHooks(reactor);
|
|
114
|
+
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
115
|
+
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|
|
116
|
+
// that never touch authentication should not pay for that.
|
|
117
|
+
let authenticationInstance;
|
|
118
|
+
const getAuthentication = () => (authenticationInstance ?? (authenticationInstance = providedAuthentication ??
|
|
119
|
+
new AuthenticationManager({ ...auth, clientManager })));
|
|
120
|
+
let identityAttributesInstance;
|
|
121
|
+
const getIdentityAttributes = () => (identityAttributesInstance ?? (identityAttributesInstance = new IdentityAttributesManager(getAuthentication())));
|
|
122
|
+
let authHooks;
|
|
123
|
+
const getAuthHooks = () => (authHooks ?? (authHooks = createAuthHooks(getAuthentication())));
|
|
124
|
+
let attributeHooks;
|
|
125
|
+
const getAttributeHooks = () => (attributeHooks ?? (attributeHooks = createIdentityAttributeHooks(getIdentityAttributes())));
|
|
126
|
+
return {
|
|
127
|
+
...hooks,
|
|
128
|
+
reactor,
|
|
129
|
+
clientManager,
|
|
130
|
+
queryClient,
|
|
131
|
+
// Stable wrappers: the hook call order inside them never changes, so the
|
|
132
|
+
// rules of hooks still hold.
|
|
133
|
+
useAuth: () => getAuthHooks().useAuth(),
|
|
134
|
+
useAgentState: () => getAuthHooks().useAgentState(),
|
|
135
|
+
useUserPrincipal: () => getAuthHooks().useUserPrincipal(),
|
|
136
|
+
useIdentityAttributes: () => getAttributeHooks().useIdentityAttributes(),
|
|
137
|
+
get authentication() {
|
|
138
|
+
return getAuthentication();
|
|
139
|
+
},
|
|
140
|
+
get identityAttributes() {
|
|
141
|
+
return getIdentityAttributes();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=defineReactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineReactor.js","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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d,cAAc,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,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
2
4
|
import type { Principal } from "@icp-sdk/core/principal";
|
|
3
5
|
import type { Identity } from "@icp-sdk/core/agent";
|
|
4
6
|
export interface UseAuthReturn {
|
|
5
7
|
authenticate: () => Promise<Identity | undefined>;
|
|
6
|
-
login: (options?:
|
|
8
|
+
login: (options?: AuthenticationSignInOptions) => Promise<void>;
|
|
7
9
|
logout: (options?: {
|
|
8
10
|
returnTo?: string;
|
|
9
11
|
}) => Promise<void>;
|
|
@@ -17,21 +19,12 @@ export interface CreateAuthHooksReturn {
|
|
|
17
19
|
useAgentState: () => AgentState;
|
|
18
20
|
useUserPrincipal: () => Principal | null;
|
|
19
21
|
useAuth: () => UseAuthReturn;
|
|
20
|
-
useIdentityAttributes: () => UseIdentityAttributesReturn;
|
|
21
|
-
}
|
|
22
|
-
export interface UseIdentityAttributesReturn {
|
|
23
|
-
requestAttributes: (params: RequestIdentityAttributesParameters) => Promise<IdentityAttributeResult>;
|
|
24
|
-
requestOpenIdAttributes: (params: RequestOpenIdIdentityAttributesParameters) => Promise<IdentityAttributeResult>;
|
|
25
|
-
attributes: IdentityAttributeResult | null;
|
|
26
|
-
isRequestingAttributes: boolean;
|
|
27
|
-
attributeError: Error | null;
|
|
28
|
-
clearAttributes: () => void;
|
|
29
22
|
}
|
|
30
23
|
/**
|
|
31
24
|
* Create authentication hooks for managing user sessions with Internet Identity.
|
|
32
25
|
*
|
|
33
26
|
* @example
|
|
34
|
-
* const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(
|
|
27
|
+
* const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(authentication)
|
|
35
28
|
*
|
|
36
29
|
* function App() {
|
|
37
30
|
* const { login, logout, principal, isAuthenticated } = useAuth()
|
|
@@ -41,5 +34,5 @@ export interface UseIdentityAttributesReturn {
|
|
|
41
34
|
* : <button onClick={login}>Login with II</button>
|
|
42
35
|
* }
|
|
43
36
|
*/
|
|
44
|
-
export declare const createAuthHooks: (
|
|
37
|
+
export declare const createAuthHooks: (authentication: AuthenticationManager) => CreateAuthHooksReturn;
|
|
45
38
|
//# sourceMappingURL=createAuthHooks.d.ts.map
|