Skip to main content

Module: @purista/core


PURISTA API / Modules / @purista/core

Module: @purista/core

This is the main package of PURISTA.

A backend framework for building message based domain services.

This framework adapts and combines a wide range of different patters from domain driven design, cqrs, microservice, event sourcing and lambda functions.

It is build from ground up in typescript and highly focuses on schema, and auto generation of types, input-output-validation, OpenApi documentation (swagger).

It contains the builders, classes & types and some helper functions. For easier testing of commands and subscriptions, the package contains different mock creation helper based on jestopen in new window and sinonopen in new window

Learn PURIST at purista.devopen in new window

Table of contents

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

Command

Event bridge

Helper

Service

Store

Subscription

Unit test helper

Type Aliases

AuthCredentials

Ƭ AuthCredentials: Object

HTTP authentication information

Type declaration

NameTypeDescription
basicAuth?{ password: string ; username: string }Basic-Auth information
basicAuth.passwordstringBasic-Auth password
basicAuth.usernamestringBasic-Auth username
bearerToken?stringBearer token header

Defined in

HttpClient/types/AuthCredentials.ts:4open in new window


BrokerHeaderCommandMsg

Ƭ BrokerHeaderCommandMsg: Prettify<BrokerHeaderCustomMsg & { receiverInstanceId?: InstanceId ; receiverServiceName: string ; receiverServiceTarget: string ; receiverServiceVersion: string }>

Defined in

core/types/BrokerHeaderCommandMsg.ts:5open in new window


BrokerHeaderCommandResponseMsg

Ƭ BrokerHeaderCommandResponseMsg: Prettify<BrokerHeaderCommandMsg & { receiverInstanceId: InstanceId }>

Defined in

core/types/BrokerHeaderCommandResponseMsg.ts:5open in new window


BrokerHeaderCustomMsg

Ƭ BrokerHeaderCustomMsg: Object

Type declaration

NameType
eventName?string
messageTypeEBMessageType
principalId?PrincipalId
senderInstanceIdInstanceId
senderServiceNamestring
senderServiceTargetstring
senderServiceVersionstring
tenantId?TenantId

Defined in

core/types/BrokerHeaderCustomMsg.ts:6open in new window


Command

Ƭ Command<PayloadType, ParameterType>: Prettify<{ correlationId: CorrelationId ; messageType: Command ; payload: { parameter: ParameterType ; payload: PayloadType } ; receiver: EBMessageAddress } & EBMessageBase>

Command is a event bridge message, which is emitted by sender to event bridge. The event bridge dispatches the event to the receiver. A command expects to get a response message from receiver back to sender.

Also if there are subscriptions which are matching given command, the event bridge also dispatches the command message to the subscriber(s).

BE AWARE: Subscribers should not respond with command responses if they are "silent" subscribers/listeners.

Type parameters

NameType
PayloadTypeunknown
ParameterTypeunknown

Defined in

core/types/commandType/Command.ts:18open in new window


CommandDefinitionList

Ƭ CommandDefinitionList<ServiceClassType>: CommandDefinition<ServiceClassType, CommandDefinitionMetadataBase, any, any, any, any, any, any>[]

Helper type for creating list of service commands to be passed as input to service class

export const userServiceCommands: CommandDefinitionList<UserService> = [signUp.getDefinition()]

Type parameters

NameType
ServiceClassTypeextends ServiceClass

Defined in

core/types/commandType/CommandDefinitionList.ts:12open in new window


CommandDefinitionMetadataBase

Ƭ CommandDefinitionMetadataBase: Object

Type declaration

NameType
expose{ contentEncodingRequest?: string ; contentEncodingResponse?: string ; contentTypeRequest?: ContentType ; contentTypeResponse?: ContentType ; deprecated?: boolean ; inputPayload?: SchemaObject ; outputPayload?: SchemaObject ; parameter?: SchemaObject }
expose.contentEncodingRequest?string
expose.contentEncodingResponse?string
expose.contentTypeRequest?ContentType
expose.contentTypeResponse?ContentType
expose.deprecated?boolean
expose.inputPayload?SchemaObject
expose.outputPayload?SchemaObject
expose.parameter?SchemaObject

Defined in

core/types/commandType/CommandDefinitionMetadataBase.ts:5open in new window


Complete

Ƭ Complete<T>: { [P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : T[P] | undefined }

A helper which forces to provide all object keys, even if they are optional.

Example

type A = {
 one?: string,
 two?: number,
 three: string
}

// without:
const x:A = { three: 'will work'}

// this will fail
const y:Complete<A> = { three: 'will complain that one and two is missing'}
// needs to be like this:
const z:Complete<A> = { one: undefined, two: undefined, three: 'will work'}

Type parameters

Name
T

Defined in

core/types/Complete.ts:20open in new window


CompressionMethod

Ƭ CompressionMethod: "gzip" | "deflat" | "br" | undefined

Defined in

core/HttpServer/types/CompressionMethod.ts:1open in new window


ContentType

Ƭ ContentType: "application/json" | "application/javascript" | "text/csv" | "text/css" | "text/html" | "text/javascript" | "text/markdown" | "text/plain" | "text/xml" | string

List of content types for message payloads. If the content type is other than application/json, the message payload must be a string. It is up to the implementation to extract the content type from the original message and to convert or transform data.

Defined in

core/types/ContentType.ts:6open in new window


ContextBase

Ƭ ContextBase: Object

The ContextBase provides is a basic type. Each context for command function, subscription function and all Hooks and transformers will have at least the properties of this type.

Type declaration

NameTypeDescription
configs{ getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction }the config store
configs.getConfigConfigGetterFunctionget a config value from the config store
configs.removeConfigConfigDeleteFunctiondelete a config value from the config store
configs.setConfigConfigSetterFunctionset a config value in the config store
loggerLoggerthe logger instance
secrets{ getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction }the secret store
secrets.getSecretSecretGetterFunctionget a secret from the secret store
secrets.removeSecretSecretDeleteFunctiondelete a secret from the secret store
secrets.setSecretSecretSetterFunctionset a secret in the secret store
startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>) => Promise<F>wrap given function in an opentelemetry active span
states{ getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction }the state store
states.getStateStateGetterFunctionget a state value from the state store
states.removeStateStateDeleteFunctiondelete a state value from the state store
states.setStateStateSetterFunctionset a state value in the state store
wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F>wrap given function in an opentelemetry span

Defined in

core/types/ContextBase.ts:12open in new window


CorrelationId

Ƭ CorrelationId: string

the correlation id links the command invocation message with the command response message

Defined in

core/types/CorrelationId.ts:2open in new window


CustomMessage

Ƭ CustomMessage<Payload>: Prettify<{ eventName: string ; messageType: CustomMessage ; payload?: Payload ; receiver?: EBMessageAddress } & EBMessageBase>

A custom message is a message which can be used to pass business information. The producer emits the message without knowledge about any consumer. The producer does not expect a response from a consumer.

Type parameters

NameType
Payloadunknown

Defined in

core/types/CustomMessage.ts:11open in new window


DefaultConfigStoreConfig

Ƭ DefaultConfigStoreConfig: Record<string, unknown>

Defined in

DefaultConfigStore/types/DefaultConfigStoreConfig.ts:1open in new window


DefaultEventBridgeConfig

Ƭ DefaultEventBridgeConfig: Object

The configuration for the DefaultEventBridge.

Type declaration

NameTypeDescription
emitMessagesAsEventBridgeEvents?booleanEmit messages which have an event name set as javascript events on the event bridge instance
logWarnOnMessagesWithoutReceiver?booleanLog warnings on messages which are emitted, but could not delivered to at least one receiver

Defined in

DefaultEventBridge/types/DefaultEventBridgeConfig.ts:4open in new window


DefaultSecretStoreConfig

Ƭ DefaultSecretStoreConfig: Record<string, unknown>

Defined in

DefaultSecretStore/types/DefaultSecretStoreConfig.ts:1open in new window


DefaultStateStoreConfig

Ƭ DefaultStateStoreConfig: Record<string, unknown>

Defined in

DefaultStateStore/types/DefaultStateStoreConfig.ts:1open in new window


DefinitionEventBridgeConfig

Ƭ DefinitionEventBridgeConfig: Object

Settings and advices for the event bridge, which are set in the command or subscription builder. The properties are advices and hints. It depends on the used event bridge implementation and underlaying message broker, if a specific property can be respected.

Type declaration

NameTypeDescription
autoacknowledgebooleanSend the acknowledge to message broker as soon as the message arrives - defaults to true for commands - defaults to false for subscriptions
durablebooleanAdvise the underlaying message broker to store messages if no consumer is available. Messages will be send as soon as the service is able to consume.
sharedbooleanIf set to true, the event bridge is adviced to deliver one message to at least one consumer instance. True is the default value. If set to false, the event bridge is adviced to deliver one message to all consumer instances. Use case: Receiving Info of message, which need to be passed to all instance to keep information in sync. In serverless environments, this flag should not have any effect Default ts true

Defined in

core/types/DefinitionEventBridgeConfig.ts:6open in new window


EBMessage

Ƭ EBMessage: Command | CommandResponse | InfoMessage | CustomMessage

EBMessage is some message which is handled by the event bridge.

Defined in

core/types/EBMessage.ts:8open in new window


EBMessageAddress

Ƭ EBMessageAddress: Object

A event bridge message address describes the sender or receiver of a message.

Type declaration

NameTypeDescription
instanceId?InstanceIdinstance id of eventbridge
serviceNamestringthe name of the service
serviceTargetstringthe name of the command or subscription
serviceVersionstringthe version of the service

Defined in

core/types/EBMessageAddress.ts:6open in new window


EBMessageBase

Ƭ EBMessageBase: Object

Default fields which are part of any purista message

Type declaration

NameTypeDescription
contentEncodingstringcontent encoding of message payload
contentTypeContentTypecontent type of message payload
correlationId?CorrelationIdcorrelation id to know which command response referrs to which command
eventName?stringevent name for this message
idEBMessageIdglobal unique id of message
otp?stringstringified Opentelemetry parent trace id
principalId?PrincipalIdprincipal id
senderEBMessageSenderAddress-
tenantId?TenantIdprincipal id
timestampnumbertimestamp of message creation time
traceId?TraceIdtrace id of message

Defined in

core/types/EBMessageBase.ts:12open in new window


EBMessageId

Ƭ EBMessageId: string

Unique id of the event bridge message

Defined in

core/types/EBMessageId.ts:4open in new window


EBMessageSenderAddress

Ƭ EBMessageSenderAddress: Prettify<Omit<EBMessageAddress, "instanceId"> & Required<Pick<EBMessageAddress, "instanceId">>>

A event bridge message address describes the sender or receiver of a message.

Defined in

core/types/EBMessageSenderAddress.ts:7open in new window


EmitCustomMessageFunction

Ƭ EmitCustomMessageFunction: <Payload>(eventName: string, payload?: Payload, contentType?: ContentType, contentEncoding?: string) => Promise<void>

Type declaration

▸ <Payload>(eventName, payload?, contentType?, contentEncoding?): Promise<void>

Emits the given payload as custom message with the given event name.

Type parameters
NameType
Payloadunknown
Parameters
NameType
eventNamestring
payload?Payload
contentType?ContentType
contentEncoding?string
Returns

Promise<void>

Example

await emit('my-custom-event-name', { the: 'payload' })

Defined in

core/types/EmitCustomMessageFunction.ts:10open in new window


ErrorResponsePayload

Ƭ ErrorResponsePayload: Object

Error message payload

Type declaration

NameTypeDescription
data?unknownaddition data
messagestringa human readable error message
statusStatusCodethe error status code
traceId?TraceIdthe trace if of the request

Defined in

core/types/ErrorResponsePayload.ts:7open in new window


EventBridgeAdapterEvents

Ƭ EventBridgeAdapterEvents: Object

Index signature

▪ [key: string]: unknown

currently not used, but reserved for further events

Group

Events

Defined in

core/EventBridge/types/EventBridgeEvents.ts:42open in new window


EventBridgeConfig

Ƭ EventBridgeConfig<CustomConfig>: Prettify<{ defaultCommandTimeout?: number ; instanceId?: string ; logLevel?: LogLevelName ; logger?: Logger ; spanProcessor?: SpanProcessor } & CustomConfig>

The config object for an event bridge. Every event bridge implementation must use this type for configuration.

Type parameters

Name
CustomConfig

Defined in

core/EventBridge/types/EventBridgeConfig.ts:10open in new window


EventBridgeCustomEvents

Ƭ EventBridgeCustomEvents: Object

Index signature

▪ [key: string]: unknown

emitted a EBMessage if event name is provided and if it is enabled and supported on the event bridge

Group

Events

Defined in

core/EventBridge/types/EventBridgeEvents.ts:37open in new window


EventBridgeEvents

Ƭ EventBridgeEvents: Prettify<EventBridgeEventsBasic & addPrefixToObject<EventBridgeAdapterEvents, "adapter-"> & addPrefixToObject<EventBridgeCustomEvents, "custom-">>

Defined in

core/EventBridge/types/EventBridgeEvents.ts:47open in new window


EventKey

Ƭ EventKey<T>: string & keyof T

Type parameters

NameType
Textends EventMap

Defined in

core/types/GenericEventEmitter.ts:5open in new window


EventMap

Ƭ EventMap: Record<string, any>

Defined in

core/types/GenericEventEmitter.ts:3open in new window


HttpClientConfig

Ƭ HttpClientConfig<CustomConfig>: Prettify<{ baseUrl: string ; basicAuth?: { password: string ; username: string } ; bearerToken?: string ; defaultHeaders?: Record<string, string> ; defaultTimeout?: number ; enableOpentelemetry?: boolean ; isKeepAlive?: boolean ; logLevel?: LogLevelName ; logger?: Logger ; name?: string ; spanProcessor?: SpanProcessor } & CustomConfig>

Tha basic configuration for a HTTPClient Requires as least a baseUrl

Type parameters

NameType
CustomConfigextends Record<string, unknown>

Defined in

HttpClient/types/HttpClientConfig.ts:9open in new window


HttpClientRequestOptions

Ƭ HttpClientRequestOptions: Object

Options for a single request

Type declaration

NameTypeDescription
hash?stringurl hash @example: http://example.com/index.html#hash
headers?Record<string, string>additional headers
query?Record<string, string>query/search string parameter
timeout?numberTimeout for the request in ms Default ts 30000

Defined in

HttpClient/types/HttpClientRequestOptions.ts:4open in new window


HttpExposedServiceMeta

Ƭ HttpExposedServiceMeta<ParameterType>: Prettify<CommandDefinitionMetadataBase & { expose: { http: { method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" ; openApi?: { additionalStatusCodes?: StatusCode[] ; description: string ; isSecure: boolean ; operationId?: string ; query?: QueryParameter<ParameterType>[] ; summary: string ; tags?: string[] } ; path: string } } }>

Type parameters

NameType
ParameterType{}

Defined in

core/HttpServer/types/HttpExposedServiceMeta.ts:4open in new window


InfoInvokeTimeout

Ƭ InfoInvokeTimeout: { messageType: InfoInvokeTimeout } & InfoServiceBase

Defined in

core/types/infoType/InfoInvokeTimeout.ts:22open in new window


InfoInvokeTimeoutPayload

Ƭ InfoInvokeTimeoutPayload: Object

Type declaration

NameType
correlationIdCorrelationId
receiver{ serviceName: string ; serviceTarget: string ; serviceVersion: string }
receiver.serviceNamestring
receiver.serviceTargetstring
receiver.serviceVersionstring
sender{ serviceName: string ; serviceTarget: string ; serviceVersion: string }
sender.serviceNamestring
sender.serviceTargetstring
sender.serviceVersionstring
timestampnumber
traceIdTraceId

Defined in

core/types/infoType/InfoInvokeTimeout.ts:6open in new window


InfoMessage

Ƭ InfoMessage: InfoServiceDrain | InfoServiceFunctionAdded | InfoServiceInit | InfoServiceNotReady | InfoServiceReady | InfoServiceShutdown | InfoInvokeTimeout | InfoSubscriptionError

Defined in

core/types/infoType/InfoMessage.ts:11open in new window


InfoMessageType

Ƭ InfoMessageType: InfoServiceDrain | InfoServiceFunctionAdded | InfoServiceInit | InfoServiceNotReady | InfoServiceReady | InfoServiceShutdown | InfoInvokeTimeout | InfoSubscriptionError

Defined in

core/types/infoType/InfoMessage.ts:21open in new window


InfoServiceBase

Ƭ InfoServiceBase: Prettify<{ contentEncoding: "utf-8" ; contentType: "application/json" ; payload?: unknown } & EBMessageBase>

Defined in

core/types/infoType/InfoServiceBase.ts:4open in new window


InfoServiceDrain

Ƭ InfoServiceDrain: Prettify<{ messageType: InfoServiceDrain } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceDrain.ts:5open in new window


InfoServiceFunctionAdded

Ƭ InfoServiceFunctionAdded: Prettify<{ messageType: InfoServiceFunctionAdded } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceFunctionAdded.ts:5open in new window


InfoServiceInit

Ƭ InfoServiceInit: Prettify<{ messageType: InfoServiceInit } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceInit.ts:5open in new window


InfoServiceNotReady

Ƭ InfoServiceNotReady: Prettify<{ messageType: InfoServiceNotReady } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceNotReady.ts:5open in new window


InfoServiceReady

Ƭ InfoServiceReady: Prettify<{ messageType: InfoServiceReady } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceReady.ts:5open in new window


InfoServiceShutdown

Ƭ InfoServiceShutdown: Prettify<{ messageType: InfoServiceShutdown } & InfoServiceBase>

Defined in

core/types/infoType/InfoServiceShutdown.ts:5open in new window


InfoSubscriptionError

Ƭ InfoSubscriptionError: Prettify<{ messageType: InfoSubscriptionError } & InfoServiceBase>

Defined in

core/types/infoType/InfoSubscriptionError.ts:5open in new window


InstanceId

Ƭ InstanceId: string

the instance id of the event bridge

Defined in

core/types/InstanceId.ts:2open in new window


InvokeFunction

Ƭ InvokeFunction: <InvokeResponseType, PayloadType, ParameterType>(address: EBMessageAddress, payload: PayloadType, parameter: ParameterType) => Promise<InvokeResponseType>

Type declaration

▸ <InvokeResponseType, PayloadType, ParameterType>(address, payload, parameter): Promise<InvokeResponseType>

Invokes a command and returns the result. It is recommended to validate the result against a schema which only contains the data you actually need.

Type parameters
NameType
InvokeResponseTypeunknown
PayloadTypeunknown
ParameterTypeunknown
Parameters
NameType
addressEBMessageAddress
payloadPayloadType
parameterParameterType
Returns

Promise<InvokeResponseType>

Example


const address: EBMessageAddress = {
  serviceName: 'name-of-service-to-invoke',
  serviceVersion: '1',
  serviceTarget: 'command-name-to-invoke',
}

const inputPayload = { my: 'input' }
const inputParameter = { search: 'for_me' }

const result = await invoke<MyResultType>(address, inputPayload inputParameter )

Defined in

core/types/InvokeFunction.ts:21open in new window


LogFnParamType

Ƭ LogFnParamType: [unknown, string?, ...any] | [string, ...any]

Defined in

core/types/Logger.ts:19open in new window


LogLevelName

Ƭ LogLevelName: "info" | "error" | "warn" | "debug" | "trace" | "fatal"

Defined in

core/types/LogLevelName.ts:1open in new window


LoggerOptions

Ƭ LoggerOptions: Object

Type declaration

NameType
hostname?string
instanceId?InstanceId
name?string
principalId?PrincipalId
puristaVersion?string
serviceName?string
serviceTarget?string
serviceVersion?string
tenantId?TenantId
traceId?TraceId

Defined in

core/types/Logger.ts:6open in new window


LoggerStubs

Ƭ LoggerStubs: Object

Type declaration

NameType
debugSinonStub
errorSinonStub
infoSinonStub
traceSinonStub
warnSinonStub

Defined in

mocks/getLogger.mock.ts:41open in new window


Newable

Ƭ Newable<T, ConfigType>: (config: ServiceConstructorInput<ConfigType>) => T

Type parameters

Name
T
ConfigType

Type declaration

new Newable(config): T

Parameters
NameType
configServiceConstructorInput<ConfigType>
Returns

T

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:28open in new window


PendigInvocation

Ƭ PendigInvocation: Object

Type declaration

NameType
reject(error: HandledError | UnhandledError) => void
resolve(responsePayload: unknown) => void

Defined in

DefaultEventBridge/types/PendingInvocations.ts:3open in new window


Prettify

Ƭ Prettify<T>: { [K in keyof T]: T[K] } & {}

Type parameters

Name
T

Defined in

core/types/Prettify.ts:1open in new window


PrincipalId

Ƭ PrincipalId: string

the principal id

Defined in

core/types/PrincipalId.ts:2open in new window


QueryParameter

Ƭ QueryParameter<ParameterType>: Object

Type parameters

NameType
ParameterType{}

Type declaration

NameType
namekeyof ParameterType
requiredboolean

Defined in

core/HttpServer/types/QueryParameter.ts:1open in new window


SecretStoreCacheMap

Ƭ SecretStoreCacheMap: Map<string, { createdAt: number ; value: string }>

Defined in

core/SecretStore/types/SecretStoreCacheMap.ts:1open in new window


ServiceEvents

Ƭ ServiceEvents: ServiceEventsInternal & addPrefixToObject<CustomEvents, "custom-"> & addPrefixToObject<CustomEvents, "misc-">

ServiceEvents are plain javascript events sent by the service. There are three types:

  • technical events when a services starts, stops, an error occurs and so on are prefixed with service-
  • response messages, which have a event name assigned, are prefixed with custom-
  • additional events, free defined by developer are prefixed with misc-

Defined in

core/types/ServiceEvents.ts:98open in new window


ServiceInfoType

Ƭ ServiceInfoType: Object

General service information

Type declaration

NameType
serviceDescriptionstring
serviceNamestring
serviceVersionstring

Defined in

core/types/infoType/ServiceInfoType.ts:4open in new window


ShutdownEntry

Ƭ ShutdownEntry: Object

Entry of thing you like to shutdown gracefully

Type declaration

NameTypeDescription
destroy() => Promise<void>a async function that is called during shutdown
namestringthe name

Defined in

helper/types/ShutdownEntry.ts:4open in new window


StoreBaseConfig

Ƭ StoreBaseConfig<Config>: Prettify<{ cacheTtl?: number ; enableCache?: boolean ; enableGet?: boolean ; enableRemove?: boolean ; enableSet?: boolean ; logLevel?: LogLevelName ; logger?: Logger } & Config>

Basic configuration object which is used by any store

Type parameters

NameType
Configextends Record<string, unknown>

Defined in

core/types/StoreBaseConfig.ts:8open in new window


SubscriptionDefinitionList

Ƭ SubscriptionDefinitionList<ServiceClassType>: SubscriptionDefinition<ServiceClassType, any, any, any, any>[]

Helper type for creating list of service commands to be passed as input to service class

export const userServiceCommands: SubscriptionDefinitionList<UserService> = [signUp.getDefinition()]

Type parameters

NameType
ServiceClassTypeextends ServiceClass

Defined in

core/types/subscription/SubscriptionDefinitionList.ts:11open in new window


SubscriptionDefinitionMetadataBase

Ƭ SubscriptionDefinitionMetadataBase: Object

Type declaration

NameType
expose{ contentEncodingRequest?: string ; contentEncodingResponse?: string ; contentTypeRequest?: ContentType ; contentTypeResponse?: ContentType ; inputPayload?: SchemaObject ; outputPayload?: SchemaObject ; parameter?: SchemaObject }
expose.contentEncodingRequest?string
expose.contentEncodingResponse?string
expose.contentTypeRequest?ContentType
expose.contentTypeResponse?ContentType
expose.inputPayload?SchemaObject
expose.outputPayload?SchemaObject
expose.parameter?SchemaObject

Defined in

core/types/subscription/SubscriptionDefinitionMetadataBase.ts:5open in new window


SubscriptionStorageEntry

Ƭ SubscriptionStorageEntry: Object

Type declaration

NameType
cb(message: EBMessage) => Promise<Omit<CustomMessage, "id" | "timestamp"> | undefined>
emitEventName?string
isMatchingEventName(input?: string) => boolean
isMatchingMessageType(input: EBMessageType) => boolean
isMatchingPrincipalId(input?: string) => boolean
isMatchingReceiverInstanceId(input?: string) => boolean
isMatchingReceiverServiceName(input?: string) => boolean
isMatchingReceiverServiceTarget(input?: string) => boolean
isMatchingReceiverServiceVersion(input?: string) => boolean
isMatchingSenderInstanceId(input?: string) => boolean
isMatchingSenderServiceName(input?: string) => boolean
isMatchingSenderServiceTarget(input?: string) => boolean
isMatchingSenderServiceVersion(input?: string) => boolean
isMatchingTenantId(input?: string) => boolean

Defined in

DefaultEventBridge/types/SubscriptionStorageEntry.ts:3open in new window


SupportedHttpMethod

Ƭ SupportedHttpMethod: "GET" | "POST" | "PATCH" | "PUT" | "DELETE"

Supported HTTP-Methods for defining endpoints

Defined in

core/HttpServer/types/SupportedHttpMethod.ts:2open in new window


TenantId

Ƭ TenantId: string

the tenant id

Defined in

core/types/TenantId.ts:2open in new window


TraceId

Ƭ TraceId: string

The trace id which will be passed through all commands, invocations and subscriptions

Defined in

core/types/TraceId.ts:4open in new window


addPrefixToObject

Ƭ addPrefixToObject<T, P>: { [K in keyof T as K extends string ? `${P}${K}` : never]: T[K] }

Helper for better typescript type. All keys of given object must start with the given prefix. Otherwise Typescript will complain.


#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | `T` |
| `P` | extends `string` |

#### Defined in

[core/types/addPrefixToObject.ts:7](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/core/types/addPrefixToObject.ts#L7)

## Variables

### MIN\_CONTENT\_SIZE\_FOR\_COMPRESSION

• `Const` **MIN\_CONTENT\_SIZE\_FOR\_COMPRESSION**: ``1024``

#### Defined in

[core/HttpServer/MinContentSizeForCompression.const.ts:1](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/core/HttpServer/MinContentSizeForCompression.const.ts#L1)

___

### ServiceInfoValidator

• `Const` **ServiceInfoValidator**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `set` | (`obj`: [`ServiceInfoType`](purista_core.md#serviceinfotype), `prop`: keyof [`ServiceInfoType`](purista_core.md#serviceinfotype), `value`: `string`) => `boolean` |

#### Defined in

[core/Service/ServiceInfoValidator.impl.ts:5](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/core/Service/ServiceInfoValidator.impl.ts#L5)

___

### infoMessageTypes

• `Const` **infoMessageTypes**: [`EBMessageType`](../enums/purista_core.EBMessageType.md)[]

#### Defined in

[core/types/infoType/InfoMessage.ts:30](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/core/types/infoType/InfoMessage.ts#L30)

___

### puristaVersion

• `Const` **puristaVersion**: ``"1.8.3"``

#### Defined in

[version.ts:1](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/version.ts#L1)

## Functions

### extendApi

▸ **extendApi**\<`T`\>(`schema`, `SchemaObject?`): `T`

#### Type parameters

| Name | Type |
| :------ | :------ |
| `T` | extends [`OpenApiZodAny`](../interfaces/purista_core.OpenApiZodAny.md) |

#### Parameters

| Name | Type |
| :------ | :------ |
| `schema` | `T` |
| `SchemaObject` | `SchemaObject` |

#### Returns

`T`

#### Defined in

[zodOpenApi/zodOpenApi.impl.ts:25](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/zodOpenApi/zodOpenApi.impl.ts#L25)

___

### generateSchema

▸ **generateSchema**(`zodRef`, `useOutput?`): `SchemaObject`

#### Parameters

| Name | Type |
| :------ | :------ |
| `zodRef` | [`OpenApiZodAny`](../interfaces/purista_core.OpenApiZodAny.md) |
| `useOutput?` | `boolean` |

#### Returns

`SchemaObject`

#### Defined in

[zodOpenApi/zodOpenApi.impl.ts:414](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/zodOpenApi/zodOpenApi.impl.ts#L414)

___

### getCommandFunctionWithValidation

▸ **getCommandFunctionWithValidation**\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `MessageResultType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>(`fn`, `inputPayloadSchema`, `inputParameterSchema`, `outputPayloadSchema`, `beforeGuards?`): [`CommandFunction`](purista_core.md#commandfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>

#### Type parameters

| Name | Type |
| :------ | :------ |
| `ServiceClassType` | extends [`ServiceClass`](../interfaces/purista_core.ServiceClass.md)\<`unknown`\> |
| `MessagePayloadType` | `unknown` |
| `MessageParamsType` | `unknown` |
| `MessageResultType` | `unknown` |
| `FunctionPayloadType` | `MessagePayloadType` |
| `FunctionParamsType` | `MessageParamsType` |
| `FunctionResultType` | `MessageResultType` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `fn` | [`CommandFunction`](purista_core.md#commandfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\> |
| `inputPayloadSchema` | `undefined` \| `ZodType`\<`FunctionPayloadType`, `ZodTypeDef`, `MessagePayloadType`\> |
| `inputParameterSchema` | `undefined` \| `ZodType`\<`FunctionParamsType`, `ZodTypeDef`, `MessageParamsType`\> |
| `outputPayloadSchema` | `undefined` \| `ZodType`\<`MessageResultType`, `ZodTypeDef`, `FunctionResultType`\> |
| `beforeGuards` | `Record`\<`string`, [`CommandBeforeGuardHook`](purista_core.md#commandbeforeguardhook)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`\>\> |

#### Returns

[`CommandFunction`](purista_core.md#commandfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>

#### Defined in

[CommandDefinitionBuilder/getCommandFunctionWithValidation.impl.ts:13](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/CommandDefinitionBuilder/getCommandFunctionWithValidation.impl.ts#L13)

___

### getDefaultEventBridgeConfig

▸ **getDefaultEventBridgeConfig**(): [`Complete`](purista_core.md#complete)\<[`DefaultEventBridgeConfig`](purista_core.md#defaulteventbridgeconfig)\>

#### Returns

[`Complete`](purista_core.md#complete)\<[`DefaultEventBridgeConfig`](purista_core.md#defaulteventbridgeconfig)\>

#### Defined in

[DefaultEventBridge/getDefaultEventBridgeConfig.impl.ts:4](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/DefaultEventBridge/getDefaultEventBridgeConfig.impl.ts#L4)

___

### getDefaultLogLevel

▸ **getDefaultLogLevel**(): [`LogLevelName`](purista_core.md#loglevelname)

#### Returns

[`LogLevelName`](purista_core.md#loglevelname)

#### Defined in

[DefaultLogger/getDefaultLogLevel.ts:4](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/DefaultLogger/getDefaultLogLevel.ts#L4)

___

### getNewSubscriptionStorageEntry

▸ **getNewSubscriptionStorageEntry**(`subscription`, `cb`): [`SubscriptionStorageEntry`](purista_core.md#subscriptionstorageentry)

#### Parameters

| Name | Type |
| :------ | :------ |
| `subscription` | [`Subscription`](purista_core.md#subscription) |
| `cb` | (`message`: [`EBMessage`](purista_core.md#ebmessage)) => `Promise`\<`undefined` \| `Omit`\<\{ `contentEncoding`: `string` ; `contentType`: `string` ; `correlationId?`: `string` ; `eventName`: `string` ; `id`: `string` ; `messageType`: [`CustomMessage`](../enums/purista_core.EBMessageType.md#custommessage) ; `otp?`: `string` ; `payload?`: `unknown` ; `principalId?`: `string` ; `receiver?`: [`EBMessageAddress`](purista_core.md#ebmessageaddress) ; `sender`: \{ serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; `tenantId?`: `string` ; `timestamp`: `number` ; `traceId?`: `string`  }, ``"id"`` \| ``"timestamp"``\>\> |

#### Returns

[`SubscriptionStorageEntry`](purista_core.md#subscriptionstorageentry)

#### Defined in

[DefaultEventBridge/getNewSubscriptionStorageEntry.impl.ts:4](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/DefaultEventBridge/getNewSubscriptionStorageEntry.impl.ts#L4)

___

### getSubscriptionFunctionWithValidation

▸ **getSubscriptionFunctionWithValidation**\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `MessageResultType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>(`fn`, `inputPayloadSchema`, `inputParameterSchema`, `outputPayloadSchema`, `beforeGuards?`): [`SubscriptionFunction`](purista_core.md#subscriptionfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>

#### Type parameters

| Name | Type |
| :------ | :------ |
| `ServiceClassType` | extends [`ServiceClass`](../interfaces/purista_core.ServiceClass.md)\<`unknown`\> |
| `MessagePayloadType` | `unknown` |
| `MessageParamsType` | `unknown` |
| `MessageResultType` | `unknown` |
| `FunctionPayloadType` | `MessagePayloadType` |
| `FunctionParamsType` | `MessageParamsType` |
| `FunctionResultType` | `MessageResultType` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `fn` | [`SubscriptionFunction`](purista_core.md#subscriptionfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\> |
| `inputPayloadSchema` | `undefined` \| `ZodType`\<`FunctionPayloadType`, `ZodTypeDef`, `MessagePayloadType`\> |
| `inputParameterSchema` | `undefined` \| `ZodType`\<`FunctionParamsType`, `ZodTypeDef`, `MessageParamsType`\> |
| `outputPayloadSchema` | `undefined` \| `ZodType`\<`MessageResultType`, `ZodTypeDef`, `FunctionResultType`\> |
| `beforeGuards` | `Record`\<`string`, [`SubscriptionBeforeGuardHook`](purista_core.md#subscriptionbeforeguardhook)\<`ServiceClassType`, `FunctionPayloadType`, `FunctionParamsType`\>\> |

#### Returns

[`SubscriptionFunction`](purista_core.md#subscriptionfunction)\<`ServiceClassType`, `MessagePayloadType`, `MessageParamsType`, `FunctionPayloadType`, `FunctionParamsType`, `FunctionResultType`\>

#### Defined in

[SubscriptionDefinitionBuilder/getSubscriptionFunctionWithValidation.impl.ts:13](https://github.com/sebastianwessel/purista/blob/master/packages/core/src/SubscriptionDefinitionBuilder/getSubscriptionFunctionWithValidation.impl.ts#L13)

___

### getTimeoutPromise

▸ **getTimeoutPromise**\<`T`\>(`fn`, `ttl?`): `Promise`\<`T`\>

#### Type parameters

| Name |
| :------ |
| `T` |

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `fn` | `Promise`\<`T`\> | `undefined` | the promise which should get a timeout |
| `ttl` | `number` | `30000` | the timeout in ms |

#### Returns

`Promise`\<`T`\>

**`Default`**

```ts
30000

Defined in

helper/getTimeoutPromise.impl.ts:9open in new window


initDefaultConfigStore

initDefaultConfigStore(options): DefaultConfigStore

Parameters

NameType
optionsObject
options.loggerLogger

Returns

DefaultConfigStore

Defined in

DefaultConfigStore/initDefaultConfigStore.impl.ts:4open in new window


initDefaultSecretStore

initDefaultSecretStore(options): DefaultSecretStore

Parameters

NameType
optionsObject
options.loggerLogger

Returns

DefaultSecretStore

Defined in

DefaultSecretStore/initDefaultSecretStore.impl.ts:4open in new window


initDefaultStateStore

initDefaultStateStore(options): DefaultStateStore

Parameters

NameType
optionsObject
options.loggerLogger

Returns

DefaultStateStore

Defined in

DefaultStateStore/initDefaultStateStore.impl.ts:4open in new window


initLogger

initLogger(level?, opt?): Logger

Create a new logger with the given minimum log level

Parameters

NameType
levelLogLevelName
opt?LoggerOptions

Returns

Logger

Defined in

DefaultLogger/initLogger.impl.ts:13open in new window


isCustomMessage

isCustomMessage(message): message is Object

Checks if a PURISTA message is type of custom message

Parameters

NameTypeDescription
messageEBMessageany PURISTA message

Returns

message is Object

true if message is type of custom message

Defined in

core/types/isCustomMessage.impl.ts:10open in new window


isHttpExposedServiceMeta

isHttpExposedServiceMeta(input?): input is Object

Checks if given input is type of HttpExposedServiceMeta

Parameters

NameType
input?any

Returns

input is Object

boolean - true if input is type of HttpExposedServiceMeta

Defined in

core/HttpServer/types/isHttpExposedServiceMeta.impl.ts:8open in new window


isInfoMessage

isInfoMessage(message): message is InfoMessage

Parameters

NameType
messageEBMessage

Returns

message is InfoMessage

Defined in

core/types/infoType/isInfoMessage.impl.ts:4open in new window


isInfoServiceFunctionAdded

isInfoServiceFunctionAdded(message): message is Object

Parameters

NameType
messageEBMessage

Returns

message is Object

Defined in

core/types/infoType/isInfoServiceFunctionAdded.impl.ts:5open in new window


isMessageMatchingSubscription

isMessageMatchingSubscription(_log, message, subscription): boolean

Parameters

NameType
_logLogger
messageEBMessage
subscriptionSubscriptionStorageEntry

Returns

boolean

Defined in

DefaultEventBridge/isMessageMatchingSubscription.impl.ts:4open in new window


throwIfNotValidMessage

throwIfNotValidMessage(input): void

Validates if the given input might be valid event bridge message It only checks for "technically possible"

Parameters

NameType
inputunknown

Returns

void

Defined in

helper/throwIfNotValidMessage.impl.ts:10open in new window

Command

CommandDefinitionBuilder<ServiceClassType, MessagePayloadType, MessageParamsType, MessageResultType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: Object

Command definition builder is a helper to create and define a command for a service. It helps to set all needed information like schemas and hooks. With these information, the types are automatically set and extended.

A working schema definition needs at least a command name, a short description and the function implementation.

Type parameters

NameType
ServiceClassTypeextends ServiceClass
MessagePayloadTypeunknown
MessageParamsTypeundefined
MessageResultTypevoid
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeMessageResultType

Defined in

CommandDefinitionBuilder/CommandDefinitionBuilder.impl.ts:31open in new window

CommandAfterGuardHook

Ƭ CommandAfterGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionResultType, FunctionPayloadType, FunctionParamsType>: (this: ServiceClassType, context: CommandFunctionContext<MessagePayloadType, MessageParamsType>, result: Readonly<FunctionResultType>, input: Readonly<FunctionPayloadType>, parameter: Readonly<FunctionParamsType>) => Promise<void>

Type parameters

NameType
ServiceClassTypeServiceClass
MessagePayloadTypeunknown
MessageParamsTypeunknown
FunctionResultTypeunknown
FunctionPayloadTypeunknown
FunctionParamsTypeunknown

Type declaration

▸ (this, context, result, input, parameter): Promise<void>

Definition of after guard hook functions. This guard is called after function successfully returns and after output validation.

Parameters
NameType
thisServiceClassType
contextCommandFunctionContext<MessagePayloadType, MessageParamsType>
resultReadonly<FunctionResultType>
inputReadonly<FunctionPayloadType>
parameterReadonly<FunctionParamsType>
Returns

Promise<void>

Defined in

core/types/commandType/CommandAfterGuardHook.ts:10open in new window


CommandBeforeGuardHook

Ƭ CommandBeforeGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType>: (this: ServiceClassType, context: CommandFunctionContext<MessagePayloadType, MessageParamsType>, payload: Readonly<FunctionPayloadType>, parameter: Readonly<FunctionParamsType>) => Promise<void>

Type parameters

NameType
ServiceClassTypeServiceClass
MessagePayloadTypeunknown
MessageParamsTypeunknown
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType

Type declaration

▸ (this, context, payload, parameter): Promise<void>

Guard is called after command function input validation and before executing the command function. The guard is usefull to separate for example auth checks from business logic. It should throw HandledError or return void.

Parameters
NameType
thisServiceClassType
contextCommandFunctionContext<MessagePayloadType, MessageParamsType>
payloadReadonly<FunctionPayloadType>
parameterReadonly<FunctionParamsType>
Returns

Promise<void>

Defined in

core/types/commandType/CommandBeforeGuardHook.ts:11open in new window


CommandDefinition

Ƭ CommandDefinition<ServiceClassType, MetadataType, MessagePayloadType, MessageParamsType, MessageResultType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: Object

The definition for a command provided by some service.

Type parameters

NameType
ServiceClassTypeextends ServiceClass = ServiceClass
MetadataTypeCommandDefinitionMetadataBase
MessagePayloadTypeunknown
MessageParamsTypeunknown
MessageResultTypeunknown
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeunknown

Type declaration

NameTypeDescription
callCommandFunction<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType, FunctionResultType>the command function
commandDescriptionstringthe description of the command
commandNamestringthe name of the command
eventBridgeConfigDefinitionEventBridgeConfigconfig information for event bridge
eventName?stringthe eventName for the command response
hooks{ afterGuard?: Record<string, CommandAfterGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionResultType, FunctionPayloadType, FunctionParamsType>> ; beforeGuard?: Record<string, CommandBeforeGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType>> ; transformInput?: { transformFunction: CommandTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType> ; transformInputSchema: z.ZodType ; transformParameterSchema: z.ZodType } ; transformOutput?: { transformFunction: CommandTransformOutputHook<ServiceClassType, MessagePayloadType, MessageResultType, FunctionParamsType, unknown> ; transformOutputSchema: z.ZodType } }hooks of command
hooks.afterGuard?Record<string, CommandAfterGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionResultType, FunctionPayloadType, FunctionParamsType>>-
hooks.beforeGuard?Record<string, CommandBeforeGuardHook<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType>>-
hooks.transformInput?{ transformFunction: CommandTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType> ; transformInputSchema: z.ZodType ; transformParameterSchema: z.ZodType }-
hooks.transformInput.transformFunctionCommandTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType>-
hooks.transformInput.transformInputSchemaz.ZodType-
hooks.transformInput.transformParameterSchemaz.ZodType-
hooks.transformOutput?{ transformFunction: CommandTransformOutputHook<ServiceClassType, MessagePayloadType, MessageResultType, FunctionParamsType, unknown> ; transformOutputSchema: z.ZodType }-
hooks.transformOutput.transformFunctionCommandTransformOutputHook<ServiceClassType, MessagePayloadType, MessageResultType, FunctionParamsType, unknown>-
hooks.transformOutput.transformOutputSchemaz.ZodType-
metadataMetadataTypethe metadata of the command

Defined in

core/types/commandType/CommandDefinition.ts:17open in new window


CommandErrorResponse

Ƭ CommandErrorResponse: Prettify<{ contentEncoding: "utf-8" ; contentType: "application/json" ; correlationId: CorrelationId ; isHandledError: boolean ; messageType: CommandErrorResponse ; payload: { data?: unknown ; message: string ; status: StatusCode } ; receiver: EBMessageSenderAddress } & EBMessageBase>

CommandErrorResponse is a response to a specific previously received command which indicates some failure.

Defined in

core/types/commandType/CommandErrorResponse.ts:13open in new window


CommandFunction

Ƭ CommandFunction<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: (this: ServiceClassType, context: CommandFunctionContext<MessagePayloadType, MessageParamsType>, payload: Readonly<FunctionPayloadType>, parameter: Readonly<FunctionParamsType>) => Promise<FunctionResultType>

Type parameters

NameType
ServiceClassTypeextends ServiceClass
MessagePayloadTypeunknown
MessageParamsTypeunknown
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeunknown

Type declaration

▸ (this, context, payload, parameter): Promise<FunctionResultType>

CommandFunction is a function which will be triggered when a matching event bridge message is received by the service

Parameters
NameType
thisServiceClassType
contextCommandFunctionContext<MessagePayloadType, MessageParamsType>
payloadReadonly<FunctionPayloadType>
parameterReadonly<FunctionParamsType>
Returns

Promise<FunctionResultType>

Defined in

core/types/commandType/CommandFunction.ts:9open in new window


CommandFunctionContext

Ƭ CommandFunctionContext<MessagePayloadType, MessageParamsType>: Prettify<ContextBase & CommandFunctionContextEnhancements<MessagePayloadType, MessageParamsType>>

The command function context which will be passed into command function.

Type parameters

NameType
MessagePayloadTypeunknown
MessageParamsTypeunknown

Defined in

core/types/commandType/CommandFunctionContext.ts:47open in new window


CommandFunctionContextEnhancements

Ƭ CommandFunctionContextEnhancements<MessagePayloadType, MessageParamsType>: Object

It provides the original command message with types for payload and parameter. Also, the methods:

  • emit which allows to emit custom events to the event bridge
  • invoke which allows to call other commands

Type parameters

NameType
MessagePayloadTypeunknown
MessageParamsTypeunknown

Type declaration

NameTypeDescription
emitEmitCustomMessageFunctionemit a custom message
invokeInvokeFunctionInvokes a command and returns the result. It is recommended to validate the result against a schema which only contains the data you actually need. Example typescript const address: EBMessageAddress = { serviceName: 'name-of-service-to-invoke', serviceVersion: '1', serviceTarget: 'command-name-to-invoke', } const inputPayload = { my: 'input' } const inputParameter = { search: 'for_me' } const result = await invoke<MyResultType>(address, inputPayload inputParameter )
messageReadonly<Command<MessagePayloadType, MessageParamsType>>the original message

Defined in

core/types/commandType/CommandFunctionContext.ts:16open in new window


CommandResponse

Ƭ CommandResponse<T>: CommandSuccessResponse<T> | CommandErrorResponse

CommandResponse is a response to a specific previously received command which can be either a success or failure

Type parameters

NameType
Tunknown

Defined in

core/types/commandType/CommandResponse.ts:9open in new window


CommandSuccessResponse

Ƭ CommandSuccessResponse<PayloadType>: Prettify<{ correlationId: CorrelationId ; messageType: CommandSuccessResponse ; payload: PayloadType ; receiver: EBMessageSenderAddress } & EBMessageBase>

CommandSuccessResponse is a response to a specific previously received command. It indicates that the command was executed successfully and contains the result payload

Type parameters

NameType
PayloadTypeunknown

Defined in

core/types/commandType/CommandSuccessResponse.ts:13open in new window


CommandTransformFunctionContext

Ƭ CommandTransformFunctionContext<PayloadType, ParameterType>: Prettify<ContextBase & { message: Readonly<Command<PayloadType, ParameterType>> }>

Type parameters

Name
PayloadType
ParameterType

Defined in

core/types/commandType/CommandTransformFunctionContext.ts:8open in new window


CommandTransformInputHook

Ƭ CommandTransformInputHook<ServiceClassType, PayloadOutput, ParamsOutput, PayloadInput, ParamsInput>: (this: ServiceClassType, context: CommandTransformFunctionContext<PayloadInput, ParamsInput>, payload: Readonly<PayloadInput>, parameter: Readonly<ParamsInput>) => Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

Type parameters

NameType
ServiceClassTypeServiceClassType
PayloadOutputunknown
ParamsOutputunknown
PayloadInputunknown
ParamsInputunknown

Type declaration

▸ (this, context, payload, parameter): Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

The command transform gets the raw message payload and parameter input, which is validated against the transform input schemas. The command transform function is called before guard hooks and before the actual command function.

It should throw HandledError or return an object with the transformed payload and parameter. The type of returned payload and parameter must match the command function input for payload and parameter

Parameters
NameType
thisServiceClassType
contextCommandTransformFunctionContext<PayloadInput, ParamsInput>
payloadReadonly<PayloadInput>
parameterReadonly<ParamsInput>
Returns

Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

Defined in

core/types/commandType/CommandTransformInputHook.ts:12open in new window


CommandTransformOutputHook

Ƭ CommandTransformOutputHook<ServiceClassType, MessagePayloadType, MessageResultType, MessageParamsType, ResponseOutput>: (this: ServiceClassType, context: CommandTransformFunctionContext<MessagePayloadType, MessageParamsType>, payload: Readonly<MessageResultType>, parameter: Readonly<MessageParamsType>) => Promise<ResponseOutput>

Type parameters

NameType
ServiceClassTypeServiceClassType
MessagePayloadTypeMessagePayloadType
MessageResultTypeMessageResultType
MessageParamsTypeMessageParamsType
ResponseOutputunknown

Type declaration

▸ (this, context, payload, parameter): Promise<ResponseOutput>

This transform hook is executed after function output validation and AfterGuardHooks.

Parameters
NameType
thisServiceClassType
contextCommandTransformFunctionContext<MessagePayloadType, MessageParamsType>
payloadReadonly<MessageResultType>
parameterReadonly<MessageParamsType>
Returns

Promise<ResponseOutput>

Defined in

core/types/commandType/CommandTransformOutputHook.ts:7open in new window


isCommand

isCommand(message): message is Object

Checks if given message is type of Command

Parameters

NameType
messageEBMessage

Returns

message is Object

boolean

Defined in

core/types/commandType/isCommand.impl.ts:12open in new window


isCommandErrorResponse

isCommandErrorResponse(message): message is Object

Checks if given message is type of CommandErrorResponse

Parameters

NameType
messageunknown

Returns

message is Object

boolean

Defined in

core/types/commandType/isCommandErrorResponse.impl.ts:12open in new window


isCommandResponse

isCommandResponse(message): message is CommandResponse

Checks if given message is type of CommandResponse (success or error)

Parameters

NameType
messageEBMessage

Returns

message is CommandResponse

boolean

Defined in

core/types/commandType/isCommandResponse.impl.ts:12open in new window


isCommandSuccessResponse

isCommandSuccessResponse(message): message is Object

Checks if given message is type of CommandSuccessResponse

Parameters

NameType
messageEBMessage

Returns

message is Object

boolean

Defined in

core/types/commandType/isCommandSuccessResponse.impl.ts:12open in new window

Event bridge

DefaultEventBridge: Object

Simple implementation of some simple in-memory event bridge. Does not support threads and does not need any external databases.

Example

import { DefaultEventBridge } from '@purista/core'

const eventBridge = new DefaultEventBridge()
await eventBridge.start()

// add your services

Defined in

DefaultEventBridge/DefaultEventBridge.impl.ts:61open in new window

EventBridgeBaseClass<ConfigType>: Object

The base class to be extended by event bridge implementations

Type parameters

Name
ConfigType

Defined in

core/EventBridge/EventBridgeBaseClass.impl.ts:17open in new window

EventBridge: Object

Event bridge interface The event bridge must implement this interface.

Defined in

core/EventBridge/types/EventBridge.ts:19open in new window

EventBridgeEventsBasic

Ƭ EventBridgeEventsBasic: Object

Events which can be emitted by a event bridge

Type declaration

NameTypeDescription
eventbridge-connectedneveremitted when then connection to event bridge is established
eventbridge-connection-errorundefined | unknown | Erroremitted when the connection to event bridge can not be established or a connection has issues or gets closed unexpectedly
eventbridge-disconnectedneveremitted when the connection to event bridge closed
eventbridge-errorUnhandledError | unknownemitted on internal event bridge error
eventbridge-reconnectingneveremitted on retry to connect to event bridge

Defined in

core/EventBridge/types/EventBridgeEvents.ts:20open in new window


getCommandQueueName

getCommandQueueName(address): string

Parameters

NameType
addressEBMessageAddress

Returns

string

Defined in

core/helper/getCommandQueueName.impl.ts:10open in new window

Helper

convertToCamelCase

convertToCamelCase(str): string

Converts a string into camelCase

Parameters

NameTypeDescription
strstringstring

Returns

string

string converted to camelCase

Link

https://github.com/30-seconds/30-seconds-of-code

Defined in

helper/string/convertToCamelCase.impl.ts:9open in new window


convertToKebabCase

convertToKebabCase(str): string

Converts a string into kebab-case

Parameters

NameTypeDescription
strstringstring

Returns

string

string converted to kebab-case

Link

https://github.com/30-seconds/30-seconds-of-code

Defined in

helper/string/convertToKebabCase.impl.ts:9open in new window


convertToPascalCase

convertToPascalCase(str): string

Converts a string into PascalCase

Parameters

NameTypeDescription
strstringstring

Returns

string

string converted to PascalCase

Link

https://github.com/30-seconds/30-seconds-of-code

Defined in

helper/string/convertToPascalCase.impl.ts:9open in new window


convertToSnakeCase

convertToSnakeCase(str): string

Converts a string into snake_case

Parameters

NameTypeDescription
strstringstring

Returns

string

string converted to snake_case

Link

https://github.com/30-seconds/30-seconds-of-code

Defined in

helper/string/convertToSnakeCase.impl.ts:9open in new window


createErrorResponse

createErrorResponse(instanceId, originalEBMessage, statusCode?, error?): 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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }, "instanceId">>

Creates a error response object based on original command Toggles sender and receiver

Parameters

NameTypeDefault value
instanceIdstringundefined
originalEBMessageReadonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: unknown ; payload: unknown } ; principalId?: string ; receiver: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>undefined
statusCodeStatusCodeStatusCode.InternalServerError
error?unknownundefined

Returns

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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }, "instanceId">>

CommandErrorResponse message object

Defined in

core/helper/createErrorResponse.impl.ts:18open in new window


createInfoMessage

createInfoMessage(messageType, sender, additional?): InfoMessage

Parameters

NameTypeDescription
messageTypeInfoMessageType-
senderObject-
sender.instanceIdstringinstance id of eventbridge
sender.serviceNamestringthe name of the service
sender.serviceTargetstringthe name of the command or subscription
sender.serviceVersionstringthe version of the service
additional?Partial<InfoMessage>-

Returns

InfoMessage

Defined in

core/helper/createInfoMessage.impl.ts:14open in new window


createSuccessResponse

createSuccessResponse<T>(instanceId, originalEBMessage, payload, eventName?, contentType?, contentEncoding?): Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: T ; principalId?: string ; receiver: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Type parameters

Name
T

Parameters

NameTypeDefault value
instanceIdstringundefined
originalEBMessageReadonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: unknown ; payload: unknown } ; principalId?: string ; receiver: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>undefined
payloadTundefined
eventName?stringundefined
contentTypestring'application/json'
contentEncodingstring'utf-8'

Returns

Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: T ; principalId?: string ; receiver: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Defined in

core/helper/createSuccessResponse.impl.ts:15open in new window


deserializeOtp

deserializeOtp(logger, otp?): undefined | Context

Parameters

NameType
loggerLogger
otp?string

Returns

undefined | Context

Defined in

core/helper/serializeOtp.impl.ts:26open in new window


getCleanedMessage

getCleanedMessage(message, stripeOutContent?): Record<string, unknown>

Helper function for logging. Returns a message object, where fields which might contain sensitive data, are overwritten with string values. For command messages, parameter and payload are overwritten with string values.

For command success responses, the response field is overwritten.

Command error responses are not changed.

Parameters

NameTypeDefault value
messageReadonly<EBMessage>undefined
stripeOutContentboolean!isDevelop()

Returns

Record<string, unknown>

Defined in

core/helper/getCleanedMessage.impl.ts:15open in new window


getErrorMessageForCode

getErrorMessageForCode(code): string

Parameters

NameType
codeStatusCode

Returns

string

Defined in

core/helper/getErrorMessageForCode.impl.ts:10open in new window


getNewCorrelationId

getNewCorrelationId(): string

Create a new unique event bridge correlation id

Returns

string

EBMessageId

Defined in

core/helper/getNewCorrelationId.impl.ts:10open in new window


getNewEBMessageId

getNewEBMessageId(): string

Create a new unique event bridge message id

Returns

string

EBMessageId

Defined in

core/helper/getNewEBMessageId.impl.ts:11open in new window


getNewInstanceId

getNewInstanceId(): string

Returns

string

Defined in

core/helper/getNewInstanceId.impl.ts:9open in new window


getNewTraceId

getNewTraceId(): string

Returns

string

Defined in

core/helper/getNewTraceId.impl.ts:9open in new window


getSubscriptionQueueName

getSubscriptionQueueName(address): string

Parameters

NameType
addressEBMessageAddress

Returns

string

Defined in

core/helper/getSubscriptionQueueName.impl.ts:10open in new window


getUniqueId

getUniqueId(): string

Returns

string

Defined in

core/helper/getUniqueId.impl.ts:11open in new window


gracefulShutdown

gracefulShutdown(logger, list, timeoutMs?): void

Helps to gracefully shut down your application. Provide in list objects. The objects contains a name and a promise function which should be executed.

The execution of array list functions is done sequential.

Parameters

NameTypeDefault valueDescription
loggerLoggerundefinedthe logger object
listShutdownEntry[]undefineda object containing name and function
timeoutMsnumber30000in ms to shut

Returns

void

Example

const shutDownList = [
 {
   name: `${serviceA.info.serviceName} version ${serviceA.info.serviceVersion}`,
   fn: serviceA.destroy
 },
 {
   name: `${serviceB.info.serviceName} version ${serviceB.info.serviceVersion}`,
   fn: serviceB.destroy
 },
{
   name: eventbridge.name,
   fn: eventbridge.destroy
 }
]
gracefulShutdown(logger, shutDownList)

// will shutdown ServiceA, then ServiceB, then the event bridge

Default

30000 milliseconds

Defined in

helper/gracefulShutdown.impl.ts:36open in new window


isDevelop

isDevelop(): boolean

returns true if NODE_ENV is set to value starting with "develop"

Returns

boolean

Defined in

core/helper/isDevelop.impl.ts:6open in new window


serializeOtp

serializeOtp(): string

Returns

string

Defined in

core/helper/serializeOtp.impl.ts:11open in new window

Service

ServiceEventsNames: Object

Events which can be emitted by a service. Internal events are prefixed with service-

Defined in

core/types/ServiceEvents.ts:11open in new window

Service<ConfigType>: Object

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()
  }
}

Type parameters

NameType
ConfigTypeunknown | undefined

Defined in

core/Service/Service.impl.ts:76open in new window

ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>: Object

This class is used to build a service. The ServiceBuilder class is used to build a service. It has a few methods that are used to add command definitions and subscription definitions to the service. It also has a method that is used to create an instance of the service class.

Type parameters

NameType
ConfigTypeRecord<string, unknown>
ConfigInputTypeRecord<string, unknown>
ServiceClassTypeextends ServiceClass = Service<ConfigType>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:38open in new window

ServiceClass<ConfigType>: Object

The ServiceClass interface

Type parameters

NameType
ConfigTypeunknown | undefined

Defined in

core/types/ServiceClass.ts:11open in new window

ServiceConstructorInput

Ƭ ServiceConstructorInput<ConfigType>: Object

Type parameters

Name
ConfigType

Type declaration

NameTypeDescription
commandDefinitionListCommandDefinitionList<any>The list of command definitions for this service
configConfigTypeThe service specific config
configStore?ConfigStoreThe config store instance
eventBridgeEventBridgeThe eventBridge instance
infoServiceInfoTypeThe service info with name, version and description of service
loggerLoggerA logger instance
secretStore?SecretStoreThe secret store instance
spanProcessor?SpanProcessorThe opentelemetry span processor instance
stateStore?StateStorethe state store instance
subscriptionDefinitionListSubscriptionDefinitionList<any>The list of subscription definitions for this service

Defined in

core/types/ServiceConstructorInput.ts:15open in new window


ServiceEventsInternal

Ƭ ServiceEventsInternal: Object

Events which can be emitted by a service. Internal events are prefixed with service-.

Response messages, which have an event name assigned, are prefixed with custom- If you like to use your own events, the event name must be prefixed with misc-.

Type declaration

NameTypeDescription
service-availableundefinedemitted when the service is fully initialized and ready Should be emitted by custom service class. It is not emitted by default
service-drainundefinedemitted when the service is going to be stopped
service-handled-command-error{ commandName: string ; error: HandledError ; traceId: TraceId }emitted when a command throws a HandledError
service-handled-command-error.commandNamestring-
service-handled-command-error.errorHandledError-
service-handled-command-error.traceIdTraceId-
service-handled-subscription-error{ error: HandledError ; subscriptionName: string ; traceId: TraceId }emitted when a subscription throws a HandledError
service-handled-subscription-error.errorHandledError-
service-handled-subscription-error.subscriptionNamestring-
service-handled-subscription-error.traceIdTraceId-
service-not-availableundefined | unknownemitted when the service is not available (for example database connection could not be established)
service-startedundefinedemitted when the service is started, but not fully initialized and not ready yet
service-stoppedundefinedemitted when the service has been stopped
service-unhandled-command-error{ commandName: string ; error: unknown ; traceId: TraceId }emitted when a command throws an error other than a HandledError
service-unhandled-command-error.commandNamestring-
service-unhandled-command-error.errorunknown-
service-unhandled-command-error.traceIdTraceId-
service-unhandled-subscription-error{ error: unknown ; subscriptionName: string ; traceId: TraceId }emitted when a subscription throws an error other than a HandledError
service-unhandled-subscription-error.errorunknown-
service-unhandled-subscription-error.subscriptionNamestring-
service-unhandled-subscription-error.traceIdTraceId-

Defined in

core/types/ServiceEvents.ts:54open in new window

Store

ConfigStoreBaseClass<ConfigType>: Object

Base class for config store adapters

Type parameters

NameType
ConfigTypeextends Record<string, unknown> = {}

Defined in

core/ConfigStore/ConfigStoreBaseClass.impl.ts:11open in new window

DefaultConfigStore: Object

The DefaultConfigStore is a placeholder which offers all needed methods. Getters and setters will throw a UnhandledError with status Unauthorized, when a disabled operation is called.

For development and testing purpose, you can initiate the store with values.

Example

const store = new DefaultConfigStore({
   enableGet: true,
   enableRemove: true,
   enableSet: true,
   config: {
     initialValue: 'initial',
   },
})

console.log(await store.getConfig('initialValue') // outputs: { initialValue: 'initial' }

Defined in

DefaultConfigStore/DefaultConfigStore.impl.ts:25open in new window

DefaultSecretStore: Object

The DefaultSecretStore is a placeholder which offers all needed methods. Getters and setters will throw a UnhandledError with status Unauthorized, when a disabled operation is called.

For development and testing purpose, you can initiate the store with values.

Example

const store = new DefaultSecretStore({
 config: {
   secretOne: 'my_secret_one_value',
   secretTwo: 'my_secret_two_value',
 }
})
console.log(await store.getSecret('secretOne', 'secretTwo) // outputs: { secretOne: my_secret_one_value, secretTwo: 'my_secret_two_value' }

Per default, setting/changing and removal of values are disabled. You can enable it on instance creation:

Example

const store = new DefaultSecretStore({
 enableGet: true,
 enableRemove: true,
 enableSet: true,
})

Defined in

DefaultSecretStore/DefaultSecretStore.impl.ts:33open in new window

DefaultStateStore: Object

The DefaultStateStore is a placeholder which offers all needed methods. Getters and setters will throw a UnhandledError with status Not implemented

Defined in

DefaultStateStore/DefaultStateStore.impl.ts:11open in new window

SecretStoreBaseClass<ConfigType>: Object

Base class for secret store adapters

Type parameters

NameType
ConfigTypeextends Record<string, unknown> = {}

Defined in

core/SecretStore/SecretStoreBaseClass.impl.ts:11open in new window

StateStoreBaseClass<ConfigType>: Object

Base class for config store implementations

Type parameters

NameType
ConfigTypeextends Record<string, unknown> = {}

Defined in

core/StateStore/StateStoreBaseClass.impl.ts:11open in new window

ConfigStore: Object

Interface definition for config store adapters

Defined in

core/ConfigStore/types/ConfigStore.ts:10open in new window

SecretStore: Object

Interface definition for a secret store implementation

Defined in

core/SecretStore/types/SecretStore.ts:9open in new window

StateStore: Object

Interface definition for state store implementations

Defined in

core/StateStore/types/StateStore.ts:10open in new window

ConfigDeleteFunction

Ƭ ConfigDeleteFunction: (configName: string) => Promise<void>

Type declaration

▸ (configName): Promise<void>

delete a config value from the config store

Parameters
NameType
configNamestring
Returns

Promise<void>

Defined in

core/ConfigStore/types/ConfigDeleteFunction.ts:2open in new window


ConfigGetterFunction

Ƭ ConfigGetterFunction: (...configNames: string[]) => Promise<Record<string, unknown | undefined>>

Type declaration

▸ (...configNames): Promise<Record<string, unknown | undefined>>

get a config value from the config store

Parameters
NameType
...configNamesstring[]
Returns

Promise<Record<string, unknown | undefined>>

Defined in

core/ConfigStore/types/ConfigGetterFunction.ts:2open in new window


ConfigSetterFunction

Ƭ ConfigSetterFunction: (secretName: string, secretValue: unknown) => Promise<void>

Type declaration

▸ (secretName, secretValue): Promise<void>

set a config value in the config store

Parameters
NameType
secretNamestring
secretValueunknown
Returns

Promise<void>

Defined in

core/ConfigStore/types/ConfigSetterFunction.ts:2open in new window


SecretDeleteFunction

Ƭ SecretDeleteFunction: (secretName: string) => Promise<void>

Type declaration

▸ (secretName): Promise<void>

delete a secret from the secret store

Parameters
NameType
secretNamestring
Returns

Promise<void>

Defined in

core/SecretStore/types/SecretDeleteFunction.ts:2open in new window


SecretGetterFunction

Ƭ SecretGetterFunction: (...secretName: string[]) => Promise<Record<string, string | undefined>>

Type declaration

▸ (...secretName): Promise<Record<string, string | undefined>>

get a secret from the secret store

Parameters
NameType
...secretNamestring[]
Returns

Promise<Record<string, string | undefined>>

Defined in

core/SecretStore/types/SecretGetterFunction.ts:2open in new window


SecretSetterFunction

Ƭ SecretSetterFunction: (secretName: string, secretValue: string) => Promise<void>

Type declaration

▸ (secretName, secretValue): Promise<void>

set a secret in the secret store

Parameters
NameType
secretNamestring
secretValuestring
Returns

Promise<void>

Defined in

core/SecretStore/types/SecretSetterFunction.ts:2open in new window


StateDeleteFunction

Ƭ StateDeleteFunction: (stateName: string) => Promise<void>

Type declaration

▸ (stateName): Promise<void>

delete a state value from the state store

Parameters
NameType
stateNamestring
Returns

Promise<void>

Defined in

core/StateStore/types/StateDeleteFunction.ts:2open in new window


StateGetterFunction

Ƭ StateGetterFunction: (...stateNames: string[]) => Promise<Record<string, unknown | undefined>>

Type declaration

▸ (...stateNames): Promise<Record<string, unknown | undefined>>

get a state value from the state store

Parameters
NameType
...stateNamesstring[]
Returns

Promise<Record<string, unknown | undefined>>

Defined in

core/StateStore/types/StateGetterFunction.ts:2open in new window


StateSetterFunction

Ƭ StateSetterFunction: (secretName: string, secretValue: unknown) => Promise<void>

Type declaration

▸ (secretName, secretValue): Promise<void>

set a state value in the state store

Parameters
NameType
secretNamestring
secretValueunknown
Returns

Promise<void>

Defined in

core/StateStore/types/StateSetterFunction.ts:2open in new window

Subscription

SubscriptionDefinitionBuilder<ServiceClassType, MessagePayloadType, MessageParamsType, MessageResultType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: Object

Subscription definition builder is a helper to create and define a subscriptions for a service. It helps to set all needed filters.

A working schema definition needs at least a subscription name, a short description and the subscription implementation.

Type parameters

NameType
ServiceClassTypeextends ServiceClass = ServiceClass
MessagePayloadTypeunknown
MessageParamsTypeundefined
MessageResultTypevoid
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeMessageResultType | void | undefined

Defined in

SubscriptionDefinitionBuilder/SubscriptionDefinitionBuilder.impl.ts:31open in new window

Subscription

Ƭ Subscription<PayloadType, ParameterType>: Object

A subscription managed by the event bridge

Type parameters

NameType
PayloadTypeunknown
ParameterTypeunknown

Type declaration

NameTypeDescription
emitEventName?stringthe event name to be used for custom message if the subscriptions returns a result
eventBridgeConfigDefinitionEventBridgeConfigconfig information for event bridge
eventName?stringthe event name to subscribe for
messageType?EBMessageTypethe message type
payload?{ parameter?: ParameterType ; payload?: PayloadType }the message payload
payload.parameter?ParameterType-
payload.payload?PayloadType-
principalId?PrincipalIdthe principal id
receiver?{ instanceId?: InstanceId ; serviceName?: string ; serviceTarget?: string ; serviceVersion?: string }the consumer address of the message
receiver.instanceId?InstanceId-
receiver.serviceName?string-
receiver.serviceTarget?string-
receiver.serviceVersion?string-
sender?{ instanceId?: InstanceId ; serviceName?: string ; serviceTarget?: string ; serviceVersion?: string }the producer address of the message
sender.instanceId?InstanceId-
sender.serviceName?string-
sender.serviceTarget?string-
sender.serviceVersion?string-
subscriberEBMessageAddressthe address of the subscription (service name, version and subscription name)
tenantId?TenantIdthe tenant id

Defined in

core/types/subscription/Subscription.ts:13open in new window


SubscriptionAfterGuardHook

Ƭ SubscriptionAfterGuardHook<ServiceClassType, FunctionResultType, FunctionPayloadOutputType, FunctionParameterType>: (this: ServiceClassType, context: SubscriptionFunctionContext, result: Readonly<FunctionResultType>, payload: Readonly<FunctionPayloadOutputType>, parameter: Readonly<FunctionParameterType>) => Promise<void>

Type parameters

NameType
ServiceClassTypeServiceClass
FunctionResultTypeunknown
FunctionPayloadOutputTypeunknown
FunctionParameterTypeunknown

Type declaration

▸ (this, context, result, payload, parameter): Promise<void>

Definition of after guard hook functions. This guard is called after function successfully returns and after output validation.

Parameters
NameType
thisServiceClassType
contextSubscriptionFunctionContext
resultReadonly<FunctionResultType>
payloadReadonly<FunctionPayloadOutputType>
parameterReadonly<FunctionParameterType>
Returns

Promise<void>

Defined in

core/types/subscription/SubscriptionAfterGuardHook.ts:10open in new window


SubscriptionBeforeGuardHook

Ƭ SubscriptionBeforeGuardHook<ServiceClassType, FunctionPayloadType, FunctionParamsType>: (this: ServiceClassType, context: SubscriptionFunctionContext, payload: Readonly<FunctionPayloadType>, parameter: Readonly<FunctionParamsType>) => Promise<void>

Type parameters

NameType
ServiceClassTypeServiceClass
FunctionPayloadTypeunknown
FunctionParamsTypeunknown

Type declaration

▸ (this, context, payload, parameter): Promise<void>

Guard is called after command function input validation and before executing the command function. The guard is usefull to separate for example auth checks from business logic. It should throw HandledError or return void.

Parameters
NameType
thisServiceClassType
contextSubscriptionFunctionContext
payloadReadonly<FunctionPayloadType>
parameterReadonly<FunctionParamsType>
Returns

Promise<void>

Defined in

core/types/subscription/SubscriptionBeforeGuardHook.ts:11open in new window


SubscriptionDefinition

Ƭ SubscriptionDefinition<ServiceClassType, MetadataType, MessagePayloadType, MessageParamsType, MessageResultType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: Object

The definition for a subscription provided by some service.

Type parameters

NameType
ServiceClassTypeextends ServiceClass = ServiceClass
MetadataTypeSubscriptionDefinitionMetadataBase
MessagePayloadTypeunknown
MessageParamsTypeunknown
MessageResultTypeunknown
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeMessageResultType

Type declaration

NameTypeDescription
callSubscriptionFunction<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType, FunctionResultType>the subscription function
emitEventName?stringevent name to be used for custom message if the subscription functions returns value
eventBridgeConfigDefinitionEventBridgeConfigconfig information for event bridge
eventName?stringfilter forevent name
hooks{ afterGuard?: Record<string, SubscriptionAfterGuardHook<ServiceClassType, FunctionResultType, FunctionPayloadType, FunctionParamsType>> ; beforeGuard?: Record<string, SubscriptionBeforeGuardHook<ServiceClassType, FunctionPayloadType, FunctionParamsType>> ; transformInput?: { transformFunction: SubscriptionTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType> ; transformInputSchema: z.ZodType ; transformParameterSchema: z.ZodType } ; transformOutput?: { transformFunction: SubscriptionTransformOutputHook<ServiceClassType, FunctionResultType, FunctionParamsType, any> ; transformOutputSchema: z.ZodType } }hooks of subscription
hooks.afterGuard?Record<string, SubscriptionAfterGuardHook<ServiceClassType, FunctionResultType, FunctionPayloadType, FunctionParamsType>>-
hooks.beforeGuard?Record<string, SubscriptionBeforeGuardHook<ServiceClassType, FunctionPayloadType, FunctionParamsType>>-
hooks.transformInput?{ transformFunction: SubscriptionTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType> ; transformInputSchema: z.ZodType ; transformParameterSchema: z.ZodType }-
hooks.transformInput.transformFunctionSubscriptionTransformInputHook<ServiceClassType, MessagePayloadType, MessageParamsType>-
hooks.transformInput.transformInputSchemaz.ZodType-
hooks.transformInput.transformParameterSchemaz.ZodType-
hooks.transformOutput?{ transformFunction: SubscriptionTransformOutputHook<ServiceClassType, FunctionResultType, FunctionParamsType, any> ; transformOutputSchema: z.ZodType }-
hooks.transformOutput.transformFunctionSubscriptionTransformOutputHook<ServiceClassType, FunctionResultType, FunctionParamsType, any>-
hooks.transformOutput.transformOutputSchemaz.ZodType-
messageType?EBMessageTypefilter for message type
metadataMetadataTypethe metadata of the subscription
principalId?PrincipalIdfilter for principal id
receiver?{ instanceId?: InstanceId ; serviceName?: string ; serviceTarget?: string ; serviceVersion?: string }filter for messages consumed by given receiver
receiver.instanceId?InstanceId-
receiver.serviceName?string-
receiver.serviceTarget?string-
receiver.serviceVersion?string-
sender?{ instanceId?: InstanceId ; serviceName?: string ; serviceTarget?: string ; serviceVersion?: string }filter for messages produced by given sender
sender.instanceId?InstanceId-
sender.serviceName?string-
sender.serviceTarget?string-
sender.serviceVersion?string-
subscriptionDescriptionstringthe description of the subscription
subscriptionNamestringthe name of the subscription
tenantId?TenantIdfilter for tenant id

Defined in

core/types/subscription/SubscriptionDefinition.ts:21open in new window


SubscriptionFunction

Ƭ SubscriptionFunction<ServiceClassType, MessagePayloadType, MessageParamsType, FunctionPayloadType, FunctionParamsType, FunctionResultType>: (this: ServiceClassType, context: SubscriptionFunctionContext, payload: Readonly<FunctionPayloadType>, parameter: Readonly<FunctionParamsType>) => Promise<FunctionResultType>

Type parameters

NameType
ServiceClassTypeextends ServiceClass
MessagePayloadTypeunknown
MessageParamsTypeundefined
FunctionPayloadTypeMessagePayloadType
FunctionParamsTypeMessageParamsType
FunctionResultTypeundefined

Type declaration

▸ (this, context, payload, parameter): Promise<FunctionResultType>

CommandFunction is a function which will be triggered when a matching event bridge message is received by the service

Parameters
NameType
thisServiceClassType
contextSubscriptionFunctionContext
payloadReadonly<FunctionPayloadType>
parameterReadonly<FunctionParamsType>
Returns

Promise<FunctionResultType>

Defined in

core/types/subscription/SubscriptionFunction.ts:8open in new window


SubscriptionFunctionContext

Ƭ SubscriptionFunctionContext: Prettify<ContextBase & SubscriptionFunctionContextEnhancements>

The subscription function context which will be passed into subscription function.

Defined in

core/types/subscription/SubscriptionFunctionContext.ts:47open in new window


SubscriptionFunctionContextEnhancements

Ƭ SubscriptionFunctionContextEnhancements: Object

It provides the original command message. Also, the methods:

  • emit which allows to emit custom events to the event bridge
  • invoke which allows to call other commands

Type declaration

NameTypeDescription
emitEmitCustomMessageFunctionemit a custom message
invokeInvokeFunctionInvokes a command and returns the result. It is recommended to validate the result against a schema which only contains the data you actually need. Example typescript const address: EBMessageAddress = { serviceName: 'name-of-service-to-invoke', serviceVersion: '1', serviceTarget: 'command-name-to-invoke', } const inputPayload = { my: 'input' } const inputParameter = { search: 'for_me' } const result = await invoke<MyResultType>(address, inputPayload inputParameter )
messageReadonly<EBMessage>the original message

Defined in

core/types/subscription/SubscriptionFunctionContext.ts:16open in new window


SubscriptionTransformFunctionContext

Ƭ SubscriptionTransformFunctionContext: Prettify<ContextBase & { message: Readonly<EBMessage> }>

Defined in

core/types/subscription/SubscriptionTransformFunctionContext.ts:8open in new window


SubscriptionTransformInputHook

Ƭ SubscriptionTransformInputHook<ServiceClassType, PayloadOutput, ParamsOutput, PayloadInput, ParamsInput>: (this: ServiceClassType, context: SubscriptionTransformFunctionContext, payload: Readonly<PayloadInput>, parameter: Readonly<ParamsInput>) => Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

Type parameters

NameType
ServiceClassTypeServiceClassType
PayloadOutputunknown
ParamsOutputunknown
PayloadInputunknown
ParamsInputunknown

Type declaration

▸ (this, context, payload, parameter): Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

Parameters
NameType
thisServiceClassType
contextSubscriptionTransformFunctionContext
payloadReadonly<PayloadInput>
parameterReadonly<ParamsInput>
Returns

Promise<{ parameter: Readonly<ParamsOutput> ; payload: Readonly<PayloadOutput> }>

Defined in

core/types/subscription/SubscriptionTransformInputHook.ts:6open in new window


SubscriptionTransformOutputHook

Ƭ SubscriptionTransformOutputHook<ServiceClassType, MessageResultType, MessageParamsType, ResponseOutput>: (this: ServiceClassType, context: SubscriptionTransformFunctionContext, payload: Readonly<MessageResultType>, parameter: Readonly<MessageParamsType>) => Promise<ResponseOutput>

Type parameters

NameType
ServiceClassTypeServiceClassType
MessageResultTypeunknown
MessageParamsTypeunknown
ResponseOutputunknown

Type declaration

▸ (this, context, payload, parameter): Promise<ResponseOutput>

This transform hook is executed after function output validation and AfterGuardHooks.

Parameters
NameType
thisServiceClassType
contextSubscriptionTransformFunctionContext
payloadReadonly<MessageResultType>
parameterReadonly<MessageParamsType>
Returns

Promise<ResponseOutput>

Defined in

core/types/subscription/SubscriptionTransformOutputHook.ts:8open in new window

Unit test helper

getCommandContextMock

getCommandContextMock<MessagePayloadType, MessageParamsType>(payload, parameter, sandbox?): Object

A function that returns a mock object for command function context

Type parameters

NameType
MessagePayloadTypeunknown
MessageParamsTypeunknown

Parameters

NameType
payloadMessagePayloadType
parameterMessageParamsType
sandbox?SinonSandbox

Returns

Object

NameType
mock{ configs: { getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction } ; emit: EmitCustomMessageFunction ; invoke: InvokeFunction ; logger: Logger ; message: Readonly<{ messageType: EBMessageType.Command; correlationId: string; receiver: EBMessageAddress; payload: { parameter: MessageParamsType; payload: MessagePayloadType; }; ... 9 more ...; sender: { ...; }; }> ; secrets: { getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction } ; startActiveSpan: <F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F> ; states: { getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction } ; wrapInSpan: <F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F> }
mock.configs{ getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction }
mock.configs.getConfigConfigGetterFunction
mock.configs.removeConfigConfigDeleteFunction
mock.configs.setConfigConfigSetterFunction
mock.emitEmitCustomMessageFunction
mock.invokeInvokeFunction
mock.loggerLogger
mock.messageReadonly<{ messageType: EBMessageType.Command; correlationId: string; receiver: EBMessageAddress; payload: { parameter: MessageParamsType; payload: MessagePayloadType; }; ... 9 more ...; sender: { ...; }; }>
mock.secrets{ getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction }
mock.secrets.getSecretSecretGetterFunction
mock.secrets.removeSecretSecretDeleteFunction
mock.secrets.setSecretSecretSetterFunction
mock.startActiveSpan<F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F>
mock.states{ getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction }
mock.states.getStateStateGetterFunction
mock.states.removeStateStateDeleteFunction
mock.states.setStateStateSetterFunction
mock.wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F>
stubs{ emit: SinonStub<any[], any> ; getConfig: SinonStub<any[], any> ; getSecret: SinonStub<any[], any> ; getState: SinonStub<any[], any> ; invoke: SinonStub<any[], any> ; logger: { debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> } = logger.stubs; removeConfig: SinonStub<any[], any> ; removeSecret: SinonStub<any[], any> ; removeState: SinonStub<any[], any> ; setConfig: SinonStub<any[], any> ; setSecret: SinonStub<any[], any> ; setState: SinonStub<any[], any> ; startActiveSpan: SinonStub<any[], any> ; wrapInSpan: SinonStub<any[], any> }
stubs.emitSinonStub<any[], any>
stubs.getConfigSinonStub<any[], any>
stubs.getSecretSinonStub<any[], any>
stubs.getStateSinonStub<any[], any>
stubs.invokeSinonStub<any[], any>
stubs.logger{ debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> }
stubs.logger.debugSinonStub<any[], any>
stubs.logger.errorSinonStub<any[], any>
stubs.logger.fatalSinonStub<any[], any>
stubs.logger.infoSinonStub<any[], any>
stubs.logger.traceSinonStub<any[], any>
stubs.logger.warnSinonStub<any[], any>
stubs.removeConfigSinonStub<any[], any>
stubs.removeSecretSinonStub<any[], any>
stubs.removeStateSinonStub<any[], any>
stubs.setConfigSinonStub<any[], any>
stubs.setSecretSinonStub<any[], any>
stubs.setStateSinonStub<any[], any>
stubs.startActiveSpanSinonStub<any[], any>
stubs.wrapInSpanSinonStub<any[], any>

Defined in

mocks/getCommandContext.mock.ts:12open in new window


getCommandErrorMessageMock

getCommandErrorMessageMock(error?, input?, commandMessage?): Readonly<{ 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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

A function that returns a mocked command error response message

Parameters

NameTypeDescription
error?HandledError | UnhandledError-
input?Partial<{ 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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>-
commandMessage?Object-
commandMessage.contentEncodingstringcontent encoding of message payload
commandMessage.contentTypestringcontent type of message payload
commandMessage.correlationIdstringcorrelation id to know which command response referrs to which command
commandMessage.eventName?stringevent name for this message
commandMessage.idstringglobal unique id of message
commandMessage.messageTypeCommand-
commandMessage.otp?stringstringified Opentelemetry parent trace id
commandMessage.payloadObject-
commandMessage.payload.parameterunknown-
commandMessage.payload.payloadunknown-
commandMessage.principalId?stringprincipal id
commandMessage.receiverEBMessageAddress-
commandMessage.sender{ serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; }-
commandMessage.tenantId?stringprincipal id
commandMessage.timestampnumbertimestamp of message creation time
commandMessage.traceId?stringtrace id of message

Returns

Readonly<{ 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: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Defined in

mocks/messages/getCommandErrorMessage.mock.ts:16open in new window


getCommandMessageMock

getCommandMessageMock<Payload, Parameter>(input?): Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: Parameter ; payload: Payload } ; principalId?: string ; receiver: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

A function that returns a mocked command message.

Type parameters

NameType
Payloadunknown
Parameterunknown

Parameters

NameType
input?Partial<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: Parameter ; payload: Payload } ; principalId?: string ; receiver: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }> & { payload?: { parameter?: Parameter ; payload?: Payload } }

Returns

Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: Parameter ; payload: Payload } ; principalId?: string ; receiver: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Defined in

mocks/messages/getCommandMessage.mock.ts:15open in new window


getCommandSuccessMessageMock

getCommandSuccessMessageMock<PayloadType>(payload, input?, commandMessage?): Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: PayloadType ; principalId?: string ; receiver: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

A function that returns a mocked command success response message.

Type parameters

Name
PayloadType

Parameters

NameTypeDescription
payloadPayloadType-
input?Partial<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: PayloadType ; principalId?: string ; receiver: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>-
commandMessage?Object-
commandMessage.contentEncodingstringcontent encoding of message payload
commandMessage.contentTypestringcontent type of message payload
commandMessage.correlationIdstringcorrelation id to know which command response referrs to which command
commandMessage.eventName?stringevent name for this message
commandMessage.idstringglobal unique id of message
commandMessage.messageTypeCommand-
commandMessage.otp?stringstringified Opentelemetry parent trace id
commandMessage.payloadObject-
commandMessage.payload.parameterunknown-
commandMessage.payload.payloadunknown-
commandMessage.principalId?stringprincipal id
commandMessage.receiverEBMessageAddress-
commandMessage.sender{ serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; }-
commandMessage.tenantId?stringprincipal id
commandMessage.timestampnumbertimestamp of message creation time
commandMessage.traceId?stringtrace id of message

Returns

Readonly<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: PayloadType ; principalId?: string ; receiver: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Defined in

mocks/messages/getCommandSuccessMessage.mock.ts:9open in new window


getCommandTransformContextMock

getCommandTransformContextMock<MessagePayloadType, MessageParamsType>(payload, parameter, sandbox?): Object

A function that returns a mock object for command transform function context

Type parameters

NameType
MessagePayloadTypeunknown
MessageParamsTypeunknown

Parameters

NameType
payloadMessagePayloadType
parameterMessageParamsType
sandbox?SinonSandbox

Returns

Object

NameType
mock{ configs: { getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction } ; logger: Logger ; message: Readonly<{ messageType: EBMessageType.Command; correlationId: string; receiver: EBMessageAddress; payload: { parameter: MessageParamsType; payload: MessagePayloadType; }; ... 9 more ...; sender: { ...; }; }> ; secrets: { getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction } ; startActiveSpan: <F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F> ; states: { getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction } ; wrapInSpan: <F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F> }
mock.configs{ getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction }
mock.configs.getConfigConfigGetterFunction
mock.configs.removeConfigConfigDeleteFunction
mock.configs.setConfigConfigSetterFunction
mock.loggerLogger
mock.messageReadonly<{ messageType: EBMessageType.Command; correlationId: string; receiver: EBMessageAddress; payload: { parameter: MessageParamsType; payload: MessagePayloadType; }; ... 9 more ...; sender: { ...; }; }>
mock.secrets{ getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction }
mock.secrets.getSecretSecretGetterFunction
mock.secrets.removeSecretSecretDeleteFunction
mock.secrets.setSecretSecretSetterFunction
mock.startActiveSpan<F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F>
mock.states{ getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction }
mock.states.getStateStateGetterFunction
mock.states.removeStateStateDeleteFunction
mock.states.setStateStateSetterFunction
mock.wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F>
stubs{ getConfig: SinonStub<any[], any> ; getSecret: SinonStub<any[], any> ; getState: SinonStub<any[], any> ; logger: { debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> } = logger.stubs; removeConfig: SinonStub<any[], any> ; removeSecret: SinonStub<any[], any> ; removeState: SinonStub<any[], any> ; setConfig: SinonStub<any[], any> ; setSecret: SinonStub<any[], any> ; setState: SinonStub<any[], any> ; startActiveSpan: SinonStub<any[], any> ; wrapInSpan: SinonStub<any[], any> }
stubs.getConfigSinonStub<any[], any>
stubs.getSecretSinonStub<any[], any>
stubs.getStateSinonStub<any[], any>
stubs.logger{ debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> }
stubs.logger.debugSinonStub<any[], any>
stubs.logger.errorSinonStub<any[], any>
stubs.logger.fatalSinonStub<any[], any>
stubs.logger.infoSinonStub<any[], any>
stubs.logger.traceSinonStub<any[], any>
stubs.logger.warnSinonStub<any[], any>
stubs.removeConfigSinonStub<any[], any>
stubs.removeSecretSinonStub<any[], any>
stubs.removeStateSinonStub<any[], any>
stubs.setConfigSinonStub<any[], any>
stubs.setSecretSinonStub<any[], any>
stubs.setStateSinonStub<any[], any>
stubs.startActiveSpanSinonStub<any[], any>
stubs.wrapInSpanSinonStub<any[], any>

Defined in

mocks/getCommandTransformContext.mock.ts:12open in new window


getCustomMessageMessageMock

getCustomMessageMessageMock<PayloadType>(eventName, payload, input?): Readonly<{ contentEncoding: string ; contentType: string ; correlationId?: string ; eventName: string ; id: string ; messageType: CustomMessage ; otp?: string ; payload?: PayloadType ; principalId?: string ; receiver?: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

A function that returns a mocked custom message.

Type parameters

Name
PayloadType

Parameters

NameType
eventNamestring
payloadPayloadType
input?Partial<{ contentEncoding: string ; contentType: string ; correlationId?: string ; eventName: string ; id: string ; messageType: CustomMessage ; otp?: string ; payload?: PayloadType ; principalId?: string ; receiver?: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Returns

Readonly<{ contentEncoding: string ; contentType: string ; correlationId?: string ; eventName: string ; id: string ; messageType: CustomMessage ; otp?: string ; payload?: PayloadType ; principalId?: string ; receiver?: EBMessageAddress ; sender: { serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; } ; tenantId?: string ; timestamp: number ; traceId?: string }>

Defined in

mocks/messages/getCustomMessage.mock.ts:15open in new window


getEventBridgeMock

getEventBridgeMock(sandbox?): Object

Mocks the eventBridge and stubs the methods

Parameters

NameType
sandbox?SinonSandbox

Returns

Object

EventBridge mocked

NameType
mockEventBridge
stubsRecord<string, SinonStub<any[], any>>

Defined in

mocks/getEventBridge.mock.ts:10open in new window


getLoggerMock

getLoggerMock(sandbox?): Object

Mocks the logger and methods are stubs

Parameters

NameType
sandbox?SinonSandbox

Returns

Object

logger mocked

NameType
mockLogger
stubs{ debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> }
stubs.debugSinonStub<any[], any>
stubs.errorSinonStub<any[], any>
stubs.fatalSinonStub<any[], any>
stubs.infoSinonStub<any[], any>
stubs.traceSinonStub<any[], any>
stubs.warnSinonStub<any[], any>

Defined in

mocks/getLogger.mock.ts:10open in new window


getSubscriptionContextMock

getSubscriptionContextMock(message, sandbox?): Object

A function that returns a mock object for subscription function context

Parameters

NameType
messageEBMessage
sandbox?SinonSandbox

Returns

Object

NameType
mock{ configs: { getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction } ; emit: EmitCustomMessageFunction ; invoke: InvokeFunction ; logger: Logger ; message: Readonly<EBMessage> ; secrets: { getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction } ; startActiveSpan: <F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F> ; states: { getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction } ; wrapInSpan: <F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F> }
mock.configs{ getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction }
mock.configs.getConfigConfigGetterFunction
mock.configs.removeConfigConfigDeleteFunction
mock.configs.setConfigConfigSetterFunction
mock.emitEmitCustomMessageFunction
mock.invokeInvokeFunction
mock.loggerLogger
mock.messageReadonly<EBMessage>
mock.secrets{ getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction }
mock.secrets.getSecretSecretGetterFunction
mock.secrets.removeSecretSecretDeleteFunction
mock.secrets.setSecretSecretSetterFunction
mock.startActiveSpan<F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F>
mock.states{ getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction }
mock.states.getStateStateGetterFunction
mock.states.removeStateStateDeleteFunction
mock.states.setStateStateSetterFunction
mock.wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F>
stubs{ emit: SinonStub<any[], any> ; getConfig: SinonStub<any[], any> ; getSecret: SinonStub<any[], any> ; getState: SinonStub<any[], any> ; invoke: SinonStub<any[], any> ; logger: { debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> } = logger.stubs; removeConfig: SinonStub<any[], any> ; removeSecret: SinonStub<any[], any> ; removeState: SinonStub<any[], any> ; setConfig: SinonStub<any[], any> ; setSecret: SinonStub<any[], any> ; setState: SinonStub<any[], any> ; startActiveSpan: SinonStub<any[], any> ; wrapInSpan: SinonStub<any[], any> }
stubs.emitSinonStub<any[], any>
stubs.getConfigSinonStub<any[], any>
stubs.getSecretSinonStub<any[], any>
stubs.getStateSinonStub<any[], any>
stubs.invokeSinonStub<any[], any>
stubs.logger{ debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> }
stubs.logger.debugSinonStub<any[], any>
stubs.logger.errorSinonStub<any[], any>
stubs.logger.fatalSinonStub<any[], any>
stubs.logger.infoSinonStub<any[], any>
stubs.logger.traceSinonStub<any[], any>
stubs.logger.warnSinonStub<any[], any>
stubs.removeConfigSinonStub<any[], any>
stubs.removeSecretSinonStub<any[], any>
stubs.removeStateSinonStub<any[], any>
stubs.setConfigSinonStub<any[], any>
stubs.setSecretSinonStub<any[], any>
stubs.setStateSinonStub<any[], any>
stubs.startActiveSpanSinonStub<any[], any>
stubs.wrapInSpanSinonStub<any[], any>

Defined in

mocks/getSubscriptionContext.mock.ts:11open in new window


getSubscriptionTransformContextMock

getSubscriptionTransformContextMock(message, sandbox?): Object

A function that returns a mock object for subscription transform function context

Parameters

NameType
messageEBMessage
sandbox?SinonSandbox

Returns

Object

NameType
mock{ configs: { getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction } ; logger: Logger ; message: Readonly<EBMessage> ; secrets: { getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction } ; startActiveSpan: <F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F> ; states: { getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction } ; wrapInSpan: <F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F> }
mock.configs{ getConfig: ConfigGetterFunction ; removeConfig: ConfigDeleteFunction ; setConfig: ConfigSetterFunction }
mock.configs.getConfigConfigGetterFunction
mock.configs.removeConfigConfigDeleteFunction
mock.configs.setConfigConfigSetterFunction
mock.loggerLogger
mock.messageReadonly<EBMessage>
mock.secrets{ getSecret: SecretGetterFunction ; removeSecret: SecretDeleteFunction ; setSecret: SecretSetterFunction }
mock.secrets.getSecretSecretGetterFunction
mock.secrets.removeSecretSecretDeleteFunction
mock.secrets.setSecretSecretSetterFunction
mock.startActiveSpan<F>(name: string, opts: SpanOptions, context: undefined | Context, fn: (span: Span) => Promise<F>) => Promise<F>
mock.states{ getState: StateGetterFunction ; removeState: StateDeleteFunction ; setState: StateSetterFunction }
mock.states.getStateStateGetterFunction
mock.states.removeStateStateDeleteFunction
mock.states.setStateStateSetterFunction
mock.wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context) => Promise<F>
stubs{ getConfig: SinonStub<any[], any> ; getSecret: SinonStub<any[], any> ; getState: SinonStub<any[], any> ; logger: { debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> } = logger.stubs; removeConfig: SinonStub<any[], any> ; removeSecret: SinonStub<any[], any> ; removeState: SinonStub<any[], any> ; setConfig: SinonStub<any[], any> ; setSecret: SinonStub<any[], any> ; setState: SinonStub<any[], any> ; startActiveSpan: SinonStub<any[], any> ; wrapInSpan: SinonStub<any[], any> }
stubs.getConfigSinonStub<any[], any>
stubs.getSecretSinonStub<any[], any>
stubs.getStateSinonStub<any[], any>
stubs.logger{ debug: SinonStub<any[], any> ; error: SinonStub<any[], any> ; fatal: SinonStub<any[], any> ; info: SinonStub<any[], any> ; trace: SinonStub<any[], any> ; warn: SinonStub<any[], any> }
stubs.logger.debugSinonStub<any[], any>
stubs.logger.errorSinonStub<any[], any>
stubs.logger.fatalSinonStub<any[], any>
stubs.logger.infoSinonStub<any[], any>
stubs.logger.traceSinonStub<any[], any>
stubs.logger.warnSinonStub<any[], any>
stubs.removeConfigSinonStub<any[], any>
stubs.removeSecretSinonStub<any[], any>
stubs.removeStateSinonStub<any[], any>
stubs.setConfigSinonStub<any[], any>
stubs.setSecretSinonStub<any[], any>
stubs.setStateSinonStub<any[], any>
stubs.startActiveSpanSinonStub<any[], any>
stubs.wrapInSpanSinonStub<any[], any>

Defined in

mocks/getSubscriptionTransformContext.mock.ts:11open in new window

Last update:
Contributors: Sebastian Wessel