kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
f4546c2218
commit
c67a94529f
|
@ -136,6 +136,7 @@ export const consumerSelectSchema = createSelectSchema(consumers, {
|
|||
.optional()
|
||||
.openapi('Deployment', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('Consumer')
|
||||
|
||||
export const consumerInsertSchema = createInsertSchema(consumers)
|
||||
|
|
|
@ -125,6 +125,7 @@ export const deploymentSelectSchema = createSelectSchema(deployments, {
|
|||
.optional()
|
||||
.openapi('Team', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('Deployment')
|
||||
|
||||
export const deploymentInsertSchema = createInsertSchema(deployments, {
|
||||
|
|
|
@ -101,6 +101,7 @@ export const logEntrySelectSchema = createSelectSchema(logEntries)
|
|||
.optional()
|
||||
.openapi('Consumer', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('LogEntry')
|
||||
|
||||
export const logEntryInsertSchema = createInsertSchema(logEntries)
|
||||
|
|
|
@ -192,6 +192,7 @@ export const projectSelectSchema = createSelectSchema(projects, {
|
|||
.optional()
|
||||
.openapi('Deployment', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('Project')
|
||||
|
||||
export const projectInsertSchema = createInsertSchema(projects, {
|
||||
|
|
|
@ -72,6 +72,7 @@ export const teamMemberSelectSchema = createSelectSchema(teamMembers)
|
|||
.optional()
|
||||
.openapi('Team', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('TeamMember')
|
||||
|
||||
export const teamMemberInsertSchema = createInsertSchema(teamMembers)
|
||||
|
|
|
@ -53,6 +53,7 @@ export const teamSelectSchema = createSelectSchema(teams)
|
|||
.optional()
|
||||
.openapi('User', { type: 'object' })
|
||||
})
|
||||
.strip()
|
||||
.openapi('Team')
|
||||
|
||||
export const teamInsertSchema = createInsertSchema(teams, {
|
||||
|
|
|
@ -5,36 +5,50 @@ export const authProviderTypeSchema = z
|
|||
.openapi('AuthProviderType')
|
||||
export type AuthProviderType = z.infer<typeof authProviderTypeSchema>
|
||||
|
||||
export const authProviderSchema = z
|
||||
.object({
|
||||
provider: authProviderTypeSchema,
|
||||
export const authProviderSchema = z.object({
|
||||
provider: authProviderTypeSchema,
|
||||
|
||||
/** Provider-specific user id */
|
||||
id: z.string(),
|
||||
/** Provider-specific user id */
|
||||
id: z.string(),
|
||||
|
||||
/** Provider-specific username */
|
||||
username: z.string().optional(),
|
||||
/** Provider-specific username */
|
||||
username: z.string().optional(),
|
||||
|
||||
/** Standard oauth2 access token */
|
||||
accessToken: z.string().optional(),
|
||||
/** Standard oauth2 access token */
|
||||
accessToken: z.string().optional(),
|
||||
|
||||
/** Standard oauth2 refresh token */
|
||||
refreshToken: z.string().optional(),
|
||||
/** Standard oauth2 refresh token */
|
||||
refreshToken: z.string().optional(),
|
||||
|
||||
/** Stripe public key */
|
||||
publicKey: z.string().optional(),
|
||||
/** Stripe public key */
|
||||
publicKey: z.string().optional(),
|
||||
|
||||
/** OAuth scope(s) */
|
||||
scope: z.string().optional()
|
||||
})
|
||||
.openapi('AuthProvider')
|
||||
/** OAuth scope(s) */
|
||||
scope: z.string().optional()
|
||||
})
|
||||
export type AuthProvider = z.infer<typeof authProviderSchema>
|
||||
|
||||
export const authProvidersSchema = z
|
||||
.record(authProviderTypeSchema, authProviderSchema.optional())
|
||||
.openapi('AuthProviders')
|
||||
export const publicAuthProviderSchema = authProviderSchema
|
||||
.omit({
|
||||
accessToken: true,
|
||||
refreshToken: true,
|
||||
publicKey: true
|
||||
})
|
||||
.strip()
|
||||
.openapi('AuthProvider')
|
||||
export type PublicAuthProvider = z.infer<typeof publicAuthProviderSchema>
|
||||
|
||||
export const authProvidersSchema = z.record(
|
||||
authProviderTypeSchema,
|
||||
authProviderSchema.optional()
|
||||
)
|
||||
export type AuthProviders = z.infer<typeof authProvidersSchema>
|
||||
|
||||
export const publicAuthProvidersSchema = z
|
||||
.record(authProviderTypeSchema, publicAuthProviderSchema.optional())
|
||||
.openapi('AuthProviders')
|
||||
export type PublicAuthProviders = z.infer<typeof publicAuthProvidersSchema>
|
||||
|
||||
export const webhookSchema = z
|
||||
.object({
|
||||
url: z.string(),
|
||||
|
|
|
@ -13,7 +13,7 @@ import { hashSync } from 'bcryptjs'
|
|||
import { sha256 } from '@/lib/utils'
|
||||
|
||||
import { teams } from './team'
|
||||
import { type AuthProviders, authProvidersSchema } from './types'
|
||||
import { type AuthProviders, publicAuthProvidersSchema } from './types'
|
||||
import {
|
||||
createInsertSchema,
|
||||
createSelectSchema,
|
||||
|
@ -69,7 +69,12 @@ export const usersRelations = relations(users, ({ many }) => ({
|
|||
teamsOwned: many(teams)
|
||||
}))
|
||||
|
||||
export const userSelectSchema = createSelectSchema(users).openapi('User')
|
||||
export const userSelectSchema = createSelectSchema(users, {
|
||||
providers: publicAuthProvidersSchema
|
||||
})
|
||||
.omit({ password: true, emailConfirmToken: true, passwordResetToken: true })
|
||||
.strip()
|
||||
.openapi('User')
|
||||
|
||||
export const userInsertSchema = createInsertSchema(users, {
|
||||
username: (schema) =>
|
||||
|
@ -77,9 +82,7 @@ export const userInsertSchema = createInsertSchema(users, {
|
|||
message: 'Invalid username'
|
||||
}),
|
||||
|
||||
email: (schema) => schema.email().optional(),
|
||||
|
||||
providers: authProvidersSchema.optional()
|
||||
email: (schema) => schema.email().optional()
|
||||
})
|
||||
.pick({
|
||||
username: true,
|
||||
|
|
|
@ -4,10 +4,11 @@ import type { schema } from '.'
|
|||
import type { User } from './types'
|
||||
|
||||
type UserSelect = typeof schema.users.$inferSelect
|
||||
type UserKeys = Exclude<keyof User, 'providers'>
|
||||
|
||||
test('User types are compatible', () => {
|
||||
// TODO: { github?: AuthProvider | undefined } !== { github: AuthProvider | undefined }
|
||||
expectTypeOf<UserSelect>().toExtend<User>()
|
||||
|
||||
expectTypeOf<User[keyof User]>().toEqualTypeOf<UserSelect[keyof UserSelect]>()
|
||||
expectTypeOf<User[UserKeys]>().toEqualTypeOf<UserSelect[UserKeys]>()
|
||||
})
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git"
|
||||
},
|
||||
"packageManager": "pnpm@10.10.0",
|
||||
"packageManager": "pnpm@10.11.0",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
|
|
Ładowanie…
Reference in New Issue