@abapify/adt-locks

中文文档
0.4.34发布于 2026/11/03MITTypeScriptES Module构建来源已验证近 30 天下载 4692

ADT lock/unlock operations and lock store management

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Recovery after a crash
  4. Role in the monorepo
  5. Related
  6. License

@abapify/adt-locks

ADT lock/unlock operations and lock-store management. This is the single lock implementation used across the abapify/adt-cli monorepo: it wraps the SAP ADT lock/unlock REST endpoints, parses their XML responses, and persists lock handles in a pluggable store so multi-object operations can release locks reliably on failure.

npm

Install

npm i @abapify/adt-locks
# or
bun add @abapify/adt-locks

Usage

Single lock / unlock via the service, backed by a file-based lock store:

import { createLockService, FileLockStore } from '@abapify/adt-locks';

const locks = createLockService(client, { store: new FileLockStore() });

const handle = await locks.lock('/sap/bc/adt/oo/classes/zcl_test');
try {
  // ... make changes via the ADT client ...
} finally {
  await locks.unlock('/sap/bc/adt/oo/classes/zcl_test', {
    lockHandle: handle.handle,
  });
}

Batch session for N objects with best-effort rollback on failure:

import { createBatchLockSession } from '@abapify/adt-locks';

const session = createBatchLockSession(locks, {
  targets: [
    { uri: '/sap/bc/adt/oo/classes/zcl_a' },
    { uri: '/sap/bc/adt/oo/classes/zcl_b' },
  ],
});

const acquired = await session.acquireAll();
// ... do work ...
await session.releaseAll();

Recovery after a crash

SAP ADT requires the exact lockHandle returned by LOCK for UNLOCK. FileLockStore persists that handle so a later process can release it:

await locks.forceUnlock('/sap/bc/adt/oo/classes/zcl_test');

Despite its historical name, forceUnlock() is not a server-side force operation: it sends only UNLOCK with a persisted handle and never attempts a second LOCK. If the handle was never persisted (for example, a server-side CTS lock created by an interrupted object POST), SAP cannot disclose it by URI. The caller must wait for expiry or ask the SAP administrator to clear it.

Role in the monorepo

  • Single source of truth for ADT locks. @abapify/adk (save flow), @abapify/adt-export, and CLI commands all delegate to LockService rather than reimplementing lock/unlock.
  • Depends only on @abapify/adt-client for transport; it does not know about specific object types, which keeps it reusable across plugins.
  • Lock handles are bound to the client's security session; see the monorepo AGENTS.md for the 3-step CSRF / security-session protocol that must be in place before any call here will succeed.

License

MIT

版本与发布记录

@abapify/adt-locks 共发布 30 个版本,首次发布于 2026/04/21;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.34latest2026/11/033 天前
0.4.332026/11/023 天前
0.4.322026/11/023 天前
0.4.312026/11/014 天前
0.4.292026/10/306 天前
0.4.282026/10/307 天前

关于 @abapify/adt-locks 的常见问题

@abapify/adt-locks 是什么?

ADT lock/unlock operations and lock store management

如何安装 @abapify/adt-locks?

在项目目录运行 npm install @abapify/adt-locks,或使用 pnpm add / yarn add / bun add。

@abapify/adt-locks 支持 TypeScript 吗?

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

@abapify/adt-locks 支持 ESM 还是 CommonJS?

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

@abapify/adt-locks 可以商用吗?

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

@abapify/adt-locks 的下载量有多少?

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

@abapify/adt-locks 还在维护吗?

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