# @appium/strongbox 中文文档

规范地址：https://npmcn.com/package/%40appium/strongbox/

版本：3\.0\.0
npm 元数据更新时间：2026-11-15T13:59:36.446Z
中文译文更新时间：2026-11-15T14:01:06.952Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40appium/strongbox
原文对照：https://npmcn.com/package/%40appium/strongbox/?lang=original
项目主页：https://appium.io/
源码仓库：https://github.com/appium/appium

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

- 包体积（解压后）：66.8 kB，19 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：^22\.22\.2 \|\| ^24\.15\.0 \|\| \>=26\.0\.0
- 运行依赖：1 个
- 首次发布：2023-04-07T19:47:08.389Z
- 最新版本发布：2026-11-15T13:59:36.054Z
- 近 30 天下载量：3087655（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 11 个）

## 中文简介

Appium 扩展的持续存储

## 安装

```sh
npm install @appium/strongbox
```

也可以使用：`pnpm add @appium/strongbox`、`yarn add @appium/strongbox`、`bun add @appium/strongbox`

## README

# @ appium/ 强框

> Appium 扩展的持续存储

## 内容提要

此包意在用于 [辅料](https://appium.io/) 在 Appium 运行之间需要坚持数据的扩展 。 此类数据的例子可能是设备符号或密钥.

`@appium/strongbox` 提供简单和可扩展的API,用于管理此类数据,同时抽象出基础存储机制.

_说明:_ 本模块并非用于存储敏感数据.

## 使用量

首先,创建一个实例: `Strongbox`数字 :

```ts
import {strongbox} from '@appium/strongbox';

const box = strongbox('my-pkg');
```

这一实例对应独特的数据收集.

在此创建数据的占位符( 您需要提供您想要存储的数据类型 ):

```ts
const item = await box.createItem<string>('my unique name');
```

...或者,如果你已经掌握了数据:

```ts
const item: Buffer|string = getSomeData();

const item = await box.createItemWithContents('my unique name', data);
```

无论哪种方式,都可以读取其内容:

```ts
// if the item doesn't exist, this result will be undefined
const contents = await item.read();
```

或将新数据写入项目:

```ts
await item.write('new stuff');
```

在事先不知道姓名的情况下列出长期存在的物项:

```ts
const items = await box.listItems();
```

`listItems` 不读取每个文件的内容; 调用 `read()` 当您需要的时候。 项目顺序遵循文件系统目录行走(不是词典). 它返回一个阵列中的每个项目; 对于可以使用很多内存的大型容器, 更喜欢同位素迭代, 将目录条目流到 `opendir` 而不是先缓冲所有名称 :

```ts
for await (const item of box) {
  // ...
}
```

最后读取的内容 `Item` 将可在 `contents` 属性,但该属性的值仅为当前 `read()`数字 :

```ts
const {contents} = item;
```

## API 密码

取而代之的是实际文件,看看这个包船的种类定义.

## 自定义

1.  创建一个执行 `Item` 接口 :
    
    ```ts
    import {strongbox, Item} from '@appium/strongbox';
    import {Foo, getFoo} from 'somewhere/else';
    
    class FooItem implements Item<Foo> {
      // ...
    }
    ```
    
2.  提供此类作为 `defaultCtor` 选项到 `strongbox()`数字 :
    
    ```ts
    const box = strongbox('my-pkg', {defaultCtor: FooItem});
    ```
    
3.  像你一样 `Strongbox` 实例:
    
    ```ts
    const foo: Foo = getFoo();
    const item = await box.createItemWithValue('my unique name', Foo);
    ```
    

## 默认行为,为好奇者

箱外,一个 `Strongbox` 实例对应磁盘上的目录,每个 `Item` (返回人数 `createItem()/createItemWithContents()`)对应该目录中的文件.

该目录 `Strongbox` 实例由 [环境路径](https://www.npmjs.com/package/env-paths) 软件包,并具有特定平台.

## 许可证

版权所有 2023 OpenJS基金会. 许可的 Apache-2.0

## 常见问题

### @appium/strongbox 是什么？

Appium 扩展的持续存储

### 如何安装 @appium/strongbox？

在项目目录运行 npm install @appium/strongbox，或使用 pnpm add / yarn add / bun add。

### @appium/strongbox 支持 TypeScript 吗？

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

### @appium/strongbox 支持 ESM 还是 CommonJS？

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

### @appium/strongbox 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js ^22\.22\.2 \|\| ^24\.15\.0 \|\| \>=26\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @appium/strongbox 可以商用吗？

@appium/strongbox 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @appium/strongbox 的下载量有多少？

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

### @appium/strongbox 还在维护吗？

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

