nestjs-serverless-workflow 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -5
- package/dist/adapter/base-workflow.adapter.d.ts +38 -0
- package/dist/adapter/base-workflow.adapter.d.ts.map +1 -0
- package/dist/adapter/base-workflow.adapter.js +42 -0
- package/dist/adapter/base-workflow.adapter.js.map +1 -0
- package/dist/adapter/durable-lambda.adapter.d.ts +1 -5
- package/dist/adapter/durable-lambda.adapter.d.ts.map +1 -1
- package/dist/adapter/durable-lambda.adapter.js +81 -77
- package/dist/adapter/durable-lambda.adapter.js.map +1 -1
- package/dist/adapter/index.d.ts +1 -0
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/adapter/index.js +1 -0
- package/dist/adapter/index.js.map +1 -1
- package/dist/core/decorators/default.decorator.d.ts +17 -0
- package/dist/core/decorators/default.decorator.d.ts.map +1 -1
- package/dist/core/decorators/default.decorator.js +17 -0
- package/dist/core/decorators/default.decorator.js.map +1 -1
- package/dist/core/decorators/event.decorator.d.ts +18 -0
- package/dist/core/decorators/event.decorator.d.ts.map +1 -1
- package/dist/core/decorators/event.decorator.js +18 -0
- package/dist/core/decorators/event.decorator.js.map +1 -1
- package/dist/core/decorators/params.decorator.d.ts +27 -0
- package/dist/core/decorators/params.decorator.d.ts.map +1 -1
- package/dist/core/decorators/params.decorator.js +27 -0
- package/dist/core/decorators/params.decorator.js.map +1 -1
- package/dist/core/decorators/with-retry.decorator.d.ts +27 -0
- package/dist/core/decorators/with-retry.decorator.d.ts.map +1 -1
- package/dist/core/decorators/with-retry.decorator.js +28 -0
- package/dist/core/decorators/with-retry.decorator.js.map +1 -1
- package/dist/core/decorators/workflow.decorator.d.ts +29 -0
- package/dist/core/decorators/workflow.decorator.d.ts.map +1 -1
- package/dist/core/decorators/workflow.decorator.js +29 -0
- package/dist/core/decorators/workflow.decorator.js.map +1 -1
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/providers/orchestrator.service.d.ts +23 -0
- package/dist/core/providers/orchestrator.service.d.ts.map +1 -1
- package/dist/core/providers/orchestrator.service.js +23 -0
- package/dist/core/providers/orchestrator.service.js.map +1 -1
- package/dist/core/providers/router.factory.d.ts +8 -0
- package/dist/core/providers/router.factory.d.ts.map +1 -1
- package/dist/core/providers/router.factory.js +8 -0
- package/dist/core/providers/router.factory.js.map +1 -1
- package/dist/core/providers/router.service.d.ts +28 -0
- package/dist/core/providers/router.service.d.ts.map +1 -1
- package/dist/core/providers/router.service.js +28 -0
- package/dist/core/providers/router.service.js.map +1 -1
- package/dist/core/types/entity.interface.d.ts +22 -0
- package/dist/core/types/entity.interface.d.ts.map +1 -1
- package/dist/core/types/retry.interface.d.ts +32 -2
- package/dist/core/types/retry.interface.d.ts.map +1 -1
- package/dist/core/types/retry.interface.js +5 -1
- package/dist/core/types/retry.interface.js.map +1 -1
- package/dist/core/types/shared.type.d.ts +15 -1
- package/dist/core/types/shared.type.d.ts.map +1 -1
- package/dist/core/types/transit-result.type.d.ts +15 -0
- package/dist/core/types/transit-result.type.d.ts.map +1 -1
- package/dist/core/types/workflow-definition.interface.d.ts +51 -2
- package/dist/core/types/workflow-definition.interface.d.ts.map +1 -1
- package/dist/core/types/workflow-event.interface.d.ts +20 -0
- package/dist/core/types/workflow-event.interface.d.ts.map +1 -1
- package/dist/core/workflow.module.d.ts +28 -0
- package/dist/core/workflow.module.d.ts.map +1 -1
- package/dist/core/workflow.module.js +28 -0
- package/dist/core/workflow.module.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
import type { IBackoffRetryConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build the metadata key for a specific handler's retry config.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
2
6
|
export declare const getRetryKey: (propertyKey: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Method decorator that attaches retry configuration to a workflow handler.
|
|
9
|
+
*
|
|
10
|
+
* When an adapter (e.g. {@link DurableLambdaEventHandler}) executes the
|
|
11
|
+
* transition, it reads this metadata and wraps the call with automatic
|
|
12
|
+
* retries using the specified backoff strategy.
|
|
13
|
+
*
|
|
14
|
+
* @param config - Backoff retry configuration (strategy, attempts, delays).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @OnEvent('order.process')
|
|
19
|
+
* @WithRetry({
|
|
20
|
+
* handler: 'onProcess',
|
|
21
|
+
* maxAttempts: 3,
|
|
22
|
+
* strategy: RetryStrategy.EXPONENTIAL_JITTER,
|
|
23
|
+
* initialDelay: 500,
|
|
24
|
+
* })
|
|
25
|
+
* async onProcess(@Entity() order: Order) {
|
|
26
|
+
* // may throw — will be retried up to 3 times
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
3
30
|
export declare function WithRetry(config: IBackoffRetryConfig): (_target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
4
31
|
//# sourceMappingURL=with-retry.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-retry.decorator.d.ts","sourceRoot":"","sources":["../../../packages/core/decorators/with-retry.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"with-retry.decorator.d.ts","sourceRoot":"","sources":["../../../packages/core/decorators/with-retry.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAKpD;;;GAGG;AACH,eAAO,MAAM,WAAW,iCAA8D,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,mBAAmB,6FAKpD"}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
+
/** @internal Base metadata key for retry configuration. */
|
|
1
2
|
const WITH_RETRY_KEY = 'workflow:retry';
|
|
3
|
+
/**
|
|
4
|
+
* Build the metadata key for a specific handler's retry config.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
2
7
|
export const getRetryKey = (propertyKey) => `${WITH_RETRY_KEY}:${propertyKey}`;
|
|
8
|
+
/**
|
|
9
|
+
* Method decorator that attaches retry configuration to a workflow handler.
|
|
10
|
+
*
|
|
11
|
+
* When an adapter (e.g. {@link DurableLambdaEventHandler}) executes the
|
|
12
|
+
* transition, it reads this metadata and wraps the call with automatic
|
|
13
|
+
* retries using the specified backoff strategy.
|
|
14
|
+
*
|
|
15
|
+
* @param config - Backoff retry configuration (strategy, attempts, delays).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* @OnEvent('order.process')
|
|
20
|
+
* @WithRetry({
|
|
21
|
+
* handler: 'onProcess',
|
|
22
|
+
* maxAttempts: 3,
|
|
23
|
+
* strategy: RetryStrategy.EXPONENTIAL_JITTER,
|
|
24
|
+
* initialDelay: 500,
|
|
25
|
+
* })
|
|
26
|
+
* async onProcess(@Entity() order: Order) {
|
|
27
|
+
* // may throw — will be retried up to 3 times
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
3
31
|
export function WithRetry(config) {
|
|
4
32
|
return (_target, propertyKey, descriptor) => {
|
|
5
33
|
Reflect.defineMetadata(getRetryKey(propertyKey), config, descriptor.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-retry.decorator.js","sourceRoot":"","sources":["../../../packages/core/decorators/with-retry.decorator.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,WAAW,EAAE,CAAC;AAEvF,MAAM,UAAU,SAAS,CAAC,MAA2B,EAAE;IACrD,OAAO,CAAC,OAAY,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE,CAAC;QAC5E,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,UAAU,CAAC;IAAA,CACnB,CAAC;AAAA,CACH"}
|
|
1
|
+
{"version":3,"file":"with-retry.decorator.js","sourceRoot":"","sources":["../../../packages/core/decorators/with-retry.decorator.ts"],"names":[],"mappings":"AAEA,2DAA2D;AAC3D,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,WAAW,EAAE,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,SAAS,CAAC,MAA2B,EAAE;IACrD,OAAO,CAAC,OAAY,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE,CAAC;QAC5E,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,UAAU,CAAC;IAAA,CACnB,CAAC;AAAA,CACH"}
|
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
import type { IWorkflowDefinition } from '../../core/index.js';
|
|
2
|
+
/** @internal Metadata key for the workflow definition on a class. */
|
|
2
3
|
export declare const WORKFLOW_DEFINITION_KEY = "workflow:definition";
|
|
4
|
+
/**
|
|
5
|
+
* Class decorator that declares a NestJS class as a workflow.
|
|
6
|
+
*
|
|
7
|
+
* Stores the {@link IWorkflowDefinition} as metadata so the
|
|
8
|
+
* {@link OrchestratorService} can discover it at module init and build
|
|
9
|
+
* the routing table for state transitions.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - Entity type
|
|
12
|
+
* @typeParam Event - Union of event names
|
|
13
|
+
* @typeParam State - Union of state values
|
|
14
|
+
*
|
|
15
|
+
* @param definition - The full workflow definition (states, transitions, entity service).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* @Workflow<Order, OrderEvent, OrderStatus>({
|
|
20
|
+
* name: 'OrderWorkflow',
|
|
21
|
+
* states: {
|
|
22
|
+
* finals: [OrderStatus.Completed],
|
|
23
|
+
* idles: [OrderStatus.Pending],
|
|
24
|
+
* failed: OrderStatus.Failed,
|
|
25
|
+
* },
|
|
26
|
+
* transitions: [ ... ],
|
|
27
|
+
* entityService: 'entity.order',
|
|
28
|
+
* })
|
|
29
|
+
* export class OrderWorkflow { ... }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
3
32
|
export declare function Workflow<T, Event, State>(definition: IWorkflowDefinition<T, Event, State>): <T extends new (...args: any[]) => {}>(instance: T) => T;
|
|
4
33
|
//# sourceMappingURL=workflow.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.decorator.d.ts","sourceRoot":"","sources":["../../../packages/core/decorators/workflow.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAElD,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAChF,CAAC,uDAKV"}
|
|
1
|
+
{"version":3,"file":"workflow.decorator.d.ts","sourceRoot":"","sources":["../../../packages/core/decorators/workflow.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAElD,qEAAqE;AACrE,eAAO,MAAM,uBAAuB,wBAAwB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAChF,CAAC,uDAKV"}
|
|
@@ -1,4 +1,33 @@
|
|
|
1
|
+
/** @internal Metadata key for the workflow definition on a class. */
|
|
1
2
|
export const WORKFLOW_DEFINITION_KEY = 'workflow:definition';
|
|
3
|
+
/**
|
|
4
|
+
* Class decorator that declares a NestJS class as a workflow.
|
|
5
|
+
*
|
|
6
|
+
* Stores the {@link IWorkflowDefinition} as metadata so the
|
|
7
|
+
* {@link OrchestratorService} can discover it at module init and build
|
|
8
|
+
* the routing table for state transitions.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - Entity type
|
|
11
|
+
* @typeParam Event - Union of event names
|
|
12
|
+
* @typeParam State - Union of state values
|
|
13
|
+
*
|
|
14
|
+
* @param definition - The full workflow definition (states, transitions, entity service).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @Workflow<Order, OrderEvent, OrderStatus>({
|
|
19
|
+
* name: 'OrderWorkflow',
|
|
20
|
+
* states: {
|
|
21
|
+
* finals: [OrderStatus.Completed],
|
|
22
|
+
* idles: [OrderStatus.Pending],
|
|
23
|
+
* failed: OrderStatus.Failed,
|
|
24
|
+
* },
|
|
25
|
+
* transitions: [ ... ],
|
|
26
|
+
* entityService: 'entity.order',
|
|
27
|
+
* })
|
|
28
|
+
* export class OrderWorkflow { ... }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
2
31
|
export function Workflow(definition) {
|
|
3
32
|
return (instance) => {
|
|
4
33
|
Reflect.defineMetadata(WORKFLOW_DEFINITION_KEY, definition, instance);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.decorator.js","sourceRoot":"","sources":["../../../packages/core/decorators/workflow.decorator.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAE7D,MAAM,UAAU,QAAQ,CAAkB,UAAgD,EAAE;IAC1F,OAAO,CAAyC,QAAW,EAAE,EAAE,CAAC;QAC9D,OAAO,CAAC,cAAc,CAAC,uBAAuB,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QAEtE,OAAO,QAAQ,CAAC;IAAA,CACjB,CAAC;AAAA,CACH"}
|
|
1
|
+
{"version":3,"file":"workflow.decorator.js","sourceRoot":"","sources":["../../../packages/core/decorators/workflow.decorator.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,QAAQ,CAAkB,UAAgD,EAAE;IAC1F,OAAO,CAAyC,QAAW,EAAE,EAAE,CAAC;QAC9D,OAAO,CAAC,cAAc,CAAC,uBAAuB,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QAEtE,OAAO,QAAQ,CAAC;IAAA,CACjB,CAAC;AAAA,CACH"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nestjs-serverless-workflow/core
|
|
3
|
+
*
|
|
4
|
+
* Core workflow engine for NestJS — provides decorators, services, types, and
|
|
5
|
+
* utilities for defining and executing state-machine-based workflows.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* Workflow, OnEvent, Entity, Payload,
|
|
11
|
+
* WorkflowModule, OrchestratorService,
|
|
12
|
+
* } from 'nestjs-serverless-workflow/core';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export * from './decorators/index.js';
|
|
2
16
|
export * from './providers/index.js';
|
|
3
17
|
export * from './providers/router.factory.js';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nestjs-serverless-workflow/core
|
|
3
|
+
*
|
|
4
|
+
* Core workflow engine for NestJS — provides decorators, services, types, and
|
|
5
|
+
* utilities for defining and executing state-machine-based workflows.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* Workflow, OnEvent, Entity, Payload,
|
|
11
|
+
* WorkflowModule, OrchestratorService,
|
|
12
|
+
* } from 'nestjs-serverless-workflow/core';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export * from './decorators/index.js';
|
|
2
16
|
export * from './providers/index.js';
|
|
3
17
|
export * from './providers/router.factory.js';
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../packages/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
|
@@ -3,15 +3,38 @@ import { type OnModuleInit } from '@nestjs/common';
|
|
|
3
3
|
import { DiscoveryService, ModuleRef } from '@nestjs/core';
|
|
4
4
|
import type { IWorkflowEvent } from '../types/workflow-event.interface.js';
|
|
5
5
|
import { StateRouterHelperFactory } from './router.factory.js';
|
|
6
|
+
/**
|
|
7
|
+
* Central orchestration engine that discovers workflow definitions at startup
|
|
8
|
+
* and routes incoming {@link IWorkflowEvent}s to the correct handler.
|
|
9
|
+
*
|
|
10
|
+
* Registered automatically by {@link WorkflowModule.register}. Adapters
|
|
11
|
+
* (and application code) call {@link transit} to trigger state transitions
|
|
12
|
+
* and receive a {@link TransitResult} describing the outcome.
|
|
13
|
+
*/
|
|
6
14
|
export declare class OrchestratorService implements OnModuleInit {
|
|
7
15
|
private readonly discoveryService;
|
|
8
16
|
private readonly routerHelperFactory;
|
|
9
17
|
private readonly moduleRef;
|
|
18
|
+
/** Event-name → route lookup table, built once during `onModuleInit`. */
|
|
10
19
|
private routes;
|
|
11
20
|
private readonly logger;
|
|
12
21
|
constructor(discoveryService: DiscoveryService, routerHelperFactory: StateRouterHelperFactory, moduleRef: ModuleRef);
|
|
13
22
|
onModuleInit(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the retry configuration attached to the handler for a given event,
|
|
25
|
+
* or `undefined` if the handler has no `@WithRetry()` decorator.
|
|
26
|
+
*/
|
|
14
27
|
getRetryConfig(event: string): IBackoffRetryConfig | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Execute a single state transition for the given workflow event.
|
|
30
|
+
*
|
|
31
|
+
* Loads the entity, finds a valid transition, runs the handler, updates
|
|
32
|
+
* the entity status, and returns a {@link TransitResult} describing what
|
|
33
|
+
* happened and what the caller should do next.
|
|
34
|
+
*
|
|
35
|
+
* @throws {BadRequestException} If no workflow is registered for the event,
|
|
36
|
+
* the entity is not found, or no valid transition matches.
|
|
37
|
+
*/
|
|
15
38
|
transit(params: IWorkflowEvent): Promise<TransitResult>;
|
|
16
39
|
}
|
|
17
40
|
//# sourceMappingURL=orchestrator.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.service.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/orchestrator.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,mBAAmB,EAMxB,KAAK,aAAa,EACnB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAA2C,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,qBACa,mBAAoB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"orchestrator.service.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/orchestrator.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,mBAAmB,EAMxB,KAAK,aAAa,EACnB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAA2C,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;GAOG;AACH,qBACa,mBAAoB,YAAW,YAAY;IAMpD,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAP5B,2EAAyE;IACzE,OAAO,CAAC,MAAM,CAA4C;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAE/D,YACmB,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,wBAAwB,EAC7C,SAAS,EAAE,SAAS,EACnC;IAEJ,YAAY,SA4CX;IAED;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAE7D;IAED;;;;;;;;;OASG;IACG,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAqG5D;CACF"}
|
|
@@ -12,10 +12,19 @@ import { UnretriableException } from '../../exception/unretriable.exception.js';
|
|
|
12
12
|
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
|
13
13
|
import { DiscoveryService, ModuleRef } from '@nestjs/core';
|
|
14
14
|
import { StateRouterHelperFactory } from './router.factory.js';
|
|
15
|
+
/**
|
|
16
|
+
* Central orchestration engine that discovers workflow definitions at startup
|
|
17
|
+
* and routes incoming {@link IWorkflowEvent}s to the correct handler.
|
|
18
|
+
*
|
|
19
|
+
* Registered automatically by {@link WorkflowModule.register}. Adapters
|
|
20
|
+
* (and application code) call {@link transit} to trigger state transitions
|
|
21
|
+
* and receive a {@link TransitResult} describing the outcome.
|
|
22
|
+
*/
|
|
15
23
|
let OrchestratorService = class OrchestratorService {
|
|
16
24
|
discoveryService;
|
|
17
25
|
routerHelperFactory;
|
|
18
26
|
moduleRef;
|
|
27
|
+
/** Event-name → route lookup table, built once during `onModuleInit`. */
|
|
19
28
|
routes = new Map();
|
|
20
29
|
logger = new Logger(OrchestratorService.name);
|
|
21
30
|
constructor(discoveryService, routerHelperFactory, moduleRef) {
|
|
@@ -57,9 +66,23 @@ let OrchestratorService = class OrchestratorService {
|
|
|
57
66
|
}
|
|
58
67
|
this.logger.log(`StateRouter initialized with ${this.routes.size} routes: `, Array.from(this.routes.keys()));
|
|
59
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the retry configuration attached to the handler for a given event,
|
|
71
|
+
* or `undefined` if the handler has no `@WithRetry()` decorator.
|
|
72
|
+
*/
|
|
60
73
|
getRetryConfig(event) {
|
|
61
74
|
return this.routes.get(event)?.retryConfig;
|
|
62
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute a single state transition for the given workflow event.
|
|
78
|
+
*
|
|
79
|
+
* Loads the entity, finds a valid transition, runs the handler, updates
|
|
80
|
+
* the entity status, and returns a {@link TransitResult} describing what
|
|
81
|
+
* happened and what the caller should do next.
|
|
82
|
+
*
|
|
83
|
+
* @throws {BadRequestException} If no workflow is registered for the event,
|
|
84
|
+
* the entity is not found, or no valid transition matches.
|
|
85
|
+
*/
|
|
63
86
|
async transit(params) {
|
|
64
87
|
const { urn, payload, event } = params;
|
|
65
88
|
const route = this.routes.get(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.service.js","sourceRoot":"","sources":["../../../packages/core/providers/orchestrator.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GAQrB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAqB,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"orchestrator.service.js","sourceRoot":"","sources":["../../../packages/core/providers/orchestrator.service.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eAAe,GAAG,EAAE,CAAC,CAAC;YACzD,OAAO;gBACL,MAAM,EAAE,WAAW;gBACnB,SAAS,EAAE;oBACT,KAAK,EAAE,SAAmB;oBAC1B,GAAG;oBACH,OAAO,EAAE,aAAa;oBACtB,OAAO,EAAE,CAAC;iBACX;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,CAAC,gDAAiD,CAAW,CAAC,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;YAC3F,4EAA0E;YAC1E,uDAAuD;YACvD,IAAI,CAAC,CAAC,CAAC,YAAY,oBAAoB,CAAC,EAAE,CAAC;gBACzC,MAAM,CAAC,CAAC;YACV,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,MAAyB;aACnD,CAAC;QACJ,CAAC;IAAA,CACF;CACF,CAAA;AAjLY,mBAAmB;IAD/B,UAAU,EAAE;qCAO0B,gBAAgB;QACb,wBAAwB;QAClC,SAAS;GAR5B,mBAAmB,CAiL/B"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type Logger } from '@nestjs/common';
|
|
2
2
|
import type { IWorkflowDefinition, IWorkflowEntity } from '../types/index.js';
|
|
3
3
|
import { RouterService } from './router.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory that creates {@link RouterService} instances with the correct
|
|
6
|
+
* generic parameters for a given workflow event.
|
|
7
|
+
*
|
|
8
|
+
* Registered as a singleton via {@link WorkflowModule} and injected into
|
|
9
|
+
* {@link OrchestratorService}.
|
|
10
|
+
*/
|
|
4
11
|
export declare class StateRouterHelperFactory {
|
|
12
|
+
/** Create a new {@link RouterService} scoped to a single event dispatch. */
|
|
5
13
|
create<T, Event, State>(event: Event, entityService: IWorkflowEntity, workflowDefinition: IWorkflowDefinition<T, Event, State>, logger: Logger): RouterService<T, Event, State>;
|
|
6
14
|
}
|
|
7
15
|
//# sourceMappingURL=router.factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.factory.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/router.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBACa,wBAAwB;IACnC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EACpB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,eAAe,EAC9B,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EACxD,MAAM,EAAE,MAAM,GACb,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAEhC;CACF"}
|
|
1
|
+
{"version":3,"file":"router.factory.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/router.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;GAMG;AACH,qBACa,wBAAwB;IACnC,4EAA4E;IAC5E,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EACpB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,eAAe,EAC9B,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EACxD,MAAM,EAAE,MAAM,GACb,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAEhC;CACF"}
|
|
@@ -6,7 +6,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Injectable } from '@nestjs/common';
|
|
8
8
|
import { RouterService } from './router.service.js';
|
|
9
|
+
/**
|
|
10
|
+
* Factory that creates {@link RouterService} instances with the correct
|
|
11
|
+
* generic parameters for a given workflow event.
|
|
12
|
+
*
|
|
13
|
+
* Registered as a singleton via {@link WorkflowModule} and injected into
|
|
14
|
+
* {@link OrchestratorService}.
|
|
15
|
+
*/
|
|
9
16
|
let StateRouterHelperFactory = class StateRouterHelperFactory {
|
|
17
|
+
/** Create a new {@link RouterService} scoped to a single event dispatch. */
|
|
10
18
|
create(event, entityService, workflowDefinition, logger) {
|
|
11
19
|
return new RouterService(event, entityService, workflowDefinition, logger);
|
|
12
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.factory.js","sourceRoot":"","sources":["../../../packages/core/providers/router.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAe,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"router.factory.js","sourceRoot":"","sources":["../../../packages/core/providers/router.factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAe,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;GAMG;AAEH,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IACnC,4EAA4E;IAC5E,MAAM,CACJ,KAAY,EACZ,aAA8B,EAC9B,kBAAwD,EACxD,MAAc,EACkB;QAChC,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;IAAA,CAC5E;CACF,CAAA;AAVY,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAUpC"}
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import { type Logger } from '@nestjs/common';
|
|
2
2
|
import type { Duration, ITransitionEvent, IWorkflowDefinition, IWorkflowEntity } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Transition-matching and entity-validation logic for a single workflow event.
|
|
5
|
+
*
|
|
6
|
+
* Created per-request by {@link StateRouterHelperFactory}. Encapsulates the
|
|
7
|
+
* rules for finding a valid transition, checking conditions, resolving idle
|
|
8
|
+
* states, and building handler arguments from parameter decorators.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - Entity type
|
|
11
|
+
* @typeParam Event - Event name type
|
|
12
|
+
* @typeParam State - State value type
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
3
15
|
export declare class RouterService<T, Event, State> {
|
|
4
16
|
private readonly event;
|
|
5
17
|
private readonly entityService;
|
|
6
18
|
private readonly workflowDefinition;
|
|
7
19
|
private readonly logger;
|
|
8
20
|
constructor(event: Event, entityService: IWorkflowEntity, workflowDefinition: IWorkflowDefinition<T, Event, State>, logger: Logger);
|
|
21
|
+
/** Load the entity by URN and verify it exists. Warns if already in a final state. */
|
|
9
22
|
loadAndValidateEntity(urn: string | number): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Search the workflow's transitions for a valid match given the entity's
|
|
25
|
+
* current state, the incoming event, and any guard conditions.
|
|
26
|
+
*
|
|
27
|
+
* @param options.skipEventCheck - When `true`, matches transitions by state
|
|
28
|
+
* only (used for auto-transition after a handler completes).
|
|
29
|
+
* @returns The first matching transition and whether any event+state pair matched.
|
|
30
|
+
*/
|
|
10
31
|
findValidTransition<P>(entity: T, payload: P, options?: {
|
|
11
32
|
skipEventCheck?: boolean;
|
|
12
33
|
}): {
|
|
@@ -15,8 +36,15 @@ export declare class RouterService<T, Event, State> {
|
|
|
15
36
|
};
|
|
16
37
|
private matchesState;
|
|
17
38
|
private matchesEvent;
|
|
39
|
+
/** Check whether the entity's current state is listed as an idle state. */
|
|
18
40
|
isInIdleStatus(entity: T): boolean;
|
|
41
|
+
/** Return the per-state timeout for an idle state, or `undefined` if none configured. */
|
|
19
42
|
getIdleTimeout(state: string | number): Duration | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve `@Entity()` and `@Payload()` parameter decorators into an ordered
|
|
45
|
+
* argument array for the handler method. Falls back to the legacy
|
|
46
|
+
* `{ entity, payload }` shape when no decorator metadata is present.
|
|
47
|
+
*/
|
|
20
48
|
buildParamDecorators(entity: T, payload: any, target: any, propertyKey: string | symbol): any[];
|
|
21
49
|
}
|
|
22
50
|
//# sourceMappingURL=router.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.service.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/router.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEjG,qBAAa,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK;IAEtC,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,YACmB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,eAAe,EAC9B,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EACxD,MAAM,EAAE,MAAM,EAC7B;
|
|
1
|
+
{"version":3,"file":"router.service.d.ts","sourceRoot":"","sources":["../../../packages/core/providers/router.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAA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1,4 +1,16 @@
|
|
|
1
1
|
import { BadRequestException } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Transition-matching and entity-validation logic for a single workflow event.
|
|
4
|
+
*
|
|
5
|
+
* Created per-request by {@link StateRouterHelperFactory}. Encapsulates the
|
|
6
|
+
* rules for finding a valid transition, checking conditions, resolving idle
|
|
7
|
+
* states, and building handler arguments from parameter decorators.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - Entity type
|
|
10
|
+
* @typeParam Event - Event name type
|
|
11
|
+
* @typeParam State - State value type
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
2
14
|
export class RouterService {
|
|
3
15
|
event;
|
|
4
16
|
entityService;
|
|
@@ -10,6 +22,7 @@ export class RouterService {
|
|
|
10
22
|
this.workflowDefinition = workflowDefinition;
|
|
11
23
|
this.logger = logger;
|
|
12
24
|
}
|
|
25
|
+
/** Load the entity by URN and verify it exists. Warns if already in a final state. */
|
|
13
26
|
async loadAndValidateEntity(urn) {
|
|
14
27
|
const entity = await this.entityService.load(urn);
|
|
15
28
|
if (!entity) {
|
|
@@ -23,6 +36,14 @@ export class RouterService {
|
|
|
23
36
|
}
|
|
24
37
|
return entity;
|
|
25
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Search the workflow's transitions for a valid match given the entity's
|
|
41
|
+
* current state, the incoming event, and any guard conditions.
|
|
42
|
+
*
|
|
43
|
+
* @param options.skipEventCheck - When `true`, matches transitions by state
|
|
44
|
+
* only (used for auto-transition after a handler completes).
|
|
45
|
+
* @returns The first matching transition and whether any event+state pair matched.
|
|
46
|
+
*/
|
|
26
47
|
findValidTransition(entity, payload, options) {
|
|
27
48
|
const currentStatus = this.entityService.status(entity);
|
|
28
49
|
const skipEventCheck = options?.skipEventCheck === true;
|
|
@@ -55,6 +76,7 @@ export class RouterService {
|
|
|
55
76
|
matchesEvent(event) {
|
|
56
77
|
return Array.isArray(event) ? event.includes(this.event) : event === this.event;
|
|
57
78
|
}
|
|
79
|
+
/** Check whether the entity's current state is listed as an idle state. */
|
|
58
80
|
isInIdleStatus(entity) {
|
|
59
81
|
const status = this.entityService.status(entity);
|
|
60
82
|
if (!status) {
|
|
@@ -64,6 +86,7 @@ export class RouterService {
|
|
|
64
86
|
? entry.state === status
|
|
65
87
|
: entry === status);
|
|
66
88
|
}
|
|
89
|
+
/** Return the per-state timeout for an idle state, or `undefined` if none configured. */
|
|
67
90
|
getIdleTimeout(state) {
|
|
68
91
|
for (const entry of this.workflowDefinition.states.idles) {
|
|
69
92
|
if (typeof entry === 'object' && entry !== null && 'state' in entry) {
|
|
@@ -73,6 +96,11 @@ export class RouterService {
|
|
|
73
96
|
}
|
|
74
97
|
return undefined;
|
|
75
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolve `@Entity()` and `@Payload()` parameter decorators into an ordered
|
|
101
|
+
* argument array for the handler method. Falls back to the legacy
|
|
102
|
+
* `{ entity, payload }` shape when no decorator metadata is present.
|
|
103
|
+
*/
|
|
76
104
|
buildParamDecorators(entity, payload, target, propertyKey) {
|
|
77
105
|
// Metadata is stored on the prototype when decorators are applied
|
|
78
106
|
const prototype = target.constructor?.prototype || target;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.service.js","sourceRoot":"","sources":["../../../packages/core/providers/router.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAe,MAAM,gBAAgB,CAAC;AAGlE,MAAM,OAAO,aAAa;IAEL,KAAK;IACL,aAAa;IACb,kBAAkB;IAClB,MAAM;IAJzB,YACmB,KAAY,EACZ,aAA8B,EAC9B,kBAAwD,EACxD,MAAc,EAC/B;qBAJiB,KAAK;6BACL,aAAa;kCACb,kBAAkB;sBAClB,MAAM;IACtB,CAAC;IAEJ,KAAK,CAAC,qBAAqB,CAAC,GAAoB,EAAc;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,IA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C;YACN,kDAAkD;YAClD,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IAAA,CACb;CACF"}
|
|
1
|
+
{"version":3,"file":"router.service.js","sourceRoot":"","sources":["../../../packages/core/providers/router.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAe,MAAM,gBAAgB,CAAC;AAGlE;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAEL,KAAK;IACL,aAAa;IACb,kBAAkB;IAClB,MAAM;IAJzB,YACmB,KAAY,EACZ,aAA8B,EAC9B,kBAAwD,EACxD,MAAc,EAC/B;qBAJiB,KAAK;6BACL,aAAa;kCACb,kBAAkB;sBAClB,MAAM;IACtB,CAAC;IAEJ,sFAAsF;IACtF,KAAK,CAAC,qBAAqB,CAAC,GAAoB,EAAc;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;YAC5C,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvD,MAAM,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAgC,CAAC;QAE3F,IAAI,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,wEAAwE,EAAE,GAAG,CAAC,CAAC;QAChH,CAAC;QAED,OAAO,MAAM,CAAC;IAAA,CACf;IAED;;;;;;;OAOG;IACH,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AAC,MAAS,EAAE,OAAY,EAAE,MAAW,EAAE,WAA4B,EAAE;QACvF,kEAAkE;QAClE,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,SAAS,IAAI,MAAM,CAAC;QAC1D,MAAM,UAAU,GACd,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAE1E,IAAI,IAAI,GAAU,EAAE,CAAC;QACrB,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,8CAA8C;YAC9C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;gBAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;oBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;qBACjD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;oBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;;oBACxD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;YACpC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IAAA,CACb;CACF"}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract for the persistence layer of a workflow entity.
|
|
3
|
+
*
|
|
4
|
+
* Implement this interface in an `@Injectable()` service and register it with
|
|
5
|
+
* {@link WorkflowModule.register} under the injection token referenced by
|
|
6
|
+
* your `@Workflow({ entityService })` definition.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The entity type (e.g. `Order`, `User`)
|
|
9
|
+
* @typeParam State - The enum or union of valid entity states
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Injectable()
|
|
14
|
+
* export class OrderEntityService implements IWorkflowEntity<Order, OrderStatus> {
|
|
15
|
+
* async create() { ... }
|
|
16
|
+
* async load(urn) { ... }
|
|
17
|
+
* async update(entity, status) { ... }
|
|
18
|
+
* status(entity) { return entity.status; }
|
|
19
|
+
* urn(entity) { return entity.id; }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
1
23
|
export interface IWorkflowEntity<T = any, State = string | number> {
|
|
2
24
|
/**
|
|
3
25
|
* Creates a new instance of the entity
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.interface.d.ts","sourceRoot":"","sources":["../../../packages/core/types/entity.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM;IAC/D;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7C;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAE9C;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;IAEzB;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;CACjC"}
|
|
1
|
+
{"version":3,"file":"entity.interface.d.ts","sourceRoot":"","sources":["../../../packages/core/types/entity.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM;IAC/D;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7C;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAE9C;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;IAEzB;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;CACjC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Available backoff strategies for retry logic.
|
|
3
|
+
*
|
|
4
|
+
* - `FIXED` — constant delay between attempts.
|
|
5
|
+
* - `EXPONENTIAL` — delay doubles (or multiplies) on each attempt.
|
|
6
|
+
* - `EXPONENTIAL_JITTER` — exponential with randomised jitter to spread load (default).
|
|
3
7
|
*/
|
|
4
8
|
export declare enum RetryStrategy {
|
|
5
9
|
FIXED = "fixed",
|
|
@@ -7,17 +11,43 @@ export declare enum RetryStrategy {
|
|
|
7
11
|
EXPONENTIAL_JITTER = "exponential_jitter"
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
14
|
+
* Configuration for the {@link WithRetry} decorator.
|
|
15
|
+
*
|
|
16
|
+
* Attach to a workflow handler method to enable automatic retries with
|
|
17
|
+
* configurable backoff. Used by adapters (e.g. {@link DurableLambdaEventHandler})
|
|
18
|
+
* to wrap `orchestrator.transit()` calls.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @OnEvent('order.process')
|
|
23
|
+
* @WithRetry({
|
|
24
|
+
* handler: 'onProcess',
|
|
25
|
+
* maxAttempts: 3,
|
|
26
|
+
* strategy: RetryStrategy.EXPONENTIAL_JITTER,
|
|
27
|
+
* initialDelay: 500,
|
|
28
|
+
* })
|
|
29
|
+
* async onProcess(@Entity() order: Order) { ... }
|
|
30
|
+
* ```
|
|
11
31
|
*/
|
|
12
32
|
export interface IBackoffRetryConfig {
|
|
33
|
+
/** Name of the handler method this config belongs to. */
|
|
13
34
|
handler: string;
|
|
35
|
+
/** Maximum number of attempts (including the initial try). */
|
|
14
36
|
maxAttempts: number;
|
|
37
|
+
/** Backoff strategy. Defaults to `EXPONENTIAL_JITTER`. */
|
|
15
38
|
strategy?: RetryStrategy;
|
|
39
|
+
/** Base delay in milliseconds before the first retry. Defaults to `1000`. */
|
|
16
40
|
initialDelay?: number;
|
|
41
|
+
/** Multiplier applied on each attempt for exponential strategies. Defaults to `2`. */
|
|
17
42
|
backoffMultiplier?: number;
|
|
43
|
+
/** Upper bound for computed delay in milliseconds. Defaults to `60000`. */
|
|
18
44
|
maxDelay?: number;
|
|
45
|
+
/** `true` for full jitter, or a number `0–1` for partial jitter percentage. */
|
|
19
46
|
jitter?: boolean | number;
|
|
20
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Minimal interface for a retry-capable handler.
|
|
50
|
+
*/
|
|
21
51
|
export interface IRetryHandler {
|
|
22
52
|
execute: () => Promise<void>;
|
|
23
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.interface.d.ts","sourceRoot":"","sources":["../../../packages/core/types/retry.interface.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.interface.d.ts","sourceRoot":"","sources":["../../../packages/core/types/retry.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,WAAW,gBAAgB;IAC3B,kBAAkB,uBAAuB;CAC1C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAA+E;IAC/E,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { RetryStrategy };
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Available backoff strategies for retry logic.
|
|
4
|
+
*
|
|
5
|
+
* - `FIXED` — constant delay between attempts.
|
|
6
|
+
* - `EXPONENTIAL` — delay doubles (or multiplies) on each attempt.
|
|
7
|
+
* - `EXPONENTIAL_JITTER` — exponential with randomised jitter to spread load (default).
|
|
4
8
|
*/
|
|
5
9
|
var RetryStrategy;
|
|
6
10
|
(function (RetryStrategy) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.interface.js","sourceRoot":"","sources":["../../../packages/core/types/retry.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.interface.js","sourceRoot":"","sources":["../../../packages/core/types/retry.interface.ts"],"names":[],"mappings":"SAOY,aAAa;AAPzB;;;;;;GAMG;AACH,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,4CAA2B,CAAA;IAC3B,0DAAyC,CAAA;AAAC,CAC5C,EAJY,aAAa,KAAb,aAAa,QAIxB"}
|