Schema
A Standard Schema whose output is T.
Usage
Persist a preference
import { Text, Toggle, VStack, persisted, type Schema } from 'kuito';
const booleanSchema: Schema<boolean> = {
'~standard': {
version: 1,
vendor: 'example',
validate: (value) =>
typeof value === 'boolean' ? { value } : { issues: [{ message: 'Expected boolean' }] },
},
};
export function Preferences() {
const wifiOnly = persisted(true, { key: 'downloads.wifiOnly', schema: booleanSchema });
return (
<VStack gap={12}>
<Toggle label="Download on Wi-Fi only" checked={wifiOnly} />
<Text>{wifiOnly.value ? 'Wi-Fi only' : 'Any connection'}</Text>
</VStack>
);
}Type declaration
export interface Schema<T> {
readonly '~standard': {
readonly version: 1;
readonly vendor: string;
readonly validate: (value: unknown) => SchemaResult<T> | Promise<SchemaResult<T>>;
readonly types?: { readonly input: unknown; readonly output: T } | undefined;
};
}Members 1
| Name | Type | Required | Description |
|---|---|---|---|
~standardreadonly | { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown) => SchemaResult<T> | Promise<SchemaResult<T>>; readonly types?: { readonly input: unknown; readonly output: T; } | undefined;} | Yes | — |
~standard — nested fields
~standard fields
| Name | Type | Required | Description |
|---|---|---|---|
versionreadonly | 1 | Yes | — |
vendorreadonly | string | Yes | — |
validatereadonly | (value: unknown) => SchemaResult<T> | Promise<SchemaResult<T>> | Yes | — |
typesreadonly | { readonly input: unknown; readonly output: T;} | No | — |
validate — method signatures
Signatures
(value: unknown): SchemaResult<T> | Promise<SchemaResult<T>>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | unknown | Yes | — |
Returns
SchemaResult<T> | Promise<SchemaResult<T>>
types — nested fields
types fields
| Name | Type | Required | Description |
|---|---|---|---|
inputreadonly | unknown | Yes | — |
outputreadonly | T | Yes | — |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.