pull/715/head
Travis Fischer 2025-05-14 16:48:40 +07:00
rodzic f4546c2218
commit c67a94529f
10 zmienionych plików z 51 dodań i 27 usunięć

Wyświetl plik

@ -136,6 +136,7 @@ export const consumerSelectSchema = createSelectSchema(consumers, {
.optional() .optional()
.openapi('Deployment', { type: 'object' }) .openapi('Deployment', { type: 'object' })
}) })
.strip()
.openapi('Consumer') .openapi('Consumer')
export const consumerInsertSchema = createInsertSchema(consumers) export const consumerInsertSchema = createInsertSchema(consumers)

Wyświetl plik

@ -125,6 +125,7 @@ export const deploymentSelectSchema = createSelectSchema(deployments, {
.optional() .optional()
.openapi('Team', { type: 'object' }) .openapi('Team', { type: 'object' })
}) })
.strip()
.openapi('Deployment') .openapi('Deployment')
export const deploymentInsertSchema = createInsertSchema(deployments, { export const deploymentInsertSchema = createInsertSchema(deployments, {

Wyświetl plik

@ -101,6 +101,7 @@ export const logEntrySelectSchema = createSelectSchema(logEntries)
.optional() .optional()
.openapi('Consumer', { type: 'object' }) .openapi('Consumer', { type: 'object' })
}) })
.strip()
.openapi('LogEntry') .openapi('LogEntry')
export const logEntryInsertSchema = createInsertSchema(logEntries) export const logEntryInsertSchema = createInsertSchema(logEntries)

Wyświetl plik

@ -192,6 +192,7 @@ export const projectSelectSchema = createSelectSchema(projects, {
.optional() .optional()
.openapi('Deployment', { type: 'object' }) .openapi('Deployment', { type: 'object' })
}) })
.strip()
.openapi('Project') .openapi('Project')
export const projectInsertSchema = createInsertSchema(projects, { export const projectInsertSchema = createInsertSchema(projects, {

Wyświetl plik

@ -72,6 +72,7 @@ export const teamMemberSelectSchema = createSelectSchema(teamMembers)
.optional() .optional()
.openapi('Team', { type: 'object' }) .openapi('Team', { type: 'object' })
}) })
.strip()
.openapi('TeamMember') .openapi('TeamMember')
export const teamMemberInsertSchema = createInsertSchema(teamMembers) export const teamMemberInsertSchema = createInsertSchema(teamMembers)

Wyświetl plik

@ -53,6 +53,7 @@ export const teamSelectSchema = createSelectSchema(teams)
.optional() .optional()
.openapi('User', { type: 'object' }) .openapi('User', { type: 'object' })
}) })
.strip()
.openapi('Team') .openapi('Team')
export const teamInsertSchema = createInsertSchema(teams, { export const teamInsertSchema = createInsertSchema(teams, {

Wyświetl plik

@ -5,36 +5,50 @@ export const authProviderTypeSchema = z
.openapi('AuthProviderType') .openapi('AuthProviderType')
export type AuthProviderType = z.infer<typeof authProviderTypeSchema> export type AuthProviderType = z.infer<typeof authProviderTypeSchema>
export const authProviderSchema = z export const authProviderSchema = z.object({
.object({ provider: authProviderTypeSchema,
provider: authProviderTypeSchema,
/** Provider-specific user id */ /** Provider-specific user id */
id: z.string(), id: z.string(),
/** Provider-specific username */ /** Provider-specific username */
username: z.string().optional(), username: z.string().optional(),
/** Standard oauth2 access token */ /** Standard oauth2 access token */
accessToken: z.string().optional(), accessToken: z.string().optional(),
/** Standard oauth2 refresh token */ /** Standard oauth2 refresh token */
refreshToken: z.string().optional(), refreshToken: z.string().optional(),
/** Stripe public key */ /** Stripe public key */
publicKey: z.string().optional(), publicKey: z.string().optional(),
/** OAuth scope(s) */ /** OAuth scope(s) */
scope: z.string().optional() scope: z.string().optional()
}) })
.openapi('AuthProvider')
export type AuthProvider = z.infer<typeof authProviderSchema> export type AuthProvider = z.infer<typeof authProviderSchema>
export const authProvidersSchema = z export const publicAuthProviderSchema = authProviderSchema
.record(authProviderTypeSchema, authProviderSchema.optional()) .omit({
.openapi('AuthProviders') 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 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 export const webhookSchema = z
.object({ .object({
url: z.string(), url: z.string(),

Wyświetl plik

@ -13,7 +13,7 @@ import { hashSync } from 'bcryptjs'
import { sha256 } from '@/lib/utils' import { sha256 } from '@/lib/utils'
import { teams } from './team' import { teams } from './team'
import { type AuthProviders, authProvidersSchema } from './types' import { type AuthProviders, publicAuthProvidersSchema } from './types'
import { import {
createInsertSchema, createInsertSchema,
createSelectSchema, createSelectSchema,
@ -69,7 +69,12 @@ export const usersRelations = relations(users, ({ many }) => ({
teamsOwned: many(teams) 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, { export const userInsertSchema = createInsertSchema(users, {
username: (schema) => username: (schema) =>
@ -77,9 +82,7 @@ export const userInsertSchema = createInsertSchema(users, {
message: 'Invalid username' message: 'Invalid username'
}), }),
email: (schema) => schema.email().optional(), email: (schema) => schema.email().optional()
providers: authProvidersSchema.optional()
}) })
.pick({ .pick({
username: true, username: true,

Wyświetl plik

@ -4,10 +4,11 @@ import type { schema } from '.'
import type { User } from './types' import type { User } from './types'
type UserSelect = typeof schema.users.$inferSelect type UserSelect = typeof schema.users.$inferSelect
type UserKeys = Exclude<keyof User, 'providers'>
test('User types are compatible', () => { test('User types are compatible', () => {
// TODO: { github?: AuthProvider | undefined } !== { github: AuthProvider | undefined } // TODO: { github?: AuthProvider | undefined } !== { github: AuthProvider | undefined }
expectTypeOf<UserSelect>().toExtend<User>() expectTypeOf<UserSelect>().toExtend<User>()
expectTypeOf<User[keyof User]>().toEqualTypeOf<UserSelect[keyof UserSelect]>() expectTypeOf<User[UserKeys]>().toEqualTypeOf<UserSelect[UserKeys]>()
}) })

Wyświetl plik

@ -7,7 +7,7 @@
"type": "git", "type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git" "url": "git+https://github.com/transitive-bullshit/agentic-platform.git"
}, },
"packageManager": "pnpm@10.10.0", "packageManager": "pnpm@10.11.0",
"engines": { "engines": {
"node": ">=18" "node": ">=18"
}, },