@bendyline/docblocks 2.0.0 → 2.1.1

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 (278) hide show
  1. package/README.md +2 -2
  2. package/dist/{chunk-2D7Y4IR3.js → chunk-4437YWLE.js} +123 -67
  3. package/dist/{chunk-5MYAICRE.js → chunk-45T5AFCN.js} +44 -57
  4. package/dist/{chunk-PGR7LK6D.js → chunk-6L3JRDE7.js} +14 -6
  5. package/dist/{chunk-RVQHY3XU.js → chunk-6XHOOBYF.js} +0 -1
  6. package/dist/chunk-73OOROXH.js +8 -0
  7. package/dist/{chunk-SI2LU2RP.js → chunk-AYWKIZLD.js} +1 -1
  8. package/dist/{chunk-GCPBEMMH.js → chunk-BVY7GGNV.js} +10 -21
  9. package/dist/{chunk-AEHCVWU5.js → chunk-DZB666V7.js} +0 -1
  10. package/dist/{chunk-75UUF6C4.js → chunk-HI7QEWL6.js} +18 -10
  11. package/dist/chunk-KQ6756AJ.js +28 -0
  12. package/dist/chunk-LMMOFRGQ.js +148 -0
  13. package/dist/{chunk-FNW556FN.js → chunk-M2PUNKHS.js} +0 -1
  14. package/dist/chunk-M5ZNQGR5.js +19 -0
  15. package/dist/chunk-M62ZGJ5I.js +51 -0
  16. package/dist/chunk-OQCPBOQA.js +168 -0
  17. package/dist/{chunk-EGNDADXB.js → chunk-QI6YKTQV.js} +2 -3
  18. package/dist/chunk-SJBB5OD7.js +227 -0
  19. package/dist/{chunk-EZKJZUNJ.js → chunk-XAMILHQP.js} +0 -1
  20. package/dist/{chunk-J32GU3F3.js → chunk-YM7O3PWO.js} +249 -222
  21. package/dist/{chunk-RQJRQF46.js → chunk-ZO7G53QP.js} +41 -49
  22. package/dist/document/index.d.ts +358 -6
  23. package/dist/document/index.js +24 -4
  24. package/dist/filesystem/electron.d.ts +73 -4
  25. package/dist/filesystem/electron.js +16 -4
  26. package/dist/filesystem/index.d.ts +228 -22
  27. package/dist/filesystem/index.js +133 -20
  28. package/dist/filesystem/indexeddb.d.ts +284 -5
  29. package/dist/filesystem/indexeddb.js +22 -5
  30. package/dist/filesystem/memory.d.ts +152 -4
  31. package/dist/filesystem/memory.js +12 -4
  32. package/dist/filesystem/native.d.ts +136 -4
  33. package/dist/filesystem/native.js +27 -4
  34. package/dist/host/index.d.ts +32 -9
  35. package/dist/host/index.js +26 -30
  36. package/dist/index.d.ts +14 -10
  37. package/dist/index.js +204 -10
  38. package/dist/mcp/index.d.ts +33 -4
  39. package/dist/mcp/index.js +31 -4
  40. package/dist/mcp/zod.d.ts +645 -643
  41. package/dist/mcp/zod.js +700 -885
  42. package/dist/share/index.d.ts +43 -0
  43. package/dist/share/index.js +12 -0
  44. package/dist/{types-CsX6EN2t.d.ts → types-BEg5SQ1_.d.ts} +1 -1
  45. package/dist/{types-eOlt9J7n.d.ts → types-CueK0tvU.d.ts} +34 -11
  46. package/dist/vscode/index.d.ts +225 -3
  47. package/dist/vscode/index.js +389 -3
  48. package/dist/workspace/index.d.ts +141 -4
  49. package/dist/workspace/index.js +28 -3
  50. package/package.json +10 -5
  51. package/dist/chunk-2D7Y4IR3.js.map +0 -1
  52. package/dist/chunk-5MYAICRE.js.map +0 -1
  53. package/dist/chunk-75UUF6C4.js.map +0 -1
  54. package/dist/chunk-AEHCVWU5.js.map +0 -1
  55. package/dist/chunk-AYZ4HN5M.js +0 -20
  56. package/dist/chunk-AYZ4HN5M.js.map +0 -1
  57. package/dist/chunk-EGNDADXB.js.map +0 -1
  58. package/dist/chunk-EZKJZUNJ.js.map +0 -1
  59. package/dist/chunk-FNW556FN.js.map +0 -1
  60. package/dist/chunk-GCPBEMMH.js.map +0 -1
  61. package/dist/chunk-J32GU3F3.js.map +0 -1
  62. package/dist/chunk-PGR7LK6D.js.map +0 -1
  63. package/dist/chunk-RQJRQF46.js.map +0 -1
  64. package/dist/chunk-RVQHY3XU.js.map +0 -1
  65. package/dist/chunk-SI2LU2RP.js.map +0 -1
  66. package/dist/chunk-W5UUUII5.js +0 -142
  67. package/dist/chunk-W5UUUII5.js.map +0 -1
  68. package/dist/document/document-session.d.ts +0 -127
  69. package/dist/document/document-session.d.ts.map +0 -1
  70. package/dist/document/document-session.js +0 -749
  71. package/dist/document/document-session.js.map +0 -1
  72. package/dist/document/filesystem-target.d.ts +0 -17
  73. package/dist/document/filesystem-target.d.ts.map +0 -1
  74. package/dist/document/filesystem-target.js +0 -70
  75. package/dist/document/filesystem-target.js.map +0 -1
  76. package/dist/document/index.d.ts.map +0 -1
  77. package/dist/document/index.js.map +0 -1
  78. package/dist/document/recovery-journal.d.ts +0 -125
  79. package/dist/document/recovery-journal.d.ts.map +0 -1
  80. package/dist/document/recovery-journal.js +0 -385
  81. package/dist/document/recovery-journal.js.map +0 -1
  82. package/dist/document/types.d.ts +0 -89
  83. package/dist/document/types.d.ts.map +0 -1
  84. package/dist/document/types.js +0 -9
  85. package/dist/document/types.js.map +0 -1
  86. package/dist/filesystem/commit-lock.d.ts +0 -3
  87. package/dist/filesystem/commit-lock.d.ts.map +0 -1
  88. package/dist/filesystem/commit-lock.js +0 -20
  89. package/dist/filesystem/commit-lock.js.map +0 -1
  90. package/dist/filesystem/dbk-workspace.d.ts +0 -34
  91. package/dist/filesystem/dbk-workspace.d.ts.map +0 -1
  92. package/dist/filesystem/dbk-workspace.js +0 -85
  93. package/dist/filesystem/dbk-workspace.js.map +0 -1
  94. package/dist/filesystem/electron-provider-v2.d.ts +0 -36
  95. package/dist/filesystem/electron-provider-v2.d.ts.map +0 -1
  96. package/dist/filesystem/electron-provider-v2.js +0 -503
  97. package/dist/filesystem/electron-provider-v2.js.map +0 -1
  98. package/dist/filesystem/electron-provider.d.ts +0 -35
  99. package/dist/filesystem/electron-provider.d.ts.map +0 -1
  100. package/dist/filesystem/electron-provider.js +0 -69
  101. package/dist/filesystem/electron-provider.js.map +0 -1
  102. package/dist/filesystem/electron.d.ts.map +0 -1
  103. package/dist/filesystem/electron.js.map +0 -1
  104. package/dist/filesystem/file-media-provider.d.ts +0 -23
  105. package/dist/filesystem/file-media-provider.d.ts.map +0 -1
  106. package/dist/filesystem/file-media-provider.js +0 -85
  107. package/dist/filesystem/file-media-provider.js.map +0 -1
  108. package/dist/filesystem/filesystem-content-container.d.ts +0 -24
  109. package/dist/filesystem/filesystem-content-container.d.ts.map +0 -1
  110. package/dist/filesystem/filesystem-content-container.js +0 -153
  111. package/dist/filesystem/filesystem-content-container.js.map +0 -1
  112. package/dist/filesystem/fs-error.d.ts +0 -46
  113. package/dist/filesystem/fs-error.d.ts.map +0 -1
  114. package/dist/filesystem/fs-error.js +0 -170
  115. package/dist/filesystem/fs-error.js.map +0 -1
  116. package/dist/filesystem/index.d.ts.map +0 -1
  117. package/dist/filesystem/index.js.map +0 -1
  118. package/dist/filesystem/indexeddb-content-container.d.ts +0 -22
  119. package/dist/filesystem/indexeddb-content-container.d.ts.map +0 -1
  120. package/dist/filesystem/indexeddb-content-container.js +0 -100
  121. package/dist/filesystem/indexeddb-content-container.js.map +0 -1
  122. package/dist/filesystem/indexeddb-provider-v2.d.ts +0 -96
  123. package/dist/filesystem/indexeddb-provider-v2.d.ts.map +0 -1
  124. package/dist/filesystem/indexeddb-provider-v2.js +0 -1241
  125. package/dist/filesystem/indexeddb-provider-v2.js.map +0 -1
  126. package/dist/filesystem/indexeddb-provider.d.ts +0 -39
  127. package/dist/filesystem/indexeddb-provider.d.ts.map +0 -1
  128. package/dist/filesystem/indexeddb-provider.js +0 -145
  129. package/dist/filesystem/indexeddb-provider.js.map +0 -1
  130. package/dist/filesystem/indexeddb-store.d.ts +0 -34
  131. package/dist/filesystem/indexeddb-store.d.ts.map +0 -1
  132. package/dist/filesystem/indexeddb-store.js +0 -165
  133. package/dist/filesystem/indexeddb-store.js.map +0 -1
  134. package/dist/filesystem/indexeddb.d.ts.map +0 -1
  135. package/dist/filesystem/indexeddb.js.map +0 -1
  136. package/dist/filesystem/legacy-v2-adapter.d.ts +0 -62
  137. package/dist/filesystem/legacy-v2-adapter.d.ts.map +0 -1
  138. package/dist/filesystem/legacy-v2-adapter.js +0 -499
  139. package/dist/filesystem/legacy-v2-adapter.js.map +0 -1
  140. package/dist/filesystem/memory-provider-v2.d.ts +0 -92
  141. package/dist/filesystem/memory-provider-v2.d.ts.map +0 -1
  142. package/dist/filesystem/memory-provider-v2.js +0 -615
  143. package/dist/filesystem/memory-provider-v2.js.map +0 -1
  144. package/dist/filesystem/memory-provider.d.ts +0 -54
  145. package/dist/filesystem/memory-provider.d.ts.map +0 -1
  146. package/dist/filesystem/memory-provider.js +0 -132
  147. package/dist/filesystem/memory-provider.js.map +0 -1
  148. package/dist/filesystem/memory.d.ts.map +0 -1
  149. package/dist/filesystem/memory.js.map +0 -1
  150. package/dist/filesystem/move-entry.d.ts +0 -9
  151. package/dist/filesystem/move-entry.d.ts.map +0 -1
  152. package/dist/filesystem/move-entry.js +0 -103
  153. package/dist/filesystem/move-entry.js.map +0 -1
  154. package/dist/filesystem/move-error.d.ts +0 -53
  155. package/dist/filesystem/move-error.d.ts.map +0 -1
  156. package/dist/filesystem/move-error.js +0 -99
  157. package/dist/filesystem/move-error.js.map +0 -1
  158. package/dist/filesystem/native-provider-v2.d.ts +0 -75
  159. package/dist/filesystem/native-provider-v2.d.ts.map +0 -1
  160. package/dist/filesystem/native-provider-v2.js +0 -849
  161. package/dist/filesystem/native-provider-v2.js.map +0 -1
  162. package/dist/filesystem/native-provider.d.ts +0 -53
  163. package/dist/filesystem/native-provider.d.ts.map +0 -1
  164. package/dist/filesystem/native-provider.js +0 -471
  165. package/dist/filesystem/native-provider.js.map +0 -1
  166. package/dist/filesystem/native.d.ts.map +0 -1
  167. package/dist/filesystem/native.js.map +0 -1
  168. package/dist/filesystem/types.d.ts +0 -83
  169. package/dist/filesystem/types.d.ts.map +0 -1
  170. package/dist/filesystem/types.js +0 -16
  171. package/dist/filesystem/types.js.map +0 -1
  172. package/dist/filesystem/v2.d.ts +0 -172
  173. package/dist/filesystem/v2.d.ts.map +0 -1
  174. package/dist/filesystem/v2.js +0 -16
  175. package/dist/filesystem/v2.js.map +0 -1
  176. package/dist/filesystem/workspace-path.d.ts +0 -21
  177. package/dist/filesystem/workspace-path.d.ts.map +0 -1
  178. package/dist/filesystem/workspace-path.js +0 -80
  179. package/dist/filesystem/workspace-path.js.map +0 -1
  180. package/dist/host/filesystem-v2.d.ts +0 -45
  181. package/dist/host/filesystem-v2.d.ts.map +0 -1
  182. package/dist/host/filesystem-v2.js +0 -13
  183. package/dist/host/filesystem-v2.js.map +0 -1
  184. package/dist/host/git.d.ts +0 -200
  185. package/dist/host/git.d.ts.map +0 -1
  186. package/dist/host/git.js +0 -15
  187. package/dist/host/git.js.map +0 -1
  188. package/dist/host/index.d.ts.map +0 -1
  189. package/dist/host/index.js.map +0 -1
  190. package/dist/host/types.d.ts +0 -232
  191. package/dist/host/types.d.ts.map +0 -1
  192. package/dist/host/types.js +0 -10
  193. package/dist/host/types.js.map +0 -1
  194. package/dist/host/wire-policy.d.ts +0 -22
  195. package/dist/host/wire-policy.d.ts.map +0 -1
  196. package/dist/host/wire-policy.js +0 -92
  197. package/dist/host/wire-policy.js.map +0 -1
  198. package/dist/index.d.ts.map +0 -1
  199. package/dist/index.js.map +0 -1
  200. package/dist/mcp/index.d.ts.map +0 -1
  201. package/dist/mcp/index.js.map +0 -1
  202. package/dist/mcp/types.d.ts +0 -466
  203. package/dist/mcp/types.d.ts.map +0 -1
  204. package/dist/mcp/types.js +0 -25
  205. package/dist/mcp/types.js.map +0 -1
  206. package/dist/mcp/wire.d.ts +0 -29
  207. package/dist/mcp/wire.d.ts.map +0 -1
  208. package/dist/mcp/wire.js +0 -1046
  209. package/dist/mcp/wire.js.map +0 -1
  210. package/dist/mcp/zod.d.ts.map +0 -1
  211. package/dist/mcp/zod.js.map +0 -1
  212. package/dist/vscode/index.d.ts.map +0 -1
  213. package/dist/vscode/index.js.map +0 -1
  214. package/dist/vscode/messages.d.ts +0 -204
  215. package/dist/vscode/messages.d.ts.map +0 -1
  216. package/dist/vscode/messages.js +0 -494
  217. package/dist/vscode/messages.js.map +0 -1
  218. package/dist/workspace/index.d.ts.map +0 -1
  219. package/dist/workspace/index.js.map +0 -1
  220. package/dist/workspace/reconcile-electron.d.ts +0 -19
  221. package/dist/workspace/reconcile-electron.d.ts.map +0 -1
  222. package/dist/workspace/reconcile-electron.js +0 -42
  223. package/dist/workspace/reconcile-electron.js.map +0 -1
  224. package/dist/workspace/types.d.ts +0 -69
  225. package/dist/workspace/types.d.ts.map +0 -1
  226. package/dist/workspace/types.js +0 -2
  227. package/dist/workspace/types.js.map +0 -1
  228. package/dist/workspace/workspace-manager.d.ts +0 -47
  229. package/dist/workspace/workspace-manager.d.ts.map +0 -1
  230. package/dist/workspace/workspace-manager.js +0 -126
  231. package/dist/workspace/workspace-manager.js.map +0 -1
  232. package/src/document/document-session.ts +0 -834
  233. package/src/document/filesystem-target.ts +0 -109
  234. package/src/document/index.ts +0 -41
  235. package/src/document/recovery-journal.ts +0 -536
  236. package/src/document/types.ts +0 -116
  237. package/src/filesystem/commit-lock.ts +0 -29
  238. package/src/filesystem/dbk-workspace.ts +0 -135
  239. package/src/filesystem/electron-provider-v2.ts +0 -630
  240. package/src/filesystem/electron-provider.ts +0 -99
  241. package/src/filesystem/electron.ts +0 -3
  242. package/src/filesystem/file-media-provider.ts +0 -103
  243. package/src/filesystem/filesystem-content-container.ts +0 -164
  244. package/src/filesystem/fs-error.ts +0 -234
  245. package/src/filesystem/index.ts +0 -143
  246. package/src/filesystem/indexeddb-content-container.ts +0 -112
  247. package/src/filesystem/indexeddb-provider-v2.ts +0 -1740
  248. package/src/filesystem/indexeddb-provider.ts +0 -171
  249. package/src/filesystem/indexeddb-store.ts +0 -207
  250. package/src/filesystem/indexeddb.ts +0 -12
  251. package/src/filesystem/legacy-v2-adapter.ts +0 -779
  252. package/src/filesystem/memory-provider-v2.ts +0 -896
  253. package/src/filesystem/memory-provider.ts +0 -180
  254. package/src/filesystem/memory.ts +0 -15
  255. package/src/filesystem/move-entry.ts +0 -142
  256. package/src/filesystem/move-error.ts +0 -159
  257. package/src/filesystem/native-provider-v2.ts +0 -1165
  258. package/src/filesystem/native-provider.ts +0 -537
  259. package/src/filesystem/native.ts +0 -16
  260. package/src/filesystem/types.ts +0 -114
  261. package/src/filesystem/v2.ts +0 -231
  262. package/src/filesystem/workspace-path.ts +0 -92
  263. package/src/host/filesystem-v2.ts +0 -104
  264. package/src/host/git.ts +0 -246
  265. package/src/host/index.ts +0 -93
  266. package/src/host/types.ts +0 -274
  267. package/src/host/wire-policy.ts +0 -103
  268. package/src/index.ts +0 -10
  269. package/src/mcp/index.ts +0 -3
  270. package/src/mcp/types.ts +0 -594
  271. package/src/mcp/wire.ts +0 -1280
  272. package/src/mcp/zod.ts +0 -1000
  273. package/src/vscode/index.ts +0 -2
  274. package/src/vscode/messages.ts +0 -704
  275. package/src/workspace/index.ts +0 -17
  276. package/src/workspace/reconcile-electron.ts +0 -65
  277. package/src/workspace/types.ts +0 -67
  278. package/src/workspace/workspace-manager.ts +0 -151
@@ -1,630 +0,0 @@
1
- import {
2
- ELECTRON_FILE_SYSTEM_V2_CAPABILITIES,
3
- maybeGetDocBlocksHost,
4
- type DocBlocksHostFsV2API,
5
- type HostFileSystemV2Result,
6
- type HostFileSystemV2WatchMessage,
7
- } from '../host/index.js';
8
- import {
9
- FsError,
10
- deserializeFsError,
11
- fsErrorFromUnknown,
12
- isSerializedFsError,
13
- type FsOperation,
14
- } from './fs-error.js';
15
- import {
16
- WORKSPACE_ROOT,
17
- parseWorkspacePath,
18
- workspacePathBasename,
19
- workspacePathDirname,
20
- type WorkspacePath,
21
- } from './workspace-path.js';
22
- import {
23
- parseFileSystemVersion,
24
- type FileSystemCreateDirectoryOptions,
25
- type FileSystemDirectorySnapshot,
26
- type FileSystemEntrySnapshot,
27
- type FileSystemFileRead,
28
- type FileSystemFileSnapshot,
29
- type FileSystemMoveOptions,
30
- type FileSystemProviderCapabilities,
31
- type FileSystemProviderV2,
32
- type FileSystemRemoveOptions,
33
- type FileSystemRemoveResult,
34
- type FileSystemSnapshot,
35
- type FileSystemSnapshotEntry,
36
- type FileSystemWatchEvent,
37
- type FileSystemWatchOptions,
38
- type FileSystemWatchSubscription,
39
- type FileSystemWriteOptions,
40
- } from './v2.js';
41
-
42
- interface ClientWatcher {
43
- readonly listener: (event: FileSystemWatchEvent) => void;
44
- readonly onError: FileSystemWatchOptions['onError'];
45
- }
46
-
47
- let fallbackInstanceSequence = 0;
48
-
49
- function getHostFsV2(operation: FsOperation): DocBlocksHostFsV2API {
50
- const host = maybeGetDocBlocksHost();
51
- if (!host?.fsV2) {
52
- throw new FsError('not-supported', 'Electron filesystem v2 host is unavailable.', {
53
- operation,
54
- });
55
- }
56
- return host.fsV2;
57
- }
58
-
59
- /** Pure renderer-side client for the typed Electron filesystem v2 transport. */
60
- export class ElectronFileSystemProviderV2 implements FileSystemProviderV2 {
61
- public readonly id: string;
62
- public readonly label: string;
63
- public readonly capabilities = ELECTRON_FILE_SYSTEM_V2_CAPABILITIES;
64
-
65
- private readonly rootPath: string;
66
- private readonly instanceId = createInstanceId();
67
- private readonly watchers = new Map<string, ClientWatcher>();
68
- private readonly subscriptions = new Set<FileSystemWatchSubscription>();
69
- private readonly inFlight = new Set<Promise<unknown>>();
70
- private openPromise: Promise<void> | null = null;
71
- private removeWatchBridge: (() => void) | null = null;
72
- private disposePromise: Promise<void> | null = null;
73
- private hostOpened = false;
74
- private disposed = false;
75
-
76
- public constructor(id: string, label: string, rootPath: string) {
77
- this.id = id;
78
- this.label = label;
79
- this.rootPath = rootPath;
80
- }
81
-
82
- public getRootPath(): string {
83
- return this.rootPath;
84
- }
85
-
86
- public async stat(path: WorkspacePath): Promise<FileSystemEntrySnapshot | null> {
87
- const canonical = parseWorkspacePath(String(path));
88
- return this.request(
89
- 'stat',
90
- () => getHostFsV2('stat').stat(this.instanceId, canonical),
91
- (value) => (value ? normalizeEntry(value) : null),
92
- );
93
- }
94
-
95
- public async readFile(path: WorkspacePath): Promise<FileSystemFileRead | null> {
96
- const canonical = parseWorkspacePath(String(path));
97
- return this.request(
98
- 'read',
99
- () => getHostFsV2('read').readFile(this.instanceId, canonical),
100
- (value) => {
101
- if (!value) return null;
102
- const entry = normalizeFile(value.entry);
103
- const data = copyWireBuffer(value.data);
104
- if (data.byteLength !== entry.size) {
105
- throw new TypeError('Filesystem transport returned file bytes with the wrong size.');
106
- }
107
- return Object.freeze({ entry, data });
108
- },
109
- );
110
- }
111
-
112
- public async readDirectory(path: WorkspacePath): Promise<readonly FileSystemEntrySnapshot[]> {
113
- const canonical = parseWorkspacePath(String(path));
114
- return this.request(
115
- 'list',
116
- () => getHostFsV2('list').readDirectory(this.instanceId, canonical),
117
- (value) => normalizeDirectoryListing(value, canonical),
118
- );
119
- }
120
-
121
- public async writeFile(
122
- path: WorkspacePath,
123
- data: ArrayBuffer | Uint8Array,
124
- options?: FileSystemWriteOptions,
125
- ): Promise<FileSystemFileSnapshot> {
126
- const canonical = parseWorkspacePath(String(path));
127
- const owned = copyBytes(data);
128
- return this.request(
129
- 'write',
130
- () => getHostFsV2('write').writeFile(this.instanceId, canonical, owned, options),
131
- normalizeFile,
132
- );
133
- }
134
-
135
- public async createDirectory(
136
- path: WorkspacePath,
137
- options?: FileSystemCreateDirectoryOptions,
138
- ): Promise<FileSystemDirectorySnapshot> {
139
- const canonical = parseWorkspacePath(String(path));
140
- return this.request(
141
- 'create-directory',
142
- () => getHostFsV2('create-directory').createDirectory(this.instanceId, canonical, options),
143
- normalizeDirectory,
144
- );
145
- }
146
-
147
- public async remove(
148
- path: WorkspacePath,
149
- options?: FileSystemRemoveOptions,
150
- ): Promise<FileSystemRemoveResult> {
151
- const canonical = parseWorkspacePath(String(path));
152
- return this.request(
153
- 'remove',
154
- () => getHostFsV2('remove').remove(this.instanceId, canonical, options),
155
- normalizeRemoveResult,
156
- );
157
- }
158
-
159
- public async move(
160
- oldPath: WorkspacePath,
161
- newPath: WorkspacePath,
162
- options?: FileSystemMoveOptions,
163
- ): Promise<FileSystemEntrySnapshot> {
164
- const source = parseWorkspacePath(String(oldPath));
165
- const destination = parseWorkspacePath(String(newPath));
166
- return this.request(
167
- 'move',
168
- () => getHostFsV2('move').move(this.instanceId, source, destination, options),
169
- normalizeEntry,
170
- );
171
- }
172
-
173
- public async snapshot(): Promise<FileSystemSnapshot> {
174
- return this.request(
175
- 'snapshot',
176
- () => getHostFsV2('snapshot').snapshot(this.instanceId),
177
- normalizeSnapshot,
178
- );
179
- }
180
-
181
- public watch(
182
- listener: (event: FileSystemWatchEvent) => void,
183
- options: FileSystemWatchOptions = {},
184
- ): FileSystemWatchSubscription {
185
- this.assertOpen('watch');
186
- this.ensureWatchBridge();
187
- const subscriptionId = createInstanceId();
188
- const watcher: ClientWatcher = { listener, onError: options.onError };
189
- this.watchers.set(subscriptionId, watcher);
190
- let closed = false;
191
- let subscribed = false;
192
- let closePromise: Promise<void> | null = null;
193
- const ready = this.ensureOpen('watch')
194
- .then(async () => {
195
- if (closed) return;
196
- unwrap(await getHostFsV2('watch').watchSubscribe(this.instanceId, subscriptionId), 'watch');
197
- subscribed = true;
198
- })
199
- .catch((error: unknown) => {
200
- closed = true;
201
- this.watchers.delete(subscriptionId);
202
- const typed = error instanceof FsError ? error : new FsError('io', String(error));
203
- try {
204
- watcher.onError?.(typed);
205
- } catch {
206
- // Isolate observers.
207
- }
208
- throw typed;
209
- });
210
-
211
- const subscription: FileSystemWatchSubscription = {
212
- get closed() {
213
- return closed;
214
- },
215
- ready,
216
- dispose: () => {
217
- if (closePromise) return closePromise;
218
- closed = true;
219
- this.watchers.delete(subscriptionId);
220
- this.subscriptions.delete(subscription);
221
- closePromise = (async () => {
222
- await ready.catch(() => undefined);
223
- if (subscribed) {
224
- unwrap(
225
- await getHostFsV2('watch').watchUnsubscribe(this.instanceId, subscriptionId),
226
- 'watch',
227
- );
228
- }
229
- })();
230
- return closePromise;
231
- },
232
- };
233
- this.subscriptions.add(subscription);
234
- return subscription;
235
- }
236
-
237
- public dispose(): Promise<void> {
238
- if (this.disposePromise) return this.disposePromise;
239
- this.disposed = true;
240
- this.disposePromise = (async () => {
241
- await Promise.allSettled([...this.inFlight]);
242
- await Promise.all([...this.subscriptions].map((subscription) => subscription.dispose()));
243
- try {
244
- if (this.openPromise) {
245
- try {
246
- await this.openPromise;
247
- } catch {
248
- // A failed request normally creates no host record. `hostOpened`
249
- // separately tracks a successful open whose response validation
250
- // failed after the main-side record had already been published.
251
- }
252
- }
253
- if (this.hostOpened) {
254
- try {
255
- unwrap(await getHostFsV2('dispose').dispose(this.instanceId), 'dispose');
256
- } catch (error: unknown) {
257
- if (!(error instanceof FsError && error.code === 'closed')) throw error;
258
- } finally {
259
- this.hostOpened = false;
260
- }
261
- }
262
- } finally {
263
- this.removeWatchBridge?.();
264
- this.removeWatchBridge = null;
265
- }
266
- })();
267
- return this.disposePromise;
268
- }
269
-
270
- private request<T, U>(
271
- operation: FsOperation,
272
- send: () => Promise<HostFileSystemV2Result<T>>,
273
- normalize: (value: T) => U,
274
- ): Promise<U> {
275
- this.assertOpen(operation);
276
- const promise = this.ensureOpen(operation).then(async () => {
277
- try {
278
- return normalize(unwrap(await send(), operation));
279
- } catch (error: unknown) {
280
- throw transportErrorFromUnknown(error, operation);
281
- }
282
- });
283
- this.inFlight.add(promise);
284
- void promise.then(
285
- () => this.inFlight.delete(promise),
286
- () => this.inFlight.delete(promise),
287
- );
288
- return promise;
289
- }
290
-
291
- private ensureOpen(operation: FsOperation): Promise<void> {
292
- this.assertOpen(operation);
293
- if (!this.openPromise) {
294
- const attempt = getHostFsV2(operation)
295
- .open({
296
- instanceId: this.instanceId,
297
- providerId: this.id,
298
- label: this.label,
299
- })
300
- .then((result) => {
301
- if (isRecord(result) && result.ok === true) this.hostOpened = true;
302
- const capabilities = unwrap(result, operation);
303
- assertCapabilities(capabilities, operation);
304
- })
305
- .catch((error: unknown) => {
306
- const typed = withOperation(fsErrorFromUnknown(error, { operation }), operation);
307
- if (typed.retryable && this.openPromise === attempt) this.openPromise = null;
308
- throw typed;
309
- });
310
- this.openPromise = attempt;
311
- }
312
- return this.openPromise;
313
- }
314
-
315
- private ensureWatchBridge(): void {
316
- if (this.removeWatchBridge) return;
317
- this.removeWatchBridge = getHostFsV2('watch').onWatchMessage((message) =>
318
- this.handleWatchMessage(message),
319
- );
320
- }
321
-
322
- private handleWatchMessage(message: HostFileSystemV2WatchMessage): void {
323
- if (message.instanceId !== this.instanceId) return;
324
- const watcher = this.watchers.get(message.subscriptionId);
325
- if (!watcher) return;
326
- if (message.kind === 'error') {
327
- const typed = isSerializedFsError(message.error)
328
- ? deserializeFsError(message.error)
329
- : invalidTransport('watch', 'Filesystem transport returned an invalid watch error.');
330
- try {
331
- watcher.onError?.(typed);
332
- } catch {
333
- // Isolate observers.
334
- }
335
- return;
336
- }
337
-
338
- let event: FileSystemWatchEvent;
339
- try {
340
- event = normalizeWatchEvent(message.event);
341
- } catch (error: unknown) {
342
- try {
343
- watcher.onError?.(transportErrorFromUnknown(error, 'watch'));
344
- } catch {
345
- // Isolate observers.
346
- }
347
- return;
348
- }
349
- try {
350
- watcher.listener(event);
351
- } catch {
352
- // Watch callbacks are observational.
353
- }
354
- }
355
-
356
- private assertOpen(operation: FsOperation): void {
357
- if (!this.disposed) return;
358
- throw new FsError('disposed', 'Filesystem provider is disposed.', { operation });
359
- }
360
- }
361
-
362
- function unwrap<T>(result: HostFileSystemV2Result<T>, operation: FsOperation): T {
363
- if (!isRecord(result) || typeof result.ok !== 'boolean') {
364
- throw invalidTransport(operation, 'Filesystem transport returned an invalid result envelope.');
365
- }
366
- if (result.ok) {
367
- if (!('value' in result)) {
368
- throw invalidTransport(operation, 'Filesystem transport omitted a result value.');
369
- }
370
- return result.value;
371
- }
372
- if (!isSerializedFsError(result.error)) {
373
- throw invalidTransport(operation, 'Filesystem transport returned an invalid error envelope.');
374
- }
375
- throw deserializeFsError(result.error);
376
- }
377
-
378
- function normalizeEntry(entry: FileSystemEntrySnapshot): FileSystemEntrySnapshot {
379
- if (!isRecord(entry)) throw new TypeError('Expected a filesystem entry object.');
380
- if (typeof entry.path !== 'string')
381
- throw new TypeError('Filesystem entry path must be a string.');
382
- if (typeof entry.name !== 'string')
383
- throw new TypeError('Filesystem entry name must be a string.');
384
- if (typeof entry.lastModified !== 'string') {
385
- throw new TypeError('Filesystem entry timestamp must be a string.');
386
- }
387
- const path = parseWorkspacePath(entry.path);
388
- if (entry.name !== workspacePathBasename(path)) {
389
- throw new TypeError('Filesystem entry name does not match its canonical path.');
390
- }
391
- const common = {
392
- path,
393
- name: entry.name,
394
- version: parseFileSystemVersion(entry.version),
395
- lastModified: new Date(entry.lastModified).toISOString(),
396
- };
397
- if (entry.kind === 'file') {
398
- if (!isNonNegativeSafeInteger(entry.size)) {
399
- throw new TypeError('Filesystem file size must be a non-negative safe integer.');
400
- }
401
- return Object.freeze({ ...common, kind: 'file', size: entry.size });
402
- }
403
- if (entry.kind === 'directory') {
404
- if (entry.size !== null) throw new TypeError('Filesystem directory size must be null.');
405
- return Object.freeze({ ...common, kind: 'directory', size: null });
406
- }
407
- throw new TypeError('Unknown filesystem entry kind.');
408
- }
409
-
410
- function normalizeDirectoryListing(
411
- value: readonly FileSystemEntrySnapshot[],
412
- parent: WorkspacePath,
413
- ): readonly FileSystemEntrySnapshot[] {
414
- if (!Array.isArray(value)) throw new TypeError('Expected a filesystem directory listing.');
415
- const entries = value.map(normalizeEntry);
416
- const seen = new Set<WorkspacePath>();
417
- for (const entry of entries) {
418
- if (entry.path === WORKSPACE_ROOT || workspacePathDirname(entry.path) !== parent) {
419
- throw new TypeError('Filesystem listing contained a non-child entry.');
420
- }
421
- if (seen.has(entry.path)) throw new TypeError('Filesystem listing contained a duplicate path.');
422
- seen.add(entry.path);
423
- }
424
- const ordered = [...entries].sort(compareDirectoryEntries);
425
- if (ordered.some((entry, index) => entry.path !== entries[index]?.path)) {
426
- throw new TypeError('Filesystem listing was not in canonical deterministic order.');
427
- }
428
- return Object.freeze(entries);
429
- }
430
-
431
- function normalizeFile(entry: FileSystemFileSnapshot): FileSystemFileSnapshot {
432
- const normalized = normalizeEntry(entry);
433
- if (normalized.kind !== 'file') throw new TypeError('Expected a file snapshot.');
434
- return normalized;
435
- }
436
-
437
- function normalizeDirectory(entry: FileSystemDirectorySnapshot): FileSystemDirectorySnapshot {
438
- const normalized = normalizeEntry(entry);
439
- if (normalized.kind !== 'directory') throw new TypeError('Expected a directory snapshot.');
440
- return normalized;
441
- }
442
-
443
- function normalizeSnapshot(snapshot: FileSystemSnapshot): FileSystemSnapshot {
444
- if (!isRecord(snapshot) || !Array.isArray(snapshot.entries)) {
445
- throw new TypeError('Expected a filesystem snapshot object.');
446
- }
447
- const version = parseFileSystemVersion(snapshot.version);
448
- const entries: FileSystemSnapshotEntry[] = snapshot.entries.map((entry) => {
449
- if (entry.kind === 'file') {
450
- const file = normalizeFile(entry);
451
- const data = copyWireBuffer(entry.data);
452
- if (data.byteLength !== file.size) {
453
- throw new TypeError('Filesystem snapshot file bytes have the wrong size.');
454
- }
455
- return Object.freeze({ ...file, data });
456
- }
457
- if (entry.kind === 'directory') return normalizeDirectory(entry);
458
- throw new TypeError('Unknown filesystem snapshot entry kind.');
459
- });
460
- const roots = entries.filter((entry) => entry.path === WORKSPACE_ROOT);
461
- if (roots.length !== 1 || roots[0]?.kind !== 'directory' || roots[0].version !== version) {
462
- throw new TypeError('Filesystem snapshot must contain one matching root directory.');
463
- }
464
- const seen = new Set<WorkspacePath>();
465
- for (const entry of entries) {
466
- if (seen.has(entry.path))
467
- throw new TypeError('Filesystem snapshot contained a duplicate path.');
468
- seen.add(entry.path);
469
- }
470
- const ordered = [...entries].sort((left, right) => compareText(left.path, right.path));
471
- if (ordered.some((entry, index) => entry.path !== entries[index]?.path)) {
472
- throw new TypeError('Filesystem snapshot was not in canonical deterministic order.');
473
- }
474
- return Object.freeze({
475
- version,
476
- entries: Object.freeze(entries),
477
- });
478
- }
479
-
480
- function normalizeWatchEvent(event: FileSystemWatchEvent): FileSystemWatchEvent {
481
- if (!isRecord(event)) throw new TypeError('Expected a filesystem watch event object.');
482
- if (!isPositiveSafeInteger(event.sequence)) {
483
- throw new TypeError('Filesystem watch sequence must be a positive safe integer.');
484
- }
485
- if (!isWatchOrigin(event.origin)) throw new TypeError('Unknown filesystem watch origin.');
486
- if (typeof event.path !== 'string') throw new TypeError('Watch event path must be a string.');
487
- const path = parseWorkspacePath(event.path);
488
- if (event.type === 'overflow') {
489
- if (
490
- event.kind !== null ||
491
- event.destinationPath !== null ||
492
- event.version !== null ||
493
- event.previousVersion !== null
494
- ) {
495
- throw new TypeError('Filesystem overflow event has entry-specific fields.');
496
- }
497
- return Object.freeze({
498
- sequence: event.sequence,
499
- origin: event.origin,
500
- type: 'overflow',
501
- kind: null,
502
- path,
503
- destinationPath: null,
504
- version: null,
505
- previousVersion: null,
506
- });
507
- }
508
- if (!isEntryWatchType(event.type)) throw new TypeError('Unknown filesystem watch event type.');
509
- if (event.kind !== 'file' && event.kind !== 'directory') {
510
- throw new TypeError('Unknown filesystem watch entry kind.');
511
- }
512
- const destinationPath =
513
- event.destinationPath === null
514
- ? null
515
- : typeof event.destinationPath === 'string'
516
- ? parseWorkspacePath(event.destinationPath)
517
- : (() => {
518
- throw new TypeError('Watch destination path must be a string or null.');
519
- })();
520
- if ((event.type === 'moved') !== (destinationPath !== null)) {
521
- throw new TypeError('Only moved watch events may have a destination path.');
522
- }
523
- return Object.freeze({
524
- sequence: event.sequence,
525
- origin: event.origin,
526
- type: event.type,
527
- kind: event.kind,
528
- path,
529
- destinationPath,
530
- version: event.version === null ? null : parseFileSystemVersion(event.version),
531
- previousVersion:
532
- event.previousVersion === null ? null : parseFileSystemVersion(event.previousVersion),
533
- });
534
- }
535
-
536
- function normalizeRemoveResult(value: FileSystemRemoveResult): FileSystemRemoveResult {
537
- if (!isRecord(value) || typeof value.removed !== 'boolean') {
538
- throw new TypeError('Filesystem transport returned an invalid remove result.');
539
- }
540
- return Object.freeze({ removed: value.removed, version: parseFileSystemVersion(value.version) });
541
- }
542
-
543
- function assertCapabilities(value: FileSystemProviderCapabilities, operation: FsOperation): void {
544
- if (!isRecord(value)) {
545
- throw invalidTransport(operation, 'Filesystem host returned invalid capabilities.');
546
- }
547
- for (const key of Object.keys(ELECTRON_FILE_SYSTEM_V2_CAPABILITIES) as Array<
548
- keyof FileSystemProviderCapabilities
549
- >) {
550
- if (value[key] !== ELECTRON_FILE_SYSTEM_V2_CAPABILITIES[key]) {
551
- throw invalidTransport(operation, `Filesystem host capability mismatch: ${key}.`);
552
- }
553
- }
554
- }
555
-
556
- function compareDirectoryEntries(
557
- left: FileSystemEntrySnapshot,
558
- right: FileSystemEntrySnapshot,
559
- ): number {
560
- if (left.kind !== right.kind) return left.kind === 'directory' ? -1 : 1;
561
- return compareText(left.path, right.path);
562
- }
563
-
564
- function compareText(left: string, right: string): number {
565
- return left < right ? -1 : left > right ? 1 : 0;
566
- }
567
-
568
- function isWatchOrigin(value: unknown): value is FileSystemWatchEvent['origin'] {
569
- return value === 'local' || value === 'external' || value === 'unknown';
570
- }
571
-
572
- function isEntryWatchType(
573
- value: unknown,
574
- ): value is Exclude<FileSystemWatchEvent['type'], 'overflow'> {
575
- return value === 'created' || value === 'modified' || value === 'removed' || value === 'moved';
576
- }
577
-
578
- function isNonNegativeSafeInteger(value: unknown): value is number {
579
- return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
580
- }
581
-
582
- function isPositiveSafeInteger(value: unknown): value is number {
583
- return isNonNegativeSafeInteger(value) && value > 0;
584
- }
585
-
586
- function isRecord(value: unknown): value is Record<string, unknown> {
587
- return typeof value === 'object' && value !== null;
588
- }
589
-
590
- function invalidTransport(operation: FsOperation, message: string): FsError {
591
- return new FsError('io', message, { operation, retryable: false });
592
- }
593
-
594
- function transportErrorFromUnknown(error: unknown, operation: FsOperation): FsError {
595
- if (error instanceof TypeError) return invalidTransport(operation, error.message);
596
- return withOperation(fsErrorFromUnknown(error, { operation }), operation);
597
- }
598
-
599
- function withOperation(error: FsError, operation: FsOperation): FsError {
600
- if (error.operation === operation) return error;
601
- return new FsError(error.code, error.message, {
602
- operation,
603
- path: error.path ?? undefined,
604
- destinationPath: error.destinationPath ?? undefined,
605
- retryable: error.retryable,
606
- });
607
- }
608
-
609
- function copyBytes(data: ArrayBuffer | Uint8Array): ArrayBuffer {
610
- const source = ArrayBuffer.isView(data)
611
- ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
612
- : new Uint8Array(data);
613
- const copy = new Uint8Array(source.byteLength);
614
- copy.set(source);
615
- return copy.buffer as ArrayBuffer;
616
- }
617
-
618
- function copyWireBuffer(data: ArrayBuffer): ArrayBuffer {
619
- if (Object.prototype.toString.call(data) !== '[object ArrayBuffer]') {
620
- throw new TypeError('Expected an ArrayBuffer from the filesystem transport.');
621
- }
622
- return data.slice(0);
623
- }
624
-
625
- function createInstanceId(): string {
626
- const randomUUID = globalThis.crypto?.randomUUID;
627
- if (typeof randomUUID === 'function') return randomUUID.call(globalThis.crypto);
628
- fallbackInstanceSequence += 1;
629
- return `electron-fs-v2-${Date.now()}-${fallbackInstanceSequence}`;
630
- }