@bendyline/docblocks 2.0.0 → 2.1.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.
- package/dist/{chunk-J32GU3F3.js → chunk-6IYMTYMQ.js} +249 -221
- package/dist/chunk-6IYMTYMQ.js.map +1 -0
- package/dist/{chunk-75UUF6C4.js → chunk-B56KWCSE.js} +2 -2
- package/dist/{chunk-RVQHY3XU.js → chunk-BNKV7MTO.js} +1 -1
- package/dist/{chunk-RVQHY3XU.js.map → chunk-BNKV7MTO.js.map} +1 -1
- package/dist/chunk-BXMF5YQJ.js +149 -0
- package/dist/chunk-BXMF5YQJ.js.map +1 -0
- package/dist/{chunk-PGR7LK6D.js → chunk-COYQXQK3.js} +14 -5
- package/dist/chunk-COYQXQK3.js.map +1 -0
- package/dist/{chunk-RQJRQF46.js → chunk-DN7A33LL.js} +42 -49
- package/dist/chunk-DN7A33LL.js.map +1 -0
- package/dist/chunk-FA7UNOXK.js +20 -0
- package/dist/chunk-FA7UNOXK.js.map +1 -0
- package/dist/chunk-GM5YXU4L.js +29 -0
- package/dist/chunk-GM5YXU4L.js.map +1 -0
- package/dist/{chunk-SI2LU2RP.js → chunk-JS6XFWQK.js} +2 -1
- package/dist/chunk-JS6XFWQK.js.map +1 -0
- package/dist/{chunk-EGNDADXB.js → chunk-MNSZ7EZN.js} +2 -2
- package/dist/chunk-P3DVZQ6S.js +228 -0
- package/dist/chunk-P3DVZQ6S.js.map +1 -0
- package/dist/chunk-P4WATND4.js +52 -0
- package/dist/chunk-P4WATND4.js.map +1 -0
- package/dist/chunk-RVPGQBWR.js +169 -0
- package/dist/chunk-RVPGQBWR.js.map +1 -0
- package/dist/chunk-U722UUFN.js +9 -0
- package/dist/chunk-U722UUFN.js.map +1 -0
- package/dist/{chunk-GCPBEMMH.js → chunk-VTCSF7VS.js} +11 -21
- package/dist/chunk-VTCSF7VS.js.map +1 -0
- package/dist/{chunk-2D7Y4IR3.js → chunk-WJKYY5QR.js} +123 -66
- package/dist/chunk-WJKYY5QR.js.map +1 -0
- package/dist/{chunk-5MYAICRE.js → chunk-XUML3MKV.js} +44 -56
- package/dist/chunk-XUML3MKV.js.map +1 -0
- package/dist/document/index.d.ts +358 -6
- package/dist/document/index.js +24 -3
- package/dist/document/index.js.map +1 -1
- package/dist/filesystem/electron.d.ts +73 -4
- package/dist/filesystem/electron.js +16 -3
- package/dist/filesystem/electron.js.map +1 -1
- package/dist/filesystem/index.d.ts +228 -22
- package/dist/filesystem/index.js +133 -19
- package/dist/filesystem/index.js.map +1 -1
- package/dist/filesystem/indexeddb.d.ts +284 -5
- package/dist/filesystem/indexeddb.js +22 -4
- package/dist/filesystem/indexeddb.js.map +1 -1
- package/dist/filesystem/memory.d.ts +152 -4
- package/dist/filesystem/memory.js +12 -3
- package/dist/filesystem/memory.js.map +1 -1
- package/dist/filesystem/native.d.ts +136 -4
- package/dist/filesystem/native.js +27 -3
- package/dist/filesystem/native.js.map +1 -1
- package/dist/host/index.d.ts +32 -9
- package/dist/host/index.js +26 -29
- package/dist/host/index.js.map +1 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.js +204 -9
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +33 -4
- package/dist/mcp/index.js +31 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/zod.d.ts +637 -635
- package/dist/mcp/zod.js +700 -884
- package/dist/mcp/zod.js.map +1 -1
- package/dist/share/index.d.ts +43 -0
- package/dist/share/index.js +13 -0
- package/dist/share/index.js.map +1 -0
- package/dist/{types-CsX6EN2t.d.ts → types-BEg5SQ1_.d.ts} +1 -1
- package/dist/{types-eOlt9J7n.d.ts → types-CueK0tvU.d.ts} +34 -11
- package/dist/vscode/index.d.ts +220 -3
- package/dist/vscode/index.js +382 -2
- package/dist/vscode/index.js.map +1 -1
- package/dist/workspace/index.d.ts +141 -4
- package/dist/workspace/index.js +28 -2
- package/dist/workspace/index.js.map +1 -1
- package/package.json +9 -5
- package/dist/chunk-2D7Y4IR3.js.map +0 -1
- package/dist/chunk-5MYAICRE.js.map +0 -1
- package/dist/chunk-AYZ4HN5M.js +0 -20
- package/dist/chunk-AYZ4HN5M.js.map +0 -1
- package/dist/chunk-GCPBEMMH.js.map +0 -1
- package/dist/chunk-J32GU3F3.js.map +0 -1
- package/dist/chunk-PGR7LK6D.js.map +0 -1
- package/dist/chunk-RQJRQF46.js.map +0 -1
- package/dist/chunk-SI2LU2RP.js.map +0 -1
- package/dist/chunk-W5UUUII5.js +0 -142
- package/dist/chunk-W5UUUII5.js.map +0 -1
- package/dist/document/document-session.d.ts +0 -127
- package/dist/document/document-session.d.ts.map +0 -1
- package/dist/document/document-session.js +0 -749
- package/dist/document/document-session.js.map +0 -1
- package/dist/document/filesystem-target.d.ts +0 -17
- package/dist/document/filesystem-target.d.ts.map +0 -1
- package/dist/document/filesystem-target.js +0 -70
- package/dist/document/filesystem-target.js.map +0 -1
- package/dist/document/index.d.ts.map +0 -1
- package/dist/document/recovery-journal.d.ts +0 -125
- package/dist/document/recovery-journal.d.ts.map +0 -1
- package/dist/document/recovery-journal.js +0 -385
- package/dist/document/recovery-journal.js.map +0 -1
- package/dist/document/types.d.ts +0 -89
- package/dist/document/types.d.ts.map +0 -1
- package/dist/document/types.js +0 -9
- package/dist/document/types.js.map +0 -1
- package/dist/filesystem/commit-lock.d.ts +0 -3
- package/dist/filesystem/commit-lock.d.ts.map +0 -1
- package/dist/filesystem/commit-lock.js +0 -20
- package/dist/filesystem/commit-lock.js.map +0 -1
- package/dist/filesystem/dbk-workspace.d.ts +0 -34
- package/dist/filesystem/dbk-workspace.d.ts.map +0 -1
- package/dist/filesystem/dbk-workspace.js +0 -85
- package/dist/filesystem/dbk-workspace.js.map +0 -1
- package/dist/filesystem/electron-provider-v2.d.ts +0 -36
- package/dist/filesystem/electron-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/electron-provider-v2.js +0 -503
- package/dist/filesystem/electron-provider-v2.js.map +0 -1
- package/dist/filesystem/electron-provider.d.ts +0 -35
- package/dist/filesystem/electron-provider.d.ts.map +0 -1
- package/dist/filesystem/electron-provider.js +0 -69
- package/dist/filesystem/electron-provider.js.map +0 -1
- package/dist/filesystem/electron.d.ts.map +0 -1
- package/dist/filesystem/file-media-provider.d.ts +0 -23
- package/dist/filesystem/file-media-provider.d.ts.map +0 -1
- package/dist/filesystem/file-media-provider.js +0 -85
- package/dist/filesystem/file-media-provider.js.map +0 -1
- package/dist/filesystem/filesystem-content-container.d.ts +0 -24
- package/dist/filesystem/filesystem-content-container.d.ts.map +0 -1
- package/dist/filesystem/filesystem-content-container.js +0 -153
- package/dist/filesystem/filesystem-content-container.js.map +0 -1
- package/dist/filesystem/fs-error.d.ts +0 -46
- package/dist/filesystem/fs-error.d.ts.map +0 -1
- package/dist/filesystem/fs-error.js +0 -170
- package/dist/filesystem/fs-error.js.map +0 -1
- package/dist/filesystem/index.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.d.ts +0 -22
- package/dist/filesystem/indexeddb-content-container.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.js +0 -100
- package/dist/filesystem/indexeddb-content-container.js.map +0 -1
- package/dist/filesystem/indexeddb-provider-v2.d.ts +0 -96
- package/dist/filesystem/indexeddb-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-provider-v2.js +0 -1241
- package/dist/filesystem/indexeddb-provider-v2.js.map +0 -1
- package/dist/filesystem/indexeddb-provider.d.ts +0 -39
- package/dist/filesystem/indexeddb-provider.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-provider.js +0 -145
- package/dist/filesystem/indexeddb-provider.js.map +0 -1
- package/dist/filesystem/indexeddb-store.d.ts +0 -34
- package/dist/filesystem/indexeddb-store.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-store.js +0 -165
- package/dist/filesystem/indexeddb-store.js.map +0 -1
- package/dist/filesystem/indexeddb.d.ts.map +0 -1
- package/dist/filesystem/legacy-v2-adapter.d.ts +0 -62
- package/dist/filesystem/legacy-v2-adapter.d.ts.map +0 -1
- package/dist/filesystem/legacy-v2-adapter.js +0 -499
- package/dist/filesystem/legacy-v2-adapter.js.map +0 -1
- package/dist/filesystem/memory-provider-v2.d.ts +0 -92
- package/dist/filesystem/memory-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/memory-provider-v2.js +0 -615
- package/dist/filesystem/memory-provider-v2.js.map +0 -1
- package/dist/filesystem/memory-provider.d.ts +0 -54
- package/dist/filesystem/memory-provider.d.ts.map +0 -1
- package/dist/filesystem/memory-provider.js +0 -132
- package/dist/filesystem/memory-provider.js.map +0 -1
- package/dist/filesystem/memory.d.ts.map +0 -1
- package/dist/filesystem/move-entry.d.ts +0 -9
- package/dist/filesystem/move-entry.d.ts.map +0 -1
- package/dist/filesystem/move-entry.js +0 -103
- package/dist/filesystem/move-entry.js.map +0 -1
- package/dist/filesystem/move-error.d.ts +0 -53
- package/dist/filesystem/move-error.d.ts.map +0 -1
- package/dist/filesystem/move-error.js +0 -99
- package/dist/filesystem/move-error.js.map +0 -1
- package/dist/filesystem/native-provider-v2.d.ts +0 -75
- package/dist/filesystem/native-provider-v2.d.ts.map +0 -1
- package/dist/filesystem/native-provider-v2.js +0 -849
- package/dist/filesystem/native-provider-v2.js.map +0 -1
- package/dist/filesystem/native-provider.d.ts +0 -53
- package/dist/filesystem/native-provider.d.ts.map +0 -1
- package/dist/filesystem/native-provider.js +0 -471
- package/dist/filesystem/native-provider.js.map +0 -1
- package/dist/filesystem/native.d.ts.map +0 -1
- package/dist/filesystem/types.d.ts +0 -83
- package/dist/filesystem/types.d.ts.map +0 -1
- package/dist/filesystem/types.js +0 -16
- package/dist/filesystem/types.js.map +0 -1
- package/dist/filesystem/v2.d.ts +0 -172
- package/dist/filesystem/v2.d.ts.map +0 -1
- package/dist/filesystem/v2.js +0 -16
- package/dist/filesystem/v2.js.map +0 -1
- package/dist/filesystem/workspace-path.d.ts +0 -21
- package/dist/filesystem/workspace-path.d.ts.map +0 -1
- package/dist/filesystem/workspace-path.js +0 -80
- package/dist/filesystem/workspace-path.js.map +0 -1
- package/dist/host/filesystem-v2.d.ts +0 -45
- package/dist/host/filesystem-v2.d.ts.map +0 -1
- package/dist/host/filesystem-v2.js +0 -13
- package/dist/host/filesystem-v2.js.map +0 -1
- package/dist/host/git.d.ts +0 -200
- package/dist/host/git.d.ts.map +0 -1
- package/dist/host/git.js +0 -15
- package/dist/host/git.js.map +0 -1
- package/dist/host/index.d.ts.map +0 -1
- package/dist/host/types.d.ts +0 -232
- package/dist/host/types.d.ts.map +0 -1
- package/dist/host/types.js +0 -10
- package/dist/host/types.js.map +0 -1
- package/dist/host/wire-policy.d.ts +0 -22
- package/dist/host/wire-policy.d.ts.map +0 -1
- package/dist/host/wire-policy.js +0 -92
- package/dist/host/wire-policy.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/types.d.ts +0 -466
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -25
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp/wire.d.ts +0 -29
- package/dist/mcp/wire.d.ts.map +0 -1
- package/dist/mcp/wire.js +0 -1046
- package/dist/mcp/wire.js.map +0 -1
- package/dist/mcp/zod.d.ts.map +0 -1
- package/dist/vscode/index.d.ts.map +0 -1
- package/dist/vscode/messages.d.ts +0 -204
- package/dist/vscode/messages.d.ts.map +0 -1
- package/dist/vscode/messages.js +0 -494
- package/dist/vscode/messages.js.map +0 -1
- package/dist/workspace/index.d.ts.map +0 -1
- package/dist/workspace/reconcile-electron.d.ts +0 -19
- package/dist/workspace/reconcile-electron.d.ts.map +0 -1
- package/dist/workspace/reconcile-electron.js +0 -42
- package/dist/workspace/reconcile-electron.js.map +0 -1
- package/dist/workspace/types.d.ts +0 -69
- package/dist/workspace/types.d.ts.map +0 -1
- package/dist/workspace/types.js +0 -2
- package/dist/workspace/types.js.map +0 -1
- package/dist/workspace/workspace-manager.d.ts +0 -47
- package/dist/workspace/workspace-manager.d.ts.map +0 -1
- package/dist/workspace/workspace-manager.js +0 -126
- package/dist/workspace/workspace-manager.js.map +0 -1
- package/src/document/document-session.ts +0 -834
- package/src/document/filesystem-target.ts +0 -109
- package/src/document/index.ts +0 -41
- package/src/document/recovery-journal.ts +0 -536
- package/src/document/types.ts +0 -116
- package/src/filesystem/commit-lock.ts +0 -29
- package/src/filesystem/dbk-workspace.ts +0 -135
- package/src/filesystem/electron-provider-v2.ts +0 -630
- package/src/filesystem/electron-provider.ts +0 -99
- package/src/filesystem/electron.ts +0 -3
- package/src/filesystem/file-media-provider.ts +0 -103
- package/src/filesystem/filesystem-content-container.ts +0 -164
- package/src/filesystem/fs-error.ts +0 -234
- package/src/filesystem/index.ts +0 -143
- package/src/filesystem/indexeddb-content-container.ts +0 -112
- package/src/filesystem/indexeddb-provider-v2.ts +0 -1740
- package/src/filesystem/indexeddb-provider.ts +0 -171
- package/src/filesystem/indexeddb-store.ts +0 -207
- package/src/filesystem/indexeddb.ts +0 -12
- package/src/filesystem/legacy-v2-adapter.ts +0 -779
- package/src/filesystem/memory-provider-v2.ts +0 -896
- package/src/filesystem/memory-provider.ts +0 -180
- package/src/filesystem/memory.ts +0 -15
- package/src/filesystem/move-entry.ts +0 -142
- package/src/filesystem/move-error.ts +0 -159
- package/src/filesystem/native-provider-v2.ts +0 -1165
- package/src/filesystem/native-provider.ts +0 -537
- package/src/filesystem/native.ts +0 -16
- package/src/filesystem/types.ts +0 -114
- package/src/filesystem/v2.ts +0 -231
- package/src/filesystem/workspace-path.ts +0 -92
- package/src/host/filesystem-v2.ts +0 -104
- package/src/host/git.ts +0 -246
- package/src/host/index.ts +0 -93
- package/src/host/types.ts +0 -274
- package/src/host/wire-policy.ts +0 -103
- package/src/index.ts +0 -10
- package/src/mcp/index.ts +0 -3
- package/src/mcp/types.ts +0 -594
- package/src/mcp/wire.ts +0 -1280
- package/src/mcp/zod.ts +0 -1000
- package/src/vscode/index.ts +0 -2
- package/src/vscode/messages.ts +0 -704
- package/src/workspace/index.ts +0 -17
- package/src/workspace/reconcile-electron.ts +0 -65
- package/src/workspace/types.ts +0 -67
- package/src/workspace/workspace-manager.ts +0 -151
- /package/dist/{chunk-75UUF6C4.js.map → chunk-B56KWCSE.js.map} +0 -0
- /package/dist/{chunk-EGNDADXB.js.map → chunk-MNSZ7EZN.js.map} +0 -0
|
@@ -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
|
-
}
|