@crvouga/ mockingbird-service-pailload-cms (英语)
本地模拟器。 真正的API合同. 部分 嘲笑鸟。 。 。 .
状态模拟器 有效载荷CMS测试套件的收藏 REST API : GET /api/<collection>
与有效载荷的相接信封(docs, (中文(简体) ), totalDocs, (中文(简体) ), limit, (中文(简体) ), totalPages, (中文(简体) ), page, (中文(简体) ),
pagingCounter, (中文(简体) ), hasPrevPage, (中文(简体) ), hasNextPage, (中文(简体) ), prevPage, (中文(简体) ), nextPage)和a 数据 where 查询
子集,以及 GET /api/<collection>/<id>编辑 marketing 收藏的种子为活动
转介卡,所以后端的转介内容来自"CMS"定型,以及
管理飞机允许测试改变它.
- 行动范围: 支助
- 合同
openapi.yaml)是用手写的,取自Aveload's REST和查询docs和 消费者的反应类型payload-cms-response.type.ts) (中文(简体) ).
安装
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、断开连接)都会导致
后端返回到默认的推荐内容,这是预设练习.
npx mockingbird-payload-cms serve --port 8822
# or seed your own collections: --collections ./cms-seed.json ({"marketing": [ … ]})
在一次测试中,应用程序的“有效载荷SDK”(@payloadcms/sdk)将模拟器当作其 fetch数字 :
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. |
部分 嘲笑鸟。 。 。 .