@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
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
const readers = new WeakMap<object, () => AuthenticationManager | undefined>()
|
|
23
|
+
|
|
24
|
+
/** The managers constructed during a running {@link collectAuthentication}. */
|
|
25
|
+
let collecting: Set<AuthenticationManager> | undefined
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Records how to read the manager `owner` built, once it has built one.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export function registerAuthentication(
|
|
33
|
+
owner: object,
|
|
34
|
+
read: () => AuthenticationManager | undefined
|
|
35
|
+
): void {
|
|
36
|
+
readers.set(owner, read)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The manager a registered result built, or `undefined` for one that has not
|
|
41
|
+
* built one yet, for one that was handed a manager, and for anything that was
|
|
42
|
+
* never registered.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function authenticationOf(
|
|
47
|
+
owner: object
|
|
48
|
+
): AuthenticationManager | undefined {
|
|
49
|
+
return readers.get(owner)?.()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Called by each `AuthenticationManager` as it is constructed.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export function recordAuthentication(manager: AuthenticationManager): void {
|
|
58
|
+
collecting?.add(manager)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Runs `build` and returns what it returned, with every manager constructed
|
|
63
|
+
* while it ran. `build` runs synchronously, so a server rendering several
|
|
64
|
+
* requests at once cannot interleave another request's managers.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export function collectAuthentication<T>(build: () => T): {
|
|
69
|
+
value: T
|
|
70
|
+
built: AuthenticationManager[]
|
|
71
|
+
} {
|
|
72
|
+
const outer = collecting
|
|
73
|
+
const built = new Set<AuthenticationManager>()
|
|
74
|
+
collecting = built
|
|
75
|
+
try {
|
|
76
|
+
const value = build()
|
|
77
|
+
return { value, built: [...built] }
|
|
78
|
+
} finally {
|
|
79
|
+
collecting = outer
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/server.ts
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
|
+
|
|
21
|
+
// Plain functions over `ValidationError`, useful in a server action that maps
|
|
22
|
+
// a rejected call onto form field errors.
|
|
23
|
+
export * from "./validation.js"
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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"
|