Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions js/btql/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type IdentPiece = z.infer<typeof identPieceSchema>;
export const identSchema = z.strictObject({
op: z.literal("ident"),
name: z.array(identPieceSchema),
alias: z.string().nullish(),
loc,
});
export type Ident = z.infer<typeof identSchema>;
Expand All @@ -109,17 +110,24 @@ export interface Star {
loc?: NullableLoc;
}

export const shapeSchema = z.enum(["spans", "traces", "summary"]);
export type Shape = z.infer<typeof shapeSchema>;

export interface Function {
op: "function";
name: Ident;
args: (Expr | AliasExpr)[];
loc?: NullableLoc;
shape?: Shape | null;
alias?: string | null;
}
export const functionSchema: z.ZodType<Function> = z.object({
op: z.literal("function"),
name: identSchema,
args: z.array(z.union([z.lazy(() => exprSchema), z.lazy(() => aliasExpr)])),
loc,
shape: shapeSchema.nullish(),
alias: z.string().nullish(),
});

export const comparisonOps = [
Expand Down Expand Up @@ -337,9 +345,6 @@ export const sortExpr = z.strictObject({

export type SortExpr = z.infer<typeof sortExpr>;

export const shapeSchema = z.enum(["spans", "traces", "summary"]);
export type Shape = z.infer<typeof shapeSchema>;

export const fromFunctionSchema = functionSchema.and(
z.object({
shape: shapeSchema.nullish(),
Expand Down