booster icon indicating copy to clipboard operation
booster copied to clipboard

Provide a method to access rocket configuration from other artefacts

Open gonzalogarciajaubert opened this issue 2 years ago • 0 comments

Feature Request

Description

Rocket configuration parameters must be accessible not only by the Rocket functions but also by the other Booster artefacts like Commands, ReadModels, etc.

For example, the RocketWebHook Rocket constructor uses the WebhookParams parameter to dispatch the function with the user configuration.

  public constructor(readonly config: BoosterConfig, readonly params: WebhookParams) {
    config.registerRocketFunction(functionID, async (config: BoosterConfig, request: unknown) => {
      const webhookRequest = request as WebhookRequest
      return dispatch(config, webhookRequest, params)
    })
  }

The problem is how to access this configuration in other artefacts. There is no easy way to do it.

Possible Solution

One possible solution is to add two new methods. One for register the configuration:

config.registerRocketConfiguration(paramaters: RocketConfiguration): Promise<void>

and another one to access to it:

config.getRegisteredRocketConfiguration(): Promise<RocketConfiguration>

In a Command we could access the configuration with:

await Booster.config.getRegisteredRocketConfiguration()

Additional information

As a workaround we can use the registerRocketConfiguration for the same purpose:

function  registerBackgroundOptions(config: BoosterConfig, backgroundOptions: BackgroundOptions) {
  config.registerRocketFunction(backgroundOptionsID, async (config: BoosterConfig, request: unknown) => {
    return (config: BoosterConfig, request: unknown) => Promise.resolve(backgroundOptions)
  })
}

and then getting the info with:

const optionsFunction = Booster.config.getRegisteredRocketFunction(backgroundOptionsID)

gonzalogarciajaubert avatar May 31 '22 07:05 gonzalogarciajaubert