@asyncdev01/frontpage
v0.1.0
Published
Scaffolding tool for generating React Query hooks and services from Zod schemas
Maintainers
Readme
@async/frontpage
Front Forge is a scaffolding tool and core library for generating React Query hooks and services from Zod schemas. It helps you automate the repetitive work of building API layers for your TypeScript projects.
Installation
npm install @async/frontpageScaffolding Tool
The CLI tool allows you to generate hooks and services directly from your Zod schemas.
Usage
npx front-forge --schema=./src/zod/vehicle.zod.tsOptions
--schema,-s: Path to the Zod schema file (base name must be{entity}.zod.ts).--output,-o: Output directory for generated files (default:src).
Core Library
The package also provides base classes and utilities that the generated code depends on.
APIService
A base class for building API services with support for query parameter chaining.
import { APIService } from "@async/frontpage";
class MyService extends APIService {
// your custom methods
}asyncHandler
A wrapper for async route handlers to catch errors and pass them to error middleware (useful for Express).
import { asyncHandler } from "@async/frontpage";
app.get(
"/users",
asyncHandler(async (req, res) => {
const users = await userService.getAllUsers();
res.json(users);
})
);apiClient
A flexible fetch wrapper for making API requests.
import { apiClient } from "@async/frontpage";
apiClient.setBaseUrl("https://api.example.com");Schema Requirements
The scrubber expects a Zod schema file with the following naming convention:
{entity-name}.zod.ts (e.g., user.zod.ts).
It parses the file to extract:
- Entity Name: Derived from the filename.
- Types: It can detect
WithRelationtypes to generate specialized hooks. - Array Fields: Automatically detects array fields to generate "include" hooks.
License
ISC
