import { SpiceflowFetchError } from './client/errors.ts'; import { ValidationError } from './error.ts'; import { ComposeSpiceflowResponse, ContentType, CreateClient, DefinitionBase, ErrorHandler, ExtractParamsFromPath, GetRequestSchema, HTTPMethod, InlineHandler, InputSchema, IsAny, JoinPath, LocalHook, MetadataBase, MiddlewareHandler, Reconcile, ResolvePath, RouteBase, RouteSchema, SingletonBase, UnwrapRoute } from './types.ts'; import { ZodType } from 'zod'; import { StandardSchemaV1 } from '@standard-schema/spec'; import type { IncomingMessage, ServerResponse } from 'node:http'; export type SpiceflowServerError = ValidationError | SpiceflowFetchError | Error; export type WaitUntil = (promise: Promise) => void; type ValidationFunction = (value: unknown) => StandardSchemaV1.Result | Promise>; export type InternalRoute = { method: HTTPMethod; path: string; type: ContentType; handler: InlineHandler; hooks: LocalHook; validateBody?: ValidationFunction; validateQuery?: ValidationFunction; validateParams?: ValidationFunction; }; export declare class Spiceflow = {}> { private id; private router; private middlewares; private onErrorHandlers; private routes; private defaultState; topLevelApp?: AnySpiceflow; private waitUntilFn; private disableSuperJsonUnlessRpc; _types: { Prefix: BasePath; ClientRoutes: ClientRoutes; RoutePaths: RoutePaths; RouteQuerySchemas: RouteQuerySchemas; Scoped: Scoped; Singleton: Singleton; Definitions: Definitions; Metadata: Metadata; }; /** @internal */ basePath?: string; /** @internal */ childrenApps: AnySpiceflow[]; /** @internal */ getAllRoutes(): { path: string; method: HTTPMethod; type: ContentType; handler: InlineHandler; hooks: LocalHook; validateBody?: ValidationFunction; validateQuery?: ValidationFunction; validateParams?: ValidationFunction; }[]; private add; private match; state(name: Name, value?: Value): Spiceflow; }, Definitions, Metadata, ClientRoutes, RoutePaths, RouteQuerySchemas>; /** * Create a new Router * @param options {@link RouterOptions} {@link Platform} */ constructor(options?: { name?: string; scoped?: Scoped; waitUntil?: WaitUntil; basePath?: BasePath; disableSuperJsonUnlessRpc?: boolean; }); post, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { post: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; get, const Schema extends UnwrapRoute, const Macro extends Metadata['macro'], const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { get: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; put, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { put: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; route, const Schema extends UnwrapRoute, const Handle extends InlineHandler>, Method extends HTTPMethod | HTTPMethod[] = '*'>(options: LocalHook> & { path: Path; method?: Method; handler: Handle; }): Spiceflow, { [M in Method extends readonly (infer E)[] ? Lowercase : Lowercase]: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; patch, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { patch: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; delete, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { delete: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; options, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { options: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; all, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { [method in string]: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; head, const Schema extends UnwrapRoute, const Handle extends InlineHandler>>(path: Path, handler: Handle, hook?: LocalHook>): Spiceflow, { head: { request: GetRequestSchema; params: undefined extends Schema['params'] ? ResolvePath : Schema['params']; query: Schema['query']; response: ComposeSpiceflowResponse; }; }>, RoutePaths | JoinPath, RouteQuerySchemas & Record, Schema['query']>>; private scoped?; use(instance: NewSpiceflow): IsAny extends true ? this : Spiceflow, RoutePaths | NewSpiceflow['_types']['RoutePaths'], RouteQuerySchemas & NewSpiceflow['_types']['RouteQuerySchemas']>; use(handler: MiddlewareHandler): this; onError(handler: ErrorHandler): this; handle: (request: Request, { state: customState }?: { state?: Singleton["state"]; }) => Promise; protected superjsonSerialize(value: any, indent?: boolean, request?: Request): string; private turnHandlerResultIntoResponse; private runErrorHandlers; private joinBasePaths; private getAppAndParents; private getAppsInScope; listen(port: number, hostname?: string): Promise<{ port: number; server: import("http").Server; } | { port: number | undefined; server: Bun.Server; }>; /** * @deprecated Use `handleForNode` instead. */ handleNode(req: IncomingMessage, res: ServerResponse, context?: { state?: Singleton['state']; }): Promise; handleForNode: (req: IncomingMessage, res: ServerResponse, context?: { state?: Singleton["state"]; }) => Promise; listenForNode(port: number, hostname?: string): Promise<{ port: number; server: import("http").Server; }>; private handleStream; safePath(path: Path, ...rest: [ExtractParamsFromPath] extends [undefined] ? Path extends keyof RouteQuerySchemas ? unknown extends RouteQuerySchemas[Path] ? [] | [allParams?: Record] : [] | [allParams?: Partial] : [] | [allParams?: Record] : Path extends keyof RouteQuerySchemas ? unknown extends RouteQuerySchemas[Path] ? [allParams: ExtractParamsFromPath & Record] : [allParams: MergeParamsAndQuery, RouteQuerySchemas[Path]>] : [allParams: ExtractParamsFromPath] | [allParams: ExtractParamsFromPath & Record]): string; } type MergeParamsAndQuery = P extends Record ? { [K in keyof (P & Omit, keyof P>)]: (P & Omit, keyof P>)[K]; } : Partial; /** * Create a standalone type-safe path builder. Pass your app instance for automatic * type inference, or call with explicit type params. The app value is not used at runtime. * * ```ts * const app = new Spiceflow() * .get('/users/:id', handler, { query: z.object({ page: z.number() }) }) * * const safePath = createSafePath(app) * safePath('/users/:id', { id: '123', page: 1 }) * ``` */ export declare function createSafePath>(_app?: { _types: { RoutePaths: Paths; RouteQuerySchemas: QS; }; }): (path: Path, ...rest: [ExtractParamsFromPath] extends [undefined] ? Path extends keyof QS ? unknown extends QS[Path] ? [] | [allParams?: Record] : [] | [allParams?: Partial] : [] | [allParams?: Record] : Path extends keyof QS ? unknown extends QS[Path] ? [allParams: ExtractParamsFromPath & Record] : [allParams: MergeParamsAndQuery, QS[Path]>] : [allParams: ExtractParamsFromPath] | [allParams: ExtractParamsFromPath & Record]) => string; declare const METHODS: readonly ["ALL", "CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"]; /** HTTP method string */ export type Method = (typeof METHODS)[number]; export declare class SpiceflowRequest extends Request { validateBody?: ValidationFunction; json(): Promise; } export declare function bfs(tree: AnySpiceflow): AnySpiceflow[]; export type AnySpiceflow = Spiceflow; export declare function isZodSchema(value: unknown): value is ZodType; import type * as z4 from 'zod/v4/core'; /** `true` ⇒ the value was created by Zod 4, `false` ⇒ Zod 3 */ export declare function isZod4(schema: any): schema is z4.$ZodObject; export declare function cloneDeep(x: any): any; export {}; //# sourceMappingURL=spiceflow.d.ts.map