@bendyline/docblocks 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +76 -11
  2. package/dist/chunk-2D7Y4IR3.js +1293 -0
  3. package/dist/chunk-2D7Y4IR3.js.map +1 -0
  4. package/dist/chunk-5MYAICRE.js +957 -0
  5. package/dist/chunk-5MYAICRE.js.map +1 -0
  6. package/dist/chunk-75UUF6C4.js +802 -0
  7. package/dist/chunk-75UUF6C4.js.map +1 -0
  8. package/dist/chunk-AEHCVWU5.js +25 -0
  9. package/dist/chunk-AEHCVWU5.js.map +1 -0
  10. package/dist/chunk-AYZ4HN5M.js +20 -0
  11. package/dist/chunk-AYZ4HN5M.js.map +1 -0
  12. package/dist/chunk-EGNDADXB.js +111 -0
  13. package/dist/chunk-EGNDADXB.js.map +1 -0
  14. package/dist/chunk-EZKJZUNJ.js +13 -0
  15. package/dist/chunk-EZKJZUNJ.js.map +1 -0
  16. package/dist/chunk-FNW556FN.js +75 -0
  17. package/dist/chunk-FNW556FN.js.map +1 -0
  18. package/dist/chunk-GCPBEMMH.js +563 -0
  19. package/dist/chunk-GCPBEMMH.js.map +1 -0
  20. package/dist/chunk-J32GU3F3.js +1664 -0
  21. package/dist/chunk-J32GU3F3.js.map +1 -0
  22. package/dist/chunk-PGR7LK6D.js +1062 -0
  23. package/dist/chunk-PGR7LK6D.js.map +1 -0
  24. package/dist/chunk-RQJRQF46.js +787 -0
  25. package/dist/chunk-RQJRQF46.js.map +1 -0
  26. package/dist/{chunk-ME76RUMR.js → chunk-RVQHY3XU.js} +15 -1
  27. package/dist/chunk-RVQHY3XU.js.map +1 -0
  28. package/dist/chunk-SI2LU2RP.js +224 -0
  29. package/dist/chunk-SI2LU2RP.js.map +1 -0
  30. package/dist/chunk-W5UUUII5.js +142 -0
  31. package/dist/chunk-W5UUUII5.js.map +1 -0
  32. package/dist/document/document-session.d.ts +127 -0
  33. package/dist/document/document-session.d.ts.map +1 -0
  34. package/dist/document/document-session.js +749 -0
  35. package/dist/document/document-session.js.map +1 -0
  36. package/dist/document/filesystem-target.d.ts +17 -0
  37. package/dist/document/filesystem-target.d.ts.map +1 -0
  38. package/dist/document/filesystem-target.js +70 -0
  39. package/dist/document/filesystem-target.js.map +1 -0
  40. package/dist/document/index.d.ts +6 -0
  41. package/dist/document/index.d.ts.map +1 -0
  42. package/dist/document/index.js +4 -0
  43. package/dist/document/index.js.map +1 -0
  44. package/dist/document/recovery-journal.d.ts +125 -0
  45. package/dist/document/recovery-journal.d.ts.map +1 -0
  46. package/dist/document/recovery-journal.js +385 -0
  47. package/dist/document/recovery-journal.js.map +1 -0
  48. package/dist/document/types.d.ts +89 -0
  49. package/dist/document/types.d.ts.map +1 -0
  50. package/dist/document/types.js +9 -0
  51. package/dist/document/types.js.map +1 -0
  52. package/dist/filesystem/commit-lock.d.ts +3 -0
  53. package/dist/filesystem/commit-lock.d.ts.map +1 -0
  54. package/dist/filesystem/commit-lock.js +20 -0
  55. package/dist/filesystem/commit-lock.js.map +1 -0
  56. package/dist/filesystem/dbk-workspace.d.ts +34 -0
  57. package/dist/filesystem/dbk-workspace.d.ts.map +1 -0
  58. package/dist/filesystem/dbk-workspace.js +85 -0
  59. package/dist/filesystem/dbk-workspace.js.map +1 -0
  60. package/dist/filesystem/electron-provider-v2.d.ts +36 -0
  61. package/dist/filesystem/electron-provider-v2.d.ts.map +1 -0
  62. package/dist/filesystem/electron-provider-v2.js +503 -0
  63. package/dist/filesystem/electron-provider-v2.js.map +1 -0
  64. package/dist/filesystem/electron-provider.d.ts +6 -3
  65. package/dist/filesystem/electron-provider.d.ts.map +1 -1
  66. package/dist/filesystem/electron-provider.js +18 -13
  67. package/dist/filesystem/electron-provider.js.map +1 -1
  68. package/dist/filesystem/electron.d.ts +4 -0
  69. package/dist/filesystem/electron.d.ts.map +1 -0
  70. package/dist/filesystem/electron.js +4 -0
  71. package/dist/filesystem/electron.js.map +1 -0
  72. package/dist/filesystem/filesystem-content-container.d.ts +1 -1
  73. package/dist/filesystem/filesystem-content-container.d.ts.map +1 -1
  74. package/dist/filesystem/filesystem-content-container.js +50 -13
  75. package/dist/filesystem/filesystem-content-container.js.map +1 -1
  76. package/dist/filesystem/fs-error.d.ts +46 -0
  77. package/dist/filesystem/fs-error.d.ts.map +1 -0
  78. package/dist/filesystem/fs-error.js +170 -0
  79. package/dist/filesystem/fs-error.js.map +1 -0
  80. package/dist/filesystem/index.d.ts +15 -1
  81. package/dist/filesystem/index.d.ts.map +1 -1
  82. package/dist/filesystem/index.js +13 -0
  83. package/dist/filesystem/index.js.map +1 -1
  84. package/dist/filesystem/indexeddb-content-container.d.ts +3 -1
  85. package/dist/filesystem/indexeddb-content-container.d.ts.map +1 -1
  86. package/dist/filesystem/indexeddb-content-container.js +18 -11
  87. package/dist/filesystem/indexeddb-content-container.js.map +1 -1
  88. package/dist/filesystem/indexeddb-provider-v2.d.ts +96 -0
  89. package/dist/filesystem/indexeddb-provider-v2.d.ts.map +1 -0
  90. package/dist/filesystem/indexeddb-provider-v2.js +1241 -0
  91. package/dist/filesystem/indexeddb-provider-v2.js.map +1 -0
  92. package/dist/filesystem/indexeddb-provider.d.ts +21 -14
  93. package/dist/filesystem/indexeddb-provider.d.ts.map +1 -1
  94. package/dist/filesystem/indexeddb-provider.js +111 -261
  95. package/dist/filesystem/indexeddb-provider.js.map +1 -1
  96. package/dist/filesystem/indexeddb-store.d.ts +34 -0
  97. package/dist/filesystem/indexeddb-store.d.ts.map +1 -0
  98. package/dist/filesystem/indexeddb-store.js +165 -0
  99. package/dist/filesystem/indexeddb-store.js.map +1 -0
  100. package/dist/filesystem/indexeddb.d.ts +5 -0
  101. package/dist/filesystem/indexeddb.d.ts.map +1 -0
  102. package/dist/filesystem/indexeddb.js +5 -0
  103. package/dist/filesystem/indexeddb.js.map +1 -0
  104. package/dist/filesystem/legacy-v2-adapter.d.ts +62 -0
  105. package/dist/filesystem/legacy-v2-adapter.d.ts.map +1 -0
  106. package/dist/filesystem/legacy-v2-adapter.js +499 -0
  107. package/dist/filesystem/legacy-v2-adapter.js.map +1 -0
  108. package/dist/filesystem/memory-provider-v2.d.ts +92 -0
  109. package/dist/filesystem/memory-provider-v2.d.ts.map +1 -0
  110. package/dist/filesystem/memory-provider-v2.js +615 -0
  111. package/dist/filesystem/memory-provider-v2.js.map +1 -0
  112. package/dist/filesystem/memory-provider.d.ts +54 -0
  113. package/dist/filesystem/memory-provider.d.ts.map +1 -0
  114. package/dist/filesystem/memory-provider.js +132 -0
  115. package/dist/filesystem/memory-provider.js.map +1 -0
  116. package/dist/filesystem/memory.d.ts +4 -0
  117. package/dist/filesystem/memory.d.ts.map +1 -0
  118. package/dist/filesystem/memory.js +4 -0
  119. package/dist/filesystem/memory.js.map +1 -0
  120. package/dist/filesystem/move-entry.d.ts +9 -0
  121. package/dist/filesystem/move-entry.d.ts.map +1 -0
  122. package/dist/filesystem/move-entry.js +103 -0
  123. package/dist/filesystem/move-entry.js.map +1 -0
  124. package/dist/filesystem/move-error.d.ts +53 -0
  125. package/dist/filesystem/move-error.d.ts.map +1 -0
  126. package/dist/filesystem/move-error.js +99 -0
  127. package/dist/filesystem/move-error.js.map +1 -0
  128. package/dist/filesystem/native-provider-v2.d.ts +75 -0
  129. package/dist/filesystem/native-provider-v2.d.ts.map +1 -0
  130. package/dist/filesystem/native-provider-v2.js +849 -0
  131. package/dist/filesystem/native-provider-v2.js.map +1 -0
  132. package/dist/filesystem/native-provider.d.ts +9 -1
  133. package/dist/filesystem/native-provider.d.ts.map +1 -1
  134. package/dist/filesystem/native-provider.js +172 -37
  135. package/dist/filesystem/native-provider.js.map +1 -1
  136. package/dist/filesystem/native.d.ts +4 -0
  137. package/dist/filesystem/native.d.ts.map +1 -0
  138. package/dist/filesystem/native.js +4 -0
  139. package/dist/filesystem/native.js.map +1 -0
  140. package/dist/filesystem/types.d.ts +37 -4
  141. package/dist/filesystem/types.d.ts.map +1 -1
  142. package/dist/filesystem/types.js +11 -3
  143. package/dist/filesystem/types.js.map +1 -1
  144. package/dist/filesystem/v2.d.ts +172 -0
  145. package/dist/filesystem/v2.d.ts.map +1 -0
  146. package/dist/filesystem/v2.js +16 -0
  147. package/dist/filesystem/v2.js.map +1 -0
  148. package/dist/filesystem/workspace-path.d.ts +21 -0
  149. package/dist/filesystem/workspace-path.d.ts.map +1 -0
  150. package/dist/filesystem/workspace-path.js +80 -0
  151. package/dist/filesystem/workspace-path.js.map +1 -0
  152. package/dist/host/filesystem-v2.d.ts +45 -0
  153. package/dist/host/filesystem-v2.d.ts.map +1 -0
  154. package/dist/host/filesystem-v2.js +13 -0
  155. package/dist/host/filesystem-v2.js.map +1 -0
  156. package/dist/host/git.d.ts +200 -0
  157. package/dist/host/git.d.ts.map +1 -0
  158. package/dist/host/git.js +15 -0
  159. package/dist/host/git.js.map +1 -0
  160. package/dist/host/index.d.ts +4 -1
  161. package/dist/host/index.d.ts.map +1 -1
  162. package/dist/host/index.js +2 -0
  163. package/dist/host/index.js.map +1 -1
  164. package/dist/host/types.d.ts +114 -31
  165. package/dist/host/types.d.ts.map +1 -1
  166. package/dist/host/wire-policy.d.ts +22 -0
  167. package/dist/host/wire-policy.d.ts.map +1 -0
  168. package/dist/host/wire-policy.js +92 -0
  169. package/dist/host/wire-policy.js.map +1 -0
  170. package/dist/index.d.ts +2 -1
  171. package/dist/index.d.ts.map +1 -1
  172. package/dist/index.js +2 -1
  173. package/dist/index.js.map +1 -1
  174. package/dist/mcp/index.d.ts +4 -0
  175. package/dist/mcp/index.d.ts.map +1 -0
  176. package/dist/mcp/index.js +4 -0
  177. package/dist/mcp/index.js.map +1 -0
  178. package/dist/mcp/types.d.ts +466 -0
  179. package/dist/mcp/types.d.ts.map +1 -0
  180. package/dist/mcp/types.js +25 -0
  181. package/dist/mcp/types.js.map +1 -0
  182. package/dist/mcp/wire.d.ts +29 -0
  183. package/dist/mcp/wire.d.ts.map +1 -0
  184. package/dist/mcp/wire.js +1046 -0
  185. package/dist/mcp/wire.js.map +1 -0
  186. package/dist/mcp/zod.d.ts +5763 -0
  187. package/dist/mcp/zod.d.ts.map +1 -0
  188. package/dist/mcp/zod.js +908 -0
  189. package/dist/mcp/zod.js.map +1 -0
  190. package/dist/types-CX893hgH.d.ts +468 -0
  191. package/dist/types-CsX6EN2t.d.ts +301 -0
  192. package/dist/types-eOlt9J7n.d.ts +478 -0
  193. package/dist/vscode/index.d.ts +3 -0
  194. package/dist/vscode/index.d.ts.map +1 -0
  195. package/dist/vscode/index.js +3 -0
  196. package/dist/vscode/index.js.map +1 -0
  197. package/dist/vscode/messages.d.ts +204 -0
  198. package/dist/vscode/messages.d.ts.map +1 -0
  199. package/dist/vscode/messages.js +494 -0
  200. package/dist/vscode/messages.js.map +1 -0
  201. package/dist/workspace/index.d.ts +3 -2
  202. package/dist/workspace/index.d.ts.map +1 -1
  203. package/dist/workspace/index.js +2 -1
  204. package/dist/workspace/index.js.map +1 -1
  205. package/dist/workspace/reconcile-electron.d.ts +19 -0
  206. package/dist/workspace/reconcile-electron.d.ts.map +1 -0
  207. package/dist/workspace/reconcile-electron.js +42 -0
  208. package/dist/workspace/reconcile-electron.js.map +1 -0
  209. package/dist/workspace/types.d.ts +41 -1
  210. package/dist/workspace/types.d.ts.map +1 -1
  211. package/dist/workspace/types.js +0 -4
  212. package/dist/workspace/types.js.map +1 -1
  213. package/dist/workspace/workspace-manager.d.ts +17 -5
  214. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  215. package/dist/workspace/workspace-manager.js +55 -11
  216. package/dist/workspace/workspace-manager.js.map +1 -1
  217. package/dist/workspace-path-CWVrcuPL.d.ts +21 -0
  218. package/package.json +43 -2
  219. package/src/document/document-session.ts +834 -0
  220. package/src/document/filesystem-target.ts +109 -0
  221. package/src/document/index.ts +41 -0
  222. package/src/document/recovery-journal.ts +536 -0
  223. package/src/document/types.ts +116 -0
  224. package/src/filesystem/commit-lock.ts +29 -0
  225. package/src/filesystem/dbk-workspace.ts +135 -0
  226. package/src/filesystem/electron-provider-v2.ts +630 -0
  227. package/src/filesystem/electron-provider.ts +25 -14
  228. package/src/filesystem/electron.ts +3 -0
  229. package/src/filesystem/filesystem-content-container.ts +53 -15
  230. package/src/filesystem/fs-error.ts +234 -0
  231. package/src/filesystem/index.ts +119 -0
  232. package/src/filesystem/indexeddb-content-container.ts +20 -12
  233. package/src/filesystem/indexeddb-provider-v2.ts +1740 -0
  234. package/src/filesystem/indexeddb-provider.ts +126 -300
  235. package/src/filesystem/indexeddb-store.ts +207 -0
  236. package/src/filesystem/indexeddb.ts +12 -0
  237. package/src/filesystem/legacy-v2-adapter.ts +779 -0
  238. package/src/filesystem/memory-provider-v2.ts +896 -0
  239. package/src/filesystem/memory-provider.ts +180 -0
  240. package/src/filesystem/memory.ts +15 -0
  241. package/src/filesystem/move-entry.ts +142 -0
  242. package/src/filesystem/move-error.ts +159 -0
  243. package/src/filesystem/native-provider-v2.ts +1165 -0
  244. package/src/filesystem/native-provider.ts +194 -41
  245. package/src/filesystem/native.ts +16 -0
  246. package/src/filesystem/types.ts +49 -4
  247. package/src/filesystem/v2.ts +231 -0
  248. package/src/filesystem/workspace-path.ts +92 -0
  249. package/src/host/filesystem-v2.ts +104 -0
  250. package/src/host/git.ts +246 -0
  251. package/src/host/index.ts +46 -0
  252. package/src/host/types.ts +155 -34
  253. package/src/host/wire-policy.ts +103 -0
  254. package/src/index.ts +2 -1
  255. package/src/mcp/index.ts +3 -0
  256. package/src/mcp/types.ts +594 -0
  257. package/src/mcp/wire.ts +1280 -0
  258. package/src/mcp/zod.ts +1000 -0
  259. package/src/vscode/index.ts +2 -0
  260. package/src/vscode/messages.ts +704 -0
  261. package/src/workspace/index.ts +8 -1
  262. package/src/workspace/reconcile-electron.ts +65 -0
  263. package/src/workspace/types.ts +39 -1
  264. package/src/workspace/workspace-manager.ts +71 -10
  265. package/dist/chunk-GUNM43XZ.js +0 -63
  266. package/dist/chunk-GUNM43XZ.js.map +0 -1
  267. package/dist/chunk-IM7LCQJ6.js +0 -850
  268. package/dist/chunk-IM7LCQJ6.js.map +0 -1
  269. package/dist/chunk-ME76RUMR.js.map +0 -1
  270. package/dist/index-pgBHBQ9G.d.ts +0 -213
@@ -0,0 +1,85 @@
1
+ import { documentCompanionPath } from './move-entry.js';
2
+ function normaliseRelativePath(path, label) {
3
+ if (path.includes('\\') || path.includes('\0')) {
4
+ throw new Error(`DBK ${label} must use a safe forward-slash path: ${path}`);
5
+ }
6
+ const normalized = path.replace(/^\/+|\/+$/g, '').replace(/\/+/g, '/');
7
+ const segments = normalized ? normalized.split('/') : [];
8
+ if (segments.length === 0 || segments.some((segment) => segment === '.' || segment === '..')) {
9
+ throw new Error(`DBK ${label} must not be empty or traverse directories: ${path}`);
10
+ }
11
+ return segments.join('/');
12
+ }
13
+ function joinPath(parent, child) {
14
+ return `${parent.replace(/\/+$/g, '')}/${child.replace(/^\/+/, '')}`;
15
+ }
16
+ /**
17
+ * Fully materialize and validate a DBK container before touching its target
18
+ * provider. A missing or unreadable entry fails the snapshot as a whole.
19
+ */
20
+ export async function createDbkWorkspaceSnapshot(source, options) {
21
+ const targetDocumentPath = normaliseRelativePath(options.targetDocumentPath, 'target document path');
22
+ const discoveredDocumentPath = await source.getDocumentPath();
23
+ if (!discoveredDocumentPath)
24
+ throw new Error('The external DBK has no primary markdown document.');
25
+ const sourceDocumentPath = normaliseRelativePath(discoveredDocumentPath, 'primary document path');
26
+ const requestedLayout = options.assetLayout ?? 'auto';
27
+ const assetLayout = requestedLayout === 'auto'
28
+ ? sourceDocumentPath === targetDocumentPath
29
+ ? 'preserve'
30
+ : 'companion'
31
+ : requestedLayout;
32
+ const companionPath = normaliseRelativePath(documentCompanionPath(targetDocumentPath), 'companion directory path');
33
+ const listed = await source.listFiles();
34
+ const entries = [...listed].sort((a, b) => a.path.localeCompare(b.path));
35
+ const seenSourcePaths = new Set();
36
+ const files = [];
37
+ let documentContent = null;
38
+ for (const entry of entries) {
39
+ const sourcePath = normaliseRelativePath(entry.path, 'entry path');
40
+ if (seenSourcePaths.has(sourcePath)) {
41
+ throw new Error(`The external DBK contains duplicate paths: ${sourcePath}`);
42
+ }
43
+ seenSourcePaths.add(sourcePath);
44
+ const data = await source.readFile(entry.path);
45
+ if (data === null) {
46
+ throw new Error(`The external DBK changed while reading: ${sourcePath}`);
47
+ }
48
+ if (sourcePath === sourceDocumentPath) {
49
+ documentContent = new TextDecoder().decode(data);
50
+ files.push({ kind: 'text', path: targetDocumentPath, content: documentContent });
51
+ continue;
52
+ }
53
+ const targetPath = assetLayout === 'preserve' ? sourcePath : joinPath(companionPath, sourcePath);
54
+ if (/\.(?:md|mdx|txt)$/i.test(sourcePath)) {
55
+ files.push({ kind: 'text', path: targetPath, content: new TextDecoder().decode(data) });
56
+ }
57
+ else {
58
+ files.push({ kind: 'binary', path: targetPath, data });
59
+ }
60
+ }
61
+ if (documentContent === null) {
62
+ throw new Error(`The external DBK did not include its primary document: ${sourceDocumentPath}`);
63
+ }
64
+ return {
65
+ sourceDocumentPath,
66
+ targetDocumentPath,
67
+ documentContent,
68
+ assetLayout,
69
+ files,
70
+ };
71
+ }
72
+ /**
73
+ * Replace a transient DBK workspace as one logical operation.
74
+ *
75
+ * Container reads and validation happen before provider mutation. The memory
76
+ * provider then stages and swaps the full tree synchronously, which removes
77
+ * stale files and guarantees the old tree survives any failed replacement.
78
+ */
79
+ export async function replaceMemoryWorkspaceFromDbk(provider, source, options) {
80
+ const expectedTreeVersion = provider.treeVersion;
81
+ const snapshot = await createDbkWorkspaceSnapshot(source, options);
82
+ provider.replaceContents(snapshot, expectedTreeVersion);
83
+ return snapshot;
84
+ }
85
+ //# sourceMappingURL=dbk-workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dbk-workspace.js","sourceRoot":"","sources":["../../src/filesystem/dbk-workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AA4BxD,SAAS,qBAAqB,CA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MAAM,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,QAAQ,CAAC,eAAe,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IACxD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { type WorkspacePath } from './workspace-path.js';
2
+ import { type FileSystemCreateDirectoryOptions, type FileSystemDirectorySnapshot, type FileSystemEntrySnapshot, type FileSystemFileRead, type FileSystemFileSnapshot, type FileSystemMoveOptions, type FileSystemProviderCapabilities, type FileSystemProviderV2, type FileSystemRemoveOptions, type FileSystemRemoveResult, type FileSystemSnapshot, type FileSystemWatchEvent, type FileSystemWatchOptions, type FileSystemWatchSubscription, type FileSystemWriteOptions } from './v2.js';
3
+ /** Pure renderer-side client for the typed Electron filesystem v2 transport. */
4
+ export declare class ElectronFileSystemProviderV2 implements FileSystemProviderV2 {
5
+ readonly id: string;
6
+ readonly label: string;
7
+ readonly capabilities: FileSystemProviderCapabilities;
8
+ private readonly rootPath;
9
+ private readonly instanceId;
10
+ private readonly watchers;
11
+ private readonly subscriptions;
12
+ private readonly inFlight;
13
+ private openPromise;
14
+ private removeWatchBridge;
15
+ private disposePromise;
16
+ private hostOpened;
17
+ private disposed;
18
+ constructor(id: string, label: string, rootPath: string);
19
+ getRootPath(): string;
20
+ stat(path: WorkspacePath): Promise<FileSystemEntrySnapshot | null>;
21
+ readFile(path: WorkspacePath): Promise<FileSystemFileRead | null>;
22
+ readDirectory(path: WorkspacePath): Promise<readonly FileSystemEntrySnapshot[]>;
23
+ writeFile(path: WorkspacePath, data: ArrayBuffer | Uint8Array, options?: FileSystemWriteOptions): Promise<FileSystemFileSnapshot>;
24
+ createDirectory(path: WorkspacePath, options?: FileSystemCreateDirectoryOptions): Promise<FileSystemDirectorySnapshot>;
25
+ remove(path: WorkspacePath, options?: FileSystemRemoveOptions): Promise<FileSystemRemoveResult>;
26
+ move(oldPath: WorkspacePath, newPath: WorkspacePath, options?: FileSystemMoveOptions): Promise<FileSystemEntrySnapshot>;
27
+ snapshot(): Promise<FileSystemSnapshot>;
28
+ watch(listener: (event: FileSystemWatchEvent) => void, options?: FileSystemWatchOptions): FileSystemWatchSubscription;
29
+ dispose(): Promise<void>;
30
+ private request;
31
+ private ensureOpen;
32
+ private ensureWatchBridge;
33
+ private handleWatchMessage;
34
+ private assertOpen;
35
+ }
36
+ //# sourceMappingURL=electron-provider-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"electron-provider-v2.d.ts","sourceRoot":"","sources":["../../src/filesystem/electron-provider-v2.ts"],"names":[],"mappings":"AAcA,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,8BAA8B,EACnC,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EAEvB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC5B,MAAM,SAAS,CAAC;AAmBjB,gFAAgF;AAChF,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,YAAY,iCAAwC;IAEpE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,iBAAi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;IAkC1B,OAAO,CAAC,UAAU;CAInB"}
@@ -0,0 +1,503 @@
1
+ import { ELECTRON_FILE_SYSTEM_V2_CAPABILITIES, maybeGetDocBlocksHost, } from '../host/index.js';
2
+ import { FsError, deserializeFsError, fsErrorFromUnknown, isSerializedFsError, } from './fs-error.js';
3
+ import { WORKSPACE_ROOT, parseWorkspacePath, workspacePathBasename, workspacePathDirname, } from './workspace-path.js';
4
+ import { parseFileSystemVersion, } from './v2.js';
5
+ let fallbackInstanceSequence = 0;
6
+ function getHostFsV2(operation) {
7
+ const host = maybeGetDocBlocksHost();
8
+ if (!host?.fsV2) {
9
+ throw new FsError('not-supported', 'Electron filesystem v2 host is unavailable.', {
10
+ operation,
11
+ });
12
+ }
13
+ return host.fsV2;
14
+ }
15
+ /** Pure renderer-side client for the typed Electron filesystem v2 transport. */
16
+ export class ElectronFileSystemProviderV2 {
17
+ constructor(id, label, rootPath) {
18
+ this.capabilities = ELECTRON_FILE_SYSTEM_V2_CAPABILITIES;
19
+ this.instanceId = createInstanceId();
20
+ this.watchers = new Map();
21
+ this.subscriptions = new Set();
22
+ this.inFlight = new Set();
23
+ this.openPromise = null;
24
+ this.removeWatchBridge = null;
25
+ this.disposePromise = null;
26
+ this.hostOpened = false;
27
+ this.disposed = false;
28
+ this.id = id;
29
+ this.label = label;
30
+ this.rootPath = rootPath;
31
+ }
32
+ getRootPath() {
33
+ return this.rootPath;
34
+ }
35
+ async stat(path) {
36
+ const canonical = parseWorkspacePath(String(path));
37
+ return this.request('stat', () => getHostFsV2('stat').stat(this.instanceId, canonical), (value) => (value ? normalizeEntry(value) : null));
38
+ }
39
+ async readFile(path) {
40
+ const canonical = parseWorkspacePath(String(path));
41
+ return this.request('read', () => getHostFsV2('read').readFile(this.instanceId, canonical), (value) => {
42
+ if (!value)
43
+ return null;
44
+ const entry = normalizeFile(value.entry);
45
+ const data = copyWireBuffer(value.data);
46
+ if (data.byteLength !== entry.size) {
47
+ throw new TypeError('Filesystem transport returned file bytes with the wrong size.');
48
+ }
49
+ return Object.freeze({ entry, data });
50
+ });
51
+ }
52
+ async readDirectory(path) {
53
+ const canonical = parseWorkspacePath(String(path));
54
+ return this.request('list', () => getHostFsV2('list').readDirectory(this.instanceId, canonical), (value) => normalizeDirectoryListing(value, canonical));
55
+ }
56
+ async writeFile(path, data, options) {
57
+ const canonical = parseWorkspacePath(String(path));
58
+ const owned = copyBytes(data);
59
+ return this.request('write', () => getHostFsV2('write').writeFile(this.instanceId, canonical, owned, options), normalizeFile);
60
+ }
61
+ async createDirectory(path, options) {
62
+ const canonical = parseWorkspacePath(String(path));
63
+ return this.request('create-directory', () => getHostFsV2('create-directory').createDirectory(this.instanceId, canonical, options), normalizeDirectory);
64
+ }
65
+ async remove(path, options) {
66
+ const canonical = parseWorkspacePath(String(path));
67
+ return this.request('remove', () => getHostFsV2('remove').remove(this.instanceId, canonical, options), normalizeRemoveResult);
68
+ }
69
+ async move(oldPath, newPath, options) {
70
+ const source = parseWorkspacePath(String(oldPath));
71
+ const destination = parseWorkspacePath(String(newPath));
72
+ return this.request('move', () => getHostFsV2('move').move(this.instanceId, source, destination, options), normalizeEntry);
73
+ }
74
+ async snapshot() {
75
+ return this.request('snapshot', () => getHostFsV2('snapshot').snapshot(this.instanceId), normalizeSnapshot);
76
+ }
77
+ watch(listener, options = {}) {
78
+ this.assertOpen('watch');
79
+ this.ensureWatchBridge();
80
+ const subscriptionId = createInstanceId();
81
+ const watcher = { listener, onError: options.onError };
82
+ this.watchers.set(subscriptionId, watcher);
83
+ let closed = false;
84
+ let subscribed = false;
85
+ let closePromise = null;
86
+ const ready = this.ensureOpen('watch')
87
+ .then(async () => {
88
+ if (closed)
89
+ return;
90
+ unwrap(await getHostFsV2('watch').watchSubscribe(this.instanceId, subscriptionId), 'watch');
91
+ subscribed = true;
92
+ })
93
+ .catch((error) => {
94
+ closed = true;
95
+ this.watchers.delete(subscriptionId);
96
+ const typed = error instanceof FsError ? error : new FsError('io', String(error));
97
+ try {
98
+ watcher.onError?.(typed);
99
+ }
100
+ catch {
101
+ // Isolate observers.
102
+ }
103
+ throw typed;
104
+ });
105
+ const subscription = {
106
+ get closed() {
107
+ return closed;
108
+ },
109
+ ready,
110
+ dispose: () => {
111
+ if (closePromise)
112
+ return closePromise;
113
+ closed = true;
114
+ this.watchers.delete(subscriptionId);
115
+ this.subscriptions.delete(subscription);
116
+ closePromise = (async () => {
117
+ await ready.catch(() => undefined);
118
+ if (subscribed) {
119
+ unwrap(await getHostFsV2('watch').watchUnsubscribe(this.instanceId, subscriptionId), 'watch');
120
+ }
121
+ })();
122
+ return closePromise;
123
+ },
124
+ };
125
+ this.subscriptions.add(subscription);
126
+ return subscription;
127
+ }
128
+ dispose() {
129
+ if (this.disposePromise)
130
+ return this.disposePromise;
131
+ this.disposed = true;
132
+ this.disposePromise = (async () => {
133
+ await Promise.allSettled([...this.inFlight]);
134
+ await Promise.all([...this.subscriptions].map((subscription) => subscription.dispose()));
135
+ try {
136
+ if (this.openPromise) {
137
+ try {
138
+ await this.openPromise;
139
+ }
140
+ catch {
141
+ // A failed request normally creates no host record. `hostOpened`
142
+ // separately tracks a successful open whose response validation
143
+ // failed after the main-side record had already been published.
144
+ }
145
+ }
146
+ if (this.hostOpened) {
147
+ try {
148
+ unwrap(await getHostFsV2('dispose').dispose(this.instanceId), 'dispose');
149
+ }
150
+ catch (error) {
151
+ if (!(error instanceof FsError && error.code === 'closed'))
152
+ throw error;
153
+ }
154
+ finally {
155
+ this.hostOpened = false;
156
+ }
157
+ }
158
+ }
159
+ finally {
160
+ this.removeWatchBridge?.();
161
+ this.removeWatchBridge = null;
162
+ }
163
+ })();
164
+ return this.disposePromise;
165
+ }
166
+ request(operation, send, normalize) {
167
+ this.assertOpen(operation);
168
+ const promise = this.ensureOpen(operation).then(async () => {
169
+ try {
170
+ return normalize(unwrap(await send(), operation));
171
+ }
172
+ catch (error) {
173
+ throw transportErrorFromUnknown(error, operation);
174
+ }
175
+ });
176
+ this.inFlight.add(promise);
177
+ void promise.then(() => this.inFlight.delete(promise), () => this.inFlight.delete(promise));
178
+ return promise;
179
+ }
180
+ ensureOpen(operation) {
181
+ this.assertOpen(operation);
182
+ if (!this.openPromise) {
183
+ const attempt = getHostFsV2(operation)
184
+ .open({
185
+ instanceId: this.instanceId,
186
+ providerId: this.id,
187
+ label: this.label,
188
+ })
189
+ .then((result) => {
190
+ if (isRecord(result) && result.ok === true)
191
+ this.hostOpened = true;
192
+ const capabilities = unwrap(result, operation);
193
+ assertCapabilities(capabilities, operation);
194
+ })
195
+ .catch((error) => {
196
+ const typed = withOperation(fsErrorFromUnknown(error, { operation }), operation);
197
+ if (typed.retryable && this.openPromise === attempt)
198
+ this.openPromise = null;
199
+ throw typed;
200
+ });
201
+ this.openPromise = attempt;
202
+ }
203
+ return this.openPromise;
204
+ }
205
+ ensureWatchBridge() {
206
+ if (this.removeWatchBridge)
207
+ return;
208
+ this.removeWatchBridge = getHostFsV2('watch').onWatchMessage((message) => this.handleWatchMessage(message));
209
+ }
210
+ handleWatchMessage(message) {
211
+ if (message.instanceId !== this.instanceId)
212
+ return;
213
+ const watcher = this.watchers.get(message.subscriptionId);
214
+ if (!watcher)
215
+ return;
216
+ if (message.kind === 'error') {
217
+ const typed = isSerializedFsError(message.error)
218
+ ? deserializeFsError(message.error)
219
+ : invalidTransport('watch', 'Filesystem transport returned an invalid watch error.');
220
+ try {
221
+ watcher.onError?.(typed);
222
+ }
223
+ catch {
224
+ // Isolate observers.
225
+ }
226
+ return;
227
+ }
228
+ let event;
229
+ try {
230
+ event = normalizeWatchEvent(message.event);
231
+ }
232
+ catch (error) {
233
+ try {
234
+ watcher.onError?.(transportErrorFromUnknown(error, 'watch'));
235
+ }
236
+ catch {
237
+ // Isolate observers.
238
+ }
239
+ return;
240
+ }
241
+ try {
242
+ watcher.listener(event);
243
+ }
244
+ catch {
245
+ // Watch callbacks are observational.
246
+ }
247
+ }
248
+ assertOpen(operation) {
249
+ if (!this.disposed)
250
+ return;
251
+ throw new FsError('disposed', 'Filesystem provider is disposed.', { operation });
252
+ }
253
+ }
254
+ function unwrap(result, operation) {
255
+ if (!isRecord(result) || typeof result.ok !== 'boolean') {
256
+ throw invalidTransport(operation, 'Filesystem transport returned an invalid result envelope.');
257
+ }
258
+ if (result.ok) {
259
+ if (!('value' in result)) {
260
+ throw invalidTransport(operation, 'Filesystem transport omitted a result value.');
261
+ }
262
+ return result.value;
263
+ }
264
+ if (!isSerializedFsError(result.error)) {
265
+ throw invalidTransport(operation, 'Filesystem transport returned an invalid error envelope.');
266
+ }
267
+ throw deserializeFsError(result.error);
268
+ }
269
+ function normalizeEntry(entry) {
270
+ if (!isRecord(entry))
271
+ throw new TypeError('Expected a filesystem entry object.');
272
+ if (typeof entry.path !== 'string')
273
+ throw new TypeError('Filesystem entry path must be a string.');
274
+ if (typeof entry.name !== 'string')
275
+ throw new TypeError('Filesystem entry name must be a string.');
276
+ if (typeof entry.lastModified !== 'string') {
277
+ throw new TypeError('Filesystem entry timestamp must be a string.');
278
+ }
279
+ const path = parseWorkspacePath(entry.path);
280
+ if (entry.name !== workspacePathBasename(path)) {
281
+ throw new TypeError('Filesystem entry name does not match its canonical path.');
282
+ }
283
+ const common = {
284
+ path,
285
+ name: entry.name,
286
+ version: parseFileSystemVersion(entry.version),
287
+ lastModified: new Date(entry.lastModified).toISOString(),
288
+ };
289
+ if (entry.kind === 'file') {
290
+ if (!isNonNegativeSafeInteger(entry.size)) {
291
+ throw new TypeError('Filesystem file size must be a non-negative safe integer.');
292
+ }
293
+ return Object.freeze({ ...common, kind: 'file', size: entry.size });
294
+ }
295
+ if (entry.kind === 'directory') {
296
+ if (entry.size !== null)
297
+ throw new TypeError('Filesystem directory size must be null.');
298
+ return Object.freeze({ ...common, kind: 'directory', size: null });
299
+ }
300
+ throw new TypeError('Unknown filesystem entry kind.');
301
+ }
302
+ function normalizeDirectoryListing(value, parent) {
303
+ if (!Array.isArray(value))
304
+ throw new TypeError('Expected a filesystem directory listing.');
305
+ const entries = value.map(normalizeEntry);
306
+ const seen = new Set();
307
+ for (const entry of entries) {
308
+ if (entry.path === WORKSPACE_ROOT || workspacePathDirname(entry.path) !== parent) {
309
+ throw new TypeError('Filesystem listing contained a non-child entry.');
310
+ }
311
+ if (seen.has(entry.path))
312
+ throw new TypeError('Filesystem listing contained a duplicate path.');
313
+ seen.add(entry.path);
314
+ }
315
+ const ordered = [...entries].sort(compareDirectoryEntries);
316
+ if (ordered.some((entry, index) => entry.path !== entries[index]?.path)) {
317
+ throw new TypeError('Filesystem listing was not in canonical deterministic order.');
318
+ }
319
+ return Object.freeze(entries);
320
+ }
321
+ function normalizeFile(entry) {
322
+ const normalized = normalizeEntry(entry);
323
+ if (normalized.kind !== 'file')
324
+ throw new TypeError('Expected a file snapshot.');
325
+ return normalized;
326
+ }
327
+ function normalizeDirectory(entry) {
328
+ const normalized = normalizeEntry(entry);
329
+ if (normalized.kind !== 'directory')
330
+ throw new TypeError('Expected a directory snapshot.');
331
+ return normalized;
332
+ }
333
+ function normalizeSnapshot(snapshot) {
334
+ if (!isRecord(snapshot) || !Array.isArray(snapshot.entries)) {
335
+ throw new TypeError('Expected a filesystem snapshot object.');
336
+ }
337
+ const version = parseFileSystemVersion(snapshot.version);
338
+ const entries = snapshot.entries.map((entry) => {
339
+ if (entry.kind === 'file') {
340
+ const file = normalizeFile(entry);
341
+ const data = copyWireBuffer(entry.data);
342
+ if (data.byteLength !== file.size) {
343
+ throw new TypeError('Filesystem snapshot file bytes have the wrong size.');
344
+ }
345
+ return Object.freeze({ ...file, data });
346
+ }
347
+ if (entry.kind === 'directory')
348
+ return normalizeDirectory(entry);
349
+ throw new TypeError('Unknown filesystem snapshot entry kind.');
350
+ });
351
+ const roots = entries.filter((entry) => entry.path === WORKSPACE_ROOT);
352
+ if (roots.length !== 1 || roots[0]?.kind !== 'directory' || roots[0].version !== version) {
353
+ throw new TypeError('Filesystem snapshot must contain one matching root directory.');
354
+ }
355
+ const seen = new Set();
356
+ for (const entry of entries) {
357
+ if (seen.has(entry.path))
358
+ throw new TypeError('Filesystem snapshot contained a duplicate path.');
359
+ seen.add(entry.path);
360
+ }
361
+ const ordered = [...entries].sort((left, right) => compareText(left.path, right.path));
362
+ if (ordered.some((entry, index) => entry.path !== entries[index]?.path)) {
363
+ throw new TypeError('Filesystem snapshot was not in canonical deterministic order.');
364
+ }
365
+ return Object.freeze({
366
+ version,
367
+ entries: Object.freeze(entries),
368
+ });
369
+ }
370
+ function normalizeWatchEvent(event) {
371
+ if (!isRecord(event))
372
+ throw new TypeError('Expected a filesystem watch event object.');
373
+ if (!isPositiveSafeInteger(event.sequence)) {
374
+ throw new TypeError('Filesystem watch sequence must be a positive safe integer.');
375
+ }
376
+ if (!isWatchOrigin(event.origin))
377
+ throw new TypeError('Unknown filesystem watch origin.');
378
+ if (typeof event.path !== 'string')
379
+ throw new TypeError('Watch event path must be a string.');
380
+ const path = parseWorkspacePath(event.path);
381
+ if (event.type === 'overflow') {
382
+ if (event.kind !== null ||
383
+ event.destinationPath !== null ||
384
+ event.version !== null ||
385
+ event.previousVersion !== null) {
386
+ throw new TypeError('Filesystem overflow event has entry-specific fields.');
387
+ }
388
+ return Object.freeze({
389
+ sequence: event.sequence,
390
+ origin: event.origin,
391
+ type: 'overflow',
392
+ kind: null,
393
+ path,
394
+ destinationPath: null,
395
+ version: null,
396
+ previousVersion: null,
397
+ });
398
+ }
399
+ if (!isEntryWatchType(event.type))
400
+ throw new TypeError('Unknown filesystem watch event type.');
401
+ if (event.kind !== 'file' && event.kind !== 'directory') {
402
+ throw new TypeError('Unknown filesystem watch entry kind.');
403
+ }
404
+ const destinationPath = event.destinationPath === null
405
+ ? null
406
+ : typeof event.destinationPath === 'string'
407
+ ? parseWorkspacePath(event.destinationPath)
408
+ : (() => {
409
+ throw new TypeError('Watch destination path must be a string or null.');
410
+ })();
411
+ if ((event.type === 'moved') !== (destinationPath !== null)) {
412
+ throw new TypeError('Only moved watch events may have a destination path.');
413
+ }
414
+ return Object.freeze({
415
+ sequence: event.sequence,
416
+ origin: event.origin,
417
+ type: event.type,
418
+ kind: event.kind,
419
+ path,
420
+ destinationPath,
421
+ version: event.version === null ? null : parseFileSystemVersion(event.version),
422
+ previousVersion: event.previousVersion === null ? null : parseFileSystemVersion(event.previousVersion),
423
+ });
424
+ }
425
+ function normalizeRemoveResult(value) {
426
+ if (!isRecord(value) || typeof value.removed !== 'boolean') {
427
+ throw new TypeError('Filesystem transport returned an invalid remove result.');
428
+ }
429
+ return Object.freeze({ removed: value.removed, version: parseFileSystemVersion(value.version) });
430
+ }
431
+ function assertCapabilities(value, operation) {
432
+ if (!isRecord(value)) {
433
+ throw invalidTransport(operation, 'Filesystem host returned invalid capabilities.');
434
+ }
435
+ for (const key of Object.keys(ELECTRON_FILE_SYSTEM_V2_CAPABILITIES)) {
436
+ if (value[key] !== ELECTRON_FILE_SYSTEM_V2_CAPABILITIES[key]) {
437
+ throw invalidTransport(operation, `Filesystem host capability mismatch: ${key}.`);
438
+ }
439
+ }
440
+ }
441
+ function compareDirectoryEntries(left, right) {
442
+ if (left.kind !== right.kind)
443
+ return left.kind === 'directory' ? -1 : 1;
444
+ return compareText(left.path, right.path);
445
+ }
446
+ function compareText(left, right) {
447
+ return left < right ? -1 : left > right ? 1 : 0;
448
+ }
449
+ function isWatchOrigin(value) {
450
+ return value === 'local' || value === 'external' || value === 'unknown';
451
+ }
452
+ function isEntryWatchType(value) {
453
+ return value === 'created' || value === 'modified' || value === 'removed' || value === 'moved';
454
+ }
455
+ function isNonNegativeSafeInteger(value) {
456
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
457
+ }
458
+ function isPositiveSafeInteger(value) {
459
+ return isNonNegativeSafeInteger(value) && value > 0;
460
+ }
461
+ function isRecord(value) {
462
+ return typeof value === 'object' && value !== null;
463
+ }
464
+ function invalidTransport(operation, message) {
465
+ return new FsError('io', message, { operation, retryable: false });
466
+ }
467
+ function transportErrorFromUnknown(error, operation) {
468
+ if (error instanceof TypeError)
469
+ return invalidTransport(operation, error.message);
470
+ return withOperation(fsErrorFromUnknown(error, { operation }), operation);
471
+ }
472
+ function withOperation(error, operation) {
473
+ if (error.operation === operation)
474
+ return error;
475
+ return new FsError(error.code, error.message, {
476
+ operation,
477
+ path: error.path ?? undefined,
478
+ destinationPath: error.destinationPath ?? undefined,
479
+ retryable: error.retryable,
480
+ });
481
+ }
482
+ function copyBytes(data) {
483
+ const source = ArrayBuffer.isView(data)
484
+ ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
485
+ : new Uint8Array(data);
486
+ const copy = new Uint8Array(source.byteLength);
487
+ copy.set(source);
488
+ return copy.buffer;
489
+ }
490
+ function copyWireBuffer(data) {
491
+ if (Object.prototype.toString.call(data) !== '[object ArrayBuffer]') {
492
+ throw new TypeError('Expected an ArrayBuffer from the filesystem transport.');
493
+ }
494
+ return data.slice(0);
495
+ }
496
+ function createInstanceId() {
497
+ const randomUUID = globalThis.crypto?.randomUUID;
498
+ if (typeof randomUUID === 'function')
499
+ return randomUUID.call(globalThis.crypto);
500
+ fallbackInstanceSequence += 1;
501
+ return `electron-fs-v2-${Date.now()}-${fallbackInstanceSequence}`;
502
+ }
503
+ //# sourceMappingURL=electron-provider-v2.js.map