@oyinlola141/lattice-lifecycle 0.1.0
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 +19 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycleComponent/index.d.ts +7 -0
- package/dist/lifecycleComponent/index.d.ts.map +1 -0
- package/dist/lifecycleComponent/index.js +7 -0
- package/dist/lifecycleComponent/index.js.map +1 -0
- package/dist/lifecycleComponent/lifecycleComponent.type.d.ts +68 -0
- package/dist/lifecycleComponent/lifecycleComponent.type.d.ts.map +1 -0
- package/dist/lifecycleComponent/lifecycleComponent.type.js +7 -0
- package/dist/lifecycleComponent/lifecycleComponent.type.js.map +1 -0
- package/dist/lifecycleContext/index.d.ts +8 -0
- package/dist/lifecycleContext/index.d.ts.map +1 -0
- package/dist/lifecycleContext/index.js +7 -0
- package/dist/lifecycleContext/index.js.map +1 -0
- package/dist/lifecycleContext/lifecycleContext.type.d.ts +23 -0
- package/dist/lifecycleContext/lifecycleContext.type.d.ts.map +1 -0
- package/dist/lifecycleContext/lifecycleContext.type.js +15 -0
- package/dist/lifecycleContext/lifecycleContext.type.js.map +1 -0
- package/dist/lifecycleEvents/index.d.ts +8 -0
- package/dist/lifecycleEvents/index.d.ts.map +1 -0
- package/dist/lifecycleEvents/index.js +7 -0
- package/dist/lifecycleEvents/index.js.map +1 -0
- package/dist/lifecycleEvents/lifecycleEvents.core.d.ts +52 -0
- package/dist/lifecycleEvents/lifecycleEvents.core.d.ts.map +1 -0
- package/dist/lifecycleEvents/lifecycleEvents.core.js +46 -0
- package/dist/lifecycleEvents/lifecycleEvents.core.js.map +1 -0
- package/dist/lifecycleExecutor/index.d.ts +8 -0
- package/dist/lifecycleExecutor/index.d.ts.map +1 -0
- package/dist/lifecycleExecutor/index.js +7 -0
- package/dist/lifecycleExecutor/index.js.map +1 -0
- package/dist/lifecycleExecutor/lifecycleExecutor.core.d.ts +35 -0
- package/dist/lifecycleExecutor/lifecycleExecutor.core.d.ts.map +1 -0
- package/dist/lifecycleExecutor/lifecycleExecutor.core.js +88 -0
- package/dist/lifecycleExecutor/lifecycleExecutor.core.js.map +1 -0
- package/dist/lifecycleInternal/asyncUtils.core.d.ts +19 -0
- package/dist/lifecycleInternal/asyncUtils.core.d.ts.map +1 -0
- package/dist/lifecycleInternal/asyncUtils.core.js +69 -0
- package/dist/lifecycleInternal/asyncUtils.core.js.map +1 -0
- package/dist/lifecycleInternal/dependencyGraph.core.d.ts +29 -0
- package/dist/lifecycleInternal/dependencyGraph.core.d.ts.map +1 -0
- package/dist/lifecycleInternal/dependencyGraph.core.js +74 -0
- package/dist/lifecycleInternal/dependencyGraph.core.js.map +1 -0
- package/dist/lifecycleInternal/index.d.ts +10 -0
- package/dist/lifecycleInternal/index.d.ts.map +1 -0
- package/dist/lifecycleInternal/index.js +9 -0
- package/dist/lifecycleInternal/index.js.map +1 -0
- package/dist/lifecycleInternal/topologicalSort.core.d.ts +19 -0
- package/dist/lifecycleInternal/topologicalSort.core.d.ts.map +1 -0
- package/dist/lifecycleInternal/topologicalSort.core.js +50 -0
- package/dist/lifecycleInternal/topologicalSort.core.js.map +1 -0
- package/dist/lifecycleManager/index.d.ts +8 -0
- package/dist/lifecycleManager/index.d.ts.map +1 -0
- package/dist/lifecycleManager/index.js +7 -0
- package/dist/lifecycleManager/index.js.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.context.d.ts +42 -0
- package/dist/lifecycleManager/lifecycleManager.context.d.ts.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.context.js +34 -0
- package/dist/lifecycleManager/lifecycleManager.context.js.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.core.d.ts +70 -0
- package/dist/lifecycleManager/lifecycleManager.core.d.ts.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.core.js +119 -0
- package/dist/lifecycleManager/lifecycleManager.core.js.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.shutdown.d.ts +12 -0
- package/dist/lifecycleManager/lifecycleManager.shutdown.d.ts.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.shutdown.js +57 -0
- package/dist/lifecycleManager/lifecycleManager.shutdown.js.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.startup.d.ts +11 -0
- package/dist/lifecycleManager/lifecycleManager.startup.d.ts.map +1 -0
- package/dist/lifecycleManager/lifecycleManager.startup.js +100 -0
- package/dist/lifecycleManager/lifecycleManager.startup.js.map +1 -0
- package/dist/lifecyclePhase/index.d.ts +7 -0
- package/dist/lifecyclePhase/index.d.ts.map +1 -0
- package/dist/lifecyclePhase/index.js +7 -0
- package/dist/lifecyclePhase/index.js.map +1 -0
- package/dist/lifecyclePhase/lifecyclePhase.core.d.ts +19 -0
- package/dist/lifecyclePhase/lifecyclePhase.core.d.ts.map +1 -0
- package/dist/lifecyclePhase/lifecyclePhase.core.js +52 -0
- package/dist/lifecyclePhase/lifecyclePhase.core.js.map +1 -0
- package/dist/lifecyclePhase/lifecyclePhase.type.d.ts +16 -0
- package/dist/lifecyclePhase/lifecyclePhase.type.d.ts.map +1 -0
- package/dist/lifecyclePhase/lifecyclePhase.type.js +17 -0
- package/dist/lifecyclePhase/lifecyclePhase.type.js.map +1 -0
- package/dist/lifecyclePlan/index.d.ts +8 -0
- package/dist/lifecyclePlan/index.d.ts.map +1 -0
- package/dist/lifecyclePlan/index.js +7 -0
- package/dist/lifecyclePlan/index.js.map +1 -0
- package/dist/lifecyclePlan/lifecyclePlan.core.d.ts +26 -0
- package/dist/lifecyclePlan/lifecyclePlan.core.d.ts.map +1 -0
- package/dist/lifecyclePlan/lifecyclePlan.core.js +40 -0
- package/dist/lifecyclePlan/lifecyclePlan.core.js.map +1 -0
- package/dist/lifecycleRegistry/index.d.ts +7 -0
- package/dist/lifecycleRegistry/index.d.ts.map +1 -0
- package/dist/lifecycleRegistry/index.js +7 -0
- package/dist/lifecycleRegistry/index.js.map +1 -0
- package/dist/lifecycleRegistry/lifecycleRegistry.core.d.ts +35 -0
- package/dist/lifecycleRegistry/lifecycleRegistry.core.d.ts.map +1 -0
- package/dist/lifecycleRegistry/lifecycleRegistry.core.js +87 -0
- package/dist/lifecycleRegistry/lifecycleRegistry.core.js.map +1 -0
- package/dist/lifecycleSignal/index.d.ts +8 -0
- package/dist/lifecycleSignal/index.d.ts.map +1 -0
- package/dist/lifecycleSignal/index.js +7 -0
- package/dist/lifecycleSignal/index.js.map +1 -0
- package/dist/lifecycleSignal/lifecycleSignal.handler.d.ts +20 -0
- package/dist/lifecycleSignal/lifecycleSignal.handler.d.ts.map +1 -0
- package/dist/lifecycleSignal/lifecycleSignal.handler.js +32 -0
- package/dist/lifecycleSignal/lifecycleSignal.handler.js.map +1 -0
- package/dist/lifecycleState/index.d.ts +7 -0
- package/dist/lifecycleState/index.d.ts.map +1 -0
- package/dist/lifecycleState/index.js +7 -0
- package/dist/lifecycleState/index.js.map +1 -0
- package/dist/lifecycleState/lifecycleState.constants.d.ts +16 -0
- package/dist/lifecycleState/lifecycleState.constants.d.ts.map +1 -0
- package/dist/lifecycleState/lifecycleState.constants.js +16 -0
- package/dist/lifecycleState/lifecycleState.constants.js.map +1 -0
- package/dist/lifecycleState/lifecycleState.machine.d.ts +36 -0
- package/dist/lifecycleState/lifecycleState.machine.d.ts.map +1 -0
- package/dist/lifecycleState/lifecycleState.machine.js +57 -0
- package/dist/lifecycleState/lifecycleState.machine.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @latticejs/lifecycle
|
|
2
|
+
|
|
3
|
+
Application and component lifecycle orchestration — state machine, dependency ordering, graceful shutdown, rollback, and signals.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @latticejs/lifecycle
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { /* add usage here */ } from "@latticejs/lifecycle";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle
|
|
3
|
+
*
|
|
4
|
+
* Application and component lifecycle orchestration for the Lattice framework.
|
|
5
|
+
*
|
|
6
|
+
* Manages state machines, dependency ordering, graceful shutdown, rollback,
|
|
7
|
+
* timeouts, retries, and process signals.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createLifecycleManager } from "@oyinlola141/lattice-lifecycle";
|
|
12
|
+
*
|
|
13
|
+
* const lifecycle = createLifecycleManager();
|
|
14
|
+
*
|
|
15
|
+
* lifecycle.register(database, { id: "database", critical: true });
|
|
16
|
+
* lifecycle.register(queue, { id: "queue", dependsOn: ["database"] });
|
|
17
|
+
* lifecycle.register(server, { id: "server", dependsOn: ["queue"] });
|
|
18
|
+
*
|
|
19
|
+
* await lifecycle.start();
|
|
20
|
+
* // ... application running ...
|
|
21
|
+
* await lifecycle.shutdown();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { LifecycleStateMachine } from "./lifecycleState/index.js";
|
|
25
|
+
export { STARTUP_PHASES, SHUTDOWN_PHASES, getPhaseHookName, getComponentMethod, } from "./lifecyclePhase/index.js";
|
|
26
|
+
export type { LifecycleComponent, LifecycleRegistrationOptions, LifecycleRetryOptions, LifecycleRegistration, } from "./lifecycleComponent/index.js";
|
|
27
|
+
export type { LifecycleContext } from "./lifecycleContext/index.js";
|
|
28
|
+
export { createLifecycleContext } from "./lifecycleContext/index.js";
|
|
29
|
+
export { LifecycleRegistry } from "./lifecycleRegistry/index.js";
|
|
30
|
+
export { DependencyGraph, topologicalSort, reverseTopologicalSort, withTimeout, withAbort, withConcurrency, } from "./lifecycleInternal/index.js";
|
|
31
|
+
export type { TopologicalStage } from "./lifecycleInternal/index.js";
|
|
32
|
+
export { buildExecutionPlan } from "./lifecyclePlan/index.js";
|
|
33
|
+
export type { ExecutionStage, ExecutionPlan } from "./lifecyclePlan/index.js";
|
|
34
|
+
export { LifecycleExecutor } from "./lifecycleExecutor/index.js";
|
|
35
|
+
export type { ExecutionResult } from "./lifecycleExecutor/index.js";
|
|
36
|
+
export { LifecycleManager, createLifecycleManager } from "./lifecycleManager/index.js";
|
|
37
|
+
export type { LifecycleManagerOptions } from "./lifecycleManager/index.js";
|
|
38
|
+
export { LifecycleEventEmitter } from "./lifecycleEvents/index.js";
|
|
39
|
+
export type { LifecycleEventType, LifecycleComponentEvent, LifecycleApplicationEvent, LifecycleEvent, LifecycleEventListener, } from "./lifecycleEvents/index.js";
|
|
40
|
+
export { installSignalHandlers, DEFAULT_SHUTDOWN_SIGNALS, } from "./lifecycleSignal/index.js";
|
|
41
|
+
export type { SignalHandlerOptions } from "./lifecycleSignal/index.js";
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,kBAAkB,EAClB,4BAA4B,EAC5B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACvF,YAAY,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,EACd,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latticejs/lifecycle
|
|
3
|
+
*
|
|
4
|
+
* Application and component lifecycle orchestration for the Lattice framework.
|
|
5
|
+
*
|
|
6
|
+
* Manages state machines, dependency ordering, graceful shutdown, rollback,
|
|
7
|
+
* timeouts, retries, and process signals.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createLifecycleManager } from "@latticejs/lifecycle";
|
|
12
|
+
*
|
|
13
|
+
* const lifecycle = createLifecycleManager();
|
|
14
|
+
*
|
|
15
|
+
* lifecycle.register(database, { id: "database", critical: true });
|
|
16
|
+
* lifecycle.register(queue, { id: "queue", dependsOn: ["database"] });
|
|
17
|
+
* lifecycle.register(server, { id: "server", dependsOn: ["queue"] });
|
|
18
|
+
*
|
|
19
|
+
* await lifecycle.start();
|
|
20
|
+
* // ... application running ...
|
|
21
|
+
* await lifecycle.shutdown();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { LifecycleStateMachine } from "./lifecycleState/index.js";
|
|
25
|
+
export { STARTUP_PHASES, SHUTDOWN_PHASES, getPhaseHookName, getComponentMethod, } from "./lifecyclePhase/index.js";
|
|
26
|
+
export { createLifecycleContext } from "./lifecycleContext/index.js";
|
|
27
|
+
export { LifecycleRegistry } from "./lifecycleRegistry/index.js";
|
|
28
|
+
export { DependencyGraph, topologicalSort, reverseTopologicalSort, withTimeout, withAbort, withConcurrency, } from "./lifecycleInternal/index.js";
|
|
29
|
+
export { buildExecutionPlan } from "./lifecyclePlan/index.js";
|
|
30
|
+
export { LifecycleExecutor } from "./lifecycleExecutor/index.js";
|
|
31
|
+
export { LifecycleManager, createLifecycleManager } from "./lifecycleManager/index.js";
|
|
32
|
+
export { LifecycleEventEmitter } from "./lifecycleEvents/index.js";
|
|
33
|
+
export { installSignalHandlers, DEFAULT_SHUTDOWN_SIGNALS, } from "./lifecycleSignal/index.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAQnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAQnE,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/component
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle component interface and registration types.
|
|
5
|
+
*/
|
|
6
|
+
export type { LifecycleComponent, LifecycleRegistrationOptions, LifecycleRetryOptions, LifecycleRegistration, } from "./lifecycleComponent.type.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycleComponent/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,kBAAkB,EAClB,4BAA4B,EAC5B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lifecycleComponent/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/component
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle component interface — the contract for managed resources.
|
|
5
|
+
*/
|
|
6
|
+
import type { LifecycleContext } from "../lifecycleContext/lifecycleContext.type.js";
|
|
7
|
+
/**
|
|
8
|
+
* Interface for components that participate in the lifecycle.
|
|
9
|
+
* All hook methods are optional — components only implement what they need.
|
|
10
|
+
*/
|
|
11
|
+
export interface LifecycleComponent {
|
|
12
|
+
/** Unique name identifying this component. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/** Initialize the component (prepare configuration, create internal objects). */
|
|
15
|
+
initialize?(context: LifecycleContext): Promise<void>;
|
|
16
|
+
/** Start the component (connect to databases, start servers). */
|
|
17
|
+
start?(context: LifecycleContext): Promise<void>;
|
|
18
|
+
/** Confirm the component is ready to serve (health check, warm-up). */
|
|
19
|
+
ready?(context: LifecycleContext): Promise<void>;
|
|
20
|
+
/** Gracefully stop the component (stop accepting work, drain queues). */
|
|
21
|
+
stop?(context: LifecycleContext): Promise<void>;
|
|
22
|
+
/** Final resource cleanup (close connections, clear timers). */
|
|
23
|
+
dispose?(context: LifecycleContext): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** Options for registering a lifecycle component. */
|
|
26
|
+
export interface LifecycleRegistrationOptions {
|
|
27
|
+
/** Unique ID for this component. Defaults to component.name. */
|
|
28
|
+
readonly id?: string;
|
|
29
|
+
/** IDs of components that must start before this one. */
|
|
30
|
+
readonly dependsOn?: readonly string[];
|
|
31
|
+
/** Priority for ordering within the same dependency level. Higher = earlier. */
|
|
32
|
+
readonly priority?: number;
|
|
33
|
+
/** If true, application startup fails when this component fails. Defaults to true. */
|
|
34
|
+
readonly critical?: boolean;
|
|
35
|
+
/** Timeout in ms for individual component operations. */
|
|
36
|
+
readonly timeout?: number;
|
|
37
|
+
/** Retry configuration for failed operations. */
|
|
38
|
+
readonly retry?: LifecycleRetryOptions;
|
|
39
|
+
}
|
|
40
|
+
/** Retry options for component operations. */
|
|
41
|
+
export interface LifecycleRetryOptions {
|
|
42
|
+
/** Maximum number of retry attempts. */
|
|
43
|
+
readonly attempts?: number;
|
|
44
|
+
/** Delay between retries in ms. */
|
|
45
|
+
readonly delay?: number;
|
|
46
|
+
/** Maximum delay between retries in ms. */
|
|
47
|
+
readonly maxDelay?: number;
|
|
48
|
+
/** Backoff strategy. */
|
|
49
|
+
readonly backoff?: "fixed" | "exponential";
|
|
50
|
+
}
|
|
51
|
+
/** A component with its registration metadata. */
|
|
52
|
+
export interface LifecycleRegistration {
|
|
53
|
+
/** Unique ID. */
|
|
54
|
+
readonly id: string;
|
|
55
|
+
/** The component instance. */
|
|
56
|
+
readonly component: LifecycleComponent;
|
|
57
|
+
/** IDs of dependencies. */
|
|
58
|
+
readonly dependsOn: readonly string[];
|
|
59
|
+
/** Priority within same dependency level. */
|
|
60
|
+
readonly priority: number;
|
|
61
|
+
/** Whether failure should abort application startup. */
|
|
62
|
+
readonly critical: boolean;
|
|
63
|
+
/** Timeout in ms for individual operations. */
|
|
64
|
+
readonly timeout: number;
|
|
65
|
+
/** Retry configuration. */
|
|
66
|
+
readonly retry: LifecycleRetryOptions;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=lifecycleComponent.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleComponent.type.d.ts","sourceRoot":"","sources":["../../src/lifecycleComponent/lifecycleComponent.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAErF;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,iFAAiF;IACjF,UAAU,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD,iEAAiE;IACjE,KAAK,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD,uEAAuE;IACvE,KAAK,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD,yEAAyE;IACzE,IAAI,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC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AE,OAAO,CAAC;IAE3B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleComponent.type.js","sourceRoot":"","sources":["../../src/lifecycleComponent/lifecycleComponent.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/context
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle context type and factory.
|
|
5
|
+
*/
|
|
6
|
+
export type { LifecycleContext } from "./lifecycleContext.type.js";
|
|
7
|
+
export { createLifecycleContext } from "./lifecycleContext.type.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycleContext/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lifecycleContext/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/context
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle context — passed to component hooks during phase execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { LifecyclePhase } from "@oyinlola141/lattice-constants";
|
|
7
|
+
/**
|
|
8
|
+
* Context passed to lifecycle component hooks.
|
|
9
|
+
* Provides cancellation, metadata, and phase information.
|
|
10
|
+
*/
|
|
11
|
+
export interface LifecycleContext {
|
|
12
|
+
/** AbortSignal for cancelling long-running operations. */
|
|
13
|
+
readonly signal: AbortSignal;
|
|
14
|
+
/** The current lifecycle phase. */
|
|
15
|
+
readonly phase: LifecyclePhase;
|
|
16
|
+
/** Timestamp when the lifecycle started. */
|
|
17
|
+
readonly startedAt: number;
|
|
18
|
+
/** Arbitrary metadata for the current operation. */
|
|
19
|
+
readonly metadata: ReadonlyMap<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** Creates a lifecycle context. */
|
|
22
|
+
export declare function createLifecycleContext(phase: LifecyclePhase, startedAt: number, signal?: AbortSignal, metadata?: Record<string, unknown>): LifecycleContext;
|
|
23
|
+
//# sourceMappingURL=lifecycleContext.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleContext.type.d.ts","sourceRoot":"","sources":["../../src/lifecycleContext/lifecycleContext.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAE/B,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjD;AAED,mCAAmC;AACnC,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,gBAAgB,CAOlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latticejs/lifecycle/context
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle context — passed to component hooks during phase execution.
|
|
5
|
+
*/
|
|
6
|
+
/** Creates a lifecycle context. */
|
|
7
|
+
export function createLifecycleContext(phase, startedAt, signal, metadata) {
|
|
8
|
+
return {
|
|
9
|
+
signal: signal ?? new AbortController().signal,
|
|
10
|
+
phase,
|
|
11
|
+
startedAt,
|
|
12
|
+
metadata: new Map(Object.entries(metadata ?? {})),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=lifecycleContext.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleContext.type.js","sourceRoot":"","sources":["../../src/lifecycleContext/lifecycleContext.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH,mCAAmC;AACnC,MAAM,UAAU,sBAAsB,CACpC,KAAqB,EACrB,SAAiB,EACjB,MAAoB,EACpB,QAAkC;IAElC,OAAO;QACL,MAAM,EAAE,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC,MAAM;QAC9C,KAAK;QACL,SAAS;QACT,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/events
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle event emitter for observability integration.
|
|
5
|
+
*/
|
|
6
|
+
export { LifecycleEventEmitter } from "./lifecycleEvents.core.js";
|
|
7
|
+
export type { LifecycleEventType, LifecycleComponentEvent, LifecycleApplicationEvent, LifecycleEvent, LifecycleEventListener, } from "./lifecycleEvents.core.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycleEvents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,EACd,sBAAsB,GACvB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lifecycleEvents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/events
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle event emitter — emits typed events for observability integration.
|
|
5
|
+
*/
|
|
6
|
+
/** Lifecycle event types. */
|
|
7
|
+
export type LifecycleEventType = "component:registered" | "component:initializing" | "component:initialized" | "component:starting" | "component:started" | "component:ready" | "component:stopping" | "component:stopped" | "component:failed" | "application:initializing" | "application:initialized" | "application:starting" | "application:ready" | "application:stopping" | "application:stopped" | "application:disposed";
|
|
8
|
+
/** Event payload for component events. */
|
|
9
|
+
export interface LifecycleComponentEvent {
|
|
10
|
+
/** Component ID. */
|
|
11
|
+
readonly componentId: string;
|
|
12
|
+
/** Duration in ms (for completion events). */
|
|
13
|
+
readonly duration?: number;
|
|
14
|
+
/** Error if the event represents a failure. */
|
|
15
|
+
readonly error?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** Event payload for application events. */
|
|
18
|
+
export interface LifecycleApplicationEvent {
|
|
19
|
+
/** Timestamp. */
|
|
20
|
+
readonly timestamp: number;
|
|
21
|
+
/** Duration in ms (for completion events). */
|
|
22
|
+
readonly duration?: number;
|
|
23
|
+
}
|
|
24
|
+
/** A lifecycle event with its type and payload. */
|
|
25
|
+
export interface LifecycleEvent {
|
|
26
|
+
/** The event type. */
|
|
27
|
+
readonly type: LifecycleEventType;
|
|
28
|
+
/** Component payload (for component events). */
|
|
29
|
+
readonly component?: LifecycleComponentEvent;
|
|
30
|
+
/** Duration in ms (for completion events). */
|
|
31
|
+
readonly duration?: number;
|
|
32
|
+
/** Error if the event represents a failure. */
|
|
33
|
+
readonly error?: unknown;
|
|
34
|
+
/** Timestamp. */
|
|
35
|
+
readonly timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
/** Event listener function. */
|
|
38
|
+
export type LifecycleEventListener = (event: LifecycleEvent) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Simple event emitter for lifecycle events.
|
|
41
|
+
* Integrates with observability without depending on the events package.
|
|
42
|
+
*/
|
|
43
|
+
export declare class LifecycleEventEmitter {
|
|
44
|
+
private readonly _listeners;
|
|
45
|
+
/** Subscribes to an event type. */
|
|
46
|
+
on(type: LifecycleEventType, listener: LifecycleEventListener): () => void;
|
|
47
|
+
/** Emits an event. */
|
|
48
|
+
emit(type: LifecycleEventType, data: Omit<LifecycleEvent, "type" | "timestamp">): void;
|
|
49
|
+
/** Removes all listeners. */
|
|
50
|
+
clear(): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=lifecycleEvents.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEvents.core.d.ts","sourceRoot":"","sources":["../../src/lifecycleEvents/lifecycleEvents.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,6BAA6B;AAC7B,MAAM,MAAM,kBAAkB,GAC1B,sBAAsB,GACtB,wBAAwB,GACxB,uBAAuB,GACvB,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,oBAAoB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,0BAA0B,GAC1B,yBAAyB,GACzB,sBAAsB,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,CAAC;AAE3B,0CAA0C;AAC1C,MAAM,WAAW,uB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|
|
1
|
+
/**
|
|
2
|
+
* @latticejs/lifecycle/events
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle event emitter — emits typed events for observability integration.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Simple event emitter for lifecycle events.
|
|
8
|
+
* Integrates with observability without depending on the events package.
|
|
9
|
+
*/
|
|
10
|
+
export class LifecycleEventEmitter {
|
|
11
|
+
_listeners = new Map();
|
|
12
|
+
/** Subscribes to an event type. */
|
|
13
|
+
on(type, listener) {
|
|
14
|
+
if (!this._listeners.has(type)) {
|
|
15
|
+
this._listeners.set(type, new Set());
|
|
16
|
+
}
|
|
17
|
+
this._listeners.get(type).add(listener);
|
|
18
|
+
return () => {
|
|
19
|
+
this._listeners.get(type)?.delete(listener);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Emits an event. */
|
|
23
|
+
emit(type, data) {
|
|
24
|
+
const event = {
|
|
25
|
+
type,
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
...data,
|
|
28
|
+
};
|
|
29
|
+
const listeners = this._listeners.get(type);
|
|
30
|
+
if (listeners) {
|
|
31
|
+
for (const listener of listeners) {
|
|
32
|
+
try {
|
|
33
|
+
listener(event);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Intentional no-op: event listeners must not crash lifecycle operations.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Removes all listeners. */
|
|
42
|
+
clear() {
|
|
43
|
+
this._listeners.clear();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=lifecycleEvents.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEvents.core.js","sourceRoot":"","sources":["../../src/lifecycleEvents/lifecycleEvents.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0DH;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACf,UAAU,GAAG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ecycleExecutor } from "./lifecycleExecutor.core.js";
|
|
7
|
+
export type { ExecutionResult } from "./lifecycleExecutor.core.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycleExecutor/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lifecycleExecutor/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/executor
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle executor — runs component hooks with timeout, retry, and error handling.
|
|
5
|
+
*/
|
|
6
|
+
import type { LifecyclePhase } from "@oyinlola141/lattice-constants";
|
|
7
|
+
import type { LifecycleRegistration } from "../lifecycleComponent/lifecycleComponent.type.js";
|
|
8
|
+
import type { LifecycleContext } from "../lifecycleContext/lifecycleContext.type.js";
|
|
9
|
+
/** Result of executing a component hook. */
|
|
10
|
+
export interface ExecutionResult {
|
|
11
|
+
/** Component ID. */
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** The phase that was executed. */
|
|
14
|
+
readonly phase: LifecyclePhase;
|
|
15
|
+
/** Duration in ms. */
|
|
16
|
+
readonly duration: number;
|
|
17
|
+
/** Error if the hook failed. */
|
|
18
|
+
readonly error?: unknown;
|
|
19
|
+
/** Whether the operation succeeded. */
|
|
20
|
+
readonly success: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Executes lifecycle component hooks with timeout, retry, and concurrency support.
|
|
24
|
+
*/
|
|
25
|
+
export declare class LifecycleExecutor {
|
|
26
|
+
/**
|
|
27
|
+
* Executes a single component hook.
|
|
28
|
+
*/
|
|
29
|
+
execute(registration: LifecycleRegistration, phase: LifecyclePhase, context: LifecycleContext): Promise<ExecutionResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Executes a stage of components in parallel with concurrency limit.
|
|
32
|
+
*/
|
|
33
|
+
executeStage(registrations: readonly LifecycleRegistration[], phase: LifecyclePhase, context: LifecycleContext, concurrency: number): Promise<readonly ExecutionResult[]>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=lifecycleExecutor.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleExecutor.core.d.ts","sourceRoot":"","sources":["../../src/lifecycleExecutor/lifecycleExecutor.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,qBAAqB,EAEtB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAOrF,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B;;OAEG;IACU,OAAO,CAClB,YAAY,EAAE,qBAAqB,EACnC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA2D1B;IAED;;OAEG;IACU,YAAY,CACvB,aAAa,EAAE,SAAS,qBAAqB,EAAE,EAC/C,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,gBAAgB,EACzB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC,CAarC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latticejs/lifecycle/executor
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle executor — runs component hooks with timeout, retry, and error handling.
|
|
5
|
+
*/
|
|
6
|
+
import { withTimeout, withConcurrency } from "../lifecycleInternal/index.js";
|
|
7
|
+
import { getComponentMethod } from "../lifecyclePhase/index.js";
|
|
8
|
+
import { LifecycleComponentError, } from "@latticejs/errors";
|
|
9
|
+
/**
|
|
10
|
+
* Executes lifecycle component hooks with timeout, retry, and concurrency support.
|
|
11
|
+
*/
|
|
12
|
+
export class LifecycleExecutor {
|
|
13
|
+
/**
|
|
14
|
+
* Executes a single component hook.
|
|
15
|
+
*/
|
|
16
|
+
async execute(registration, phase, context) {
|
|
17
|
+
const methodName = getComponentMethod(phase);
|
|
18
|
+
const hook = registration.component[methodName];
|
|
19
|
+
if (typeof hook !== "function") {
|
|
20
|
+
return {
|
|
21
|
+
id: registration.id,
|
|
22
|
+
phase,
|
|
23
|
+
duration: 0,
|
|
24
|
+
success: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
let lastError;
|
|
29
|
+
const retryConfig = registration.retry;
|
|
30
|
+
const maxAttempts = 1 + (retryConfig.attempts ?? 0);
|
|
31
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
32
|
+
try {
|
|
33
|
+
await withTimeout(async () => {
|
|
34
|
+
const result = hook.call(registration.component, context);
|
|
35
|
+
if (result instanceof Promise) {
|
|
36
|
+
await result;
|
|
37
|
+
}
|
|
38
|
+
}, registration.timeout, registration.id, phase);
|
|
39
|
+
return {
|
|
40
|
+
id: registration.id,
|
|
41
|
+
phase,
|
|
42
|
+
duration: Date.now() - startTime,
|
|
43
|
+
success: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
lastError = error;
|
|
48
|
+
if (attempt < maxAttempts - 1) {
|
|
49
|
+
const delay = calculateDelay(retryConfig, attempt);
|
|
50
|
+
await sleep(delay);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
id: registration.id,
|
|
56
|
+
phase,
|
|
57
|
+
duration: Date.now() - startTime,
|
|
58
|
+
error: lastError,
|
|
59
|
+
success: false,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Executes a stage of components in parallel with concurrency limit.
|
|
64
|
+
*/
|
|
65
|
+
async executeStage(registrations, phase, context, concurrency) {
|
|
66
|
+
const results = [];
|
|
67
|
+
await withConcurrency(registrations, concurrency, async (reg) => {
|
|
68
|
+
const result = await this.execute(reg, phase, context);
|
|
69
|
+
results.push(result);
|
|
70
|
+
});
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Calculates retry delay with backoff. */
|
|
75
|
+
function calculateDelay(config, attempt) {
|
|
76
|
+
const base = config.delay ?? 500;
|
|
77
|
+
const max = config.maxDelay ?? 10_000;
|
|
78
|
+
const backoff = config.backoff ?? "exponential";
|
|
79
|
+
if (backoff === "exponential") {
|
|
80
|
+
return Math.min(base * 2 ** attempt, max);
|
|
81
|
+
}
|
|
82
|
+
return base;
|
|
83
|
+
}
|
|
84
|
+
/** Sleeps for the given duration. */
|
|
85
|
+
function sleep(ms) {
|
|
86
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=lifecycleExecutor.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycleEx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,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,aAAa,CAAC;IAEhD,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,OAAO,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qCAAqC;AACrC,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oyinlola141/lattice-lifecycle/internal/async-utils
|
|
3
|
+
*
|
|
4
|
+
* Async utilities for timeout, abort, and concurrency control.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Executes an async operation with a timeout.
|
|
8
|
+
* Throws LifecycleTimeoutError if the timeout is exceeded.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withTimeout<T>(fn: () => Promise<T>, timeoutMs: number, componentId: string, phase: string): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Executes an async operation with abort signal support.
|
|
13
|
+
*/
|
|
14
|
+
export declare function withAbort<T>(fn: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Executes async operations with a concurrency limit.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withConcurrency<T>(items: readonly T[], concurrency: number, fn: (item: T, index: number) => Promise<void>): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=asyncUtils.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncUtils.core.d.ts","sourceRoot":"","sources":["../../src/lifecycleInternal/asyncUtils.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,CAAC,CAAC,CAkBZ;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACvC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,CAAC,CAAC,CAsBZ;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC5C,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|