PURISTA API / @purista/core / Service
Class: Service<S>
Defined in: packages/core/src/core/Service/Service.impl.ts:84
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
Type Parameters
• S extends ServiceClassTypes
= ServiceClassTypes
Implements
ServiceClass
<S
>
Constructors
new Service()
new Service<
S
>(config
):Service
<S
>
Defined in: packages/core/src/core/Service/Service.impl.ts:105
Parameters
config
Returns
Service
<S
>
Overrides
ServiceBaseClass.constructor
Properties
commandDefinitionList
commandDefinitionList:
CommandDefinitionListResolved
<any
>
Defined in: packages/core/src/core/Service/Service.impl.ts:97
commands
protected
commands:Map
<string
,CommandDefinition
<any
,any
,any
,any
,any
,any
,any
,any
,any
,any
,S
["Resources"
],any
,any
,any
>>
Defined in: packages/core/src/core/Service/Service.impl.ts:92
config
config:
S
["ConfigType"
]
Defined in: packages/core/src/core/Service/Service.impl.ts:99
Implementation of
configSchema
protected
configSchema:undefined
|SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:43
Inherited from
ServiceBaseClass.configSchema
configStore
protected
configStore:ConfigStore
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:40
Inherited from
ServiceBaseClass.configStore
eventBridge
protected
eventBridge:EventBridge
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:31
Inherited from
ServiceBaseClass.eventBridge
info
readonly
info:ServiceInfoType
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:29
Inherited from
ServiceBaseClass.info
isStarted
isStarted:
boolean
=false
Defined in: packages/core/src/core/Service/Service.impl.ts:103
logger
logger:
Logger
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:33
Inherited from
ServiceBaseClass.logger
resources
resources:
S
["Resources"
]
Defined in: packages/core/src/core/Service/Service.impl.ts:101
Implementation of
secretStore
protected
secretStore:SecretStore
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:39
Inherited from
ServiceBaseClass.secretStore
spanProcessor
spanProcessor:
undefined
|SpanProcessor
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:35
Inherited from
ServiceBaseClass.spanProcessor
stateStore
protected
stateStore:StateStore
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:41
Inherited from
ServiceBaseClass.stateStore
subscriptionDefinitionList
subscriptionDefinitionList:
SubscriptionDefinitionListResolved
<any
>
Defined in: packages/core/src/core/Service/Service.impl.ts:98
subscriptions
protected
subscriptions:Map
<string
,SubscriptionDefinition
<any
,any
,any
,any
,any
,any
,any
,any
,S
["Resources"
],any
,any
,any
>>
Defined in: packages/core/src/core/Service/Service.impl.ts:88
traceProvider
traceProvider:
NodeTracerProvider
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:37
Inherited from
ServiceBaseClass.traceProvider
Accessors
name
Get Signature
get name():
string
Defined in: packages/core/src/core/Service/Service.impl.ts:123
Returns
string
serviceInfo
Get Signature
get serviceInfo():
ServiceInfoType
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:103
Get service info
Returns
Inherited from
ServiceBaseClass.serviceInfo
Methods
destroy()
destroy():
Promise
<void
>
Defined in: packages/core/src/core/Service/Service.impl.ts:1103
Stop and destroy the current service
Returns
Promise
<void
>
Implementation of
Overrides
ServiceBaseClass.destroy
emit()
emit<
K
>(eventName
,parameter
?):void
Defined in: packages/core/src/core/types/GenericEventEmitter.ts:24
Type Parameters
• K extends EventKey
<ServiceEvents
>
Parameters
eventName
K
parameter?
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: packages/core/src/core/Service/Service.impl.ts:609
Called when a command is received by the service
Parameters
message
Readonly
<{ contentEncoding
: string
; contentType
: string
; correlationId
: string
; eventName
: string
; id
: string
; messageType
: Command
; otp
: string
; payload
: { parameter
: unknown
; payload
: unknown
; }; principalId
: string
; receiver
: EBMessageAddress
; sender
: { instanceId
: string
; serviceName
: string
; serviceTarget
: string
; serviceVersion
: string
; }; tenantId
: string
; timestamp
: number
; traceId
: string
; }>
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
; }>
executeSubscription()
executeSubscription(
message
,subscriptionName
):Promise
<undefined
|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"
>>
Defined in: packages/core/src/core/Service/Service.impl.ts:848
Parameters
message
Readonly
<EBMessage
>
subscriptionName
string
Returns
Promise
<undefined
| 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"
>>
getContextFunctions()
getContextFunctions(
logger
):ContextBase
Defined in: packages/core/src/core/Service/Service.impl.ts:436
Parameters
logger
Returns
getEmitFunction()
protected
getEmitFunction<EmitList
>(serviceTarget
,traceId
?,principalId
?,tenantId
?,emitList
?): <K
,Payload
>(eventName
,eventPayload
?,contentType
,contentEncoding
) =>Promise
<void
>
Defined in: packages/core/src/core/Service/Service.impl.ts:358
Type Parameters
• EmitList extends Record
<string
, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>> = EmptyObject
Parameters
serviceTarget
string
traceId?
string
principalId?
string
tenantId?
string
emitList?
EmitList
Returns
Function
Type Parameters
• K extends string
| number
| symbol
• 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: packages/core/src/core/Service/Service.impl.ts:223
Type Parameters
• Invokes extends InvokeList
Parameters
serviceTarget
string
traceId?
string
principalId?
string
tenantId?
string
invokes?
Invokes
Returns
Function
Type Parameters
• Payload
• Parameter extends EmptyObject
Parameters
receiver
invokePayload
Payload
invokeparameter
Parameter
contentType
string
= 'application/json'
contentEncoding
string
= 'utf-8'
Returns
Promise
<any
>
getTracer()
getTracer(
name
?,version
?):Tracer
Defined in: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:112
Returns open telemetry tracer of this service
Parameters
name?
string
version?
string
Returns
Tracer
Tracer
Implementation of
Inherited from
ServiceBaseClass.getTracer
initializeEventbridgeConnect()
protected
initializeEventbridgeConnect(commandDefinitionList
,subscriptions
):Promise
<void
>
Defined in: packages/core/src/core/Service/Service.impl.ts:169
Connect service to event bridge to receive commands and command responses
Parameters
commandDefinitionList
CommandDefinitionListResolved
<any
>
subscriptions
SubscriptionDefinitionListResolved
<any
>
Returns
Promise
<void
>
off()
off<
K
>(eventName
,fn
):void
Defined in: packages/core/src/core/types/GenericEventEmitter.ts:20
Type Parameters
• 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: packages/core/src/core/types/GenericEventEmitter.ts:16
Type Parameters
• K extends EventKey
<ServiceEvents
>
Parameters
eventName
K
fn
EventReceiver
<ServiceEvents
[K
]>
Returns
void
Inherited from
ServiceBaseClass.on
registerCommand()
registerCommand(
commandDefinition
):Promise
<void
>
Defined in: packages/core/src/core/Service/Service.impl.ts:804
Registers a new command for the service
Parameters
commandDefinition
CommandDefinition
<any
, any
, any
, any
, any
, any
, any
, any
, any
, any
, S
["Resources"
], any
, any
, any
>
the service command definition
Returns
Promise
<void
>
Implementation of
registerSubscription()
registerSubscription(
subscriptionDefinition
):Promise
<void
>
Defined in: packages/core/src/core/Service/Service.impl.ts:1052
Registers a new subscription for the service
Parameters
subscriptionDefinition
SubscriptionDefinition
<any
, any
, any
, any
, any
, any
, any
, any
, S
["Resources"
], any
, any
, any
>
the subscription definition
Returns
Promise
<void
>
Implementation of
ServiceClass
.registerSubscription
removeAllListeners()
removeAllListeners():
void
Defined in: packages/core/src/core/types/GenericEventEmitter.ts:28
Returns
void
Inherited from
ServiceBaseClass.removeAllListeners
sendServiceInfo()
protected
sendServiceInfo(infoType
,target
?,payload
?):Promise
<Readonly
<EBMessage
>>
Defined in: packages/core/src/core/Service/Service.impl.ts:203
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: packages/core/src/core/Service/Service.impl.ts:130
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: packages/core/src/core/Service/ServiceBaseClass/ServiceBaseClass.impl.ts:127
Start a child span for opentelemetry tracking
Type Parameters
• F
Parameters
name
string
name of span
opts
SpanOptions
span options
context
optional context
undefined
| 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
wrapInSpan()
wrapInSpan<
F
>(name
,opts
,fn
,context
?):Promise
<F
>
Defined in: packages/core/src/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
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