@bendyline/docblocks

中文文档
2.7.13发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 2760

Core data structures and filesystem abstractions for DocBlocks

原始使用文档
文档目录9 节
  1. Installation
  2. Exports
  3. Filesystem ( @bendyline/docblocks/filesystem )
  4. Document ( @bendyline/docblocks/document )
  5. Workspace ( @bendyline/docblocks/workspace )
  6. Host ( @bendyline/docblocks/host )
  7. VS Code protocol ( @bendyline/docblocks/vscode )
  8. Conventions
  9. License

@bendyline/docblocks

Core types and abstractions for DocBlocks — the single source of truth for everything that crosses a process or storage boundary (filesystem providers, workspace management, and the Electron host contract).

Installation

npm install @bendyline/docblocks

Exports

The package exposes focused subpath modules. Filesystem, document, workspace, and host APIs are also re-exported from the package root; boundary-specific wire protocols stay isolated in their own entry points.

Filesystem (@bendyline/docblocks/filesystem)

Correctness-first, byte-authoritative filesystem abstraction — the single seam for user-document storage. UI code never touches indexedDB, node:fs, or electron directly; it goes through a provider.

  • FileSystemProviderV2 — canonical branded paths, typed errors, explicit mutation modes, opaque versions, capabilities, snapshots, watches, and disposal
  • WorkspacePath / parseWorkspacePath() — the portable logical path representation ('' is workspace root)
  • FsError — stable error codes that survive IPC/structured clone boundaries
  • IndexedDBFileSystemProvider — browser-local persistent storage (site, VS Code webview fallback)
  • NativeFileSystemProvider — real folders in the browser via the File System Access API
  • ElectronFileSystemProvider — bridges to the desktop main process over the host API
  • MemoryFileSystemProvider — authoritative in-memory v2 storage for transient loose-file and DBK workspaces
  • IndexedDBContentContainer / FileSystemContentContainer — content-container layer for media alongside documents
  • createFileMediaProvider — media provider wired to a filesystem provider
import { IndexedDBFileSystemProvider, parseWorkspacePath } from '@bendyline/docblocks/filesystem';

const fs = new IndexedDBFileSystemProvider('my-workspace', 'My workspace');
const path = parseWorkspacePath('/doc.md');
await fs.v2.writeFile(path, new TextEncoder().encode('# Hello'), {
  mode: 'create',
  createParents: true,
});
const content = await fs.v2.readFile(path);

FileSystemProvider remains as a deprecated text compatibility facade during the v2 migration. New code should discover provider.v2 with getFileSystemProviderV2() and use v1 only as an explicit compatibility fallback. Every new backend must pass the shared v2 conformance suite.

Provider families also have isolated entry points so a browser or desktop surface can load only the backend it selects:

  • @bendyline/docblocks/filesystem/indexeddb
  • @bendyline/docblocks/filesystem/memory
  • @bendyline/docblocks/filesystem/native
  • @bendyline/docblocks/filesystem/electron

Use literal dynamic imports of those subpaths in multi-surface shells. The compatibility filesystem barrel still re-exports every provider, but eagerly constructing from that barrel puts mutually exclusive backends in one startup bundle.

Mutation behavior is explicit: writeFile accepts a create, replace, or upsert mode and defaults to upsert when omitted; remove distinguishes an empty-directory removal from a recursive tree removal; and move never overwrites its destination. Missing entries are returned as null only by stat and readFile. Permission, wrong-kind, conflict, quota, and I/O failures remain typed FsErrors.

Capability declarations are conservative promises, not marketing labels:

ProviderWriteMoveSnapshotConditional writeWatchDurability
Memoryprocessprocessprocessprocessyesvolatile
IndexedDBcross-contextcross-contextcross-contextstorage-atomicnobest-effort
Native File System Accessnonenonenoneprocessnobest-effort
Electron workspaceprocessprocessprocessprocessyesbest-effort

Versions are opaque equality tokens scoped to their issuing provider. A consumer must never parse them or compare tokens from different providers. When a watch reports overflow, discard incremental assumptions and reload or snapshot the relevant state.

IndexedDB workspaces migrate the legacy fs:* text/binary namespace in one transaction and then use v2 records as their sole authority. Divergent legacy or pre-release v2 data is retained as an explicit recovery candidate instead of being guessed away. If an obsolete tab recreates legacy keys, a bounded prefix probe quarantines that branch before the requested operation retries; ordinary operations do not scan or deserialize the complete workspace.

Document (@bendyline/docblocks/document)

Framework-neutral document transaction/session primitives: serialized latest-write commits, monotonic revisions, explicit transitions/retarget/delete/close, conflict state, and crash-recovery journals.

Workspace (@bendyline/docblocks/workspace)

Workspace registry — how DocBlocks tracks the document collections a user has opened.

  • WorkspaceDescriptor — the workspace record type
  • listWorkspaces / getWorkspace / saveWorkspace / removeWorkspace — registry CRUD
  • touchWorkspace — update the last-opened timestamp
  • ensureDefaultWorkspace — create a default workspace if none exist
import { listWorkspaces, ensureDefaultWorkspace } from '@bendyline/docblocks/workspace';

const workspaces = await listWorkspaces();

Host (@bendyline/docblocks/host)

The canonical contract for what the Electron desktop shell exposes to its renderer (fsV2, legacy fs, workspaces, shell, ffmpeg, updater, menu, open-file requests).

  • DocBlocksHostAPI — the contract type (implemented by desktop/main/ipc-*.ts, exposed by desktop/preload/preload.ts)
  • isElectronHost() — feature-detect the desktop shell
  • getDocBlocksHost() — get the host API (throws outside Electron)
  • maybeGetDocBlocksHost() — get the host API or null, for code that degrades gracefully in the browser
import { isElectronHost, maybeGetDocBlocksHost } from '@bendyline/docblocks/host';

const host = maybeGetDocBlocksHost();
if (host) {
  await host.shell.revealInFolder(workspaceId, path);
}

VS Code protocol (@bendyline/docblocks/vscode)

The canonical bidirectional postMessage contract for the VS Code extension host and editor webview. Both sides consume the same discriminated unions and must parse incoming unknown values with parseWebviewToExtensionMessage() or parseExtensionToWebviewMessage() before dispatch.

Conventions

Anything that crosses IPC, postMessage, HTTP, or MCP boundaries belongs in this package — surface packages must not define their own copies of wire types.

Wire types document shape; they do not grant authority. Privileged hosts must parse runtime values as unknown, apply HOST_WIRE_LIMITS, use parseExternalHttpUrl for external navigation, and accept workspace IDs or owner-scoped opaque grants instead of renderer-provided absolute paths.

License

MIT

版本与发布记录

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

版本发布日期距今
2.7.13latest2026/11/062 天前
2.7.122026/11/062 天前
2.7.112026/11/017 天前
2.7.102026/10/318 天前
2.7.92026/10/309 天前
2.7.82026/10/2811 天前

关于 @bendyline/docblocks 的常见问题

@bendyline/docblocks 是什么?

Core data structures and filesystem abstractions for DocBlocks

如何安装 @bendyline/docblocks?

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

@bendyline/docblocks 支持 TypeScript 吗?

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

@bendyline/docblocks 支持 ESM 还是 CommonJS?

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

@bendyline/docblocks 需要什么版本的 Node.js?

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

@bendyline/docblocks 可以商用吗?

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

@bendyline/docblocks 的下载量有多少?

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

@bendyline/docblocks 还在维护吗?

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