Skip to content

PURISTA API


PURISTA API / @purista/core / Service

Class: Service<S>

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

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 = ServiceClassTypes

Implements

Constructors

Constructor

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

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

Parameters

config

ServiceConstructorInput<S>

Returns

Service<S>

Overrides

ServiceBaseClass.constructor

Properties

activeStreamSessions

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

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


commandDefinitionList

commandDefinitionList: CommandDefinitionListResolved<any>

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


commands

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

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


config

config: S["ConfigType"]

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

Implementation of

ServiceClass.config


configSchema

protected configSchema: Schema | undefined

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

Inherited from

ServiceBaseClass.configSchema


configStore

protected configStore: ConfigStore

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

Inherited from

ServiceBaseClass.configStore


eventBridge

protected eventBridge: EventBridge

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

Inherited from

ServiceBaseClass.eventBridge


info

readonly info: ServiceInfoType

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

Inherited from

ServiceBaseClass.info


isStarted

isStarted: boolean = false

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


logger

logger: Logger

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

Inherited from

ServiceBaseClass.logger


queueDefinitionList

protected queueDefinitionList: QueueDefinitionListResolved<any>

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


queueWorkerDefinitionList

protected queueWorkerDefinitionList: QueueWorkerDefinitionListResolved<any>

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


resources

resources: S["Resources"]

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

Implementation of

ServiceClass.resources


secretStore

protected secretStore: SecretStore

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

Inherited from

ServiceBaseClass.secretStore


spanProcessor

spanProcessor: SpanProcessor | undefined

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

Inherited from

ServiceBaseClass.spanProcessor


stateStore

protected stateStore: StateStore

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

Inherited from

ServiceBaseClass.stateStore


streamDefinitionList

streamDefinitionList: StreamDefinitionListResolved<any>

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


streams

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

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


subscriptionDefinitionList

subscriptionDefinitionList: SubscriptionDefinitionListResolved<any>

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


subscriptions

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

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


traceProvider

traceProvider: NodeTracerProvider

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

Inherited from

ServiceBaseClass.traceProvider

Accessors

name

Get Signature

get name(): string

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

Returns

string


serviceInfo

Get Signature

get serviceInfo(): ServiceInfoType

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

Get service info

Returns

ServiceInfoType

Inherited from

ServiceBaseClass.serviceInfo

Methods

destroy()

destroy(): Promise<void>

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

Stop and destroy the current service

Returns

Promise<void>

Implementation of

ServiceClass.destroy

Overrides

ServiceBaseClass.destroy


emit()

emit<K>(eventName, parameter?): void

Defined in: core/types/GenericEventEmitter.ts:27

Type Parameters

K

K extends EventKey<ServiceEvents>

Parameters

eventName

K

parameter?

ServiceEvents[K]

Returns

void

Inherited from

ServiceBaseClass.emit


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:1523

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:2051

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:2311

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>


getAgentInvokeFunction()

protected getAgentInvokeFunction<Invokes>(serviceTarget, traceId?, principalId?, tenantId?, agentInvokes?): <InvokeResponseType, PayloadType, ParameterType>(receiver, payload, parameter) => AgentInvocation<InvokeResponseType>

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

Type Parameters

Invokes

Invokes extends AgentInvokeList

Parameters

serviceTarget

string

traceId?

string

principalId?

string

tenantId?

string

agentInvokes?

Invokes

Returns

<InvokeResponseType, PayloadType, ParameterType>(receiver, payload, parameter): AgentInvocation<InvokeResponseType>

Type Parameters
InvokeResponseType

InvokeResponseType = { history: any[]; message: any; }

PayloadType

PayloadType = {[key: string]: unknown; attachments: any[]; conversationId?: string; history: any[]; message: string; }

ParameterType

ParameterType = EmptyObject

Parameters
receiver

EBMessageAddress

payload

PayloadType

parameter

ParameterType

Returns

AgentInvocation<InvokeResponseType>


getConsumeStreamFunction()

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

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

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:1348

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:1270

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>

Type Parameters
K

K extends string | number | symbol

Payload

Payload = EmitList[K]

Parameters
eventName

K

eventPayload?

Payload

contentType?

string = 'application/json'

contentEncoding?

string = 'utf-8'

Returns

Promise<void>


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:327

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>

Type Parameters
Payload

Payload

Parameter

Parameter extends EmptyObject

Parameters
receiver

EBMessageAddress

invokePayload

Payload

invokeparameter

Parameter

contentType?

string = 'application/json'

contentEncoding?

string = 'utf-8'

Returns

Promise<any>


getQueueNamespace()

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

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

Parameters

queueInvokes?

QueueInvokeList

traceId?

string

principalId?

string

tenantId?

string

Returns

object

enqueue

enqueue: QueueInvokeFunction & QueueInvokeClientMap<QueueInvokeList> = enqueueProxy

scheduleAt

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


getServiceHealth()

getServiceHealth(): Promise<ServiceHealthState>

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

Returns

Promise<ServiceHealthState>

Implementation of

ServiceClass.getServiceHealth


getTracer()

getTracer(name?, version?): Tracer

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

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:246

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:282

Returns

Promise<void>


off()

off<K>(eventName, fn): void

Defined in: core/types/GenericEventEmitter.ts:23

Type Parameters

K

K extends EventKey<ServiceEvents>

Parameters

eventName

K

fn

EventReceiver<ServiceEvents[K]>

Returns

void

Inherited from

ServiceBaseClass.off


on()

on<K>(eventName, fn): void

Defined in: core/types/GenericEventEmitter.ts:19

Type Parameters

K

K extends EventKey<ServiceEvents>

Parameters

eventName

K

fn

EventReceiver<ServiceEvents[K]>

Returns

void

Inherited from

ServiceBaseClass.on


registerCommand()

registerCommand(commandDefinition): Promise<void>

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

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:2282

Parameters

streamDefinition

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

Returns

Promise<void>


registerSubscription()

registerSubscription(subscriptionDefinition): Promise<void>

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

Parameters

subscriptionDefinition

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

Returns

Promise<void>


removeAllListeners()

removeAllListeners(): void

Defined in: core/types/GenericEventEmitter.ts:31

Returns

void

Inherited from

ServiceBaseClass.removeAllListeners


sendServiceInfo()

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

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

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:202

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:127

Start a child span for opentelemetry tracking

Type Parameters

F

F

Parameters

name

string

name of span

opts

SpanOptions

span options

context

optional context

Context | undefined

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:1806

Returns

void


stopQueueWorkers()

protected stopQueueWorkers(): Promise<void>

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

Returns

Promise<void>


wrapInSpan()

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

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

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