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
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
ServiceClass<S>
Constructors
Constructor
new Service<
S>(config):Service<S>
Defined in: core/Service/Service.impl.ts:197
Parameters
config
Returns
Service<S>
Overrides
ServiceBaseClass.constructor
Properties
__serviceClassTypes?
readonlyoptional__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
protectedactiveStreamSessions: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
protectedcommands: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
configSchema
protectedconfigSchema:Schema|undefined
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:52
Inherited from
ServiceBaseClass.configSchema
configStore
protectedconfigStore:ConfigStore
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:49
Inherited from
ServiceBaseClass.configStore
eventBridge
protectedeventBridge:EventBridge
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:40
Inherited from
ServiceBaseClass.eventBridge
info
readonlyinfo: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
protectedmetricContext:PuristaMetricContext<PuristaMetricDefinitions>
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:55
Inherited from
ServiceBaseClass.metricContext
metricDefinitions
protectedmetricDefinitions:PuristaMetricDefinitions
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:54
Inherited from
ServiceBaseClass.metricDefinitions
metricsRecorder
protectedmetricsRecorder:PuristaMetricsRecorderInterface
Defined in: core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:53
Inherited from
ServiceBaseClass.metricsRecorder
queueDefinitionList
protectedqueueDefinitionList:QueueDefinitionListResolved<any>
Defined in: core/Service/Service.impl.ts:167
queueWorkerDefinitionList
protectedqueueWorkerDefinitionList:QueueWorkerDefinitionListResolved<any>
Defined in: core/Service/Service.impl.ts:168
resources
resources:
S["Resources"]
Defined in: core/Service/Service.impl.ts:193
Implementation of
secretStore
protectedsecretStore: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
protectedstateStore: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
protectedstreams: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
protectedsubscriptions: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
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
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()
protectedgetConsumeStreamFunction<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
getContextFunctions()
getContextFunctions(
logger,queueNamespace?):ContextBase
Defined in: core/Service/Service.impl.ts:1682
Parameters
logger
queueNamespace?
Returns
Implementation of
ServiceClass.getContextFunctions
getEmitFunction()
protectedgetEmitFunction<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
Implementation of
ServiceClass.getInFlightDiagnostics
getInvokeFunction()
protectedgetInvokeFunction<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()
protectedgetQueueNamespace(queueInvokes?,traceId?,principalId?,tenantId?):object
Defined in: core/Service/Service.impl.ts:531
Parameters
queueInvokes?
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
Implementation of
ServiceClass.getQueueWorkerPauseState
getServiceHealth()
getServiceHealth():
Promise<ServiceHealthState>
Defined in: core/Service/Service.impl.ts:2593
Returns
Promise<ServiceHealthState>
Implementation of
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
Inherited from
ServiceBaseClass.getTracer
initializeEventbridgeConnect()
protectedinitializeEventbridgeConnect(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()
protectedinitializeQueues():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()
protectedsendServiceInfo(infoType,target?,payload?):Promise<Readonly<EBMessage>>
Defined in: core/Service/Service.impl.ts:376
Broadcast service info message
Parameters
infoType
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
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
Inherited from
ServiceBaseClass.startActiveSpan
startQueueWorkers()
protectedstartQueueWorkers():void
Defined in: core/Service/Service.impl.ts:2159
Returns
void
stopQueueWorkers()
protectedstopQueueWorkers():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
Inherited from
ServiceBaseClass.wrapInSpan
