11// SQLite dialect codegen entry — facts + type table + class chrome in,
22// generated .ts files out via the unified emitter (../emission/emit.ts).
33// All emission knowledge lives there; this file contributes DATA: the
4- // committed facts (via signatures.ts), the sqlite type table, and the
4+ // committed per-doc-page facts (docs/<page>.json — schema and
5+ // extraction prompt in docs/index.ts), the sqlite type table, and the
56// per-class chrome (imports/statics/heritage).
67//
8+ // The emitted surface is derived from the facts by global rules —
9+ // - method receivers = each overload's FIRST argument's domain
10+ // ("any" ⇒ universal); args are in exact SQL call order;
11+ // - names are camelCase(sql) for functions, symbol + PG-style
12+ // alias for operators.
13+ // The only remaining judgment is EXCLUSIONS below. Every claim is
14+ // mechanically checked by signatures.verify.test.ts against the real
15+ // engine; its completeness gate ensures every pragma_function_list
16+ // entry is either defined in the facts or excluded here.
17+ //
718// Run: node --experimental-strip-types src/types/sqlite/emit.ts
819// [--out-dir <dir>] (codegen:check)
920
21+ import * as fs from "node:fs" ;
1022import * as path from "node:path" ;
1123import { pathToFileURL } from "node:url" ;
12- import { SIGNATURES } from "./signatures.ts" ;
24+ import { DocPageSchema } from "./docs/index.ts" ;
25+ import { type EmitFn } from "../emission/facts.ts" ;
1326import {
1427 writeGeneratedTree ,
1528 chromeImportLines ,
@@ -22,7 +35,60 @@ import {
2235} from "../emission/emit.ts" ;
2336
2437const HEADER =
25- "// Auto-generated by src/types/sqlite/emit.ts from signatures.ts — do not edit.\n" ;
38+ "// Auto-generated by src/types/sqlite/emit.ts from docs/*.json — do not edit.\n" ;
39+
40+ // --- facts: one JSON per vendored doc page --------------------------------
41+ // Loaded with fs (not import attributes — parser-neutral across node
42+ // strip-types / swc / tsgo / tsdown) and zod-validated at import time:
43+ // a malformed JSON fails loudly here, before any emission.
44+
45+ const PAGES = [
46+ "lang_corefunc" ,
47+ "lang_mathfunc" ,
48+ "lang_datefunc" ,
49+ "lang_aggfunc" ,
50+ "percentile" ,
51+ "json1" ,
52+ "lang_expr" ,
53+ ] as const ;
54+
55+ export const SIGNATURES : EmitFn [ ] = PAGES . flatMap ( ( page ) => {
56+ const raw = fs . readFileSync ( path . join ( import . meta. dirname , "docs" , `${ page } .json` ) , "utf8" ) ;
57+ return DocPageSchema . parse ( JSON . parse ( raw ) ) . functions ;
58+ } ) ;
59+
60+ // Functions typegres refuses to surface — the completeness gate's
61+ // whitelist: every pragma_function_list entry must be either defined
62+ // in the facts or listed here.
63+ export const EXCLUSIONS : string [ ] = [
64+ // Window functions — typegres has no OVER-clause modeling yet (PG
65+ // doesn't either). Revisit with window support in the query builder.
66+ "row_number" , "rank" , "dense_rank" , "percent_rank" , "cume_dist" , "ntile" ,
67+ "lag" , "lead" , "first_value" , "last_value" , "nth_value" ,
68+ // FTS / rtree / geopoly — only meaningful on virtual tables, which
69+ // typegres doesn't model.
70+ "bm25" , "fts3_tokenizer" , "fts5" , "fts5_get_locale" , "fts5_insttoken" ,
71+ "fts5_locale" , "fts5_source_id" , "highlight" , "matchinfo" , "offsets" ,
72+ "optimize" , "snippet" ,
73+ "rtreecheck" , "rtreedepth" , "rtreenode" ,
74+ "geopoly_area" , "geopoly_bbox" , "geopoly_blob" , "geopoly_ccw" ,
75+ "geopoly_contains_point" , "geopoly_debug" , "geopoly_group_bbox" ,
76+ "geopoly_json" , "geopoly_overlap" , "geopoly_regular" , "geopoly_svg" ,
77+ "geopoly_within" , "geopoly_xform" ,
78+ "match" , // MATCH operator function — only meaningful on FTS virtual tables
79+ // Planner hints — no-ops for typing purposes; noise on the API.
80+ "likelihood" , "likely" , "unlikely" ,
81+ // Introspection / footguns.
82+ "load_extension" , // loads native code — must not be reachable from a query builder
83+ "sqlite_compileoption_get" , // build introspection
84+ "sqlite_compileoption_used" , // build introspection
85+ "sqlite_offset" , // low-level file-offset introspection
86+ "sqlite_log" , // error-log side effect, returns nothing useful
87+ "subtype" , // internal function-subtype plumbing
88+ // CURRENT_* keywords aren't callable syntax — the datetime functions
89+ // cover them (date('now'), time('now'), datetime('now')).
90+ "current_date" , "current_time" , "current_timestamp" ,
91+ ] ;
2692
2793// The sqlite type table. No `generic`/`element` entries (sqlite has
2894// no containers or pseudotypes), so the emitter's T-threading
0 commit comments