@cratestack/api

中文文档
0.19.3发布于 2026/11/09MITTypeScriptES Module构建来源已验证近 30 天下载 2382

Compat umbrella over the split @cratestack/{ts-types,link-,runtime-,validator-,adapter-} family for CrateStack's generated TypeScript RPC client — batching, logging, and more.

原始使用文档

@cratestack/api

Compat umbrella over the split @cratestack/* npm family for CrateStack's generated TypeScript RPC client (transport rpc schemas). If you're starting fresh, prefer depending on the individual packages below directly — smaller install, no unused peer dependencies. @cratestack/api exists so existing import { createBatchLink } from "@cratestack/api" code keeps working unchanged.

The split

PackageWhat it does
@cratestack/ts-typesShared RpcLink/wire-frame interfaces. Types only — no runtime code.
@cratestack/link-batchAutomatic batch-scheduler RpcLink.
@cratestack/link-loggerReference logging RpcLink.
@cratestack/runtime-fetchtypeof fetch transport with an optional timeout.
@cratestack/runtime-axiostypeof fetch transport backed by axios.
@cratestack/validator-zodInput-validating RpcLink, zod schemas.
@cratestack/validator-yupInput-validating RpcLink, yup schemas.
@cratestack/adapter-tanstack-queryGeneric TanStack Query option builders.
@cratestack/adapter-rtkRTK Query BaseQueryFn adapter.

Usage

The root import is unchanged from before the split — it re-exports exactly ts-types + link-batch + link-logger, so importing it never pulls in zod/yup/axios/tanstack-query/rtk as implicit peer dependencies:

import { createBatchLink, createLoggerLink } from "@cratestack/api";
import { CratestackRpcRuntime } from "./generated/runtime"; // your project's generated client

const runtime = new CratestackRpcRuntime("https://api.example.com", {
  links: [createLoggerLink(), createBatchLink()],
});
const client = new MyGeneratedClient(runtime);

// These three calls, if issued in the same tick, become ONE /rpc/batch request:
const [a, b, c] = await Promise.all([
  client.widgets.get(1),
  client.widgets.get(2),
  client.widgets.get(3),
]);

Everything else added since the split is available as a named subpath — each pulls in only its own peer dependency, not every package's:

import { createFetchRuntime } from "@cratestack/api/runtime-fetch";
import { createAxiosRuntime } from "@cratestack/api/runtime-axios";
import { createZodValidatorLink } from "@cratestack/api/validator-zod";
import { createYupValidatorLink } from "@cratestack/api/validator-yup";
import { rpcQueryOptions, rpcMutationOptions } from "@cratestack/api/adapter-tanstack-query";
import { createRpcBaseQuery } from "@cratestack/api/adapter-rtk";

See each package's own README (linked in the table above) for its full API and semantics.

Order matters: a link's next reruns everything below it (the real fetch and any links declared after it), never just the terminal fetch. stream() calls bypass the chain entirely — a link that wants to inspect/retry a response would need to clone a streamed body, which defeats streaming.

版本与发布记录

@cratestack/api 共发布 73 个版本,首次发布于 2026/07/26;过去 12 个月发布了 73 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.3latest2026/11/091 天前
0.19.22026/11/091 天前
0.19.12026/11/092 天前
0.19.02026/11/092 天前
0.18.12026/11/073 天前
0.18.02026/11/074 天前

关于 @cratestack/api 的常见问题

@cratestack/api 是什么?

Compat umbrella over the split @cratestack/{ts-types,link-,runtime-,validator-,adapter-} family for CrateStack's generated TypeScript RPC client — batching, logging, and more.

如何安装 @cratestack/api?

在项目目录运行 npm install @cratestack/api,或使用 pnpm add / yarn add / bun add。

@cratestack/api 支持 TypeScript 吗?

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

@cratestack/api 支持 ESM 还是 CommonJS?

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

@cratestack/api 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cratestack/api 可以商用吗?

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

@cratestack/api 的下载量有多少?

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

@cratestack/api 还在维护吗?

最新版本 0.19.3 发布于 2026/11/09(1 天前);至今共发布 73 个版本,其中过去 12 个月发布了 73 个;首次发布于 2026/07/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。