2018-12-01 12:03:47 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-31 22:15:09 +02:00
|
|
|
const joi = require('joi');
|
2018-12-12 10:09:38 +01:00
|
|
|
const { nameType } = require('./util');
|
|
|
|
|
|
|
|
const nameSchema = joi.object().keys({ name: nameType });
|
2018-12-01 12:03:47 +01:00
|
|
|
|
2019-11-20 22:11:30 +01:00
|
|
|
const constraintSchema = joi.object().keys({
|
|
|
|
contextName: joi.string(),
|
|
|
|
operator: joi.string(),
|
|
|
|
values: joi.array().items(joi.string()),
|
|
|
|
});
|
|
|
|
|
2018-12-01 12:03:47 +01:00
|
|
|
const strategiesSchema = joi.object().keys({
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
2019-11-20 22:11:30 +01:00
|
|
|
constraints: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.items(constraintSchema),
|
2018-12-01 12:03:47 +01:00
|
|
|
parameters: joi.object(),
|
|
|
|
});
|
|
|
|
|
2018-01-30 15:57:12 +01:00
|
|
|
const variantsSchema = joi.object().keys({
|
|
|
|
name: nameType,
|
2019-01-24 11:26:07 +01:00
|
|
|
weight: joi
|
|
|
|
.number()
|
|
|
|
.min(0)
|
2020-02-13 17:53:09 +01:00
|
|
|
.max(1000)
|
2019-01-24 11:26:07 +01:00
|
|
|
.required(),
|
2020-08-03 13:24:51 +02:00
|
|
|
weightType: joi
|
|
|
|
.string()
|
|
|
|
.valid('variable', 'fix')
|
|
|
|
.default('variable'),
|
2019-01-24 11:26:07 +01:00
|
|
|
payload: joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
type: joi.string().required(),
|
|
|
|
value: joi.string().required(),
|
|
|
|
})
|
|
|
|
.optional(),
|
2019-01-29 09:21:54 +01:00
|
|
|
overrides: joi.array().items(
|
|
|
|
joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
2019-02-04 14:04:58 +01:00
|
|
|
contextName: joi.string().required(),
|
2019-01-29 09:21:54 +01:00
|
|
|
values: joi.array().items(joi.string()),
|
|
|
|
})
|
2020-04-14 22:29:11 +02:00
|
|
|
.optional(),
|
2019-01-29 09:21:54 +01:00
|
|
|
),
|
2018-01-30 15:57:12 +01:00
|
|
|
});
|
|
|
|
|
2018-12-01 12:03:47 +01:00
|
|
|
const featureShema = joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
2018-12-01 12:03:47 +01:00
|
|
|
enabled: joi.boolean().default(false),
|
2020-08-07 10:46:35 +02:00
|
|
|
stale: joi.boolean().default(false),
|
2020-08-06 11:18:52 +02:00
|
|
|
type: joi.string().default('release'),
|
2019-03-14 17:56:02 +01:00
|
|
|
description: joi
|
|
|
|
.string()
|
|
|
|
.allow('')
|
|
|
|
.allow(null)
|
|
|
|
.optional(),
|
2018-12-01 12:03:47 +01:00
|
|
|
strategies: joi
|
|
|
|
.array()
|
|
|
|
.required()
|
|
|
|
.min(1)
|
|
|
|
.items(strategiesSchema),
|
2018-01-30 15:57:12 +01:00
|
|
|
variants: joi
|
|
|
|
.array()
|
2019-03-14 17:56:02 +01:00
|
|
|
.allow(null)
|
2019-01-24 11:26:07 +01:00
|
|
|
.unique((a, b) => a.name === b.name)
|
2018-01-30 15:57:12 +01:00
|
|
|
.optional()
|
2019-03-14 17:56:02 +01:00
|
|
|
.items(variantsSchema),
|
2018-12-01 12:03:47 +01:00
|
|
|
})
|
|
|
|
.options({ allowUnknown: false, stripUnknown: true });
|
|
|
|
|
2018-12-12 10:09:38 +01:00
|
|
|
module.exports = { featureShema, strategiesSchema, nameSchema };
|