1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/services/state-schema.ts
olav 66d9d7a6d2
feat: add segments (#1426)
* refactor: fix missing tsconfig path in .eslintrc

* refactor: require contextName and operator

* refactor: fix crash on missing feature strategies

* feat: add segments schema

* feat: add segments client API

* feat: add segments permissions

* refactor: fail migration if things exist

* refactor: remove strategy IDs from responses

* refactor: allow empty description

* refactor: add segment import/export

* refactor: add perf scripts

* refactor: add get segment fn

* refactor: move constraint validation endpoint

* refactor: use a separate id for segment updates

* refactor: use PERF_AUTH_KEY for artillery

* refactor: adjust segment seed size

* refactor: add missing event data await

* refactor: improve method order

* refactor: remove request body limit override
2022-03-29 14:59:14 +02:00

66 lines
2.3 KiB
TypeScript

import joi from 'joi';
import { featureSchema, featureTagSchema } from '../schema/feature-schema';
import strategySchema from './strategy-schema';
import { tagSchema } from './tag-schema';
import { tagTypeSchema } from './tag-type-schema';
import { projectSchema } from './project-schema';
import { nameType } from '../routes/util';
import { featureStrategySegmentSchema, segmentSchema } from './segment-schema';
export const featureStrategySchema = joi
.object()
.keys({
id: joi.string().optional(),
featureName: joi.string(),
projectId: joi.string(),
environment: joi.string(),
parameters: joi.object().optional().allow(null),
constraints: joi.array().optional(),
strategyName: joi.string(),
})
.options({ stripUnknown: true });
export const featureEnvironmentsSchema = joi.object().keys({
environment: joi.string(),
featureName: joi.string(),
enabled: joi.boolean(),
});
export const environmentSchema = joi.object().keys({
name: nameType,
displayName: joi.string().optional().allow(''),
type: joi.string().required(),
sortOrder: joi.number().optional(),
enabled: joi.boolean().optional(),
protected: joi.boolean().optional(),
});
export const updateEnvironmentSchema = joi.object().keys({
displayName: joi.string().optional().allow(''),
type: joi.string().optional(),
sortOrder: joi.number().optional(),
});
export const sortOrderSchema = joi.object().pattern(/^/, joi.number());
export const stateSchema = joi.object().keys({
version: joi.number(),
features: joi.array().optional().items(featureSchema),
strategies: joi.array().optional().items(strategySchema),
tags: joi.array().optional().items(tagSchema),
tagTypes: joi.array().optional().items(tagTypeSchema),
featureTags: joi.array().optional().items(featureTagSchema),
projects: joi.array().optional().items(projectSchema),
featureStrategies: joi.array().optional().items(featureStrategySchema),
featureEnvironments: joi
.array()
.optional()
.items(featureEnvironmentsSchema),
environments: joi.array().optional().items(environmentSchema),
segments: joi.array().optional().items(segmentSchema),
featureStrategySegments: joi
.array()
.optional()
.items(featureStrategySegmentSchema),
});