kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
6b36a91aa7
commit
fbbbc0f2f2
|
@ -33,13 +33,29 @@ export const idPrefixMap = {
|
||||||
|
|
||||||
export type ModelType = keyof typeof idPrefixMap
|
export type ModelType = keyof typeof idPrefixMap
|
||||||
|
|
||||||
export function createId(modelType: ModelType): string {
|
function createIdForModel(modelType: ModelType): string {
|
||||||
const prefix = idPrefixMap[modelType]
|
const prefix = idPrefixMap[modelType]
|
||||||
assert(prefix, 500, `Invalid model type: ${modelType}`)
|
assert(prefix, 500, `Invalid model type: ${modelType}`)
|
||||||
|
|
||||||
return `${prefix}_${createCuid2()}`
|
return `${prefix}_${createCuid2()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the `id` primary key to use for a given model type.
|
||||||
|
*/
|
||||||
|
function getPrimaryId(modelType: ModelType) {
|
||||||
|
return id()
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => createIdForModel(modelType))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const projectPrimaryId = getPrimaryId('project')
|
||||||
|
export const deploymentPrimaryId = getPrimaryId('deployment')
|
||||||
|
export const consumerPrimaryId = getPrimaryId('consumer')
|
||||||
|
export const logEntryPrimaryId = getPrimaryId('logEntry')
|
||||||
|
export const teamPrimaryId = getPrimaryId('team')
|
||||||
|
export const userPrimaryId = getPrimaryId('user')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of our model primary ids have the following format:
|
* All of our model primary ids have the following format:
|
||||||
*
|
*
|
||||||
|
@ -51,22 +67,6 @@ export function id<U extends string, T extends Readonly<[U, ...U[]]>>(
|
||||||
return varchar({ length: idMaxLength, ...config })
|
return varchar({ length: idMaxLength, ...config })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the `id` primary key to use for a given model type.
|
|
||||||
*/
|
|
||||||
function getPrimaryId(modelType: ModelType) {
|
|
||||||
return id()
|
|
||||||
.primaryKey()
|
|
||||||
.$defaultFn(() => createId(modelType))
|
|
||||||
}
|
|
||||||
|
|
||||||
export const projectPrimaryId = getPrimaryId('project')
|
|
||||||
export const deploymentPrimaryId = getPrimaryId('deployment')
|
|
||||||
export const consumerPrimaryId = getPrimaryId('consumer')
|
|
||||||
export const logEntryPrimaryId = getPrimaryId('logEntry')
|
|
||||||
export const teamPrimaryId = getPrimaryId('team')
|
|
||||||
export const userPrimaryId = getPrimaryId('user')
|
|
||||||
|
|
||||||
export const projectId = id
|
export const projectId = id
|
||||||
export const deploymentId = id
|
export const deploymentId = id
|
||||||
export const consumerId = id
|
export const consumerId = id
|
||||||
|
|
Ładowanie…
Reference in New Issue