@rilaykit/core 4.0.0 → 5.0.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { z } from 'zod';
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
3
 
4
4
  /**
5
5
  * Main configuration class for Rilay form components and workflows
@@ -15,6 +15,20 @@ declare class ril<C> {
15
15
  * @param type - The component type (e.g., 'text', 'email', 'heading'), used as a unique identifier.
16
16
  * @param config - Component configuration without id and type
17
17
  * @returns The ril instance for chaining
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Component avec validation par défaut
22
+ * const factory = ril.create()
23
+ * .addComponent('email', {
24
+ * name: 'Email Input',
25
+ * renderer: EmailInput,
26
+ * validation: {
27
+ * validators: [email('Format email invalide')],
28
+ * validateOnBlur: true,
29
+ * }
30
+ * });
31
+ * ```
18
32
  */
19
33
  addComponent<NewType extends string, TProps = any>(type: NewType, config: Omit<ComponentConfig<TProps>, 'id' | 'type'>): ril<C & {
20
34
  [K in NewType]: TProps;
@@ -113,81 +127,140 @@ interface RilayLicenseConfig {
113
127
  readonly environment?: 'development' | 'production';
114
128
  readonly allowTrial?: boolean;
115
129
  }
130
+ interface ValidationError {
131
+ readonly message: string;
132
+ readonly code?: string;
133
+ readonly path?: string;
134
+ }
116
135
  interface ValidationResult {
117
136
  readonly isValid: boolean;
118
137
  readonly errors: ValidationError[];
119
138
  }
120
- interface ValidationError {
121
- readonly code: string;
122
- readonly message: string;
123
- readonly path?: string[];
124
- }
125
139
  interface ValidationContext {
126
- readonly fieldId: string;
127
- readonly formData: Record<string, any>;
128
- readonly fieldProps: Record<string, any>;
129
- readonly touched: boolean;
130
- readonly dirty: boolean;
131
- }
132
- type ValidatorFunction<TProps = any> = (value: any, context: ValidationContext, props: TProps) => ValidationResult | Promise<ValidationResult>;
133
- interface ValidationConfig<TProps = any> {
134
- readonly validator?: ValidatorFunction<TProps>;
135
- readonly debounceMs?: number;
140
+ readonly fieldId?: string;
141
+ readonly formId?: string;
142
+ readonly stepId?: string;
143
+ readonly workflowId?: string;
144
+ readonly allFormData?: Record<string, any>;
145
+ readonly stepData?: Record<string, any>;
146
+ readonly workflowData?: Record<string, any>;
147
+ }
148
+ type FieldValidator<T = any> = (value: T, context: ValidationContext) => ValidationResult | Promise<ValidationResult>;
149
+ type FormValidator<T = Record<string, any>> = (formData: T, context: ValidationContext) => ValidationResult | Promise<ValidationResult>;
150
+ type ValidationSchema<T = any> = {
151
+ parse: (value: T) => T;
152
+ safeParse: (value: T) => {
153
+ success: boolean;
154
+ data?: T;
155
+ error?: any;
156
+ };
157
+ };
158
+ interface ValidationAdapter<TSchema = any> {
159
+ readonly name: string;
160
+ readonly version?: string;
161
+ createFieldValidator<T>(schema: TSchema): FieldValidator<T>;
162
+ createFormValidator<T>(schema: TSchema): FormValidator<T>;
163
+ }
164
+ interface FieldValidationConfig {
165
+ readonly validators?: FieldValidator[];
166
+ readonly schema?: ValidationSchema;
136
167
  readonly validateOnChange?: boolean;
137
168
  readonly validateOnBlur?: boolean;
169
+ readonly debounceMs?: number;
170
+ }
171
+ interface FormValidationConfig {
172
+ readonly validators?: FormValidator[];
173
+ readonly schema?: ValidationSchema;
138
174
  readonly validateOnSubmit?: boolean;
139
- readonly dependencies?: string[];
175
+ readonly validateOnStepChange?: boolean;
176
+ }
177
+ type ComponentRenderer<TProps = any> = (props: ComponentRenderProps<TProps>) => React__default.ReactElement;
178
+ type RendererChildrenFunction<TProps = any> = (props: TProps) => React__default.ReactNode;
179
+ interface ComponentRendererBaseProps<TProps = any> {
180
+ className?: string;
181
+ children?: React__default.ReactNode | RendererChildrenFunction<TProps>;
182
+ renderAs?: 'default' | 'children' | boolean;
183
+ }
184
+ interface ComponentRendererWrapperProps<TProps = any> extends Omit<ComponentRendererBaseProps<TProps>, 'className'> {
185
+ name: string;
186
+ props: TProps;
187
+ renderer?: RendererChildrenFunction<TProps>;
140
188
  }
141
- type ComponentRenderer<TProps = any> = (props: ComponentRenderProps<TProps>) => React.ReactElement;
142
189
  interface ComponentRenderProps<TProps = any> {
143
190
  id: string;
144
191
  props: TProps;
145
192
  value?: any;
146
193
  onChange?: (value: any) => void;
147
194
  onBlur?: () => void;
148
- error?: ValidationError[];
149
- touched?: boolean;
150
195
  disabled?: boolean;
196
+ error?: ValidationError[];
151
197
  isValidating?: boolean;
152
198
  [key: string]: any;
153
199
  }
154
- type RendererChildrenFunction<TProps = any> = (props: TProps) => React.ReactNode;
155
- declare function resolveRendererChildren<TProps>(children: React.ReactNode | RendererChildrenFunction<TProps> | undefined, props: TProps): React.ReactNode;
156
200
  interface ComponentConfig<TProps = any> {
157
201
  readonly id: string;
158
202
  readonly type: string;
159
203
  readonly name: string;
160
204
  readonly description?: string;
161
205
  readonly renderer: ComponentRenderer<TProps>;
162
- readonly validation?: ValidationConfig<TProps>;
163
206
  readonly defaultProps?: Partial<TProps>;
164
207
  readonly useFieldRenderer?: boolean;
208
+ readonly validation?: FieldValidationConfig;
165
209
  }
166
210
  interface FormFieldConfig {
167
211
  readonly id: string;
168
212
  readonly componentId: string;
169
213
  readonly props: Record<string, any>;
170
- readonly validation?: ValidationConfig;
171
- readonly conditional?: ConditionalConfig;
214
+ readonly validation?: FieldValidationConfig;
172
215
  }
173
216
  interface FormFieldRow {
174
217
  readonly id: string;
175
218
  readonly fields: FormFieldConfig[];
176
219
  readonly maxColumns?: number;
177
- readonly spacing?: 'tight' | 'normal' | 'loose';
178
- readonly alignment?: 'start' | 'center' | 'end' | 'stretch';
179
220
  }
180
- interface ConditionalConfig {
181
- readonly condition: (formData: Record<string, any>) => boolean;
182
- readonly action: 'show' | 'hide' | 'disable' | 'require';
221
+ interface FormConfiguration<C extends Record<string, any> = Record<string, never>> {
222
+ readonly id: string;
223
+ readonly config: ril<C>;
224
+ readonly rows: FormFieldRow[];
225
+ readonly allFields: FormFieldConfig[];
226
+ readonly renderConfig?: FormRenderConfig;
227
+ readonly validation?: FormValidationConfig;
228
+ }
229
+ interface FormRenderConfig {
230
+ readonly rowRenderer?: FormRowRenderer;
231
+ readonly bodyRenderer?: FormBodyRenderer;
232
+ readonly submitButtonRenderer?: FormSubmitButtonRenderer;
233
+ readonly fieldRenderer?: FieldRenderer;
234
+ }
235
+ interface FormComponentRendererProps {
236
+ children: React__default.ReactNode;
237
+ }
238
+ interface FormRowRendererProps {
239
+ row: FormFieldRow;
240
+ children: React__default.ReactNode;
241
+ className?: string;
242
+ }
243
+ interface FormBodyRendererProps {
244
+ formConfig: FormConfiguration;
245
+ children: React__default.ReactNode;
246
+ className?: string;
247
+ }
248
+ interface FormSubmitButtonRendererProps {
249
+ isSubmitting: boolean;
250
+ onSubmit: () => void;
251
+ className?: string;
252
+ children?: React__default.ReactNode;
183
253
  }
184
- interface StepLifecycleHooks {
185
- readonly onBeforeEnter?: (stepData: any, allData: any, context: WorkflowContext) => Promise<void>;
186
- readonly onAfterLeave?: (stepData: any, allData: any, context: WorkflowContext) => Promise<boolean>;
187
- readonly onValidate?: (stepData: any, context: WorkflowContext) => Promise<ValidationResult>;
188
- readonly onTransform?: (stepData: any, context: WorkflowContext) => Promise<any>;
189
- readonly onError?: (error: Error, context: WorkflowContext) => Promise<void>;
254
+ interface FieldRendererProps {
255
+ children: React__default.ReactNode;
256
+ id: string;
257
+ disabled?: boolean;
258
+ [key: string]: any;
190
259
  }
260
+ type FormRowRenderer = RendererChildrenFunction<FormRowRendererProps>;
261
+ type FormBodyRenderer = RendererChildrenFunction<FormBodyRendererProps>;
262
+ type FormSubmitButtonRenderer = RendererChildrenFunction<FormSubmitButtonRendererProps>;
263
+ type FieldRenderer = RendererChildrenFunction<FieldRendererProps>;
191
264
  interface WorkflowContext {
192
265
  readonly workflowId: string;
193
266
  readonly currentStepIndex: number;
@@ -197,80 +270,61 @@ interface WorkflowContext {
197
270
  readonly isFirstStep: boolean;
198
271
  readonly isLastStep: boolean;
199
272
  readonly visitedSteps: Set<string>;
200
- readonly user?: any;
201
- }
202
- interface StepPermissions {
203
- readonly requiredRoles?: string[];
204
- readonly requiredPermissions?: string[];
205
- readonly customGuard?: (user: any, context: WorkflowContext) => boolean | Promise<boolean>;
206
- }
207
- interface DynamicStepConfig {
208
- readonly resolver: (previousData: any, context: WorkflowContext) => Promise<StepConfig[]>;
209
- readonly cacheKey?: string;
210
- readonly retryPolicy?: RetryPolicy;
211
273
  }
212
- interface RetryPolicy {
213
- readonly maxRetries: number;
214
- readonly delayMs: number;
215
- readonly backoffMultiplier?: number;
274
+ interface StepDataHelper {
275
+ /**
276
+ * Set data for a specific step by step ID
277
+ */
278
+ setStepData: (stepId: string, data: Record<string, any>) => void;
279
+ /**
280
+ * Set specific field values for a step
281
+ */
282
+ setStepFields: (stepId: string, fields: Record<string, any>) => void;
283
+ /**
284
+ * Get current data for a specific step
285
+ */
286
+ getStepData: (stepId: string) => Record<string, any>;
287
+ /**
288
+ * Set field value for the next step
289
+ */
290
+ setNextStepField: (fieldId: string, value: any) => void;
291
+ /**
292
+ * Set multiple fields for the next step
293
+ */
294
+ setNextStepFields: (fields: Record<string, any>) => void;
295
+ /**
296
+ * Get all workflow data
297
+ */
298
+ getAllData: () => Record<string, any>;
299
+ /**
300
+ * Get all step configurations for reference
301
+ */
302
+ getSteps: () => StepConfig[];
216
303
  }
217
304
  interface StepConfig {
218
305
  readonly id: string;
219
306
  readonly title: string;
220
307
  readonly description?: string;
221
308
  readonly formConfig: FormConfiguration;
222
- readonly validation?: StepValidationConfig;
223
- readonly conditional?: StepConditionalConfig;
224
309
  readonly allowSkip?: boolean;
225
- readonly requiredToComplete?: boolean;
226
- readonly hooks?: StepLifecycleHooks;
227
- readonly permissions?: StepPermissions;
228
- readonly isDynamic?: boolean;
229
- readonly dynamicConfig?: DynamicStepConfig;
230
310
  readonly renderer?: CustomStepRenderer;
311
+ readonly onAfterValidation?: (stepData: Record<string, any>, helper: StepDataHelper, context: WorkflowContext) => void | Promise<void>;
231
312
  }
232
- interface StepValidationConfig {
233
- readonly validator?: (stepData: Record<string, any>, allFormData: Record<string, any>, context: WorkflowContext) => ValidationResult | Promise<ValidationResult>;
234
- readonly validateOnStepChange?: boolean;
235
- readonly blockNextIfInvalid?: boolean;
236
- }
237
- interface StepConditionalConfig {
238
- readonly condition: (formData: Record<string, any>, context: WorkflowContext) => boolean;
239
- readonly action: 'show' | 'hide' | 'skip';
240
- }
241
- type CustomStepRenderer = (props: StepConfig) => React.ReactElement;
242
- interface WorkflowPersistenceData {
243
- readonly workflowId: string;
244
- readonly currentStepIndex: number;
245
- readonly allData: Record<string, any>;
246
- readonly metadata: {
247
- readonly timestamp: number;
248
- readonly version?: string;
249
- readonly userId?: string;
250
- readonly sessionId?: string;
251
- };
252
- }
253
- interface PersistenceAdapter {
313
+ type CustomStepRenderer = (props: StepConfig) => React__default.ReactElement;
314
+ interface WorkflowConfig {
315
+ readonly id: string;
254
316
  readonly name: string;
255
- save(key: string, data: WorkflowPersistenceData): Promise<void>;
256
- load(key: string): Promise<WorkflowPersistenceData | null>;
257
- remove(key: string): Promise<void>;
258
- exists(key: string): Promise<boolean>;
259
- list?(pattern?: string): Promise<string[]>;
260
- }
261
- interface PersistenceConfig {
262
- readonly adapter: PersistenceAdapter;
263
- readonly key?: string;
264
- readonly debounceMs?: number;
265
- readonly autoSave?: boolean;
266
- readonly saveOnStepChange?: boolean;
267
- readonly encryptionKey?: string;
268
- readonly maxRetries?: number;
269
- readonly retryDelayMs?: number;
270
- readonly onSave?: (data: WorkflowPersistenceData) => Promise<void> | void;
271
- readonly onLoad?: (data: WorkflowPersistenceData) => Promise<void> | void;
272
- readonly onError?: (error: Error, operation: 'save' | 'load' | 'remove') => Promise<void> | void;
273
- readonly onRetry?: (attempt: number, maxRetries: number, error: Error) => Promise<void> | void;
317
+ readonly description?: string;
318
+ readonly steps: StepConfig[];
319
+ readonly analytics?: WorkflowAnalytics;
320
+ readonly plugins?: WorkflowPlugin[];
321
+ readonly renderConfig?: WorkflowRenderConfig;
322
+ }
323
+ interface WorkflowRenderConfig {
324
+ readonly stepperRenderer?: WorkflowStepperRenderer;
325
+ readonly nextButtonRenderer?: WorkflowNextButtonRenderer;
326
+ readonly previousButtonRenderer?: WorkflowPreviousButtonRenderer;
327
+ readonly skipButtonRenderer?: WorkflowSkipButtonRenderer;
274
328
  }
275
329
  interface WorkflowAnalytics {
276
330
  readonly onWorkflowStart?: (workflowId: string, context: WorkflowContext) => void;
@@ -279,43 +333,21 @@ interface WorkflowAnalytics {
279
333
  readonly onStepStart?: (stepId: string, timestamp: number, context: WorkflowContext) => void;
280
334
  readonly onStepComplete?: (stepId: string, duration: number, data: any, context: WorkflowContext) => void;
281
335
  readonly onStepSkip?: (stepId: string, reason: string, context: WorkflowContext) => void;
282
- readonly onValidationError?: (stepId: string, errors: ValidationError[], context: WorkflowContext) => void;
283
336
  readonly onError?: (error: Error, context: WorkflowContext) => void;
284
337
  }
285
- interface WorkflowHooks {
286
- readonly onStepChange?: (from: string, to: string, context: WorkflowContext) => void;
287
- readonly onDataChange?: (data: any, context: WorkflowContext) => void;
288
- readonly onValidation?: (result: ValidationResult, context: WorkflowContext) => void;
289
- }
290
338
  interface WorkflowPlugin {
291
339
  readonly name: string;
292
340
  readonly version?: string;
293
341
  readonly install: (workflow: any) => void;
294
- readonly hooks?: WorkflowHooks;
295
342
  readonly dependencies?: string[];
296
343
  }
297
- interface WorkflowConfig {
298
- readonly id: string;
299
- readonly name: string;
300
- readonly description?: string;
301
- readonly steps: StepConfig[];
302
- readonly navigation?: NavigationConfig;
303
- readonly persistence?: PersistenceConfig;
304
- readonly completion?: CompletionConfig;
305
- readonly analytics?: WorkflowAnalytics;
306
- readonly plugins?: WorkflowPlugin[];
307
- readonly renderConfig?: WorkflowRenderConfig;
308
- }
309
- interface NavigationConfig {
310
- readonly allowBackNavigation?: boolean;
311
- readonly allowStepSkipping?: boolean;
312
- readonly showProgress?: boolean;
313
- readonly customNavigation?: boolean;
314
- }
315
- interface CompletionConfig {
316
- readonly onComplete?: (formData: Record<string, any>) => void | Promise<void>;
317
- readonly confirmBeforeSubmit?: boolean;
318
- readonly customCompletionStep?: any;
344
+ interface WorkflowComponentRendererBaseProps {
345
+ children?: React__default.ReactNode;
346
+ className?: string;
347
+ currentStep: StepConfig;
348
+ stepData: Record<string, any>;
349
+ allData: Record<string, any>;
350
+ context: WorkflowContext;
319
351
  }
320
352
  interface WorkflowStepperRendererProps {
321
353
  readonly steps: StepConfig[];
@@ -324,96 +356,26 @@ interface WorkflowStepperRendererProps {
324
356
  readonly onStepClick?: (stepIndex: number) => void;
325
357
  readonly className?: string;
326
358
  }
327
- type WorkflowStepperRenderer = (props: WorkflowStepperRendererProps) => React.ReactElement;
328
- interface WorkflowRenderConfig {
329
- readonly stepperRenderer?: WorkflowStepperRenderer;
330
- readonly nextButtonRenderer?: WorkflowNextButtonRenderer;
331
- readonly previousButtonRenderer?: WorkflowPreviousButtonRenderer;
332
- readonly skipButtonRenderer?: WorkflowSkipButtonRenderer;
333
- }
334
- interface FormRowRendererProps {
335
- row: FormFieldRow;
336
- children: React.ReactNode;
337
- className?: string;
338
- spacing?: 'tight' | 'normal' | 'loose';
339
- alignment?: 'start' | 'center' | 'end' | 'stretch';
340
- }
341
- interface FormBodyRendererProps {
342
- formConfig: FormConfiguration;
343
- children: React.ReactNode;
344
- className?: string;
345
- }
346
- interface FormSubmitButtonRendererProps {
347
- isSubmitting: boolean;
348
- isValid: boolean;
349
- isDirty: boolean;
350
- onSubmit: () => void;
351
- className?: string;
352
- children?: React.ReactNode;
353
- }
354
- type FormRowRenderer = (props: FormRowRendererProps) => React.ReactElement;
355
- type FormBodyRenderer = (props: FormBodyRendererProps) => React.ReactElement;
356
- type FormSubmitButtonRenderer = (props: FormSubmitButtonRendererProps) => React.ReactElement;
357
- interface FieldRendererProps {
358
- children: React.ReactNode;
359
- id: string;
360
- error?: ValidationError[];
361
- touched?: boolean;
362
- disabled?: boolean;
363
- isValidating?: boolean;
364
- [key: string]: any;
365
- }
366
- type FieldRenderer = (props: FieldRendererProps) => React.ReactElement;
367
- interface FormRenderConfig {
368
- readonly rowRenderer?: FormRowRenderer;
369
- readonly bodyRenderer?: FormBodyRenderer;
370
- readonly submitButtonRenderer?: FormSubmitButtonRenderer;
371
- readonly fieldRenderer?: FieldRenderer;
372
- }
373
- interface FormConfiguration<C extends Record<string, any> = Record<string, never>> {
374
- readonly id: string;
375
- readonly schema?: any;
376
- readonly config: ril<C>;
377
- readonly rows: FormFieldRow[];
378
- readonly allFields: FormFieldConfig[];
379
- readonly renderConfig?: FormRenderConfig;
380
- }
381
- interface WorkflowNextButtonRendererProps {
359
+ type WorkflowNextButtonRendererProps = WorkflowComponentRendererBaseProps & {
382
360
  isLastStep: boolean;
383
361
  canGoNext: boolean;
384
362
  isSubmitting: boolean;
385
- onNext: (event?: React.FormEvent) => void;
386
- onSubmit: (event?: React.FormEvent) => void;
387
- className?: string;
388
- children?: React.ReactNode;
389
- currentStep: StepConfig;
390
- stepData: Record<string, any>;
391
- allData: Record<string, any>;
392
- context: WorkflowContext;
393
- }
394
- interface WorkflowPreviousButtonRendererProps {
363
+ onSubmit: (event?: React__default.FormEvent) => void;
364
+ };
365
+ type WorkflowPreviousButtonRendererProps = WorkflowComponentRendererBaseProps & {
395
366
  canGoPrevious: boolean;
396
- onPrevious: (event?: React.FormEvent) => void;
397
- className?: string;
398
- children?: React.ReactNode;
399
- currentStep: StepConfig;
400
- stepData: Record<string, any>;
401
- allData: Record<string, any>;
402
- context: WorkflowContext;
403
- }
404
- interface WorkflowSkipButtonRendererProps {
367
+ onPrevious: (event?: React__default.FormEvent) => void;
368
+ };
369
+ type WorkflowSkipButtonRendererProps = WorkflowComponentRendererBaseProps & {
405
370
  canSkip: boolean;
406
- onSkip: (event?: React.FormEvent) => void;
407
- className?: string;
408
- children?: React.ReactNode;
409
- currentStep: StepConfig;
410
- stepData: Record<string, any>;
411
- allData: Record<string, any>;
412
- context: WorkflowContext;
413
- }
414
- type WorkflowNextButtonRenderer = (props: WorkflowNextButtonRendererProps) => React.ReactElement;
415
- type WorkflowPreviousButtonRenderer = (props: WorkflowPreviousButtonRendererProps) => React.ReactElement;
416
- type WorkflowSkipButtonRenderer = (props: WorkflowSkipButtonRendererProps) => React.ReactElement;
371
+ onSkip: (event?: React__default.FormEvent) => void;
372
+ };
373
+ type WorkflowStepperRenderer = RendererChildrenFunction<WorkflowStepperRendererProps>;
374
+ type WorkflowNextButtonRenderer = RendererChildrenFunction<WorkflowNextButtonRendererProps>;
375
+ type WorkflowPreviousButtonRenderer = RendererChildrenFunction<WorkflowPreviousButtonRendererProps>;
376
+ type WorkflowSkipButtonRenderer = RendererChildrenFunction<WorkflowSkipButtonRendererProps>;
377
+
378
+ declare function ComponentRendererWrapper<TProps = any>({ children, renderAs, renderer, name, props: baseProps, }: ComponentRendererWrapperProps<TProps>): React$1.ReactNode;
417
379
 
418
380
  /**
419
381
  * Utility for merging partial configurations into existing objects
@@ -436,26 +398,6 @@ declare class IdGenerator {
436
398
  next(prefix: string): string;
437
399
  reset(prefix?: string): void;
438
400
  }
439
- /**
440
- * Validation error builder for consistent error handling
441
- */
442
- declare class ValidationErrorBuilder {
443
- private errors;
444
- add(code: string, message: string, path?: string[]): this;
445
- addIf(condition: boolean, code: string, message: string, path?: string[]): this;
446
- build(): ValidationError[];
447
- hasErrors(): boolean;
448
- clear(): this;
449
- }
450
- /**
451
- * Common validation patterns
452
- */
453
- declare const ValidationPatterns: {
454
- hasValue: (value: any) => boolean;
455
- isArray: (value: any) => value is any[];
456
- arrayMinLength: (value: any[], min: number) => boolean;
457
- arrayMaxLength: (value: any[], max: number) => boolean;
458
- };
459
401
  /**
460
402
  * Polymorphic helper for handling single items or arrays
461
403
  */
@@ -469,167 +411,416 @@ declare function deepClone<T>(obj: T): T;
469
411
  */
470
412
  declare function configureObject<T>(target: T, updates: Partial<T>, allowedKeys?: (keyof T)[]): T;
471
413
 
414
+ declare function resolveRendererChildren<TProps>(children: React.ReactNode | RendererChildrenFunction<TProps> | undefined, props: TProps): React.ReactNode;
415
+
472
416
  /**
473
- * Create a `Zod`-based validator
474
- * @param schema - Zod schema to validate against
475
- * @returns Validator function
417
+ * @fileoverview Validation utilities
418
+ *
419
+ * This module provides utility functions for working with validation results,
420
+ * combining validators, and managing validation contexts.
476
421
  */
477
- declare const createZodValidator: <T>(schema: z.ZodSchema<T>) => ValidatorFunction;
422
+
478
423
  /**
479
- * Create a custom validator from a validation function
480
- * @param validationFn - Function that returns boolean, string, or Promise
481
- * @returns Validator function
424
+ * Creates a validation result object
425
+ *
426
+ * @param isValid - Whether the validation passed
427
+ * @param errors - Array of validation errors (empty if valid)
428
+ * @returns A complete ValidationResult object
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * const result = createValidationResult(false, [
433
+ * { message: 'Email is required', code: 'REQUIRED' }
434
+ * ]);
435
+ * ```
482
436
  */
483
- declare const createCustomValidator: (validationFn: (value: any, context: ValidationContext) => boolean | string | Promise<boolean | string>) => ValidatorFunction;
437
+ declare function createValidationResult(isValid: boolean, errors?: ValidationError[]): ValidationResult;
484
438
  /**
485
- * Combine multiple validators
486
- * @param validators - Array of validators to combine
487
- * @param mode - 'all' (all must pass) or 'any' (at least one must pass)
488
- * @returns Combined validator function
439
+ * Combines multiple validation results into a single result
440
+ *
441
+ * The combined result is valid only if all input results are valid.
442
+ * All errors from all results are included in the combined result.
443
+ *
444
+ * @param results - Array of ValidationResult objects to combine
445
+ * @returns A single ValidationResult combining all inputs
446
+ *
447
+ * @example
448
+ * ```typescript
449
+ * const combined = combineValidationResults([
450
+ * emailValidator(value),
451
+ * requiredValidator(value),
452
+ * minLengthValidator(value)
453
+ * ]);
454
+ * ```
489
455
  */
490
- declare const combineValidators: (validators: ValidatorFunction[], mode?: "all" | "any") => ValidatorFunction;
456
+ declare function combineValidationResults(results: ValidationResult[]): ValidationResult;
491
457
  /**
492
- * Create a conditional validator that only runs when condition is met
493
- * @param condition - Function to determine if validation should run
494
- * @param validator - Validator to run when condition is true
495
- * @returns Conditional validator function
458
+ * Runs multiple synchronous validators and combines their results
459
+ *
460
+ * @param validators - Array of validators to run
461
+ * @param value - The value to validate
462
+ * @param context - Validation context
463
+ * @returns Combined validation result
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const result = runValidators([
468
+ * required,
469
+ * email,
470
+ * minLength(5)
471
+ * ], emailValue, context);
472
+ * ```
496
473
  */
497
- declare const createConditionalValidator: (condition: (value: any, context: ValidationContext) => boolean, validator: ValidatorFunction) => ValidatorFunction;
474
+ declare function runValidators<T>(validators: FieldValidator<T>[], value: T, context: ValidationContext): ValidationResult;
498
475
  /**
499
- * Common validation patterns
476
+ * Runs multiple asynchronous validators and combines their results
477
+ *
478
+ * @param validators - Array of validators to run (can be sync or async)
479
+ * @param value - The value to validate
480
+ * @param context - Validation context
481
+ * @returns Promise resolving to combined validation result
482
+ *
483
+ * @example
484
+ * ```typescript
485
+ * const result = await runValidatorsAsync([
486
+ * required,
487
+ * email,
488
+ * checkEmailUnique // async validator
489
+ * ], emailValue, context);
490
+ * ```
500
491
  */
501
- declare const commonValidators: {
502
- /**
503
- * Required field validator
504
- */
505
- required: (message?: string) => ValidatorFunction;
506
- /**
507
- * Email validation
508
- */
509
- email: (message?: string) => ValidatorFunction;
510
- /**
511
- * Minimum length validation
512
- */
513
- minLength: (min: number, message?: string) => ValidatorFunction;
514
- /**
515
- * Maximum length validation
516
- */
517
- maxLength: (max: number, message?: string) => ValidatorFunction;
518
- /**
519
- * Pattern/regex validation
520
- */
521
- pattern: (regex: RegExp, message?: string) => ValidatorFunction;
522
- /**
523
- * Number range validation
524
- */
525
- numberRange: (min?: number, max?: number, message?: string) => ValidatorFunction;
526
- /**
527
- * URL validation
528
- */
529
- url: (message?: string) => ValidatorFunction;
530
- /**
531
- * Phone number validation (basic)
532
- */
533
- phoneNumber: (message?: string) => ValidatorFunction;
534
- /**
535
- * Custom async validation with debouncing
536
- */
537
- asyncValidation: (asyncFn: (value: any, context: ValidationContext) => Promise<boolean | string>, debounceMs?: number) => ValidatorFunction;
538
- };
492
+ declare function runValidatorsAsync<T>(validators: FieldValidator<T>[], value: T, context: ValidationContext): Promise<ValidationResult>;
539
493
  /**
540
- * Utility to create validation result
541
- * @param isValid - Whether validation passed
542
- * @param errors - Array of errors (optional)
543
- * @returns ValidationResult object
494
+ * Creates a validation context object
495
+ *
496
+ * @param options - Context configuration options
497
+ * @returns A complete ValidationContext object
498
+ *
499
+ * @example
500
+ * ```typescript
501
+ * const context = createValidationContext({
502
+ * fieldId: 'email',
503
+ * formId: 'registration',
504
+ * allFormData: { email: 'test@example.com', name: 'John' }
505
+ * });
506
+ * ```
544
507
  */
545
- declare const createValidationResult: (isValid: boolean, errors?: ValidationError[]) => ValidationResult;
508
+ declare function createValidationContext(options?: Partial<ValidationContext>): ValidationContext;
509
+
546
510
  /**
547
- * Utility to create validation error
548
- * @param code - Error code
549
- * @param message - Error message
550
- * @param path - Error path (optional)
551
- * @returns ValidationError object
511
+ * @fileoverview Built-in validators
512
+ *
513
+ * This module provides a comprehensive set of built-in validators for common
514
+ * validation scenarios. These validators follow the FieldValidator interface
515
+ * and can be used standalone or combined with other validators.
552
516
  */
553
- declare const createValidationError: (code: string, message: string, path?: string[]) => ValidationError;
554
517
 
555
518
  /**
556
- * LocalStorage persistence adapter
557
- * Perfect for client-side persistence across browser sessions
558
- */
559
- declare class LocalStorageAdapter implements PersistenceAdapter {
560
- readonly name = "localStorage";
561
- save(key: string, data: WorkflowPersistenceData): Promise<void>;
562
- load(key: string): Promise<WorkflowPersistenceData | null>;
563
- remove(key: string): Promise<void>;
564
- exists(key: string): Promise<boolean>;
565
- list(pattern?: string): Promise<string[]>;
566
- }
567
- /**
568
- * SessionStorage persistence adapter
569
- * Perfect for temporary persistence within a single browser session
570
- */
571
- declare class SessionStorageAdapter implements PersistenceAdapter {
572
- readonly name = "sessionStorage";
573
- save(key: string, data: WorkflowPersistenceData): Promise<void>;
574
- load(key: string): Promise<WorkflowPersistenceData | null>;
575
- remove(key: string): Promise<void>;
576
- exists(key: string): Promise<boolean>;
577
- list(pattern?: string): Promise<string[]>;
578
- }
579
- /**
580
- * In-Memory persistence adapter
581
- * Perfect for testing or temporary workflows
582
- */
583
- declare class MemoryAdapter implements PersistenceAdapter {
584
- readonly name = "memory";
585
- private storage;
586
- save(key: string, data: WorkflowPersistenceData): Promise<void>;
587
- load(key: string): Promise<WorkflowPersistenceData | null>;
588
- remove(key: string): Promise<void>;
589
- exists(key: string): Promise<boolean>;
590
- list(pattern?: string): Promise<string[]>;
591
- clear(): void;
592
- }
519
+ * Validates that a value is not empty, null, or undefined
520
+ *
521
+ * @param message - Custom error message (optional)
522
+ * @returns A FieldValidator function
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * const nameValidator = required('Name is required');
527
+ * ```
528
+ */
529
+ declare function required(message?: string): FieldValidator;
593
530
  /**
594
- * Composite adapter that can use multiple adapters with fallback
595
- * Perfect for robust persistence with primary/backup strategies
531
+ * Validates minimum string length
532
+ *
533
+ * @param min - Minimum length required
534
+ * @param message - Custom error message (optional)
535
+ * @returns A FieldValidator function
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * const passwordValidator = minLength(8, 'Password must be at least 8 characters');
540
+ * ```
596
541
  */
597
- declare class CompositeAdapter implements PersistenceAdapter {
598
- private primary;
599
- private fallbacks;
600
- readonly name = "composite";
601
- constructor(primary: PersistenceAdapter, fallbacks?: PersistenceAdapter[]);
602
- save(key: string, data: WorkflowPersistenceData): Promise<void>;
603
- load(key: string): Promise<WorkflowPersistenceData | null>;
604
- remove(key: string): Promise<void>;
605
- exists(key: string): Promise<boolean>;
606
- list(pattern?: string): Promise<string[]>;
607
- }
542
+ declare function minLength(min: number, message?: string): FieldValidator<string>;
543
+ /**
544
+ * Validates maximum string length
545
+ *
546
+ * @param max - Maximum length allowed
547
+ * @param message - Custom error message (optional)
548
+ * @returns A FieldValidator function
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const bioValidator = maxLength(500, 'Bio must be under 500 characters');
553
+ * ```
554
+ */
555
+ declare function maxLength(max: number, message?: string): FieldValidator<string>;
556
+ /**
557
+ * Validates that a string matches a regular expression pattern
558
+ *
559
+ * @param regex - The regular expression pattern
560
+ * @param message - Custom error message (optional)
561
+ * @returns A FieldValidator function
562
+ *
563
+ * @example
564
+ * ```typescript
565
+ * const phoneValidator = pattern(/^\d{3}-\d{3}-\d{4}$/, 'Invalid phone format');
566
+ * ```
567
+ */
568
+ declare function pattern(regex: RegExp, message?: string): FieldValidator<string>;
569
+ /**
570
+ * Email validation using a comprehensive regex pattern
571
+ *
572
+ * @param message - Custom error message (optional)
573
+ * @returns A FieldValidator function
574
+ *
575
+ * @example
576
+ * ```typescript
577
+ * const emailValidator = email('Please enter a valid email address');
578
+ * ```
579
+ */
580
+ declare function email(message?: string): FieldValidator<string>;
581
+ /**
582
+ * URL validation using a comprehensive regex pattern
583
+ *
584
+ * @param message - Custom error message (optional)
585
+ * @returns A FieldValidator function
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const websiteValidator = url('Please enter a valid URL');
590
+ * ```
591
+ */
592
+ declare function url(message?: string): FieldValidator<string>;
593
+ /**
594
+ * Validates that a value is a valid number
595
+ *
596
+ * @param message - Custom error message (optional)
597
+ * @returns A FieldValidator function
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * const ageValidator = number('Age must be a valid number');
602
+ * ```
603
+ */
604
+ declare function number(message?: string): FieldValidator<string | number>;
605
+ /**
606
+ * Validates minimum numeric value
607
+ *
608
+ * @param minValue - Minimum value allowed
609
+ * @param message - Custom error message (optional)
610
+ * @returns A FieldValidator function
611
+ *
612
+ * @example
613
+ * ```typescript
614
+ * const ageValidator = min(18, 'Must be at least 18 years old');
615
+ * ```
616
+ */
617
+ declare function min(minValue: number, message?: string): FieldValidator<string | number>;
618
+ /**
619
+ * Validates maximum numeric value
620
+ *
621
+ * @param maxValue - Maximum value allowed
622
+ * @param message - Custom error message (optional)
623
+ * @returns A FieldValidator function
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * const scoreValidator = max(100, 'Score cannot exceed 100');
628
+ * ```
629
+ */
630
+ declare function max(maxValue: number, message?: string): FieldValidator<string | number>;
631
+ /**
632
+ * Creates a custom validator from a validation function
633
+ *
634
+ * @param validateFn - Custom validation function
635
+ * @param message - Error message for failed validation
636
+ * @param code - Optional error code
637
+ * @returns A FieldValidator function
638
+ *
639
+ * @example
640
+ * ```typescript
641
+ * const evenNumberValidator = custom(
642
+ * (value) => Number(value) % 2 === 0,
643
+ * 'Number must be even',
644
+ * 'NOT_EVEN'
645
+ * );
646
+ * ```
647
+ */
648
+ declare function custom<T>(validateFn: (value: T, context: ValidationContext) => boolean, message: string, code?: string): FieldValidator<T>;
649
+ /**
650
+ * Creates a validator that checks if a value matches another field's value
651
+ *
652
+ * @param targetFieldId - ID of the field to match against
653
+ * @param message - Custom error message (optional)
654
+ * @returns A FieldValidator function
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * const confirmPasswordValidator = matchField('password', 'Passwords must match');
659
+ * ```
660
+ */
661
+ declare function matchField(targetFieldId: string, message?: string): FieldValidator;
662
+ /**
663
+ * Creates a validator that only validates when a condition is met
664
+ *
665
+ * @param condition - Function that determines if validation should run
666
+ * @param validator - The validator to run conditionally
667
+ * @returns A FieldValidator function
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * const conditionalValidator = when(
672
+ * (value, context) => context.allFormData?.userType === 'premium',
673
+ * required('Premium users must provide this field')
674
+ * );
675
+ * ```
676
+ */
677
+ declare function when<T>(condition: (value: T, context: ValidationContext) => boolean, validator: FieldValidator<T>): FieldValidator<T>;
678
+ /**
679
+ * Creates an async custom validator from a validation function
680
+ *
681
+ * @param validateFn - Async custom validation function that returns a Promise<boolean>
682
+ * @param message - Error message for failed validation
683
+ * @param code - Optional error code
684
+ * @returns A FieldValidator function that returns a Promise
685
+ *
686
+ * @example
687
+ * ```typescript
688
+ * const checkEmailUnique = customAsync(
689
+ * async (email) => {
690
+ * const response = await fetch(`/api/check-email?email=${email}`);
691
+ * const data = await response.json();
692
+ * return data.isUnique;
693
+ * },
694
+ * 'Email address is already taken',
695
+ * 'EMAIL_NOT_UNIQUE'
696
+ * );
697
+ * ```
698
+ */
699
+ declare function async<T>(validateFn: (value: T, context: ValidationContext) => Promise<boolean>, message: string, code?: string): FieldValidator<T>;
608
700
 
609
701
  /**
610
- * Utility functions to create persistence configurations easily
702
+ * @fileoverview Validation adapters for popular validation libraries
703
+ *
704
+ * This module provides adapters that integrate popular validation libraries
705
+ * like Zod with Rilay's validation system. Adapters convert external schemas
706
+ * into Rilay validators while maintaining type safety and error handling.
611
707
  */
612
- declare const persistence: {
613
- /**
614
- * Create a localStorage-based persistence configuration
615
- */
616
- localStorage(options?: Partial<PersistenceConfig>): PersistenceConfig;
617
- /**
618
- * Create a sessionStorage-based persistence configuration
619
- */
620
- sessionStorage(options?: Partial<PersistenceConfig>): PersistenceConfig;
708
+
709
+ /**
710
+ * Generic schema interface that Zod and similar libraries implement
711
+ */
712
+ interface ZodLikeSchema<T = any> {
713
+ parse(value: unknown): T;
714
+ safeParse(value: unknown): {
715
+ success: true;
716
+ data: T;
717
+ } | {
718
+ success: false;
719
+ error: {
720
+ errors: Array<{
721
+ message: string;
722
+ path: (string | number)[];
723
+ }>;
724
+ };
725
+ };
726
+ }
727
+ /**
728
+ * Zod validation adapter that converts Zod schemas into Rilay validators
729
+ *
730
+ * This adapter provides seamless integration with Zod schemas, automatically
731
+ * converting Zod validation errors into Rilay ValidationError objects while
732
+ * preserving error messages and field paths.
733
+ *
734
+ * @example
735
+ * ```typescript
736
+ * import { z } from 'zod';
737
+ * import { createZodAdapter } from '@rilaykit/core';
738
+ *
739
+ * const zodAdapter = createZodAdapter();
740
+ * const emailValidator = zodAdapter.createFieldValidator(
741
+ * z.string().email('Invalid email format')
742
+ * );
743
+ * ```
744
+ */
745
+ declare class ZodValidationAdapter implements ValidationAdapter<ZodLikeSchema> {
746
+ readonly name = "ZodValidationAdapter";
747
+ readonly version = "1.0.0";
621
748
  /**
622
- * Create an in-memory persistence configuration (for testing)
749
+ * Creates a field validator from a Zod schema
750
+ *
751
+ * @param schema - The Zod schema to convert
752
+ * @returns A FieldValidator function compatible with Rilay
753
+ *
754
+ * @example
755
+ * ```typescript
756
+ * const emailSchema = z.string().email();
757
+ * const validator = adapter.createFieldValidator(emailSchema);
758
+ * ```
623
759
  */
624
- memory(options?: Partial<PersistenceConfig>): PersistenceConfig;
760
+ createFieldValidator<T>(schema: ZodLikeSchema<T>): FieldValidator<T>;
625
761
  /**
626
- * Create a custom persistence configuration
762
+ * Creates a form validator from a Zod object schema
763
+ *
764
+ * @param schema - The Zod object schema to convert
765
+ * @returns A FormValidator function compatible with Rilay
766
+ *
767
+ * @example
768
+ * ```typescript
769
+ * const formSchema = z.object({
770
+ * email: z.string().email(),
771
+ * password: z.string().min(8)
772
+ * });
773
+ * const validator = adapter.createFormValidator(formSchema);
774
+ * ```
627
775
  */
628
- custom(adapter: PersistenceAdapter, options?: Partial<PersistenceConfig>): PersistenceConfig;
629
- };
776
+ createFormValidator<T>(schema: ZodLikeSchema<T>): FormValidator<T>;
777
+ }
778
+ /**
779
+ * Creates a new Zod validation adapter instance
780
+ *
781
+ * @returns A configured ZodValidationAdapter instance
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * const adapter = createZodAdapter();
786
+ * ```
787
+ */
788
+ declare function createZodAdapter(): ZodValidationAdapter;
789
+ /**
790
+ * Helper function to create a field validator directly from a Zod schema
791
+ *
792
+ * This is a convenience function that creates an adapter and field validator
793
+ * in a single call, useful for simple use cases.
794
+ *
795
+ * @param schema - The Zod schema to convert
796
+ * @returns A FieldValidator function
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * import { z } from 'zod';
801
+ * import { zodFieldValidator } from '@rilaykit/core';
802
+ *
803
+ * const emailValidator = zodFieldValidator(z.string().email());
804
+ * ```
805
+ */
806
+ declare function zodFieldValidator<T>(schema: ZodLikeSchema<T>): FieldValidator<T>;
630
807
  /**
631
- * Utility to create persistence configurations with retry logic
808
+ * Helper function to create a form validator directly from a Zod schema
809
+ *
810
+ * @param schema - The Zod object schema to convert
811
+ * @returns A FormValidator function
812
+ *
813
+ * @example
814
+ * ```typescript
815
+ * import { z } from 'zod';
816
+ * import { zodFormValidator } from '@rilaykit/core';
817
+ *
818
+ * const formValidator = zodFormValidator(z.object({
819
+ * email: z.string().email(),
820
+ * password: z.string().min(8)
821
+ * }));
822
+ * ```
632
823
  */
633
- declare function createResilientPersistence(primary: PersistenceAdapter, fallback?: PersistenceAdapter, options?: Partial<PersistenceConfig>): PersistenceConfig;
824
+ declare function zodFormValidator<T>(schema: ZodLikeSchema<T>): FormValidator<T>;
634
825
 
635
- export { type CompletionConfig, type ComponentConfig, type ComponentRenderProps, type ComponentRenderer, CompositeAdapter, type ConditionalConfig, type CustomStepRenderer, type DynamicStepConfig, type FieldRenderer, type FieldRendererProps, type FormBodyRenderer, type FormBodyRendererProps, type FormConfiguration, type FormFieldConfig, type FormFieldRow, type FormRenderConfig, type FormRowRenderer, type FormRowRendererProps, type FormSubmitButtonRenderer, type FormSubmitButtonRendererProps, IdGenerator, LocalStorageAdapter, MemoryAdapter, type NavigationConfig, type PersistenceAdapter, type PersistenceConfig, type RendererChildrenFunction, type RetryPolicy, type RilayLicenseConfig, SessionStorageAdapter, type StepConditionalConfig, type StepConfig, type StepLifecycleHooks, type StepPermissions, type StepValidationConfig, type ValidationConfig, type ValidationContext, type ValidationError, ValidationErrorBuilder, ValidationPatterns, type ValidationResult, type ValidatorFunction, type WorkflowAnalytics, type WorkflowConfig, type WorkflowContext, type WorkflowHooks, type WorkflowNextButtonRenderer, type WorkflowNextButtonRendererProps, type WorkflowPersistenceData, type WorkflowPlugin, type WorkflowPreviousButtonRenderer, type WorkflowPreviousButtonRendererProps, type WorkflowRenderConfig, type WorkflowSkipButtonRenderer, type WorkflowSkipButtonRendererProps, type WorkflowStepperRenderer, type WorkflowStepperRendererProps, combineValidators, commonValidators, configureObject, createConditionalValidator, createCustomValidator, createResilientPersistence, createValidationError, createValidationResult, createZodValidator, deepClone, ensureUnique, mergeInto, normalizeToArray, persistence, resolveRendererChildren, ril, validateRequired };
826
+ export { type ComponentConfig, type ComponentRenderProps, type ComponentRenderer, type ComponentRendererBaseProps, ComponentRendererWrapper, type ComponentRendererWrapperProps, type CustomStepRenderer, type FieldRenderer, type FieldRendererProps, type FieldValidationConfig, type FieldValidator, type FormBodyRenderer, type FormBodyRendererProps, type FormComponentRendererProps, type FormConfiguration, type FormFieldConfig, type FormFieldRow, type FormRenderConfig, type FormRowRenderer, type FormRowRendererProps, type FormSubmitButtonRenderer, type FormSubmitButtonRendererProps, type FormValidationConfig, type FormValidator, IdGenerator, type RendererChildrenFunction, type RilayLicenseConfig, type StepConfig, type StepDataHelper, type ValidationAdapter, type ValidationContext, type ValidationError, type ValidationResult, type ValidationSchema, type WorkflowAnalytics, type WorkflowComponentRendererBaseProps, type WorkflowConfig, type WorkflowContext, type WorkflowNextButtonRenderer, type WorkflowNextButtonRendererProps, type WorkflowPlugin, type WorkflowPreviousButtonRenderer, type WorkflowPreviousButtonRendererProps, type WorkflowRenderConfig, type WorkflowSkipButtonRenderer, type WorkflowSkipButtonRendererProps, type WorkflowStepperRenderer, type WorkflowStepperRendererProps, async, combineValidationResults, configureObject, createValidationContext, createValidationResult, createZodAdapter, custom, deepClone, email, ensureUnique, matchField, max, maxLength, mergeInto, min, minLength, normalizeToArray, number, pattern, required, resolveRendererChildren, ril, runValidators, runValidatorsAsync, url, validateRequired, when, zodFieldValidator, zodFormValidator };