// --- JSON primitive types --- export type JsonPrimitive = string | number | boolean | null; // --- Recursive JSON value --- export type JsonValue = JsonPrimitive | JsonObject | JsonArray; export interface JsonObject { [key: string]: JsonValue; } export type JsonArray = JsonValue[]; // --- Serializable constraint (for generic parameters) --- /** * Constrains T to be JSON-serializable. * Use as a bound: `function store>(value: T)` * This catches functions, symbols, undefined, BigInt, etc. at compile time. */ export type JsonSerializable = T extends JsonPrimitive ? T : T extends readonly (infer U)[] ? JsonSerializable[] : T extends Record ? { [K in keyof T]: JsonSerializable } : never; // --- JSON parse result (typed alternative to JSON.parse) --- export type JsonParsed = T extends string ? JsonValue : T extends JsonValue ? T : never; // --- Deep partial (useful for KV patch operations) --- export type DeepPartial = T extends JsonPrimitive ? T : T extends readonly (infer U)[] ? readonly DeepPartial[] : T extends Record ? { [K in keyof T]?: DeepPartial } : T; // --- Deep readonly (useful for cached/immutable data) --- export type DeepReadonly = T extends JsonPrimitive ? T : T extends readonly (infer U)[] ? readonly DeepReadonly[] : T extends Record ? { readonly [K in keyof T]: DeepReadonly } : T;