# @drupal-api-client/utils 中文文档

规范地址：https://npmcn.com/package/%40drupal-api-client/utils/

版本：0\.4\.1
npm 元数据更新时间：2026-03-26T21:05:09.167Z
中文译文更新时间：2026-11-12T20:47:58.669Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40drupal-api-client/utils
原文对照：https://npmcn.com/package/%40drupal-api-client/utils/?lang=original
项目主页：https://project.pages.drupalcode.org/api_client/
源码仓库：https://git.drupalcode.org/project/api_client

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

- 包体积（解压后）：8.1 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2024-04-15T14:29:55.108Z
- 最新版本发布：2026-03-26T21:05:09.010Z
- 近 30 天下载量：18004（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 2 个）

## 中文简介

Drupal API 客户的共享公用事业

## 安装

```sh
npm install @drupal-api-client/utils
```

也可以使用：`pnpm add @drupal-api-client/utils`、`yarn add @drupal-api-client/utils`、`bun add @drupal-api-client/utils`

## README

# 公用事业和其他工具

此套件包含可选的公用设施,可能对 Drupal API 客户端工作有用,但并不包含在基础套件中.

## 安装

```shell
npm install @drupal-api-client/utils
```

## 使用量

### 创建缓存

```typescript
import { createCache } from "@drupal-api-client/utils";

const cache = createCache();
```

基于 [纳米店](https://github.com/nanostores/nanostores) 满足 `@drupal-api-client/api-client` 缓存接口 .

### 默认序列器

延伸的序列器 [乔纳](https://www.npmjs.com/package/jsona) 并附上 JSON: API 顶级 `meta` 财务报告和审定财务报表 `links` 将结果通过 `getMeta()` 财务报告和审定财务报表 `getLinks()` 方法。 。 。 用这个 `JsonApiClient` 当您需要访问文档级别元和链接而不对资源对象进行挤压时.

```typescript
import { DefaultSerializer, createCache } from "@drupal-api-client/utils";
import { JsonApiClient } from "@drupal-api-client/json-api-client";

const client = new JsonApiClient(baseUrl, {
  serializer: new DefaultSerializer(),
  cache: createCache(),
});

// Single resource: result has the same shape as Jsona, plus getMeta() and getLinks()
const article = await client.getResource("node--article", "123");
article.getMeta(); // top-level "meta" from the response, or undefined
article.getLinks(); // top-level "links" from the response, or undefined

// Collection: the array has getMeta() and getLinks() on the result itself
const articles = await client.getCollection("node--article");
articles.getMeta(); // top-level "meta", or undefined
articles.getLinks(); // top-level "links", or undefined
```

`DefaultSerializer` 使用与Jsona相同的去序列化形状(平分属性等). 也揭露了乔娜的 `serialize` 方法,因此在更新或创建资源时可以重排数据序列。 Meta和链接被存储在结果上,具有不可假定的属性,所以它们不出现在 `Object.keys()` 或者JSON输出.

## 常见问题

### @drupal-api-client/utils 是什么？

Drupal API 客户的共享公用事业

### 如何安装 @drupal-api-client/utils？

在项目目录运行 npm install @drupal-api-client/utils，或使用 pnpm add / yarn add / bun add。

### @drupal-api-client/utils 支持 TypeScript 吗？

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

### @drupal-api-client/utils 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @drupal-api-client/utils 可以商用吗？

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

### @drupal-api-client/utils 的下载量有多少？

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

### @drupal-api-client/utils 还在维护吗？

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

