PURISTA API / @purista/core / ServiceBuilder
Class: ServiceBuilder<S>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:65
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
• S extends ServiceBuilderTypes
= ServiceBuilderTypes
Constructors
new ServiceBuilder()
new ServiceBuilder<
S
>(info
):ServiceBuilder
<S
>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:84
Parameters
info
Returns
Properties
info
info:
ServiceInfoType
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:84
SClass
SClass:
Newable
<S
["ServiceClassType"
],ServiceClassTypes
<S
["ConfigType"
],S
["Resources"
]>> =Service
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:81
Methods
addCommandDefinition()
addCommandDefinition(...
commands
):ServiceBuilder
<S
>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:134
addCommandDefinition
adds a list of command definitions to the service builder
Parameters
commands
...CommandDefinitionList
<S
["ServiceClassType"
]>
CommandDefinitionList
Returns
The service builder
addSubscriptionDefinition()
addSubscriptionDefinition(...
subscription
):ServiceBuilder
<S
>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:150
It adds a subscription definition to the service builder
Parameters
subscription
...SubscriptionDefinitionList
<S
["ServiceClassType"
]>
SubscriptionDefinitionList
Returns
The service builder
defineResource()
defineResource<
ResourceName
,ResourcesType
>():ServiceBuilder
<SetNewTypeValue
<S
,"Resources"
,S
["Resources"
] &{ [K in string]: InstanceOrType<ResourcesType> }
>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:197
Define the resources of the service. Resources are available within commands and subscriptions.
Type Parameters
• ResourceName extends string
• ResourcesType
Returns
ServiceBuilder
<SetNewTypeValue
<S
, "Resources"
, S
["Resources"
] & { [K in string]: InstanceOrType<ResourcesType> }
>>
The builder with defined types for resources
Example
serviceBuilder.defineResources<'resource_name',ResourceType>()
getCommandBuilder()
getCommandBuilder<
T
,N
>(commandName
,description
,eventName
?):CommandDefinitionBuilder
<S
["ServiceClassType"
],CommandDefinitionBuilderTypes
<SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>,S
["Resources"
],InvokeList
,Record
<string
,SchemaObject
|Schema
<any
,any
,any
,""
> |ZodType
<any
,ZodTypeDef
,any
>>>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:306
It returns a new instance of the CommandDefinitionBuilder class, which is a class that is used to build a command definition
Type Parameters
• T extends string
• N extends string
Parameters
commandName
The name of the command.
description
string
The description of the command.
eventName?
The name of the event that will be emitted when the command is executed.
Returns
CommandDefinitionBuilder
<S
["ServiceClassType"
], CommandDefinitionBuilderTypes
<SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>, S
["Resources"
], InvokeList
, Record
<string
, SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>>>>
A CommandDefinitionBuilder object.
getCommandDefinitions()
getCommandDefinitions():
CommandDefinitionListResolved
<S
["ServiceClassType"
]>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:350
Returns
CommandDefinitionListResolved
<S
["ServiceClassType"
]>
the definition of registered commands
getCustomClass()
getCustomClass():
Newable
<S
["ServiceClassType"
],ServiceClassTypes
<S
["ConfigType"
],S
["Resources"
]>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:216
Returns
Newable
<S
["ServiceClassType"
], ServiceClassTypes
<S
["ConfigType"
], S
["Resources"
]>>
getFullServiceDefintion()
getFullServiceDefintion():
Promise
<{commands
:CommandDefinitionListResolved
<S
["ServiceClassType"
]>;deprecated
:boolean
;serviceDescription
:string
;serviceName
:string
;serviceVersion
:string
;subscriptions
:SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>; }>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:415
Returns the service definition. This inclues information about commands and subscriptions.
Returns
Promise
<{ commands
: CommandDefinitionListResolved
<S
["ServiceClassType"
]>; deprecated
: boolean
; serviceDescription
: string
; serviceName
: string
; serviceVersion
: string
; subscriptions
: SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>; }>
getInstance()
getInstance(
eventBridge
,options
?):Promise
<S
["ServiceClassType"
]>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:227
It creates a new instance of the service class, passing in the logger, service info, event bridge, command functions, subscription list, and configuration
Parameters
eventBridge
EventBridge
options?
{ [K in string | number | symbol]: ({ configStore?: ConfigStore; logger?: Logger; logLevel?: LogLevelName; secretStore?: SecretStore; spanProcessor?: SpanProcessor; stateStore?: StateStore } & (keyof S["Resources"] extends NeverObject ? { resources?: undefined } : { resources: S["Resources"] }) & (keyof S["ConfigInputType"] extends NeverObject ? { serviceConfig?: undefined } : { serviceConfig: S["ConfigInputType"] }))[K] }
additional config like logger, stores and opentelemetry span processor
Returns
Promise
<S
["ServiceClassType"
]>
The instance of the service class
getSubscriptionBuilder()
getSubscriptionBuilder<
T
>(subscriptionName
,description
):SubscriptionDefinitionBuilder
<S
["ServiceClassType"
],SubscriptionDefinitionBuilderTypes
<any
,any
,any
,any
,any
,any
,S
["Resources"
]>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:334
It returns a new instance of the SubscriptionDefinitionBuilder
class, which is a class that is used to build a subscription definition
Type Parameters
• T extends string
Parameters
subscriptionName
The name of the subscription.
description
string
The description of the subscription.
Returns
SubscriptionDefinitionBuilder
<S
["ServiceClassType"
], SubscriptionDefinitionBuilderTypes
<any
, any
, any
, any
, any
, any
, S
["Resources"
]>>
A SubscriptionDefinitionBuilder
getSubscriptionDefinitions()
getSubscriptionDefinitions():
SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:363
Returns
SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>
the definition of registered subscriptions
markAsDeprecated()
markAsDeprecated():
ServiceBuilder
<S
>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:124
Mark this service as deprecated
Returns
The ServiceBuilder instance
resolveDefinitions()
resolveDefinitions():
Promise
<{commands
:CommandDefinitionListResolved
<S
["ServiceClassType"
]>;subscriptions
:SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>; }>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:165
Resolves the command and subscription definitions
Returns
Promise
<{ commands
: CommandDefinitionListResolved
<S
["ServiceClassType"
]>; subscriptions
: SubscriptionDefinitionListResolved
<S
["ServiceClassType"
]>; }>
setConfigSchema()
setConfigSchema<
T
>(schema
):ServiceBuilder
<SetNewTypeValues
<S
, {ConfigInputType
:UnknownIfNever
<InputFrom
<AdapterResolver
,T
>> extendsRecord
<string
,any
> ?Record
<string
,any
> &UnknownIfNever
<InputFrom
<AdapterResolver
,T
>> :NeverObject
;ConfigType
:UnknownIfNever
<OutputFrom
<AdapterResolver
,T
>> extendsRecord
<string
,any
> ?Record
<string
,any
> &UnknownIfNever
<OutputFrom
<AdapterResolver
,T
>> :NeverObject
;ServiceClassType
:Service
<ServiceClassTypes
<UnknownIfNever
<OutputFrom
<AdapterResolver
,T
>> extendsRecord
<string
,any
> ?Record
<string
,any
> &UnknownIfNever
<OutputFrom
<AdapterResolver
,T
>> :EmptyObject
,S
["Resources"
]>>; }>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:92
"This function sets the config schema for the service builder."
Type Parameters
• T extends SchemaObject
| Schema
<any
, any
, any
, ""
> | ZodType
<any
, ZodTypeDef
, any
>
Parameters
schema
T
The schema that will be used to validate the config.
Returns
ServiceBuilder
<SetNewTypeValues
<S
, { ConfigInputType
: UnknownIfNever
<InputFrom
<AdapterResolver
, T
>> extends Record
<string
, any
> ? Record
<string
, any
> & UnknownIfNever
<InputFrom
<AdapterResolver
, T
>> : NeverObject
; ConfigType
: UnknownIfNever
<OutputFrom
<AdapterResolver
, T
>> extends Record
<string
, any
> ? Record
<string
, any
> & UnknownIfNever
<OutputFrom
<AdapterResolver
, T
>> : NeverObject
; ServiceClassType
: Service
<ServiceClassTypes
<UnknownIfNever
<OutputFrom
<AdapterResolver
, T
>> extends Record
<string
, any
> ? Record
<string
, any
> & UnknownIfNever
<OutputFrom
<AdapterResolver
, T
>> : EmptyObject
, S
["Resources"
]>>; }>>
ServiceBuilder
setCustomClass()
setCustomClass<
T
>(customClass
):ServiceBuilder
<SetNewTypeValue
<S
,"ServiceClassType"
,T
>>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:209
It sets the class type of the service.
Type Parameters
• T extends Service
<ServiceClassTypes
<S
["ConfigType"
], S
["Resources"
]>>
Parameters
customClass
Newable
<T
, ServiceClassTypes
<S
["ConfigType"
], S
["Resources"
]>>
A class which extends the Service class
Returns
ServiceBuilder
<SetNewTypeValue
<S
, "ServiceClassType"
, T
>>
The builder itself, but with the type of the service class changed.
setDefaultConfig()
setDefaultConfig(
config
):this
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:115
"This function sets the default configuration for the service."
Parameters
config
Complete
<S
["ConfigType"
]>
ConfigType - The default configuration for the service.
Returns
this
The ServiceBuilder instance
Deprecated
Use a default value in the config validation schema instead
testServiceSetup()
testServiceSetup():
Promise
<boolean
>
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:376
A simple test helper, which ensures, that there ar no duplicate names used.
Returns
Promise
<boolean
>
validateCommandDefinitions()
validateCommandDefinitions():
void
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:440
Returns
void
Deprecated
Use testServiceSetup() instead
validateCommands()
protected
validateCommands(commandDefinitions
):void
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:385
Parameters
commandDefinitions
CommandDefinitionListResolved
<any
>
Returns
void
validateSubscriptionDefinitions()
validateSubscriptionDefinitions():
void
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:448
Returns
void
Deprecated
Use testServiceSetup() instead
validateSubscriptions()
protected
validateSubscriptions(subscriptionDefinitions
):void
Defined in: packages/core/src/ServiceBuilder/ServiceBuilder.impl.ts:425
Parameters
subscriptionDefinitions
SubscriptionDefinitionListResolved
<any
>
Returns
void