Files
fullstack-starter/src/server/db/fields.ts
T
imbytecat 695e826dcf refactor(types): 消除非必要 as 逃逸,锁紧 strict 政策
按 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,防止后续漂移。
2026-04-25 14:23:08 +08:00

22 lines
595 B
TypeScript

import { timestamp, uuid } from 'drizzle-orm/pg-core'
import { v7 as uuidv7 } from 'uuid'
export const generatedFields = {
id: uuid('id')
.primaryKey()
.$defaultFn(() => uuidv7()),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.notNull()
.defaultNow()
.$onUpdateFn(() => new Date()),
}
type GeneratedFieldKey = keyof typeof generatedFields
export const generatedFieldKeys = {
id: true,
createdAt: true,
updatedAt: true,
} satisfies Record<GeneratedFieldKey, true>