import type { Command, CommandDefinitionMetadataBase, EBMessageAddress, EmptyObject, ServiceClassTypes, ServiceConstructorInput, StreamHandle } from '@purista/core'; import { Service } from '@purista/core'; import { Hono } from 'hono'; import { OpenApiBuilder } from 'openapi3-ts/oas31'; import type { BindingsBase } from '../../../types/BindingsBase.js'; import type { EndpointProtectMiddleware } from '../../../types/EndpointProtectMiddleware.js'; /** Service instance accepted by the Hono HTTP projection registry. */ export type AnyService = Service; import type { HealthFunction } from '../../../types/HealthFunction.js'; import type { VariablesBase } from '../../../types/VariablesBase.js'; import type { HonoServiceV1Config } from './honoServiceConfig.js'; /** * PURISTA service that exposes command, stream and async queue-backed endpoints through Hono. * * Register services before `start()` to project their HTTP metadata into Hono * routes and OpenAPI paths. Synchronous endpoints invoke commands directly, * stream endpoints open PURISTA stream definitions, and async endpoints return * `202 Accepted` with queue job information from the owning command. * * The web server listener is started by the application after this service has * started. * * Minimal example: * * @example * ```typescript * import { serve } from '@hono/node-server' * import { DefaultEventBridge } from '@purista/core' * import { honoV1Service } from '@purista/hono-http-server' * * // create and init our eventbridge * const eventBridge = new DefaultEventBridge() * await eventBridge.start() * * // add your service * const pingService = await pingV1Service.getInstance(eventBridge) * await pingService.start() * * const honoService = await honoV1Service.getInstance(eventBridge, { * serviceConfig: { * enableDynamicRoutes: false, * } * }) * honoService.registerService(pingService) * await honoService.start() * * const _serverInstance = serve({ * fetch: honoService.app.fetch, * port: 3000, * }) * * ``` */ export declare class HonoServiceClass extends Service> { /** * Hono application hosting health, OpenAPI and generated endpoint routes. */ app: Hono<{ Bindings: Bindings; Variables: Variables; }, import("hono/types").BlankSchema, "/">; /** * OpenAPI builder populated as command and stream endpoints are registered. */ openApi: OpenApiBuilder; private knownServices; private knownEndpoints; private isAvailable; /** Creates the Hono service runtime and configures routing, health, and protection defaults. */ constructor(config: ServiceConstructorInput>); /** * Narrows Hono `Bindings` and `Variables` types for middleware and handlers. * * @returns The same service instance with updated generic types. */ setHonoTypes; Variables?: Record; } = { Bindings: EmptyObject; Variables: EmptyObject; }>(): HonoServiceClass; /** * Sets the callback used by the configured health endpoint. * * Throw from this callback when the process should fail health checks. * * @param fn - Health callback bound to this service instance. */ setHealthFunction(fn: HealthFunction): this; /** * Sets middleware for endpoints marked as protected in HTTP metadata. * * The middleware can also enrich `additionalParameter`, `principalId` and * `tenantId` Hono variables before the generated command or stream handler * calls PURISTA. * * @example * ```typescript * honoService.setProtectMiddleware(async function (c, next) { * c.set('principalId', 'user-123') * c.set('tenantId', 'tenant-a') * return next() * }) * ``` * * @param fn - Hono middleware for protected endpoints. */ setProtectMiddleware(fn: EndpointProtectMiddleware): this; private sendProblemResponse; /** * Starts the service and registers health, OpenAPI and error handling routes. * * If configured, services from `services` are registered automatically before * the service becomes available. */ start(): Promise; /** * Registers service instances and adds their HTTP-exposed commands and streams. * * Must be called before `start()`. Commands and streams are distinct PURISTA * primitives; this method maps both to HTTP only when their definition * metadata declares HTTP exposure. * * @param services - PURISTA service instances to expose. */ registerService(...services: AnyService[]): this; /** * Adds a single command or stream endpoint to the Hono router. * * Synchronous command endpoints return command payloads, async command * endpoints return queue job metadata, and stream endpoints either aggregate * the final payload or deliver Server-Sent Events based on metadata. * * @param metadata - Command or stream metadata produced by a builder. * @param service - Address of the service hosting the command or stream. */ addEndpoint(metadata: CommandDefinitionMetadataBase, service: EBMessageAddress): void; /** Invokes a PURISTA command through the event bridge on behalf of an HTTP endpoint. */ invoke(input: Omit, endpoint: string): Promise; /** Opens a PURISTA stream through the event bridge on behalf of an HTTP endpoint. */ openStream(input: Omit, endpoint: string, timeoutMs?: number): Promise>; /** * Set the service unavailable * The webserver will return 503 Service Unavailable */ setServiceUnavailable(): Promise; /** * Set the service available * Request will be processed. */ setServiceAvailable(): Promise; /** * Helper function to be used in gracefulShutdown. * It prevents to handle new requests during shut down. * Incoming requests are rejected with 503 Service Unavailable. * * @example * ```typescript * gracefulShutdown(logger, [ * honoService.prepareDestroy(), * eventbridge, * ...services, * honoService * ]) * ``` * @returns */ prepareDestroy(): { name: string; destroy: () => Promise; }; destroy(): Promise; } //# sourceMappingURL=HonoServiceClass.d.ts.map