# @crvouga/mockingbird-service-payload-cms 中文文档

规范地址：https://npmcn.com/package/%40crvouga/mockingbird-service-payload-cms/

版本：3\.11\.0
npm 元数据更新时间：2026-11-11T02:28:01.463Z
中文译文更新时间：2026-11-11T05:51:38.539Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40crvouga/mockingbird-service-payload-cms
原文对照：https://npmcn.com/package/%40crvouga/mockingbird-service-payload-cms/?lang=original
项目主页：https://github.com/crvouga/mockingbird/tree/main/packages/service/payload-cms#readme
源码仓库：https://github.com/crvouga/mockingbird

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：4.3 MB，18 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2026-09-22T23:56:12.371Z
- 最新版本发布：2026-11-11T02:28:01.093Z
- 近 30 天下载量：3093（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：42（近 12 个月 42 个）

## 中文简介

Bayload CMS Collection REST API 的状态仿真器:由 id 找到的 pagized finds 以 Where-query 子集,由 id 找到被种子的市场集和可管理编辑的文件.

## 安装

```sh
npm install @crvouga/mockingbird-service-payload-cms
```

也可以使用：`pnpm add @crvouga/mockingbird-service-payload-cms`、`yarn add @crvouga/mockingbird-service-payload-cms`、`bun add @crvouga/mockingbird-service-payload-cms`

## README

# @crvouga/ mockingbird-service-pailload-cms (英语)

> 本地模拟器。 真正的API合同. 部分 [嘲笑鸟](https://github.com/crvouga/mockingbird)。 。 。 .

状态模拟器 **有效载荷CMS**测试套件的收藏 REST API : `GET /api/<collection>` 与有效载荷的相接信封(`docs`, (中文(简体) ), `totalDocs`, (中文(简体) ), `limit`, (中文(简体) ), `totalPages`, (中文(简体) ), `page`, (中文(简体) ), `pagingCounter`, (中文(简体) ), `hasPrevPage`, (中文(简体) ), `hasNextPage`, (中文(简体) ), `prevPage`, (中文(简体) ), `nextPage`)和a 数据 `where` 查询 子集,以及 `GET /api/<collection>/<id>`编辑 `marketing` 收藏的种子为活动 转介卡,所以后端的转介内容来自"CMS"定型,以及 管理飞机允许测试改变它.

-   行动范围: [支助](https://github.com/crvouga/mockingbird/blob/main/packages/service/payload-cms/SUPPORT.md)
-   合同`openapi.yaml`)是用手写的,取自Aveload's REST和查询docs和 消费者的反应类型`payload-cms-response.type.ts`) (中文(简体) ).

## 安装

```bash
npm install -D @crvouga/mockingbird-service-payload-cms
```

仅限无害环境管理。 节点 22或 Bun 1.2. 无土生属地. 给它服务 `npx mockingbird-payload-cms serve`, (中文(简体) ), `createServer` 从 `./server` (节点),或 `createRuntime` 与任何获取服务器.

## 使用量

点 `PAYLOAD_CMS_API_URL` 在模拟者那里。 后端验证为 **仅限 https** (单位:千美元)`validation.schema.ts`),所以要么放松回放,要么将模拟器放入TLS后. 任何出错(非-2xx、空文件、坏JSON、断开连接)都会导致 后端返回到默认的推荐内容,这是预设练习.

```bash
npx mockingbird-payload-cms serve --port 8822
# or seed your own collections: --collections ./cms-seed.json   ({"marketing": [ … ]})
```

在一次测试中,应用程序的“有效载荷SDK”(`@payloadcms/sdk`)将模拟器当作其 `fetch`数字 :

```ts
import { PayloadSDK } from "@payloadcms/sdk"
import { createRuntime } from "@crvouga/mockingbird-service-payload-cms"

// Test setup: an in-process CMS, with one more marketing document added through the admin plane.
const emulator = createRuntime()
await emulator.fetch(
  new Request("http://cms.test/__admin/collections/marketing/docs", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ name: "Fall", type: "referral", isActive: true, cardTitle: "Fall Rewards" }),
  }),
)

// Application code: Payload's SDK. Only its fetch changes, so requests reach the emulator in
// this process instead of the CMS.
const cms = new PayloadSDK({
  baseURL: "http://cms.test/api",
  fetch: ((url: string, init: RequestInit) =>
    emulator.fetch(new Request(url, init))) as typeof fetch,
})
const page = await cms.find({
  collection: "marketing",
  where: { type: { equals: "referral" }, isActive: { equals: true } },
  limit: 1,
})
// → {docs: [{id: 4, cardTitle: "Fall Rewards", …}], totalDocs: 2, limit: 1, …}
```

### 路线

| 路线 | 行为 |
| --- | --- |
| `GET /api/<collection>` | `where[<field>][<op>]=<value>` 与 `equals`, (中文(简体) ), `not_equals`, (中文(简体) ), `in` 编号 : `not_in` (清单), `exists`, (中文(简体) ), `greater_than(_equal)`, (中文(简体) ), `less_than(_equal)`, (中文(简体) ), `like` (所有单词,对大小写不敏感), `contains`; 有巢状 `where[and|or][<i>][…]`; 点字段路径。 向文档字段类型投放值( Q)`"true"` → `true`) (中文(简体) ). `sort=<field>` 编号 : `-<field>` (默认) `-createdAt`, (中文(简体) ), `limit` (违约10; `0` = 无限额, `page`一个未知的字段是 400 `{errors: [{message: "The following path cannot be queried: <field>"}]}`; 一个未知的集合 404. `depth`, (中文(简体) ), `locale`, (中文(简体) ), `draft` 被接受和忽略. |
| `GET /api/<collection>/<id>` | 文件,或404 `{errors: [{message: "The requested resource was not found."}]}`。 。 。 . |

仅 `marketing` 在合同中宣布(这是我们的后端所宣读的);任何收藏 通过管理员飞机播种的同样方式服务。 ID 是整数( Payload 的 Postgres) 适配器),匹配消费者的 `id: number`。 。 。 .

**种子** (单位:千美元)`DEFAULT_MARKETING_DOCS`: `1` 无效转诊卡, `2` 正在转介 纸牌, `3` 一个活跃的旗帜.

### 管理员(超过标准合同)

| 路线 | 效果 |
| --- | --- |
| `GET /__admin/collections` | `{collections: {<slug>: <doc count>}}`。 。 。 . |
| `GET /__admin/collections/:slug` | 所收所收之文件. |
| `PUT /__admin/collections/:slug` | `{docs: [...]}` 替换收藏(如果新创建它). |
| `POST /__admin/collections/:slug/docs` | 添加文档(下个整数 ID, 仿真器时钟中的时间戳). |
| `PATCH /__admin/collections/:slug/docs/:id` | 合并字段为文档. |
| `DELETE /__admin/collections/:slug/docs/:id` | 删除文档. |

错误预设( E)`POST /__admin/faults {"preset": "<name>", "count"?: n}`: `server_error` (500个), `forbidden` (403个), `collection_not_found` (404个), `no_active_docs` (一页为空), `malformed_json` (200 HTML), (英语), `unavailable` (503 HTML), (中文(简体) ), `connection_drop`, (中文(简体) ), `slow` (10 s) (中文(简体) ).

### 命名空间

我们的后端 `fetch` 没有证书,所以使用 `/__admin/ns/<name>` 打开后缀 `PAYLOAD_CMS_API_URL` (例如:. `http://127.0.0.1:8822/__admin/ns/worker-1`)或(或) `x-mockingbird-namespace`。 。 。 . 载有 `Authorization: <collection> API-Key <key>` 也可以是无记名标志 映射为 `PUT /__admin/credentials`。 。 。 .

### 故意不模拟

-   通过 REST API (创建/ 更新/ 删除) 、 认证端点、 访问控制、 草稿, 版本、地方、关系人口`depth`,上传和图表QL.
-   `where` 以上子集以外的运算符( e)`near`, (中文(简体) ), `within`, (中文(简体) ), `intersects`, (中文(简体) ), `all`) (中文(简体) ).

## API 密码

| 导出 | 仁爱 | 说明 |
| --- | --- | --- |
| `PayloadCmsAPI` | 类 | 进程模拟器 : `fetch(request)`, (中文(简体) ), `reset()`, (中文(简体) ), `addDoc(slug, fields)`, (中文(简体) ), `updateDoc(slug, id, patch)`, (中文(简体) ), `deleteDoc(slug, id)`, (中文(简体) ), `collections()`选项: `sqlite`, (中文(简体) ), `now`, (中文(简体) ), `namespace`, (中文(简体) ), `collections`。 。 。 . |
| `createRuntime` | 函数 | 全面服务合同的仿真器(保健、管理、命名空间、预设)。 选项 : `collections`, (中文(简体) ), `clock`, (中文(简体) ), `seed`, (中文(简体) ), `adminKey`, (中文(简体) ), `onLog`, (中文(简体) ), `sqlite`。 。 。 . |
| `PAYLOAD_CMS_PRESETS` | 对象 | 每个命名的断层预设. |
| `PAYLOAD_CMS_NAMESPACE` | 字符串 | 服务名称, `"payload-cms"`。 。 。 . |
| `DEFAULT_MARKETING_DOCS` | 数组 | 营销收藏种子. |
| `MARKETING_FIELDS` | 数组 | 市场集成的可查询地. |
| `compileWhere` | 函数 | 编译有效载荷 `where` 对象进入上游(或400个消息). |
| `payloadCredential` | 函数 | 请求携带的 API 密钥或无记名符号 . |
| `payloadError` | 函数 | 构建有效载荷错误响应 `{errors: [{message}]}`。 。 。 . |
| `document`, (中文(简体) ), `operationIds`, (中文(简体) ), `supportedOperationIds` | 数值 | OpenAPI合同及其操作代号. |
| `createServer`, (中文(简体) ), `serveTarget`, (中文(简体) ), `DEFAULT_PORT` (单位:千美元)`./server`(中文(简体) ) | 节点 | 服务过来 `node:http`; 数据 `serve` CLI目标(`--collections <file>`; 开口8822. |

部分 [嘲笑鸟](https://github.com/crvouga/mockingbird)。 。 。 .

## 常见问题

### @crvouga/mockingbird-service-payload-cms 是什么？

Bayload CMS Collection REST API 的状态仿真器:由 id 找到的 pagized finds 以 Where-query 子集,由 id 找到被种子的市场集和可管理编辑的文件\.

### 如何安装 @crvouga/mockingbird-service-payload-cms？

在项目目录运行 npm install @crvouga/mockingbird-service-payload-cms，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 mockingbird-payload-cms，可以用 npx mockingbird-payload-cms 直接运行。

### @crvouga/mockingbird-service-payload-cms 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @crvouga/mockingbird-service-payload-cms 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @crvouga/mockingbird-service-payload-cms 可以商用吗？

@crvouga/mockingbird-service-payload-cms 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @crvouga/mockingbird-service-payload-cms 的下载量有多少？

根据 npm 官方下载统计，@crvouga/mockingbird-service-payload-cms 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,093 次，日均约 103 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @crvouga/mockingbird-service-payload-cms 还在维护吗？

最新版本 3\.11\.0 发布于 2026/11/11（今天）；至今共发布 42 个版本，其中过去 12 个月发布了 42 个；首次发布于 2026/09/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

