UNPKG

@honorestjs/contract

Version:

Contract-first API definitions for HonorestJS - Framework-agnostic contract definitions with full type safety

122 lines 2.82 kB
import type { Contract } from './contract'; /** * App-level metadata for API documentation */ export interface AppMetadata { /** * API title * @example 'My Application API' */ title?: string; /** * API version * @example '1.0.0' */ version?: string; /** * API description * @example 'RESTful API for my application' */ description?: string; /** * Contact information */ contact?: { name?: string; email?: string; url?: string; }; /** * License information */ license?: { name: string; url?: string; }; /** * Terms of service URL */ termsOfService?: string; /** * External documentation */ externalDocs?: { description?: string; url: string; }; } /** * App definition structure * Aggregates multiple contracts into a complete API */ export interface AppDefinition<TContracts extends Record<string, Contract> = Record<string, Contract>> { /** * API version number * Applies to all contracts unless overridden * @example 1 | 2 */ version?: number; /** * Global prefix for all routes * Prepended to all contract paths * @example '/api' | '/v1' */ prefix?: string; /** * Contracts grouped by name * Maps contract names to their definitions * @example { users: UsersContract, posts: PostsContract } */ contracts: TContracts; /** * App metadata for documentation */ metadata?: AppMetadata; } /** * Branded app type - a definition with a runtime marker */ export type App<T extends AppDefinition = AppDefinition> = T & { readonly __app: unique symbol; }; /** * Defines an application with multiple contracts * * An app represents the complete API surface, aggregating * all contracts into a single, type-safe interface. * * @param definition - The app specification * @returns An app object with type inference helpers * * @example * ```typescript * const AppContract = defineApp({ * version: 1, * prefix: '/api', * contracts: { * users: UsersContract, * posts: PostsContract, * auth: AuthContract * }, * metadata: { * title: 'My API', * version: '1.0.0', * description: 'API for my application', * contact: { * name: 'API Support', * email: 'support@example.com' * }, * license: { * name: 'MIT', * url: 'https://opensource.org/licenses/MIT' * } * } * }) * ``` */ export declare function defineApp<const T extends AppDefinition>(definition: T): App<T>; /** * Type guard to check if a value is an app */ export declare function isApp(value: unknown): value is App; //# sourceMappingURL=app.d.ts.map