12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- if (typeof b !== "function" && b !== null)
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- import { getDependencyByIndex, IdentifierUndefinedError, setDependency, } from './decorators';
- import { prettyPrintIdentifier } from './dependencyItem';
- import { RediError } from './error';
- import { Quantity } from './types';
- var QuantityCheckError = /** @class */ (function (_super) {
- __extends(QuantityCheckError, _super);
- function QuantityCheckError(id, quantity, actual) {
- var msg = "Expect \"".concat(quantity, "\" dependency items for id \"").concat(prettyPrintIdentifier(id), "\" but get ").concat(actual, ".");
- return _super.call(this, msg) || this;
- }
- return QuantityCheckError;
- }(RediError));
- export function checkQuantity(id, quantity, length) {
- if ((quantity === Quantity.OPTIONAL && length > 1) ||
- (quantity === Quantity.REQUIRED && length !== 1)) {
- throw new QuantityCheckError(id, quantity, length);
- }
- }
- export function retrieveQuantity(quantity, arr) {
- if (quantity === Quantity.MANY) {
- return arr;
- }
- else {
- return arr[0];
- }
- }
- function changeQuantity(target, index, quantity) {
- var descriptor = getDependencyByIndex(target, index);
- descriptor.quantity = quantity;
- }
- function quantifyDecoratorFactoryProducer(quantity) {
- return function decoratorFactory(id) {
- if (this instanceof decoratorFactory) {
- return this;
- }
- return function (registerTarget, _key, index) {
- if (id) {
- setDependency(registerTarget, id, index, quantity);
- }
- else {
- if (quantity === Quantity.REQUIRED) {
- throw new IdentifierUndefinedError(registerTarget, index);
- }
- changeQuantity(registerTarget, index, quantity);
- }
- };
- };
- }
- export var Many = quantifyDecoratorFactoryProducer(Quantity.MANY);
- export var Optional = quantifyDecoratorFactoryProducer(Quantity.OPTIONAL);
- export var Inject = quantifyDecoratorFactoryProducer(Quantity.REQUIRED);
- //# sourceMappingURL=dependencyQuantity.js.map
|