@collective-intelligence/extensions-sdk-backend-zod

中文文档
0.2.1发布于 2026/11/05TypeScriptES Module近 30 天下载 5019

Optional Zod 4 schema adapter for Collective Intelligence extension packages.

此软件包已被标记为弃用

Use @collective-intelligence/extensions-sdk-backend with its /effect export.

原始使用文档

@collective-intelligence/extensions-sdk-backend-zod

Optional Zod 4 authoring adapter for @collective-intelligence/extensions-sdk. The core SDK remains provider-neutral; this package owns Zod and exposes one public adapter.

zod (>=4.4.2 <5) is a peer dependency. Install it next to the adapter so the adapter and your schemas share one Zod instance:

bun add @collective-intelligence/extensions-sdk \
  @collective-intelligence/extensions-sdk-backend-zod zod
import type { PackageCodec } from "@collective-intelligence/extensions-sdk"
import { zodSchema } from "@collective-intelligence/extensions-sdk-backend-zod"
import { z } from "zod"

const identifier = zodSchema(
  z.codec(z.string().regex(/^item:[0-9]+$/), z.number().int(), {
    decode: (wire) => Number(wire.slice(5)),
    encode: (value) => `item:${value}`
  })
)

const outputSchema: PackageCodec<string, number> = identifier

zodSchema(...) infers Zod input as the wire type and Zod output as the implementation value. Validation uses safeParseAsync; encoding uses safeEncodeAsync, so asynchronous refinements and codecs retain their native behavior.

The adapter also creates deterministic input and output JSON Schema Draft 2020-12 projections for interchange consumers only. Runtime validation and encoding always call Zod directly. Both directions describe Zod's input wire type: input validation consumes that wire type, and output encoding produces it. The Zod output type remains the in-process domain value and is validated by native reverse encoding rather than advertised as transported JSON. Codecs, transforms, preprocessors, success schemas, coercion, catches, overwrites, and custom refinements are conservatively reported as structural fidelity because their native callbacks or semantics can be stricter than the portable schema. Unsupported JSON Schema constructs fail when the adapter is created instead of being silently widened.

One-way transforms

Zod transforms and preprocessors do not provide reverse encoding. Their adapter result is therefore decoder-only and has no output projection:

const parsedNumber = zodSchema(z.string().transform(Number))

await parsedNumber.validate("42") // { value: 42 }
// parsedNumber does not satisfy PackageCodec<string, number>

This is recursive for nested objects, arrays, unions, tuples, records, exact optionals, promises, and other wrappers. z.success(...) is also decoder-only. Use an explicit z.codec(inputSchema, outputSchema, { decode, encode }) when the schema must be accepted in an output position. Lazy schemas are treated as decoder-only conservatively because their recursive type cannot prove encoder capability statically.

The provider string (zod/4) is diagnostic metadata only. Hosts dispatch on the structural validate and encode capabilities; project(...) is only for portable consumers. There is no registry or provider switch.

Packed boundary

Run bun run test:pack to verify the published boundary. It builds and packs this package and @collective-intelligence/extensions-sdk, installs the packed artifacts and the peer zod into a temporary copy of test/consumer, then type-checks and runs that consumer. The build requires the base SDK declarations, so build @collective-intelligence/extensions-sdk first.

版本与发布记录

@collective-intelligence/extensions-sdk-backend-zod 共发布 35 个版本,首次发布于 2026/10/08;过去 12 个月发布了 35 个版本。

版本发布日期距今
0.2.1latest2026/11/055 天前
0.2.02026/11/055 天前
0.1.322026/11/046 天前
0.1.312026/11/037 天前
0.1.302026/11/028 天前
0.1.292026/10/319 天前

关于 @collective-intelligence/extensions-sdk-backend-zod 的常见问题

@collective-intelligence/extensions-sdk-backend-zod 是什么?

Optional Zod 4 schema adapter for Collective Intelligence extension packages.注意:该包已被作者标记为弃用——Use @collective-intelligence/extensions-sdk-backend with its /effect export.

如何安装 @collective-intelligence/extensions-sdk-backend-zod?

在项目目录运行 npm install @collective-intelligence/extensions-sdk-backend-zod,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(>=4.4.2 <5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@collective-intelligence/extensions-sdk-backend-zod 支持 TypeScript 吗?

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

@collective-intelligence/extensions-sdk-backend-zod 支持 ESM 还是 CommonJS?

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

@collective-intelligence/extensions-sdk-backend-zod 可以商用吗?

@collective-intelligence/extensions-sdk-backend-zod 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@collective-intelligence/extensions-sdk-backend-zod 的下载量有多少?

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

@collective-intelligence/extensions-sdk-backend-zod 还在维护吗?

最新版本 0.2.1 发布于 2026/11/05(5 天前);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/10/08。作者已将其标记为弃用,新项目建议寻找替代方案。