@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,849 +0,0 @@
1
- import { withFileCommitLock } from './commit-lock.js';
2
- import { FsError, fsErrorFromUnknown } from './fs-error.js';
3
- import { parseFileSystemVersion, } from './v2.js';
4
- import { WORKSPACE_ROOT, parseWorkspacePath, workspacePathBasename, workspacePathContains, workspacePathDirname, workspacePathJoin, } from './workspace-path.js';
5
- /**
6
- * A copy/delete move failed and the provider could not prove that rollback
7
- * restored the source-only state. Callers must inspect `state` before retrying.
8
- */
9
- export class NativeFileSystemMoveRecoveryError extends FsError {
10
- constructor(sourcePath, destinationPath, primaryError, recoveryErrors, state) {
11
- super('io', `Native move recovery is incomplete (source: ${state.source}, destination: ${state.destination}).`, {
12
- operation: 'move',
13
- path: sourcePath,
14
- destinationPath,
15
- retryable: false,
16
- });
17
- this.name = 'NativeFileSystemMoveRecoveryError';
18
- this.primaryError = primaryError;
19
- this.recoveryErrors = Object.freeze([...recoveryErrors]);
20
- this.state = Object.freeze({ ...state });
21
- }
22
- }
23
- const EPOCH = new Date(0).toISOString();
24
- const NATIVE_V2_CAPABILITIES = Object.freeze({
25
- writeAtomicity: 'none',
26
- moveAtomicity: 'none',
27
- snapshotAtomicity: 'none',
28
- conditionalWrite: 'process',
29
- recursiveRemove: true,
30
- watch: false,
31
- caseSensitivity: 'platform',
32
- symlinkPolicy: 'unsupported',
33
- durability: 'best-effort',
34
- });
35
- /** Direct File System Access API implementation of FileSystemProviderV2. */
36
- export class NativeFileSystemProviderV2 {
37
- constructor(id, root) {
38
- this.capabilities = NATIVE_V2_CAPABILITIES;
39
- this.subscriptions = new Set();
40
- this.inFlight = new Set();
41
- this.disposed = false;
42
- this.disposePromise = null;
43
- this.id = id;
44
- this.label = root.name;
45
- this.root = root;
46
- this.lockKey = `native:${id}:workspace`;
47
- }
48
- async stat(path) {
49
- const canonical = this.canonical(path);
50
- return this.execute('stat', canonical, null, async () => {
51
- const scanned = await this.tryScanMetadata(canonical, 'stat');
52
- return scanned ? withoutData(scanned.root) : null;
53
- });
54
- }
55
- async readFile(path) {
56
- const canonical = this.canonical(path);
57
- return this.execute('read', canonical, null, async () => {
58
- const handle = await this.getHandle(canonical);
59
- if (!handle)
60
- return null;
61
- if (handle.kind !== 'file') {
62
- throw this.error('type-mismatch', 'read', canonical, 'Expected a file, found a directory.');
63
- }
64
- const scanned = await this.scanSnapshotHandle(canonical, handle, 'read');
65
- if (scanned.root.kind !== 'file') {
66
- throw this.error('io', 'read', canonical, 'Native file handle changed kind during read.');
67
- }
68
- return Object.freeze({
69
- entry: withoutData(scanned.root),
70
- data: scanned.root.data.slice(0),
71
- });
72
- });
73
- }
74
- async readDirectory(path) {
75
- const canonical = this.canonical(path);
76
- return this.execute('list', canonical, null, async () => {
77
- const handle = await this.getHandle(canonical);
78
- if (!handle)
79
- throw this.error('not-found', 'list', canonical, 'Directory does not exist.');
80
- if (handle.kind !== 'directory') {
81
- throw this.error('type-mismatch', 'list', canonical, 'Expected a directory, found a file.');
82
- }
83
- const children = [];
84
- for (const [name, childHandle] of await listDirectory(handle, 'list', canonical)) {
85
- const childPath = workspacePathJoin(canonical, name);
86
- children.push(withoutData((await this.scanMetadataHandle(childPath, childHandle, 'list')).root));
87
- }
88
- children.sort(compareSnapshots);
89
- return Object.freeze(children);
90
- });
91
- }
92
- async writeFile(path, data, options = {}) {
93
- const canonical = this.canonicalNonRoot(path, 'write');
94
- const ownedData = copyBytes(data);
95
- return this.mutate('write', canonical, null, async () => {
96
- const mode = options.mode ?? 'upsert';
97
- if (mode !== 'upsert' && mode !== 'create' && mode !== 'replace') {
98
- throw this.error('invalid-path', 'write', canonical, 'Invalid write mode.');
99
- }
100
- const existing = await this.tryScanMetadata(canonical, 'write');
101
- if (existing?.root.kind === 'directory') {
102
- throw this.error('type-mismatch', 'write', canonical, 'Cannot replace a directory with a file.');
103
- }
104
- if (mode === 'create' && existing) {
105
- throw this.error('already-exists', 'write', canonical, 'File already exists.');
106
- }
107
- if (mode === 'replace' && !existing) {
108
- throw this.error('not-found', 'write', canonical, 'File does not exist.');
109
- }
110
- this.assertExpectedVersion(existing?.root, options.expectedVersion, 'write', canonical);
111
- const missingParents = await this.planParents(canonical, options.createParents ?? false, 'write');
112
- const createdParents = await this.createDirectories(missingParents);
113
- let writeCompleted = false;
114
- try {
115
- await this.writeBytes(canonical, ownedData);
116
- writeCompleted = true;
117
- const written = await this.requireSnapshot(canonical, 'write');
118
- if (written.root.kind !== 'file' || !equalBytes(written.root.data, ownedData)) {
119
- throw this.error('conflict', 'write', canonical, 'Stored bytes changed before the write could be verified.');
120
- }
121
- return withoutData(written.root);
122
- }
123
- catch (error) {
124
- if (!existing && !writeCompleted) {
125
- await this.removeEmptyFileIfPresent(canonical).catch(() => undefined);
126
- }
127
- await this.rollbackDirectories(createdParents);
128
- throw error;
129
- }
130
- });
131
- }
132
- async createDirectory(path, options = {}) {
133
- const canonical = this.canonical(path);
134
- return this.mutate('create-directory', canonical, null, async () => {
135
- const mode = options.mode ?? 'ensure';
136
- if (mode !== 'ensure' && mode !== 'create') {
137
- throw this.error('invalid-path', 'create-directory', canonical, 'Invalid directory mode.');
138
- }
139
- const existing = await this.tryScanMetadata(canonical, 'create-directory');
140
- if (existing) {
141
- if (existing.root.kind !== 'directory') {
142
- throw this.error('type-mismatch', 'create-directory', canonical, 'Cannot replace a file with a directory.');
143
- }
144
- if (mode === 'create') {
145
- throw this.error('already-exists', 'create-directory', canonical, 'Directory already exists.');
146
- }
147
- return withoutData(existing.root);
148
- }
149
- const missingParents = await this.planParents(canonical, options.createParents ?? false, 'create-directory');
150
- const planned = [...missingParents, canonical];
151
- const created = await this.createDirectories(planned);
152
- try {
153
- const scanned = await this.requireMetadata(canonical, 'create-directory');
154
- if (scanned.root.kind !== 'directory') {
155
- throw this.error('io', 'create-directory', canonical, 'The native backend did not create a directory.');
156
- }
157
- return withoutData(scanned.root);
158
- }
159
- catch (error) {
160
- await this.rollbackDirectories(created);
161
- throw error;
162
- }
163
- });
164
- }
165
- async remove(path, options = {}) {
166
- const canonical = this.canonicalNonRoot(path, 'remove');
167
- return this.mutate('remove', canonical, null, async () => {
168
- const existing = await this.tryScanMetadata(canonical, 'remove');
169
- if (!existing) {
170
- if ((options.missing ?? 'error') === 'ignore') {
171
- return Object.freeze({
172
- removed: false,
173
- version: await this.currentTreeVersion('remove'),
174
- });
175
- }
176
- throw this.error('not-found', 'remove', canonical, 'Entry does not exist.');
177
- }
178
- this.assertExpectedVersion(existing.root, options.expectedVersion, 'remove', canonical);
179
- if (existing.root.kind === 'directory' && !options.recursive) {
180
- const handle = await this.getHandle(canonical);
181
- if (!handle || handle.kind !== 'directory') {
182
- throw this.error('conflict', 'remove', canonical, 'Directory changed before removal.');
183
- }
184
- if ((await listDirectory(handle, 'remove', canonical)).length > 0) {
185
- throw this.error('not-empty', 'remove', canonical, 'Directory is not empty.');
186
- }
187
- }
188
- await this.removeEntry(canonical, existing.root.kind === 'directory' && !!options.recursive);
189
- if (await this.getHandle(canonical)) {
190
- throw this.error('conflict', 'remove', canonical, 'Entry was recreated during removal.');
191
- }
192
- return Object.freeze({
193
- removed: true,
194
- version: await this.currentTreeVersion('remove'),
195
- });
196
- });
197
- }
198
- async move(oldPath, newPath, options = {}) {
199
- const sourcePath = this.canonicalNonRoot(oldPath, 'move');
200
- const destinationPath = this.canonicalNonRoot(newPath, 'move');
201
- return this.mutate('move', sourcePath, destinationPath, async () => {
202
- const sourceMetadata = await this.tryScanMetadata(sourcePath, 'move');
203
- if (!sourceMetadata) {
204
- throw this.error('not-found', 'move', sourcePath, 'Source does not exist.');
205
- }
206
- this.assertExpectedVersion(sourceMetadata.root, options.expectedVersion, 'move', sourcePath);
207
- if (sourcePath === destinationPath)
208
- return withoutData(sourceMetadata.root);
209
- if (sourceMetadata.root.kind === 'directory' &&
210
- workspacePathContains(sourcePath, destinationPath, false)) {
211
- throw new FsError('invalid-path', 'Cannot move a directory into itself.', {
212
- operation: 'move',
213
- path: sourcePath,
214
- destinationPath,
215
- });
216
- }
217
- if (await this.getHandle(destinationPath)) {
218
- throw new FsError('already-exists', 'Destination already exists.', {
219
- operation: 'move',
220
- path: sourcePath,
221
- destinationPath,
222
- });
223
- }
224
- const missingParents = await this.planParents(destinationPath, options.createParents ?? false, 'move');
225
- const source = await this.tryScanSnapshot(sourcePath, 'move');
226
- if (!source ||
227
- source.root.kind !== sourceMetadata.root.kind ||
228
- source.root.version !== sourceMetadata.root.version) {
229
- throw new FsError('conflict', 'Source changed before the move could be copied.', {
230
- operation: 'move',
231
- path: sourcePath,
232
- destinationPath,
233
- });
234
- }
235
- const createdParents = await this.createDirectories(missingParents);
236
- let destinationVersion = null;
237
- let sourceDeleted = false;
238
- try {
239
- await this.writeTree(source, sourcePath, destinationPath);
240
- const copied = await this.requireSnapshot(destinationPath, 'move');
241
- destinationVersion = copied.root.version;
242
- if (!equalTreeContents(source, sourcePath, copied, destinationPath)) {
243
- throw new FsError('conflict', 'Destination changed while the move was copied.', {
244
- operation: 'move',
245
- path: sourcePath,
246
- destinationPath,
247
- });
248
- }
249
- const sourceBeforeDelete = await this.tryScanMetadata(sourcePath, 'move');
250
- if (!sourceBeforeDelete ||
251
- sourceBeforeDelete.root.kind !== source.root.kind ||
252
- sourceBeforeDelete.root.version !== source.root.version) {
253
- throw new FsError('conflict', 'Source changed while the move was copied.', {
254
- operation: 'move',
255
- path: sourcePath,
256
- destinationPath,
257
- });
258
- }
259
- await this.removeEntry(sourcePath, source.root.kind === 'directory');
260
- sourceDeleted = true;
261
- const [sourceAfter, destinationAfter] = await Promise.all([
262
- this.tryScanMetadata(sourcePath, 'move'),
263
- this.tryScanMetadata(destinationPath, 'move'),
264
- ]);
265
- if (sourceAfter ||
266
- !destinationAfter ||
267
- destinationAfter.root.kind !== source.root.kind ||
268
- destinationAfter.root.version !== destinationVersion) {
269
- throw new FsError('conflict', 'Move state changed before it could be verified.', {
270
- operation: 'move',
271
- path: sourcePath,
272
- destinationPath,
273
- });
274
- }
275
- return withoutData(destinationAfter.root);
276
- }
277
- catch (error) {
278
- return await this.rollbackMoveAndThrow(sourcePath, destinationPath, source, createdParents, destinationVersion, sourceDeleted, error);
279
- }
280
- });
281
- }
282
- async snapshot() {
283
- return this.mutate('snapshot', WORKSPACE_ROOT, null, async () => {
284
- const scanned = await this.scanSnapshotHandle(WORKSPACE_ROOT, this.root, 'snapshot');
285
- const entries = [...scanned.entries]
286
- .sort((left, right) => compareText(left.path, right.path))
287
- .map(copySnapshotEntry);
288
- return Object.freeze({ version: scanned.root.version, entries: Object.freeze(entries) });
289
- });
290
- }
291
- watch(_listener, options = {}) {
292
- this.assertOpen('watch');
293
- const error = new FsError('not-supported', 'Native filesystem watching is unavailable.', {
294
- operation: 'watch',
295
- });
296
- let closed = false;
297
- let disposePromise = null;
298
- const ready = Promise.reject(error);
299
- void ready.catch((caught) => {
300
- try {
301
- options.onError?.(caught);
302
- }
303
- catch {
304
- // Observers cannot change provider state.
305
- }
306
- });
307
- const subscription = {
308
- get closed() {
309
- return closed;
310
- },
311
- ready,
312
- dispose: () => {
313
- if (disposePromise)
314
- return disposePromise;
315
- closed = true;
316
- this.subscriptions.delete(subscription);
317
- disposePromise = Promise.resolve();
318
- return disposePromise;
319
- },
320
- };
321
- this.subscriptions.add(subscription);
322
- return subscription;
323
- }
324
- dispose() {
325
- if (this.disposePromise)
326
- return this.disposePromise;
327
- this.disposed = true;
328
- this.disposePromise = (async () => {
329
- await Promise.allSettled([...this.inFlight]);
330
- await Promise.all([...this.subscriptions].map((subscription) => subscription.dispose()));
331
- })();
332
- return this.disposePromise;
333
- }
334
- canonical(path) {
335
- return parseWorkspacePath(String(path));
336
- }
337
- canonicalNonRoot(path, operation) {
338
- const canonical = this.canonical(path);
339
- if (!canonical) {
340
- throw this.error('invalid-path', operation, canonical, 'Workspace root cannot be mutated.');
341
- }
342
- return canonical;
343
- }
344
- execute(operation, path, destinationPath, work) {
345
- this.assertOpen(operation);
346
- const promise = (async () => {
347
- try {
348
- return await work();
349
- }
350
- catch (error) {
351
- throw this.translateError(error, operation, path, destinationPath);
352
- }
353
- })();
354
- this.inFlight.add(promise);
355
- void promise.then(() => this.inFlight.delete(promise), () => this.inFlight.delete(promise));
356
- return promise;
357
- }
358
- mutate(operation, path, destinationPath, work) {
359
- return this.execute(operation, path, destinationPath, () => withFileCommitLock(this.lockKey, work));
360
- }
361
- assertOpen(operation) {
362
- if (!this.disposed)
363
- return;
364
- throw new FsError('disposed', 'Filesystem provider is disposed.', { operation });
365
- }
366
- translateError(error, operation, path, destinationPath) {
367
- if (error instanceof FsError)
368
- return error;
369
- return fsErrorFromUnknown(error, {
370
- operation,
371
- path: path ?? undefined,
372
- destinationPath: destinationPath ?? undefined,
373
- });
374
- }
375
- error(code, operation, path, message) {
376
- return new FsError(code, message, { operation, path });
377
- }
378
- assertExpectedVersion(entry, expected, operation, path) {
379
- if (expected === undefined)
380
- return;
381
- if (expected === null ? !entry : entry?.version === expected)
382
- return;
383
- throw this.error('conflict', operation, path, 'Entry version does not match the expected version.');
384
- }
385
- async resolveDirectory(path) {
386
- if (!path)
387
- return this.root;
388
- let current = this.root;
389
- for (const segment of path.split('/')) {
390
- try {
391
- current = await current.getDirectoryHandle(segment);
392
- }
393
- catch (error) {
394
- if (errorName(error) === 'NotFoundError')
395
- return null;
396
- throw error;
397
- }
398
- }
399
- return current;
400
- }
401
- async getHandle(path) {
402
- if (!path)
403
- return this.root;
404
- const parent = await this.resolveDirectory(workspacePathDirname(path));
405
- if (!parent)
406
- return null;
407
- const name = workspacePathBasename(path);
408
- try {
409
- return await parent.getFileHandle(name);
410
- }
411
- catch (error) {
412
- if (!isMissingOrKindError(error))
413
- throw error;
414
- }
415
- try {
416
- return await parent.getDirectoryHandle(name);
417
- }
418
- catch (error) {
419
- if (!isMissingOrKindError(error))
420
- throw error;
421
- return null;
422
- }
423
- }
424
- async tryScanMetadata(path, operation) {
425
- const handle = await this.getHandle(path);
426
- return handle ? this.scanMetadataHandle(path, handle, operation) : null;
427
- }
428
- async tryScanSnapshot(path, operation) {
429
- const handle = await this.getHandle(path);
430
- return handle ? this.scanSnapshotHandle(path, handle, operation) : null;
431
- }
432
- async requireMetadata(path, operation) {
433
- const scanned = await this.tryScanMetadata(path, operation);
434
- if (!scanned)
435
- throw this.error('not-found', operation, path, 'Entry does not exist.');
436
- return scanned;
437
- }
438
- async requireSnapshot(path, operation) {
439
- const scanned = await this.tryScanSnapshot(path, operation);
440
- if (!scanned)
441
- throw this.error('not-found', operation, path, 'Entry does not exist.');
442
- return scanned;
443
- }
444
- scanMetadataHandle(path, handle, operation) {
445
- // File snapshots expose stable size/lastModified metadata without reading payload bytes.
446
- // Keep stat/list/version checks on this path so directory scans scale with entries, not bytes.
447
- return this.scanHandle(path, handle, operation, (filePath, fileHandle) => this.scanFileMetadata(filePath, fileHandle, operation));
448
- }
449
- scanSnapshotHandle(path, handle, operation) {
450
- return this.scanHandle(path, handle, operation, (filePath, fileHandle) => this.scanFileSnapshot(filePath, fileHandle, operation));
451
- }
452
- async scanHandle(path, handle, operation, scanFile) {
453
- if (handle.kind === 'file') {
454
- const entry = await scanFile(path, handle);
455
- return { root: entry, entries: Object.freeze([entry]) };
456
- }
457
- const children = [];
458
- for (const [name, childHandle] of await listDirectory(handle, operation, path)) {
459
- children.push(await this.scanHandle(workspacePathJoin(path, name), childHandle, operation, scanFile));
460
- }
461
- const childRoots = children.map((child) => child.root).sort(compareSnapshots);
462
- const version = await metadataVersion('directory', new TextEncoder().encode(childRoots
463
- .map((child) => `${child.kind}\0${child.name.length}:${child.name}\0${child.version}`)
464
- .join('\n')), operation, path);
465
- const directory = Object.freeze({
466
- kind: 'directory',
467
- path,
468
- name: workspacePathBasename(path),
469
- size: null,
470
- version,
471
- lastModified: newestLastModified(childRoots),
472
- });
473
- return {
474
- root: directory,
475
- entries: Object.freeze([directory, ...children.flatMap((child) => child.entries)]),
476
- };
477
- }
478
- async scanFileMetadata(path, handle, operation) {
479
- const file = await this.getFileSnapshot(handle, path, operation);
480
- return this.fileMetadata(file, path, operation);
481
- }
482
- async scanFileSnapshot(path, handle, operation) {
483
- const file = await this.getFileSnapshot(handle, path, operation);
484
- const metadata = await this.fileMetadata(file, path, operation);
485
- let data;
486
- try {
487
- data = copyBytes(await file.arrayBuffer());
488
- }
489
- catch (error) {
490
- throw this.translateError(error, operation, path, null);
491
- }
492
- if (metadata.size !== data.byteLength) {
493
- throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
494
- }
495
- return Object.freeze({ ...metadata, data });
496
- }
497
- async getFileSnapshot(handle, path, operation) {
498
- try {
499
- return await handle.getFile();
500
- }
501
- catch (error) {
502
- throw this.translateError(error, operation, path, null);
503
- }
504
- }
505
- async fileMetadata(file, path, operation) {
506
- if (!Number.isSafeInteger(file.size) || file.size < 0 || !Number.isFinite(file.lastModified)) {
507
- throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
508
- }
509
- let lastModified;
510
- try {
511
- lastModified = new Date(file.lastModified).toISOString();
512
- }
513
- catch {
514
- throw this.error('io', operation, path, 'Native file metadata is inconsistent.');
515
- }
516
- return Object.freeze({
517
- kind: 'file',
518
- path,
519
- name: workspacePathBasename(path),
520
- size: file.size,
521
- version: await metadataVersion('file', new TextEncoder().encode(`${file.size}\0${file.lastModified}`), operation, path),
522
- lastModified,
523
- });
524
- }
525
- async planParents(path, createParents, operation) {
526
- const missing = [];
527
- for (const parent of parentChain(path)) {
528
- const handle = await this.getHandle(parent);
529
- if (handle?.kind === 'file') {
530
- throw this.error('type-mismatch', operation, parent, 'A parent path is a file.');
531
- }
532
- if (!handle) {
533
- if (!createParents) {
534
- throw this.error('not-found', operation, parent, 'Parent directory does not exist.');
535
- }
536
- missing.push(parent);
537
- }
538
- }
539
- return missing;
540
- }
541
- async createDirectories(paths) {
542
- const created = [];
543
- try {
544
- for (const path of paths) {
545
- if (!path)
546
- continue;
547
- const parent = await this.resolveDirectory(workspacePathDirname(path));
548
- if (!parent) {
549
- throw new DOMException('Parent directory does not exist.', 'NotFoundError');
550
- }
551
- await parent.getDirectoryHandle(workspacePathBasename(path), { create: true });
552
- created.push(path);
553
- }
554
- return created;
555
- }
556
- catch (error) {
557
- await this.rollbackDirectories(created);
558
- throw error;
559
- }
560
- }
561
- async rollbackDirectories(paths) {
562
- for (const path of [...paths].reverse()) {
563
- try {
564
- await this.removeEntry(path, false);
565
- }
566
- catch {
567
- // Best effort: a non-empty directory may now contain external data.
568
- }
569
- }
570
- }
571
- async writeBytes(path, data) {
572
- const parent = await this.resolveDirectory(workspacePathDirname(path));
573
- if (!parent)
574
- throw new DOMException('Parent directory does not exist.', 'NotFoundError');
575
- const fileHandle = await parent.getFileHandle(workspacePathBasename(path), { create: true });
576
- const writable = await fileHandle.createWritable();
577
- await writeAndClose(writable, data);
578
- }
579
- async removeEntry(path, recursive) {
580
- const parent = await this.resolveDirectory(workspacePathDirname(path));
581
- if (!parent)
582
- throw new DOMException('Parent directory does not exist.', 'NotFoundError');
583
- await parent.removeEntry(workspacePathBasename(path), { recursive });
584
- }
585
- async removeEmptyFileIfPresent(path) {
586
- const current = await this.tryScanMetadata(path, 'write');
587
- if (current?.root.kind !== 'file' || current.root.size !== 0)
588
- return;
589
- await this.removeEntry(path, false);
590
- }
591
- async currentTreeVersion(operation) {
592
- return (await this.scanMetadataHandle(WORKSPACE_ROOT, this.root, operation)).root.version;
593
- }
594
- async writeTree(source, sourcePath, destinationPath) {
595
- const remapped = source.entries.map((entry) => {
596
- const suffix = entry.path.slice(sourcePath.length);
597
- return [entry, parseWorkspacePath(`${destinationPath}${suffix}`)];
598
- });
599
- const directories = remapped
600
- .filter((item) => item[0].kind === 'directory')
601
- .sort((left, right) => pathDepth(left[1]) - pathDepth(right[1]));
602
- for (const [, path] of directories) {
603
- const parent = await this.resolveDirectory(workspacePathDirname(path));
604
- if (!parent)
605
- throw new DOMException('Parent directory does not exist.', 'NotFoundError');
606
- await parent.getDirectoryHandle(workspacePathBasename(path), { create: true });
607
- }
608
- for (const [entry, path] of remapped) {
609
- if (entry.kind === 'file')
610
- await this.writeBytes(path, entry.data);
611
- }
612
- }
613
- async rollbackMoveAndThrow(sourcePath, destinationPath, source, createdParents, destinationVersion, sourceDeleted, primary) {
614
- const primaryError = this.translateError(primary, 'move', sourcePath, destinationPath);
615
- const recoveryErrors = [];
616
- const sourceCurrent = await this.probeScan(sourcePath);
617
- if (sourceCurrent === null && sourceDeleted) {
618
- try {
619
- await this.writeTree(source, sourcePath, sourcePath);
620
- const restored = await this.probeSnapshot(sourcePath);
621
- if (!restored || !equalTreeContents(source, sourcePath, restored, sourcePath)) {
622
- throw new FsError('conflict', 'Restored source does not match its captured state.', {
623
- operation: 'move',
624
- path: sourcePath,
625
- destinationPath,
626
- });
627
- }
628
- }
629
- catch (error) {
630
- recoveryErrors.push(this.translateError(error, 'move', sourcePath, destinationPath));
631
- }
632
- }
633
- const destinationCurrent = await this.probeScan(destinationPath);
634
- if (destinationCurrent) {
635
- if (destinationVersion && destinationCurrent.root.version !== destinationVersion) {
636
- recoveryErrors.push(new FsError('conflict', 'Destination changed; rollback will not delete it.', {
637
- operation: 'move',
638
- path: sourcePath,
639
- destinationPath,
640
- }));
641
- }
642
- else {
643
- try {
644
- await this.removeEntry(destinationPath, destinationCurrent.root.kind === 'directory');
645
- }
646
- catch (error) {
647
- recoveryErrors.push(this.translateError(error, 'move', sourcePath, destinationPath));
648
- }
649
- }
650
- }
651
- await this.rollbackDirectories(createdParents);
652
- const state = {
653
- source: await this.probePresence(sourcePath),
654
- destination: await this.probePresence(destinationPath),
655
- };
656
- if (recoveryErrors.length === 0 &&
657
- state.source === 'present' &&
658
- state.destination === 'missing') {
659
- throw primaryError;
660
- }
661
- throw new NativeFileSystemMoveRecoveryError(sourcePath, destinationPath, primaryError, recoveryErrors, state);
662
- }
663
- async probeScan(path) {
664
- try {
665
- return await this.tryScanMetadata(path, 'move');
666
- }
667
- catch {
668
- return undefined;
669
- }
670
- }
671
- async probeSnapshot(path) {
672
- try {
673
- return await this.tryScanSnapshot(path, 'move');
674
- }
675
- catch {
676
- return undefined;
677
- }
678
- }
679
- async probePresence(path) {
680
- try {
681
- return (await this.getHandle(path)) ? 'present' : 'missing';
682
- }
683
- catch {
684
- return 'unknown';
685
- }
686
- }
687
- }
688
- async function listDirectory(directory, operation, path) {
689
- const entries = [];
690
- try {
691
- for await (const entry of directory) {
692
- const [name, handle] = entry;
693
- if (typeof name !== 'string' ||
694
- !handle ||
695
- (handle.kind !== 'file' && handle.kind !== 'directory')) {
696
- throw new FsError('io', 'Native directory returned an invalid entry.', {
697
- operation,
698
- path,
699
- });
700
- }
701
- entries.push([name, handle]);
702
- }
703
- }
704
- catch (error) {
705
- throw fsErrorFromUnknown(error, { operation, path });
706
- }
707
- entries.sort(([left], [right]) => compareText(left, right));
708
- return entries;
709
- }
710
- async function writeAndClose(writable, data) {
711
- try {
712
- await writable.write(data);
713
- await writable.close();
714
- }
715
- catch (error) {
716
- await writable.abort(error).catch(() => undefined);
717
- throw error;
718
- }
719
- }
720
- async function metadataVersion(kind, metadata, operation, path) {
721
- const prefix = new TextEncoder().encode(`${kind}\0`);
722
- const input = new Uint8Array(prefix.byteLength + metadata.byteLength);
723
- input.set(prefix);
724
- input.set(metadata, prefix.byteLength);
725
- let digest;
726
- try {
727
- digest = await globalThis.crypto.subtle.digest('SHA-256', input.buffer);
728
- }
729
- catch (error) {
730
- throw fsErrorFromUnknown(error, {
731
- operation,
732
- path,
733
- defaultCode: 'not-supported',
734
- });
735
- }
736
- const hex = [...new Uint8Array(digest)]
737
- .map((value) => value.toString(16).padStart(2, '0'))
738
- .join('');
739
- return parseFileSystemVersion(`sha256:${hex}`);
740
- }
741
- function parentChain(path) {
742
- const parents = [];
743
- let current = workspacePathDirname(path);
744
- while (current) {
745
- parents.unshift(current);
746
- current = workspacePathDirname(current);
747
- }
748
- return parents;
749
- }
750
- function pathDepth(path) {
751
- return path ? path.split('/').length : 0;
752
- }
753
- function errorName(error) {
754
- if (!error || typeof error !== 'object')
755
- return null;
756
- const name = error.name;
757
- return typeof name === 'string' ? name : null;
758
- }
759
- function isMissingOrKindError(error) {
760
- const name = errorName(error);
761
- return name === 'NotFoundError' || name === 'TypeMismatchError';
762
- }
763
- function copyBytes(data) {
764
- const source = ArrayBuffer.isView(data)
765
- ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
766
- : new Uint8Array(data);
767
- const copy = new Uint8Array(source.byteLength);
768
- copy.set(source);
769
- return copy.buffer;
770
- }
771
- function equalBytes(left, right) {
772
- const leftBytes = new Uint8Array(left);
773
- const rightBytes = new Uint8Array(right);
774
- return (leftBytes.byteLength === rightBytes.byteLength &&
775
- leftBytes.every((value, index) => value === rightBytes[index]));
776
- }
777
- function equalTreeContents(left, leftRoot, right, rightRoot) {
778
- if (left.entries.length !== right.entries.length)
779
- return false;
780
- const rightByRelativePath = new Map();
781
- for (const entry of right.entries) {
782
- const relativePath = treeRelativePath(rightRoot, entry.path);
783
- if (relativePath === null || rightByRelativePath.has(relativePath))
784
- return false;
785
- rightByRelativePath.set(relativePath, entry);
786
- }
787
- for (const entry of left.entries) {
788
- const relativePath = treeRelativePath(leftRoot, entry.path);
789
- if (relativePath === null)
790
- return false;
791
- const counterpart = rightByRelativePath.get(relativePath);
792
- if (!counterpart || counterpart.kind !== entry.kind)
793
- return false;
794
- if (entry.kind === 'file') {
795
- if (counterpart.kind !== 'file' || !equalBytes(entry.data, counterpart.data))
796
- return false;
797
- }
798
- }
799
- return true;
800
- }
801
- function treeRelativePath(root, path) {
802
- if (path === root)
803
- return '';
804
- const prefix = root ? `${root}/` : '';
805
- return path.startsWith(prefix) ? path.slice(prefix.length) : null;
806
- }
807
- function withoutData(entry) {
808
- if (entry.kind === 'directory')
809
- return Object.freeze({ ...entry });
810
- return Object.freeze({
811
- kind: 'file',
812
- path: entry.path,
813
- name: entry.name,
814
- size: entry.size,
815
- version: entry.version,
816
- lastModified: entry.lastModified,
817
- });
818
- }
819
- function copySnapshotEntry(entry) {
820
- if (entry.kind === 'directory')
821
- return Object.freeze({ ...entry });
822
- return Object.freeze({
823
- kind: 'file',
824
- path: entry.path,
825
- name: entry.name,
826
- size: entry.size,
827
- version: entry.version,
828
- lastModified: entry.lastModified,
829
- data: entry.data.slice(0),
830
- });
831
- }
832
- function newestLastModified(children) {
833
- let newest = 0;
834
- for (const child of children) {
835
- const timestamp = Date.parse(child.lastModified);
836
- if (Number.isFinite(timestamp))
837
- newest = Math.max(newest, timestamp);
838
- }
839
- return newest ? new Date(newest).toISOString() : EPOCH;
840
- }
841
- function compareSnapshots(left, right) {
842
- if (left.kind !== right.kind)
843
- return left.kind === 'directory' ? -1 : 1;
844
- return compareText(left.name, right.name);
845
- }
846
- function compareText(left, right) {
847
- return left < right ? -1 : left > right ? 1 : 0;
848
- }
849
- //# sourceMappingURL=native-provider-v2.js.map