UNPKG

@darlean/base

Version:

Base types and definitions for creating Darlean actors and suites

86 lines (85 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.activator = exports.deactivator = exports.timer = exports.action = void 0; /** * Decorator for an action method. * * When the method name already matches with the action name, and no additional opions are required: * ```ts * @action() * public myActor(...) {} * ``` * * When the method name does not match with the action name, and/or when additional options are required: * ```ts * @action({name: 'myAction', locking: 'shared'}) * public myActorFunction(...) {} * ``` * * For a list of options, see [[IActionDecoration]]. * * @decorator */ function action(config) { // eslint-disable-next-line @typescript-eslint/ban-types return function (prototype, propertyKey, descriptor) { descriptor.value._darlean_options = { kind: 'action', locking: config?.locking }; }; } exports.action = action; /** * Decorator for a volatile timer method. * * @decorator */ function timer(config) { // eslint-disable-next-line @typescript-eslint/ban-types return function (prototype, propertyKey, descriptor) { descriptor.value._darlean_options = { kind: 'action', locking: config?.locking }; }; } exports.timer = timer; /** * Decorator for a deactivate method that can be used to provide additional configuration to * the deactivate method. * * @remarks This decorator should only be used when the actor class does not implement the standard * {@link IDeactivatable.deactivate} method, or when it is necessary to change the default options * for the standard eactivate method. * @decorator */ function deactivator(config) { // eslint-disable-next-line @typescript-eslint/ban-types return function (prototype, propertyKey, descriptor) { descriptor.value._darlean_options = { kind: 'deactivator', locking: config?.locking || 'exclusive' }; }; } exports.deactivator = deactivator; /** * Decorator for an activate method that can be used to provide additional configuration to * the activate method. * * @remarks This decorator should only be used when the actor class does not implement the standard * {@link IActivatable.activate} method, or when it is necessary to change the default options * for the standard eactivate method. * @decorator */ function activator(config) { // eslint-disable-next-line @typescript-eslint/ban-types return function (prototype, propertyKey, descriptor) { descriptor.value._darlean_options = { kind: 'activator', locking: config?.locking || 'exclusive' }; }; } exports.activator = activator;