@rxap/xml-parser
Version:
Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into
42 lines • 2.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementClearParser = ElementClearParser;
const reflect_metadata_1 = require("@rxap/reflect-metadata");
const metadata_keys_1 = require("./metadata-keys");
const utilities_1 = require("./utilities");
/**
* Decorator factory that clears specific element parser metadata from a class or its instance.
* It removes metadata entries related to the specified property from both the class and its instances.
*
* @remarks
* This decorator is useful when you need to dynamically alter the parsing behavior associated with
* specific properties of a class, typically used in scenarios involving conditional parsing or
* overriding inherited parsing configurations.
*
* The decorator first retrieves all parser metadata associated with the class and its instances,
* filters out the metadata for the given property, and then resets the metadata without the entries
* for that property.
*
* @param target - The prototype of the class on which the decorator is applied.
* @param propertyKey - The property key for which the parser metadata should be cleared.
*
* Usage:
* Apply `@ElementClearParser()` to a property within a class to clear its associated parser metadata.
*
* Example:
* ```typescript
* @ElementClearParser()
* someProperty: string;
* ```
*/
function ElementClearParser() {
return function (target, propertyKey) {
const clearedParsers = (0, utilities_1.GetAllElementParser)(target.constructor)
.filter(parser => parser.propertyKey !== propertyKey);
const clearedParserInstances = (0, utilities_1.GetAllElementParserInstances)(target.constructor)
.filter(parser => parser.propertyKey !== propertyKey);
(0, reflect_metadata_1.setMetadata)(metadata_keys_1.ElementParserMetaData.PARSER, clearedParsers, target.constructor);
(0, reflect_metadata_1.setMetadata)(metadata_keys_1.ElementParserMetaData.PARSER_INSTANCE, clearedParserInstances, target);
};
}
//# sourceMappingURL=element-clear-parser.js.map