@nasriya/orchestriq
Version:
A package to generate Docker files
38 lines (37 loc) • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Service_1 = __importDefault(require("./assets/Service"));
class ServicesManager {
#_container;
#_services = {};
constructor(container) {
this.#_container = container;
}
/**
* Retrieves a record of all services managed by the ServicesManager.
* @returns {Record<string, Service>} A record containing all the services.
*/
get list() { return this.#_services; }
/**
* Creates a new service and adds it to the container.
* @param options The options for creating the service.
* @returns The created service.
* @throws {Error} If a service with the same name already exists.
* @throws {Error} If the service is marked as the main service and another main service already exists.
*/
create(options) {
if (options?.name in this.#_services) {
throw new Error(`Service with name ${options?.name} already exists.`);
}
if (options?.isMain && Object.values(this.#_services).some(service => service.isMain)) {
throw new Error('There can only be one main service.');
}
const service = new Service_1.default(options, this.#_container);
this.#_services[service.name] = service;
return service;
}
}
exports.default = ServicesManager;