@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.
- package/README.md +2 -2
- package/dist/{chunk-2D7Y4IR3.js → chunk-4437YWLE.js} +123 -67
- package/dist/{chunk-5MYAICRE.js → chunk-45T5AFCN.js} +44 -57
- package/dist/{chunk-PGR7LK6D.js → chunk-6L3JRDE7.js} +14 -6
- package/dist/{chunk-RVQHY3XU.js → chunk-6XHOOBYF.js} +0 -1
- package/dist/chunk-73OOROXH.js +8 -0
- package/dist/{chunk-SI2LU2RP.js → chunk-AYWKIZLD.js} +1 -1
- package/dist/{chunk-GCPBEMMH.js → chunk-BVY7GGNV.js} +10 -21
- package/dist/{chunk-AEHCVWU5.js → chunk-DZB666V7.js} +0 -1
- package/dist/{chunk-75UUF6C4.js → chunk-HI7QEWL6.js} +18 -10
- package/dist/chunk-KQ6756AJ.js +28 -0
- package/dist/chunk-LMMOFRGQ.js +148 -0
- package/dist/{chunk-FNW556FN.js → chunk-M2PUNKHS.js} +0 -1
- package/dist/chunk-M5ZNQGR5.js +19 -0
- package/dist/chunk-M62ZGJ5I.js +51 -0
- package/dist/chunk-OQCPBOQA.js +168 -0
- package/dist/{chunk-EGNDADXB.js → chunk-QI6YKTQV.js} +2 -3
- package/dist/chunk-SJBB5OD7.js +227 -0
- package/dist/{chunk-EZKJZUNJ.js → chunk-XAMILHQP.js} +0 -1
- package/dist/{chunk-J32GU3F3.js → chunk-YM7O3PWO.js} +249 -222
- package/dist/{chunk-RQJRQF46.js → chunk-ZO7G53QP.js} +41 -49
- package/dist/document/index.d.ts +358 -6
- package/dist/document/index.js +24 -4
- package/dist/filesystem/electron.d.ts +73 -4
- package/dist/filesystem/electron.js +16 -4
- package/dist/filesystem/index.d.ts +228 -22
- package/dist/filesystem/index.js +133 -20
- package/dist/filesystem/indexeddb.d.ts +284 -5
- package/dist/filesystem/indexeddb.js +22 -5
- package/dist/filesystem/memory.d.ts +152 -4
- package/dist/filesystem/memory.js +12 -4
- package/dist/filesystem/native.d.ts +136 -4
- package/dist/filesystem/native.js +27 -4
- package/dist/host/index.d.ts +32 -9
- package/dist/host/index.js +26 -30
- package/dist/index.d.ts +14 -10
- package/dist/index.js +204 -10
- package/dist/mcp/index.d.ts +33 -4
- package/dist/mcp/index.js +31 -4
- package/dist/mcp/zod.d.ts +645 -643
- package/dist/mcp/zod.js +700 -885
- package/dist/share/index.d.ts +43 -0
- package/dist/share/index.js +12 -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 +225 -3
- package/dist/vscode/index.js +389 -3
- package/dist/workspace/index.d.ts +141 -4
- package/dist/workspace/index.js +28 -3
- package/package.json +10 -5
- package/dist/chunk-2D7Y4IR3.js.map +0 -1
- package/dist/chunk-5MYAICRE.js.map +0 -1
- package/dist/chunk-75UUF6C4.js.map +0 -1
- package/dist/chunk-AEHCVWU5.js.map +0 -1
- package/dist/chunk-AYZ4HN5M.js +0 -20
- package/dist/chunk-AYZ4HN5M.js.map +0 -1
- package/dist/chunk-EGNDADXB.js.map +0 -1
- package/dist/chunk-EZKJZUNJ.js.map +0 -1
- package/dist/chunk-FNW556FN.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-RVQHY3XU.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/index.js.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/electron.js.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/index.js.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/indexeddb.js.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/memory.js.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/native.js.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/index.js.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/index.js.map +0 -1
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js.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/mcp/zod.js.map +0 -1
- package/dist/vscode/index.d.ts.map +0 -1
- package/dist/vscode/index.js.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/index.js.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
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RawIndexedDBFileSystemStore
|
|
3
|
+
} from "./chunk-OQCPBOQA.js";
|
|
4
|
+
import {
|
|
5
|
+
getFileSystemProviderV2
|
|
6
|
+
} from "./chunk-XAMILHQP.js";
|
|
7
|
+
|
|
8
|
+
// src/workspace/workspace-schema.ts
|
|
9
|
+
var MAX_IDENTIFIER_CHARACTERS = 256;
|
|
10
|
+
var MAX_LABEL_CHARACTERS = 1024;
|
|
11
|
+
var MAX_PATH_CHARACTERS = 4096;
|
|
12
|
+
var MAX_WORKSPACES = 1e4;
|
|
13
|
+
function parsePersistedWorkspaceList(value) {
|
|
14
|
+
if (!Array.isArray(value)) throw new Error("Persisted workspaces must be an array.");
|
|
15
|
+
if (value.length > MAX_WORKSPACES) throw new Error("Persisted workspace list is too large.");
|
|
16
|
+
const parsed = value.map(parsePersistedWorkspace);
|
|
17
|
+
if (new Set(parsed.map((workspace) => workspace.id)).size !== parsed.length) {
|
|
18
|
+
throw new Error("Persisted workspace IDs must be unique.");
|
|
19
|
+
}
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
function parsePersistedWorkspace(value, index) {
|
|
23
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
24
|
+
throw new Error(`Persisted workspace ${index} must be an object.`);
|
|
25
|
+
}
|
|
26
|
+
const record = value;
|
|
27
|
+
const allowed = ["id", "name", "type", "lastOpened", "rootPath", "versioningOverride"];
|
|
28
|
+
const unknownKey = Object.keys(record).find((key) => !allowed.includes(key));
|
|
29
|
+
if (unknownKey) throw new Error(`Persisted workspace ${index} has unknown field ${unknownKey}.`);
|
|
30
|
+
const id = boundedString(record.id, MAX_IDENTIFIER_CHARACTERS, `workspace ${index} id`);
|
|
31
|
+
const name = boundedString(record.name, MAX_LABEL_CHARACTERS, `workspace ${index} name`);
|
|
32
|
+
if (record.type !== "indexeddb" && record.type !== "native" && record.type !== "electron-native") {
|
|
33
|
+
throw new Error(`Persisted workspace ${index} has an invalid provider type.`);
|
|
34
|
+
}
|
|
35
|
+
const lastOpened = boundedString(
|
|
36
|
+
record.lastOpened,
|
|
37
|
+
MAX_IDENTIFIER_CHARACTERS,
|
|
38
|
+
`workspace ${index} lastOpened`
|
|
39
|
+
);
|
|
40
|
+
if (!Number.isFinite(Date.parse(lastOpened)) || new Date(lastOpened).toISOString() !== lastOpened) {
|
|
41
|
+
throw new Error(`Persisted workspace ${index} has an invalid lastOpened timestamp.`);
|
|
42
|
+
}
|
|
43
|
+
const descriptor = { id, name, type: record.type, lastOpened };
|
|
44
|
+
if (record.rootPath !== void 0) {
|
|
45
|
+
descriptor.rootPath = boundedString(
|
|
46
|
+
record.rootPath,
|
|
47
|
+
MAX_PATH_CHARACTERS,
|
|
48
|
+
`workspace ${index} rootPath`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (record.type === "electron-native" && descriptor.rootPath === void 0) {
|
|
52
|
+
throw new Error(`Persisted Electron workspace ${index} is missing rootPath.`);
|
|
53
|
+
}
|
|
54
|
+
if (record.type !== "electron-native" && descriptor.rootPath !== void 0) {
|
|
55
|
+
throw new Error(`Persisted workspace ${index} must not contain rootPath.`);
|
|
56
|
+
}
|
|
57
|
+
if (record.versioningOverride !== void 0) {
|
|
58
|
+
if (record.versioningOverride !== "inherit" && record.versioningOverride !== "on" && record.versioningOverride !== "off") {
|
|
59
|
+
throw new Error(`Persisted workspace ${index} has an invalid versioning override.`);
|
|
60
|
+
}
|
|
61
|
+
descriptor.versioningOverride = record.versioningOverride;
|
|
62
|
+
}
|
|
63
|
+
return descriptor;
|
|
64
|
+
}
|
|
65
|
+
function boundedString(value, maximum, label) {
|
|
66
|
+
if (typeof value !== "string" || value.length < 1 || value.length > maximum || value.includes("\0")) {
|
|
67
|
+
throw new Error(`Persisted ${label} must be a bounded non-empty string.`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/workspace/workspace-manager.ts
|
|
73
|
+
var DB_NAME = "docblocks-workspaces";
|
|
74
|
+
var STORE_NAME = "workspaces";
|
|
75
|
+
var LIST_KEY = "workspace-list";
|
|
76
|
+
var DEFAULT_WORKSPACE_ID = "default";
|
|
77
|
+
var registryStore = null;
|
|
78
|
+
function store() {
|
|
79
|
+
registryStore ?? (registryStore = new RawIndexedDBFileSystemStore(DB_NAME, STORE_NAME));
|
|
80
|
+
return registryStore;
|
|
81
|
+
}
|
|
82
|
+
var transientWorkspaces = /* @__PURE__ */ new Map();
|
|
83
|
+
var persistedMutationTail = Promise.resolve();
|
|
84
|
+
function registerTransientWorkspace(descriptor, provider) {
|
|
85
|
+
const previous = transientWorkspaces.get(descriptor.id);
|
|
86
|
+
if (previous && previous.provider !== provider) {
|
|
87
|
+
void getFileSystemProviderV2(previous.provider)?.dispose();
|
|
88
|
+
}
|
|
89
|
+
transientWorkspaces.set(descriptor.id, { descriptor, provider });
|
|
90
|
+
}
|
|
91
|
+
function getTransientWorkspace(id) {
|
|
92
|
+
return transientWorkspaces.get(id) ?? null;
|
|
93
|
+
}
|
|
94
|
+
async function unregisterTransientWorkspace(id) {
|
|
95
|
+
const entry = transientWorkspaces.get(id);
|
|
96
|
+
if (!entry) return;
|
|
97
|
+
transientWorkspaces.delete(id);
|
|
98
|
+
await getFileSystemProviderV2(entry.provider)?.dispose();
|
|
99
|
+
}
|
|
100
|
+
async function readPersistedIn(transaction) {
|
|
101
|
+
const list = await transaction.get(LIST_KEY);
|
|
102
|
+
return list == null ? [] : parsePersistedWorkspaceList(list);
|
|
103
|
+
}
|
|
104
|
+
async function readPersisted() {
|
|
105
|
+
return store().transaction("readonly", readPersistedIn);
|
|
106
|
+
}
|
|
107
|
+
async function listPersisted() {
|
|
108
|
+
await persistedMutationTail;
|
|
109
|
+
return readPersisted();
|
|
110
|
+
}
|
|
111
|
+
function mutatePersisted(mutation) {
|
|
112
|
+
const operation = persistedMutationTail.then(async () => {
|
|
113
|
+
await store().transaction("readwrite", async (transaction) => {
|
|
114
|
+
const current = await readPersistedIn(transaction);
|
|
115
|
+
const next = parsePersistedWorkspaceList(mutation([...current]));
|
|
116
|
+
await transaction.put(LIST_KEY, next);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
persistedMutationTail = operation.then(
|
|
120
|
+
() => void 0,
|
|
121
|
+
() => void 0
|
|
122
|
+
);
|
|
123
|
+
return operation;
|
|
124
|
+
}
|
|
125
|
+
async function listWorkspaces() {
|
|
126
|
+
const persisted = await listPersisted();
|
|
127
|
+
const transient = [...transientWorkspaces.values()].map((t) => t.descriptor);
|
|
128
|
+
return [...persisted, ...transient];
|
|
129
|
+
}
|
|
130
|
+
async function getWorkspace(id) {
|
|
131
|
+
const transient = transientWorkspaces.get(id);
|
|
132
|
+
if (transient) return transient.descriptor;
|
|
133
|
+
const list = await listPersisted();
|
|
134
|
+
return list.find((w) => w.id === id) ?? null;
|
|
135
|
+
}
|
|
136
|
+
async function saveWorkspace(workspace) {
|
|
137
|
+
if (workspace.type === "transient") return;
|
|
138
|
+
const persisted = parsePersistedWorkspaceList([workspace])[0];
|
|
139
|
+
await mutatePersisted((list) => {
|
|
140
|
+
const idx = list.findIndex((candidate) => candidate.id === persisted.id);
|
|
141
|
+
if (idx >= 0) list[idx] = persisted;
|
|
142
|
+
else list.push(persisted);
|
|
143
|
+
return list;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async function removeWorkspace(id) {
|
|
147
|
+
if (transientWorkspaces.has(id)) {
|
|
148
|
+
await unregisterTransientWorkspace(id);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
await mutatePersisted((list) => list.filter((workspace) => workspace.id !== id));
|
|
152
|
+
}
|
|
153
|
+
async function touchWorkspace(id) {
|
|
154
|
+
const transient = transientWorkspaces.get(id);
|
|
155
|
+
if (transient) {
|
|
156
|
+
transient.descriptor.lastOpened = (/* @__PURE__ */ new Date()).toISOString();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
await mutatePersisted((list) => {
|
|
160
|
+
const workspace = list.find((candidate) => candidate.id === id);
|
|
161
|
+
if (workspace) workspace.lastOpened = (/* @__PURE__ */ new Date()).toISOString();
|
|
162
|
+
return list;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async function ensureDefaultWorkspace() {
|
|
166
|
+
const existing = await getWorkspace(DEFAULT_WORKSPACE_ID);
|
|
167
|
+
if (existing) return existing;
|
|
168
|
+
const descriptor = {
|
|
169
|
+
id: DEFAULT_WORKSPACE_ID,
|
|
170
|
+
name: "My Documents",
|
|
171
|
+
type: "indexeddb",
|
|
172
|
+
lastOpened: (/* @__PURE__ */ new Date()).toISOString()
|
|
173
|
+
};
|
|
174
|
+
await saveWorkspace(descriptor);
|
|
175
|
+
return descriptor;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/workspace/reconcile-electron.ts
|
|
179
|
+
function comparableRoot(rootPath, platform) {
|
|
180
|
+
const normalized = rootPath.replace(/\\/gu, "/").replace(/\/+$/gu, "");
|
|
181
|
+
return platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
182
|
+
}
|
|
183
|
+
function reconcileElectronWorkspaceDescriptors(local, hostWorkspaces, platform, now) {
|
|
184
|
+
const electron = local.filter((workspace) => workspace.type === "electron-native");
|
|
185
|
+
const matchedLocalIds = /* @__PURE__ */ new Set();
|
|
186
|
+
const idRemap = {};
|
|
187
|
+
const upsert = hostWorkspaces.map((hostWorkspace) => {
|
|
188
|
+
const root = comparableRoot(hostWorkspace.rootPath, platform);
|
|
189
|
+
const candidates = electron.filter(
|
|
190
|
+
(workspace) => workspace.rootPath && comparableRoot(workspace.rootPath, platform) === root
|
|
191
|
+
);
|
|
192
|
+
const matching = candidates.sort(
|
|
193
|
+
(left, right) => right.lastOpened.localeCompare(left.lastOpened)
|
|
194
|
+
)[0];
|
|
195
|
+
if (matching) {
|
|
196
|
+
matchedLocalIds.add(matching.id);
|
|
197
|
+
if (matching.id !== hostWorkspace.id) idRemap[matching.id] = hostWorkspace.id;
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
id: hostWorkspace.id,
|
|
201
|
+
name: matching?.name ?? hostWorkspace.name,
|
|
202
|
+
type: "electron-native",
|
|
203
|
+
rootPath: hostWorkspace.rootPath,
|
|
204
|
+
lastOpened: matching?.lastOpened ?? now,
|
|
205
|
+
...matching?.versioningOverride ? { versioningOverride: matching.versioningOverride } : {}
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
const canonicalIds = new Set(hostWorkspaces.map((workspace) => workspace.id));
|
|
209
|
+
const removeIds = electron.filter(
|
|
210
|
+
(workspace) => !canonicalIds.has(workspace.id) || matchedLocalIds.has(workspace.id) && !upsert.some((candidate) => candidate.id === workspace.id)
|
|
211
|
+
).map((workspace) => workspace.id);
|
|
212
|
+
return { removeIds, upsert, idRemap };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
parsePersistedWorkspaceList,
|
|
217
|
+
registerTransientWorkspace,
|
|
218
|
+
getTransientWorkspace,
|
|
219
|
+
unregisterTransientWorkspace,
|
|
220
|
+
listWorkspaces,
|
|
221
|
+
getWorkspace,
|
|
222
|
+
saveWorkspace,
|
|
223
|
+
removeWorkspace,
|
|
224
|
+
touchWorkspace,
|
|
225
|
+
ensureDefaultWorkspace,
|
|
226
|
+
reconcileElectronWorkspaceDescriptors
|
|
227
|
+
};
|