@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
72 lines (70 loc) • 3.21 kB
JavaScript
import 'reflect-metadata';
/**
* Gets the Decorator strings from the shell strings on the fly
*/
export function getDecoratorStrings() {
const decoratorStrings = {
Deprecated: {
messageFormat: '\"{0}\" has been deprecated since {1}. {2} {3}',
alternateSignatureFormat: 'Use \"{0}\" instead.'
},
Obsolete: {
messageFormat: '\"{0}\" has been obsolete since {1} and will be removed soon. {2} {3}',
alternateSignatureFormat: 'Use \"{0}\" instead.'
}
};
return decoratorStrings;
}
/**
* Enables the creation of a decorator that in turn can be used for any decorator type provided in the options
* @param options The options for this decorator
*/
export function createUniversalDecorator(options) {
return function (target, property, descriptorOrParameterIndex) {
// Only class decorators have 1 argument
if (arguments.length === 1) {
if (!options.classDecorator) {
throw new SyntaxError(`${options.name} decorator is not supported on classes.`);
}
return options.classDecorator(target);
}
// Only property decorators have no third argument.
if (descriptorOrParameterIndex === undefined) {
if (!options.propertyDecorator) {
throw new SyntaxError(`${options.name} decorator is not supported on properties.`);
}
return options.propertyDecorator(target, property);
}
// Parameter decorators have a nuumber as the third argument.
if (MsftSme.isNumber(descriptorOrParameterIndex)) {
if (!options.parameterDecorator) {
throw new SyntaxError(`${options.name} decorator is not supported on parameters.`);
}
return options.parameterDecorator(target, property, descriptorOrParameterIndex);
}
// now we know that the third argument must be a descriptor
const descriptor = descriptorOrParameterIndex;
// Method descriptors have a value
if (MsftSme.isFunction(descriptor.value)) {
if (!options.methodDecorator) {
throw new SyntaxError(`${options.name} decorator is not supported on methods.`);
}
return options.methodDecorator(target, property, descriptor);
}
// Accessor descriptors have a get/set
if (MsftSme.isFunction(descriptor.get) || MsftSme.isFunction(descriptor.set)) {
if (!options.accessorDecorator) {
throw new SyntaxError(`${options.name} decorator is not supported on get/set accessors.`);
}
return options.accessorDecorator(target, property, descriptor);
}
// if we get here something terrible has happened and we shall be scratching our heads.
const type = MsftSme.getValue(target, 'logSourceName')
|| MsftSme.getValue(target, 'name')
|| MsftSme.getValue(target, 'constructor.name')
|| property
|| 'unknown type';
throw new SyntaxError(`${options.name} decorator target not supported on ${type}.`);
};
}
//# sourceMappingURL=base.js.map