seitu
Version:
31 lines • 1.4 kB
text/typescript
import { i as Subscribable, n as Readable, s as Writable } from "./index-B0IeflOl.mjs";
import { i as StandardSchemaV1, r as ValidationSchemaOutput, t as ValidationSchemaErrorProps } from "./validate-C_H-c0gq.mjs";
//#region src/core/schema-store/index.d.ts
interface SchemaStore<O> extends Subscribable<O>, Readable<O>, Writable<O, O> {}
interface SchemaStoreOptions<S extends StandardSchemaV1<unknown>> {
schema: S;
defaultValue: ValidationSchemaOutput<S>;
/** Return a repaired value, or nothing to fall back to `defaultValue`. */
onValidationError?: (props: ValidationSchemaErrorProps<ValidationSchemaOutput<S>>) => void | ValidationSchemaOutput<S>;
}
/**
* Reactive store validated on read. Invalid values fall back to `defaultValue`.
* Validation is memoized on the raw state reference.
*
* @example
* ```ts twoslash
* import { createSchemaStore } from 'seitu'
* import * as z from 'zod'
*
* const store = createSchemaStore({
* schema: z.object({ count: z.number(), name: z.string() }),
* defaultValue: { count: 0, name: '' },
* })
* store.get()
* store.set({ count: 1, name: 'alice' })
* store.subscribe(console.log)
* ```
*/
declare function createSchemaStore<S extends StandardSchemaV1<unknown>>(options: SchemaStoreOptions<S>): SchemaStore<ValidationSchemaOutput<S>>;
//#endregion
export { SchemaStoreOptions as n, createSchemaStore as r, SchemaStore as t };