UNPKG

@opra/common

Version:
63 lines (62 loc) 2.35 kB
import { __decorate, __metadata } from "tslib"; import { toString, validator, vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { DataType } from '../data-type.js'; import { SimpleType } from '../simple-type.js'; let FieldPathType = class FieldPathType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [DECODER](properties, element, scope) { const dataType = properties.dataType ? element.node.getComplexType(properties.dataType) : element.node.getComplexType('object'); const allowSigns = properties.allowSigns; const decodeFieldPath = validator('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns, scope })); return vg.pipe([toString, decodeFieldPath]); } [ENCODER](properties, element, scope) { return this[DECODER](properties, element, scope); } toJSON(properties, element, options) { const dataType = properties.dataType ? element.node.getComplexType(properties.dataType) : element.node.getComplexType('object'); /** Test scope */ DataType.prototype.toJSON.call(dataType, options); const typeName = dataType ? element.node.getDataTypeNameWithNs(dataType) : undefined; return { dataType: typeName ? typeName : dataType.toJSON(options), allowSigns: properties.allowSigns, }; } }; __decorate([ SimpleType.Attribute({ description: 'Data type which field belong to', }), __metadata("design:type", Object) ], FieldPathType.prototype, "dataType", void 0); __decorate([ SimpleType.Attribute({ description: 'Determines if signs (+,-) are allowed. ' + 'If set "first" signs are allowed only beginning of the field path' + 'If set "each" signs are allowed at each field in the path', }), __metadata("design:type", String) ], FieldPathType.prototype, "allowSigns", void 0); FieldPathType = __decorate([ SimpleType({ name: 'fieldpath', description: 'Field path', nameMappings: { js: 'string', json: 'string', }, }), __metadata("design:paramtypes", [Object]) ], FieldPathType); export { FieldPathType };