kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
903d052548
commit
612519ec68
|
@ -1,11 +1,11 @@
|
||||||
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import type { AuthenticatedEnv } from '@/lib/types'
|
import type { AuthenticatedEnv } from '@/lib/types'
|
||||||
import { db, eq, populateProjectSchema, schema } from '@/db'
|
import { db, eq, schema } from '@/db'
|
||||||
import { acl } from '@/lib/acl'
|
import { acl } from '@/lib/acl'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { ProjectIdParamsSchema } from './schemas'
|
import { populateProjectSchema, projectIdParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Gets a project',
|
description: 'Gets a project',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'projects/{projectId}',
|
path: 'projects/{projectId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: ProjectIdParamsSchema,
|
params: projectIdParamsSchema,
|
||||||
query: populateProjectSchema
|
query: populateProjectSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi'
|
import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import type { AuthenticatedEnv } from '@/lib/types'
|
import type { AuthenticatedEnv } from '@/lib/types'
|
||||||
import { db, eq, paginationSchema, schema } from '@/db'
|
import { db, eq, schema } from '@/db'
|
||||||
import { parseZodSchema } from '@/lib/utils'
|
import { parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
|
import { paginationAndPopulateProjectSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Lists projects the authenticated user has access to.',
|
description: 'Lists projects the authenticated user has access to.',
|
||||||
tags: ['projects'],
|
tags: ['projects'],
|
||||||
|
@ -12,7 +14,7 @@ const route = createRoute({
|
||||||
path: 'projects',
|
path: 'projects',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
query: paginationSchema
|
query: paginationAndPopulateProjectSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
@ -36,7 +38,8 @@ export function registerV1ProjectsListProjects(
|
||||||
offset = 0,
|
offset = 0,
|
||||||
limit = 10,
|
limit = 10,
|
||||||
sort = 'desc',
|
sort = 'desc',
|
||||||
sortBy = 'createdAt'
|
sortBy = 'createdAt',
|
||||||
|
populate = []
|
||||||
} = c.req.valid('query')
|
} = c.req.valid('query')
|
||||||
|
|
||||||
const user = c.get('user')
|
const user = c.get('user')
|
||||||
|
@ -50,7 +53,8 @@ export function registerV1ProjectsListProjects(
|
||||||
? eq(schema.projects.teamId, teamMember.teamId)
|
? eq(schema.projects.teamId, teamMember.teamId)
|
||||||
: eq(schema.projects.userId, user.id),
|
: eq(schema.projects.userId, user.id),
|
||||||
with: {
|
with: {
|
||||||
lastPublishedDeployment: true
|
lastPublishedDeployment: true,
|
||||||
|
...Object.fromEntries(populate.map((field) => [field, true]))
|
||||||
},
|
},
|
||||||
orderBy: (projects, { asc, desc }) => [
|
orderBy: (projects, { asc, desc }) => [
|
||||||
sort === 'desc' ? desc(projects[sortBy]) : asc(projects[sortBy])
|
sort === 'desc' ? desc(projects[sortBy]) : asc(projects[sortBy])
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { z } from '@hono/zod-openapi'
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { projectIdSchema } from '@/db'
|
import { paginationSchema, projectIdSchema } from '@/db'
|
||||||
|
import { projectRelationsSchema } from '@/db/schema'
|
||||||
|
|
||||||
export const ProjectIdParamsSchema = z.object({
|
export const projectIdParamsSchema = z.object({
|
||||||
projectId: projectIdSchema.openapi({
|
projectId: projectIdSchema.openapi({
|
||||||
param: {
|
param: {
|
||||||
description: 'Project ID',
|
description: 'Project ID',
|
||||||
|
@ -11,3 +12,12 @@ export const ProjectIdParamsSchema = z.object({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const populateProjectSchema = z.object({
|
||||||
|
populate: z.array(projectRelationsSchema).default([]).optional()
|
||||||
|
})
|
||||||
|
|
||||||
|
export const paginationAndPopulateProjectSchema = z.object({
|
||||||
|
...paginationSchema.shape,
|
||||||
|
...populateProjectSchema.shape
|
||||||
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
||||||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from './schemas'
|
import { teamSlugParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Deletes a team by slug.',
|
description: 'Deletes a team by slug.',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}',
|
path: 'teams/{team}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema
|
params: teamSlugParamsSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
||||||
import { aclTeamMember } from '@/lib/acl-team-member'
|
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from './schemas'
|
import { teamSlugParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Gets a team by slug.',
|
description: 'Gets a team by slug.',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}',
|
path: 'teams/{team}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema
|
params: teamSlugParamsSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { and, db, eq, schema } from '@/db'
|
||||||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from '../schemas'
|
import { teamSlugParamsSchema } from '../schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Creates a team member.',
|
description: 'Creates a team member.',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}/members',
|
path: 'teams/{team}/members',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema,
|
params: teamSlugParamsSchema,
|
||||||
body: {
|
body: {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
|
|
|
@ -6,8 +6,7 @@ import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||||
import { aclTeamMember } from '@/lib/acl-team-member'
|
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from '../schemas'
|
import { teamSlugTeamMemberUserIdParamsSchema } from './schemas'
|
||||||
import { TeamMemberUserIdParamsSchema } from './schemas'
|
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Deletes a team member.',
|
description: 'Deletes a team member.',
|
||||||
|
@ -17,7 +16,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}/members/{userId}',
|
path: 'teams/{team}/members/{userId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema.merge(TeamMemberUserIdParamsSchema)
|
params: teamSlugTeamMemberUserIdParamsSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
@ -54,7 +53,7 @@ export function registerV1TeamsMembersDeleteTeamMember(
|
||||||
assert(
|
assert(
|
||||||
teamMember,
|
teamMember,
|
||||||
404,
|
404,
|
||||||
`Team member "${userId}" for team "${teamSlug}" not found`
|
`Failed to update team member "${userId}" for team "${teamSlug}"`
|
||||||
)
|
)
|
||||||
|
|
||||||
return c.json(parseZodSchema(schema.teamMemberSelectSchema, teamMember))
|
return c.json(parseZodSchema(schema.teamMemberSelectSchema, teamMember))
|
||||||
|
|
|
@ -2,7 +2,10 @@ import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { userIdSchema } from '@/db'
|
import { userIdSchema } from '@/db'
|
||||||
|
|
||||||
export const TeamMemberUserIdParamsSchema = z.object({
|
import { teamSlugParamsSchema } from '../schemas'
|
||||||
|
|
||||||
|
export const teamSlugTeamMemberUserIdParamsSchema = z.object({
|
||||||
|
...teamSlugParamsSchema.shape,
|
||||||
userId: userIdSchema.openapi({
|
userId: userIdSchema.openapi({
|
||||||
param: {
|
param: {
|
||||||
description: 'Team member user ID',
|
description: 'Team member user ID',
|
||||||
|
|
|
@ -6,8 +6,7 @@ import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||||
import { aclTeamMember } from '@/lib/acl-team-member'
|
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from '../schemas'
|
import { teamSlugTeamMemberUserIdParamsSchema } from './schemas'
|
||||||
import { TeamMemberUserIdParamsSchema } from './schemas'
|
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Updates a team member.',
|
description: 'Updates a team member.',
|
||||||
|
@ -17,7 +16,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}/members/{userId}',
|
path: 'teams/{team}/members/{userId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema.merge(TeamMemberUserIdParamsSchema),
|
params: teamSlugTeamMemberUserIdParamsSchema,
|
||||||
body: {
|
body: {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { teamSlugSchema } from '@/db'
|
import { teamSlugSchema } from '@/db'
|
||||||
|
|
||||||
export const TeamSlugParamsSchema = z.object({
|
export const teamSlugParamsSchema = z.object({
|
||||||
team: teamSlugSchema.openapi({
|
team: teamSlugSchema.openapi({
|
||||||
param: {
|
param: {
|
||||||
description: 'Team slug',
|
description: 'Team slug',
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
||||||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { TeamSlugParamsSchema } from './schemas'
|
import { teamSlugParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Updates a team.',
|
description: 'Updates a team.',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'teams/{team}',
|
path: 'teams/{team}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: TeamSlugParamsSchema,
|
params: teamSlugParamsSchema,
|
||||||
body: {
|
body: {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
||||||
import { acl } from '@/lib/acl'
|
import { acl } from '@/lib/acl'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { UserIdParamsSchema } from './schemas'
|
import { userIdParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Gets a user',
|
description: 'Gets a user',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'users/{userId}',
|
path: 'users/{userId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: UserIdParamsSchema
|
params: userIdParamsSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { userIdSchema } from '@/db'
|
import { userIdSchema } from '@/db'
|
||||||
|
|
||||||
export const UserIdParamsSchema = z.object({
|
export const userIdParamsSchema = z.object({
|
||||||
userId: userIdSchema.openapi({
|
userId: userIdSchema.openapi({
|
||||||
param: {
|
param: {
|
||||||
description: 'User ID',
|
description: 'User ID',
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
||||||
import { acl } from '@/lib/acl'
|
import { acl } from '@/lib/acl'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
import { UserIdParamsSchema } from './schemas'
|
import { userIdParamsSchema } from './schemas'
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
description: 'Updates a user',
|
description: 'Updates a user',
|
||||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
||||||
path: 'users/{userId}',
|
path: 'users/{userId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: UserIdParamsSchema,
|
params: userIdParamsSchema,
|
||||||
body: {
|
body: {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { validators } from '@agentic/validators'
|
import { validators } from '@agentic/validators'
|
||||||
import { z } from '@hono/zod-openapi'
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { projectRelationsSchema } from './schema/project'
|
|
||||||
|
|
||||||
function getCuidSchema(idLabel: string) {
|
function getCuidSchema(idLabel: string) {
|
||||||
return z.string().refine((id) => validators.cuid(id), {
|
return z.string().refine((id) => validators.cuid(id), {
|
||||||
message: `Invalid ${idLabel}`
|
message: `Invalid ${idLabel}`
|
||||||
|
@ -43,10 +41,6 @@ export const paginationSchema = z.object({
|
||||||
sortBy: z.enum(['createdAt', 'updatedAt']).default('createdAt').optional()
|
sortBy: z.enum(['createdAt', 'updatedAt']).default('createdAt').optional()
|
||||||
})
|
})
|
||||||
|
|
||||||
export const populateProjectSchema = z.object({
|
|
||||||
populate: z.array(projectRelationsSchema).default([]).optional()
|
|
||||||
})
|
|
||||||
|
|
||||||
// import type { PgTable, TableConfig } from '@fisch0920/drizzle-orm/pg-core'
|
// import type { PgTable, TableConfig } from '@fisch0920/drizzle-orm/pg-core'
|
||||||
// import type { AnyZodObject } from 'zod'
|
// import type { AnyZodObject } from 'zod'
|
||||||
//
|
//
|
||||||
|
|
Ładowanie…
Reference in New Issue