lifecycleion 0.0.14 → 0.0.16
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 +1 -1
- package/dist/lib/http-client-node/index.cjs +3 -0
- package/dist/lib/http-client-node/index.cjs.map +1 -1
- package/dist/lib/http-client-node/index.d.cts +7 -0
- package/dist/lib/http-client-node/index.d.ts +7 -0
- package/dist/lib/http-client-node/index.js +3 -0
- package/dist/lib/http-client-node/index.js.map +1 -1
- package/dist/lib/lifecycle-manager/index.cjs +26 -4
- package/dist/lib/lifecycle-manager/index.cjs.map +1 -1
- package/dist/lib/lifecycle-manager/index.d.cts +18 -4
- package/dist/lib/lifecycle-manager/index.d.ts +18 -4
- package/dist/lib/lifecycle-manager/index.js +26 -4
- package/dist/lib/lifecycle-manager/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -438,13 +438,20 @@ interface ValueResult<T = unknown> {
|
|
|
438
438
|
code: 'found' | 'not_found' | 'stopped' | 'stalled' | 'no_handler' | 'error';
|
|
439
439
|
}
|
|
440
440
|
type EventEmitterSurface = Pick<EventEmitterProtected, 'on' | 'once' | 'hasListener' | 'hasListeners' | 'listenerCount'>;
|
|
441
|
+
/**
|
|
442
|
+
* Public value lookup surface shared by LifecycleManager and component-scoped
|
|
443
|
+
* lifecycle references.
|
|
444
|
+
*/
|
|
445
|
+
interface LifecycleValueProvider {
|
|
446
|
+
getValue<T = unknown>(componentName: string, key: string, options?: GetValueOptions): ValueResult<T>;
|
|
447
|
+
}
|
|
441
448
|
/**
|
|
442
449
|
* Common lifecycle interface shared by LifecycleManager and ComponentLifecycle
|
|
443
450
|
*
|
|
444
451
|
* Keep in sync with public LifecycleManager API and ComponentLifecycle proxy.
|
|
445
452
|
* Purpose: define the shared surface both expose to avoid drift across the two.
|
|
446
453
|
*/
|
|
447
|
-
interface LifecycleCommon extends EventEmitterSurface {
|
|
454
|
+
interface LifecycleCommon extends EventEmitterSurface, LifecycleValueProvider {
|
|
448
455
|
hasComponent(name: string): boolean;
|
|
449
456
|
isComponentRunning(name: string): boolean;
|
|
450
457
|
getComponentNames(): string[];
|
|
@@ -479,7 +486,6 @@ interface LifecycleCommon extends EventEmitterSurface {
|
|
|
479
486
|
broadcastMessage(payload: unknown, options?: BroadcastOptions): Promise<BroadcastResult[]>;
|
|
480
487
|
checkComponentHealth(name: string): Promise<HealthCheckResult>;
|
|
481
488
|
checkAllHealth(): Promise<HealthReport>;
|
|
482
|
-
getValue<T = unknown>(componentName: string, key: string, options?: GetValueOptions): ValueResult<T>;
|
|
483
489
|
}
|
|
484
490
|
/**
|
|
485
491
|
* Component-scoped lifecycle interface injected into BaseComponent
|
|
@@ -546,7 +552,7 @@ interface UnregisterOptions {
|
|
|
546
552
|
* Options for starting all components
|
|
547
553
|
*/
|
|
548
554
|
interface StartupOptions {
|
|
549
|
-
/** Allow
|
|
555
|
+
/** Allow bulk startup to proceed by skipping stalled components (default: false) */
|
|
550
556
|
ignoreStalledComponents?: boolean;
|
|
551
557
|
/** Global timeout for entire startup process in milliseconds (default: constructor's startupTimeoutMS) */
|
|
552
558
|
timeoutMS?: number;
|
|
@@ -960,6 +966,8 @@ declare abstract class BaseComponent {
|
|
|
960
966
|
private _unexpectedStopHandler?;
|
|
961
967
|
/** @internal Incremented whenever the unexpected-stop handler is re-armed or cleared. */
|
|
962
968
|
private _unexpectedStopGeneration;
|
|
969
|
+
/** @internal Flag indicating whether this component is currently registered with a LifecycleManager */
|
|
970
|
+
private _isRegistered;
|
|
963
971
|
/**
|
|
964
972
|
* Create a new component
|
|
965
973
|
*
|
|
@@ -972,6 +980,12 @@ declare abstract class BaseComponent {
|
|
|
972
980
|
_setUnexpectedStopHandler(handler: (error?: Error) => boolean): void;
|
|
973
981
|
/** @internal Called by LifecycleManager when stop begins or component is unregistered. */
|
|
974
982
|
_clearUnexpectedStopHandler(): void;
|
|
983
|
+
/** @internal Called by LifecycleManager when registering the component. */
|
|
984
|
+
_markRegistered(): void;
|
|
985
|
+
/** @internal Called by LifecycleManager when unregistering the component. */
|
|
986
|
+
_markUnregistered(): void;
|
|
987
|
+
/** @internal Check if the component is registered with any LifecycleManager. */
|
|
988
|
+
_isRegisteredWithManager(): boolean;
|
|
975
989
|
/**
|
|
976
990
|
* Start the component
|
|
977
991
|
*
|
|
@@ -2404,4 +2418,4 @@ declare const lifecycleManagerErrCodes: {
|
|
|
2404
2418
|
readonly StopTimeout: "StopTimeout";
|
|
2405
2419
|
};
|
|
2406
2420
|
|
|
2407
|
-
export { BaseComponent, type BaseOperationResult, type BroadcastOptions, type BroadcastResult, type ComponentHealthResult, ComponentNotFoundError, type ComponentOperationFailureCode, type ComponentOperationResult, type ComponentOptions, ComponentRegistrationError, type ComponentSignalResult, type ComponentStallInfo, ComponentStartTimeoutError, ComponentStartupError, type ComponentState, type ComponentStatus, ComponentStopTimeoutError, type ComponentValueResult, DependencyCycleError, type DependencyValidationResult, type ForceShutdownContext, type GetValueOptions, type HealthCheckResult, type HealthReport, type InsertComponentAtResult, type InsertPosition, InvalidComponentNameError, LifecycleManager, type LifecycleManagerEmit, type LifecycleManagerEventMap, type LifecycleManagerEventName, LifecycleManagerEvents, type LifecycleManagerOptions, type LifecycleManagerStatus, type MessageResult, MissingDependencyError, type RegisterComponentResult, type RegisterOptions, type RegistrationFailureCode, type RepeatedShutdownRequestPolicy, type RestartComponentOptions, type RestartResult, type SendMessageOptions, type ShutdownEscalationStatus, type ShutdownMethod, type ShutdownResult, type SignalBroadcastResult, type StartComponentOptions, type StartupOptions, type StartupOrderFailureCode, type StartupOrderResult, type StartupResult, StartupTimeoutError, type StopAllOptions, type StopComponentOptions, type SystemState, type UnregisterComponentResult, type UnregisterFailureCode, type UnregisterOptions, type ValueResult, lifecycleManagerErrCodes, lifecycleManagerErrPrefix, lifecycleManagerErrTypes };
|
|
2421
|
+
export { BaseComponent, type BaseOperationResult, type BroadcastOptions, type BroadcastResult, type ComponentHealthResult, ComponentNotFoundError, type ComponentOperationFailureCode, type ComponentOperationResult, type ComponentOptions, ComponentRegistrationError, type ComponentSignalResult, type ComponentStallInfo, ComponentStartTimeoutError, ComponentStartupError, type ComponentState, type ComponentStatus, ComponentStopTimeoutError, type ComponentValueResult, DependencyCycleError, type DependencyValidationResult, type ForceShutdownContext, type GetValueOptions, type HealthCheckResult, type HealthReport, type InsertComponentAtResult, type InsertPosition, InvalidComponentNameError, LifecycleManager, type LifecycleManagerEmit, type LifecycleManagerEventMap, type LifecycleManagerEventName, LifecycleManagerEvents, type LifecycleManagerOptions, type LifecycleManagerStatus, type LifecycleValueProvider, type MessageResult, MissingDependencyError, type RegisterComponentResult, type RegisterOptions, type RegistrationFailureCode, type RepeatedShutdownRequestPolicy, type RestartComponentOptions, type RestartResult, type SendMessageOptions, type ShutdownEscalationStatus, type ShutdownMethod, type ShutdownResult, type SignalBroadcastResult, type StartComponentOptions, type StartupOptions, type StartupOrderFailureCode, type StartupOrderResult, type StartupResult, StartupTimeoutError, type StopAllOptions, type StopComponentOptions, type SystemState, type UnregisterComponentResult, type UnregisterFailureCode, type UnregisterOptions, type ValueResult, lifecycleManagerErrCodes, lifecycleManagerErrPrefix, lifecycleManagerErrTypes };
|
|
@@ -438,13 +438,20 @@ interface ValueResult<T = unknown> {
|
|
|
438
438
|
code: 'found' | 'not_found' | 'stopped' | 'stalled' | 'no_handler' | 'error';
|
|
439
439
|
}
|
|
440
440
|
type EventEmitterSurface = Pick<EventEmitterProtected, 'on' | 'once' | 'hasListener' | 'hasListeners' | 'listenerCount'>;
|
|
441
|
+
/**
|
|
442
|
+
* Public value lookup surface shared by LifecycleManager and component-scoped
|
|
443
|
+
* lifecycle references.
|
|
444
|
+
*/
|
|
445
|
+
interface LifecycleValueProvider {
|
|
446
|
+
getValue<T = unknown>(componentName: string, key: string, options?: GetValueOptions): ValueResult<T>;
|
|
447
|
+
}
|
|
441
448
|
/**
|
|
442
449
|
* Common lifecycle interface shared by LifecycleManager and ComponentLifecycle
|
|
443
450
|
*
|
|
444
451
|
* Keep in sync with public LifecycleManager API and ComponentLifecycle proxy.
|
|
445
452
|
* Purpose: define the shared surface both expose to avoid drift across the two.
|
|
446
453
|
*/
|
|
447
|
-
interface LifecycleCommon extends EventEmitterSurface {
|
|
454
|
+
interface LifecycleCommon extends EventEmitterSurface, LifecycleValueProvider {
|
|
448
455
|
hasComponent(name: string): boolean;
|
|
449
456
|
isComponentRunning(name: string): boolean;
|
|
450
457
|
getComponentNames(): string[];
|
|
@@ -479,7 +486,6 @@ interface LifecycleCommon extends EventEmitterSurface {
|
|
|
479
486
|
broadcastMessage(payload: unknown, options?: BroadcastOptions): Promise<BroadcastResult[]>;
|
|
480
487
|
checkComponentHealth(name: string): Promise<HealthCheckResult>;
|
|
481
488
|
checkAllHealth(): Promise<HealthReport>;
|
|
482
|
-
getValue<T = unknown>(componentName: string, key: string, options?: GetValueOptions): ValueResult<T>;
|
|
483
489
|
}
|
|
484
490
|
/**
|
|
485
491
|
* Component-scoped lifecycle interface injected into BaseComponent
|
|
@@ -546,7 +552,7 @@ interface UnregisterOptions {
|
|
|
546
552
|
* Options for starting all components
|
|
547
553
|
*/
|
|
548
554
|
interface StartupOptions {
|
|
549
|
-
/** Allow
|
|
555
|
+
/** Allow bulk startup to proceed by skipping stalled components (default: false) */
|
|
550
556
|
ignoreStalledComponents?: boolean;
|
|
551
557
|
/** Global timeout for entire startup process in milliseconds (default: constructor's startupTimeoutMS) */
|
|
552
558
|
timeoutMS?: number;
|
|
@@ -960,6 +966,8 @@ declare abstract class BaseComponent {
|
|
|
960
966
|
private _unexpectedStopHandler?;
|
|
961
967
|
/** @internal Incremented whenever the unexpected-stop handler is re-armed or cleared. */
|
|
962
968
|
private _unexpectedStopGeneration;
|
|
969
|
+
/** @internal Flag indicating whether this component is currently registered with a LifecycleManager */
|
|
970
|
+
private _isRegistered;
|
|
963
971
|
/**
|
|
964
972
|
* Create a new component
|
|
965
973
|
*
|
|
@@ -972,6 +980,12 @@ declare abstract class BaseComponent {
|
|
|
972
980
|
_setUnexpectedStopHandler(handler: (error?: Error) => boolean): void;
|
|
973
981
|
/** @internal Called by LifecycleManager when stop begins or component is unregistered. */
|
|
974
982
|
_clearUnexpectedStopHandler(): void;
|
|
983
|
+
/** @internal Called by LifecycleManager when registering the component. */
|
|
984
|
+
_markRegistered(): void;
|
|
985
|
+
/** @internal Called by LifecycleManager when unregistering the component. */
|
|
986
|
+
_markUnregistered(): void;
|
|
987
|
+
/** @internal Check if the component is registered with any LifecycleManager. */
|
|
988
|
+
_isRegisteredWithManager(): boolean;
|
|
975
989
|
/**
|
|
976
990
|
* Start the component
|
|
977
991
|
*
|
|
@@ -2404,4 +2418,4 @@ declare const lifecycleManagerErrCodes: {
|
|
|
2404
2418
|
readonly StopTimeout: "StopTimeout";
|
|
2405
2419
|
};
|
|
2406
2420
|
|
|
2407
|
-
export { BaseComponent, type BaseOperationResult, type BroadcastOptions, type BroadcastResult, type ComponentHealthResult, ComponentNotFoundError, type ComponentOperationFailureCode, type ComponentOperationResult, type ComponentOptions, ComponentRegistrationError, type ComponentSignalResult, type ComponentStallInfo, ComponentStartTimeoutError, ComponentStartupError, type ComponentState, type ComponentStatus, ComponentStopTimeoutError, type ComponentValueResult, DependencyCycleError, type DependencyValidationResult, type ForceShutdownContext, type GetValueOptions, type HealthCheckResult, type HealthReport, type InsertComponentAtResult, type InsertPosition, InvalidComponentNameError, LifecycleManager, type LifecycleManagerEmit, type LifecycleManagerEventMap, type LifecycleManagerEventName, LifecycleManagerEvents, type LifecycleManagerOptions, type LifecycleManagerStatus, type MessageResult, MissingDependencyError, type RegisterComponentResult, type RegisterOptions, type RegistrationFailureCode, type RepeatedShutdownRequestPolicy, type RestartComponentOptions, type RestartResult, type SendMessageOptions, type ShutdownEscalationStatus, type ShutdownMethod, type ShutdownResult, type SignalBroadcastResult, type StartComponentOptions, type StartupOptions, type StartupOrderFailureCode, type StartupOrderResult, type StartupResult, StartupTimeoutError, type StopAllOptions, type StopComponentOptions, type SystemState, type UnregisterComponentResult, type UnregisterFailureCode, type UnregisterOptions, type ValueResult, lifecycleManagerErrCodes, lifecycleManagerErrPrefix, lifecycleManagerErrTypes };
|
|
2421
|
+
export { BaseComponent, type BaseOperationResult, type BroadcastOptions, type BroadcastResult, type ComponentHealthResult, ComponentNotFoundError, type ComponentOperationFailureCode, type ComponentOperationResult, type ComponentOptions, ComponentRegistrationError, type ComponentSignalResult, type ComponentStallInfo, ComponentStartTimeoutError, ComponentStartupError, type ComponentState, type ComponentStatus, ComponentStopTimeoutError, type ComponentValueResult, DependencyCycleError, type DependencyValidationResult, type ForceShutdownContext, type GetValueOptions, type HealthCheckResult, type HealthReport, type InsertComponentAtResult, type InsertPosition, InvalidComponentNameError, LifecycleManager, type LifecycleManagerEmit, type LifecycleManagerEventMap, type LifecycleManagerEventName, LifecycleManagerEvents, type LifecycleManagerOptions, type LifecycleManagerStatus, type LifecycleValueProvider, type MessageResult, MissingDependencyError, type RegisterComponentResult, type RegisterOptions, type RegistrationFailureCode, type RepeatedShutdownRequestPolicy, type RestartComponentOptions, type RestartResult, type SendMessageOptions, type ShutdownEscalationStatus, type ShutdownMethod, type ShutdownResult, type SignalBroadcastResult, type StartComponentOptions, type StartupOptions, type StartupOrderFailureCode, type StartupOrderResult, type StartupResult, StartupTimeoutError, type StopAllOptions, type StopComponentOptions, type SystemState, type UnregisterComponentResult, type UnregisterFailureCode, type UnregisterOptions, type ValueResult, lifecycleManagerErrCodes, lifecycleManagerErrPrefix, lifecycleManagerErrTypes };
|
|
@@ -1427,6 +1427,7 @@ var LIFECYCLE_MANAGER_LOG_REQUIRED_COMPONENT_UNEXPECTED_STOP_DURING_STARTUP = "R
|
|
|
1427
1427
|
var LIFECYCLE_MANAGER_MESSAGE_REGISTER_SHUTDOWN_IN_PROGRESS = "Cannot register component while shutdown is in progress (isShuttingDown=true).";
|
|
1428
1428
|
var LIFECYCLE_MANAGER_MESSAGE_REGISTER_REQUIRED_DEPENDENCY_DURING_STARTUP = "Cannot register component during startup when it is a required dependency for other components.";
|
|
1429
1429
|
var LIFECYCLE_MANAGER_MESSAGE_DUPLICATE_COMPONENT_INSTANCE = "Component instance is already registered.";
|
|
1430
|
+
var LIFECYCLE_MANAGER_MESSAGE_DUPLICATE_COMPONENT_INSTANCE_EXTERNAL = "Component instance is already registered with another lifecycle manager.";
|
|
1430
1431
|
|
|
1431
1432
|
// src/lib/process-signal-manager.ts
|
|
1432
1433
|
import { ulid } from "ulid";
|
|
@@ -2216,6 +2217,7 @@ var LifecycleManager = class extends EventEmitterProtected {
|
|
|
2216
2217
|
}
|
|
2217
2218
|
this.components = this.components.filter((c) => c.getName() !== name);
|
|
2218
2219
|
component._clearUnexpectedStopHandler();
|
|
2220
|
+
component._markUnregistered();
|
|
2219
2221
|
this.componentStates.delete(name);
|
|
2220
2222
|
this.componentTimestamps.delete(name);
|
|
2221
2223
|
this.componentErrors.delete(name);
|
|
@@ -3934,12 +3936,16 @@ var LifecycleManager = class extends EventEmitterProtected {
|
|
|
3934
3936
|
targetFound: void 0
|
|
3935
3937
|
});
|
|
3936
3938
|
}
|
|
3937
|
-
if (
|
|
3938
|
-
this.
|
|
3939
|
+
if (component._isRegisteredWithManager()) {
|
|
3940
|
+
const isRegisteredHere = this.hasComponentInstance(component);
|
|
3941
|
+
const message = isRegisteredHere ? LIFECYCLE_MANAGER_MESSAGE_DUPLICATE_COMPONENT_INSTANCE : LIFECYCLE_MANAGER_MESSAGE_DUPLICATE_COMPONENT_INSTANCE_EXTERNAL;
|
|
3942
|
+
this.logger.entity(componentName).warn(
|
|
3943
|
+
isRegisteredHere ? "Component instance already registered" : "Component instance already registered with another lifecycle manager"
|
|
3944
|
+
);
|
|
3939
3945
|
this.lifecycleEvents.componentRegistrationRejected({
|
|
3940
3946
|
name: componentName,
|
|
3941
3947
|
reason: "duplicate_instance",
|
|
3942
|
-
message
|
|
3948
|
+
message,
|
|
3943
3949
|
registrationIndexBefore,
|
|
3944
3950
|
registrationIndexAfter: registrationIndexBefore,
|
|
3945
3951
|
requestedPosition: isInsertAction ? { position, targetComponentName } : void 0,
|
|
@@ -3951,7 +3957,7 @@ var LifecycleManager = class extends EventEmitterProtected {
|
|
|
3951
3957
|
targetComponentName,
|
|
3952
3958
|
registrationIndexBefore,
|
|
3953
3959
|
code: "duplicate_instance",
|
|
3954
|
-
reason:
|
|
3960
|
+
reason: message,
|
|
3955
3961
|
targetFound: void 0
|
|
3956
3962
|
});
|
|
3957
3963
|
}
|
|
@@ -4064,6 +4070,7 @@ var LifecycleManager = class extends EventEmitterProtected {
|
|
|
4064
4070
|
getValueInternal: (compName, key, from) => this.getValueInternal(compName, key, from)
|
|
4065
4071
|
};
|
|
4066
4072
|
component.lifecycle = new ComponentLifecycle(this, componentName, internalCallbacks);
|
|
4073
|
+
component._markRegistered();
|
|
4067
4074
|
this.componentStates.set(componentName, "registered");
|
|
4068
4075
|
this.componentTimestamps.set(componentName, {
|
|
4069
4076
|
startedAt: null,
|
|
@@ -6340,6 +6347,8 @@ var BaseComponent = class {
|
|
|
6340
6347
|
_unexpectedStopHandler;
|
|
6341
6348
|
/** @internal Incremented whenever the unexpected-stop handler is re-armed or cleared. */
|
|
6342
6349
|
_unexpectedStopGeneration = 0;
|
|
6350
|
+
/** @internal Flag indicating whether this component is currently registered with a LifecycleManager */
|
|
6351
|
+
_isRegistered = false;
|
|
6343
6352
|
/**
|
|
6344
6353
|
* Create a new component
|
|
6345
6354
|
*
|
|
@@ -6392,6 +6401,19 @@ var BaseComponent = class {
|
|
|
6392
6401
|
this._unexpectedStopHandler = void 0;
|
|
6393
6402
|
this.reportUnexpectedStop = () => false;
|
|
6394
6403
|
}
|
|
6404
|
+
/** @internal Called by LifecycleManager when registering the component. */
|
|
6405
|
+
_markRegistered() {
|
|
6406
|
+
this._isRegistered = true;
|
|
6407
|
+
}
|
|
6408
|
+
/** @internal Called by LifecycleManager when unregistering the component. */
|
|
6409
|
+
_markUnregistered() {
|
|
6410
|
+
this._isRegistered = false;
|
|
6411
|
+
this.lifecycle = void 0;
|
|
6412
|
+
}
|
|
6413
|
+
/** @internal Check if the component is registered with any LifecycleManager. */
|
|
6414
|
+
_isRegisteredWithManager() {
|
|
6415
|
+
return this._isRegistered;
|
|
6416
|
+
}
|
|
6395
6417
|
/**
|
|
6396
6418
|
* Get component name
|
|
6397
6419
|
*/
|