pull/715/head
Travis Fischer 2025-05-20 17:13:59 +07:00
rodzic a128c145e7
commit 1a372fd9ff
3 zmienionych plików z 14 dodań i 3 usunięć

Wyświetl plik

@ -5,6 +5,12 @@ export { drizzle } from '@fisch0920/drizzle-orm/postgres-js'
export type PostgresClient = ReturnType<typeof postgres>
export * as schema from './schema'
export {
createIdForModel,
idMaxLength,
idPrefixMap,
type ModelType
} from './schema/common'
export * from './schema/schemas'
export * from './schemas'
export type * from './types'

Wyświetl plik

@ -1,12 +1,17 @@
import { expect, test } from 'vitest'
import { getIdSchemaForModelType } from '../schemas'
import { createId, idMaxLength, idPrefixMap, type ModelType } from './common'
import {
createIdForModel,
idMaxLength,
idPrefixMap,
type ModelType
} from './common'
for (const modelType of Object.keys(idPrefixMap)) {
test(`${modelType} id`, () => {
for (let i = 0; i < 100; ++i) {
const id = createId(modelType as ModelType)
const id = createIdForModel(modelType as ModelType)
expect(id.startsWith(idPrefixMap[modelType as ModelType])).toBe(true)
expect(id.length).toBeLessThanOrEqual(idMaxLength)
expect(getIdSchemaForModelType(modelType as ModelType).parse(id)).toBe(id)

Wyświetl plik

@ -33,7 +33,7 @@ export const idPrefixMap = {
export type ModelType = keyof typeof idPrefixMap
function createIdForModel(modelType: ModelType): string {
export function createIdForModel(modelType: ModelType): string {
const prefix = idPrefixMap[modelType]
assert(prefix, 500, `Invalid model type: ${modelType}`)