UNPKG

@opra/common

Version:
68 lines (67 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateType = void 0; const tslib_1 = require("tslib"); const valgen_1 = require("valgen"); const constants_js_1 = require("../../constants.js"); const simple_type_js_1 = require("../simple-type.js"); let DateType = class DateType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [constants_js_1.DECODER](properties) { const fn = valgen_1.vg.isDate({ precision: 'date', coerce: true }); const x = []; if (properties.minValue != null) { (0, valgen_1.isDateString)(properties.minValue); x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue)); } if (properties.maxValue != null) { (0, valgen_1.isDateString)(properties.maxValue); x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue)); } return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } [constants_js_1.ENCODER](properties) { const fn = valgen_1.vg.isDateString({ precision: 'date', trim: 'date', coerce: true, }); const x = []; if (properties.minValue != null) { (0, valgen_1.isDateString)(properties.minValue); x.push(valgen_1.vg.isGte(properties.minValue)); } if (properties.maxValue != null) { (0, valgen_1.isDateString)(properties.maxValue); x.push(valgen_1.vg.isLte(properties.maxValue)); } return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } }; exports.DateType = DateType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Minimum value', }), tslib_1.__metadata("design:type", String) ], DateType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Maximum value', }), tslib_1.__metadata("design:type", String) ], DateType.prototype, "maxValue", void 0); exports.DateType = DateType = tslib_1.__decorate([ ((0, simple_type_js_1.SimpleType)({ name: 'date', description: 'A date without time', nameMappings: { js: 'Date', json: 'string', }, }).Example('2021-04-18', 'Full date value')), tslib_1.__metadata("design:paramtypes", [Object]) ], DateType);