UNPKG

@aedart/support

Version:

The Ion support package

91 lines (82 loc) 2.18 kB
/** * @aedart/support * * BSD-3-Clause, Copyright (c) 2023-present Alin Eugen Deac <aedart@gmail.com>. */ 'use strict'; var container = require('@aedart/contracts/container'); var meta = require('@aedart/support/meta'); /** * Define the dependencies that a target requires * * **Note**: _Method is intended to be used as a class or method decorator!_ * * @example * ```js * @dependencies('RockService', 'apiConnection') * class Radio { * * @dependencies(RockSong) * play(song) * } * ``` * * @param {...Identifier[]} identifiers * * @return {ClassDecorator | ClassMethodDecorator} */ function dependencies(...identifiers) { return meta.targetMeta(container.DEPENDENCIES, identifiers); } /** * Alias for [dependencies()]{@link import('@aedart/support/container').dependencies} * * @param {...Identifier[]} identifiers * * @return {ClassDecorator | ClassMethodDecorator} */ function dependsOn(...identifiers) { return dependencies(...identifiers); } /** * Returns the defined dependencies for given target * * @param {object} target * * @return {Identifier[]} Empty identifiers list, if none defined for target */ function getDependencies(target) { return meta.getTargetMeta(target, container.DEPENDENCIES, []); } /** * Determine if target has dependencies defined * * @see dependencies * * @param {object} target * * @return {boolean} */ function hasDependencies(target) { return meta.hasTargetMeta(target, container.DEPENDENCIES); } /** * Determine if value is of the type [Identifier]{@link import('@aedart/contracts/container').Identifier}. * * @param {unknown} value * * @return {boolean} */ function isBindingIdentifier(value) { if (value === undefined || value === null) { return false; } return ['string', 'number', 'symbol', 'object', 'function'].includes(typeof value); } exports.dependencies = dependencies; exports.dependsOn = dependsOn; exports.getDependencies = getDependencies; exports.hasDependencies = hasDependencies; exports.isBindingIdentifier = isBindingIdentifier; module.exports = Object.assign(exports.default, exports); //# sourceMappingURL=container.cjs.map