Update db schemas

This commit is contained in:
Oliver-Akins 2025-05-31 23:15:42 -06:00
parent 22036c419d
commit 5fe11fda0d

View file

@ -3,31 +3,25 @@ import { PrivacyMode } from "../privacy.mjs";
// MARK: Buckets // MARK: Buckets
export const numberBucketSchema = Joi.object({ export const numberBucketSchema = Joi.object({
type: Joi.string().valid(`number`, `range`).required(), type: Joi.string().valid(`number`).required(),
min: Joi min: Joi
.number() .number()
.integer() .integer()
.when(`type`, { .when(`step`, {
is: Joi.string().valid(`range`), is: Joi.exist(),
then: Joi.required(), then: Joi.required(),
otherwise: Joi.optional(),
}), }),
max: Joi max: Joi
.number() .number()
.integer() .integer()
.when(`type`, { .when(`min`, {
is: Joi.string().valid(`range`), is: Joi.exist(),
then: Joi.required(), then: Joi.number().greater(Joi.ref(`min`)),
otherwise: Joi.optional(),
}), }),
step: Joi step: Joi
.number() .number()
.integer() .integer()
.when(`type`, { .min(1),
is: Joi.string().valid(`range`),
then: Joi.required(),
otherwise: Joi.optional(),
}),
}); });
export const stringBucketSchema = Joi.object({ export const stringBucketSchema = Joi.object({
@ -37,16 +31,15 @@ export const stringBucketSchema = Joi.object({
.items( .items(
Joi.string().trim().invalid(``), Joi.string().trim().invalid(``),
) )
.min(1)
.optional(), .optional(),
}); });
// MARK: Graphs // MARK: Graphs
export const barGraphSchema = Joi.object({ export const barGraphSchema = Joi.object({
type: Joi.string().valid(`bar`).required(), type: Joi.string().valid(`bar`).required(),
stacked: Joi stacked: Joi.boolean().optional().default(true),
.boolean() showEmptyBuckets: Joi.boolean().optional().default(false),
.default(true)
.optional(),
}); });
// MARK: Table // MARK: Table
@ -59,18 +52,34 @@ export const tableSchema = Joi.object({
.pattern(/^[0-9a-z \-_]+(\/[0-9a-z \-_]+)?$/i), .pattern(/^[0-9a-z \-_]+(\/[0-9a-z \-_]+)?$/i),
buckets: Joi buckets: Joi
.alternatives() .alternatives()
.try( .conditional(
numberBucketSchema, `/buckets.type`,
stringBucketSchema, {
switch: [
{
is: `number`,
then: numberBucketSchema,
},
{
is: `string`,
then: stringBucketSchema,
},
],
otherwise: Joi.forbidden(),
},
) )
.match(`one`)
.required(), .required(),
graph: Joi graph: Joi
.alternatives() .alternatives()
.try( .conditional(
barGraphSchema, `/graph.type`,
{
switch: [
{ is: `bar`, then: barGraphSchema },
],
otherwise: Joi.forbidden(),
},
) )
.match(`one`)
.required(), .required(),
}); });