Skip to main content

Parameters

Injecting parameters into your engine steps is a powerful feature that allows you to customize the behavior of your application based on dynamic values. Parameters can be used to pass data between different steps in the engine, enabling you to create more flexible and adaptable workflows.

Default Parameters​

By default, the engine system provides a set of built-in parameters that can be used in your steps. These parameters include:

ParameterDescription
@Context()Injects the current execution context into the step, allowing you to access request-specific data and services.
@Error()Injects the error object into the step, allowing you to access and handle errors that occurred during execution.

Creating a new Parameter​

The AxiSpark.js engine system allows you to create custom parameters that can be injected into your steps. To create a new parameter you need to do the following:

  • Create a new decorator to inject the parameter into the step.
  • Create a new parameter resolver that will be responsible for resolving the parameter value at runtime.
  • Register the new parameter resolver in the engine system so that it can be used in your steps.

For a better understanding of how to create a new parameter, see these examples of the HttpPlugin creating their own parameters:

http-plugin-parameters.ts
import { ParameterResolver, ParameterDefinition, Parameter, ParameterGenerator } from '@axisparkjs/engine';

// Example decorators
export const Body = () => Parameter(HttpParameter.Body); // HttpParameter.Body can be replaced by any string. This string needs to be unique for each parameter.
export const Path = (field: string) => Parameter(HttpParameter.Path, field); // You can pass additional data to the parameter resolver by passing it as an argument to the decorator.

// Resolvers
@Injectable()
export class BodyResolver implements ParameterResolver<any> {
resolve(httpContext: HttpContext) {
return httpContext.request.body;
}
}
@Injectable()
export class PathResolver implements ParameterResolver<string | string[]> {
resolve(httpContext: HttpContext, parameter: ParameterDefinition) {
return httpContext.request.params[parameter.field as string];
}
}

// Register the resolvers in the engine system
// You need to pass an instance of the resolver. It can be instantiated manually or retrieved from the dependency injection container if needed.
ParameterGenerator.registerParameter(HttpParameter.Request, await this.injector.get(RequestResolver));
ParameterGenerator.registerParameter(HttpParameter.Path, await this.injector.get(PathResolver));

Example of using Parameters in a Step​