Skip to content

Commit c449dc9

Browse files
ryanrasticlaude
andcommitted
refactor(types): inline single-use locals in the dialect entries
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f2197e2 commit c449dc9

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/types/postgres/emit.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
typnameStaticLines,
99
scanOverrideNames,
1010
type EmitFn,
11-
type EmitConfig,
1211
type TypeEntry,
1312
type Nullability,
1413
type ClassChrome,
@@ -180,7 +179,6 @@ const pgChrome = (
180179
): ClassChrome => {
181180
const isGeneric = GENERIC_TYPES.has(pgType.typname);
182181
const extendsClass = EXTENDS_MAP[pgType.typname];
183-
const needsGenericT = isGeneric;
184182
const parentIsContainer = extendsClass !== undefined
185183
&& [...GENERIC_TYPES].some((n) => nameTable.get(n)?.className === extendsClass);
186184

@@ -202,7 +200,7 @@ const pgChrome = (
202200
// Explicit `in out N` variance annotation skips TS's structural
203201
// variance inference across 77 mutually-referencing classes.
204202
let classDecl = `export class ${pgType.className}`;
205-
if (needsGenericT) {
203+
if (isGeneric) {
206204
classDecl += `<T extends types.Any<any>, in out N extends number>`;
207205
} else {
208206
classDecl += `<in out N extends number>`;
@@ -244,10 +242,6 @@ export const generate = async () => {
244242

245243
try {
246244
const { typeMap, pgFuncs } = await introspect(db, Object.keys(OPERATOR_ALIASES));
247-
// Facts instance — catalog-independent (typnames, not OIDs),
248-
// generated on the fly. This is what the unified emitter consumes;
249-
// sqlite's equivalent is its committed docs/*.json.
250-
const facts = produceFacts(typeMap, pgFuncs);
251245
const types: TypeEntry[] = [...typeMap.values()].map((t) => ({
252246
typname: t.typname,
253247
className: t.className,
@@ -257,14 +251,16 @@ export const generate = async () => {
257251
}));
258252
const nameTable = new Map(types.map((t) => [t.typname, t]));
259253
const overrideNames = scanOverrides();
260-
const cfg: EmitConfig = { typeTable: nameTable, noMethod: new Set() };
261254

262255
writeGeneratedTree({
263256
generatedDir: GENERATED_DIR,
264257
barrelPath: TYPES_INDEX,
265258
types,
266-
facts,
267-
cfg,
259+
// Facts instance — catalog-independent (typnames, not OIDs),
260+
// generated on the fly. This is what the unified emitter
261+
// consumes; sqlite's equivalent is its committed docs/*.json.
262+
facts: produceFacts(typeMap, pgFuncs),
263+
cfg: { typeTable: nameTable, noMethod: new Set() },
268264
chromeFor: (host) => pgChrome(host, nameTable, overrideNames),
269265
overrides: overrideNames,
270266
});

src/types/sqlite/emit.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ const chromeFor = (typname: string): ClassChrome => {
154154
lines.push(...chromeImportLines(parentImport));
155155

156156
const cls = CONFIG.typeTable.get(typname)!.className;
157-
const parent = typname === "any" ? "SqlValue" : "Any";
158-
lines.push(`export class ${cls}<in out N extends number> extends ${parent}<N> {`);
157+
lines.push(`export class ${cls}<in out N extends number> extends ${typname === "any" ? "SqlValue" : "Any"}<N> {`);
159158

160159
// Every concrete class (everything but the root) gets the brand +
161160
// [meta] + typname chrome — same rule as PG. types.Cls refs: the
@@ -180,7 +179,7 @@ const main = (): void => {
180179

181180
writeGeneratedTree({
182181
generatedDir: path.join(outDir, "generated"),
183-
barrelPath: path.join(path.resolve(import.meta.dirname), "index.ts"),
182+
barrelPath: path.join(import.meta.dirname, "index.ts"),
184183
types: TYPES,
185184
facts: SIGNATURES,
186185
cfg: CONFIG,

0 commit comments

Comments
 (0)