695e826dcf
按 Oracle 复核处置全仓 5 处类型断言: - fields.ts: as const → satisfies Record<GeneratedFieldKey, true> - compile.ts: as readonly string[] → ReadonlySet<string>.has() - embed-migrations.ts: JSON.parse as Journal → Zod schema 运行时校验,JSON.parse 显式 unknown - interceptors.ts: 唯一保留的跨包断言(ORPC→Zod)注释扩写为完整背景 - router.tsx: satisfies 非 cast,保留 biome.json 增配 noExplicitAny / noTsIgnore / noNonNullAssertion,防止后续漂移。
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { existsSync } from 'node:fs'
|
|
import { readFile, writeFile } from 'node:fs/promises'
|
|
import { z } from 'zod'
|
|
|
|
const JOURNAL = './drizzle/meta/_journal.json'
|
|
const OUTPUT = './src/server/db/migrations.gen.ts'
|
|
const SQL_RELATIVE_FROM_OUTPUT = '../../../drizzle'
|
|
|
|
const journalEntrySchema = z.object({
|
|
idx: z.number(),
|
|
tag: z.string(),
|
|
when: z.number(),
|
|
breakpoints: z.boolean(),
|
|
})
|
|
const journalSchema = z.object({ entries: z.array(journalEntrySchema).default([]) })
|
|
|
|
type JournalEntry = z.infer<typeof journalEntrySchema>
|
|
|
|
const readJournalEntries = async (): Promise<JournalEntry[]> => {
|
|
if (!existsSync(JOURNAL)) {
|
|
return []
|
|
}
|
|
const raw: unknown = JSON.parse(await readFile(JOURNAL, 'utf-8'))
|
|
return journalSchema.parse(raw).entries.sort((a, b) => a.idx - b.idx)
|
|
}
|
|
|
|
const main = async () => {
|
|
const entries = await readJournalEntries()
|
|
|
|
const imports = entries
|
|
.map((e) => `import sql_${e.idx} from '${SQL_RELATIVE_FROM_OUTPUT}/${e.tag}.sql' with { type: 'text' }`)
|
|
.join('\n')
|
|
|
|
const arrayBody = entries.length
|
|
? `[\n${entries.map((e) => ` { tag: '${e.tag}', sql: sql_${e.idx}, when: ${e.when}, breakpoints: ${e.breakpoints} },`).join('\n')}\n]`
|
|
: '[]'
|
|
|
|
const out = `// AUTO-GENERATED by \`bun run db:embed\`. Do not edit.
|
|
${imports ? `${imports}\n` : ''}
|
|
export type EmbeddedMigration = { tag: string; sql: string; when: number; breakpoints: boolean }
|
|
|
|
export const embeddedMigrations: readonly EmbeddedMigration[] = ${arrayBody}
|
|
`
|
|
|
|
await writeFile(OUTPUT, out)
|
|
console.log(`✓ ${OUTPUT} (${entries.length} migration${entries.length === 1 ? '' : 's'})`)
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('❌', err instanceof Error ? err.message : err)
|
|
process.exit(1)
|
|
})
|