Skip to content

PURISTA API


PURISTA API / @purista/core / Service

Class: Service<S>

Defined in: core/Service/Service.impl.ts:149

Base class for all services. This class provides base functions to work with the event bridge, logging and so on

Every service should extend this class and should not directly access the eventbridge or other service

typescript
class MyService extends Service {

  async start() {
    await super.start()
    // your custom implementation
  }

  async destroy() {
    // your custom implementation
   await super.destroy()
  }
}

Extends

  • ServiceBaseClass

Extended by

Type Parameters

S

S extends ServiceClassTypes<any, any, any> = ServiceClassTypes<any, any, any>

Implements

Constructors

Constructor

new Service<S>(config): Service<S>

Defined in: core/Service/Service.impl.ts:197

Parameters

config

ServiceConstructorInput<S>

Returns

Service<S>

Overrides

ServiceBaseClass.constructor

Properties

__serviceClassTypes?

readonly optional __serviceClassTypes?: S

Defined in: core/Service/Service.impl.ts:153

Type-only anchor used to preserve cascading service builder types.

This property is never read at runtime.

Implementation of

ServiceClass.__serviceClassTypes


activeStreamSessions

protected activeStreamSessions: Map<string, { cancelled: boolean; cancelReason?: string; onCancel: (reason?) => void[]; }>

Defined in: core/Service/Service.impl.ts:169


commandDefinitionList

commandDefinitionList: CommandDefinitionListResolved<any>

Defined in: core/Service/Service.impl.ts:188


commands

protected commands: Map<string, CommandDefinition<any, any, any, any, any, any, any, any, any, any, S["Resources"], any, any, any>>

Defined in: core/Service/Service.impl.ts:159


config

config: S["ConfigType"]

Defined in: core/Service/Service.impl.ts:191

Implementation of

ServiceClass.config


configSchema

protected configSchema: Schema | undefined

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:52

Inherited from

ServiceBaseClass.configSchema


configStore

protected configStore: ConfigStore

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:49

Inherited from

ServiceBaseClass.configStore


eventBridge

protected eventBridge: EventBridge

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:40

Inherited from

ServiceBaseClass.eventBridge


info

readonly info: ServiceInfoType

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:38

Inherited from

ServiceBaseClass.info


isStarted

isStarted: boolean = false

Defined in: core/Service/Service.impl.ts:195


logger

logger: Logger

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:42

Inherited from

ServiceBaseClass.logger


metricContext

protected metricContext: PuristaMetricContext<PuristaMetricDefinitions>

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:55

Inherited from

ServiceBaseClass.metricContext


metricDefinitions

protected metricDefinitions: PuristaMetricDefinitions

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:54

Inherited from

ServiceBaseClass.metricDefinitions


metricsRecorder

protected metricsRecorder: PuristaMetricsRecorderInterface

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:53

Inherited from

ServiceBaseClass.metricsRecorder


queueDefinitionList

protected queueDefinitionList: QueueDefinitionListResolved<any>

Defined in: core/Service/Service.impl.ts:167


queueWorkerDefinitionList

protected queueWorkerDefinitionList: QueueWorkerDefinitionListResolved<any>

Defined in: core/Service/Service.impl.ts:168


resources

resources: S["Resources"]

Defined in: core/Service/Service.impl.ts:193

Implementation of

ServiceClass.resources


secretStore

protected secretStore: SecretStore

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:48

Inherited from

ServiceBaseClass.secretStore


spanProcessor

spanProcessor: SpanProcessor | undefined

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:44

Inherited from

ServiceBaseClass.spanProcessor


stateStore

protected stateStore: StateStore

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:50

Inherited from

ServiceBaseClass.stateStore


streamDefinitionList

streamDefinitionList: StreamDefinitionListResolved<any>

Defined in: core/Service/Service.impl.ts:190


streams

protected streams: Map<string, StreamDefinition<any, any, any, any, any, any, any, S["Resources"], any, any, any>>

Defined in: core/Service/Service.impl.ts:163


subscriptionDefinitionList

subscriptionDefinitionList: SubscriptionDefinitionListResolved<any>

Defined in: core/Service/Service.impl.ts:189


subscriptions

protected subscriptions: Map<string, SubscriptionDefinition<any, any, any, any, any, any, any, any, S["Resources"], any, any, any>>

Defined in: core/Service/Service.impl.ts:155


traceProvider

traceProvider: NodeTracerProvider

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:46

Inherited from

ServiceBaseClass.traceProvider

Accessors

name

Get Signature

get name(): string

Defined in: core/Service/Service.impl.ts:231

Returns

string


serviceInfo

Get Signature

get serviceInfo(): ServiceInfoType

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:129

Get service info

Returns

ServiceInfoType

Inherited from

ServiceBaseClass.serviceInfo

Methods

destroy()

destroy(): Promise<void>

Defined in: core/Service/Service.impl.ts:3398

Stop and destroy the current service

Returns

Promise<void>

Implementation of

ServiceClass.destroy

Overrides

ServiceBaseClass.destroy


executeCommand()

executeCommand(message): Promise<Readonly<Omit<{ contentEncoding: "utf-8"; contentType: "application/json"; correlationId: string; eventName?: string; id: string; isHandledError: boolean; messageType: CommandErrorResponse; otp?: string; payload: { data?: unknown; message: string; status: StatusCode; }; principalId?: string; receiver: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }, "instanceId">> | { contentEncoding: string; contentType: string; correlationId: string; eventName?: string; id: string; messageType: CommandSuccessResponse; otp: string; payload: unknown; principalId?: string; receiver: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }>

Defined in: core/Service/Service.impl.ts:1876

Called when a command is received by the service

Parameters

message

Readonly<Command>

Command envelope to execute

Returns

Promise<Readonly<Omit<{ contentEncoding: "utf-8"; contentType: "application/json"; correlationId: string; eventName?: string; id: string; isHandledError: boolean; messageType: CommandErrorResponse; otp?: string; payload: { data?: unknown; message: string; status: StatusCode; }; principalId?: string; receiver: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }, "instanceId">> | { contentEncoding: string; contentType: string; correlationId: string; eventName?: string; id: string; messageType: CommandSuccessResponse; otp: string; payload: unknown; principalId?: string; receiver: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }>


executeStream()

executeStream(message): Promise<void>

Defined in: core/Service/Service.impl.ts:2736

Parameters

message

Readonly<StreamMessage>

Returns

Promise<void>


executeSubscription()

executeSubscription(message, subscriptionName): Promise<Omit<{ contentEncoding: string; contentType: string; correlationId?: string; eventName: string; id: string; messageType: CustomMessage; otp?: string; payload?: unknown; principalId?: string; receiver?: EBMessageAddress; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }, "id" | "timestamp"> | undefined>

Defined in: core/Service/Service.impl.ts:3030

Parameters

message

Readonly<EBMessage>

subscriptionName

string

Returns

Promise<Omit<{ contentEncoding: string; contentType: string; correlationId?: string; eventName: string; id: string; messageType: CustomMessage; otp?: string; payload?: unknown; principalId?: string; receiver?: EBMessageAddress; sender: { instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }; tenantId?: string; timestamp: number; traceId?: string; }, "id" | "timestamp"> | undefined>


getConsumeStreamFunction()

protected getConsumeStreamFunction<StreamInvokes>(serviceTarget, traceId?, principalId?, tenantId?, streamInvokes?): OpenStreamFunction

Defined in: core/Service/Service.impl.ts:1461

Type Parameters

StreamInvokes

StreamInvokes extends StreamInvokeList

Parameters

serviceTarget

string

traceId?

string

principalId?

string

tenantId?

string

streamInvokes?

StreamInvokes

Returns

OpenStreamFunction


getContextFunctions()

getContextFunctions(logger, queueNamespace?): ContextBase

Defined in: core/Service/Service.impl.ts:1682

Parameters

logger

Logger

queueNamespace?

QueueContext

Returns

ContextBase

Implementation of

ServiceClass.getContextFunctions


getEmitFunction()

protected getEmitFunction<EmitList>(serviceTarget, traceId?, principalId?, tenantId?, emitList?): <K, Payload>(eventName, eventPayload?, contentType, contentEncoding) => Promise<void>

Defined in: core/Service/Service.impl.ts:1573

Type Parameters

EmitList

EmitList extends Record<string, Schema> = EmptyObject

Parameters

serviceTarget

string

traceId?

string

principalId?

string

tenantId?

string

emitList?

EmitList

Returns

<K, Payload>(eventName, eventPayload?, contentType, contentEncoding) => Promise<void>


getInFlightDiagnostics()

getInFlightDiagnostics(): InFlightDiagnostics

Defined in: core/Service/Service.impl.ts:2700

Returns

InFlightDiagnostics

Implementation of

ServiceClass.getInFlightDiagnostics


getInvokeFunction()

protected getInvokeFunction<Invokes>(serviceTarget, traceId?, principalId?, tenantId?, invokes?): <Payload, Parameter>(receiver, invokePayload, invokeparameter, contentType, contentEncoding) => Promise<any>

Defined in: core/Service/Service.impl.ts:396

Type Parameters

Invokes

Invokes extends InvokeList

Parameters

serviceTarget

string

traceId?

string

principalId?

string

tenantId?

string

invokes?

Invokes

Returns

<Payload, Parameter>(receiver, invokePayload, invokeparameter, contentType, contentEncoding) => Promise<any>


getPausedSubscriptionConsumerState()

getPausedSubscriptionConsumerState(): PausedSubscriptionConsumersByRegistrationKey

Defined in: core/Service/Service.impl.ts:2711

Returns

PausedSubscriptionConsumersByRegistrationKey

Implementation of

ServiceClass.getPausedSubscriptionConsumerState


getQueueNamespace()

protected getQueueNamespace(queueInvokes?, traceId?, principalId?, tenantId?): object

Defined in: core/Service/Service.impl.ts:531

Parameters

queueInvokes?

QueueInvokeList

traceId?

string

principalId?

string

tenantId?

string

Returns

object

enqueue

enqueue: QueueInvokeFunction & QueueInvokeClientMap<QueueInvokeList> = enqueueProxy

scheduleAt

scheduleAt: QueueScheduleFunction & QueueScheduleProxy<QueueInvokeClientMap<QueueInvokeList>> = scheduleProxy


getQueueWorkerPauseState()

getQueueWorkerPauseState(): QueueWorkerPauseStateByQueue

Defined in: core/Service/Service.impl.ts:2707

Returns

QueueWorkerPauseStateByQueue

Implementation of

ServiceClass.getQueueWorkerPauseState


getServiceHealth()

getServiceHealth(): Promise<ServiceHealthState>

Defined in: core/Service/Service.impl.ts:2593

Returns

Promise<ServiceHealthState>

Implementation of

ServiceClass.getServiceHealth


getTracer()

getTracer(name?, version?): Tracer

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:138

Returns open telemetry tracer of this service

Parameters

name?

string

version?

string

Returns

Tracer

Tracer

Implementation of

ServiceClass.getTracer

Inherited from

ServiceBaseClass.getTracer


initializeEventbridgeConnect()

protected initializeEventbridgeConnect(commandDefinitionList, subscriptions, streams): Promise<void>

Defined in: core/Service/Service.impl.ts:314

Connect service to event bridge to receive commands and command responses

Parameters

commandDefinitionList

CommandDefinitionListResolved<any>

subscriptions

SubscriptionDefinitionListResolved<any>

streams

StreamDefinitionListResolved<any>

Returns

Promise<void>


initializeQueues()

protected initializeQueues(): Promise<void>

Defined in: core/Service/Service.impl.ts:350

Returns

Promise<void>


pauseQueueWorkers()

pauseQueueWorkers(queueName, reason?): void

Defined in: core/Service/Service.impl.ts:2715

Parameters

queueName

string

reason?

string = 'paused_by_operator'

Returns

void

Implementation of

ServiceClass.pauseQueueWorkers


registerCommand()

registerCommand(commandDefinition): Promise<void>

Defined in: core/Service/Service.impl.ts:2114

Parameters

commandDefinition

CommandDefinition<any, any, any, any, any, any, any, any, any, any, S["Resources"], any, any, any>

Returns

Promise<void>


registerStream()

registerStream(streamDefinition): Promise<void>

Defined in: core/Service/Service.impl.ts:3000

Parameters

streamDefinition

StreamDefinition<any, any, any, any, any, any, any, S["Resources"], any, any, any>

Returns

Promise<void>


registerSubscription()

registerSubscription(subscriptionDefinition): Promise<void>

Defined in: core/Service/Service.impl.ts:3329

Parameters

subscriptionDefinition

SubscriptionDefinition<any, any, any, any, any, any, any, any, S["Resources"], any, any, any>

Returns

Promise<void>


resumeQueueWorkers()

resumeQueueWorkers(queueName): void

Defined in: core/Service/Service.impl.ts:2722

Parameters

queueName

string

Returns

void

Implementation of

ServiceClass.resumeQueueWorkers


resumeSubscriptionConsumer()

resumeSubscriptionConsumer(registrationKey): Promise<void>

Defined in: core/Service/Service.impl.ts:2726

Parameters

registrationKey

string

Returns

Promise<void>

Implementation of

ServiceClass.resumeSubscriptionConsumer


sendServiceInfo()

protected sendServiceInfo(infoType, target?, payload?): Promise<Readonly<EBMessage>>

Defined in: core/Service/Service.impl.ts:376

Broadcast service info message

Parameters

infoType

InfoMessageType

type of info message

target?

string

function name is need in messages like InfoServiceFunctionAdded

payload?

Record<string, unknown>

Returns

Promise<Readonly<EBMessage>>


start()

start(): Promise<void>

Defined in: core/Service/Service.impl.ts:272

It connects to the event bridge and subscribes to the topics that are in the subscription list.

Returns

Promise<void>

Implementation of

ServiceClass.start


startActiveSpan()

startActiveSpan<F>(name, opts, context, fn): Promise<F>

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:153

Start a child span for opentelemetry tracking

Type Parameters

F

F

Parameters

name

string

name of span

opts

SpanOptions

span options

context

Context | undefined

optional context

fn

(span) => Promise<F>

function to be executed within the span

Returns

Promise<F>

return value of fn

Implementation of

ServiceClass.startActiveSpan

Inherited from

ServiceBaseClass.startActiveSpan


startQueueWorkers()

protected startQueueWorkers(): void

Defined in: core/Service/Service.impl.ts:2159

Returns

void


stopQueueWorkers()

protected stopQueueWorkers(): Promise<void>

Defined in: core/Service/Service.impl.ts:2174

Returns

Promise<void>


wrapInSpan()

wrapInSpan<F>(name, opts, fn, context?): Promise<F>

Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:203

Start span for opentelemetry tracking on same level. The created span will not become the "active" span within opentelemetry!

This means during logging and similar the spanId of parent span is logged.

Use wrapInSpan for marking points in flow of one bigger function, but not to trace the program flow itself

Type Parameters

F

F

Parameters

name

string

name of span

opts

SpanOptions

span options

fn

(span) => Promise<F>

function te be executed in the span

context?

Context

span context

Returns

Promise<F>

return value of fn

Implementation of

ServiceClass.wrapInSpan

Inherited from

ServiceBaseClass.wrapInSpan