Classes · @purista/hono-http-server
HonoServiceClass
PURISTA service that exposes command, stream and async queue-backed endpoints through Hono.
Signature
class HonoServiceClass<Bindings, Variables> Examples
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,
}) Constructors
1 entry
constructor
Constructor
new constructor<Bindings, Variables>(config: ServiceConstructorInput<ServiceClassTypes<{ apiMountPath: string; autoRegisterServicesFromConfig: boolean; enableDynamicRoutes: boolean; enableHealth: boolean; healthFunction: any; healthPath: string; ... }, EmptyObject>>) Creates the Hono service runtime and configures routing, health, and protection defaults.
Properties
27 entries
__serviceClassTypes
Property
__serviceClassTypes: ServiceClassTypes<{ apiMountPath: string; autoRegisterServicesFromConfig: boolean; enableDynamicRoutes: boolean; enableHealth: boolean; healthFunction: any; healthPath: string; ... }> Type-only anchor used to preserve cascading service builder types.
activeStreamSessions
Property
activeStreamSessions: Map<string, { cancelled: boolean; cancelReason: string; onCancel: (reason?: string) => void[] }> app
Property
app: Hono<{ Bindings: Bindings; Variables: Variables }, BlankSchema, "/"> Hono application hosting health, OpenAPI and generated endpoint routes.
commandDefinitionList
Property
commandDefinitionList: CommandDefinitionListResolved<any> commands
Property
commands: Map<string, CommandDefinition<any, any, any, any, any, any, any, any, any, any, EmptyObject, any, any, any>> config
Property
config: { apiMountPath: string; autoRegisterServicesFromConfig: boolean; enableDynamicRoutes: boolean; enableHealth: boolean; healthFunction: any; healthPath: string; ... } configSchema
Property
configSchema: Schema | undefined configStore
Property
configStore: ConfigStore eventBridge
Property
eventBridge: EventBridge info
Property
info: ServiceInfoType isStarted
Property
isStarted: boolean logger
Property
logger: Logger metricContext
Property
metricContext: PuristaMetricContext<PuristaMetricDefinitions> metricDefinitions
Property
metricDefinitions: PuristaMetricDefinitions metricsRecorder
Property
metricsRecorder: PuristaMetricsRecorder openApi
Property
openApi: OpenApiBuilder OpenAPI builder populated as command and stream endpoints are registered.
queueDefinitionList
Property
queueDefinitionList: QueueDefinitionListResolved<any> queueWorkerDefinitionList
Property
queueWorkerDefinitionList: QueueWorkerDefinitionListResolved<any> resources
Property
resources: EmptyObject secretStore
Property
secretStore: SecretStore spanProcessor
Property
spanProcessor: SpanProcessor | undefined stateStore
Property
stateStore: StateStore streamDefinitionList
Property
streamDefinitionList: StreamDefinitionListResolved<any> streams
Property
streams: Map<string, StreamDefinition<any, any, any, any, any, any, any, EmptyObject, any, any, any>> subscriptionDefinitionList
Property
subscriptionDefinitionList: SubscriptionDefinitionListResolved<any> subscriptions
Property
subscriptions: Map<string, SubscriptionDefinition<any, any, any, any, any, any, any, any, EmptyObject, any, any, any>> traceProvider
Property
traceProvider: NodeTracerProvider Accessors
2 entries
name
Member
name serviceInfo
Member
serviceInfo Methods
38 entries
addEndpoint
Method
addEndpoint(metadata: CommandDefinitionMetadataBase, service: EBMessageAddress): void Adds a single command or stream endpoint to the Hono router.
destroy
Method
destroy(): Promise<void> Stop and destroy the current service
executeCommand
Method
executeCommand(message: Readonly<Command>): Promise<Readonly<Omit<{ contentEncoding: unknown; contentType: unknown; correlationId: unknown; eventName: unknown; id: unknown; isHandledError: unknown; ... }, "instanceId">> | { contentEncoding: string; contentType: string; correlationId: string; eventName: string; id: string; messageType: CommandSuccessResponse; ... }> Called when a command is received by the service
executeStream
Method
executeStream(message: Readonly<StreamMessage>): Promise<void> executeSubscription
Method
executeSubscription(message: Readonly<EBMessage>, subscriptionName: string): Promise<Omit<{ contentEncoding: string; contentType: string; correlationId: string; eventName: string; id: string; messageType: CustomMessage; ... }, "id" | "timestamp"> | undefined> getConsumeStreamFunction
Method
getConsumeStreamFunction<StreamInvokes>(serviceTarget: string, traceId?: string, principalId?: string, tenantId?: string, streamInvokes?: StreamInvokes): OpenStreamFunction getContextFunctions
Method
getContextFunctions(logger: Logger, queueNamespace?: QueueContext): ContextBase getEmitFunction
Method
getEmitFunction<EmitList>(serviceTarget: string, traceId?: string, principalId?: string, tenantId?: string, emitList?: EmitList): (eventName: K, eventPayload?: Payload, contentType?: string, contentEncoding?: string) => Promise<void> getInFlightDiagnostics
Method
getInFlightDiagnostics(): InFlightDiagnostics getInvokeFunction
Method
getInvokeFunction<Invokes>(serviceTarget: string, traceId?: string, principalId?: string, tenantId?: string, invokes?: Invokes): (receiver: EBMessageAddress, invokePayload: Payload, invokeparameter: Parameter, contentType?: string, contentEncoding?: string) => Promise<any> getPausedSubscriptionConsumerState
Method
getPausedSubscriptionConsumerState(): PausedSubscriptionConsumersByRegistrationKey getQueueNamespace
Method
getQueueNamespace(queueInvokes?: QueueInvokeList, traceId?: string, principalId?: string, tenantId?: string): { enqueue: QueueInvokeFunction & QueueInvokeClientMap<QueueInvokeList>; scheduleAt: QueueScheduleFunction & QueueScheduleProxy<QueueInvokeClientMap<QueueInvokeList>> } getQueueWorkerPauseState
Method
getQueueWorkerPauseState(): QueueWorkerPauseStateByQueue getServiceHealth
Method
getServiceHealth(): Promise<ServiceHealthState> getTracer
Method
getTracer(name?: string, version?: string): Tracer Returns open telemetry tracer of this service
initializeEventbridgeConnect
Method
initializeEventbridgeConnect(commandDefinitionList: CommandDefinitionListResolved<any>, subscriptions: SubscriptionDefinitionListResolved<any>, streams: StreamDefinitionListResolved<any>): Promise<void> Connect service to event bridge to receive commands and command responses
initializeQueues
Method
initializeQueues(): Promise<void> invoke
Method
invoke<T>(input: Omit<Command, "id" | "messageType" | "timestamp" | "correlationId" | "sender">, endpoint: string): Promise<T> Invokes a PURISTA command through the event bridge on behalf of an HTTP endpoint.
openStream
Method
openStream(input: Omit<Command, "id" | "messageType" | "timestamp" | "correlationId" | "sender">, endpoint: string, timeoutMs: number): Promise<StreamHandle<unknown, unknown>> Opens a PURISTA stream through the event bridge on behalf of an HTTP endpoint.
pauseQueueWorkers
Method
pauseQueueWorkers(queueName: string, reason?: string): void prepareDestroy
Method
prepareDestroy(): { destroy: () => Promise<void>; name: string } Helper function to be used in gracefulShutdown. It prevents to handle new requests during shut down. Incoming requests are rejected with 503 Service Unavailable.
registerCommand
Method
registerCommand(commandDefinition: CommandDefinition<any, any, any, any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void> registerService
Method
registerService(...services: AnyService[]): HonoServiceClass<Bindings, Variables> Registers service instances and adds their HTTP-exposed commands and streams.
registerStream
Method
registerStream(streamDefinition: StreamDefinition<any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void> registerSubscription
Method
registerSubscription(subscriptionDefinition: SubscriptionDefinition<any, any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void> resumeQueueWorkers
Method
resumeQueueWorkers(queueName: string): void resumeSubscriptionConsumer
Method
resumeSubscriptionConsumer(registrationKey: string): Promise<void> sendServiceInfo
Method
sendServiceInfo(infoType: InfoMessageType, target?: string, payload?: Record<string, unknown>): Promise<Readonly<EBMessage>> Broadcast service info message
setHealthFunction
Method
setHealthFunction(fn: HealthFunction<HonoServiceClass<Bindings, Variables>>): HonoServiceClass<Bindings, Variables> Sets the callback used by the configured health endpoint.
setHonoTypes
Method
setHonoTypes<E>(): HonoServiceClass<Bindings & E["Bindings"], Variables & E["Variables"]> Narrows Hono `Bindings` and `Variables` types for middleware and handlers.
setProtectMiddleware
Method
setProtectMiddleware(fn: EndpointProtectMiddleware<HonoServiceClass<Bindings, Variables>, Bindings, Variables>): HonoServiceClass<Bindings, Variables> Sets middleware for endpoints marked as protected in HTTP metadata.
setServiceAvailable
Method
setServiceAvailable(): Promise<void> Set the service available Request will be processed.
setServiceUnavailable
Method
setServiceUnavailable(): Promise<void> Set the service unavailable The webserver will return 503 Service Unavailable
start
Method
start(): Promise<void> Starts the service and registers health, OpenAPI and error handling routes.
startActiveSpan
Method
startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>): Promise<F> Start a child span for opentelemetry tracking
startQueueWorkers
Method
startQueueWorkers(): void stopQueueWorkers
Method
stopQueueWorkers(): Promise<void> wrapInSpan
Method
wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context): Promise<F> Start span for opentelemetry tracking on same level. The created span will not become the "active" span within opentelemetry!