@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.
Files changed (152) hide show
  1. package/README.md +410 -44
  2. package/dist/auth/auth-client-compat.d.ts +122 -0
  3. package/dist/auth/auth-client-compat.d.ts.map +1 -0
  4. package/dist/auth/auth-client-compat.js +162 -0
  5. package/dist/auth/auth-client-compat.js.map +1 -0
  6. package/dist/auth/authentication-manager.d.ts +287 -5
  7. package/dist/auth/authentication-manager.d.ts.map +1 -1
  8. package/dist/auth/authentication-manager.js +920 -150
  9. package/dist/auth/authentication-manager.js.map +1 -1
  10. package/dist/auth/createIdentityAttributeHooks.d.ts.map +1 -1
  11. package/dist/auth/createIdentityAttributeHooks.js +36 -20
  12. package/dist/auth/createIdentityAttributeHooks.js.map +1 -1
  13. package/dist/auth/identity-attributes-manager.d.ts +2 -1
  14. package/dist/auth/identity-attributes-manager.d.ts.map +1 -1
  15. package/dist/auth/identity-attributes-manager.js +90 -6
  16. package/dist/auth/identity-attributes-manager.js.map +1 -1
  17. package/dist/auth/identity-attributes.d.ts.map +1 -1
  18. package/dist/auth/identity-attributes.js +57 -0
  19. package/dist/auth/identity-attributes.js.map +1 -1
  20. package/dist/auth/local-ii-probe.d.ts +12 -1
  21. package/dist/auth/local-ii-probe.d.ts.map +1 -1
  22. package/dist/auth/local-ii-probe.js +22 -3
  23. package/dist/auth/local-ii-probe.js.map +1 -1
  24. package/dist/auth/types.d.ts +48 -5
  25. package/dist/auth/types.d.ts.map +1 -1
  26. package/dist/createActorHooks.d.ts +9 -20
  27. package/dist/createActorHooks.d.ts.map +1 -1
  28. package/dist/createActorHooks.js.map +1 -1
  29. package/dist/createInfiniteQuery.d.ts +51 -10
  30. package/dist/createInfiniteQuery.d.ts.map +1 -1
  31. package/dist/createInfiniteQuery.js +39 -15
  32. package/dist/createInfiniteQuery.js.map +1 -1
  33. package/dist/createMutation.d.ts +4 -1
  34. package/dist/createMutation.d.ts.map +1 -1
  35. package/dist/createMutation.js +121 -84
  36. package/dist/createMutation.js.map +1 -1
  37. package/dist/createQuery.d.ts +35 -2
  38. package/dist/createQuery.d.ts.map +1 -1
  39. package/dist/createQuery.js +104 -17
  40. package/dist/createQuery.js.map +1 -1
  41. package/dist/createReactorProvider.d.ts +158 -0
  42. package/dist/createReactorProvider.d.ts.map +1 -0
  43. package/dist/createReactorProvider.js +256 -0
  44. package/dist/createReactorProvider.js.map +1 -0
  45. package/dist/createSuspenseInfiniteQuery.d.ts +16 -9
  46. package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -1
  47. package/dist/createSuspenseInfiniteQuery.js +59 -27
  48. package/dist/createSuspenseInfiniteQuery.js.map +1 -1
  49. package/dist/createSuspenseQuery.d.ts +23 -2
  50. package/dist/createSuspenseQuery.d.ts.map +1 -1
  51. package/dist/createSuspenseQuery.js +68 -21
  52. package/dist/createSuspenseQuery.js.map +1 -1
  53. package/dist/defineDisplayReactor.d.ts +43 -0
  54. package/dist/defineDisplayReactor.d.ts.map +1 -0
  55. package/dist/defineDisplayReactor.js +42 -0
  56. package/dist/defineDisplayReactor.js.map +1 -0
  57. package/dist/defineReactor.d.ts +46 -72
  58. package/dist/defineReactor.d.ts.map +1 -1
  59. package/dist/defineReactor.js +11 -176
  60. package/dist/defineReactor.js.map +1 -1
  61. package/dist/defineReactorShared.d.ts +84 -0
  62. package/dist/defineReactorShared.d.ts.map +1 -0
  63. package/dist/defineReactorShared.js +139 -0
  64. package/dist/defineReactorShared.js.map +1 -0
  65. package/dist/hooks/createAuthHooks.d.ts +9 -2
  66. package/dist/hooks/createAuthHooks.d.ts.map +1 -1
  67. package/dist/hooks/createAuthHooks.js +184 -24
  68. package/dist/hooks/createAuthHooks.js.map +1 -1
  69. package/dist/hooks/useActorInfiniteQuery.d.ts +36 -8
  70. package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -1
  71. package/dist/hooks/useActorInfiniteQuery.js +54 -21
  72. package/dist/hooks/useActorInfiniteQuery.js.map +1 -1
  73. package/dist/hooks/useActorMethod.d.ts +37 -4
  74. package/dist/hooks/useActorMethod.d.ts.map +1 -1
  75. package/dist/hooks/useActorMethod.js +201 -57
  76. package/dist/hooks/useActorMethod.js.map +1 -1
  77. package/dist/hooks/useActorMutation.d.ts +15 -12
  78. package/dist/hooks/useActorMutation.d.ts.map +1 -1
  79. package/dist/hooks/useActorMutation.js +14 -13
  80. package/dist/hooks/useActorMutation.js.map +1 -1
  81. package/dist/hooks/useActorQuery.d.ts +17 -4
  82. package/dist/hooks/useActorQuery.d.ts.map +1 -1
  83. package/dist/hooks/useActorQuery.js +30 -9
  84. package/dist/hooks/useActorQuery.js.map +1 -1
  85. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +17 -5
  86. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -1
  87. package/dist/hooks/useActorSuspenseInfiniteQuery.js +37 -17
  88. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -1
  89. package/dist/hooks/useActorSuspenseQuery.d.ts +2 -2
  90. package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -1
  91. package/dist/hooks/useActorSuspenseQuery.js +20 -9
  92. package/dist/hooks/useActorSuspenseQuery.js.map +1 -1
  93. package/dist/index.d.ts +4 -0
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +6 -0
  96. package/dist/index.js.map +1 -1
  97. package/dist/ownedAuthentication.d.ts +52 -0
  98. package/dist/ownedAuthentication.d.ts.map +1 -0
  99. package/dist/ownedAuthentication.js +49 -0
  100. package/dist/ownedAuthentication.js.map +1 -0
  101. package/dist/server.d.ts +21 -0
  102. package/dist/server.d.ts.map +1 -0
  103. package/dist/server.js +23 -0
  104. package/dist/server.js.map +1 -0
  105. package/dist/testing.d.ts +19 -0
  106. package/dist/testing.d.ts.map +1 -0
  107. package/dist/testing.js +19 -0
  108. package/dist/testing.js.map +1 -0
  109. package/dist/types.d.ts +428 -21
  110. package/dist/types.d.ts.map +1 -1
  111. package/dist/types.js +1 -1
  112. package/dist/utils.d.ts +159 -3
  113. package/dist/utils.d.ts.map +1 -1
  114. package/dist/utils.js +301 -1
  115. package/dist/utils.js.map +1 -1
  116. package/dist/validation.d.ts +12 -7
  117. package/dist/validation.d.ts.map +1 -1
  118. package/dist/validation.js +34 -15
  119. package/dist/validation.js.map +1 -1
  120. package/llms.txt +259 -33
  121. package/package.json +17 -5
  122. package/src/auth/auth-client-compat.ts +273 -0
  123. package/src/auth/authentication-manager.ts +918 -96
  124. package/src/auth/createIdentityAttributeHooks.ts +47 -21
  125. package/src/auth/identity-attributes-manager.ts +100 -5
  126. package/src/auth/identity-attributes.ts +75 -0
  127. package/src/auth/local-ii-probe.ts +29 -3
  128. package/src/auth/types.ts +49 -6
  129. package/src/createActorHooks.ts +50 -42
  130. package/src/createInfiniteQuery.ts +120 -28
  131. package/src/createMutation.ts +213 -132
  132. package/src/createQuery.ts +164 -32
  133. package/src/createReactorProvider.ts +365 -0
  134. package/src/createSuspenseInfiniteQuery.ts +93 -43
  135. package/src/createSuspenseQuery.ts +102 -32
  136. package/src/defineDisplayReactor.ts +62 -0
  137. package/src/defineReactor.ts +81 -263
  138. package/src/defineReactorShared.ts +268 -0
  139. package/src/hooks/createAuthHooks.ts +210 -28
  140. package/src/hooks/useActorInfiniteQuery.ts +156 -55
  141. package/src/hooks/useActorMethod.ts +295 -92
  142. package/src/hooks/useActorMutation.ts +42 -30
  143. package/src/hooks/useActorQuery.ts +43 -10
  144. package/src/hooks/useActorSuspenseInfiniteQuery.ts +110 -54
  145. package/src/hooks/useActorSuspenseQuery.ts +30 -15
  146. package/src/index.ts +8 -0
  147. package/src/ownedAuthentication.ts +81 -0
  148. package/src/server.ts +23 -0
  149. package/src/testing.ts +18 -0
  150. package/src/types.ts +492 -22
  151. package/src/utils.ts +387 -3
  152. 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"