MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / emitSchemaFile

Function emitSchemaFile

packages/wl-sdk/scripts/generate-from-schema.ts:154–188  ·  view source on GitHub ↗
(schemaSql: string)

Source from the content-addressed store, hash-verified

152}
153
154function emitSchemaFile(schemaSql: string): string {
155 const parsed = parseSchema(schemaSql);
156
157 const versionStmt = parsed.statements.find(s =>
158 /INSERT\s+IGNORE\s+INTO\s+_meta.+schema_version/i.test(s)
159 );
160 const versionMatch = versionStmt
161 ? /VALUES\s*\(\s*'schema_version'\s*,\s*'([^']+)'/i.exec(versionStmt)
162 : null;
163 const schemaVersion = versionMatch ? versionMatch[1] : 'unknown';
164
165 const sections: string[] = [];
166 sections.push(HEADER_LINES.join('\n'));
167 sections.push(`import { z } from 'zod';`);
168 sections.push(`export const COMMONS_SCHEMA_VERSION = ${JSON.stringify(schemaVersion)} as const;`);
169
170 for (const table of parsed.tables) {
171 sections.push(renderRowSchema(table));
172 sections.push(renderTableMeta(table));
173 }
174
175 sections.push(
176 [
177 '/**',
178 ' * The wasteland commons DDL split into individual statements, ready to',
179 " * feed to DoltHub's write API one at a time. Order is preserved from",
180 ' * the source file. Statements have no trailing `;` so callers can append',
181 ' * one (or not) as the API expects.',
182 ' */',
183 renderSchemaStatements(parsed.statements.map(renderCreateTableStatement)),
184 ].join('\n')
185 );
186
187 return sections.join('\n\n') + '\n';
188}
189
190// ---------------------------------------------------------------------------
191// DML helpers

Callers 1

mainFunction · 0.85

Calls 7

parseSchemaFunction · 0.90
renderRowSchemaFunction · 0.85
renderTableMetaFunction · 0.85
renderSchemaStatementsFunction · 0.85
pushMethod · 0.80
joinMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected