@draftline/client

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

Typed Draftline client for Tauri host applications.

原始使用文档

Draftline client

client/ contains the TypeScript command client used by Workbench and host apps. It wraps Tauri invoke calls and mirrors the serializable shapes from draftline::tauri_contract.

The client also exposes the stable Draftline workspace event channel used by configured Tauri hosts:

const client = createDraftlineClient();
const unlisten = await client.subscribeWorkspaceEvents((event) => {
  if (event.kind === 'history_changed' || event.kind === 'dirty_changed') {
    // Refresh product UI from inspectWorkspace.
  }
});

Remote merge flows use the same typed DTOs as draftline::tauri_contract. Call preflightMergeIncoming first; if it returns conflicts and a token with can_merge_cleanly: false, use createMergeConflictViewModel to render file/field groups and createWholeFileUseContentResolutions when the product UI offers whole-file "use ours/theirs/base" actions. Those helpers emit explicit use_content resolutions so the submitted payload matches the content the user reviewed:

await client.mergeIncomingWithResolutions({
  workspace_path: workspacePath,
  remote: 'origin',
  label: 'Resolve teammate changes',
  token: preflight.token,
  resolutions: createWholeFileUseContentResolutions(preflight, 'theirs'),
});

For host code, createDraftlineHostFacade binds a client to one workspace path and exposes product-level operations such as save, selectedSave, diffWorkspaceFile, previewWorkspaceFile, fetchRemote, mergeIncoming, mergeIncomingWithResolutions, local variation merges (preflightMergeVariation, mergeVariation, mergeVariationWithResolutions), recovery repair/rollback, and remote variation adoption without repeating request DTO plumbing in every component.

Workspace graph integration

@draftline/client exports the graph DTOs and helper return types directly, including WorkspaceGraph, WorkspaceGraphNode, WorkspaceGraphRef, WorkspaceGraphActionHint, WorkspaceGraphBoundary, WorkspaceGraphSearchResult, WorkspaceGraphPath, WorkspaceGraphNodeDetail, and WorkspaceGraphCompareSummary.

Prefer bounded graph calls for product UI:

const facade = createDraftlineHostFacade({ workspacePath });

const overview = await facade.workspaceGraphOverview({
  max_nodes: 80,
  recent_nodes: 40,
});
const refs = await facade.workspaceGraphRefs();
const focus = await facade.workspaceGraphNeighborhood(versionId, 2);

Use workspaceGraphRefs for cheap ref/badge refreshes, overview or workspaceGraphForVariation for default panels, and workspaceGraphAroundVersion, workspaceGraphNeighborhood, searchWorkspaceGraph, workspaceGraphPath, and workspaceGraphCommonAncestor for focused expansion. Reserve the full workspaceGraph call for explicit expanded history views.

Treat graph node IDs as opaque. Use the path/common-ancestor helpers for graph relationships instead of parsing IDs. Bounded results can be partial; use was_pruned, has_more, next_cursor, and each node's boundary fields to render hidden edges. Layout hints are advisory for stable rendering within a graph snapshot. Node and ref action_hints include stable action IDs, command names, workspace-switch/version-creating flags, and a disabled_reason when an action is unsafe.

Build from the repository root:

npm run client:build

版本与发布记录

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

版本发布日期距今
0.11.0latest2026/11/067 天前
0.10.02026/11/067 天前
0.9.02026/11/067 天前
0.8.02026/11/058 天前
0.7.02026/11/058 天前
0.6.02026/11/058 天前

关于 @draftline/client 的常见问题

@draftline/client 是什么?

Typed Draftline client for Tauri host applications.

如何安装 @draftline/client?

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

@draftline/client 支持 TypeScript 吗?

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

@draftline/client 支持 ESM 还是 CommonJS?

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

@draftline/client 可以商用吗?

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

@draftline/client 的下载量有多少?

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

@draftline/client 还在维护吗?

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