@akohn/dashql 0.0.19-dev.305.gb0f831a47 → 0.0.19-dev.368.g7091b292b
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 +1 -2
- package/dist/core/api.d.ts +24 -18
- package/dist/core/api.js +42 -46
- package/dist/core/connection.d.ts +1 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.js +1 -4
- package/dist/core/runtime.d.ts +1 -1
- package/dist/core/workbook.d.ts +1 -1
- package/dist/platform/compute/arrow_formatter.d.ts +3 -1
- package/dist/platform/compute/arrow_formatter.js +23 -20
- package/dist/platform/compute/computation_types.d.ts +7 -12
- package/dist/platform/compute/computation_types.js +6 -3
- package/dist/platform/compute/query_result_search_sql.d.ts +0 -7
- package/dist/platform/compute/query_result_search_sql.js +1 -19
- package/dist/platform/connections/connection_params.d.ts +5 -6
- package/dist/platform/connections/connection_params.js +14 -25
- package/dist/platform/connections/connection_state.d.ts +1 -1
- package/dist/platform/connections/connector_configs.d.ts +2 -3
- package/dist/platform/connections/connector_info.d.ts +4 -14
- package/dist/platform/connections/connector_info.js +1 -25
- package/dist/platform/connections/embedded_database_channel.d.ts +3 -3
- package/dist/platform/connections/embedded_database_channel.js +12 -6
- package/dist/platform/connections/hyper/hyper_error_info.d.ts +0 -15
- package/dist/platform/connections/hyper/hyper_error_info.js +1 -18
- package/dist/platform/connections/query_execution.js +9 -7
- package/dist/platform/connections/query_execution_args.d.ts +2 -2
- package/dist/platform/http_client.d.ts +1 -1
- package/dist/platform/logger/logger.d.ts +3 -3
- package/dist/platform/query/query_execution_state.d.ts +11 -38
- package/dist/platform/query/query_execution_state.js +6 -1
- package/dist/platform/query/query_progress.d.ts +0 -14
- package/dist/platform/query/query_result_cache.d.ts +2 -2
- package/dist/platform/storage/composite_storage_backend.d.ts +64 -0
- package/dist/platform/storage/composite_storage_backend.js +321 -0
- package/dist/platform/storage/native_storage_backend.d.ts +1 -1
- package/dist/platform/storage/native_storage_backend.js +1 -1
- package/dist/platform/storage/opfs_query_result_cache.d.ts +0 -2
- package/dist/platform/storage/opfs_query_result_cache.js +3 -5
- package/dist/platform/storage/opfs_storage_backend.d.ts +67 -0
- package/dist/platform/storage/opfs_storage_backend.js +494 -0
- package/dist/platform/storage/workbook_locator.d.ts +7 -0
- package/dist/platform/storage/workbook_locator.js +14 -0
- package/dist/platform/storage/workbook_tables.d.ts +1 -4
- package/dist/platform/storage/workbook_tables.js +3 -17
- package/dist/platform/storage/workbook_transfer.d.ts +9 -0
- package/dist/platform/storage/workbook_transfer.js +84 -0
- package/dist/platform/storage/workbook_tree.d.ts +30 -9
- package/dist/platform/storage/workbook_tree.js +17 -96
- package/dist/platform/utils/base64.js +4 -4
- package/dist/platform/web_http_client.d.ts +1 -4
- package/dist/platform/web_http_client.js +0 -5
- package/dist/platform/workbook/attachment_mounts.d.ts +12 -4
- package/dist/platform/workbook/attachment_mounts.js +69 -60
- package/dist/platform/workbook/run_events.js +1 -1
- package/dist/platform/workbook/script_compilation.d.ts +0 -1
- package/dist/platform/workbook/script_compilation.js +1 -14
- package/dist/platform/workbook/script_reference_check.js +7 -6
- package/dist/platform/workbook/script_types.d.ts +1 -1
- package/dist/platform/workbook/script_types.js +1 -10
- package/dist/platform/workbook/workbook_execution.d.ts +0 -2
- package/dist/platform/workbook/workbook_execution.js +1 -4
- package/dist/platform/workbook/workbook_inputs.d.ts +7 -7
- package/dist/platform/workbook/workbook_inputs.js +4 -4
- package/dist/platform/workbook/workbook_scripts.d.ts +2 -2
- package/dist/runtime/compute_platform.js +2 -2
- package/dist/runtime/node/node_platform.js +1 -1
- package/dist/runtime/platform_requests.js +1 -1
- package/dist/runtime/query/query_channels.d.ts +0 -2
- package/dist/runtime/query/query_channels.js +36 -55
- package/dist/runtime/run_mounts.d.ts +2 -1
- package/dist/runtime/run_mounts.js +4 -5
- package/dist/runtime/runtime.d.ts +3 -0
- package/dist/runtime/runtime.js +10 -6
- package/dist/runtime/runtime_storage.d.ts +2 -5
- package/dist/runtime/runtime_storage.js +4 -13
- package/dist/runtime/workbook_projection.js +2 -2
- package/dist/runtime/workbook_run_report.d.ts +3 -6
- package/dist/runtime/workbook_run_report.js +33 -47
- package/dist/wasm/dashql_core.d.ts +2363 -2090
- package/dist/wasm/dashql_core.js +362 -222
- package/dist/wasm/dashql_core.wasm +0 -0
- package/dist/wasm/dashql_dataflow.wasm +0 -0
- package/package.json +1 -1
- package/dist/core/format.d.ts +0 -4
- package/dist/core/format.js +0 -23
- package/dist/core/lookup.d.ts +0 -10
- package/dist/core/lookup.js +0 -129
- package/dist/core/tokens.d.ts +0 -9
- package/dist/core/tokens.js +0 -78
- package/dist/core/variant.d.ts +0 -4
- package/dist/core/variant.js +0 -0
- package/dist/platform/connections/hyper/local_cloud.d.ts +0 -15
- package/dist/platform/connections/hyper/local_cloud.js +0 -14
- package/dist/platform/connections/query_channel.d.ts +0 -3
- package/dist/platform/connections/query_channel.js +0 -11
- package/dist/platform/hyper_link_target.d.ts +0 -8
- package/dist/platform/hyper_link_target.js +0 -35
- package/dist/platform/sql/sql_format.d.ts +0 -9
- package/dist/platform/sql/sql_format.js +0 -40
- package/dist/platform/sql/sql_lint.d.ts +0 -27
- package/dist/platform/sql/sql_lint.js +0 -69
- package/dist/platform/sql/sql_report.d.ts +0 -18
- package/dist/platform/sql/sql_report.js +0 -80
- package/dist/platform/storage/storage_versions.d.ts +0 -3
- package/dist/platform/storage/storage_versions.js +0 -13
- package/dist/platform/utils/async_consumer.d.ts +0 -14
- package/dist/platform/utils/async_consumer.js +0 -24
- package/dist/platform/workbook/attachment_mirror.d.ts +0 -2
- package/dist/platform/workbook/attachment_mirror.js +0 -25
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { STORAGE_ATTACHMENTS_FOLDER, STORAGE_CONNECTIONS_FOLDER, STORAGE_MANIFEST_FILE, STORAGE_SCRIPTS_FOLDER, STORAGE_SHELL_FOLDER, STORAGE_WORKBOOKS_FOLDER, STORAGE_WORKBOOK_FILE, StorageBackendType } from "./storage_backend.js";
|
|
2
|
+
import { sleep } from "../utils/sleep.js";
|
|
3
|
+
import { getOPFSRoot } from "../opfs_root.js";
|
|
4
|
+
import { HYPER_CLOUDS_DIRECTORY } from "../hyperdb/hyperdb_opfs_instance.js";
|
|
5
|
+
import { INITIAL_WORKBOOK_FOLDER, STORAGE_FOLDER_FILE, STORAGE_WORKBOOK_TREE_FOLDER, changeWorkbookTree, emptyWorkbookTree, flattenWorkbookTree, folderAt, isFolderPathWithin, listWorkbookTreeDirectory, sameFolderPath } from "./workbook_tree.js";
|
|
6
|
+
// dist/.stage/src/platform/storage/opfs_storage_backend.ts
|
|
7
|
+
var OPFS_MANIFEST_LOCK = "dashql-manifest";
|
|
8
|
+
var OPFS_WORKBOOK_TREE_LOCK = "dashql-workbook-tree";
|
|
9
|
+
var DELETE_IN_USE_ATTEMPTS = 20;
|
|
10
|
+
var DELETE_IN_USE_RETRY_MS = 100;
|
|
11
|
+
function domErrorName(error) {
|
|
12
|
+
return error instanceof DOMException ? error.name : null;
|
|
13
|
+
}
|
|
14
|
+
function isMissingDirectory(error) {
|
|
15
|
+
return domErrorName(error) === "NotFoundError" || error instanceof Error && error.message.startsWith("Directory not found");
|
|
16
|
+
}
|
|
17
|
+
var OPFSStorageBackend = class {
|
|
18
|
+
core;
|
|
19
|
+
getRoot;
|
|
20
|
+
rootHandle = null;
|
|
21
|
+
manifestChain = Promise.resolve();
|
|
22
|
+
treeChain = Promise.resolve();
|
|
23
|
+
constructor(core, getRoot = getOPFSRoot) {
|
|
24
|
+
this.core = core;
|
|
25
|
+
this.getRoot = getRoot;
|
|
26
|
+
}
|
|
27
|
+
getBackendType() {
|
|
28
|
+
return StorageBackendType.OPFS;
|
|
29
|
+
}
|
|
30
|
+
async initialize() {
|
|
31
|
+
this.rootHandle = await this.getRoot();
|
|
32
|
+
await this.createWorkbookTree();
|
|
33
|
+
}
|
|
34
|
+
async createWorkbookTree() {
|
|
35
|
+
const root = this.ensureInitialized();
|
|
36
|
+
await this.withTreeLock(async () => {
|
|
37
|
+
try {
|
|
38
|
+
await root.getDirectoryHandle(STORAGE_WORKBOOK_TREE_FOLDER, { create: false });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.name !== "NotFoundError") throw error;
|
|
41
|
+
await this.writeFolderFile([], []);
|
|
42
|
+
await this.writeFolderFile(INITIAL_WORKBOOK_FOLDER, []);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
withManifestLock(fn) {
|
|
47
|
+
const locks = typeof navigator !== "undefined" ? navigator.locks : void 0;
|
|
48
|
+
const run = locks != null ? () => locks.request(OPFS_MANIFEST_LOCK, fn) : fn;
|
|
49
|
+
const result = this.manifestChain.then(run, run);
|
|
50
|
+
this.manifestChain = result.then(() => {}, () => {});
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
withTreeLock(fn) {
|
|
54
|
+
const locks = typeof navigator !== "undefined" ? navigator.locks : void 0;
|
|
55
|
+
const run = locks != null ? () => locks.request(OPFS_WORKBOOK_TREE_LOCK, fn) : fn;
|
|
56
|
+
const result = this.treeChain.then(run, run);
|
|
57
|
+
this.treeChain = result.then(() => {}, () => {});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
mutateManifest(fn) {
|
|
61
|
+
return this.withManifestLock(async () => {
|
|
62
|
+
const root = this.ensureInitialized();
|
|
63
|
+
const manifest = await this.readManifest(root);
|
|
64
|
+
if (fn(manifest) === false) return;
|
|
65
|
+
await this.writeManifest(root, manifest);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
ensureInitialized() {
|
|
69
|
+
if (!this.rootHandle) throw new Error("OPFSStorageBackend not initialized. Call initialize() first.");
|
|
70
|
+
return this.rootHandle;
|
|
71
|
+
}
|
|
72
|
+
workbookRelPath(workbookId) {
|
|
73
|
+
return `${STORAGE_WORKBOOKS_FOLDER}/${workbookId}`;
|
|
74
|
+
}
|
|
75
|
+
naturalSort(a, b) {
|
|
76
|
+
return a.localeCompare(b, void 0, {
|
|
77
|
+
numeric: true,
|
|
78
|
+
sensitivity: "base"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async listWorkbooks() {
|
|
82
|
+
return flattenWorkbookTree(await this.loadWorkbookTree());
|
|
83
|
+
}
|
|
84
|
+
async loadWorkbook(workbookId) {
|
|
85
|
+
const text = await (await (await (await this.getWorkbookDir(this.workbookRelPath(workbookId), false)).getFileHandle(STORAGE_WORKBOOK_FILE)).getFile()).text();
|
|
86
|
+
const data = JSON.parse(text);
|
|
87
|
+
if (!data.workbookId) throw new Error(`Workbook ${workbookId} is missing required workbookId field. Please migrate the workbook or regenerate it.`);
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
async saveWorkbookManifest(workbookId, data) {
|
|
91
|
+
const writable = await (await (await this.getWorkbookDir(this.workbookRelPath(workbookId), true)).getFileHandle(STORAGE_WORKBOOK_FILE, { create: true })).createWritable();
|
|
92
|
+
await writable.write(JSON.stringify(data, null, 2));
|
|
93
|
+
await writable.close();
|
|
94
|
+
await this.upsertWorkbookEntry({
|
|
95
|
+
path: workbookId,
|
|
96
|
+
storageType: StorageBackendType.OPFS
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async deleteWorkbook(workbookId) {
|
|
100
|
+
await this.deleteWorkbookFiles(workbookId);
|
|
101
|
+
await this.removeWorkbookEntry(workbookId);
|
|
102
|
+
}
|
|
103
|
+
async deleteWorkbookFiles(workbookId) {
|
|
104
|
+
const relativePath = this.workbookRelPath(workbookId);
|
|
105
|
+
const root = this.ensureInitialized();
|
|
106
|
+
try {
|
|
107
|
+
const parts = relativePath.split("/").filter((p) => p);
|
|
108
|
+
if (parts.length > 0) {
|
|
109
|
+
let parentDir = root;
|
|
110
|
+
for (let i = 0; i < parts.length - 1; i++) parentDir = await parentDir.getDirectoryHandle(parts[i], { create: false });
|
|
111
|
+
await parentDir.removeEntry(parts[parts.length - 1], { recursive: true });
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (domErrorName(error) !== "NotFoundError") throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async loadScripts(workbookId) {
|
|
118
|
+
const workbookDir = await this.getWorkbookDir(this.workbookRelPath(workbookId), false).catch((error) => {
|
|
119
|
+
if (domErrorName(error) === "NotFoundError") return null;
|
|
120
|
+
throw error;
|
|
121
|
+
});
|
|
122
|
+
if (!workbookDir) return [];
|
|
123
|
+
let scriptsDir;
|
|
124
|
+
try {
|
|
125
|
+
scriptsDir = await workbookDir.getDirectoryHandle(STORAGE_SCRIPTS_FOLDER, { create: false });
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (domErrorName(error) === "NotFoundError") return [];
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
const scripts = [];
|
|
131
|
+
for await (const [name, handle] of scriptsDir.entries()) {
|
|
132
|
+
if (handle.kind === "directory") throw new Error(`Invalid V2 workbook layout: nested scripts directory ${name}`);
|
|
133
|
+
if (name.toLowerCase() === "dashql-draft.sql") throw new Error("Invalid V2 workbook layout: dashql-draft.sql is not supported");
|
|
134
|
+
if (handle.kind === "file" && name.toLowerCase().endsWith(".sql")) {
|
|
135
|
+
const file = await handle.getFile();
|
|
136
|
+
scripts.push({
|
|
137
|
+
name,
|
|
138
|
+
sql: await file.text()
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
scripts.sort((a, b) => this.naturalSort(a.name, b.name));
|
|
143
|
+
return scripts;
|
|
144
|
+
}
|
|
145
|
+
async moveFile(srcDir, srcName, destDir, destName) {
|
|
146
|
+
if (srcDir === destDir && srcName === destName) return;
|
|
147
|
+
const srcHandle = await srcDir.getFileHandle(srcName, { create: false });
|
|
148
|
+
const move = srcHandle.move;
|
|
149
|
+
if (typeof move === "function") {
|
|
150
|
+
await (srcDir === destDir ? move.call(srcHandle, destName) : move.call(srcHandle, destDir, destName));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const file = await srcHandle.getFile();
|
|
154
|
+
const writable = await (await destDir.getFileHandle(destName, { create: true })).createWritable();
|
|
155
|
+
await writable.write(file);
|
|
156
|
+
await writable.close();
|
|
157
|
+
await srcDir.removeEntry(srcName);
|
|
158
|
+
}
|
|
159
|
+
async loadScript(workbookId, scriptName) {
|
|
160
|
+
const scriptsDir = await (await this.getWorkbookDir(this.workbookRelPath(workbookId), false)).getDirectoryHandle(STORAGE_SCRIPTS_FOLDER, { create: false });
|
|
161
|
+
try {
|
|
162
|
+
return {
|
|
163
|
+
name: scriptName,
|
|
164
|
+
sql: await (await (await scriptsDir.getFileHandle(scriptName)).getFile()).text()
|
|
165
|
+
};
|
|
166
|
+
} catch {
|
|
167
|
+
throw new Error(`Script not found: workbook ${workbookId}, script ${scriptName}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async saveScript(workbookId, scriptName, sql) {
|
|
171
|
+
const writable = await (await (await (await this.getWorkbookDir(this.workbookRelPath(workbookId), true)).getDirectoryHandle(STORAGE_SCRIPTS_FOLDER, { create: true })).getFileHandle(scriptName, { create: true })).createWritable();
|
|
172
|
+
await writable.write(sql);
|
|
173
|
+
await writable.close();
|
|
174
|
+
}
|
|
175
|
+
async deleteScript(workbookId, scriptName) {
|
|
176
|
+
try {
|
|
177
|
+
await (await (await this.getWorkbookDir(this.workbookRelPath(workbookId), false)).getDirectoryHandle(STORAGE_SCRIPTS_FOLDER, { create: false })).removeEntry(scriptName);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (isMissingDirectory(error)) return;
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async renameScript(workbookId, oldScriptName, newScriptName) {
|
|
184
|
+
if (oldScriptName === newScriptName) return;
|
|
185
|
+
let scriptsDir;
|
|
186
|
+
try {
|
|
187
|
+
scriptsDir = await (await this.getWorkbookDir(this.workbookRelPath(workbookId), false)).getDirectoryHandle(STORAGE_SCRIPTS_FOLDER, { create: false });
|
|
188
|
+
await scriptsDir.getFileHandle(oldScriptName, { create: false });
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (isMissingDirectory(error)) return;
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
await this.moveFile(scriptsDir, oldScriptName, scriptsDir, newScriptName);
|
|
194
|
+
}
|
|
195
|
+
async dataDir(workbookId, create) {
|
|
196
|
+
const root = this.ensureInitialized();
|
|
197
|
+
try {
|
|
198
|
+
return await (await (await root.getDirectoryHandle(STORAGE_WORKBOOKS_FOLDER, { create })).getDirectoryHandle(workbookId, { create })).getDirectoryHandle(STORAGE_ATTACHMENTS_FOLDER, { create });
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (!create && error.name === "NotFoundError") return null;
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async listDataFiles(workbookId) {
|
|
205
|
+
const dir = await this.dataDir(workbookId, false);
|
|
206
|
+
if (!dir) return [];
|
|
207
|
+
const files = [];
|
|
208
|
+
for await (const [name, handle] of dir.entries()) {
|
|
209
|
+
if (handle.kind === "directory") throw new Error(`Invalid workbook layout: nested data directory ${name}`);
|
|
210
|
+
if (!this.core.isAttachmentFileName(name)) continue;
|
|
211
|
+
this.core.validateDataFileName(name);
|
|
212
|
+
const file = await handle.getFile();
|
|
213
|
+
files.push({
|
|
214
|
+
name,
|
|
215
|
+
sizeBytes: file.size,
|
|
216
|
+
mtimeMs: file.lastModified
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return files.sort((a, b) => this.naturalSort(a.name, b.name));
|
|
220
|
+
}
|
|
221
|
+
async loadDataFile(workbookId, name) {
|
|
222
|
+
this.core.validateDataFileName(name);
|
|
223
|
+
const dir = await this.dataDir(workbookId, false);
|
|
224
|
+
if (!dir) throw new Error(`Data file not found: ${name}`);
|
|
225
|
+
const handle = await dir.getFileHandle(name, { create: false });
|
|
226
|
+
return new Uint8Array(await (await handle.getFile()).arrayBuffer());
|
|
227
|
+
}
|
|
228
|
+
async saveDataFile(workbookId, name, content) {
|
|
229
|
+
this.core.validateDataFileName(name);
|
|
230
|
+
const writable = await (await (await this.dataDir(workbookId, true)).getFileHandle(name, { create: true })).createWritable();
|
|
231
|
+
if (content instanceof Blob) await writable.write(content);
|
|
232
|
+
else {
|
|
233
|
+
const buffer = new ArrayBuffer(content.byteLength);
|
|
234
|
+
new Uint8Array(buffer).set(content);
|
|
235
|
+
await writable.write(buffer);
|
|
236
|
+
}
|
|
237
|
+
await writable.close();
|
|
238
|
+
}
|
|
239
|
+
async deleteDataFile(workbookId, name) {
|
|
240
|
+
this.core.validateDataFileName(name);
|
|
241
|
+
const dir = await this.dataDir(workbookId, false);
|
|
242
|
+
if (!dir) return;
|
|
243
|
+
try {
|
|
244
|
+
await dir.removeEntry(name);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error.name === "NotFoundError") return;
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async renameDataFile(workbookId, oldName, newName) {
|
|
251
|
+
this.core.validateDataFileName(oldName);
|
|
252
|
+
this.core.validateDataFileName(newName);
|
|
253
|
+
if (oldName === newName) return;
|
|
254
|
+
const dir = await this.dataDir(workbookId, false);
|
|
255
|
+
if (!dir) return;
|
|
256
|
+
await this.moveFile(dir, oldName, dir, newName);
|
|
257
|
+
}
|
|
258
|
+
async writeEmptyFile(dir, name) {
|
|
259
|
+
const writable = await (await dir.getFileHandle(name, { create: true })).createWritable();
|
|
260
|
+
await writable.write(/* @__PURE__ */ new ArrayBuffer(0));
|
|
261
|
+
await writable.close();
|
|
262
|
+
}
|
|
263
|
+
async clearAllStorage() {
|
|
264
|
+
const root = this.ensureInitialized();
|
|
265
|
+
try {
|
|
266
|
+
await this.withTreeLock(() => root.removeEntry(STORAGE_WORKBOOK_TREE_FOLDER, { recursive: true }));
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (error.name !== "NotFoundError") console.warn("Failed to clear the workbook tree:", error);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
await this.withManifestLock(async () => {
|
|
272
|
+
const storageVersion = await this.readManifest(root).then((manifest) => manifest.storageVersion, () => void 0);
|
|
273
|
+
await this.writeManifest(root, storageVersion == null ? {} : { storageVersion });
|
|
274
|
+
});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.warn("Failed to clear manifest:", error);
|
|
277
|
+
}
|
|
278
|
+
for (const folder of [
|
|
279
|
+
STORAGE_WORKBOOKS_FOLDER,
|
|
280
|
+
STORAGE_CONNECTIONS_FOLDER,
|
|
281
|
+
STORAGE_SHELL_FOLDER,
|
|
282
|
+
HYPER_CLOUDS_DIRECTORY
|
|
283
|
+
]) try {
|
|
284
|
+
await root.removeEntry(folder, { recursive: true });
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (error.name !== "NotFoundError") console.warn(`Failed to delete ${folder} folder:`, error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async loadAppSettings() {
|
|
290
|
+
const root = this.ensureInitialized();
|
|
291
|
+
try {
|
|
292
|
+
const text = await (await (await root.getFileHandle(STORAGE_MANIFEST_FILE, { create: false })).getFile()).text();
|
|
293
|
+
return JSON.parse(text).appSettings ?? null;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (domErrorName(error) === "NotFoundError") return null;
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async saveAppSettings(settings) {
|
|
300
|
+
await this.mutateManifest((manifest) => {
|
|
301
|
+
manifest.appSettings = settings;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
async loadManifest() {
|
|
305
|
+
const root = this.ensureInitialized();
|
|
306
|
+
return await this.withManifestLock(() => this.readManifest(root));
|
|
307
|
+
}
|
|
308
|
+
async updateConnections(update) {
|
|
309
|
+
await this.mutateManifest((manifest) => {
|
|
310
|
+
const next = update(manifest.connections);
|
|
311
|
+
if (next == null) return false;
|
|
312
|
+
manifest.connections = next;
|
|
313
|
+
return true;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
connectionRelPath(connectionId) {
|
|
317
|
+
return `${STORAGE_CONNECTIONS_FOLDER}/${connectionId}`;
|
|
318
|
+
}
|
|
319
|
+
async loadConnectionFile(connectionId, fileName) {
|
|
320
|
+
try {
|
|
321
|
+
return await (await (await (await this.getWorkbookDir(this.connectionRelPath(connectionId), false)).getFileHandle(fileName, { create: false })).getFile()).text();
|
|
322
|
+
} catch {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async saveConnectionFile(connectionId, fileName, text) {
|
|
327
|
+
const writable = await (await (await this.getWorkbookDir(this.connectionRelPath(connectionId), true)).getFileHandle(fileName, { create: true })).createWritable();
|
|
328
|
+
await writable.write(text);
|
|
329
|
+
await writable.close();
|
|
330
|
+
}
|
|
331
|
+
async createConnectionFolder(connectionId) {
|
|
332
|
+
await this.getWorkbookDir(this.connectionRelPath(connectionId), true);
|
|
333
|
+
}
|
|
334
|
+
async deleteConnectionFiles(connectionId) {
|
|
335
|
+
const root = this.ensureInitialized();
|
|
336
|
+
for (let attempt = 1;; ++attempt) try {
|
|
337
|
+
await (await root.getDirectoryHandle(STORAGE_CONNECTIONS_FOLDER, { create: false })).removeEntry(connectionId, { recursive: true });
|
|
338
|
+
return;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
const name = domErrorName(error);
|
|
341
|
+
if (name === "NotFoundError") return;
|
|
342
|
+
if (!(name === "NoModificationAllowedError" || name === "InvalidModificationError") || attempt >= DELETE_IN_USE_ATTEMPTS) throw error;
|
|
343
|
+
await sleep(DELETE_IN_USE_RETRY_MS);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async readManifest(root) {
|
|
347
|
+
try {
|
|
348
|
+
const text = await (await (await root.getFileHandle(STORAGE_MANIFEST_FILE, { create: false })).getFile()).text();
|
|
349
|
+
const manifest = JSON.parse(text);
|
|
350
|
+
if (manifest == null || typeof manifest !== "object" || Array.isArray(manifest)) throw new Error("Invalid manifest format: not a JSON object");
|
|
351
|
+
return manifest;
|
|
352
|
+
} catch (error) {
|
|
353
|
+
if (domErrorName(error) === "NotFoundError") return {};
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async writeManifest(root, manifest) {
|
|
358
|
+
const writable = await (await root.getFileHandle(STORAGE_MANIFEST_FILE, { create: true })).createWritable();
|
|
359
|
+
await writable.write(JSON.stringify(manifest, null, 2));
|
|
360
|
+
await writable.close();
|
|
361
|
+
}
|
|
362
|
+
async loadWorkbookTree() {
|
|
363
|
+
return await this.withTreeLock(async () => await this.readTree(false));
|
|
364
|
+
}
|
|
365
|
+
async upsertWorkbookEntry(entry, folderPath = []) {
|
|
366
|
+
await this.mutateTree({
|
|
367
|
+
kind: "upsert",
|
|
368
|
+
entry,
|
|
369
|
+
folderPath
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
async removeWorkbookEntry(workbookId) {
|
|
373
|
+
await this.mutateTree({
|
|
374
|
+
kind: "remove",
|
|
375
|
+
workbookId
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
async moveWorkbook(workbookId, folderPath, index) {
|
|
379
|
+
await this.mutateTree({
|
|
380
|
+
kind: "move",
|
|
381
|
+
workbookId,
|
|
382
|
+
folderPath,
|
|
383
|
+
index
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
async createFolder(path) {
|
|
387
|
+
await this.withTreeLock(async () => {
|
|
388
|
+
const tree = await this.readTree();
|
|
389
|
+
const name = path[path.length - 1];
|
|
390
|
+
const parent = folderAt(tree, path.slice(0, -1));
|
|
391
|
+
if (name == null || parent == null) throw new Error(`There is no folder ${path.slice(0, -1).join("/")}`);
|
|
392
|
+
const error = this.core.folderNameError(name, parent.folders.map((folder) => folder.name));
|
|
393
|
+
if (error != null) throw new Error(error);
|
|
394
|
+
await this.writeFolderFile(path, []);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
async moveFolder(path, parentPath, name = path[path.length - 1] ?? "") {
|
|
398
|
+
await this.withTreeLock(async () => {
|
|
399
|
+
const tree = await this.readTree();
|
|
400
|
+
const parent = folderAt(tree, parentPath);
|
|
401
|
+
if (path.length === 0 || folderAt(tree, path) == null) throw new Error(`There is no folder ${path.join("/")}`);
|
|
402
|
+
if (parent == null) throw new Error(`There is no folder ${parentPath.join("/")}`);
|
|
403
|
+
if (isFolderPathWithin(parentPath, path)) throw new Error("A folder cannot move into itself");
|
|
404
|
+
const sameParent = sameFolderPath(parentPath, path.slice(0, -1));
|
|
405
|
+
const oldName = path[path.length - 1];
|
|
406
|
+
if (sameParent && name === oldName) return;
|
|
407
|
+
const siblings = parent.folders.map((folder) => folder.name).filter((sibling) => !(sameParent && sibling === oldName));
|
|
408
|
+
const error = this.core.folderNameError(name, siblings);
|
|
409
|
+
if (error != null) throw new Error(error);
|
|
410
|
+
if (sameParent && name.toLowerCase() === oldName.toLowerCase()) {
|
|
411
|
+
const detour = `${name}.${crypto.randomUUID()}`;
|
|
412
|
+
await this.copyFolderUnlocked(path, parentPath, detour);
|
|
413
|
+
await this.copyFolderUnlocked([...parentPath, detour], parentPath, name);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
await this.copyFolderUnlocked(path, parentPath, name);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
async deleteFolder(path) {
|
|
420
|
+
await this.withTreeLock(async () => {
|
|
421
|
+
const tree = await this.readTree(false);
|
|
422
|
+
const folder = folderAt(tree, path);
|
|
423
|
+
if (path.length === 0 || folder == null) throw new Error(`There is no folder ${path.join("/")}`);
|
|
424
|
+
const parentPath = path.slice(0, -1);
|
|
425
|
+
const parent = folderAt(tree, parentPath);
|
|
426
|
+
const moved = flattenWorkbookTree(folder);
|
|
427
|
+
if (moved.length > 0) await this.writeFolderFile(parentPath, [...parent.workbooks, ...moved]);
|
|
428
|
+
await (await this.folderDir(parentPath, false)).removeEntry(path[path.length - 1], { recursive: true });
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
async readTree(stored = true) {
|
|
432
|
+
const root = this.ensureInitialized();
|
|
433
|
+
let dir;
|
|
434
|
+
try {
|
|
435
|
+
dir = await root.getDirectoryHandle(STORAGE_WORKBOOK_TREE_FOLDER, { create: false });
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (error.name === "NotFoundError") return emptyWorkbookTree();
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
return this.core.readWorkbookTree(await listWorkbookTreeDirectory(dir), stored);
|
|
441
|
+
}
|
|
442
|
+
async mutateTree(change) {
|
|
443
|
+
await this.withTreeLock(async () => {
|
|
444
|
+
const { writes } = changeWorkbookTree(this.core, await this.readTree(), change);
|
|
445
|
+
for (const write of writes) await this.writeFolderText(write.path, write.text);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
async folderDir(path, create) {
|
|
449
|
+
let dir = await this.ensureInitialized().getDirectoryHandle(STORAGE_WORKBOOK_TREE_FOLDER, { create });
|
|
450
|
+
for (const name of path) dir = await dir.getDirectoryHandle(name, { create });
|
|
451
|
+
return dir;
|
|
452
|
+
}
|
|
453
|
+
async writeFolderFile(path, workbooks) {
|
|
454
|
+
await this.writeFolderText(path, JSON.stringify({ workbooks }, null, 2));
|
|
455
|
+
}
|
|
456
|
+
async writeFolderText(path, text) {
|
|
457
|
+
const writable = await (await (await this.folderDir(path, true)).getFileHandle(STORAGE_FOLDER_FILE, { create: true })).createWritable();
|
|
458
|
+
await writable.write(text);
|
|
459
|
+
await writable.close();
|
|
460
|
+
}
|
|
461
|
+
async copyFolderUnlocked(path, parentPath, name) {
|
|
462
|
+
await copyDirectory(await this.folderDir(path, false), await (await this.folderDir(parentPath, true)).getDirectoryHandle(name, { create: true }));
|
|
463
|
+
await (await this.folderDir(path.slice(0, -1), false)).removeEntry(path[path.length - 1], { recursive: true });
|
|
464
|
+
}
|
|
465
|
+
async getWorkbookDir(relativePath, create) {
|
|
466
|
+
const root = this.ensureInitialized();
|
|
467
|
+
const parts = relativePath.split("/");
|
|
468
|
+
let currentDir = root;
|
|
469
|
+
let accumulated = "";
|
|
470
|
+
for (const part of parts) if (part) {
|
|
471
|
+
accumulated = accumulated ? `${accumulated}/${part}` : part;
|
|
472
|
+
try {
|
|
473
|
+
currentDir = await currentDir.getDirectoryHandle(part, { create });
|
|
474
|
+
} catch (error) {
|
|
475
|
+
if (domErrorName(error) === "NotFoundError") throw new Error(`Directory not found: opfs://${accumulated}`, { cause: error });
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return currentDir;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
async function copyDirectory(source, target) {
|
|
483
|
+
for await (const [name, handle] of source.entries()) {
|
|
484
|
+
if (handle.kind === "directory") {
|
|
485
|
+
await copyDirectory(handle, await target.getDirectoryHandle(name, { create: true }));
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const file = await handle.getFile();
|
|
489
|
+
const writable = await (await target.getFileHandle(name, { create: true })).createWritable();
|
|
490
|
+
await writable.write(file);
|
|
491
|
+
await writable.close();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
export { OPFSStorageBackend, OPFS_MANIFEST_LOCK, OPFS_WORKBOOK_TREE_LOCK };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StorageBackendType, type WorkbookEntry } from './storage_backend.js';
|
|
2
|
+
export interface WorkbookLocation {
|
|
3
|
+
type: StorageBackendType;
|
|
4
|
+
nativePath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function locationFromEntry(entry: WorkbookEntry): WorkbookLocation;
|
|
7
|
+
export declare function displayPath(uuid: string, loc: WorkbookLocation): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { STORAGE_WORKBOOKS_FOLDER, StorageBackendType } from "./storage_backend.js";
|
|
2
|
+
// dist/.stage/src/platform/storage/workbook_locator.ts
|
|
3
|
+
function locationFromEntry(entry) {
|
|
4
|
+
if (entry.storageType === StorageBackendType.Native && entry.nativePath) return {
|
|
5
|
+
type: StorageBackendType.Native,
|
|
6
|
+
nativePath: entry.nativePath
|
|
7
|
+
};
|
|
8
|
+
return { type: StorageBackendType.OPFS };
|
|
9
|
+
}
|
|
10
|
+
function displayPath(uuid, loc) {
|
|
11
|
+
if (loc.type === StorageBackendType.Native && loc.nativePath) return `fs://${loc.nativePath}`;
|
|
12
|
+
return `opfs://${STORAGE_WORKBOOKS_FOLDER}/${uuid}`;
|
|
13
|
+
}
|
|
14
|
+
export { displayPath, locationFromEntry };
|
|
@@ -14,8 +14,7 @@ export declare const WORKBOOK_TABLE_NAMES: readonly ["workbook", "workbook_conne
|
|
|
14
14
|
export type WorkbookTableName = typeof WORKBOOK_TABLE_NAMES[number];
|
|
15
15
|
export type WorkbookTableColumnType = core.WorkbookTableColumnType;
|
|
16
16
|
export type WorkbookTableColumn = core.WorkbookTableColumn;
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function workbookTableColumns(name: WorkbookTableName): WorkbookTableColumn[];
|
|
17
|
+
export declare function workbookTableColumns(instance: core.DashQL, name: WorkbookTableName): WorkbookTableColumn[];
|
|
19
18
|
export interface WorkbookRow {
|
|
20
19
|
workbook_id: string;
|
|
21
20
|
format_version: number;
|
|
@@ -88,5 +87,3 @@ export interface WorkbookTables {
|
|
|
88
87
|
data: Map<string, DataTableFile>;
|
|
89
88
|
}
|
|
90
89
|
export declare function emptyWorkbookTables(): WorkbookTables;
|
|
91
|
-
export declare function newDataTableName(prefix: typeof ATTACHMENT_TABLE_PREFIX | typeof RESULT_TABLE_PREFIX): string;
|
|
92
|
-
export declare function isDataTableName(name: string): boolean;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { DashQL } from "../../core/api.js";
|
|
2
|
-
import "../../core/index.js";
|
|
3
1
|
// dist/.stage/src/platform/storage/workbook_tables.ts
|
|
4
2
|
var WORKBOOK_TABLE = "workbook";
|
|
5
3
|
var CONNECTIONS_TABLE = "workbook_connections";
|
|
@@ -23,14 +21,8 @@ var WORKBOOK_TABLE_NAMES = [
|
|
|
23
21
|
ATTACHMENTS_TABLE,
|
|
24
22
|
RESULTS_TABLE
|
|
25
23
|
];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
schemas ??= instance.workbookTables();
|
|
29
|
-
}
|
|
30
|
-
function workbookTableColumns(name) {
|
|
31
|
-
schemas ??= DashQL.instantiated()?.workbookTables() ?? null;
|
|
32
|
-
if (schemas == null) throw new Error("The columns of the workbook tables need the core, which is not instantiated yet");
|
|
33
|
-
const table = schemas.find((table) => table.name === name);
|
|
24
|
+
function workbookTableColumns(instance, name) {
|
|
25
|
+
const table = instance.workbookTables().find((table) => table.name === name);
|
|
34
26
|
if (table == null) throw new Error(`Unknown workbook table ${name}`);
|
|
35
27
|
return table.columns;
|
|
36
28
|
}
|
|
@@ -48,10 +40,4 @@ function emptyWorkbookTables() {
|
|
|
48
40
|
data: /* @__PURE__ */ new Map()
|
|
49
41
|
};
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
return `${prefix}${crypto.randomUUID().replace(/-/g, "")}`;
|
|
53
|
-
}
|
|
54
|
-
function isDataTableName(name) {
|
|
55
|
-
return /^workbook_(attachment|result)_[0-9a-f]{32}$/.test(name);
|
|
56
|
-
}
|
|
57
|
-
export { ATTACHMENTS_TABLE, ATTACHMENT_TABLE_PREFIX, CATALOG_COLUMNS_TABLE, CATALOG_FUNCTIONS_TABLE, CATALOG_FUNCTION_PARAMS_TABLE, CATALOG_TABLES_TABLE, CONNECTIONS_TABLE, RESULTS_TABLE, RESULT_TABLE_PREFIX, SCRIPTS_TABLE, WORKBOOK_TABLE, WORKBOOK_TABLE_NAMES, emptyWorkbookTables, isDataTableName, newDataTableName, provideWorkbookTables, workbookTableColumns };
|
|
43
|
+
export { ATTACHMENTS_TABLE, ATTACHMENT_TABLE_PREFIX, CATALOG_COLUMNS_TABLE, CATALOG_FUNCTIONS_TABLE, CATALOG_FUNCTION_PARAMS_TABLE, CATALOG_TABLES_TABLE, CONNECTIONS_TABLE, RESULTS_TABLE, RESULT_TABLE_PREFIX, SCRIPTS_TABLE, WORKBOOK_TABLE, WORKBOOK_TABLE_NAMES, emptyWorkbookTables, workbookTableColumns };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Logger } from '../logger/logger.js';
|
|
2
|
+
import type { StorageBackend } from './storage_backend.js';
|
|
3
|
+
export interface WorkbookTransferResult {
|
|
4
|
+
workbookCount: number;
|
|
5
|
+
fileCount: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function copyWorkbook(workbookId: string, source: StorageBackend, target: StorageBackend, logger: Logger): Promise<WorkbookTransferResult>;
|
|
8
|
+
export declare function cloneWorkbook(sourceWorkbookId: string, source: StorageBackend, target: StorageBackend, newWorkbookId: string, logger: Logger): Promise<WorkbookTransferResult>;
|
|
9
|
+
export declare function verifyWorkbook(workbookId: string, source: StorageBackend, target: StorageBackend): Promise<boolean>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// dist/.stage/src/platform/storage/workbook_transfer.ts
|
|
2
|
+
var LOG_CTX = "workbook_transfer";
|
|
3
|
+
async function copyWorkbook(workbookId, source, target, logger) {
|
|
4
|
+
let fileCount = 0;
|
|
5
|
+
const workbookData = await source.loadWorkbook(workbookId);
|
|
6
|
+
await target.saveWorkbookManifest(workbookId, workbookData);
|
|
7
|
+
fileCount++;
|
|
8
|
+
for (const script of await source.loadScripts(workbookId)) {
|
|
9
|
+
await target.saveScript(workbookId, script.name, script.sql);
|
|
10
|
+
fileCount++;
|
|
11
|
+
}
|
|
12
|
+
for (const file of await source.listDataFiles(workbookId)) {
|
|
13
|
+
await target.saveDataFile(workbookId, file.name, await source.loadDataFile(workbookId, file.name));
|
|
14
|
+
fileCount++;
|
|
15
|
+
}
|
|
16
|
+
logger.info("copied workbook", {
|
|
17
|
+
workbookId,
|
|
18
|
+
files: String(fileCount)
|
|
19
|
+
}, LOG_CTX);
|
|
20
|
+
return {
|
|
21
|
+
workbookCount: 1,
|
|
22
|
+
fileCount
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function cloneWorkbook(sourceWorkbookId, source, target, newWorkbookId, logger) {
|
|
26
|
+
let fileCount = 0;
|
|
27
|
+
try {
|
|
28
|
+
const workbookData = {
|
|
29
|
+
...await source.loadWorkbook(sourceWorkbookId),
|
|
30
|
+
workbookId: newWorkbookId
|
|
31
|
+
};
|
|
32
|
+
delete workbookData.workbookPath;
|
|
33
|
+
const trimmedName = workbookData.name?.trim();
|
|
34
|
+
if (trimmedName) workbookData.name = `${trimmedName} (copy)`;
|
|
35
|
+
await target.saveWorkbookManifest(newWorkbookId, workbookData);
|
|
36
|
+
fileCount++;
|
|
37
|
+
for (const script of await source.loadScripts(sourceWorkbookId)) {
|
|
38
|
+
await target.saveScript(newWorkbookId, script.name, script.sql);
|
|
39
|
+
fileCount++;
|
|
40
|
+
}
|
|
41
|
+
for (const file of await source.listDataFiles(sourceWorkbookId)) {
|
|
42
|
+
await target.saveDataFile(newWorkbookId, file.name, await source.loadDataFile(sourceWorkbookId, file.name));
|
|
43
|
+
fileCount++;
|
|
44
|
+
}
|
|
45
|
+
logger.info("cloned workbook", {
|
|
46
|
+
sourceWorkbookId,
|
|
47
|
+
workbookId: newWorkbookId,
|
|
48
|
+
files: String(fileCount)
|
|
49
|
+
}, LOG_CTX);
|
|
50
|
+
return {
|
|
51
|
+
workbookCount: 1,
|
|
52
|
+
fileCount
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
try {
|
|
56
|
+
await target.deleteWorkbook(newWorkbookId);
|
|
57
|
+
} catch {}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function verifyWorkbook(workbookId, source, target) {
|
|
62
|
+
let targetData;
|
|
63
|
+
try {
|
|
64
|
+
targetData = await target.loadWorkbook(workbookId);
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (!targetData.workbookId) return false;
|
|
69
|
+
if ((await source.loadScripts(workbookId)).length !== (await target.loadScripts(workbookId)).length) return false;
|
|
70
|
+
try {
|
|
71
|
+
const sourceFiles = await source.listDataFiles(workbookId);
|
|
72
|
+
const targetFiles = await target.listDataFiles(workbookId);
|
|
73
|
+
if (sourceFiles.length !== targetFiles.length) return false;
|
|
74
|
+
for (const file of sourceFiles) {
|
|
75
|
+
const sourceBytes = await source.loadDataFile(workbookId, file.name);
|
|
76
|
+
const targetBytes = await target.loadDataFile(workbookId, file.name);
|
|
77
|
+
if (sourceBytes.length !== targetBytes.length || !sourceBytes.every((byte, i) => byte === targetBytes[i])) return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export { cloneWorkbook, copyWorkbook, verifyWorkbook };
|