@zenning/tool-app-contracts
v0.1.0
Published
Shared Zod contracts for Zenning Tool Apps
Maintainers
Readme
Zenning Tool App Contracts
Shared Zod contracts for Zenning Tool Apps, ensuring type safety between backend and frontend.
Installation
Since this is a private GitHub repository, install it as a Git dependency:
# Install from main branch
npm install github:AllTheTables/zenning-tool-app-contracts#main
# OR with pnpm
pnpm add github:AllTheTables/zenning-tool-app-contracts#mainUpdating
To pull the latest changes:
npm update zenning-tool-app-contracts
# or
pnpm update zenning-tool-app-contractsUsage
Tools are exported as namespaces to keep things tidy.
import { VisualiseDataTables } from 'zenning-tool-app-contracts';
// 1. Use the Schema for runtime validation
const result = VisualiseDataTables.Schema.safeParse(data);
if (result.success) {
// 2. Use the Contract type for TypeScript definitions
const myData: VisualiseDataTables.Contract = result.data;
console.log(myData.toolId);
}Available Tools
VisualiseDataTables- Data visualisation tool for tabular data
Adding a New Tool
- Create a new folder in
src/tools/<tool-name>/ - Create
schema.tsextendingBaseToolSchema:// src/tools/my-tool/schema.ts import { z } from 'zod'; import { BaseToolSchema } from '../../base'; export const MyToolSchema = BaseToolSchema.extend({ toolId: z.literal('my-tool-id'), // ... custom fields }); - Create
types.tsfor inferred types:// src/tools/my-tool/types.ts import { z } from 'zod'; import { MyToolSchema } from './schema'; export type MyTool = z.infer<typeof MyToolSchema>; - Create
index.tsto export and alias them:// src/tools/my-tool/index.ts import { MyToolSchema } from './schema'; import { MyTool } from './types'; export * from './schema'; export * from './types'; // Standard aliases export { MyToolSchema as Schema }; export type { MyTool as Contract }; - Add to
src/tools/index.ts:export * as MyTool from './my-tool'; - Run
npm run buildto verify - Commit and push your changes
