@gathertown/webhook-对象类型
为 Gather webhook-object( Smart Object) 事件生成类型脚本: 每条线
type (例如:. counter.increment) 及其定义 data 有效载荷外形,外加预设能力
分组。 只类型,零运行时代码,零依赖.
使用量
npm install --save-dev @gathertown/webhook-object-types
import type {
DataFor,
EventTypeForPreset,
WebhookEventEnvelope,
WebhookEventType,
WebhookWireErrorCode,
} from "@gathertown/webhook-object-types"
// The HTTP request body for any event, fully typed per event type:
const event: WebhookEventEnvelope<"counter.increment"> = {
type: "counter.increment",
timestamp: new Date().toISOString(),
data: { by: 1 }, // DataFor<"counter.increment">
}
// What a given preset accepts:
type InboxEvent = EventTypeForPreset<"inbox"> // "activity.add" | "counter.set" | …
// Error codes the receiver returns in `{ "error": "<code>" }` bodies:
const code: WebhookWireErrorCode = "token_revoked"
大多数整形师想要
@gathertown/webhook-object-sdk
相反,它将这些类型包裹在一个签名的重试客户端中.
schemas/: 语文中立合同
schemas/*.json 每场赛事拥有1个JSON Schema(草案07) data 由电线命名的有效载荷
类型(counter.increment.json) (中文(简体) ). 类型脚本在 src/ 由这些相同的
通过快取型的策略, 和其他语言上的集成器可以做同样的事情:
npx quicktype -s schema schemas/*.json --lang go --just-types
npx quicktype -s schema schemas/*.json --lang python
(明确输入文件,以快速指向 目录 令其视之为 JSON样本并生成图案文件本身的类型. )
计划还和任何JSON Schema 校验器(jav等)合作进行运行时间校验 动态制造的有效载荷,可直接导入:
import counterIncrement from "@gathertown/webhook-object-types/schemas/counter.increment.json"
这里的一切都是由同一计划产生的 验证事件服务器侧,所以 这些类型永远不会从执行中消失.