@asterql/codegen
Type inference and TypeScript declaration generation for AsterQL.
This package evaluates an AsterQL AST over @asterql/schema TypeNodes. It does
not run the query against data. It predicts the shape a query returns so view
definitions, docs demos, editor tooling, and AI-authored routes can verify the
data contract before runtime.
import {
analyzeType,
generateTypeDeclaration,
inferType,
} from "@asterql/codegen";
import {
arrayType,
defineSchema,
objectType,
stringType,
} from "@asterql/schema";
const schema = defineSchema({
root: objectType({
posts: arrayType(
objectType({
id: stringType(),
title: stringType(),
}),
),
}),
});
const result = inferType("*.posts[] {id, title}", schema);
const analysis = analyzeType("*.posts[] {id, title}", schema);
const declaration = generateTypeDeclaration("*.posts[] {id, title}", schema, {
typeName: "PostListView",
});
API
analyzeType(query, schema, options?): parse/evaluate a query and return the
final result plus per-AST-node typed scopes for editor tooling.
inferType(query, schema, options?): parse/evaluate a query over TypeNodes.
generateTypeDeclaration(query, schema, options?): infer the result and emit
a TypeScript declaration string.
typeToTypeScript(type, options?): render a TypeNode as a TypeScript type.
options.functions, options.reducers, and options.params let hosts provide
the same extension surface they use at runtime, but with static TypeNode return
signatures.