@ic-reactor/react 3.12.4 → 3.13.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 +410 -44
- package/dist/auth/auth-client-compat.d.ts +122 -0
- package/dist/auth/auth-client-compat.d.ts.map +1 -0
- package/dist/auth/auth-client-compat.js +162 -0
- package/dist/auth/auth-client-compat.js.map +1 -0
- package/dist/auth/authentication-manager.d.ts +287 -5
- package/dist/auth/authentication-manager.d.ts.map +1 -1
- package/dist/auth/authentication-manager.js +920 -150
- package/dist/auth/authentication-manager.js.map +1 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +1 -1
- package/dist/auth/createIdentityAttributeHooks.js +36 -20
- package/dist/auth/createIdentityAttributeHooks.js.map +1 -1
- package/dist/auth/identity-attributes-manager.d.ts +2 -1
- package/dist/auth/identity-attributes-manager.d.ts.map +1 -1
- package/dist/auth/identity-attributes-manager.js +90 -6
- package/dist/auth/identity-attributes-manager.js.map +1 -1
- package/dist/auth/identity-attributes.d.ts.map +1 -1
- package/dist/auth/identity-attributes.js +57 -0
- package/dist/auth/identity-attributes.js.map +1 -1
- package/dist/auth/local-ii-probe.d.ts +12 -1
- package/dist/auth/local-ii-probe.d.ts.map +1 -1
- package/dist/auth/local-ii-probe.js +22 -3
- package/dist/auth/local-ii-probe.js.map +1 -1
- package/dist/auth/types.d.ts +48 -5
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/createActorHooks.d.ts +9 -20
- package/dist/createActorHooks.d.ts.map +1 -1
- package/dist/createActorHooks.js.map +1 -1
- package/dist/createInfiniteQuery.d.ts +51 -10
- package/dist/createInfiniteQuery.d.ts.map +1 -1
- package/dist/createInfiniteQuery.js +39 -15
- package/dist/createInfiniteQuery.js.map +1 -1
- package/dist/createMutation.d.ts +4 -1
- package/dist/createMutation.d.ts.map +1 -1
- package/dist/createMutation.js +121 -84
- package/dist/createMutation.js.map +1 -1
- package/dist/createQuery.d.ts +35 -2
- package/dist/createQuery.d.ts.map +1 -1
- package/dist/createQuery.js +104 -17
- package/dist/createQuery.js.map +1 -1
- package/dist/createReactorProvider.d.ts +158 -0
- package/dist/createReactorProvider.d.ts.map +1 -0
- package/dist/createReactorProvider.js +256 -0
- package/dist/createReactorProvider.js.map +1 -0
- package/dist/createSuspenseInfiniteQuery.d.ts +16 -9
- package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/createSuspenseInfiniteQuery.js +59 -27
- package/dist/createSuspenseInfiniteQuery.js.map +1 -1
- package/dist/createSuspenseQuery.d.ts +23 -2
- package/dist/createSuspenseQuery.d.ts.map +1 -1
- package/dist/createSuspenseQuery.js +68 -21
- package/dist/createSuspenseQuery.js.map +1 -1
- package/dist/defineDisplayReactor.d.ts +43 -0
- package/dist/defineDisplayReactor.d.ts.map +1 -0
- package/dist/defineDisplayReactor.js +42 -0
- package/dist/defineDisplayReactor.js.map +1 -0
- package/dist/defineReactor.d.ts +46 -72
- package/dist/defineReactor.d.ts.map +1 -1
- package/dist/defineReactor.js +11 -176
- package/dist/defineReactor.js.map +1 -1
- package/dist/defineReactorShared.d.ts +84 -0
- package/dist/defineReactorShared.d.ts.map +1 -0
- package/dist/defineReactorShared.js +139 -0
- package/dist/defineReactorShared.js.map +1 -0
- package/dist/hooks/createAuthHooks.d.ts +9 -2
- package/dist/hooks/createAuthHooks.d.ts.map +1 -1
- package/dist/hooks/createAuthHooks.js +184 -24
- package/dist/hooks/createAuthHooks.js.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +36 -8
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorInfiniteQuery.js +54 -21
- package/dist/hooks/useActorInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorMethod.d.ts +37 -4
- package/dist/hooks/useActorMethod.d.ts.map +1 -1
- package/dist/hooks/useActorMethod.js +201 -57
- package/dist/hooks/useActorMethod.js.map +1 -1
- package/dist/hooks/useActorMutation.d.ts +15 -12
- package/dist/hooks/useActorMutation.d.ts.map +1 -1
- package/dist/hooks/useActorMutation.js +14 -13
- package/dist/hooks/useActorMutation.js.map +1 -1
- package/dist/hooks/useActorQuery.d.ts +17 -4
- package/dist/hooks/useActorQuery.d.ts.map +1 -1
- package/dist/hooks/useActorQuery.js +30 -9
- package/dist/hooks/useActorQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +17 -5
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +37 -17
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +2 -2
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -1
- package/dist/hooks/useActorSuspenseQuery.js +20 -9
- package/dist/hooks/useActorSuspenseQuery.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/ownedAuthentication.d.ts +52 -0
- package/dist/ownedAuthentication.d.ts.map +1 -0
- package/dist/ownedAuthentication.js +49 -0
- package/dist/ownedAuthentication.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +23 -0
- package/dist/server.js.map +1 -0
- package/dist/testing.d.ts +19 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +19 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +428 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +159 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +301 -1
- package/dist/utils.js.map +1 -1
- package/dist/validation.d.ts +12 -7
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +34 -15
- package/dist/validation.js.map +1 -1
- package/llms.txt +259 -33
- package/package.json +17 -5
- package/src/auth/auth-client-compat.ts +273 -0
- package/src/auth/authentication-manager.ts +918 -96
- package/src/auth/createIdentityAttributeHooks.ts +47 -21
- package/src/auth/identity-attributes-manager.ts +100 -5
- package/src/auth/identity-attributes.ts +75 -0
- package/src/auth/local-ii-probe.ts +29 -3
- package/src/auth/types.ts +49 -6
- package/src/createActorHooks.ts +50 -42
- package/src/createInfiniteQuery.ts +120 -28
- package/src/createMutation.ts +213 -132
- package/src/createQuery.ts +164 -32
- package/src/createReactorProvider.ts +365 -0
- package/src/createSuspenseInfiniteQuery.ts +93 -43
- package/src/createSuspenseQuery.ts +102 -32
- package/src/defineDisplayReactor.ts +62 -0
- package/src/defineReactor.ts +81 -263
- package/src/defineReactorShared.ts +268 -0
- package/src/hooks/createAuthHooks.ts +210 -28
- package/src/hooks/useActorInfiniteQuery.ts +156 -55
- package/src/hooks/useActorMethod.ts +295 -92
- package/src/hooks/useActorMutation.ts +42 -30
- package/src/hooks/useActorQuery.ts +43 -10
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +110 -54
- package/src/hooks/useActorSuspenseQuery.ts +30 -15
- package/src/index.ts +8 -0
- package/src/ownedAuthentication.ts +81 -0
- package/src/server.ts +23 -0
- package/src/testing.ts +18 -0
- package/src/types.ts +492 -22
- package/src/utils.ts +387 -3
- package/src/validation.ts +43 -19
|
@@ -1,31 +1,51 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useQuery, } from "@tanstack/react-query";
|
|
2
|
+
import { useQuery, skipToken, } from "@tanstack/react-query";
|
|
3
|
+
import { retryOption, skippedQueryKey, useMountQueryClient } from "../utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* Hook for executing query calls on a canister.
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
|
-
* const { data, isLoading } =
|
|
8
|
+
* const { data, isLoading } = useReactorQuery({
|
|
8
9
|
* reactor,
|
|
9
10
|
* functionName: "getUser",
|
|
10
11
|
* args: ["user-123"],
|
|
11
12
|
* })
|
|
12
13
|
*
|
|
13
14
|
* // With select transformation
|
|
14
|
-
* const { data } =
|
|
15
|
+
* const { data } = useReactorQuery({
|
|
15
16
|
* reactor,
|
|
16
17
|
* functionName: "getUser",
|
|
17
18
|
* args: ["user-123"],
|
|
18
19
|
* select: (user) => user.name,
|
|
19
20
|
* })
|
|
21
|
+
*
|
|
22
|
+
* // Wait for the args: no fetch until userId is known
|
|
23
|
+
* const { data } = useReactorQuery({
|
|
24
|
+
* reactor,
|
|
25
|
+
* functionName: "getUser",
|
|
26
|
+
* args: userId ? [userId] : skipToken,
|
|
27
|
+
* })
|
|
20
28
|
*/
|
|
21
29
|
export const useActorQuery = ({ reactor, functionName, args, callConfig, queryKey: defaultQueryKey, ...options }) => {
|
|
30
|
+
useMountQueryClient(reactor.queryClient);
|
|
22
31
|
// Memoize query options to prevent unnecessary re-computations
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
args,
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
// For an update method, the options also carry its default `retry`; see
|
|
33
|
+
// `Reactor.getQueryRetry`.
|
|
34
|
+
const { queryKey, queryFn, retry } = useMemo(() => args === skipToken
|
|
35
|
+
? // Waiting for its args: an entry of its own under the method's key,
|
|
36
|
+
// with nothing to run until then; see skippedQueryKey.
|
|
37
|
+
{
|
|
38
|
+
queryKey: skippedQueryKey(reactor.generateQueryKey({ functionName }, callConfig), "query"),
|
|
39
|
+
// Kept as the unique symbol, which an object literal widens.
|
|
40
|
+
queryFn: skipToken,
|
|
41
|
+
retry: undefined,
|
|
42
|
+
}
|
|
43
|
+
: reactor.getQueryOptions({
|
|
44
|
+
callConfig,
|
|
45
|
+
functionName,
|
|
46
|
+
args,
|
|
47
|
+
queryKey: defaultQueryKey,
|
|
48
|
+
}),
|
|
29
49
|
// `canisterId` is mutable reactor state that `setCanisterId` can change,
|
|
30
50
|
// while `reactor` itself stays the same object — so it has to be a
|
|
31
51
|
// dependency in its own right or the key stays pinned to the old canister.
|
|
@@ -41,6 +61,7 @@ export const useActorQuery = ({ reactor, functionName, args, callConfig, queryKe
|
|
|
41
61
|
queryFn,
|
|
42
62
|
...options,
|
|
43
63
|
queryKey,
|
|
64
|
+
...retryOption(options.retry, retry),
|
|
44
65
|
}, reactor.queryClient);
|
|
45
66
|
};
|
|
46
67
|
//# sourceMappingURL=useActorQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAEL,QAAQ,
|
|
1
|
+
{"version":3,"file":"useActorQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAEL,QAAQ,EACR,SAAS,GAIV,MAAM,uBAAuB,CAAA;AAW9B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AA+C/E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAK3B,EACA,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,QAAQ,EAAE,eAAe,EACzB,GAAG,OAAO,EAMX,EAA6D,EAAE;IAC9D,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAExC,+DAA+D;IAC/D,wEAAwE;IACxE,2BAA2B;IAC3B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAC1C,GAAG,EAAE,CACH,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,oEAAoE;YACpE,uDAAuD;YACvD;gBACE,QAAQ,EAAE,eAAe,CACvB,OAAO,CAAC,gBAAgB,CAAC,EAAE,YAAY,EAAE,EAAE,UAAU,CAAC,EACtD,OAAO,CACR;gBACD,6DAA6D;gBAC7D,OAAO,EAAE,SAAsB;gBAC/B,KAAK,EAAE,SAAS;aACjB;QACH,CAAC,CAAC,OAAO,CAAC,eAAe,CAAS;YAC9B,UAAU;YACV,YAAY;YACZ,IAAI;YACJ,QAAQ,EAAE,eAAe;SAC1B,CAAC;IACR,yEAAyE;IACzE,mEAAmE;IACnE,2EAA2E;IAC3E;QACE,OAAO;QACP,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE;QAC9B,UAAU;QACV,YAAY;QACZ,IAAI;QACJ,eAAe;KAChB,CACF,CAAA;IAED,OAAO,QAAQ,CACb;QACE,OAAO;QACP,GAAG,OAAO;QACV,QAAQ;QACR,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;KACrC,EACD,OAAO,CAAC,WAAW,CACpB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -12,6 +12,18 @@ export interface UseActorSuspenseInfiniteQueryParameters<Service, Method extends
|
|
|
12
12
|
functionName: Method;
|
|
13
13
|
/** Function to get args from page parameter */
|
|
14
14
|
getArgs: (pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>;
|
|
15
|
+
/**
|
|
16
|
+
* Narrows what the cache key derives from the call arguments.
|
|
17
|
+
*
|
|
18
|
+
* By default the key is scoped by `getArgs(initialPageParam)`, so two
|
|
19
|
+
* infinite queries on the same method with different arguments stay in
|
|
20
|
+
* separate cache entries. Supply this when those args embed the cursor and
|
|
21
|
+
* only part of them identifies the query — return the stable, serializable
|
|
22
|
+
* portion (typically everything except the pagination field). It is required
|
|
23
|
+
* when `initialPageParam` changes between renders, as `Date.now()` does:
|
|
24
|
+
* without it every render keys a new query.
|
|
25
|
+
*/
|
|
26
|
+
getKeyArgs?: (args: ReactorArgs<Service, Method, Transform>) => unknown;
|
|
15
27
|
/** Agent call configuration (effectiveCanisterId, etc.) */
|
|
16
28
|
callConfig?: CallConfig;
|
|
17
29
|
/** Custom query key (auto-generated if not provided) */
|
|
@@ -21,19 +33,19 @@ export interface UseActorSuspenseInfiniteQueryParameters<Service, Method extends
|
|
|
21
33
|
/** Function to determine next page parameter */
|
|
22
34
|
getNextPageParam: (lastPage: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, allPages: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined | null;
|
|
23
35
|
}
|
|
24
|
-
export type UseActorSuspenseInfiniteQueryConfig<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown
|
|
25
|
-
export type UseActorSuspenseInfiniteQueryResult<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown
|
|
36
|
+
export type UseActorSuspenseInfiniteQueryConfig<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>> = Omit<UseActorSuspenseInfiniteQueryParameters<Service, Method, Transform, TPageParam, Selected>, "reactor">;
|
|
37
|
+
export type UseActorSuspenseInfiniteQueryResult<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>> = UseSuspenseInfiniteQueryResult<Selected, ReactorReturnErr<Service, Method, Transform>>;
|
|
26
38
|
/**
|
|
27
39
|
* Hook for executing suspense-enabled infinite/paginated query calls on a canister.
|
|
28
40
|
*
|
|
29
41
|
* @example
|
|
30
|
-
* const { data, fetchNextPage, hasNextPage } =
|
|
42
|
+
* const { data, fetchNextPage, hasNextPage } = useReactorSuspenseInfiniteQuery({
|
|
31
43
|
* reactor,
|
|
32
44
|
* functionName: "getItems",
|
|
33
|
-
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }],
|
|
45
|
+
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }] as const,
|
|
34
46
|
* initialPageParam: 0,
|
|
35
47
|
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
36
48
|
* })
|
|
37
49
|
*/
|
|
38
|
-
export declare const useActorSuspenseInfiniteQuery: <Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown
|
|
50
|
+
export declare const useActorSuspenseInfiniteQuery: <Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TPageParam = unknown, Selected = InfiniteData<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, TPageParam>>({ reactor, functionName, getArgs, getKeyArgs, callConfig, queryKey, ...options }: UseActorSuspenseInfiniteQueryParameters<Service, Method, Transform, TPageParam, Selected>) => UseActorSuspenseInfiniteQueryResult<Service, Method, Transform, TPageParam, Selected>;
|
|
39
51
|
//# sourceMappingURL=useActorSuspenseInfiniteQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorSuspenseInfiniteQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,8BAA8B,EAC9B,+BAA+B,EAC/B,YAAY,EACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"useActorSuspenseInfiniteQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,8BAA8B,EAC9B,+BAA+B,EAC/B,YAAY,EACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,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N,SAAS,EACT,UAAU,EACV,QAAQ,CACT,KAAG,mCAAmC,CACrC,OAAO,EACP,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,CA0FT,CAAA"}
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import { useMemo, useCallback } from "react";
|
|
2
2
|
import { useSuspenseInfiniteQuery, } from "@tanstack/react-query";
|
|
3
|
-
import { mergeFactoryQueryKey, normalizeQueryData } from "../utils.js";
|
|
3
|
+
import { callConfigForKey, mergeFactoryQueryKey, mountWhileSuspended, normalizeQueryData, retryOption, useMountQueryClient, } from "../utils.js";
|
|
4
4
|
/**
|
|
5
5
|
* Hook for executing suspense-enabled infinite/paginated query calls on a canister.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* const { data, fetchNextPage, hasNextPage } =
|
|
8
|
+
* const { data, fetchNextPage, hasNextPage } = useReactorSuspenseInfiniteQuery({
|
|
9
9
|
* reactor,
|
|
10
10
|
* functionName: "getItems",
|
|
11
|
-
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }],
|
|
11
|
+
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }] as const,
|
|
12
12
|
* initialPageParam: 0,
|
|
13
13
|
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
14
14
|
* })
|
|
15
15
|
*/
|
|
16
|
-
export const useActorSuspenseInfiniteQuery = ({ reactor, functionName, getArgs, callConfig, queryKey, ...options }) => {
|
|
16
|
+
export const useActorSuspenseInfiniteQuery = ({ reactor, functionName, getArgs, getKeyArgs, callConfig, queryKey, ...options }) => {
|
|
17
|
+
useMountQueryClient(reactor.queryClient);
|
|
17
18
|
// Always pass queryKey through generateQueryKey so it is merged with the
|
|
18
19
|
// reactor/function identity. Using the custom key verbatim would cause cache
|
|
19
20
|
// collisions if two different actors or methods share the same key string.
|
|
20
|
-
const baseQueryKey = useMemo(() =>
|
|
21
|
-
functionName,
|
|
21
|
+
const baseQueryKey = useMemo(() => {
|
|
22
22
|
// Fold the call arguments into the key. They live in the `getArgs`
|
|
23
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
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// same method with different arguments share one cache entry and serve
|
|
25
|
+
// each other's pages. `getKeyArgs` narrows them exactly as it does for the
|
|
26
|
+
// factories, which the bound hook's config type always accepted: it used
|
|
27
|
+
// to be ignored here, so the cursor stayed in the key, and an
|
|
28
|
+
// `initialPageParam` that changes every render (`Date.now()`) keyed a new
|
|
29
|
+
// query on every render — an endless loop of first-page fetches.
|
|
30
|
+
const initialArgs = getArgs(options.initialPageParam);
|
|
31
|
+
const keyArgs = getKeyArgs?.(initialArgs) ?? initialArgs;
|
|
32
|
+
return reactor.generateQueryKey({
|
|
33
|
+
functionName,
|
|
34
|
+
queryKey: mergeFactoryQueryKey(queryKey, undefined, keyArgs),
|
|
35
|
+
}, callConfig);
|
|
36
|
+
}, [
|
|
28
37
|
queryKey,
|
|
29
38
|
reactor,
|
|
30
39
|
// `canisterId` is mutable reactor state that `setCanisterId` can change,
|
|
@@ -35,22 +44,33 @@ export const useActorSuspenseInfiniteQuery = ({ reactor, functionName, getArgs,
|
|
|
35
44
|
functionName,
|
|
36
45
|
callConfig,
|
|
37
46
|
getArgs,
|
|
47
|
+
getKeyArgs,
|
|
38
48
|
options.initialPageParam,
|
|
39
49
|
]);
|
|
40
50
|
// Memoize queryFn to prevent recreation on every render
|
|
41
|
-
const queryFn = useCallback(async ({ pageParam }) => {
|
|
51
|
+
const queryFn = useCallback(async ({ pageParam, queryKey: fetchedKey, }) => {
|
|
42
52
|
const args = getArgs(pageParam);
|
|
43
53
|
const result = await reactor.callMethod({
|
|
44
54
|
functionName,
|
|
45
55
|
args,
|
|
46
|
-
callConfig,
|
|
56
|
+
callConfig: callConfigForKey(fetchedKey, callConfig),
|
|
47
57
|
});
|
|
48
58
|
return normalizeQueryData(result);
|
|
49
59
|
}, [reactor, functionName, getArgs, callConfig]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
// The method's default `retry`: for an update method, only failures that
|
|
61
|
+
// prove the canister never ran the call; see `Reactor.getQueryRetry`.
|
|
62
|
+
const defaultRetry = useMemo(() => reactor.getQueryRetry(functionName, baseQueryKey), [reactor, functionName, baseQueryKey]);
|
|
63
|
+
try {
|
|
64
|
+
return useSuspenseInfiniteQuery({
|
|
65
|
+
queryKey: baseQueryKey,
|
|
66
|
+
queryFn,
|
|
67
|
+
...options,
|
|
68
|
+
...retryOption(options.retry, defaultRetry),
|
|
69
|
+
}, reactor.queryClient);
|
|
70
|
+
}
|
|
71
|
+
catch (thrown) {
|
|
72
|
+
mountWhileSuspended(reactor.queryClient, thrown);
|
|
73
|
+
throw thrown;
|
|
74
|
+
}
|
|
55
75
|
};
|
|
56
76
|
//# sourceMappingURL=useActorSuspenseInfiniteQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorSuspenseInfiniteQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAEL,wBAAwB,GAIzB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,
|
|
1
|
+
{"version":3,"file":"useActorSuspenseInfiniteQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseInfiniteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAEL,wBAAwB,GAIzB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,mBAAmB,GACpB,MAAM,aAAa,CAAA;AA4FpB;;;;;;;;;;;GAWG;AACH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C;SACrD,CAAC,CAAA;QACF,OAAO,kBAAkB,CACvB,MAAqD,CACtD,CAAA;IACH,CAAC,EACD,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC,CAC7C,CAAA;IAED,yEAAyE;IACzE,sEAAsE;IACtE,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,EAAE,YAAY,CAAC,EACvD,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CACtC,CAAA;IAED,IAAI,CAAC;QACH,OAAO,wBAAwB,CAC7B;YACE,QAAQ,EAAE,YAAY;YACtB,OAAO;YACP,GAAG,OAAO;YACV,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC;SACrC,EACR,OAAO,CAAC,WAAW,CAOpB,CAAA;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,mBAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;QAChD,MAAM,MAAM,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -14,14 +14,14 @@ export type UseActorSuspenseQueryResult<Service, Method extends FunctionName<Ser
|
|
|
14
14
|
* Hook for executing suspense-enabled query calls on a canister.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
* const { data } =
|
|
17
|
+
* const { data } = useReactorSuspenseQuery({
|
|
18
18
|
* reactor,
|
|
19
19
|
* functionName: "getUser",
|
|
20
20
|
* args: ["user-123"],
|
|
21
21
|
* })
|
|
22
22
|
*
|
|
23
23
|
* // With select transformation
|
|
24
|
-
* const { data } =
|
|
24
|
+
* const { data } = useReactorSuspenseQuery({
|
|
25
25
|
* reactor,
|
|
26
26
|
* functionName: "getUser",
|
|
27
27
|
* args: ["user-123"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorSuspenseQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,oBAAoB,EACpB,sBAAsB,EAEvB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"useActorSuspenseQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,oBAAoB,EACpB,sBAAsB,EAEvB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAOhD,MAAM,WAAW,+BAA+B,CAC9C,OAAO,EACP,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,EACpC,SAAS,SAAS,YAAY,GAAG,QAAQ,EACzC,QAAQ,GAAG,gBAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CACxE,SAAQ,IAAI,CACZ,oBAAoB,CAClB,gBAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,EAC7D,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAC5C,QAAQ,EACR,gBAAgB,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,EAC7D,QAAQ,CACT,EACD,UAAU,GAAG,SAAS,CACvB;IACC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IACpC,YAAY,EAAE,MAAM,CA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Query, } from "@tanstack/react-query";
|
|
3
|
+
import { mountWhileSuspended, retryOption, useMountQueryClient, } from "../utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* Hook for executing suspense-enabled query calls on a canister.
|
|
5
6
|
*
|
|
6
7
|
* @example
|
|
7
|
-
* const { data } =
|
|
8
|
+
* const { data } = useReactorSuspenseQuery({
|
|
8
9
|
* reactor,
|
|
9
10
|
* functionName: "getUser",
|
|
10
11
|
* args: ["user-123"],
|
|
11
12
|
* })
|
|
12
13
|
*
|
|
13
14
|
* // With select transformation
|
|
14
|
-
* const { data } =
|
|
15
|
+
* const { data } = useReactorSuspenseQuery({
|
|
15
16
|
* reactor,
|
|
16
17
|
* functionName: "getUser",
|
|
17
18
|
* args: ["user-123"],
|
|
@@ -19,8 +20,11 @@ import { useSuspenseQuery, } from "@tanstack/react-query";
|
|
|
19
20
|
* })
|
|
20
21
|
*/
|
|
21
22
|
export const useActorSuspenseQuery = ({ reactor, functionName, args, callConfig, queryKey: defaultQueryKey, ...options }) => {
|
|
23
|
+
useMountQueryClient(reactor.queryClient);
|
|
22
24
|
// Memoize query options to prevent unnecessary re-computations
|
|
23
|
-
|
|
25
|
+
// For an update method, the options also carry its default `retry`; see
|
|
26
|
+
// `Reactor.getQueryRetry`.
|
|
27
|
+
const { queryKey, queryFn, retry } = useMemo(() => reactor.getQueryOptions({
|
|
24
28
|
callConfig,
|
|
25
29
|
functionName,
|
|
26
30
|
args,
|
|
@@ -37,11 +41,18 @@ export const useActorSuspenseQuery = ({ reactor, functionName, args, callConfig,
|
|
|
37
41
|
args,
|
|
38
42
|
defaultQueryKey,
|
|
39
43
|
]);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
return useSuspenseQuery({
|
|
46
|
+
// Suspense queries don't support skipToken, so cast the queryFn
|
|
47
|
+
queryFn: queryFn,
|
|
48
|
+
...options,
|
|
49
|
+
queryKey,
|
|
50
|
+
...retryOption(options.retry, retry),
|
|
51
|
+
}, reactor.queryClient);
|
|
52
|
+
}
|
|
53
|
+
catch (thrown) {
|
|
54
|
+
mountWhileSuspended(reactor.queryClient, thrown);
|
|
55
|
+
throw thrown;
|
|
56
|
+
}
|
|
46
57
|
};
|
|
47
58
|
//# sourceMappingURL=useActorSuspenseQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActorSuspenseQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAEL,gBAAgB,GAIjB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useActorSuspenseQuery.js","sourceRoot":"","sources":["../../src/hooks/useActorSuspenseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAEL,gBAAgB,GAIjB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,mBAAmB,GACpB,MAAM,aAAa,CAAA;AA4CpB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAKnC,EACA,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,QAAQ,EAAE,eAAe,EACzB,GAAG,OAAO,EAMX,EAAqE,EAAE;IACtE,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAExC,+DAA+D;IAC/D,wEAAwE;IACxE,2BAA2B;IAC3B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAC1C,GAAG,EAAE,CACH,OAAO,CAAC,eAAe,CAAS;QAC9B,UAAU;QACV,YAAY;QACZ,IAAI;QACJ,QAAQ,EAAE,eAAe;KAC1B,CAAC;IACJ,yEAAyE;IACzE,mEAAmE;IACnE,2EAA2E;IAC3E;QACE,OAAO;QACP,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE;QAC9B,UAAU;QACV,YAAY;QACZ,IAAI;QACJ,eAAe;KAChB,CACF,CAAA;IAED,IAAI,CAAC;QACH,OAAO,gBAAgB,CACrB;YACE,gEAAgE;YAChE,OAAO,EAAE,OAGR;YACD,GAAG,OAAO;YACV,QAAQ;YACR,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrC,EACD,OAAO,CAAC,WAAW,CACpB,CAAA;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,mBAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;QAChD,MAAM,MAAM,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export * from "./hooks/index.js";
|
|
|
3
3
|
export * from "./validation.js";
|
|
4
4
|
export * from "./createActorHooks.js";
|
|
5
5
|
export * from "./defineReactor.js";
|
|
6
|
+
export * from "./defineDisplayReactor.js";
|
|
7
|
+
export * from "./createReactorProvider.js";
|
|
6
8
|
export * from "./createQuery.js";
|
|
7
9
|
export * from "./createSuspenseQuery.js";
|
|
8
10
|
export * from "./createInfiniteQuery.js";
|
|
@@ -10,4 +12,6 @@ export * from "./createSuspenseInfiniteQuery.js";
|
|
|
10
12
|
export * from "./createMutation.js";
|
|
11
13
|
export * from "./auth/index.js";
|
|
12
14
|
export * from "./types.js";
|
|
15
|
+
export { skipToken } from "@tanstack/react-query";
|
|
16
|
+
export type { SkipToken } from "@tanstack/react-query";
|
|
13
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAGhC,cAAc,kBAAkB,CAAA;AAGhC,cAAc,iBAAiB,CAAA;AAG/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAGhC,cAAc,kBAAkB,CAAA;AAGhC,cAAc,iBAAiB,CAAA;AAG/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAE1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kCAAkC,CAAA;AAChD,cAAc,qBAAqB,CAAA;AAEnC,cAAc,iBAAiB,CAAA;AAE/B,cAAc,YAAY,CAAA;AAK1B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export * from "./validation.js";
|
|
|
8
8
|
// React-specific exports
|
|
9
9
|
export * from "./createActorHooks.js";
|
|
10
10
|
export * from "./defineReactor.js";
|
|
11
|
+
export * from "./defineDisplayReactor.js";
|
|
12
|
+
export * from "./createReactorProvider.js";
|
|
11
13
|
export * from "./createQuery.js";
|
|
12
14
|
export * from "./createSuspenseQuery.js";
|
|
13
15
|
export * from "./createInfiniteQuery.js";
|
|
@@ -15,4 +17,8 @@ export * from "./createSuspenseInfiniteQuery.js";
|
|
|
15
17
|
export * from "./createMutation.js";
|
|
16
18
|
export * from "./auth/index.js";
|
|
17
19
|
export * from "./types.js";
|
|
20
|
+
// TanStack Query's marker for a query whose args are not known yet, which the
|
|
21
|
+
// non-suspense query hooks and createQueryFactory take in place of args. It is
|
|
22
|
+
// the same symbol as @tanstack/react-query's, so either import works.
|
|
23
|
+
export { skipToken } from "@tanstack/react-query";
|
|
18
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,sFAAsF;AACtF,cAAc,kBAAkB,CAAA;AAEhC,kBAAkB;AAClB,cAAc,kBAAkB,CAAA;AAEhC,iCAAiC;AACjC,cAAc,iBAAiB,CAAA;AAE/B,yBAAyB;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,sFAAsF;AACtF,cAAc,kBAAkB,CAAA;AAEhC,kBAAkB;AAClB,cAAc,kBAAkB,CAAA;AAEhC,iCAAiC;AACjC,cAAc,iBAAiB,CAAA;AAE/B,yBAAyB;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAE1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kCAAkC,CAAA;AAChD,cAAc,qBAAqB,CAAA;AAEnC,cAAc,iBAAiB,CAAA;AAE/B,cAAc,YAAY,CAAA;AAE1B,8EAA8E;AAC9E,+EAA+E;AAC/E,sEAAsE;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which `AuthenticationManager`s a `createReactorProvider` value owns, for the
|
|
3
|
+
* provider to dispose when its tree unmounts. Not part of the public API.
|
|
4
|
+
*
|
|
5
|
+
* A value owns the managers built for it: those constructed while its factory
|
|
6
|
+
* ran, and those a `defineReactor` or `defineDisplayReactor` result in it
|
|
7
|
+
* builds later, on first use. A manager built elsewhere and handed in, such as
|
|
8
|
+
* an app-wide one every provider shares, belongs to whoever built it, and
|
|
9
|
+
* disposing it on each remount would stop its client following the session.
|
|
10
|
+
*
|
|
11
|
+
* A result's `authentication` is a getter that builds the manager on first
|
|
12
|
+
* read, and building one loads the optional `@icp-sdk/auth` peer in a browser.
|
|
13
|
+
* A provider that read it to release the manager would build one only to
|
|
14
|
+
* dispose it, for every reactor whose tree never signed in. Each result
|
|
15
|
+
* registers a reader here instead, which answers without building anything.
|
|
16
|
+
*
|
|
17
|
+
* Kept apart from `defineReactorShared.ts` so that the provider does not pull
|
|
18
|
+
* that module's reactor setup into an app that builds its reactors by hand.
|
|
19
|
+
*/
|
|
20
|
+
import type { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
21
|
+
/**
|
|
22
|
+
* Records how to read the manager `owner` built, once it has built one.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export declare function registerAuthentication(owner: object, read: () => AuthenticationManager | undefined): void;
|
|
27
|
+
/**
|
|
28
|
+
* The manager a registered result built, or `undefined` for one that has not
|
|
29
|
+
* built one yet, for one that was handed a manager, and for anything that was
|
|
30
|
+
* never registered.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export declare function authenticationOf(owner: object): AuthenticationManager | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Called by each `AuthenticationManager` as it is constructed.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function recordAuthentication(manager: AuthenticationManager): void;
|
|
41
|
+
/**
|
|
42
|
+
* Runs `build` and returns what it returned, with every manager constructed
|
|
43
|
+
* while it ran. `build` runs synchronously, so a server rendering several
|
|
44
|
+
* requests at once cannot interleave another request's managers.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare function collectAuthentication<T>(build: () => T): {
|
|
49
|
+
value: T;
|
|
50
|
+
built: AuthenticationManager[];
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=ownedAuthentication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownedAuthentication.d.ts","sourceRoot":"","sources":["../src/ownedAuthentication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAO7E;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,qBAAqB,GAAG,SAAS,GAC5C,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GACZ,qBAAqB,GAAG,SAAS,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IACxD,KAAK,EAAE,CAAC,CAAA;IACR,KAAK,EAAE,qBAAqB,EAAE,CAAA;CAC/B,CAUA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const readers = new WeakMap();
|
|
2
|
+
/** The managers constructed during a running {@link collectAuthentication}. */
|
|
3
|
+
let collecting;
|
|
4
|
+
/**
|
|
5
|
+
* Records how to read the manager `owner` built, once it has built one.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function registerAuthentication(owner, read) {
|
|
10
|
+
readers.set(owner, read);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The manager a registered result built, or `undefined` for one that has not
|
|
14
|
+
* built one yet, for one that was handed a manager, and for anything that was
|
|
15
|
+
* never registered.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function authenticationOf(owner) {
|
|
20
|
+
return readers.get(owner)?.();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Called by each `AuthenticationManager` as it is constructed.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function recordAuthentication(manager) {
|
|
28
|
+
collecting?.add(manager);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs `build` and returns what it returned, with every manager constructed
|
|
32
|
+
* while it ran. `build` runs synchronously, so a server rendering several
|
|
33
|
+
* requests at once cannot interleave another request's managers.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export function collectAuthentication(build) {
|
|
38
|
+
const outer = collecting;
|
|
39
|
+
const built = new Set();
|
|
40
|
+
collecting = built;
|
|
41
|
+
try {
|
|
42
|
+
const value = build();
|
|
43
|
+
return { value, built: [...built] };
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
collecting = outer;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ownedAuthentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownedAuthentication.js","sourceRoot":"","sources":["../src/ownedAuthentication.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,GAAG,IAAI,OAAO,EAAmD,CAAA;AAE9E,+EAA+E;AAC/E,IAAI,UAAkD,CAAA;AAEtD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,IAA6C;IAE7C,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa;IAEb,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAI,KAAc;IAIrD,MAAM,KAAK,GAAG,UAAU,CAAA;IACxB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC9C,UAAU,GAAG,KAAK,CAAA;IAClB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,EAAE,CAAA;QACrB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAA;IACrC,CAAC;YAAS,CAAC;QACT,UAAU,GAAG,KAAK,CAAA;IACpB,CAAC;AACH,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `react-server` entry of `@ic-reactor/react`.
|
|
3
|
+
*
|
|
4
|
+
* React Server Components are bundled with the `react-server` export
|
|
5
|
+
* condition, and `package.json` routes that condition here instead of to
|
|
6
|
+
* `index.ts`. The main entry also loads every hook, and a bundler rejects a
|
|
7
|
+
* hook import anywhere in the server graph, so a server component that
|
|
8
|
+
* imported only `Reactor` from it failed to build.
|
|
9
|
+
*
|
|
10
|
+
* This entry carries the core runtime (`Reactor`, `DisplayReactor`,
|
|
11
|
+
* `ClientManager`, the error classes and utilities) and the framework-free
|
|
12
|
+
* validation helpers, and nothing that imports React. A hook or a hook factory
|
|
13
|
+
* imported in a server component is therefore a missing export at build time,
|
|
14
|
+
* which is the error to get: those only run in a `"use client"` module.
|
|
15
|
+
*
|
|
16
|
+
* TypeScript does not read the `react-server` condition, so types still come
|
|
17
|
+
* from the main entry.
|
|
18
|
+
*/
|
|
19
|
+
export * from "@ic-reactor/core";
|
|
20
|
+
export * from "./validation.js";
|
|
21
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,kBAAkB,CAAA;AAIhC,cAAc,iBAAiB,CAAA"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `react-server` entry of `@ic-reactor/react`.
|
|
3
|
+
*
|
|
4
|
+
* React Server Components are bundled with the `react-server` export
|
|
5
|
+
* condition, and `package.json` routes that condition here instead of to
|
|
6
|
+
* `index.ts`. The main entry also loads every hook, and a bundler rejects a
|
|
7
|
+
* hook import anywhere in the server graph, so a server component that
|
|
8
|
+
* imported only `Reactor` from it failed to build.
|
|
9
|
+
*
|
|
10
|
+
* This entry carries the core runtime (`Reactor`, `DisplayReactor`,
|
|
11
|
+
* `ClientManager`, the error classes and utilities) and the framework-free
|
|
12
|
+
* validation helpers, and nothing that imports React. A hook or a hook factory
|
|
13
|
+
* imported in a server component is therefore a missing export at build time,
|
|
14
|
+
* which is the error to get: those only run in a `"use client"` module.
|
|
15
|
+
*
|
|
16
|
+
* TypeScript does not read the `react-server` condition, so types still come
|
|
17
|
+
* from the main entry.
|
|
18
|
+
*/
|
|
19
|
+
export * from "@ic-reactor/core";
|
|
20
|
+
// Plain functions over `ValidationError`, useful in a server action that maps
|
|
21
|
+
// a rejected call onto form field errors.
|
|
22
|
+
export * from "./validation.js";
|
|
23
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,kBAAkB,CAAA;AAEhC,8EAA8E;AAC9E,0CAA0C;AAC1C,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ic-reactor/react/testing`: the testing utilities of
|
|
3
|
+
* `@ic-reactor/core/testing`, re-exported for an app that depends on
|
|
4
|
+
* `@ic-reactor/react` alone. The main entry re-exports `@ic-reactor/core` the
|
|
5
|
+
* same way, but a package manager that installs strictly does not let such an
|
|
6
|
+
* app import `@ic-reactor/core/testing` itself.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here imports React, and neither the main entry nor the
|
|
9
|
+
* `react-server` entry imports this one, so none of it reaches an app bundle.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createTestCanister, installFakeReplica } from "@ic-reactor/react/testing"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export * from "@ic-reactor/core/testing";
|
|
19
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,cAAc,0BAA0B,CAAA"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ic-reactor/react/testing`: the testing utilities of
|
|
3
|
+
* `@ic-reactor/core/testing`, re-exported for an app that depends on
|
|
4
|
+
* `@ic-reactor/react` alone. The main entry re-exports `@ic-reactor/core` the
|
|
5
|
+
* same way, but a package manager that installs strictly does not let such an
|
|
6
|
+
* app import `@ic-reactor/core/testing` itself.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here imports React, and neither the main entry nor the
|
|
9
|
+
* `react-server` entry imports this one, so none of it reaches an app bundle.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createTestCanister, installFakeReplica } from "@ic-reactor/react/testing"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export * from "@ic-reactor/core/testing";
|
|
19
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,cAAc,0BAA0B,CAAA"}
|