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
Name | Type |
---|---|
ConfigType | Record <string , unknown > |
ConfigInputType | Record <string , unknown > |
ServiceClassType | extends ServiceClass = Service <ConfigType > |
Table of contents
Constructors
Properties
- SClass
- commandDefinitionList
- commandDefinitionListResolved
- configSchema
- defaultConfig
- definitionsResolved
- info
- instance
- subscriptionDefinitionList
- subscriptionDefinitionListResolved
Methods
- addCommandDefinition
- addSubscriptionDefinition
- getCommandBuilder
- getCommandDefinitions
- getCustomClass
- getInstance
- getSubscriptionBuilder
- getSubscriptionDefinitions
- resolveDefinitions
- setConfigSchema
- setCustomClass
- setDefaultConfig
- testServiceSetup
- validateCommandDefinitions
- validateCommands
- validateSubscriptionDefinitions
- validateSubscriptions
Constructors
constructor
• new ServiceBuilder<ConfigType
, ConfigInputType
, ServiceClassType
>(info
): ServiceBuilder
<ConfigType
, ConfigInputType
, ServiceClassType
>
Type parameters
Name | Type |
---|---|
ConfigType | Record <string , unknown > |
ConfigInputType | Record <string , unknown > |
ServiceClassType | extends ServiceClass <unknown > = Service <ConfigType > |
Parameters
Name | Type |
---|---|
info | ServiceInfoType |
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
Name | Type | Description |
---|---|---|
...commands | CommandDefinitionList <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
Name | Type | Description |
---|---|---|
...subscription | SubscriptionDefinitionList <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
Name | Type |
---|---|
T | extends string |
N | extends string |
Parameters
Name | Type | Description |
---|---|---|
commandName | NonEmptyString <T > | The name of the command. |
description | string | The 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
Name | Type | Description |
---|---|---|
eventBridge | EventBridge | EventBridge |
options | Object | additional 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
Name | Type |
---|---|
T | extends string |
Parameters
Name | Type | Description |
---|---|---|
subscriptionName | NonEmptyString <T > | The name of the subscription. |
description | string | The 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
Name | Type |
---|---|
T | extends Schema <any , any , any , "" > | ZodType <any , ZodTypeDef , any > |
Parameters
Name | Type | Description |
---|---|---|
schema | T | The 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
Name | Type |
---|---|
T | extends ServiceClass <ConfigType > |
Parameters
Name | Type | Description |
---|---|---|
customClass | Newable <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
Name | Type | Description |
---|---|---|
config | Complete <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
Name | Type |
---|---|
commandDefinitions | CommandDefinitionListResolved <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
Name | Type |
---|---|
subscriptionDefinitions | SubscriptionDefinitionListResolved <any > |
Returns
void