@baukit/data-contracts-dexie

中文文档
0.18.3发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 7890

Dexie 4.x implementation of @baukit/data-contracts for web applications.

原始使用文档

@baukit/data-contracts-dexie

A product-neutral Dexie 4.x implementation of @baukit/data-contracts for web applications that need key/value data, ID-ordered records, portable schema metadata, and compound write transactions.

import { openDexieStore } from '@baukit/data-contracts-dexie';

interface CachedRecord {
  readonly id: string;
  readonly value: string;
}

const storage = await openDexieStore<CachedRecord>('product-cache');
await storage.withTransaction(async (transaction) => {
  await transaction.records.put({ id: 'record-1', value: 'local' });
  await transaction.keyValues.set('outbox:mutation-1', {
    entityId: 'record-1',
    operation: 'put',
  });
});
await storage.close();

The package owns three generic IndexedDB object stores. It does not define product tables, entity relationships, soft-delete behavior, revisions, sync protocols, or database naming policy.

Authenticated products should resolve an opaque name with @baukit/data-contracts before calling openDexieStore. The fake-IndexedDB and Chromium/WebKit suites run the shared offline E→F→E identity-transition cases in addition to the transaction contract.

Transaction model

Nested transactions explicitly join the ambient transaction when they are started through the callback's transaction-scoped context:

await storage.withTransaction((transaction) =>
  transaction.withTransaction((sameTransaction) => sameTransaction.records.put(record)),
);

Compose transactional repositories from that scoped context. A call on the root storage object is an independent transaction and is serialized behind transactions that already started. Transaction contexts must not be retained after their callback ends.

Prepare network, native, crypto, filesystem, or other external promise results before opening a write transaction. Dexie tracks its own promise zone, but an unrelated promise layer can let the browser's IndexedDB request queue drain and auto-commit early. Keep the callback limited to the complete local write set.

Do not blanket-ignore Dexie's PrematureCommitError. That error can mean the browser committed only an early subset of the intended writes. Treating it as success without proof can silently split a compound operation. Acceptance tests must observe every intended write, the matching outbox entry, and full rollback when any step fails.

Quota failures surface as StorageError with code storage_quota_exceeded. After close() resolves, operations fail with code storage_closed.

Verification

pnpm test uses fake-indexeddb and stays fast. The browser suite is a separate Chromium and WebKit gate. Install browsers into a repository-local cache and run it from the repository root:

PLAYWRIGHT_BROWSERS_PATH="$PWD/typescript/.playwright-browsers" \
  corepack pnpm --dir typescript --filter @baukit/data-contracts-dexie \
  exec playwright install --with-deps chromium webkit
PLAYWRIGHT_BROWSERS_PATH="$PWD/typescript/.playwright-browsers" \
  corepack pnpm --dir typescript --filter @baukit/data-contracts-dexie \
  run test:browser

Run corepack pnpm --dir typescript run check for the normal workspace gate. The package-local check script also includes the browser suite and therefore expects the two browser binaries to be installed. CI should add the same repository-local browser install and test:browser commands as a distinct step; the workspace's ordinary test task intentionally remains fast.

版本与发布记录

@baukit/data-contracts-dexie 共发布 67 个版本,首次发布于 2026/08/26;过去 12 个月发布了 67 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.18.3latest2026/11/07今天
0.18.22026/11/061 天前
0.18.12026/11/062 天前
0.18.02026/11/052 天前
0.17.12026/11/034 天前
0.17.02026/11/025 天前

关于 @baukit/data-contracts-dexie 的常见问题

@baukit/data-contracts-dexie 是什么?

Dexie 4.x implementation of @baukit/data-contracts for web applications.

如何安装 @baukit/data-contracts-dexie?

在项目目录运行 npm install @baukit/data-contracts-dexie,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:dexie(^4.4.6)、@baukit/data-contracts(^0.18.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@baukit/data-contracts-dexie 支持 TypeScript 吗?

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

@baukit/data-contracts-dexie 支持 ESM 还是 CommonJS?

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

@baukit/data-contracts-dexie 需要什么版本的 Node.js?

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

@baukit/data-contracts-dexie 可以商用吗?

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

@baukit/data-contracts-dexie 的下载量有多少?

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

@baukit/data-contracts-dexie 还在维护吗?

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