@ic-reactor/react 3.12.5 → 4.0.0-beta.1
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 +236 -423
- package/dist/index.d.ts +259 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -17
- package/dist/index.js.map +1 -1
- package/llms.txt +82 -54
- package/package.json +12 -28
- package/src/index.tsx +611 -0
- package/dist/auth/authentication-manager.d.ts +0 -123
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -767
- package/dist/auth/authentication-manager.js.map +0 -1
- package/dist/auth/constants.d.ts +0 -24
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -24
- package/dist/auth/constants.js.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.js +0 -106
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -26
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -107
- package/dist/auth/identity-attributes-manager.js.map +0 -1
- package/dist/auth/identity-attributes.d.ts +0 -19
- package/dist/auth/identity-attributes.d.ts.map +0 -1
- package/dist/auth/identity-attributes.js +0 -170
- package/dist/auth/identity-attributes.js.map +0 -1
- package/dist/auth/index.d.ts +0 -8
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/local-ii-probe.d.ts +0 -46
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -102
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -179
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/createActorHooks.d.ts +0 -52
- package/dist/createActorHooks.d.ts.map +0 -1
- package/dist/createActorHooks.js +0 -17
- package/dist/createActorHooks.js.map +0 -1
- package/dist/createInfiniteQuery.d.ts +0 -144
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -174
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -30
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -192
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -30
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -117
- package/dist/createQuery.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -147
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -177
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -25
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -111
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -125
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -180
- package/dist/defineReactor.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -43
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -131
- package/dist/hooks/createAuthHooks.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -21
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -24
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +0 -39
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -56
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -115
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -250
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -48
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -69
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -32
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -46
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -39
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -56
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.js +0 -47
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/types.d.ts +0 -270
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -51
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -131
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -125
- package/dist/validation.js.map +0 -1
- package/src/auth/authentication-manager.ts +0 -860
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -143
- package/src/auth/identity-attributes-manager.ts +0 -131
- package/src/auth/identity-attributes.ts +0 -270
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -147
- package/src/auth/types.ts +0 -200
- package/src/createActorHooks.ts +0 -220
- package/src/createInfiniteQuery.ts +0 -578
- package/src/createMutation.ts +0 -341
- package/src/createQuery.ts +0 -237
- package/src/createSuspenseInfiniteQuery.ts +0 -601
- package/src/createSuspenseQuery.ts +0 -234
- package/src/defineReactor.ts +0 -324
- package/src/hooks/createAuthHooks.ts +0 -189
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -205
- package/src/hooks/useActorMethod.ts +0 -507
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -124
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -205
- package/src/hooks/useActorSuspenseQuery.ts +0 -132
- package/src/index.ts +0 -23
- package/src/types.ts +0 -499
- package/src/utils.ts +0 -121
- package/src/validation.ts +0 -202
package/src/validation.ts
DELETED
|
@@ -1,202 +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
|
-
* Maps validation error issues to a simple field -> message object.
|
|
43
|
-
* Returns the first error message for each field path.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```tsx
|
|
47
|
-
* const { mutate } = useActorMutation({
|
|
48
|
-
* functionName: "transfer",
|
|
49
|
-
* onError: (error) => {
|
|
50
|
-
* if (isValidationError(error)) {
|
|
51
|
-
* const fieldErrors = mapValidationErrors(error)
|
|
52
|
-
* // { to: "Recipient is required", amount: "Must be a number" }
|
|
53
|
-
*
|
|
54
|
-
* // Use with React Hook Form
|
|
55
|
-
* Object.entries(fieldErrors).forEach(([field, message]) => {
|
|
56
|
-
* form.setError(field, { message })
|
|
57
|
-
* })
|
|
58
|
-
* }
|
|
59
|
-
* }
|
|
60
|
-
* })
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export function mapValidationErrors(error: ValidationError): FieldErrors
|
|
64
|
-
export function mapValidationErrors(
|
|
65
|
-
error: ValidationError,
|
|
66
|
-
options: { multiple: true }
|
|
67
|
-
): FieldErrorsMultiple
|
|
68
|
-
export function mapValidationErrors(
|
|
69
|
-
error: ValidationError,
|
|
70
|
-
options: { multiple: false }
|
|
71
|
-
): FieldErrors
|
|
72
|
-
export function mapValidationErrors(
|
|
73
|
-
error: ValidationError,
|
|
74
|
-
options?: MapValidationErrorsOptions
|
|
75
|
-
): FieldErrors | FieldErrorsMultiple {
|
|
76
|
-
if (options?.multiple) {
|
|
77
|
-
const result: FieldErrorsMultiple = {}
|
|
78
|
-
for (const issue of error.issues) {
|
|
79
|
-
const fieldName = String(issue.path[0] ?? "")
|
|
80
|
-
if (!result[fieldName]) {
|
|
81
|
-
result[fieldName] = []
|
|
82
|
-
}
|
|
83
|
-
result[fieldName].push(issue.message)
|
|
84
|
-
}
|
|
85
|
-
return result
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const result: FieldErrors = {}
|
|
89
|
-
for (const issue of error.issues) {
|
|
90
|
-
const fieldName = String(issue.path[0] ?? "")
|
|
91
|
-
if (!result[fieldName]) {
|
|
92
|
-
result[fieldName] = issue.message
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Gets error message for a specific field from a ValidationError.
|
|
100
|
-
* Returns undefined if no error exists for that field.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```tsx
|
|
104
|
-
* if (isValidationError(error)) {
|
|
105
|
-
* const toError = getFieldError(error, "to")
|
|
106
|
-
* const amountError = getFieldError(error, "amount")
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export function getFieldError(
|
|
111
|
-
error: ValidationError,
|
|
112
|
-
fieldName: string
|
|
113
|
-
): string | undefined {
|
|
114
|
-
const issue = error.issues.find((i) => String(i.path[0]) === fieldName)
|
|
115
|
-
return issue?.message
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Gets all error messages for a specific field from a ValidationError.
|
|
120
|
-
* Returns empty array if no errors exist for that field.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```tsx
|
|
124
|
-
* if (isValidationError(error)) {
|
|
125
|
-
* const amountErrors = getFieldErrors(error, "amount")
|
|
126
|
-
* // ["Amount is required", "Amount must be positive"]
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
export function getFieldErrors(
|
|
131
|
-
error: ValidationError,
|
|
132
|
-
fieldName: string
|
|
133
|
-
): string[] {
|
|
134
|
-
return error.issues
|
|
135
|
-
.filter((i) => String(i.path[0]) === fieldName)
|
|
136
|
-
.map((i) => i.message)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Checks if a given error is a ValidationError and optionally
|
|
141
|
-
* extracts field errors in one step.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```tsx
|
|
145
|
-
* const { mutateAsync } = useActorMutation({ functionName: "transfer" })
|
|
146
|
-
*
|
|
147
|
-
* const handleSubmit = async (data) => {
|
|
148
|
-
* try {
|
|
149
|
-
* await mutateAsync([data])
|
|
150
|
-
* } catch (error) {
|
|
151
|
-
* const fieldErrors = extractValidationErrors(error)
|
|
152
|
-
* if (fieldErrors) {
|
|
153
|
-
* // Handle validation errors
|
|
154
|
-
* Object.entries(fieldErrors).forEach(([field, message]) => {
|
|
155
|
-
* form.setError(field, { message })
|
|
156
|
-
* })
|
|
157
|
-
* } else {
|
|
158
|
-
* // Handle other errors
|
|
159
|
-
* console.error(error)
|
|
160
|
-
* }
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export function extractValidationErrors(error: unknown): FieldErrors | null {
|
|
166
|
-
if (isValidationError(error)) {
|
|
167
|
-
return mapValidationErrors(error)
|
|
168
|
-
}
|
|
169
|
-
return null
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* React hook-friendly error handler that extracts validation errors.
|
|
174
|
-
* Returns a callback suitable for onError handlers.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```tsx
|
|
178
|
-
* const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
|
|
179
|
-
*
|
|
180
|
-
* const { mutate } = useActorMutation({
|
|
181
|
-
* functionName: "transfer",
|
|
182
|
-
* onError: handleValidationError(setFieldErrors),
|
|
183
|
-
* })
|
|
184
|
-
*
|
|
185
|
-
* // In JSX
|
|
186
|
-
* <input name="to" />
|
|
187
|
-
* {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
export function handleValidationError(
|
|
191
|
-
setFieldErrors: (errors: FieldErrors) => void,
|
|
192
|
-
onOtherError?: (error: Error) => void
|
|
193
|
-
): (error: Error) => void {
|
|
194
|
-
return (error: Error) => {
|
|
195
|
-
const fieldErrors = extractValidationErrors(error)
|
|
196
|
-
if (fieldErrors) {
|
|
197
|
-
setFieldErrors(fieldErrors)
|
|
198
|
-
} else if (onOtherError) {
|
|
199
|
-
onOtherError(error)
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|