kentico-cloud-delivery
Version:
Official Kentico Cloud Delivery SDK
29 lines • 1.16 kB
JavaScript
import 'reflect-metadata';
export var FieldDecorators;
(function (FieldDecorators) {
var codenameMetadataKey = Symbol('codename');
var generateKey = function (name) {
return codenameMetadataKey.toString() + ":" + name;
};
/**
* Get the metadata entry saved by the decorator
* @param target - object instance
* @param fieldName - field name (code name from Kentico Cloud)
*/
function getPropertyName(target, fieldName) {
return Reflect.getMetadata(generateKey(fieldName), target);
}
FieldDecorators.getPropertyName = getPropertyName;
/**
* Decorator - reates metadata entry for the @target - Value is the property name.
* This will then be retrieved in the FieldMap service when resolving the field name
* @param value - field code name
*/
function codename(value) {
return function (target, propertyKey) {
Reflect.defineMetadata(generateKey(value), propertyKey, target);
};
}
FieldDecorators.codename = codename;
})(FieldDecorators || (FieldDecorators = {}));
//# sourceMappingURL=field-decorators.js.map