server-prop-types/test.js

20 lines
1012 B
JavaScript

const spt = require('./ServerPropTypes.js');
const type = {
segment_id: { type: 'array', of: 'int', comment: 'Сегмент(ы)' },
init_area: { type: 'num', min: 0.1, required: true, comment: 'Начальное отклонение площади объекта' },
search_order: { type: 'array', of: {
field: { type: 'enum', of2: [ 'area', 'radius', 'pubdate' ], required: true, comment: 'Поле' },
step: { type: 'num', required: true, comment: 'Шаг' },
iter: { type: 'int', required: true, comment: 'Число итераций' },
}, comment: 'Порядок перебора параметров' },
};
console.log(JSON.stringify(spt.check({ type: 'object', items: type }, spt.metaType, { return_error: true }), null, 2));
// Self-validate!
let r = {};
for (let i = 0; i < 1000; i++)
r = spt.check(spt.metaType, spt.metaType, { return_error: true });
console.log(JSON.stringify(spt.check(spt.metaType, spt.metaType, { return_error: true }), null, 2));