@sladg/apex-state 3.0.4 → 3.1.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.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ReactNode } from 'react';
2
- import { z } from 'zod';
3
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
3
 
5
4
  /**
@@ -223,6 +222,26 @@ type ArrayOfChanges<DATA, META extends GenericMeta = GenericMeta> = {
223
222
  * their return types for proper type-safe concern registration and reading.
224
223
  */
225
224
 
225
+ /**
226
+ * Validation schema interface — the minimal contract for validation.
227
+ *
228
+ * Any library whose schema exposes `safeParse()` with this shape works
229
+ * out of the box (Zod, Valibot, ArkType, or a plain object).
230
+ */
231
+ interface ValidationSchema<T = unknown> {
232
+ safeParse(data: unknown): {
233
+ success: true;
234
+ data: T;
235
+ } | {
236
+ success: false;
237
+ error: {
238
+ errors: {
239
+ path: (string | number)[];
240
+ message: string;
241
+ }[];
242
+ };
243
+ };
244
+ }
226
245
  /**
227
246
  * Config type for the validationState concern at a specific path.
228
247
  *
@@ -233,11 +252,11 @@ type ArrayOfChanges<DATA, META extends GenericMeta = GenericMeta> = {
233
252
  * targeting a different path in the same state.
234
253
  */
235
254
  type ValidationStateInput<DATA, PATH extends DeepKey<DATA>> = {
236
- schema: z.ZodSchema<DeepValue<DATA, PATH>>;
255
+ schema: ValidationSchema<DeepValue<DATA, PATH>>;
237
256
  } | {
238
257
  [SCOPE in DeepKey<DATA>]: {
239
258
  scope: SCOPE;
240
- schema: z.ZodSchema<DeepValue<DATA, SCOPE>>;
259
+ schema: ValidationSchema<DeepValue<DATA, SCOPE>>;
241
260
  };
242
261
  }[DeepKey<DATA>];
243
262
  /**
@@ -304,9 +323,10 @@ type EvaluatedConcerns<CONCERNS extends readonly any[]> = {
304
323
  *
305
324
  * @example
306
325
  * ```typescript
326
+ * // Works with any library implementing ValidationSchema (Zod, Valibot, ArkType, etc.)
307
327
  * const registration: ConcernRegistrationMap<MyFormState> = {
308
- * email: { validationState: { schema: z.string().email() } },
309
- * name: { validationState: { schema: z.string().min(1) } },
328
+ * email: { validationState: { schema: emailSchema } },
329
+ * name: { validationState: { schema: nameSchema } },
310
330
  * }
311
331
  * ```
312
332
  */
@@ -585,8 +605,8 @@ interface WasmPipeline {
585
605
  unregisterBoolLogic: (logicId: number) => void;
586
606
  pipelineReset: () => void;
587
607
  destroy: () => void;
588
- /** Per-instance storage for Zod schemas (can't cross WASM boundary). */
589
- validatorSchemas: Map<number, z.ZodSchema>;
608
+ /** Per-instance storage for validation schemas (can't cross WASM boundary). */
609
+ validatorSchemas: Map<number, ValidationSchema>;
590
610
  }
591
611
 
592
612
  /**