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
Ivar Conradi Østhus 4b7e1f4a81
feat: rename :global: env to "default" (#947)
Our testing and internal validation has proven that
the :global: environment concept confuses people more
than the problems it solves. We have thus decided to
group all configuration that was created before the
environment concept was introduced in to the "default
environment. This would still make everything work
as before in addition to introducing the env concept.

Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
2021-09-24 13:55:00 +02:00

60 lines
2.1 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';
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),
});