kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
a128c145e7
commit
1a372fd9ff
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}`)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue