@dolittle/sdk.common
Version:
Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.
45 lines • 4.21 kB
JavaScript
;
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DecoratorAppliedMultipleTimes = void 0;
const DecoratorTarget_1 = require("./DecoratorTarget");
/**
* The exception that gets thrown when a decorator that is only permitted once is applied multiple times to the same target.
*/
class DecoratorAppliedMultipleTimes extends Error {
/**
* Initialises a new instance of the {@link DecoratorAppliedMultipleTimes} class.
* @param {string} displayName - The display name of the decorator.
* @param {DecoratorTarget} decoratedTarget - The type of the decorated target.
* @param {Constructor<any>} type - The class that was decorated.
* @param {Function | Object} target - The decorated target.
* @param {string | symbol} [propertyKey] - An optional decorated property key.
* @param {PropertyDescriptor | number} [descriptorOrIndex] - An optional decorated descriptor or index.
*/
constructor(displayName, decoratedTarget, type, target, propertyKey, descriptorOrIndex) {
super(`The @${displayName} decorator was applied to ${DecoratorAppliedMultipleTimes.getDecoratedTarget(decoratedTarget, type, target, propertyKey, descriptorOrIndex)} in ${type.name} multiple times. Only one is permitted.`);
}
static getDecoratedTarget(decoratedTarget, type, target, propertyKey, descriptorOrIndex) {
switch (decoratedTarget) {
case DecoratorTarget_1.DecoratorTarget.Class:
return 'the class';
case DecoratorTarget_1.DecoratorTarget.ConstructorParameter:
return `constructor parameter ${descriptorOrIndex}`;
case DecoratorTarget_1.DecoratorTarget.Method:
return `method ${propertyKey.toString()}`;
case DecoratorTarget_1.DecoratorTarget.MethodParameter:
return `method ${propertyKey.toString()} parameter ${descriptorOrIndex}`;
case DecoratorTarget_1.DecoratorTarget.Property:
return `property ${propertyKey.toString()}`;
case DecoratorTarget_1.DecoratorTarget.Setter:
return `setter ${propertyKey.toString()}`;
case DecoratorTarget_1.DecoratorTarget.Getter:
return `getter ${propertyKey.toString()}`;
case DecoratorTarget_1.DecoratorTarget.All:
return '';
}
}
}
exports.DecoratorA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