web: added the base for the web project
This commit is contained in:
@@ -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,
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user