Skip to content

feat: export astToZQL from @rocicorp/zero/ast-to-zql#5638

Open
jb-chief wants to merge 1 commit intorocicorp:mainfrom
jb-chief:export-ast-to-zql
Open

feat: export astToZQL from @rocicorp/zero/ast-to-zql#5638
jb-chief wants to merge 1 commit intorocicorp:mainfrom
jb-chief:export-ast-to-zql

Conversation

@jb-chief
Copy link

@jb-chief jb-chief commented Mar 4, 2026

Summary

Adds ./ast-to-zql to the @rocicorp/zero package exports map so consumers can import the astToZQL function directly:

import { astToZQL } from "@rocicorp/zero/ast-to-zql";

Motivation

We're building query plan regression tests that:

  1. Extract the AST from actual ZQL query definitions via the .ast getter
  2. Serialize the AST back to a ZQL string using astToZQL
  3. Pass it to analyze-query --query to verify no table scans, proper index usage, etc.

This keeps our tests automatically in sync with our real query definitions — if a query changes, the test reflects it without manual string updates.

Currently we have to use a dynamic import hack to access the function since it's not in the exports map:

const _require = createRequire(import.meta.url);
const zeroMainPath = _require.resolve("@rocicorp/zero");
const astToZqlModulePath = zeroMainPath.replace(
  /out\/zero\/src\/zero\.js$/,
  "out/ast-to-zql/src/ast-to-zql.js",
);
const _astToZqlModule = await import(astToZqlModulePath);

Change

One-liner addition to packages/zero/package.json exports, following the existing { types, default } pattern:

"./ast-to-zql": {
  "types": "./out/ast-to-zql/src/ast-to-zql.d.ts",
  "default": "./out/ast-to-zql/src/ast-to-zql.js"
}

No new code — just exposing an existing internal module.

Add `./ast-to-zql` to the package exports map so consumers can import
the AST-to-ZQL serializer without resorting to dynamic import hacks.

This enables use cases like query plan regression testing where you
extract the AST from a query builder and serialize it back to a ZQL
string for analyze-query.
@vercel
Copy link

vercel bot commented Mar 4, 2026

@jb-chief is attempting to deploy a commit to the Rocicorp Team on Vercel.

A member of the Team first needs to authorize it.

@aboodman
Copy link
Contributor

aboodman commented Mar 5, 2026

you don't need the zql to do this. analyze-query accepts ast too.

CleanShot 2026-03-04 at 16 54 43@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants