fix: improve types for chart/reports
This commit is contained in:
@@ -135,7 +135,9 @@ export const zReportOptions = z.discriminatedUnion('type', [
|
||||
export type IReportOptions = z.infer<typeof zReportOptions>;
|
||||
export type ISankeyOptions = z.infer<typeof zSankeyOptions>;
|
||||
|
||||
export const zChartInputBase = z.object({
|
||||
// Base input schema - for API calls, engine, chart queries
|
||||
export const zReportInput = z.object({
|
||||
projectId: z.string().describe('The ID of the project this chart belongs to'),
|
||||
chartType: zChartType
|
||||
.default('linear')
|
||||
.describe('What type of chart should be displayed'),
|
||||
@@ -153,6 +155,18 @@ export const zChartInputBase = z.object({
|
||||
range: zRange
|
||||
.default('30d')
|
||||
.describe('The time range for which data should be displayed'),
|
||||
startDate: z
|
||||
.string()
|
||||
.nullish()
|
||||
.describe(
|
||||
'Custom start date for the data range (overrides range if provided)',
|
||||
),
|
||||
endDate: z
|
||||
.string()
|
||||
.nullish()
|
||||
.describe(
|
||||
'Custom end date for the data range (overrides range if provided)',
|
||||
),
|
||||
previous: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
@@ -166,19 +180,6 @@ export const zChartInputBase = z.object({
|
||||
.describe(
|
||||
'The aggregation method for the metric (e.g., sum, count, average)',
|
||||
),
|
||||
projectId: z.string().describe('The ID of the project this chart belongs to'),
|
||||
startDate: z
|
||||
.string()
|
||||
.nullish()
|
||||
.describe(
|
||||
'Custom start date for the data range (overrides range if provided)',
|
||||
),
|
||||
endDate: z
|
||||
.string()
|
||||
.nullish()
|
||||
.describe(
|
||||
'Custom end date for the data range (overrides range if provided)',
|
||||
),
|
||||
limit: z
|
||||
.number()
|
||||
.optional()
|
||||
@@ -187,27 +188,12 @@ export const zChartInputBase = z.object({
|
||||
.number()
|
||||
.optional()
|
||||
.describe('Skip how many series should be returned'),
|
||||
criteria: zCriteria
|
||||
options: zReportOptions
|
||||
.optional()
|
||||
.describe('Filtering criteria for retention chart (e.g., on_or_after, on)'),
|
||||
funnelGroup: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Group identifier for funnel analysis, e.g. "profile_id" or "session_id"',
|
||||
),
|
||||
funnelWindow: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe('Time window in hours for funnel analysis'),
|
||||
options: zReportOptions.optional(),
|
||||
});
|
||||
|
||||
export const zChartInput = zChartInputBase;
|
||||
|
||||
export const zReportInput = zChartInputBase.extend({
|
||||
name: z.string().describe('The user-defined name for the report'),
|
||||
lineType: zLineType.describe('The visual style of the line in the chart'),
|
||||
.describe('Chart-specific options (funnel, retention, sankey)'),
|
||||
// Optional display fields
|
||||
name: z.string().optional().describe('The user-defined name for the report'),
|
||||
lineType: zLineType.optional().describe('The visual style of the line in the chart'),
|
||||
unit: z
|
||||
.string()
|
||||
.optional()
|
||||
@@ -216,17 +202,14 @@ export const zReportInput = zChartInputBase.extend({
|
||||
),
|
||||
});
|
||||
|
||||
export const zChartInputAI = zReportInput
|
||||
.omit({
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
lineType: true,
|
||||
unit: true,
|
||||
})
|
||||
.extend({
|
||||
startDate: z.string().describe('The start date for the report'),
|
||||
endDate: z.string().describe('The end date for the report'),
|
||||
});
|
||||
// Complete report schema - for saved reports
|
||||
export const zReport = zReportInput.extend({
|
||||
name: z.string().default('Untitled').describe('The user-defined name for the report'),
|
||||
lineType: zLineType.default('monotone').describe('The visual style of the line in the chart'),
|
||||
});
|
||||
|
||||
// Alias for backward compatibility
|
||||
export const zChartInput = zReportInput;
|
||||
|
||||
export const zInviteUser = z.object({
|
||||
email: z.string().email(),
|
||||
|
||||
@@ -10,25 +10,28 @@ import type {
|
||||
zChartEventItem,
|
||||
zChartEventSegment,
|
||||
zChartFormula,
|
||||
zChartInput,
|
||||
zChartInputAI,
|
||||
zChartSeries,
|
||||
zChartType,
|
||||
zCriteria,
|
||||
zLineType,
|
||||
zMetric,
|
||||
zRange,
|
||||
zReport,
|
||||
zReportInput,
|
||||
zTimeInterval,
|
||||
} from './index';
|
||||
|
||||
export type IChartInput = z.infer<typeof zChartInput>;
|
||||
export type IChartInputAi = z.infer<typeof zChartInputAI>;
|
||||
export type IChartProps = z.infer<typeof zReportInput> & {
|
||||
name: string;
|
||||
lineType: IChartLineType;
|
||||
unit?: string;
|
||||
};
|
||||
// For saved reports - complete report with required display fields
|
||||
export type IReport = z.infer<typeof zReport>;
|
||||
|
||||
// For API/engine use - flexible input
|
||||
export type IReportInput = z.infer<typeof zReportInput>;
|
||||
|
||||
// With resolved dates (engine internal)
|
||||
export interface IReportInputWithDates extends IReportInput {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
}
|
||||
export type IChartEvent = z.infer<typeof zChartEvent>;
|
||||
export type IChartFormula = z.infer<typeof zChartFormula>;
|
||||
export type IChartEventItem = z.infer<typeof zChartEventItem>;
|
||||
@@ -47,16 +50,12 @@ export type IChartType = z.infer<typeof zChartType>;
|
||||
export type IChartMetric = z.infer<typeof zMetric>;
|
||||
export type IChartLineType = z.infer<typeof zLineType>;
|
||||
export type IChartRange = z.infer<typeof zRange>;
|
||||
export interface IChartInputWithDates extends IChartInput {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
}
|
||||
export type IGetChartDataInput = {
|
||||
event: IChartEvent;
|
||||
projectId: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
} & Omit<IChartInput, 'series' | 'name' | 'startDate' | 'endDate' | 'range'>;
|
||||
} & Omit<IReportInput, 'series' | 'startDate' | 'endDate' | 'range'>;
|
||||
export type ICriteria = z.infer<typeof zCriteria>;
|
||||
|
||||
export type PreviousValue =
|
||||
|
||||
Reference in New Issue
Block a user