web: added the base for the web project

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-26 20:53:11 +02:00
parent 15e29edaa7
commit 8a87fff689
107 changed files with 3607 additions and 512 deletions

View File

@@ -1,14 +1,27 @@
import { ChartType } from "@prisma/client";
import { z } from "zod";
import { operators } from "./constants";
function objectToZodEnums<K extends string> ( obj: Record<K, any> ): [ K, ...K[] ] {
const [ firstKey, ...otherKeys ] = Object.keys( obj ) as K[]
return [ firstKey!, ...otherKeys ]
}
export const zChartEvent = z.object({
id: z.string(),
name: z.string(),
segment: z.enum(["event", "user"]),
filters: z.array(
z.object({
id: z.string(),
name: z.string(),
value: z.string(),
operator: z.enum(objectToZodEnums(operators)),
value: z.array(
z
.string()
.or(z.number())
.or(z.boolean())
.or(z.null())
),
}),
),
});
@@ -20,7 +33,7 @@ export const zChartBreakdown = z.object({
export const zChartEvents = z.array(zChartEvent);
export const zChartBreakdowns = z.array(zChartBreakdown);
export const zChartType = z.enum(['linear', 'bar', 'pie', 'metric', 'area']);
export const zChartType = z.enum(["linear", "bar", "pie", "metric", "area"]);
export const zTimeInterval = z.enum(["day", "hour", "month"]);
@@ -32,4 +45,4 @@ export const zChartInput = z.object({
interval: zTimeInterval,
events: zChartEvents,
breakdowns: zChartBreakdowns,
})
});