@sidequest/engine
Version:
@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.
55 lines (53 loc) • 1.77 kB
JavaScript
/**
* Enumeration of available dependency tokens for the dependency registry.
* Used as keys to register and retrieve dependencies throughout the engine.
*/
var Dependency;
(function (Dependency) {
/** Engine configuration */
Dependency["Config"] = "config";
/** Backend instance */
Dependency["Backend"] = "backend";
})(Dependency || (Dependency = {}));
/**
* A type-safe dependency injection container for managing core engine dependencies.
* Provides methods to register, retrieve, and clear dependencies used throughout the engine lifecycle.
*/
class DependencyRegistry {
/**
* Internal storage for registered dependencies.
*/
registry = new Map();
/**
* Retrieves a registered dependency by its token.
* @param token - The dependency token to look up
* @returns The registered dependency instance, or undefined if not found
*/
get(token) {
return this.registry.get(token);
}
/**
* Registers a dependency instance with the specified token.
* @param token - The dependency token to register under
* @param instance - The dependency instance to register
* @returns The registered instance
*/
register(token, instance) {
this.registry.set(token, instance);
return instance;
}
/**
* Clears all registered dependencies from the registry.
* Useful for cleanup and testing scenarios.
*/
clear() {
this.registry.clear();
}
}
/**
* Singleton instance of the dependency registry.
* This is the main container used throughout the engine to manage dependencies.
*/
const dependencyRegistry = new DependencyRegistry();
export { Dependency, dependencyRegistry };
//# sourceMappingURL=dependency-registry.js.map