UNPKG

@tjc-group/odata-v2-service-metadata

Version:

Limited version of OData metadata response for OData V2, based on odata-v4-service-metadata

77 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // function isFunction(o: any) { // return "function" === typeof o // } function isUndefined(o) { return o === undefined; } const definitionPropName = 'definition'; class MemberAttribute { constructor(attributeName) { this.attributeName = attributeName; } registerMember(target, key) { var def = target[definitionPropName] = target[definitionPropName] || {}; let md = (def.members || []); if (md.indexOf(key) < 0) { md.push(key); } def.members = md; } getDecoratorValue(_target, _key, presentedValue) { return presentedValue; } decorate(value) { return (target, key, _descriptor) => { this.registerMember(target, key); var decoratorValue = this.getDecoratorValue(target, key, value); target[definitionPropName][this.attributeName] = target[definitionPropName][this.attributeName] || {}; target[definitionPropName][this.attributeName][key] = decoratorValue; }; } get decorator() { return this.decorate(); } static getMembers(target) { return target[definitionPropName].members; } static getAttributeValue(target, memberName, attributeName) { return ((target[definitionPropName] || {})[attributeName] || {})[memberName]; } } exports.MemberAttribute = MemberAttribute; class AttributeFunctionChain { constructor(...steps) { this.steps = []; this.steps = steps; } invoke(definition, instance) { var result = definition; this.steps.forEach(fn => { result = fn(result, instance); }); return result; } } exports.AttributeFunctionChain = AttributeFunctionChain; class ParseAttribute extends MemberAttribute { constructor() { super("serialize"); } getDecoratorValue(_target, key, presentedValue) { if (!isUndefined(presentedValue)) { return presentedValue; } return new AttributeFunctionChain(d => d[key]); } } exports.ParseAttribute = ParseAttribute; exports.required = new MemberAttribute("required").decorate(true); exports.defaultValueAttribute = new MemberAttribute("defaultValue"); exports.defaultValue = exports.defaultValueAttribute.decorate.bind(exports.defaultValueAttribute); exports.parseAttribute = new ParseAttribute(); exports.parse = exports.parseAttribute.decorator; exports.parseAs = exports.parseAttribute.decorate.bind(exports.parseAttribute); exports.typeArgument = new MemberAttribute("typeArgument"); //# sourceMappingURL=metacode.js.map