UNPKG

@clawject/di

Version:

<p align="center"> <a href="https://clawject.com/" target="_blank"><img src="https://clawject.com/img/logo.svg" align="center" alt="Clawject Logo" width="120" height="120" /></a> </p>

48 lines (47 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApplicationConfiguration = void 0; const MetadataStorage_1 = require("../MetadataStorage"); const RuntimeErrors_1 = require("../api/RuntimeErrors"); class ApplicationConfiguration { get index() { if (this._index === null) { throw new RuntimeErrors_1.RuntimeErrors.IllegalStateError('Id not initialized in application configuration'); } return this._index; } get id() { if (this._id === null) { throw new RuntimeErrors_1.RuntimeErrors.IllegalStateError('Id not initialized in application configuration'); } return this._id; } constructor(classConstructor, applicationClassConstructorParameters) { this.classConstructor = classConstructor; this.applicationClassConstructorParameters = applicationClassConstructorParameters; this._instance = null; this._index = null; this._id = null; } init(index, id) { this._index = index; this._id = id; } get metadata() { return this.getMetadataUnsafe(this.classConstructor); } get instance() { if (this._instance === null) { this._instance = new this.classConstructor(...this.applicationClassConstructorParameters); } return this._instance; } getMetadataUnsafe(classConstructor) { const metadata = MetadataStorage_1.MetadataStorage.getApplicationMetadata(classConstructor) ?? MetadataStorage_1.MetadataStorage.getConfigurationMetadata(classConstructor); if (metadata === null) { throw new RuntimeErrors_1.RuntimeErrors.NoClassMetadataFoundError('No configuration metadata found'); } return metadata; } } exports.ApplicationConfiguration = ApplicationConfiguration;