@dbsp/cli 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbsp/cli",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "CLI tools for db-semantic-planner — REPL, schema generation, DDL provisioning",
5
5
  "author": "Olivier Orabona <oorabona@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -56,14 +56,14 @@
56
56
  "dist"
57
57
  ],
58
58
  "dependencies": {
59
- "@oclif/table": "^0.5.9",
59
+ "@dbsp/adapter-pgsql": "6.0.0",
60
+ "@dbsp/core": "5.0.0",
61
+ "@dbsp/nql": "1.10.5",
62
+ "@dbsp/types": "5.0.0",
63
+ "@oclif/table": "^1.0.0",
60
64
  "commander": "^15.0.0",
61
65
  "ink": "^7.1.0",
62
- "react": "^19.2.7",
63
- "@dbsp/adapter-pgsql": "3.4.0",
64
- "@dbsp/core": "3.4.0",
65
- "@dbsp/types": "3.4.0",
66
- "@dbsp/nql": "1.10.3"
66
+ "react": "^19.2.7"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "pg": "^8.21.0",
@@ -83,7 +83,7 @@
83
83
  "tsup": "^8.5.1",
84
84
  "tsx": "^4.9.0",
85
85
  "typescript": "~6.0.3",
86
- "vitest": "^4.1.9"
86
+ "vitest": "^5.0.0"
87
87
  },
88
88
  "scripts": {
89
89
  "build": "tsup",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/schema-codegen.ts","../src/utils/db-utils.ts"],"sourcesContent":["/**\n * CLI-DDL: Schema Codegen Module\n *\n * Generates TypeScript schema files from IntrospectedModelIR.\n * Used by `dbsp introspect` to create dbsp.schema.ts from a database.\n */\n\nimport {\n\tcanGenerateCreateIndex,\n\tgenerateCreateIndex,\n\tidentityNaming,\n} from '@dbsp/adapter-pgsql';\nimport {\n\ttype ModelIR,\n\ttype TableIR,\n\tvalidateSchemaIndexOptions,\n} from '@dbsp/core';\nimport type { IndexIR } from '@dbsp/types';\nimport { redactDbUrl } from '../utils/db-utils.js';\n\n/**\n * Convert a snake_case string to camelCase.\n * @example 'author_id' → 'authorId'\n */\nfunction snakeToCamelCase(name: string): string {\n\treturn name.replace(/_([a-z])/g, (_, letter: string) => letter.toUpperCase());\n}\n\n/**\n * Options for schema code generation.\n */\nexport interface SchemaCodegenOptions {\n\t/** Source database URL (for comment header) */\n\treadonly sourceUrl?: string;\n\t/** Include original DB types as comments */\n\treadonly includeDbTypeComments?: boolean;\n\t/** Receive diagnostics as they are collected, including model warnings. */\n\treadonly onWarning?: (message: string) => void;\n\t/** Timestamp of introspection */\n\treadonly introspectedAt?: Date;\n\t/**\n\t * Database column casing convention.\n\t * When set to 'snake_case', column names are converted to camelCase\n\t * and a `dbCasing: 'snake_case'` comment is added to the generated code.\n\t * @default 'preserve'\n\t */\n\treadonly dbCasing?: 'snake_case' | 'camelCase' | 'preserve';\n}\n\nexport type SchemaCodegenDiagnosticsOptions = SchemaCodegenOptions;\n\nexport interface SchemaCodegenResult {\n\treadonly code: string;\n\treadonly warnings: readonly string[];\n}\n\n/**\n * Serialize a column default value to valid TypeScript source code.\n *\n * CODEX-11/CODEX-14: String(value) produced \"[object Object]\" for SQL-expression\n * defaults like { sql: 'now()' }, and single-quote wrapping without escape broke\n * strings containing quotes, backslashes, or newlines.\n *\n * Rules:\n * - null/undefined → 'null'\n * - number | boolean → unquoted literal (String(value))\n * - string → singleQuoteEscape (escapes \\, ', \\n, \\r, \\t — produces single-quoted TS literal)\n * - { sql: '...' } shape → `{ sql: ${JSON.stringify(sqlExpr)} }`\n * - anything else → throws (unrecognized shape; prevents silent [object Object])\n */\n\n/**\n * Wrap a string value in single quotes for TypeScript source output,\n * escaping any single quotes and backslashes contained in the value.\n *\n * Examples:\n * 'hello' → \"'hello'\"\n * \"O'Brien\" → \"'O\\\\'Brien'\"\n * 'C:\\\\Users' → \"'C:\\\\\\\\Users'\"\n */\nfunction singleQuoteEscape(s: string): string {\n\treturn `'${s\n\t\t.replace(/\\\\/g, '\\\\\\\\')\n\t\t.replace(/'/g, \"\\\\'\")\n\t\t.replace(/\\n/g, '\\\\n')\n\t\t.replace(/\\r/g, '\\\\r')\n\t\t.replace(/\\t/g, '\\\\t')}'`;\n}\n\n/**\n * Neutralize text that must remain inside generated block comments.\n *\n * Catalog-derived values are otherwise capable of closing `/* ... *\\/` comments\n * and turning the rest of the generated file into executable TypeScript.\n */\nfunction blockCommentText(s: string): string {\n\treturn s\n\t\t.replace(/\\*\\//g, '* /')\n\t\t.replace(/\\n/g, '\\\\n')\n\t\t.replace(/\\r/g, '\\\\r')\n\t\t.replace(/\\t/g, '\\\\t');\n}\n\n/**\n * Return the key suitable for use as a TypeScript object key.\n * Valid JS identifiers can be used bare; anything else is single-quote-wrapped.\n * A valid JS identifier starts with a letter, underscore, or $, followed by\n * letters, digits, underscores, or $.\n */\nfunction quoteKey(name: string): string {\n\tif (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)) {\n\t\treturn name;\n\t}\n\t// F3: Delegate to singleQuoteEscape() which also handles \\n, \\r, \\t.\n\t// The previous inline chain only escaped \\\\ and ' — identifiers containing\n\t// newlines, CR, or tabs would have produced invalid TypeScript output.\n\treturn singleQuoteEscape(name);\n}\n\nfunction emitDefault(d: unknown): string {\n\tif (d === null || d === undefined) return 'null';\n\tif (typeof d === 'number' || typeof d === 'boolean') return String(d);\n\tif (typeof d === 'string') return singleQuoteEscape(d);\n\tif (\n\t\ttypeof d === 'object' &&\n\t\t'sql' in d &&\n\t\ttypeof (d as { sql: unknown }).sql === 'string'\n\t) {\n\t\treturn `{ sql: ${singleQuoteEscape((d as { sql: string }).sql)} }`;\n\t}\n\tthrow new Error(\n\t\t`[schema-codegen] Unrecognized default shape: ${JSON.stringify(d)}`,\n\t);\n}\n\n/**\n * Generate column definition object code.\n */\nfunction generateColumnCode(\n\tcolumn: TableIR['columns'][number],\n\tisPrimaryKey: boolean,\n\tfkInfo:\n\t\t| {\n\t\t\t\ttable: string;\n\t\t\t\tcolumn?: string;\n\t\t\t\tnullable?: boolean;\n\t\t\t\tunique?: boolean;\n\t\t\t\tonDelete?: string;\n\t\t\t\tonUpdate?: string;\n\t\t\t\tisSelfRef?: boolean;\n\t\t }\n\t\t| undefined,\n\toptions: SchemaCodegenOptions,\n): string {\n\t// CODEX-13: FK + PK overlap — a column can be both FK and PK (e.g. shared-PK 1:1).\n\t// We must preserve isPrimaryKey even when fkInfo is present.\n\tif (fkInfo) {\n\t\treturn generateRefCode(column, fkInfo, isPrimaryKey, options);\n\t}\n\n\t// Check if we can use short form (just 'type' string)\n\tconst canUseShortForm =\n\t\t!isPrimaryKey &&\n\t\t!column.nullable &&\n\t\tcolumn.default === undefined &&\n\t\t!column.unique;\n\n\tif (canUseShortForm) {\n\t\t// Short form: 'type'\n\t\tlet code = singleQuoteEscape(column.type);\n\t\tif (options.includeDbTypeComments && column.originalDbType) {\n\t\t\tcode += ` /* from: ${blockCommentText(column.originalDbType)} */`;\n\t\t}\n\t\treturn code;\n\t}\n\n\t// Long form: { type, primaryKey?, nullable?, default?, unique? }\n\tconst props: string[] = [];\n\tprops.push(`type: ${singleQuoteEscape(column.type)}`);\n\n\tif (isPrimaryKey) {\n\t\tprops.push('primaryKey: true');\n\t}\n\n\tif (column.nullable) {\n\t\tprops.push('nullable: true');\n\t}\n\n\tif (column.default !== undefined) {\n\t\tprops.push(`default: ${emitDefault(column.default)}`);\n\t}\n\n\tif (column.unique) {\n\t\tprops.push('unique: true');\n\t}\n\n\tlet code = `{ ${props.join(', ')} }`;\n\n\tif (options.includeDbTypeComments && column.originalDbType) {\n\t\tcode += ` /* from: ${blockCommentText(column.originalDbType)} */`;\n\t}\n\n\treturn code;\n}\n\n/**\n * Generate ref() call for a foreign key column.\n * ARCH-005: Use ref() instead of references: { table, column }\n */\nfunction generateRefCode(\n\tcolumn: TableIR['columns'][number],\n\tfkInfo: {\n\t\ttable: string;\n\t\tcolumn?: string;\n\t\tnullable?: boolean;\n\t\tunique?: boolean;\n\t\tonDelete?: string;\n\t\tonUpdate?: string;\n\t\tisSelfRef?: boolean;\n\t},\n\tisPrimaryKey: boolean,\n\toptions: SchemaCodegenOptions,\n): string {\n\tconst refOptions: string[] = [];\n\n\t// C2: emit references option for non-PK FK target columns.\n\t// Now that buildRefColumn plumbs options.references into ModelIR,\n\t// emitting ref('table', { references: ['col'] }) round-trips correctly.\n\t// L1-followup-4: apply snake→camel transform to the target column name when\n\t// dbCasing='snake_case' so the generated references array round-trips correctly.\n\tif (fkInfo.column) {\n\t\tconst refColName =\n\t\t\toptions.dbCasing === 'snake_case'\n\t\t\t\t? snakeToCamelCase(fkInfo.column)\n\t\t\t\t: fkInfo.column;\n\t\trefOptions.push(`references: [${singleQuoteEscape(refColName)}]`);\n\t}\n\n\t// CODEX-13: FK column that is also PK — emit isPrimaryKey inside ref() options\n\tif (isPrimaryKey) {\n\t\trefOptions.push('isPrimaryKey: true');\n\t}\n\n\t// Nullable FK\n\tif (fkInfo.nullable || column.nullable) {\n\t\trefOptions.push('nullable: true');\n\t}\n\n\t// Unique FK → hasOne (1:1 relation)\n\tif (fkInfo.unique || column.unique) {\n\t\trefOptions.push('unique: true');\n\t}\n\n\t// onDelete action\n\tif (fkInfo.onDelete && fkInfo.onDelete !== 'NO ACTION') {\n\t\trefOptions.push(`onDelete: ${singleQuoteEscape(fkInfo.onDelete)}`);\n\t}\n\n\t// CODEX-12: onUpdate action\n\tif (fkInfo.onUpdate && fkInfo.onUpdate !== 'NO ACTION') {\n\t\trefOptions.push(`onUpdate: ${singleQuoteEscape(fkInfo.onUpdate)}`);\n\t}\n\n\t// Self-referential FK needs roles\n\tif (fkInfo.isSelfRef) {\n\t\t// Infer role names from column name\n\t\t// e.g., 'parentId' → parent: 'parent', children: 'children'\n\t\tconst baseName = column.name.replace(/_?[iI]d$/, '');\n\t\tconst childrenName = baseName === 'parent' ? 'children' : `${baseName}s`;\n\t\trefOptions.push(\n\t\t\t`roles: { parent: ${singleQuoteEscape(baseName)}, children: ${singleQuoteEscape(childrenName)} }`,\n\t\t);\n\t}\n\n\t// Build the ref() call — table name converted if dbCasing applies.\n\t// Route through singleQuoteEscape so a table name containing a single quote,\n\t// backslash, or newline produces valid TypeScript instead of a syntax error.\n\tconst refTable =\n\t\toptions.dbCasing === 'snake_case'\n\t\t\t? snakeToCamelCase(fkInfo.table)\n\t\t\t: fkInfo.table;\n\tlet code: string;\n\tif (refOptions.length === 0) {\n\t\tcode = `ref(${singleQuoteEscape(refTable)})`;\n\t} else {\n\t\tcode = `ref(${singleQuoteEscape(refTable)}, { ${refOptions.join(', ')} })`;\n\t}\n\n\t// Add comment for original DB type if requested\n\tif (options.includeDbTypeComments && column.originalDbType) {\n\t\tcode += ` /* from: ${blockCommentText(column.originalDbType)} */`;\n\t}\n\n\treturn code;\n}\n\n/**\n * Generate table definition code.\n */\nfunction generateTableCode(\n\ttable: TableIR,\n\toptions: SchemaCodegenOptions,\n): string {\n\t// ARCH-005: Build FK info map with extended properties\n\tconst fkMap = new Map<\n\t\tstring,\n\t\t{\n\t\t\ttable: string;\n\t\t\tcolumn?: string;\n\t\t\tnullable?: boolean;\n\t\t\tunique?: boolean;\n\t\t\tonDelete?: string;\n\t\t\tonUpdate?: string;\n\t\t\tisSelfRef?: boolean;\n\t\t}\n\t>();\n\n\tfor (const fk of table.foreignKeys) {\n\t\tconst localCol = fk.columns[0];\n\t\tconst refCol = fk.references.columns[0];\n\t\tif (\n\t\t\tfk.columns.length === 1 &&\n\t\t\tfk.references.columns.length === 1 &&\n\t\t\tfk.references.schema === undefined &&\n\t\t\tlocalCol &&\n\t\t\trefCol\n\t\t) {\n\t\t\t// Find the column to check nullable/unique\n\t\t\t// FK column names may be snake_case (from raw SQL) while column.name\n\t\t\t// is camelCase (when CamelCasePlugin is active)\n\t\t\tconst colDef = table.columns.find(\n\t\t\t\t(c) => c.name === localCol || c.name === snakeToCamelCase(localCol),\n\t\t\t);\n\n\t\t\tconst entry: {\n\t\t\t\ttable: string;\n\t\t\t\tcolumn?: string;\n\t\t\t\tnullable?: boolean;\n\t\t\t\tunique?: boolean;\n\t\t\t\tonDelete?: string;\n\t\t\t\tonUpdate?: string;\n\t\t\t\tisSelfRef?: boolean;\n\t\t\t} = {\n\t\t\t\ttable: fk.references.table,\n\t\t\t\tisSelfRef:\n\t\t\t\t\tfk.references.schema === undefined &&\n\t\t\t\t\tfk.references.table === table.name,\n\t\t\t};\n\n\t\t\t// Only include column if not 'id' (the default)\n\t\t\tif (refCol !== 'id') {\n\t\t\t\tentry.column = refCol;\n\t\t\t}\n\n\t\t\t// Include nullable if true\n\t\t\tif (colDef?.nullable) {\n\t\t\t\tentry.nullable = true;\n\t\t\t}\n\n\t\t\t// Include unique if true\n\t\t\tif (colDef?.unique) {\n\t\t\t\tentry.unique = true;\n\t\t\t}\n\n\t\t\t// Include onDelete if not the default\n\t\t\tif (fk.onDelete && fk.onDelete !== 'NO ACTION') {\n\t\t\t\tentry.onDelete = fk.onDelete;\n\t\t\t}\n\n\t\t\t// CODEX-12: Include onUpdate if not the default\n\t\t\tif (fk.onUpdate && fk.onUpdate !== 'NO ACTION') {\n\t\t\t\tentry.onUpdate = fk.onUpdate;\n\t\t\t}\n\n\t\t\t// Store under both snake_case and camelCase keys so fkMap.get(col.name) works\n\t\t\t// regardless of naming convention\n\t\t\tfkMap.set(localCol, entry);\n\t\t\tconst camelCol = snakeToCamelCase(localCol);\n\t\t\tif (camelCol !== localCol) {\n\t\t\t\tfkMap.set(camelCol, entry);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst shouldCamelCase = options.dbCasing === 'snake_case';\n\n\tconst columnLines = table.columns.map((col) => {\n\t\tconst isPrimaryKey = table.primaryKey\n\t\t\t? typeof table.primaryKey === 'string'\n\t\t\t\t? col.name === table.primaryKey\n\t\t\t\t: table.primaryKey.includes(col.name)\n\t\t\t: false;\n\t\tconst fkInfo = fkMap.get(col.name);\n\t\tconst code = generateColumnCode(col, isPrimaryKey, fkInfo, options);\n\t\tconst rawColName = shouldCamelCase ? snakeToCamelCase(col.name) : col.name;\n\t\t// C7: quote the key if it's not a valid JS identifier (e.g. contains hyphens)\n\t\tconst colKey = quoteKey(rawColName);\n\t\treturn `\\t\\t${colKey}: ${code}`;\n\t});\n\n\tconst rawTableName = shouldCamelCase\n\t\t? snakeToCamelCase(table.name)\n\t\t: table.name;\n\t// C7: quote the table key if it's not a valid JS identifier\n\tconst tableKey = quoteKey(rawTableName);\n\treturn `\\t${tableKey}: {\\n${columnLines.join(',\\n')},\\n\\t}`;\n}\n\nfunction generatedName(name: string, options: SchemaCodegenOptions): string {\n\treturn options.dbCasing === 'snake_case' ? snakeToCamelCase(name) : name;\n}\n\nfunction stringArrayLiteral(values: readonly string[]): string {\n\treturn `[${values.map(singleQuoteEscape).join(', ')}]`;\n}\n\n/**\n * Emit a strict boolean literal. Interpolating the value itself would run a\n * foreign object's toString into the generated source, which is later imported.\n */\nfunction booleanLiteral(value: unknown): 'true' | 'false' {\n\treturn value === true ? 'true' : 'false';\n}\n\nfunction stringRecordLiteral(\n\tvalues: Readonly<Record<string, string>>,\n\tkeyName: (name: string) => string = (name) => name,\n): string {\n\tconst entries = Object.entries(values).map(\n\t\t([key, value]) =>\n\t\t\t`[${singleQuoteEscape(keyName(key))}]: ${singleQuoteEscape(value)}`,\n\t);\n\treturn `{ ${entries.join(', ')} }`;\n}\n\nfunction tableLevelForeignKeys(table: TableIR): TableIR['foreignKeys'] {\n\treturn table.foreignKeys.filter(\n\t\t(fk) =>\n\t\t\tfk.references.schema !== undefined ||\n\t\t\tfk.columns.length > 1 ||\n\t\t\tfk.references.columns.length > 1,\n\t);\n}\n\nfunction hasExpressions(idx: IndexIR): boolean {\n\treturn (idx.expressions?.length ?? 0) > 0;\n}\n\nfunction tableLevelIndexes(table: TableIR): readonly IndexIR[] {\n\treturn table.indexes.filter(\n\t\t(idx) => indexRepresentationWarning(table.name, idx) === undefined,\n\t);\n}\n\nfunction warningName(name: string | undefined): string {\n\treturn name === undefined ? '<unnamed>' : JSON.stringify(name);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction indexRepresentationWarning(\n\ttableName: string,\n\tidx: IndexIR,\n): string | undefined {\n\tif (hasExpressions(idx)) {\n\t\treturn `Expression index ${warningName(idx.name)} on table ${warningName(tableName)} cannot be represented in the schema and is not managed by dbsp. dbsp will neither drop nor recreate it; maintain it by hand.`;\n\t}\n\tconst schemaWarning = schemaIndexRepresentationWarning(tableName, idx);\n\tconst ddlWarning = ddlIndexRepresentationWarning(tableName, idx);\n\treturn schemaWarning ?? ddlWarning;\n}\n\nfunction ddlIndexRepresentationWarning(\n\ttableName: string,\n\tidx: IndexIR,\n): string | undefined {\n\tif (canGenerateCreateIndex(tableName, idx, undefined, identityNaming)) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tgenerateCreateIndex(tableName, idx, undefined, identityNaming);\n\t} catch (error) {\n\t\treturn `Index ${warningName(idx.name)} on table ${warningName(tableName)} cannot be represented in the schema and is not managed by dbsp because the DDL emitter rejected it: ${errorMessage(error)}. dbsp will neither drop nor recreate it; maintain it by hand.`;\n\t}\n\treturn undefined;\n}\n\nfunction schemaIndexRepresentationWarning(\n\ttableName: string,\n\tidx: IndexIR,\n): string | undefined {\n\ttry {\n\t\tvalidateSchemaIndexOptions(tableName, idx);\n\t} catch (error) {\n\t\treturn `Index ${warningName(idx.name)} on table ${warningName(tableName)} cannot be represented in the schema and is not managed by dbsp because schema() rejected it: ${errorMessage(error)}. dbsp will neither drop nor recreate it; maintain it by hand.`;\n\t}\n\treturn undefined;\n}\n\nfunction schemaCodegenWarnings(model: ModelIR): string[] {\n\tconst warnings: string[] = [];\n\tfor (const table of model.tables.values()) {\n\t\tfor (const idx of table.indexes) {\n\t\t\tconst warning = indexRepresentationWarning(table.name, idx);\n\t\t\tif (warning !== undefined) {\n\t\t\t\twarnings.push(warning);\n\t\t\t}\n\t\t}\n\t}\n\treturn warnings;\n}\n\nfunction modelWarnings(model: ModelIR): readonly string[] {\n\tconst warnings = (model as ModelIR & { readonly warnings?: unknown })\n\t\t.warnings;\n\treturn Array.isArray(warnings) && warnings.every((w) => typeof w === 'string')\n\t\t? warnings\n\t\t: [];\n}\n\nfunction generateIndexCode(\n\tidx: IndexIR,\n\toptions: SchemaCodegenOptions,\n): string {\n\tconst indexOptions = [\n\t\t`columns: ${stringArrayLiteral(idx.columns.map((col) => generatedName(col, options)))}`,\n\t];\n\tif (idx.unique !== undefined) {\n\t\tindexOptions.push(`unique: ${booleanLiteral(idx.unique)}`);\n\t}\n\tif (idx.name !== undefined) {\n\t\tindexOptions.push(`name: ${singleQuoteEscape(idx.name)}`);\n\t}\n\tif (idx.method !== undefined) {\n\t\tindexOptions.push(`method: ${singleQuoteEscape(idx.method)}`);\n\t}\n\tif (idx.where !== undefined) {\n\t\tindexOptions.push(`where: ${singleQuoteEscape(idx.where)}`);\n\t}\n\tif (idx.opclass !== undefined) {\n\t\tindexOptions.push(\n\t\t\t`opclass: ${stringRecordLiteral(idx.opclass, (key) => generatedName(key, options))}`,\n\t\t);\n\t}\n\tif (idx.with !== undefined) {\n\t\tindexOptions.push(`with: ${stringRecordLiteral(idx.with)}`);\n\t}\n\tif (idx.include !== undefined) {\n\t\tindexOptions.push(\n\t\t\t`include: ${stringArrayLiteral(idx.include.map((col) => generatedName(col, options)))}`,\n\t\t);\n\t}\n\tif (idx.nullsNotDistinct !== undefined) {\n\t\tindexOptions.push(\n\t\t\t`nullsNotDistinct: ${booleanLiteral(idx.nullsNotDistinct)}`,\n\t\t);\n\t}\n\treturn `\\t\\t\\t{ ${indexOptions.join(', ')} }`;\n}\n\nfunction generateTableConstraintCode(\n\tmodel: ModelIR,\n\toptions: SchemaCodegenOptions,\n): string | undefined {\n\tconst tableBlocks: string[] = [];\n\tfor (const table of model.tables.values()) {\n\t\tconst fks = tableLevelForeignKeys(table);\n\t\tconst indexes = tableLevelIndexes(table);\n\t\tif (fks.length === 0 && indexes.length === 0) continue;\n\t\tconst tableOptions: string[] = [];\n\t\tif (indexes.length > 0) {\n\t\t\tconst indexLines = indexes.map((idx) => generateIndexCode(idx, options));\n\t\t\ttableOptions.push(`\\t\\tindexes: [\\n${indexLines.join(',\\n')}\\n\\t\\t]`);\n\t\t}\n\t\tif (fks.length > 0) {\n\t\t\tconst fkLines = fks.map((fk) => {\n\t\t\t\tconst refOptions = [\n\t\t\t\t\t...(fk.references.schema !== undefined\n\t\t\t\t\t\t? [`schema: ${singleQuoteEscape(fk.references.schema)}`]\n\t\t\t\t\t\t: []),\n\t\t\t\t\t`columns: ${stringArrayLiteral(fk.columns.map((col) => generatedName(col, options)))}`,\n\t\t\t\t\t`references: ${stringArrayLiteral(fk.references.columns.map((col) => generatedName(col, options)))}`,\n\t\t\t\t];\n\t\t\t\tif (fk.onDelete && fk.onDelete !== 'NO ACTION') {\n\t\t\t\t\trefOptions.push(`onDelete: ${singleQuoteEscape(fk.onDelete)}`);\n\t\t\t\t}\n\t\t\t\tif (fk.onUpdate && fk.onUpdate !== 'NO ACTION') {\n\t\t\t\t\trefOptions.push(`onUpdate: ${singleQuoteEscape(fk.onUpdate)}`);\n\t\t\t\t}\n\t\t\t\treturn `\\t\\t\\tref(${singleQuoteEscape(generatedName(fk.references.table, options))}, { ${refOptions.join(', ')} })`;\n\t\t\t});\n\t\t\ttableOptions.push(`\\t\\tforeignKeys: [\\n${fkLines.join(',\\n')}\\n\\t\\t]`);\n\t\t}\n\t\ttableBlocks.push(\n\t\t\t`\\t${quoteKey(generatedName(table.name, options))}: {\\n${tableOptions.join(',\\n')}\\n\\t}`,\n\t\t);\n\t}\n\tif (tableBlocks.length === 0) return undefined;\n\treturn `{\\n${tableBlocks.join(',\\n\\n')}\\n}`;\n}\n\n/**\n * Generate a TypeScript schema file from ModelIR and return diagnostics.\n *\n * @param model - The ModelIR (or IntrospectedModelIR) to generate from\n * @param options - Code generation options\n * @returns Generated source code and warnings\n */\nexport function generateSchemaFileWithDiagnostics(\n\tmodel: ModelIR,\n\toptions: SchemaCodegenDiagnosticsOptions = {},\n): SchemaCodegenResult {\n\tconst warnings = [...modelWarnings(model), ...schemaCodegenWarnings(model)];\n\tfor (const warning of warnings) {\n\t\toptions.onWarning?.(warning);\n\t}\n\n\tconst lines: string[] = [];\n\n\t// Header comment\n\tlines.push('/**');\n\tlines.push(' * Auto-generated by: dbsp introspect');\n\tif (options.sourceUrl) {\n\t\tconst redactedUrl = redactDbUrl(options.sourceUrl);\n\t\tlines.push(` * Source: ${blockCommentText(redactedUrl)}`);\n\t}\n\tif (options.introspectedAt) {\n\t\tlines.push(` * Generated: ${options.introspectedAt.toISOString()}`);\n\t}\n\tlines.push(' *');\n\tlines.push(' * Review before using in production.');\n\tlines.push(' */');\n\tlines.push('');\n\n\t// ARCH-005: Check if any table has FKs to determine imports\n\tconst hasForeignKeys = Array.from(model.tables.values()).some(\n\t\t(table) => table.foreignKeys.length > 0,\n\t);\n\n\t// Imports for the live schema() + ref() authoring API.\n\tconst coreImports = ['schema'];\n\tif (hasForeignKeys) {\n\t\tcoreImports.push('ref');\n\t}\n\tlines.push(`import { ${coreImports.join(', ')} } from '@dbsp/core';`);\n\tif (options.dbCasing && options.dbCasing !== 'preserve') {\n\t\tlines.push(\"import { createPgsqlAdapter } from '@dbsp/adapter-pgsql';\");\n\t}\n\tlines.push('');\n\n\t// Schema definition.\n\tlines.push('export const dbSchema = schema({');\n\n\t// Generate each table\n\tconst tables = Array.from(model.tables.values());\n\tconst tableLines = tables.map((table) => generateTableCode(table, options));\n\tlines.push(tableLines.join(',\\n\\n'));\n\n\tconst tableConstraints = generateTableConstraintCode(model, options);\n\tif (tableConstraints) {\n\t\tlines.push(`}, ${tableConstraints});`);\n\t} else {\n\t\tlines.push('});');\n\t}\n\tlines.push('');\n\n\t// Add a default export so schema-loader can load generated files directly.\n\t// schema-loader accepts module.schema || module.default; the named dbSchema\n\t// export is the canonical API, but the default export allows `loadSchema()`\n\t// to round-trip without the caller knowing the internal export name.\n\tlines.push('export default dbSchema;');\n\tlines.push('');\n\n\t// Usage hint with dbCasing\n\tif (options.dbCasing && options.dbCasing !== 'preserve') {\n\t\tlines.push('/**');\n\t\tlines.push(\n\t\t\t` * Usage: columns above are camelCase; the database uses ${options.dbCasing}.`,\n\t\t);\n\t\tlines.push(\n\t\t\t' * Pass dbCasing to the adapter so it maps camelCase ↔ snake_case automatically.',\n\t\t);\n\t\tlines.push(' *');\n\t\tlines.push(' * @example');\n\t\tlines.push(' * ```typescript');\n\t\tlines.push(' * const orm = createOrm({');\n\t\tlines.push(' * model: dbSchema.model,');\n\t\tlines.push(\n\t\t\t` * adapter: createPgsqlAdapter(pool, { dbCasing: '${options.dbCasing}' }),`,\n\t\t);\n\t\tlines.push(' * });');\n\t\tlines.push(' * ```');\n\t\tlines.push(' */');\n\t\tlines.push(`export const dbCasing = '${options.dbCasing}' as const;`);\n\t\tlines.push('');\n\t}\n\n\treturn {\n\t\tcode: lines.join('\\n'),\n\t\twarnings,\n\t};\n}\n","/**\n * Shared database utilities for CLI commands.\n *\n * E09: Extracted from verify.ts and introspect.ts to DRY up code.\n * E09b: Shared URL redaction for secure logging.\n */\n\n/**\n * Create a database connection pool.\n * pg is an optional peer dependency.\n *\n * @param connectionUrl - PostgreSQL connection URL\n * @returns Pool instance\n * @throws Error if pg is not installed\n */\nexport async function createDbConnection(connectionUrl: string) {\n\tlet pg: typeof import('pg').default;\n\ttry {\n\t\tconst mod = await import('pg');\n\t\tpg = mod.default;\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'pg is required for this command. Install it with: pnpm add pg',\n\t\t);\n\t}\n\n\tconst pool = new pg.Pool({\n\t\tconnectionString: connectionUrl,\n\t});\n\treturn { pool };\n}\n\n/**\n * Redact password from a database connection URL for safe logging.\n *\n * @param url - Database connection URL (e.g., postgres://user:pass@host/db)\n * @returns URL with password replaced by ***\n *\n * @example\n * redactDbUrl('postgres://user:secret@localhost/mydb')\n * // => 'postgres://user:***@localhost/mydb'\n */\nexport function redactDbUrl(url: string): string {\n\ttry {\n\t\tconst u = new URL(url);\n\t\tif (u.password) {\n\t\t\tu.password = '***';\n\t\t}\n\t\treturn u.toString();\n\t} catch {\n\t\t// Fall back to regex for non-standard or malformed URLs\n\t\treturn url.replace(/:[^:@]+@/, ':***@');\n\t}\n}\n"],"mappings":";AAOA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EAGC;AAAA,OACM;;;ACDP,eAAsB,mBAAmB,eAAuB;AAC/D,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,MAAM,OAAO,IAAI;AAC7B,SAAK,IAAI;AAAA,EACV,QAAQ;AACP,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,OAAO,IAAI,GAAG,KAAK;AAAA,IACxB,kBAAkB;AAAA,EACnB,CAAC;AACD,SAAO,EAAE,KAAK;AACf;AAYO,SAAS,YAAY,KAAqB;AAChD,MAAI;AACH,UAAM,IAAI,IAAI,IAAI,GAAG;AACrB,QAAI,EAAE,UAAU;AACf,QAAE,WAAW;AAAA,IACd;AACA,WAAO,EAAE,SAAS;AAAA,EACnB,QAAQ;AAEP,WAAO,IAAI,QAAQ,YAAY,OAAO;AAAA,EACvC;AACD;;;AD7BA,SAAS,iBAAiB,MAAsB;AAC/C,SAAO,KAAK,QAAQ,aAAa,CAAC,GAAG,WAAmB,OAAO,YAAY,CAAC;AAC7E;AAsDA,SAAS,kBAAkB,GAAmB;AAC7C,SAAO,IAAI,EACT,QAAQ,OAAO,MAAM,EACrB,QAAQ,MAAM,KAAK,EACnB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,CAAC;AACxB;AAQA,SAAS,iBAAiB,GAAmB;AAC5C,SAAO,EACL,QAAQ,SAAS,KAAK,EACtB,QAAQ,OAAO,KAAK,EACpB,QAA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