Classes · @purista/hono-http-server

HonoServiceClass

PURISTA service that exposes command, stream and async queue-backed endpoints through Hono.

Signature

HonoServiceClass.ts typescript
class HonoServiceClass<Bindings, Variables>

Examples

example-1.ts 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,
})

Constructors

1 entry

constructor

Constructor

Source
constructor.ts typescript
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.ts typescript
__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.ts typescript
activeStreamSessions: Map<string, { cancelled: boolean; cancelReason: string; onCancel: (reason?: string) => void[] }>

app

Property

Source
app.ts typescript
app: Hono<{ Bindings: Bindings; Variables: Variables }, BlankSchema, "/">

Hono application hosting health, OpenAPI and generated endpoint routes.

commandDefinitionList

Property

commandDefinitionList.ts typescript
commandDefinitionList: CommandDefinitionListResolved<any>

commands

Property

commands.ts typescript
commands: Map<string, CommandDefinition<any, any, any, any, any, any, any, any, any, any, EmptyObject, any, any, any>>

config

Property

config.ts typescript
config: { apiMountPath: string; autoRegisterServicesFromConfig: boolean; enableDynamicRoutes: boolean; enableHealth: boolean; healthFunction: any; healthPath: string; ... }

configSchema

Property

configSchema.ts typescript
configSchema: Schema | undefined

configStore

Property

configStore.ts typescript
configStore: ConfigStore

eventBridge

Property

eventBridge.ts typescript
eventBridge: EventBridge

info

Property

info.ts typescript
info: ServiceInfoType

isStarted

Property

isStarted.ts typescript
isStarted: boolean

logger

Property

logger.ts typescript
logger: Logger

metricContext

Property

metricContext.ts typescript
metricContext: PuristaMetricContext<PuristaMetricDefinitions>

metricDefinitions

Property

metricDefinitions.ts typescript
metricDefinitions: PuristaMetricDefinitions

metricsRecorder

Property

metricsRecorder.ts typescript
metricsRecorder: PuristaMetricsRecorder

openApi

Property

Source
openApi.ts typescript
openApi: OpenApiBuilder

OpenAPI builder populated as command and stream endpoints are registered.

queueDefinitionList

Property

queueDefinitionList.ts typescript
queueDefinitionList: QueueDefinitionListResolved<any>

queueWorkerDefinitionList

Property

queueWorkerDefinitionList.ts typescript
queueWorkerDefinitionList: QueueWorkerDefinitionListResolved<any>

resources

Property

resources.ts typescript
resources: EmptyObject

secretStore

Property

secretStore.ts typescript
secretStore: SecretStore

spanProcessor

Property

spanProcessor.ts typescript
spanProcessor: SpanProcessor | undefined

stateStore

Property

stateStore.ts typescript
stateStore: StateStore

streamDefinitionList

Property

streamDefinitionList.ts typescript
streamDefinitionList: StreamDefinitionListResolved<any>

streams

Property

streams.ts typescript
streams: Map<string, StreamDefinition<any, any, any, any, any, any, any, EmptyObject, any, any, any>>

subscriptionDefinitionList

Property

subscriptionDefinitionList.ts typescript
subscriptionDefinitionList: SubscriptionDefinitionListResolved<any>

subscriptions

Property

subscriptions.ts typescript
subscriptions: Map<string, SubscriptionDefinition<any, any, any, any, any, any, any, any, EmptyObject, any, any, any>>

traceProvider

Property

traceProvider.ts typescript
traceProvider: NodeTracerProvider

Accessors

2 entries

name

Member

name.ts typescript
name

serviceInfo

Member

serviceInfo.ts typescript
serviceInfo

Methods

38 entries

addEndpoint

Method

Source
addEndpoint.ts typescript
addEndpoint(metadata: CommandDefinitionMetadataBase, service: EBMessageAddress): void

Adds a single command or stream endpoint to the Hono router.

destroy

Method

Source
destroy.ts typescript
destroy(): Promise<void>

Stop and destroy the current service

executeCommand

Method

executeCommand.ts typescript
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.ts typescript
executeStream(message: Readonly<StreamMessage>): Promise<void>

executeSubscription

Method

executeSubscription.ts typescript
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.ts typescript
getConsumeStreamFunction<StreamInvokes>(serviceTarget: string, traceId?: string, principalId?: string, tenantId?: string, streamInvokes?: StreamInvokes): OpenStreamFunction

getContextFunctions

Method

getContextFunctions.ts typescript
getContextFunctions(logger: Logger, queueNamespace?: QueueContext): ContextBase

getEmitFunction

Method

getEmitFunction.ts typescript
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.ts typescript
getInFlightDiagnostics(): InFlightDiagnostics

getInvokeFunction

Method

getInvokeFunction.ts typescript
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.ts typescript
getPausedSubscriptionConsumerState(): PausedSubscriptionConsumersByRegistrationKey

getQueueNamespace

Method

getQueueNamespace.ts typescript
getQueueNamespace(queueInvokes?: QueueInvokeList, traceId?: string, principalId?: string, tenantId?: string): { enqueue: QueueInvokeFunction & QueueInvokeClientMap<QueueInvokeList>; scheduleAt: QueueScheduleFunction & QueueScheduleProxy<QueueInvokeClientMap<QueueInvokeList>> }

getQueueWorkerPauseState

Method

getQueueWorkerPauseState.ts typescript
getQueueWorkerPauseState(): QueueWorkerPauseStateByQueue

getServiceHealth

Method

getServiceHealth.ts typescript
getServiceHealth(): Promise<ServiceHealthState>

getTracer

Method

getTracer.ts typescript
getTracer(name?: string, version?: string): Tracer

Returns open telemetry tracer of this service

initializeEventbridgeConnect

Method

initializeEventbridgeConnect.ts typescript
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.ts typescript
initializeQueues(): Promise<void>

invoke

Method

Source
invoke.ts typescript
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

Source
openStream.ts typescript
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.ts typescript
pauseQueueWorkers(queueName: string, reason?: string): void

prepareDestroy

Method

Source
prepareDestroy.ts typescript
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.ts typescript
registerCommand(commandDefinition: CommandDefinition<any, any, any, any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void>

registerService

Method

Source
registerService.ts typescript
registerService(...services: AnyService[]): HonoServiceClass<Bindings, Variables>

Registers service instances and adds their HTTP-exposed commands and streams.

registerStream

Method

registerStream.ts typescript
registerStream(streamDefinition: StreamDefinition<any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void>

registerSubscription

Method

registerSubscription.ts typescript
registerSubscription(subscriptionDefinition: SubscriptionDefinition<any, any, any, any, any, any, any, any, EmptyObject, any, any, any>): Promise<void>

resumeQueueWorkers

Method

resumeQueueWorkers.ts typescript
resumeQueueWorkers(queueName: string): void

resumeSubscriptionConsumer

Method

resumeSubscriptionConsumer.ts typescript
resumeSubscriptionConsumer(registrationKey: string): Promise<void>

sendServiceInfo

Method

sendServiceInfo.ts typescript
sendServiceInfo(infoType: InfoMessageType, target?: string, payload?: Record<string, unknown>): Promise<Readonly<EBMessage>>

Broadcast service info message

setHealthFunction

Method

Source
setHealthFunction.ts typescript
setHealthFunction(fn: HealthFunction<HonoServiceClass<Bindings, Variables>>): HonoServiceClass<Bindings, Variables>

Sets the callback used by the configured health endpoint.

setHonoTypes

Method

Source
setHonoTypes.ts typescript
setHonoTypes<E>(): HonoServiceClass<Bindings & E["Bindings"], Variables & E["Variables"]>

Narrows Hono `Bindings` and `Variables` types for middleware and handlers.

setProtectMiddleware

Method

Source
setProtectMiddleware.ts typescript
setProtectMiddleware(fn: EndpointProtectMiddleware<HonoServiceClass<Bindings, Variables>, Bindings, Variables>): HonoServiceClass<Bindings, Variables>

Sets middleware for endpoints marked as protected in HTTP metadata.

setServiceAvailable

Method

Source
setServiceAvailable.ts typescript
setServiceAvailable(): Promise<void>

Set the service available Request will be processed.

setServiceUnavailable

Method

Source
setServiceUnavailable.ts typescript
setServiceUnavailable(): Promise<void>

Set the service unavailable The webserver will return 503 Service Unavailable

start

Method

Source
start.ts typescript
start(): Promise<void>

Starts the service and registers health, OpenAPI and error handling routes.

startActiveSpan

Method

startActiveSpan.ts typescript
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.ts typescript
startQueueWorkers(): void

stopQueueWorkers

Method

stopQueueWorkers.ts typescript
stopQueueWorkers(): Promise<void>

wrapInSpan

Method

wrapInSpan.ts typescript
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!