Core library for TypeServe - TypeScript mock API generator
npm install @typeserve/coreCore library for TypeServe — generate mock APIs from your TypeScript types.
``bash`
npm install @typeserve/core
`typescript
import { defineMock, createRoute } from '@typeserve/core';
export default defineMock({
port: 3000,
basePath: '/api',
routes: [
createRoute({
path: '/users',
method: 'GET',
type: 'User',
file: './src/types.ts',
count: 5, // returns array of 5 items
}),
],
});
`
`typescript
interface RouteConfig {
path: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
type: string; // Name of the TypeScript type
file?: string; // Path to the types file
count?: 1 | 2 | 3 | 4 | 5; // Array length (optional)
}
interface TypeServeConfig {
routes: RouteConfig[];
port?: number; // Default: 3000
basePath?: string; // API prefix
}
`
| Export | Description |
|--------|-------------|
| defineMock(config) | Define your mock configuration |createRoute(route)
| | Create a route with validation |loadConfig(path)
| | Load config from file |parseTypes(file, typeName)
| | Parse TypeScript types |generateData(parsedType)
| | Generate mock data |startServer(config)
| | Start the mock server |watchFiles(paths, callback)` | Watch for file changes |
|
AGPL-3.0