UNPKG

spfn

Version:

Superfunction CLI - Add SPFN to your Next.js project

112 lines (106 loc) 3.03 kB
import { Type } from '@sinclair/typebox'; import type { RouteContract } from '@spfn/core/route'; import { ApiResponseSchema } from '@spfn/core/route'; /** * Example Contracts * * Demonstrates SPFN's contract-based routing with absolute paths */ /** * GET /examples - List examples */ export const getExamplesContract = { method: 'GET' as const, path: '/examples', // ← Absolute path query: Type.Object({ limit: Type.Optional(Type.Number({ minimum: 1, maximum: 100 })), offset: Type.Optional(Type.Number({ minimum: 0 })) }), response: ApiResponseSchema( Type.Object({ examples: Type.Array(Type.Object({ id: Type.String(), name: Type.String(), description: Type.String() })), total: Type.Number(), limit: Type.Number(), offset: Type.Number() }) ) } as const satisfies RouteContract; /** * GET /examples/:id - Get single example */ export const getExampleContract = { method: 'GET' as const, path: '/examples/:id', // ← Absolute path with parameter params: Type.Object({ id: Type.Integer({ minimum: 1 }) // Auto-converts string to number }), response: ApiResponseSchema( Type.Object({ id: Type.Number(), name: Type.String(), description: Type.String(), createdAt: Type.Number(), updatedAt: Type.Number() }) ) } as const satisfies RouteContract; /** * POST /examples - Create example */ export const createExampleContract = { method: 'POST' as const, path: '/examples', // ← Absolute path body: Type.Object({ name: Type.String(), description: Type.String() }), response: ApiResponseSchema( Type.Object({ id: Type.String(), name: Type.String(), description: Type.String(), createdAt: Type.Number() }) ) } as const satisfies RouteContract; /** * PUT /examples/:id - Update example */ export const updateExampleContract = { method: 'PUT' as const, path: '/examples/:id', // ← Absolute path with parameter params: Type.Object({ id: Type.String() }), body: Type.Object({ name: Type.Optional(Type.String()), description: Type.Optional(Type.String()) }), response: ApiResponseSchema( Type.Object({ id: Type.String(), name: Type.String(), description: Type.String(), updatedAt: Type.Number() }) ) } as const satisfies RouteContract; /** * DELETE /examples/:id - Delete example */ export const deleteExampleContract = { method: 'DELETE' as const, path: '/examples/:id', // ← Absolute path with parameter params: Type.Object({ id: Type.String() }), response: ApiResponseSchema( Type.Object({ id: Type.String() }) ) } as const satisfies RouteContract;