@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
1 lines • 5.98 kB
Source Map (JSON)
{"version":3,"sources":["../../../packages/core/base/decorators/base.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,mBAAmB;;;;;;;;;EAYlC;AAED;;GAEG;AACH,oBAAY,wBAAwB,GAChC,CAAC,SAAS,SAAS,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAExG;;GAEG;AACH,oBAAY,qBAAqB,GAC7B,CAAC,SAAS,SAAS,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,SAAS,KAAK,IAAI,CAAC;AAEpG;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,iBAAiB,CAAC,EAAE,eAAe,CAAC;IACpC;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CAC3C;AAED;;GAEG;AACH,oBAAY,SAAS,GAAG,cAAc,GAAG,iBAAiB,GAAG,eAAe,GAAG,kBAAkB,CAAC;AAElG;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,GAAG,CAqDhF","file":"base.d.ts","sourcesContent":["import 'reflect-metadata';\r\n\r\n/**\r\n * Gets the Decorator strings from the shell strings on the fly\r\n */\r\nexport function getDecoratorStrings() {\r\n const decoratorStrings = {\r\n Deprecated: {\r\n messageFormat: '\\\"{0}\\\" has been deprecated since {1}. {2} {3}',\r\n alternateSignatureFormat: 'Use \\\"{0}\\\" instead.'\r\n },\r\n Obsolete: {\r\n messageFormat: '\\\"{0}\\\" has been obsolete since {1} and will be removed soon. {2} {3}',\r\n alternateSignatureFormat: 'Use \\\"{0}\\\" instead.'\r\n }\r\n };\r\n return decoratorStrings;\r\n}\r\n\r\n/**\r\n * Describes a function used to modify an instance of a class before its constructor is called\r\n */\r\nexport type InstanceModifierFunction =\r\n <TFunction extends Function>(instance: any, originalConstructor: TFunction, ...args: any[]) => void;\r\n\r\n/**\r\n * Describes a function used to modify an instance of a class before its constructor is called\r\n */\r\nexport type ClassModifierFunction =\r\n <TFunction extends Function>(newConstructor: TFunction, originalConstructor: TFunction) => void;\r\n\r\n/**\r\n * Universal Decorator Options\r\n */\r\nexport interface UniversalDecoratorOptions {\r\n /**\r\n * The name of this decorator\r\n */\r\n name: string;\r\n /**\r\n * The decorator to use if a class decorator is needed\r\n */\r\n classDecorator?: ClassDecorator;\r\n /**\r\n * The decorator to use if a property decorator is needed\r\n */\r\n propertyDecorator?: PropertyDecorator;\r\n /**\r\n * The decorator to use if a accessor decorator is needed\r\n */\r\n accessorDecorator?: MethodDecorator;\r\n /**\r\n * The decorator to use if a method decorator is needed\r\n */\r\n methodDecorator?: MethodDecorator;\r\n /**\r\n * The decorator to use if a parameter decorator is needed\r\n */\r\n parameterDecorator?: ParameterDecorator;\r\n}\r\n\r\n/**\r\n * Generic definition for any Decorator type\r\n */\r\nexport type Decorator = ClassDecorator | PropertyDecorator | MethodDecorator | ParameterDecorator;\r\n\r\n/**\r\n * Enables the creation of a decorator that in turn can be used for any decorator type provided in the options\r\n * @param options The options for this decorator\r\n */\r\nexport function createUniversalDecorator(options: UniversalDecoratorOptions): any {\r\n return function (target: any, property: string | symbol, descriptorOrParameterIndex: PropertyDescriptor | number) {\r\n // Only class decorators have 1 argument\r\n if (arguments.length === 1) {\r\n if (!options.classDecorator) {\r\n throw new SyntaxError(`${options.name} decorator is not supported on classes.`);\r\n }\r\n return options.classDecorator(target);\r\n }\r\n\r\n // Only property decorators have no third argument.\r\n if (descriptorOrParameterIndex === undefined) {\r\n if (!options.propertyDecorator) {\r\n throw new SyntaxError(`${options.name} decorator is not supported on properties.`);\r\n }\r\n return options.propertyDecorator(target, property);\r\n }\r\n\r\n // Parameter decorators have a nuumber as the third argument.\r\n if (MsftSme.isNumber(descriptorOrParameterIndex)) {\r\n if (!options.parameterDecorator) {\r\n throw new SyntaxError(`${options.name} decorator is not supported on parameters.`);\r\n }\r\n return options.parameterDecorator(target, property, descriptorOrParameterIndex as number);\r\n }\r\n\r\n // now we know that the third argument must be a descriptor\r\n const descriptor = descriptorOrParameterIndex as PropertyDescriptor;\r\n\r\n // Method descriptors have a value\r\n if (MsftSme.isFunction(descriptor.value)) {\r\n if (!options.methodDecorator) {\r\n throw new SyntaxError(`${options.name} decorator is not supported on methods.`);\r\n }\r\n return options.methodDecorator(target, property, descriptor);\r\n }\r\n\r\n // Accessor descriptors have a get/set\r\n if (MsftSme.isFunction(descriptor.get) || MsftSme.isFunction(descriptor.set)) {\r\n if (!options.accessorDecorator) {\r\n throw new SyntaxError(`${options.name} decorator is not supported on get/set accessors.`);\r\n }\r\n return options.accessorDecorator(target, property, descriptor);\r\n }\r\n\r\n // if we get here something terrible has happened and we shall be scratching our heads.\r\n const type = MsftSme.getValue(target, 'logSourceName')\r\n || MsftSme.getValue(target, 'name')\r\n || MsftSme.getValue(target, 'constructor.name')\r\n || property\r\n || 'unknown type';\r\n throw new SyntaxError(`${options.name} decorator target not supported on ${type}.`);\r\n };\r\n}\r\n"]}