@ic-reactor/react 3.13.0 → 4.0.0-beta.2

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 (174) hide show
  1. package/README.md +237 -787
  2. package/dist/index.d.ts +260 -16
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +471 -23
  5. package/dist/index.js.map +1 -1
  6. package/llms.txt +82 -278
  7. package/package.json +11 -39
  8. package/src/index.tsx +612 -0
  9. package/dist/auth/auth-client-compat.d.ts +0 -122
  10. package/dist/auth/auth-client-compat.d.ts.map +0 -1
  11. package/dist/auth/auth-client-compat.js +0 -162
  12. package/dist/auth/auth-client-compat.js.map +0 -1
  13. package/dist/auth/authentication-manager.d.ts +0 -405
  14. package/dist/auth/authentication-manager.d.ts.map +0 -1
  15. package/dist/auth/authentication-manager.js +0 -1537
  16. package/dist/auth/authentication-manager.js.map +0 -1
  17. package/dist/auth/constants.d.ts +0 -24
  18. package/dist/auth/constants.d.ts.map +0 -1
  19. package/dist/auth/constants.js +0 -24
  20. package/dist/auth/constants.js.map +0 -1
  21. package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
  22. package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
  23. package/dist/auth/createIdentityAttributeHooks.js +0 -122
  24. package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
  25. package/dist/auth/identity-attributes-manager.d.ts +0 -27
  26. package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
  27. package/dist/auth/identity-attributes-manager.js +0 -191
  28. package/dist/auth/identity-attributes-manager.js.map +0 -1
  29. package/dist/auth/identity-attributes.d.ts +0 -19
  30. package/dist/auth/identity-attributes.d.ts.map +0 -1
  31. package/dist/auth/identity-attributes.js +0 -227
  32. package/dist/auth/identity-attributes.js.map +0 -1
  33. package/dist/auth/index.d.ts +0 -8
  34. package/dist/auth/index.d.ts.map +0 -1
  35. package/dist/auth/index.js +0 -8
  36. package/dist/auth/index.js.map +0 -1
  37. package/dist/auth/local-ii-probe.d.ts +0 -57
  38. package/dist/auth/local-ii-probe.d.ts.map +0 -1
  39. package/dist/auth/local-ii-probe.js +0 -121
  40. package/dist/auth/local-ii-probe.js.map +0 -1
  41. package/dist/auth/types.d.ts +0 -222
  42. package/dist/auth/types.d.ts.map +0 -1
  43. package/dist/auth/types.js +0 -2
  44. package/dist/auth/types.js.map +0 -1
  45. package/dist/createActorHooks.d.ts +0 -41
  46. package/dist/createActorHooks.d.ts.map +0 -1
  47. package/dist/createActorHooks.js +0 -17
  48. package/dist/createActorHooks.js.map +0 -1
  49. package/dist/createInfiniteQuery.d.ts +0 -185
  50. package/dist/createInfiniteQuery.d.ts.map +0 -1
  51. package/dist/createInfiniteQuery.js +0 -198
  52. package/dist/createInfiniteQuery.js.map +0 -1
  53. package/dist/createMutation.d.ts +0 -33
  54. package/dist/createMutation.d.ts.map +0 -1
  55. package/dist/createMutation.js +0 -199
  56. package/dist/createMutation.js.map +0 -1
  57. package/dist/createQuery.d.ts +0 -63
  58. package/dist/createQuery.d.ts.map +0 -1
  59. package/dist/createQuery.js +0 -204
  60. package/dist/createQuery.js.map +0 -1
  61. package/dist/createReactorProvider.d.ts +0 -158
  62. package/dist/createReactorProvider.d.ts.map +0 -1
  63. package/dist/createReactorProvider.js +0 -256
  64. package/dist/createReactorProvider.js.map +0 -1
  65. package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
  66. package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
  67. package/dist/createSuspenseInfiniteQuery.js +0 -209
  68. package/dist/createSuspenseInfiniteQuery.js.map +0 -1
  69. package/dist/createSuspenseQuery.d.ts +0 -46
  70. package/dist/createSuspenseQuery.d.ts.map +0 -1
  71. package/dist/createSuspenseQuery.js +0 -158
  72. package/dist/createSuspenseQuery.js.map +0 -1
  73. package/dist/defineDisplayReactor.d.ts +0 -43
  74. package/dist/defineDisplayReactor.d.ts.map +0 -1
  75. package/dist/defineDisplayReactor.js +0 -42
  76. package/dist/defineDisplayReactor.js.map +0 -1
  77. package/dist/defineReactor.d.ts +0 -99
  78. package/dist/defineReactor.d.ts.map +0 -1
  79. package/dist/defineReactor.js +0 -15
  80. package/dist/defineReactor.js.map +0 -1
  81. package/dist/defineReactorShared.d.ts +0 -84
  82. package/dist/defineReactorShared.d.ts.map +0 -1
  83. package/dist/defineReactorShared.js +0 -139
  84. package/dist/defineReactorShared.js.map +0 -1
  85. package/dist/hooks/createAuthHooks.d.ts +0 -50
  86. package/dist/hooks/createAuthHooks.d.ts.map +0 -1
  87. package/dist/hooks/createAuthHooks.js +0 -291
  88. package/dist/hooks/createAuthHooks.js.map +0 -1
  89. package/dist/hooks/index.d.ts +0 -21
  90. package/dist/hooks/index.d.ts.map +0 -1
  91. package/dist/hooks/index.js +0 -24
  92. package/dist/hooks/index.js.map +0 -1
  93. package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
  94. package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
  95. package/dist/hooks/useActorInfiniteQuery.js +0 -89
  96. package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
  97. package/dist/hooks/useActorMethod.d.ts +0 -148
  98. package/dist/hooks/useActorMethod.d.ts.map +0 -1
  99. package/dist/hooks/useActorMethod.js +0 -394
  100. package/dist/hooks/useActorMethod.js.map +0 -1
  101. package/dist/hooks/useActorMutation.d.ts +0 -51
  102. package/dist/hooks/useActorMutation.d.ts.map +0 -1
  103. package/dist/hooks/useActorMutation.js +0 -70
  104. package/dist/hooks/useActorMutation.js.map +0 -1
  105. package/dist/hooks/useActorQuery.d.ts +0 -45
  106. package/dist/hooks/useActorQuery.d.ts.map +0 -1
  107. package/dist/hooks/useActorQuery.js +0 -67
  108. package/dist/hooks/useActorQuery.js.map +0 -1
  109. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
  110. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
  111. package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
  112. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
  113. package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
  114. package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
  115. package/dist/hooks/useActorSuspenseQuery.js +0 -58
  116. package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
  117. package/dist/ownedAuthentication.d.ts +0 -52
  118. package/dist/ownedAuthentication.d.ts.map +0 -1
  119. package/dist/ownedAuthentication.js +0 -49
  120. package/dist/ownedAuthentication.js.map +0 -1
  121. package/dist/server.d.ts +0 -21
  122. package/dist/server.d.ts.map +0 -1
  123. package/dist/server.js +0 -23
  124. package/dist/server.js.map +0 -1
  125. package/dist/testing.d.ts +0 -19
  126. package/dist/testing.d.ts.map +0 -1
  127. package/dist/testing.js +0 -19
  128. package/dist/testing.js.map +0 -1
  129. package/dist/types.d.ts +0 -671
  130. package/dist/types.d.ts.map +0 -1
  131. package/dist/types.js +0 -5
  132. package/dist/types.js.map +0 -1
  133. package/dist/utils.d.ts +0 -207
  134. package/dist/utils.d.ts.map +0 -1
  135. package/dist/utils.js +0 -405
  136. package/dist/utils.js.map +0 -1
  137. package/dist/validation.d.ts +0 -136
  138. package/dist/validation.d.ts.map +0 -1
  139. package/dist/validation.js +0 -144
  140. package/dist/validation.js.map +0 -1
  141. package/src/auth/auth-client-compat.ts +0 -273
  142. package/src/auth/authentication-manager.ts +0 -1682
  143. package/src/auth/constants.ts +0 -32
  144. package/src/auth/createIdentityAttributeHooks.ts +0 -169
  145. package/src/auth/identity-attributes-manager.ts +0 -226
  146. package/src/auth/identity-attributes.ts +0 -345
  147. package/src/auth/index.ts +0 -7
  148. package/src/auth/local-ii-probe.ts +0 -173
  149. package/src/auth/types.ts +0 -243
  150. package/src/createActorHooks.ts +0 -208
  151. package/src/createInfiniteQuery.ts +0 -670
  152. package/src/createMutation.ts +0 -324
  153. package/src/createQuery.ts +0 -369
  154. package/src/createReactorProvider.ts +0 -365
  155. package/src/createSuspenseInfiniteQuery.ts +0 -651
  156. package/src/createSuspenseQuery.ts +0 -304
  157. package/src/defineDisplayReactor.ts +0 -62
  158. package/src/defineReactor.ts +0 -142
  159. package/src/defineReactorShared.ts +0 -268
  160. package/src/hooks/createAuthHooks.ts +0 -371
  161. package/src/hooks/index.ts +0 -103
  162. package/src/hooks/useActorInfiniteQuery.ts +0 -278
  163. package/src/hooks/useActorMethod.ts +0 -710
  164. package/src/hooks/useActorMutation.ts +0 -205
  165. package/src/hooks/useActorQuery.ts +0 -157
  166. package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
  167. package/src/hooks/useActorSuspenseQuery.ts +0 -147
  168. package/src/index.ts +0 -31
  169. package/src/ownedAuthentication.ts +0 -81
  170. package/src/server.ts +0 -23
  171. package/src/testing.ts +0 -18
  172. package/src/types.ts +0 -948
  173. package/src/utils.ts +0 -505
  174. package/src/validation.ts +0 -226
package/src/validation.ts DELETED
@@ -1,226 +0,0 @@
1
- /**
2
- * Validation utilities for React
3
- *
4
- * Helpers for working with ValidationError in React components,
5
- * especially for form integration.
6
- */
7
-
8
- import {
9
- ValidationError,
10
- isValidationError,
11
- ValidationIssue,
12
- } from "@ic-reactor/core"
13
-
14
- // Re-export for convenience
15
- export { isValidationError, ValidationError }
16
- export type { ValidationIssue }
17
-
18
- /**
19
- * A map of field names to error messages.
20
- * This format is compatible with most form libraries.
21
- */
22
- export type FieldErrors = Record<string, string>
23
-
24
- /**
25
- * A map of field names to arrays of error messages.
26
- * Use when you need to show multiple errors per field.
27
- */
28
- export type FieldErrorsMultiple = Record<string, string[]>
29
-
30
- /**
31
- * Options for mapValidationErrors
32
- */
33
- export interface MapValidationErrorsOptions {
34
- /**
35
- * If true, returns all messages for each field as an array.
36
- * If false (default), returns only the first message for each field.
37
- */
38
- multiple?: boolean
39
- }
40
-
41
- /**
42
- * The field an issue belongs to: the first segment of its path, as a string.
43
- * An issue with an empty path is about the whole argument (a zod object-level
44
- * `.refine()`, or any issue of a primitive argument) and belongs to `""`.
45
- */
46
- function fieldNameOf(issue: ValidationIssue): string {
47
- return String(issue.path[0] ?? "")
48
- }
49
-
50
- /**
51
- * Maps validation error issues to a simple field -> message object.
52
- * Returns the first error message for each field path, or every message with
53
- * `{ multiple: true }`. Issues about the whole argument (an empty path) are
54
- * filed under `""`.
55
- *
56
- * @example
57
- * ```tsx
58
- * const { mutate } = useActorMutation({
59
- * functionName: "transfer",
60
- * onError: (error) => {
61
- * if (isValidationError(error)) {
62
- * const fieldErrors = mapValidationErrors(error)
63
- * // { to: "Recipient is required", amount: "Must be a number" }
64
- *
65
- * // Use with React Hook Form
66
- * Object.entries(fieldErrors).forEach(([field, message]) => {
67
- * form.setError(field, { message })
68
- * })
69
- * }
70
- * }
71
- * })
72
- * ```
73
- */
74
- export function mapValidationErrors(
75
- error: ValidationError,
76
- options?: { multiple?: false }
77
- ): FieldErrors
78
- export function mapValidationErrors(
79
- error: ValidationError,
80
- options: { multiple: true }
81
- ): FieldErrorsMultiple
82
- export function mapValidationErrors(
83
- error: ValidationError,
84
- options?: MapValidationErrorsOptions
85
- ): FieldErrors | FieldErrorsMultiple
86
- export function mapValidationErrors(
87
- error: ValidationError,
88
- options?: MapValidationErrorsOptions
89
- ): FieldErrors | FieldErrorsMultiple {
90
- // Collected in a Map, not a plain object: a field named like an
91
- // Object.prototype member (`constructor`, `toString`, `__proto__`) read that
92
- // member back as if the field were already filled, which dropped its issue,
93
- // and threw on `.push` with `multiple`. `Object.fromEntries` then creates
94
- // every field as an own property, `__proto__` included.
95
- if (options?.multiple) {
96
- const messages = new Map<string, string[]>()
97
- for (const issue of error.issues) {
98
- const fieldName = fieldNameOf(issue)
99
- const fieldMessages = messages.get(fieldName)
100
- if (fieldMessages) {
101
- fieldMessages.push(issue.message)
102
- } else {
103
- messages.set(fieldName, [issue.message])
104
- }
105
- }
106
- return Object.fromEntries(messages)
107
- }
108
-
109
- const messages = new Map<string, string>()
110
- for (const issue of error.issues) {
111
- const fieldName = fieldNameOf(issue)
112
- if (!messages.get(fieldName)) {
113
- messages.set(fieldName, issue.message)
114
- }
115
- }
116
- return Object.fromEntries(messages)
117
- }
118
-
119
- /**
120
- * Gets error message for a specific field from a ValidationError.
121
- * Returns undefined if no error exists for that field. Pass `""` for issues
122
- * about the whole argument (an empty path), the key `mapValidationErrors`
123
- * files them under.
124
- *
125
- * @example
126
- * ```tsx
127
- * if (isValidationError(error)) {
128
- * const toError = getFieldError(error, "to")
129
- * const amountError = getFieldError(error, "amount")
130
- * }
131
- * ```
132
- */
133
- export function getFieldError(
134
- error: ValidationError,
135
- fieldName: string
136
- ): string | undefined {
137
- const issue = error.issues.find((i) => fieldNameOf(i) === fieldName)
138
- return issue?.message
139
- }
140
-
141
- /**
142
- * Gets all error messages for a specific field from a ValidationError.
143
- * Returns empty array if no errors exist for that field. Pass `""` for issues
144
- * about the whole argument (an empty path).
145
- *
146
- * @example
147
- * ```tsx
148
- * if (isValidationError(error)) {
149
- * const amountErrors = getFieldErrors(error, "amount")
150
- * // ["Amount is required", "Amount must be positive"]
151
- * }
152
- * ```
153
- */
154
- export function getFieldErrors(
155
- error: ValidationError,
156
- fieldName: string
157
- ): string[] {
158
- return error.issues
159
- .filter((i) => fieldNameOf(i) === fieldName)
160
- .map((i) => i.message)
161
- }
162
-
163
- /**
164
- * Checks if a given error is a ValidationError and optionally
165
- * extracts field errors in one step.
166
- *
167
- * @example
168
- * ```tsx
169
- * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
170
- *
171
- * const handleSubmit = async (data) => {
172
- * try {
173
- * await mutateAsync([data])
174
- * } catch (error) {
175
- * const fieldErrors = extractValidationErrors(error)
176
- * if (fieldErrors) {
177
- * // Handle validation errors
178
- * Object.entries(fieldErrors).forEach(([field, message]) => {
179
- * form.setError(field, { message })
180
- * })
181
- * } else {
182
- * // Handle other errors
183
- * console.error(error)
184
- * }
185
- * }
186
- * }
187
- * ```
188
- */
189
- export function extractValidationErrors(error: unknown): FieldErrors | null {
190
- if (isValidationError(error)) {
191
- return mapValidationErrors(error)
192
- }
193
- return null
194
- }
195
-
196
- /**
197
- * React hook-friendly error handler that extracts validation errors.
198
- * Returns a callback suitable for onError handlers.
199
- *
200
- * @example
201
- * ```tsx
202
- * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
203
- *
204
- * const { mutate } = useActorMutation({
205
- * functionName: "transfer",
206
- * onError: handleValidationError(setFieldErrors),
207
- * })
208
- *
209
- * // In JSX
210
- * <input name="to" />
211
- * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
212
- * ```
213
- */
214
- export function handleValidationError(
215
- setFieldErrors: (errors: FieldErrors) => void,
216
- onOtherError?: (error: Error) => void
217
- ): (error: Error) => void {
218
- return (error: Error) => {
219
- const fieldErrors = extractValidationErrors(error)
220
- if (fieldErrors) {
221
- setFieldErrors(fieldErrors)
222
- } else if (onOtherError) {
223
- onOtherError(error)
224
- }
225
- }
226
- }