cogsbox-shape
Version:
A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for r
39 lines (38 loc) • 1.07 kB
JavaScript
/**
* Minimal end-to-end example — open and hover inside Example.
* Run from cogsbox-shape repo after: pnpm build
*/
import { createCogsState } from "cogsbox-state";
import { createSchemaBox, s, schema } from "cogsbox-shape";
import { z } from "zod";
import { createShapePlugin } from "../plugin.js";
const taskItemSchema = z.object({
id: z.number(),
title: z.string(),
done: z.boolean(),
});
const taskManagerSchema = schema({
_tableName: "client",
tasks: s.client({
value: [],
schema: z.array(taskItemSchema),
}),
filter: s.client({
value: "all",
schema: z.string(),
}),
});
const demoBox = createSchemaBox({
taskManager: taskManagerSchema,
}, {});
const shapePlugin = createShapePlugin(demoBox);
const { useCogsState } = createCogsState({}, { plugins: [shapePlugin] });
export function Example() {
const taskManager = useCogsState("taskManager");
// hover ↓
const tasks = taskManager.tasks;
const filter = taskManager.filter;
void tasks;
void filter;
return null;
}