@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>
35 lines (34 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bean = void 0;
const ErrorBuilder_1 = require("../../ErrorBuilder");
const RuntimeErrors_1 = require("../RuntimeErrors");
/**
* Indicates that a method/property produces/contains a bean or a bean constructor
* to be managed by the Clawject container.
*
* @docs https://clawject.com/docs/fundamentals/bean
*
* @public
*/
const Bean = (...args) => {
if (args.length === 1 && typeof args[0] === 'function') {
return {
constructor: args[0],
factory: (...constructorArgs) => new args[0](...constructorArgs)
};
}
if (args.length === 1 && args[0] instanceof Promise) {
return args[0].then((constructor) => {
return {
constructor,
factory: (...constructorArgs) => new constructor(...constructorArgs)
};
});
}
if (args.length === 1) {
throw new RuntimeErrors_1.RuntimeErrors.IllegalArgumentError('Argument must be a class constructor or a promise of a class constructor');
}
throw ErrorBuilder_1.ErrorBuilder.usageWithoutConfiguredDI('@Bean');
};
exports.Bean = Bean;