🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@asterql/codegen

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asterql/codegen

Type inference and TypeScript declaration generation for AsterQL queries.

latest
Source
npmnpm
Version
0.5.0
Version published
Maintainers
1
Created
Source

@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);
// result.type is a TypeNode for Array<{ id: string; title: string }>

const analysis = analyzeType("*.posts[] {id, title}", schema);
// analysis.nodes contains the typed input scope and output type for each AST node.

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.

Keywords

asterql

FAQs

Package last updated on 08 Jul 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts