litestar-vite-plugin 0.15.0-rc.4 → 0.15.0-rc.5
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.
|
@@ -171,3 +171,122 @@ export interface ScrollProps {
|
|
|
171
171
|
/** Next page number, or null if on last page */
|
|
172
172
|
nextPage: number | null;
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* HTTP headers used by the Precognition protocol.
|
|
176
|
+
*
|
|
177
|
+
* These headers enable real-time form validation without executing
|
|
178
|
+
* handler side effects. Compatible with Laravel's laravel-precognition
|
|
179
|
+
* frontend libraries.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* // Sending a Precognition request
|
|
184
|
+
* fetch('/users', {
|
|
185
|
+
* method: 'POST',
|
|
186
|
+
* headers: {
|
|
187
|
+
* [PrecognitionHeaders.PRECOGNITION]: 'true',
|
|
188
|
+
* [PrecognitionHeaders.VALIDATE_ONLY]: 'email,password',
|
|
189
|
+
* },
|
|
190
|
+
* body: JSON.stringify({ email: 'test@example.com', password: '123' })
|
|
191
|
+
* })
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare const PrecognitionHeaders: {
|
|
195
|
+
/** Indicates this is a Precognition validation request */
|
|
196
|
+
readonly PRECOGNITION: "Precognition";
|
|
197
|
+
/** Returned on successful validation (204 response) */
|
|
198
|
+
readonly PRECOGNITION_SUCCESS: "Precognition-Success";
|
|
199
|
+
/** Comma-separated list of fields to validate (partial validation) */
|
|
200
|
+
readonly VALIDATE_ONLY: "Precognition-Validate-Only";
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Validation error format returned by Precognition responses.
|
|
204
|
+
*
|
|
205
|
+
* Follows Laravel's validation error format for compatibility
|
|
206
|
+
* with laravel-precognition-vue and laravel-precognition-react.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* // Error response from server (422)
|
|
211
|
+
* const response: PrecognitionValidationErrors = {
|
|
212
|
+
* message: "The given data was invalid.",
|
|
213
|
+
* errors: {
|
|
214
|
+
* email: ["The email field is required."],
|
|
215
|
+
* password: ["The password must be at least 8 characters."]
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export interface PrecognitionValidationErrors {
|
|
221
|
+
/** Human-readable error message */
|
|
222
|
+
message: string;
|
|
223
|
+
/** Map of field names to array of error messages */
|
|
224
|
+
errors: Record<string, string[]>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Configuration options for Precognition forms.
|
|
228
|
+
*
|
|
229
|
+
* Use with laravel-precognition-vue or laravel-precognition-react.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* // Vue 3
|
|
234
|
+
* import { useForm } from 'laravel-precognition-vue'
|
|
235
|
+
*
|
|
236
|
+
* const form = useForm('post', '/users', {
|
|
237
|
+
* email: '',
|
|
238
|
+
* password: '',
|
|
239
|
+
* }, {
|
|
240
|
+
* validationTimeout: 500,
|
|
241
|
+
* onSuccess: () => { ... }
|
|
242
|
+
* })
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export interface PrecognitionFormConfig {
|
|
246
|
+
/**
|
|
247
|
+
* Debounce timeout in milliseconds before sending validation request.
|
|
248
|
+
* Helps prevent excessive requests during rapid typing.
|
|
249
|
+
*
|
|
250
|
+
* Default varies by library, typically 300-500ms.
|
|
251
|
+
*/
|
|
252
|
+
validationTimeout?: number;
|
|
253
|
+
/**
|
|
254
|
+
* Callback when form submission succeeds.
|
|
255
|
+
*/
|
|
256
|
+
onSuccess?: () => void;
|
|
257
|
+
/**
|
|
258
|
+
* Callback when form submission fails with validation errors.
|
|
259
|
+
*/
|
|
260
|
+
onValidationError?: (errors: PrecognitionValidationErrors) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Callback before each Precognition request.
|
|
263
|
+
* Return false to cancel the request.
|
|
264
|
+
*/
|
|
265
|
+
onBefore?: () => boolean | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Callback after each Precognition request completes.
|
|
268
|
+
*/
|
|
269
|
+
onFinish?: () => void;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Check if a response is a successful Precognition validation.
|
|
273
|
+
*
|
|
274
|
+
* @param response - Fetch Response object
|
|
275
|
+
* @returns True if this is a successful Precognition response (204 with header)
|
|
276
|
+
*/
|
|
277
|
+
export declare function isPrecognitionSuccess(response: Response): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Check if a response is a Precognition validation error.
|
|
280
|
+
*
|
|
281
|
+
* @param response - Fetch Response object
|
|
282
|
+
* @returns True if this is a Precognition validation error (422 with header)
|
|
283
|
+
*/
|
|
284
|
+
export declare function isPrecognitionError(response: Response): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Extract validation errors from a Precognition error response.
|
|
287
|
+
*
|
|
288
|
+
* @param response - Fetch Response object (must be a Precognition error)
|
|
289
|
+
* @returns Promise resolving to validation errors
|
|
290
|
+
* @throws If response is not valid JSON
|
|
291
|
+
*/
|
|
292
|
+
export declare function extractPrecognitionErrors(response: Response): Promise<PrecognitionValidationErrors>;
|
|
@@ -87,3 +87,62 @@ export async function resolvePageComponent(path, pages) {
|
|
|
87
87
|
}
|
|
88
88
|
throw new Error(`Page not found: ${path}`);
|
|
89
89
|
}
|
|
90
|
+
// ============================================================================
|
|
91
|
+
// Precognition Types (Laravel Precognition Protocol)
|
|
92
|
+
// ============================================================================
|
|
93
|
+
/**
|
|
94
|
+
* HTTP headers used by the Precognition protocol.
|
|
95
|
+
*
|
|
96
|
+
* These headers enable real-time form validation without executing
|
|
97
|
+
* handler side effects. Compatible with Laravel's laravel-precognition
|
|
98
|
+
* frontend libraries.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* // Sending a Precognition request
|
|
103
|
+
* fetch('/users', {
|
|
104
|
+
* method: 'POST',
|
|
105
|
+
* headers: {
|
|
106
|
+
* [PrecognitionHeaders.PRECOGNITION]: 'true',
|
|
107
|
+
* [PrecognitionHeaders.VALIDATE_ONLY]: 'email,password',
|
|
108
|
+
* },
|
|
109
|
+
* body: JSON.stringify({ email: 'test@example.com', password: '123' })
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export const PrecognitionHeaders = {
|
|
114
|
+
/** Indicates this is a Precognition validation request */
|
|
115
|
+
PRECOGNITION: "Precognition",
|
|
116
|
+
/** Returned on successful validation (204 response) */
|
|
117
|
+
PRECOGNITION_SUCCESS: "Precognition-Success",
|
|
118
|
+
/** Comma-separated list of fields to validate (partial validation) */
|
|
119
|
+
VALIDATE_ONLY: "Precognition-Validate-Only",
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Check if a response is a successful Precognition validation.
|
|
123
|
+
*
|
|
124
|
+
* @param response - Fetch Response object
|
|
125
|
+
* @returns True if this is a successful Precognition response (204 with header)
|
|
126
|
+
*/
|
|
127
|
+
export function isPrecognitionSuccess(response) {
|
|
128
|
+
return response.status === 204 && response.headers.get(PrecognitionHeaders.PRECOGNITION_SUCCESS) === "true";
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if a response is a Precognition validation error.
|
|
132
|
+
*
|
|
133
|
+
* @param response - Fetch Response object
|
|
134
|
+
* @returns True if this is a Precognition validation error (422 with header)
|
|
135
|
+
*/
|
|
136
|
+
export function isPrecognitionError(response) {
|
|
137
|
+
return response.status === 422 && response.headers.get(PrecognitionHeaders.PRECOGNITION) === "true";
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Extract validation errors from a Precognition error response.
|
|
141
|
+
*
|
|
142
|
+
* @param response - Fetch Response object (must be a Precognition error)
|
|
143
|
+
* @returns Promise resolving to validation errors
|
|
144
|
+
* @throws If response is not valid JSON
|
|
145
|
+
*/
|
|
146
|
+
export async function extractPrecognitionErrors(response) {
|
|
147
|
+
return response.json();
|
|
148
|
+
}
|