Skip to main content
Version: Next

Type Alias: KeySchema<TValue, K, TSchema>

KeySchema<TValue, K, TSchema> = object

Defined in: src/Mnemonic/types.ts:576

Schema definition for a single key at a specific version.

Each registered schema binds a storage key + version number to a JSON Schema that validates the payload. Schemas are fully serializable (no functions).

When the provider reads a value whose envelope version matches a registered schema, the payload is validated against the schema's JSON Schema definition.

Example​

const userSchemaV1: KeySchema = {
key: "user",
version: 1,
schema: {
type: "object",
properties: {
name: { type: "string" },
},
required: ["name"],
},
};

See​

Type Parameters​

Type ParameterDefault type
TValueunknown
K extends stringstring
TSchema extends JsonSchemaJsonSchema

Properties​

[keySchemaValueBrand]?​

readonly optional [keySchemaValueBrand]?: TValue

Defined in: src/Mnemonic/types.ts:604

Phantom type linking this runtime schema to its decoded TypeScript value.

This field is never set at runtime. It exists only so helpers such as defineKeySchema(...), defineMnemonicKey(...), and defineMigration(...) can preserve a single source of truth between schema shape and value type.


key​

key: K

Defined in: src/Mnemonic/types.ts:580

The unprefixed storage key this schema applies to.


schema​

schema: TSchema

Defined in: src/Mnemonic/types.ts:595

JSON Schema that validates the payload at this version.

Only the subset of JSON Schema keywords defined in JsonSchema are supported. An empty schema {} accepts any value.


version​

version: number

Defined in: src/Mnemonic/types.ts:587

The version number for this schema.

Must be a non-negative integer. Any version (including 0) is valid.