用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mx-space/core --skill api-conventions命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Create a new NestJS module with repository, service, controller, schema, and Drizzle table definition. Use when adding new feature modules, API endpoints, or business domains.
Review code for Mix Space project conventions. Checks NestJS patterns, Drizzle ORM repositories, Zod schemas, API design, etc.
Mix Space project Zod schema patterns. Apply when creating DTOs, validation schemas, or handling request validation.
正在显示 SKILL.md
| name | api-conventions |
| description | Mix Space API design conventions. Apply when writing controllers, API endpoints, or handling HTTP requests. |
| user-invocable | false |
// Use @ApiController instead of @Controller
// Dev environment has no prefix, production auto-adds /api/v{version} prefix
@ApiController('posts') // ✓
@Controller('posts') // ✗
// Endpoints requiring login
@Auth()
async create() {}
// Optional auth (get current user status)
async get(@IsAuthenticated() isAuth: boolean) {}
// Get current user
async get(@CurrentUser() user: UserModel) {}
ResponseInterceptor (global APP_INTERCEPTOR) wraps every controller return value:
| Return value | Emitted |
|---|---|
bare value T | { data: T } |
withMeta(data, meta) | { data, meta } |
undefined | 204 No Content |
@HTTPDecorators.RawResponse | untouched — skips envelope and case conversion |
withMeta (from ~/common/response/envelope.types) is detected by an internal Symbol,
not by the presence of a data key — returning an object literal whose top-level keys
include data gets double-wrapped. CI enforces this via
scripts/check-controller-response-envelope.ts.
transformResponseCase (~/common/response/case-transform.ts) converts the response
data/meta to snake_case at the wire boundary:
createdAt → created_atcategoryId → category_idOpt a field subtree out with @BypassCaseTransform(['items[].rawPayload']).
Pagination belongs in meta, never merged into data. Build it with MetaObjectBuilder:
@Get('/')
async list(@Query() query: PagerDto) {
const result = await this.postRepository.list({
page: query.page,
size: query.size,
sortBy: query.sortBy,
sortOrder: query.sortOrder,
})
const metaBuilder = new MetaObjectBuilder().view('card').pagination({
page: result.pagination.currentPage,
size: result.pagination.size,
total: result.pagination.total,
totalPages: result.pagination.totalPage,
})
return withMeta(result.data, metaBuilder.build())
}
For CRUD boilerplate, use BasePgCrudFactory:
@ApiController(paths)
export class LinkControllerCrud extends BasePgCrudFactory({
repository: LinkRepository,
}) {
@Get('/')
async gets(@Query() pager: PagerDto) {
const { size = 10, page = 1 } = pager
return this.repository.list(page, size)
}
}
// Path parameters — use EntityIdDto for Snowflake entity IDs
@Get('/:id')
async get(@Param() params: EntityIdDto) {
return this.service.findById(params.id)
}
// For integer IDs or entity IDs (e.g. notes with nid)
@Get('/:id')
async get(@Param() params: IntIdOrEntityIdDto) {}
// Query parameters
@Get('/')
async list(@Query() query: PagerDto) {}
// Request body
@Post('/')
async create(@Body() body: CreateDto) {}
| Method | Purpose | Status Code |
|---|---|---|
| GET | Retrieve resource | 200 |
| POST | Create resource | 201 |
| PUT | Full update | 200 |
| PATCH | Partial update | 200 |
| DELETE | Delete resource | 204 |
import { BusinessException } from '~/common/exceptions/biz.exception'
import { ErrorCodeEnum } from '~/constants/error-code.constant'
// Business errors
throw new BusinessException(ErrorCodeEnum.PostNotFound)
throw new BusinessException(ErrorCodeEnum.SlugNotAvailable, slug)
// HTTP errors
throw new BadRequestException('Invalid input')
throw new NotFoundException('Resource not found')
throw new UnauthorizedException('Not logged in')
// Add idempotency protection for create operations
@Post('/')
@HTTPDecorators.Idempotence()
async create() {}
// Custom idempotency key
@HTTPDecorators.Idempotence({ key: 'custom-key' })
// Disable cache
@Get('/')
@HttpCache.disable
async list() {}
// Custom cache
@HttpCache({ ttl: 60, key: 'my-key' })
async get() {}