@opra/common
Version:
Opra common package
66 lines (65 loc) • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldPathType = void 0;
const tslib_1 = require("tslib");
const valgen_1 = require("valgen");
const constants_js_1 = require("../../constants.js");
const data_type_js_1 = require("../data-type.js");
const simple_type_js_1 = require("../simple-type.js");
let FieldPathType = class FieldPathType {
constructor(attributes) {
if (attributes)
Object.assign(this, attributes);
}
[constants_js_1.DECODER](properties, element, scope) {
const dataType = properties.dataType
? element.node.getComplexType(properties.dataType)
: element.node.getComplexType('object');
const allowSigns = properties.allowSigns;
const decodeFieldPath = (0, valgen_1.validator)('decodeFieldPath', (input) => dataType.normalizeFieldPath(input, { allowSigns, scope }));
return valgen_1.vg.pipe([valgen_1.toString, decodeFieldPath]);
}
[constants_js_1.ENCODER](properties, element, scope) {
return this[constants_js_1.DECODER](properties, element, scope);
}
toJSON(properties, element, options) {
const dataType = properties.dataType
? element.node.getComplexType(properties.dataType)
: element.node.getComplexType('object');
/** Test scope */
data_type_js_1.DataType.prototype.toJSON.call(dataType, options);
const typeName = dataType
? element.node.getDataTypeNameWithNs(dataType)
: undefined;
return {
dataType: typeName ? typeName : dataType.toJSON(options),
allowSigns: properties.allowSigns,
};
}
};
exports.FieldPathType = FieldPathType;
tslib_1.__decorate([
simple_type_js_1.SimpleType.Attribute({
description: 'Data type which field belong to',
}),
tslib_1.__metadata("design:type", Object)
], FieldPathType.prototype, "dataType", void 0);
tslib_1.__decorate([
simple_type_js_1.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',
}),
tslib_1.__metadata("design:type", String)
], FieldPathType.prototype, "allowSigns", void 0);
exports.FieldPathType = FieldPathType = tslib_1.__decorate([
(0, simple_type_js_1.SimpleType)({
name: 'fieldpath',
description: 'Field path',
nameMappings: {
js: 'string',
json: 'string',
},
}),
tslib_1.__metadata("design:paramtypes", [Object])
], FieldPathType);