Skip to content

PURISTA API / Modules / @purista/core / ServiceBuilder

Class: ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

@purista/core.ServiceBuilder

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>

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>(info): ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

Type parameters

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

Parameters

NameType
infoServiceInfoType

Returns

ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:60

Properties

SClass

SClass: Newable<any, ConfigType> = Service

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:57


commandDefinitionList

Private commandDefinitionList: CommandDefinitionList<ServiceClassType> = []

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:45


commandDefinitionListResolved

Private commandDefinitionListResolved: CommandDefinitionListResolved<ServiceClassType> = []

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:48


configSchema

Private Optional configSchema: Schema<any, any, any, ""> | ZodType<any, ZodTypeDef, any>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:51


defaultConfig

Private Optional defaultConfig: Complete<ConfigType>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:52


definitionsResolved

Private definitionsResolved: boolean = false

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:54


info

info: ServiceInfoType

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:60


instance

Optional instance: ServiceClassType

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:56


subscriptionDefinitionList

Private subscriptionDefinitionList: SubscriptionDefinitionList<ServiceClassType> = []

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:46


subscriptionDefinitionListResolved

Private subscriptionDefinitionListResolved: SubscriptionDefinitionListResolved<ServiceClassType> = []

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:49

Methods

addCommandDefinition

addCommandDefinition(...commands): ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

addCommandDefinition adds a list of command definitions to the service builder

Parameters

NameTypeDescription
...commandsCommandDefinitionList<ServiceClassType>CommandDefinitionList

Returns

ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

The service builder

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:89


addSubscriptionDefinition

addSubscriptionDefinition(...subscription): ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

It adds a subscription definition to the service builder

Parameters

NameTypeDescription
...subscriptionSubscriptionDefinitionList<ServiceClassType>SubscriptionDefinitionList

Returns

ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

The service builder

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:105


getCommandBuilder

getCommandBuilder<T, N>(commandName, description, eventName?): CommandDefinitionBuilder<ServiceClassType, unknown, {}, void, ZodAny, ZodAny, ZodAny, {}, {}>

It returns a new instance of the CommandDefinitionBuilder class, which is a class that is used to build a command definition

Type parameters

NameType
Textends string
Nextends string

Parameters

NameTypeDescription
commandNameNonEmptyString<T>The name of the command.
descriptionstringThe description of the command.
eventName?NonEmptyString<N>The name of the event that will be emitted when the command is executed.

Returns

CommandDefinitionBuilder<ServiceClassType, unknown, {}, void, ZodAny, ZodAny, ZodAny, {}, {}>

A CommandDefinitionBuilder object.

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:233


getCommandDefinitions

getCommandDefinitions(): CommandDefinitionListResolved<ServiceClassType>

Returns

CommandDefinitionListResolved<ServiceClassType>

the definition of registered commands

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:258


getCustomClass

getCustomClass(): Newable<any, ConfigType>

Returns

Newable<any, ConfigType>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:151


getInstance

getInstance(eventBridge, options?): Promise<ServiceClassType>

It creates a new instance of the service class, passing in the logger, service info, event bridge, command functions, subscription list, and configuration

Parameters

NameTypeDescription
eventBridgeEventBridgeEventBridge
optionsObjectadditional config like logger, stores and opentelemetry span processor
options.configStore?ConfigStore-
options.logLevel?LogLevelName-
options.logger?Logger-
options.secretStore?SecretStore-
options.serviceConfig?Partial<ConfigInputType>-
options.spanProcessor?SpanProcessor-
options.stateStore?StateStore-

Returns

Promise<ServiceClassType>

The instance of the service class

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:162


getSubscriptionBuilder

getSubscriptionBuilder<T>(subscriptionName, description): SubscriptionDefinitionBuilder<ServiceClassType, unknown, undefined, void, ZodAny, ZodAny, ZodAny, {}, {}>

It returns a new instance of the SubscriptionDefinitionBuilder class, which is a class that is used to build a subscription definition

Type parameters

NameType
Textends string

Parameters

NameTypeDescription
subscriptionNameNonEmptyString<T>The name of the subscription.
descriptionstringThe description of the subscription.

Returns

SubscriptionDefinitionBuilder<ServiceClassType, unknown, undefined, void, ZodAny, ZodAny, ZodAny, {}, {}>

A SubscriptionDefinitionBuilder

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:248


getSubscriptionDefinitions

getSubscriptionDefinitions(): SubscriptionDefinitionListResolved<ServiceClassType>

Returns

SubscriptionDefinitionListResolved<ServiceClassType>

the definition of registered subscriptions

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:271


resolveDefinitions

resolveDefinitions(): Promise<{ commands: CommandDefinitionListResolved<ServiceClassType> ; subscriptions: SubscriptionDefinitionListResolved<ServiceClassType> }>

Resolves the command and subscription definitions

Returns

Promise<{ commands: CommandDefinitionListResolved<ServiceClassType> ; subscriptions: SubscriptionDefinitionListResolved<ServiceClassType> }>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:120


setConfigSchema

setConfigSchema<T>(schema): ServiceBuilder<UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? output<T> : never> : never>>, UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? input<T> : never> : never>>, Service<UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? output<T> : never> : never>>>>

"This function sets the config schema for the service builder."

Type parameters

NameType
Textends Schema<any, any, any, ""> | ZodType<any, ZodTypeDef, any>

Parameters

NameTypeDescription
schemaTThe schema that will be used to validate the config.

Returns

ServiceBuilder<UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? output<T> : never> : never>>, UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? input<T> : never> : never>>, Service<UnknownIfNever<IfDefined<T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends never ? never : never | T extends Schema<any, any, any, ""> ? IfDefined<T extends Schema<any, any, any, ""> ? InferType<T> : never> : never | T extends ZodType<any, ZodTypeDef, any> ? IfDefined<T extends ZodType<any, ZodTypeDef, any> ? output<T> : never> : never>>>>

ServiceBuilder

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:68


setCustomClass

setCustomClass<T>(customClass): ServiceBuilder<ConfigType, ConfigInputType, T>

It sets the class type of the service.

Type parameters

NameType
Textends ServiceClass<ConfigType>

Parameters

NameTypeDescription
customClassNewable<T, ConfigType>A class which extends the Service class

Returns

ServiceBuilder<ConfigType, ConfigInputType, T>

The builder itself, but with the type of the service class changed.

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:146


setDefaultConfig

setDefaultConfig(config): ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

"This function sets the default configuration for the service."

Parameters

NameTypeDescription
configComplete<ConfigType>ConfigType - The default configuration for the service.

Returns

ServiceBuilder<ConfigType, ConfigInputType, ServiceClassType>

The ServiceBuilder instance.

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:79


testServiceSetup

testServiceSetup(): Promise<boolean>

A simple test helper, which ensures, that there ar no duplicate names used.

Returns

Promise<boolean>

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:284


validateCommandDefinitions

validateCommandDefinitions(): void

Returns

void

Deprecated

Use validateServiceConfig() instead

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:332


validateCommands

validateCommands(commandDefinitions): void

Parameters

NameType
commandDefinitionsCommandDefinitionListResolved<any>

Returns

void

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:293


validateSubscriptionDefinitions

validateSubscriptionDefinitions(): void

Returns

void

Deprecated

Use validateServiceConfig() instead

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:340


validateSubscriptions

validateSubscriptions(subscriptionDefinitions): void

Parameters

NameType
subscriptionDefinitionsSubscriptionDefinitionListResolved<any>

Returns

void

Defined in

ServiceBuilder/ServiceBuilder.impl.ts:317