payload-cms
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePersistent HTTP server + thin CLI client for Payload CMS Local API.
用于Payload CMS Local API的持久化HTTP服务器+轻量CLI客户端。
Quick Start
快速开始
bash
undefinedbash
undefinedResolve plugin root even when CLAUDE_PLUGIN_ROOT is missing
Resolve plugin root even when CLAUDE_PLUGIN_ROOT is missing
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(node -e "const fs=require('fs');const path=require('path');const os=require('os');const c=['C:/.config/vercel-skills/skills/payload-cms',path.join(os.homedir(),'.claude/skills/payload-cms'),path.join(os.homedir(),'.agents/skills/payload-cms'),'P:/aromatt/payload/skills/payload-cms'];const hit=c.find(p=>fs.existsSync(path.join(p,'scripts','payload.js')));if(!hit){process.exit(1)};process.stdout.write(hit);")}"
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(node -e "const fs=require('fs');const path=require('path');const os=require('os');const c=['C:/.config/vercel-skills/skills/payload-cms',path.join(os.homedir(),'.claude/skills/payload-cms'),path.join(os.homedir(),'.agents/skills/payload-cms'),'P:/aromatt/payload/skills/payload-cms'];const hit=c.find(p=>fs.existsSync(path.join(p,'scripts','payload.js')));if(!hit){process.exit(1)};process.stdout.write(hit);")}"
1. Start the server (from project root)
1. 启动服务器(从项目根目录执行)
node "$PLUGIN_ROOT/scripts/payload.js" start
node "$PLUGIN_ROOT/scripts/payload.js" start
2. Query data
2. 查询数据
node "$PLUGIN_ROOT/scripts/payload.js" find users --limit 5
node "$PLUGIN_ROOT/scripts/payload.js" schema tutors
undefinednode "$PLUGIN_ROOT/scripts/payload.js" find users --limit 5
node "$PLUGIN_ROOT/scripts/payload.js" schema tutors
undefinedCLI
CLI
bash
node "$PLUGIN_ROOT/scripts/payload.js" $ARGUMENTSRun with for full command list.
Use from Quick Start in all examples below when is not set.
help$PLUGIN_ROOTCLAUDE_PLUGIN_ROOTbash
node "$PLUGIN_ROOT/scripts/payload.js" $ARGUMENTS运行时加上参数获取完整命令列表。
当未设置CLAUDE_PLUGIN_ROOT时,所有示例请使用快速开始中的。
help$PLUGIN_ROOTServer Lifecycle
服务器生命周期
The server initializes Payload once and serves requests over HTTP. This avoids re-initializing Payload for each query (~10-15s cold start).
| Command | Description |
|---|---|
| Start persistent Payload server (background) |
| Graceful shutdown |
| Check if server is running + uptime |
服务器会初始化一次Payload,并通过HTTP处理请求。这样避免了每次查询都重新初始化Payload(冷启动约10-15秒)。
| 命令 | 描述 |
|---|---|
| 启动持久化Payload服务器(后台运行) |
| 优雅关闭服务器 |
| 检查服务器是否运行及运行时长 |
Start Flags
启动参数
| Flag | Default | Description |
|---|---|---|
| | HTTP port |
| | Auto-shutdown after idle (ms, default 30min) |
| env | Test database connection string |
| env | Test database port |
| 参数 | 默认值 | 描述 |
|---|---|---|
| | HTTP端口 |
| | 空闲自动关闭超时时间(毫秒,默认30分钟) |
| 环境变量 | 测试数据库连接字符串 |
| 环境变量 | 测试数据库端口 |
Examples
示例
bash
undefinedbash
undefinedStart with defaults
使用默认配置启动
node $PLUGIN_ROOT/scripts/payload.js start
node $PLUGIN_ROOT/scripts/payload.js start
Start with custom port and test DB
使用自定义端口和测试数据库启动
node $PLUGIN_ROOT/scripts/payload.js start --port 9000 --test-db-url "postgresql://localhost:7357/test"
node $PLUGIN_ROOT/scripts/payload.js start --port 9000 --test-db-url "postgresql://localhost:7357/test"
Check status
检查状态
node $PLUGIN_ROOT/scripts/payload.js status
node $PLUGIN_ROOT/scripts/payload.js status
Stop server
停止服务器
node $PLUGIN_ROOT/scripts/payload.js stop
---node $PLUGIN_ROOT/scripts/payload.js stop
---Schema & Discovery
架构与发现
| Command | Description |
|---|---|
| List all collection slugs, field counts, labels |
| Full field definitions (name, type, required, relationships) |
Schema includes recursive field mapping for: text, number, email, relationship, upload, array, group, blocks, select, radio, checkbox, date, point, json, code, richText, tabs, collapsible, row.
| 命令 | 描述 |
|---|---|
| 列出所有集合别名、字段数量和标签 |
| 获取完整字段定义(名称、类型、必填项、关联关系) |
Schema包含以下字段的递归映射:text、number、email、relationship、upload、array、group、blocks、select、radio、checkbox、date、point、json、code、richText、tabs、collapsible、row。
Examples
示例
bash
undefinedbash
undefinedList all collections
列出所有集合
node $PLUGIN_ROOT/scripts/payload.js collections list
node $PLUGIN_ROOT/scripts/payload.js collections list
Get schema for a collection
获取某个集合的Schema
node $PLUGIN_ROOT/scripts/payload.js schema users
node $PLUGIN_ROOT/scripts/payload.js schema calendarEntries
---node $PLUGIN_ROOT/scripts/payload.js schema users
node $PLUGIN_ROOT/scripts/payload.js schema calendarEntries
---Query Operations
查询操作
All query commands require a running server ( first).
start| Command | Description |
|---|---|
| Find documents with filters, sort, pagination |
| Get a single document by ID |
| Count matching documents |
所有查询命令需要先启动服务器(执行命令)。
start| 命令 | 描述 |
|---|---|
| 使用筛选器、排序、分页查找文档 |
| 通过ID获取单个文档 |
| 统计匹配的文档数量 |
Query Flags
查询参数
| Flag | Description | Example |
|---|---|---|
| Database: | |
| JSON filter object | |
| Sort field (prefix | |
| Max results | |
| Page number (1-indexed) | |
| Population depth (default 1) | |
| Field selection | |
| Per-request timeout (ms) | |
| 参数 | 描述 | 示例 |
|---|---|---|
| 数据库: | |
| JSON筛选对象 | |
| 排序字段(前缀 | |
| 最大结果数 | |
| 页码(从1开始) | |
| 关联数据加载深度(默认1) | |
| 字段选择 | |
| 单请求超时时间(毫秒) | |
Where Clause Operators
Where子句操作符
json
{ "field": { "equals": "value" } }
{ "field": { "not_equals": "value" } }
{ "field": { "greater_than": 100 } }
{ "field": { "less_than": 100 } }
{ "field": { "like": "partial" } }
{ "field": { "contains": "text" } }
{ "field": { "in": ["a", "b"] } }
{ "field": { "not_in": ["a", "b"] } }
{ "field": { "exists": true } }Compound:
json
{ "and": [{ "status": { "equals": "active" } }, { "role": { "equals": "tutor" } }] }
{ "or": [{ "status": { "equals": "active" } }, { "status": { "equals": "pending" } }] }json
{ "field": { "equals": "value" } }
{ "field": { "not_equals": "value" } }
{ "field": { "greater_than": 100 } }
{ "field": { "less_than": 100 } }
{ "field": { "like": "partial" } }
{ "field": { "contains": "text" } }
{ "field": { "in": ["a", "b"] } }
{ "field": { "not_in": ["a", "b"] } }
{ "field": { "exists": true } }复合条件:
json
{ "and": [{ "status": { "equals": "active" } }, { "role": { "equals": "tutor" } }] }
{ "or": [{ "status": { "equals": "active" } }, { "status": { "equals": "pending" } }] }Query Examples
查询示例
bash
undefinedbash
undefinedFind first 5 users
查找前5个用户
node $PLUGIN_ROOT/scripts/payload.js find users --limit 5
node $PLUGIN_ROOT/scripts/payload.js find users --limit 5
Find active tutors sorted by name
查找活跃的导师并按名称排序
node $PLUGIN_ROOT/scripts/payload.js find tutors --where '{"status":{"equals":"active"}}' --sort name
node $PLUGIN_ROOT/scripts/payload.js find tutors --where '{"status":{"equals":"active"}}' --sort name
Find recent calendar entries
查找最近的日历条目
node $PLUGIN_ROOT/scripts/payload.js find calendarEntries --sort -createdAt --limit 10
node $PLUGIN_ROOT/scripts/payload.js find calendarEntries --sort -createdAt --limit 10
Count customers
统计客户数量
node $PLUGIN_ROOT/scripts/payload.js count customers
node $PLUGIN_ROOT/scripts/payload.js count customers
Get user by ID with minimal depth
通过ID获取用户,最小关联深度
node $PLUGIN_ROOT/scripts/payload.js find-by-id users --id abc123 --depth 0
node $PLUGIN_ROOT/scripts/payload.js find-by-id users --id abc123 --depth 0
Select specific fields only
仅选择特定字段
node $PLUGIN_ROOT/scripts/payload.js find users --select '{"email":true,"name":true}' --limit 10
node $PLUGIN_ROOT/scripts/payload.js find users --select '{"email":true,"name":true}' --limit 10
Query test database
查询测试数据库
node $PLUGIN_ROOT/scripts/payload.js find users --db test --limit 5
---node $PLUGIN_ROOT/scripts/payload.js find users --db test --limit 5
---Mutate Operations
修改操作
| Command | Description |
|---|---|
| Create a new document |
| Update an existing document |
| Delete a document |
Data can be passed via flag or piped through stdin.
--data| 命令 | 描述 |
|---|---|
| 创建新文档 |
| 更新现有文档 |
| 删除文档 |
数据可通过参数传递,或通过标准输入管道传入。
--dataMutate Flags
修改参数
| Flag | Description |
|---|---|
| JSON string with document data |
| Document ID (required for update/delete) |
| Database: |
| Population depth in response |
| Field selection in response |
| 参数 | 描述 |
|---|---|
| 包含文档数据的JSON字符串 |
| 文档ID(更新/删除时必填) |
| 数据库: |
| 响应中的关联数据加载深度 |
| 响应中的字段选择 |
Mutate Examples
修改示例
bash
undefinedbash
undefinedCreate a document
创建文档
node $PLUGIN_ROOT/scripts/payload.js create customers --data '{"name":"John","email":"john@example.com"}'
node $PLUGIN_ROOT/scripts/payload.js create customers --data '{"name":"John","email":"john@example.com"}'
Create via stdin pipe
通过标准输入管道创建
echo '{"name":"Jane","email":"jane@example.com"}' | node $PLUGIN_ROOT/scripts/payload.js create customers
echo '{"name":"Jane","email":"jane@example.com"}' | node $PLUGIN_ROOT/scripts/payload.js create customers
Update a document
更新文档
node $PLUGIN_ROOT/scripts/payload.js update customers --id abc123 --data '{"name":"John Updated"}'
node $PLUGIN_ROOT/scripts/payload.js update customers --id abc123 --data '{"name":"John Updated"}'
Delete a document
删除文档
node $PLUGIN_ROOT/scripts/payload.js delete customers --id abc123
node $PLUGIN_ROOT/scripts/payload.js delete customers --id abc123
Mutate on test database
在测试数据库中执行修改操作
node $PLUGIN_ROOT/scripts/payload.js create customers --db test --data '{"name":"Test User"}'
---node $PLUGIN_ROOT/scripts/payload.js create customers --db test --data '{"name":"Test User"}'
---Output Format
输出格式
All commands output JSON to stdout:
json
// Success
{ "ok": true, "data": { ... } }
// Error
{ "ok": false, "error": { "message": "...", "code": "..." } }Find results include Payload pagination:
json
{
"ok": true,
"data": {
"docs": [...],
"totalDocs": 42,
"limit": 10,
"totalPages": 5,
"page": 1,
"pagingCounter": 1,
"hasPrevPage": false,
"hasNextPage": true,
"prevPage": null,
"nextPage": 2
}
}所有命令均向标准输出输出JSON:
json
// Success
{ "ok": true, "data": { ... } }
// Error
{ "ok": false, "error": { "message": "...", "code": "..." } }查询结果包含Payload分页信息:
json
{
"ok": true,
"data": {
"docs": [...],
"totalDocs": 42,
"limit": 10,
"totalPages": 5,
"page": 1,
"pagingCounter": 1,
"hasPrevPage": false,
"hasNextPage": true,
"prevPage": null,
"nextPage": 2
}
}Architecture
架构
payload.js (CLI client, CommonJS, zero deps)
│
▼ HTTP
server.ts (persistent, initialized Payload instances)
│
▼ Local API
Payload CMS (dev DB + optional test DB)- Server starts once, stays running (30min idle timeout)
- Each CLI call makes an HTTP request to the running server
- Server PID + port stored in
${PAYLOAD_CMS_HOME:-~/.payload-cms}/server.json
payload.js (CLI client, CommonJS, zero deps)
│
▼ HTTP
server.ts (persistent, initialized Payload instances)
│
▼ Local API
Payload CMS (dev DB + optional test DB)- 服务器启动一次后保持运行(30分钟空闲超时)
- 每次CLI调用向运行中的服务器发送HTTP请求
- 服务器PID和端口存储在中
${PAYLOAD_CMS_HOME:-~/.payload-cms}/server.json