@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.
Files changed (109) hide show
  1. package/README.md +1 -2
  2. package/dist/core/api.d.ts +24 -18
  3. package/dist/core/api.js +42 -46
  4. package/dist/core/connection.d.ts +1 -1
  5. package/dist/core/index.d.ts +0 -4
  6. package/dist/core/index.js +1 -4
  7. package/dist/core/runtime.d.ts +1 -1
  8. package/dist/core/workbook.d.ts +1 -1
  9. package/dist/platform/compute/arrow_formatter.d.ts +3 -1
  10. package/dist/platform/compute/arrow_formatter.js +23 -20
  11. package/dist/platform/compute/computation_types.d.ts +7 -12
  12. package/dist/platform/compute/computation_types.js +6 -3
  13. package/dist/platform/compute/query_result_search_sql.d.ts +0 -7
  14. package/dist/platform/compute/query_result_search_sql.js +1 -19
  15. package/dist/platform/connections/connection_params.d.ts +5 -6
  16. package/dist/platform/connections/connection_params.js +14 -25
  17. package/dist/platform/connections/connection_state.d.ts +1 -1
  18. package/dist/platform/connections/connector_configs.d.ts +2 -3
  19. package/dist/platform/connections/connector_info.d.ts +4 -14
  20. package/dist/platform/connections/connector_info.js +1 -25
  21. package/dist/platform/connections/embedded_database_channel.d.ts +3 -3
  22. package/dist/platform/connections/embedded_database_channel.js +12 -6
  23. package/dist/platform/connections/hyper/hyper_error_info.d.ts +0 -15
  24. package/dist/platform/connections/hyper/hyper_error_info.js +1 -18
  25. package/dist/platform/connections/query_execution.js +9 -7
  26. package/dist/platform/connections/query_execution_args.d.ts +2 -2
  27. package/dist/platform/http_client.d.ts +1 -1
  28. package/dist/platform/logger/logger.d.ts +3 -3
  29. package/dist/platform/query/query_execution_state.d.ts +11 -38
  30. package/dist/platform/query/query_execution_state.js +6 -1
  31. package/dist/platform/query/query_progress.d.ts +0 -14
  32. package/dist/platform/query/query_result_cache.d.ts +2 -2
  33. package/dist/platform/storage/composite_storage_backend.d.ts +64 -0
  34. package/dist/platform/storage/composite_storage_backend.js +321 -0
  35. package/dist/platform/storage/native_storage_backend.d.ts +1 -1
  36. package/dist/platform/storage/native_storage_backend.js +1 -1
  37. package/dist/platform/storage/opfs_query_result_cache.d.ts +0 -2
  38. package/dist/platform/storage/opfs_query_result_cache.js +3 -5
  39. package/dist/platform/storage/opfs_storage_backend.d.ts +67 -0
  40. package/dist/platform/storage/opfs_storage_backend.js +494 -0
  41. package/dist/platform/storage/workbook_locator.d.ts +7 -0
  42. package/dist/platform/storage/workbook_locator.js +14 -0
  43. package/dist/platform/storage/workbook_tables.d.ts +1 -4
  44. package/dist/platform/storage/workbook_tables.js +3 -17
  45. package/dist/platform/storage/workbook_transfer.d.ts +9 -0
  46. package/dist/platform/storage/workbook_transfer.js +84 -0
  47. package/dist/platform/storage/workbook_tree.d.ts +30 -9
  48. package/dist/platform/storage/workbook_tree.js +17 -96
  49. package/dist/platform/utils/base64.js +4 -4
  50. package/dist/platform/web_http_client.d.ts +1 -4
  51. package/dist/platform/web_http_client.js +0 -5
  52. package/dist/platform/workbook/attachment_mounts.d.ts +12 -4
  53. package/dist/platform/workbook/attachment_mounts.js +69 -60
  54. package/dist/platform/workbook/run_events.js +1 -1
  55. package/dist/platform/workbook/script_compilation.d.ts +0 -1
  56. package/dist/platform/workbook/script_compilation.js +1 -14
  57. package/dist/platform/workbook/script_reference_check.js +7 -6
  58. package/dist/platform/workbook/script_types.d.ts +1 -1
  59. package/dist/platform/workbook/script_types.js +1 -10
  60. package/dist/platform/workbook/workbook_execution.d.ts +0 -2
  61. package/dist/platform/workbook/workbook_execution.js +1 -4
  62. package/dist/platform/workbook/workbook_inputs.d.ts +7 -7
  63. package/dist/platform/workbook/workbook_inputs.js +4 -4
  64. package/dist/platform/workbook/workbook_scripts.d.ts +2 -2
  65. package/dist/runtime/compute_platform.js +2 -2
  66. package/dist/runtime/node/node_platform.js +1 -1
  67. package/dist/runtime/platform_requests.js +1 -1
  68. package/dist/runtime/query/query_channels.d.ts +0 -2
  69. package/dist/runtime/query/query_channels.js +36 -55
  70. package/dist/runtime/run_mounts.d.ts +2 -1
  71. package/dist/runtime/run_mounts.js +4 -5
  72. package/dist/runtime/runtime.d.ts +3 -0
  73. package/dist/runtime/runtime.js +10 -6
  74. package/dist/runtime/runtime_storage.d.ts +2 -5
  75. package/dist/runtime/runtime_storage.js +4 -13
  76. package/dist/runtime/workbook_projection.js +2 -2
  77. package/dist/runtime/workbook_run_report.d.ts +3 -6
  78. package/dist/runtime/workbook_run_report.js +33 -47
  79. package/dist/wasm/dashql_core.d.ts +2363 -2090
  80. package/dist/wasm/dashql_core.js +362 -222
  81. package/dist/wasm/dashql_core.wasm +0 -0
  82. package/dist/wasm/dashql_dataflow.wasm +0 -0
  83. package/package.json +1 -1
  84. package/dist/core/format.d.ts +0 -4
  85. package/dist/core/format.js +0 -23
  86. package/dist/core/lookup.d.ts +0 -10
  87. package/dist/core/lookup.js +0 -129
  88. package/dist/core/tokens.d.ts +0 -9
  89. package/dist/core/tokens.js +0 -78
  90. package/dist/core/variant.d.ts +0 -4
  91. package/dist/core/variant.js +0 -0
  92. package/dist/platform/connections/hyper/local_cloud.d.ts +0 -15
  93. package/dist/platform/connections/hyper/local_cloud.js +0 -14
  94. package/dist/platform/connections/query_channel.d.ts +0 -3
  95. package/dist/platform/connections/query_channel.js +0 -11
  96. package/dist/platform/hyper_link_target.d.ts +0 -8
  97. package/dist/platform/hyper_link_target.js +0 -35
  98. package/dist/platform/sql/sql_format.d.ts +0 -9
  99. package/dist/platform/sql/sql_format.js +0 -40
  100. package/dist/platform/sql/sql_lint.d.ts +0 -27
  101. package/dist/platform/sql/sql_lint.js +0 -69
  102. package/dist/platform/sql/sql_report.d.ts +0 -18
  103. package/dist/platform/sql/sql_report.js +0 -80
  104. package/dist/platform/storage/storage_versions.d.ts +0 -3
  105. package/dist/platform/storage/storage_versions.js +0 -13
  106. package/dist/platform/utils/async_consumer.d.ts +0 -14
  107. package/dist/platform/utils/async_consumer.js +0 -24
  108. package/dist/platform/workbook/attachment_mirror.d.ts +0 -2
  109. package/dist/platform/workbook/attachment_mirror.js +0 -25
@@ -1,4 +1,5 @@
1
1
  import type * as app_folder from '../../gen/jsonschema/app_folder.js';
2
+ import type * as core from '../../core/index.js';
2
3
  export declare const STORAGE_WORKBOOK_TREE_FOLDER = "workbooktree";
3
4
  export declare const STORAGE_FOLDER_FILE = "dashql-folder.json";
4
5
  export declare const INITIAL_WORKBOOK_FOLDER: readonly string[];
@@ -10,20 +11,40 @@ export interface WorkbookTreeFolder {
10
11
  folders: WorkbookTreeFolder[];
11
12
  workbooks: WorkbookEntry[];
12
13
  }
14
+ export interface WorkbookTreeDirectory {
15
+ name: string;
16
+ folderFile: string | null;
17
+ directories: WorkbookTreeDirectory[];
18
+ }
19
+ export type WorkbookTreeChange = {
20
+ kind: 'upsert';
21
+ entry: WorkbookEntry;
22
+ folderPath?: readonly string[];
23
+ } | {
24
+ kind: 'remove';
25
+ workbookId: string;
26
+ } | {
27
+ kind: 'move';
28
+ workbookId: string;
29
+ folderPath: readonly string[];
30
+ index: number;
31
+ };
32
+ export interface FolderFileWrite {
33
+ path: string[];
34
+ text: string;
35
+ }
13
36
  export declare function emptyWorkbookTree(): WorkbookTreeFolder;
14
- export declare function compareFolderNames(left: string, right: string): number;
15
37
  export declare function sameFolderPath(left: readonly string[], right: readonly string[]): boolean;
16
38
  export declare function isFolderPathWithin(path: readonly string[], ancestor: readonly string[]): boolean;
17
39
  export declare function flattenWorkbookTree(folder: WorkbookTreeFolder): WorkbookEntry[];
18
40
  export declare function folderAt(tree: WorkbookTreeFolder, path: readonly string[]): WorkbookTreeFolder | null;
19
41
  export declare function findWorkbookFolder(tree: WorkbookTreeFolder, workbookId: string): string[] | null;
20
- export declare function folderNameError(name: string, siblings: readonly string[]): string | null;
21
- export declare function dropDuplicateWorkbooks(tree: WorkbookTreeFolder): WorkbookTreeFolder;
22
- export declare function removeWorkbookFromTree(tree: WorkbookTreeFolder, workbookId: string): WorkbookTreeFolder;
23
- export declare function upsertWorkbookInTree(tree: WorkbookTreeFolder, entry: WorkbookEntry, folderPath?: readonly string[]): WorkbookTreeFolder;
24
- export declare function moveWorkbookInTree(tree: WorkbookTreeFolder, workbookId: string, folderPath: readonly string[], index: number): WorkbookTreeFolder;
25
42
  export declare function listFolders(tree: WorkbookTreeFolder): WorkbookTreeFolder[];
26
43
  export declare function folderPathKey(path: readonly string[]): string;
27
- export declare function readWorkbookTreeDirectory(dir: FileSystemDirectoryHandle, path?: string[]): Promise<WorkbookTreeFolder>;
28
- export declare function readWorkbookTree(root: FileSystemDirectoryHandle): Promise<WorkbookTreeFolder>;
29
- export declare function freeFolderName(siblings: readonly string[]): string;
44
+ export declare function changeWorkbookTree(instance: core.DashQL, stored: WorkbookTreeFolder, change: WorkbookTreeChange): {
45
+ tree: WorkbookTreeFolder;
46
+ writes: FolderFileWrite[];
47
+ };
48
+ export declare function applyWorkbookTreeChange(instance: core.DashQL, tree: WorkbookTreeFolder, change: WorkbookTreeChange): WorkbookTreeFolder;
49
+ export declare function listWorkbookTreeDirectory(dir: FileSystemDirectoryHandle, name?: string): Promise<WorkbookTreeDirectory>;
50
+ export declare function readWorkbookTree(instance: core.DashQL, root: FileSystemDirectoryHandle): Promise<WorkbookTreeFolder>;
@@ -10,12 +10,6 @@ function emptyWorkbookTree() {
10
10
  workbooks: []
11
11
  };
12
12
  }
13
- function compareFolderNames(left, right) {
14
- return left.localeCompare(right, void 0, {
15
- numeric: true,
16
- sensitivity: "base"
17
- });
18
- }
19
13
  function sameFolderPath(left, right) {
20
14
  return left.length === right.length && left.every((name, index) => name === right[index]);
21
15
  }
@@ -47,70 +41,6 @@ function findWorkbookFolder(tree, workbookId) {
47
41
  }
48
42
  return null;
49
43
  }
50
- function folderNameError(name, siblings) {
51
- if (name.length === 0) return "The folder needs a name";
52
- if (name === "." || name === ".." || /[/\\\0]/.test(name)) return `"${name}" is not a valid folder name`;
53
- const lower = name.toLowerCase();
54
- if (siblings.some((sibling) => sibling.toLowerCase() === lower)) return `There is already a folder "${name}"`;
55
- return null;
56
- }
57
- function dropDuplicateWorkbooks(tree) {
58
- const seen = /* @__PURE__ */ new Set();
59
- const visit = (folder) => {
60
- const folders = folder.folders.map(visit);
61
- const workbooks = folder.workbooks.filter((entry) => {
62
- if (seen.has(entry.path)) return false;
63
- seen.add(entry.path);
64
- return true;
65
- });
66
- return {
67
- ...folder,
68
- folders,
69
- workbooks
70
- };
71
- };
72
- return visit(tree);
73
- }
74
- function replaceFolder(tree, path, replace) {
75
- if (path.length === 0) return replace(tree);
76
- const [head, ...rest] = path;
77
- return {
78
- ...tree,
79
- folders: tree.folders.map((folder) => folder.name === head ? replaceFolder(folder, rest, replace) : folder)
80
- };
81
- }
82
- function removeWorkbookFromTree(tree, workbookId) {
83
- const visit = (folder) => ({
84
- ...folder,
85
- folders: folder.folders.map(visit),
86
- workbooks: folder.workbooks.filter((entry) => entry.path !== workbookId)
87
- });
88
- return visit(tree);
89
- }
90
- function upsertWorkbookInTree(tree, entry, folderPath = []) {
91
- const current = findWorkbookFolder(tree, entry.path);
92
- if (current != null) return replaceFolder(tree, current, (folder) => ({
93
- ...folder,
94
- workbooks: folder.workbooks.map((existing) => existing.path === entry.path ? entry : existing)
95
- }));
96
- return replaceFolder(tree, folderAt(tree, folderPath) != null ? folderPath : [], (folder) => ({
97
- ...folder,
98
- workbooks: [...folder.workbooks, entry]
99
- }));
100
- }
101
- function moveWorkbookInTree(tree, workbookId, folderPath, index) {
102
- if (folderAt(tree, folderPath) == null) return tree;
103
- const from = findWorkbookFolder(tree, workbookId);
104
- const entry = from == null ? { path: workbookId } : folderAt(tree, from).workbooks.find((workbook) => workbook.path === workbookId);
105
- return replaceFolder(removeWorkbookFromTree(tree, workbookId), folderPath, (folder) => {
106
- const workbooks = [...folder.workbooks];
107
- workbooks.splice(Math.max(0, Math.min(index, workbooks.length)), 0, entry);
108
- return {
109
- ...folder,
110
- workbooks
111
- };
112
- });
113
- }
114
44
  function listFolders(tree) {
115
45
  const folders = [];
116
46
  const visit = (folder) => {
@@ -123,20 +53,23 @@ function listFolders(tree) {
123
53
  function folderPathKey(path) {
124
54
  return JSON.stringify(path);
125
55
  }
126
- async function readWorkbookTreeDirectory(dir, path = []) {
127
- const folders = [];
128
- let workbooks = [];
129
- for await (const [name, handle] of dir.entries()) if (handle.kind === "directory") folders.push(await readWorkbookTreeDirectory(handle, [...path, name]));
130
- else if (name === "dashql-folder.json") workbooks = parseWorkbookFolderFile(await (await handle.getFile()).text(), path);
131
- folders.sort((left, right) => compareFolderNames(left.name, right.name));
132
- return {
133
- name: path[path.length - 1] ?? "",
134
- path,
135
- folders,
136
- workbooks
56
+ function changeWorkbookTree(instance, stored, change) {
57
+ return instance.changeWorkbookTree(stored, change);
58
+ }
59
+ function applyWorkbookTreeChange(instance, tree, change) {
60
+ return changeWorkbookTree(instance, tree, change).tree;
61
+ }
62
+ async function listWorkbookTreeDirectory(dir, name = "") {
63
+ const listed = {
64
+ name,
65
+ folderFile: null,
66
+ directories: []
137
67
  };
68
+ for await (const [entry, handle] of dir.entries()) if (handle.kind === "directory") listed.directories.push(await listWorkbookTreeDirectory(handle, entry));
69
+ else if (entry === "dashql-folder.json") listed.folderFile = await (await handle.getFile()).text();
70
+ return listed;
138
71
  }
139
- async function readWorkbookTree(root) {
72
+ async function readWorkbookTree(instance, root) {
140
73
  let dir;
141
74
  try {
142
75
  dir = await root.getDirectoryHandle(STORAGE_WORKBOOK_TREE_FOLDER, { create: false });
@@ -144,18 +77,6 @@ async function readWorkbookTree(root) {
144
77
  if (error.name === "NotFoundError") return emptyWorkbookTree();
145
78
  throw error;
146
79
  }
147
- return dropDuplicateWorkbooks(await readWorkbookTreeDirectory(dir));
148
- }
149
- function parseWorkbookFolderFile(text, path) {
150
- const workbooks = JSON.parse(text)?.workbooks;
151
- if (!Array.isArray(workbooks)) throw new Error(`Invalid ${STORAGE_WORKBOOK_TREE_FOLDER}/${[...path, STORAGE_FOLDER_FILE].join("/")}: workbooks must be an array`);
152
- return workbooks.filter((entry) => typeof entry?.path === "string" && entry.path.length > 0);
153
- }
154
- function freeFolderName(siblings) {
155
- const taken = new Set(siblings.map((name) => name.toLowerCase()));
156
- if (!taken.has("new folder")) return "New folder";
157
- let n = 2;
158
- while (taken.has(`new folder ${n}`)) ++n;
159
- return `New folder ${n}`;
80
+ return instance.readWorkbookTree(await listWorkbookTreeDirectory(dir));
160
81
  }
161
- export { INITIAL_WORKBOOK_FOLDER, STORAGE_FOLDER_FILE, STORAGE_WORKBOOK_TREE_FOLDER, compareFolderNames, dropDuplicateWorkbooks, emptyWorkbookTree, findWorkbookFolder, flattenWorkbookTree, folderAt, folderNameError, folderPathKey, freeFolderName, isFolderPathWithin, listFolders, moveWorkbookInTree, readWorkbookTree, readWorkbookTreeDirectory, removeWorkbookFromTree, sameFolderPath, upsertWorkbookInTree };
82
+ export { INITIAL_WORKBOOK_FOLDER, STORAGE_FOLDER_FILE, STORAGE_WORKBOOK_TREE_FOLDER, applyWorkbookTreeChange, changeWorkbookTree, emptyWorkbookTree, findWorkbookFolder, flattenWorkbookTree, folderAt, folderPathKey, isFolderPathWithin, listFolders, listWorkbookTreeDirectory, readWorkbookTree, sameFolderPath };
@@ -69,13 +69,13 @@ var Base64Codec = class {
69
69
  const encoded2 = this.lookupTable[base64.charCodeAt(reader + 1)];
70
70
  const encoded3 = this.lookupTable[base64.charCodeAt(reader + 2)];
71
71
  bytes[writer++] = encoded1 << 2 | encoded2 >> 4;
72
- bytes[writer++] = (encoded2 & 15) << 4 | encoded3 >> 2;
72
+ bytes[writer] = (encoded2 & 15) << 4 | encoded3 >> 2;
73
73
  break;
74
74
  }
75
75
  case 2: {
76
76
  const encoded1 = this.lookupTable[base64.charCodeAt(reader)];
77
77
  const encoded2 = this.lookupTable[base64.charCodeAt(reader + 1)];
78
- bytes[writer++] = encoded1 << 2 | encoded2 >> 4;
78
+ bytes[writer] = encoded1 << 2 | encoded2 >> 4;
79
79
  break;
80
80
  }
81
81
  }
@@ -144,13 +144,13 @@ var Base64UrlCodec = class {
144
144
  const encoded2 = this.lookupTable[base64.charCodeAt(reader + 1)];
145
145
  const encoded3 = this.lookupTable[base64.charCodeAt(reader + 2)];
146
146
  bytes[writer++] = encoded1 << 2 | encoded2 >> 4;
147
- bytes[writer++] = (encoded2 & 15) << 4 | encoded3 >> 2;
147
+ bytes[writer] = (encoded2 & 15) << 4 | encoded3 >> 2;
148
148
  break;
149
149
  }
150
150
  case 2: {
151
151
  const encoded1 = this.lookupTable[base64.charCodeAt(reader)];
152
152
  const encoded2 = this.lookupTable[base64.charCodeAt(reader + 1)];
153
- bytes[writer++] = encoded1 << 2 | encoded2 >> 4;
153
+ bytes[writer] = encoded1 << 2 | encoded2 >> 4;
154
154
  break;
155
155
  }
156
156
  }
@@ -1,7 +1,4 @@
1
- import { ClientOptions, HttpClient, HttpFetchResult } from './http_client.js';
2
- import { Logger } from './logger/logger.js';
1
+ import type { ClientOptions, HttpClient, HttpFetchResult } from './http_client.js';
3
2
  export declare class WebHttpClient implements HttpClient {
4
- logger: Logger;
5
- constructor(logger: Logger);
6
3
  fetch(input: URL | Request | string, init?: RequestInit & ClientOptions): Promise<HttpFetchResult>;
7
4
  }
@@ -1,11 +1,6 @@
1
1
  // dist/.stage/src/platform/web_http_client.ts
2
2
  var WebHttpClient = class {
3
- logger;
4
- constructor(logger) {
5
- this.logger = logger;
6
- }
7
3
  async fetch(input, init) {
8
- if (input instanceof Request) return await fetch(input, init);
9
4
  return await fetch(input, init);
10
5
  }
11
6
  };
@@ -1,6 +1,14 @@
1
1
  import type { ParquetDatabase } from '../hyperdb/hyperdb_parquet_export.js';
2
2
  export type AttachmentFiles = ReadonlyMap<string, Blob>;
3
- export declare function mountWorkbookAttachments(database: ParquetDatabase, workbookId: string, files?: AttachmentFiles | null, getRoot?: () => Promise<FileSystemDirectoryHandle>): Promise<string>;
4
- export declare function markWorkbookAttachmentsChanged(workbookId: string): void;
5
- export declare function unmountWorkbookAttachments(workbookId: string): Promise<void>;
6
- export declare function readAttachmentColumns(database: ParquetDatabase, workbookId: string, fileName: string, files?: AttachmentFiles | null): Promise<string[]>;
3
+ export declare class AttachmentMounts {
4
+ private readonly getRoot;
5
+ private readonly mounts;
6
+ private pending;
7
+ constructor(getRoot?: () => Promise<FileSystemDirectoryHandle>);
8
+ private serialize;
9
+ mount(database: ParquetDatabase, workbookId: string, files?: AttachmentFiles | null): Promise<string>;
10
+ changed(workbookId: string): void;
11
+ unmount(workbookId: string): Promise<void>;
12
+ unmountAll(): Promise<void>;
13
+ readColumns(database: ParquetDatabase, workbookId: string, fileName: string, files?: AttachmentFiles | null): Promise<string[]>;
14
+ }
@@ -7,67 +7,76 @@ function sameFiles(left, right) {
7
7
  if (left == null || right == null) return left === right;
8
8
  return left.size === right.size && [...left].every(([name, file]) => right.get(name) === file);
9
9
  }
10
- var MOUNTS = /* @__PURE__ */ new Map();
11
- var pending = Promise.resolve();
12
- function serialize(f) {
13
- const next = pending.then(f, f);
14
- pending = next.catch(() => {});
15
- return next;
16
- }
17
- function mountWorkbookAttachments(database, workbookId, files = null, getRoot = getOPFSRoot) {
18
- return serialize(async () => {
19
- const path = attachmentPrefix(workbookId);
20
- let mount = MOUNTS.get(workbookId);
21
- if (mount != null && (mount.database !== database || !sameFiles(mount.files, files))) {
22
- await mount.database.removeExternalDirectory(path).catch(() => {});
23
- MOUNTS.delete(workbookId);
24
- mount = void 0;
25
- }
26
- if (mount == null) {
27
- if (files == null) {
28
- const folder = await (await (await (await getRoot()).getDirectoryHandle(STORAGE_WORKBOOKS_FOLDER, { create: true })).getDirectoryHandle(workbookId, { create: true })).getDirectoryHandle(STORAGE_ATTACHMENTS_FOLDER, { create: true });
29
- await database.registerExternalDirectory(folder, path, "read");
30
- } else {
31
- if (!supportsMemoryDirectories(database)) throw new Error("The compute database can not mount the attachments of a workbook in memory");
32
- await database.registerMemoryDirectory(Object.fromEntries(files), path);
10
+ var AttachmentMounts = class {
11
+ getRoot;
12
+ mounts = /* @__PURE__ */ new Map();
13
+ pending = Promise.resolve();
14
+ constructor(getRoot = getOPFSRoot) {
15
+ this.getRoot = getRoot;
16
+ }
17
+ serialize(f) {
18
+ const next = this.pending.then(f, f);
19
+ this.pending = next.catch(() => {});
20
+ return next;
21
+ }
22
+ mount(database, workbookId, files = null) {
23
+ return this.serialize(async () => {
24
+ const path = attachmentPrefix(workbookId);
25
+ let mount = this.mounts.get(workbookId);
26
+ if (mount != null && (mount.database !== database || !sameFiles(mount.files, files))) {
27
+ await mount.database.removeExternalDirectory(path).catch(() => {});
28
+ this.mounts.delete(workbookId);
29
+ mount = void 0;
33
30
  }
34
- MOUNTS.set(workbookId, {
35
- database,
36
- files,
37
- stale: false
38
- });
39
- } else if (mount.stale && mount.files == null) {
40
- mount.stale = false;
41
- try {
42
- await database.refreshExternalDirectory(path);
43
- } catch (error) {
44
- mount.stale = true;
45
- throw error;
31
+ if (mount == null) {
32
+ if (files == null) {
33
+ const folder = await (await (await (await this.getRoot()).getDirectoryHandle(STORAGE_WORKBOOKS_FOLDER, { create: true })).getDirectoryHandle(workbookId, { create: true })).getDirectoryHandle(STORAGE_ATTACHMENTS_FOLDER, { create: true });
34
+ await database.registerExternalDirectory(folder, path, "read");
35
+ } else {
36
+ if (!supportsMemoryDirectories(database)) throw new Error("The compute database can not mount the attachments of a workbook in memory");
37
+ await database.registerMemoryDirectory(Object.fromEntries(files), path);
38
+ }
39
+ this.mounts.set(workbookId, {
40
+ database,
41
+ files,
42
+ stale: false
43
+ });
44
+ } else if (mount.stale && mount.files == null) {
45
+ mount.stale = false;
46
+ try {
47
+ await database.refreshExternalDirectory(path);
48
+ } catch (error) {
49
+ mount.stale = true;
50
+ throw error;
51
+ }
46
52
  }
53
+ return path;
54
+ });
55
+ }
56
+ changed(workbookId) {
57
+ const mount = this.mounts.get(workbookId);
58
+ if (mount != null) mount.stale = true;
59
+ }
60
+ unmount(workbookId) {
61
+ return this.serialize(async () => {
62
+ const mount = this.mounts.get(workbookId);
63
+ if (mount == null) return;
64
+ this.mounts.delete(workbookId);
65
+ await mount.database.removeExternalDirectory(attachmentPrefix(workbookId)).catch(() => {});
66
+ });
67
+ }
68
+ async unmountAll() {
69
+ for (const workbookId of [...this.mounts.keys()]) await this.unmount(workbookId);
70
+ }
71
+ async readColumns(database, workbookId, fileName, files = null) {
72
+ await this.mount(database, workbookId, files);
73
+ const connection = await database.connect({ pooled: true });
74
+ try {
75
+ const path = attachmentPath(workbookId, fileName).replace(/'/g, "''");
76
+ return (await connection.query(`select * from external('${path}', format => 'parquet') limit 0`)).schema.fields.map((field) => field.name);
77
+ } finally {
78
+ await connection.close();
47
79
  }
48
- return path;
49
- });
50
- }
51
- function markWorkbookAttachmentsChanged(workbookId) {
52
- const mount = MOUNTS.get(workbookId);
53
- if (mount != null) mount.stale = true;
54
- }
55
- function unmountWorkbookAttachments(workbookId) {
56
- return serialize(async () => {
57
- const mount = MOUNTS.get(workbookId);
58
- if (mount == null) return;
59
- MOUNTS.delete(workbookId);
60
- await mount.database.removeExternalDirectory(attachmentPrefix(workbookId)).catch(() => {});
61
- });
62
- }
63
- async function readAttachmentColumns(database, workbookId, fileName, files = null) {
64
- await mountWorkbookAttachments(database, workbookId, files);
65
- const connection = await database.connect({ pooled: true });
66
- try {
67
- const path = attachmentPath(workbookId, fileName).replace(/'/g, "''");
68
- return (await connection.query(`select * from external('${path}', format => 'parquet') limit 0`)).schema.fields.map((field) => field.name);
69
- } finally {
70
- await connection.close();
71
80
  }
72
- }
73
- export { markWorkbookAttachmentsChanged, mountWorkbookAttachments, readAttachmentColumns, unmountWorkbookAttachments };
81
+ };
82
+ export { AttachmentMounts };
@@ -28,7 +28,7 @@ function decodeRunEvent(value) {
28
28
  if (value == null || typeof value !== "object" || typeof value.type !== "string") return null;
29
29
  const event = value;
30
30
  if (event.type === "script_chart") {
31
- let png = null;
31
+ let png;
32
32
  try {
33
33
  png = typeof event.png === "string" ? fromBase64(event.png) : null;
34
34
  } catch {
@@ -1,4 +1,3 @@
1
1
  import * as core from '../../core/index.js';
2
2
  import type { ResolvedVisualizeQuery } from './script_types.js';
3
- export declare function chartStatementId(scriptSession: core.DashQLScriptSessionReader): number | null;
4
3
  export declare function resolveCompiledVisualization(sql: string, visualization: core.buffers.execution.CompiledVisualizationT, statementId: number): ResolvedVisualizeQuery | null;
@@ -1,17 +1,4 @@
1
- import { FormattingDialect } from "../../gen/flatbuffers/dashql/buffers/formatting/formatting-dialect.js";
2
- import { FormattingMode } from "../../gen/flatbuffers/dashql/buffers/formatting/formatting-mode.js";
3
- import { FormattingConfigT } from "../../gen/flatbuffers/dashql/buffers/formatting/formatting-config.js";
4
- import { ConnectorType } from "../../wasm/dashql_core.js";
5
- import "../../core/index.js";
6
- import "../connections/connector_info.js";
7
1
  // dist/.stage/src/platform/workbook/script_compilation.ts
8
- function executionFormattingConfig(connectorType) {
9
- return new FormattingConfigT(connectorType === ConnectorType.TRINO ? FormattingDialect.TRINO : FormattingDialect.HYPER, FormattingMode.INLINE, 120, 2, false);
10
- }
11
- function chartStatementId(scriptSession) {
12
- const statementId = scriptSession.compileQuery(executionFormattingConfig(ConnectorType.HYPER)).read().terminalStatementId();
13
- return statementId === 4294967295 ? null : statementId;
14
- }
15
2
  function resolveCompiledVisualization(sql, visualization, statementId) {
16
3
  const dashboardSpec = visualization.dashboard ?? null;
17
4
  switch (visualization.renderer) {
@@ -49,4 +36,4 @@ function resolveCompiledVisualization(sql, visualization, statementId) {
49
36
  default: return null;
50
37
  }
51
38
  }
52
- export { chartStatementId, resolveCompiledVisualization };
39
+ export { resolveCompiledVisualization };
@@ -9,6 +9,12 @@ var ScriptReferenceKind = /* @__PURE__ */ function(ScriptReferenceKind) {
9
9
  ScriptReferenceKind["Attachment"] = "attachment";
10
10
  return ScriptReferenceKind;
11
11
  }({});
12
+ var REFERENCE_KINDS = {
13
+ [ScriptReferenceKind$1.INLINE]: ScriptReferenceKind.Inline,
14
+ [ScriptReferenceKind$1.SCAN]: ScriptReferenceKind.Scan,
15
+ [ScriptReferenceKind$1.INVALID]: ScriptReferenceKind.Invalid,
16
+ [ScriptReferenceKind$1.ATTACHMENT]: ScriptReferenceKind.Attachment
17
+ };
12
18
  function sameReport(l, r) {
13
19
  return l.textVersion === r.textVersion && l.marks.length === r.marks.length && l.marks.every((m, i) => {
14
20
  const o = r.marks[i];
@@ -28,18 +34,13 @@ function readScriptReferenceReports(check, scriptKeys, files, attachments, prev)
28
34
  const marks = checked.references.map((reference) => {
29
35
  const span = reference.textSpan;
30
36
  const from = span?.offset ?? 0;
31
- let kind;
32
- if (reference.errors.length > 0 || reference.kind === ScriptReferenceKind$1.INVALID) kind = ScriptReferenceKind.Invalid;
33
- else if (reference.kind === ScriptReferenceKind$1.SCAN) kind = ScriptReferenceKind.Scan;
34
- else if (reference.kind === ScriptReferenceKind$1.ATTACHMENT) kind = ScriptReferenceKind.Attachment;
35
- else kind = ScriptReferenceKind.Inline;
36
37
  return {
37
38
  from,
38
39
  to: from + (span?.length ?? 0),
39
40
  parameter: String(reference.parameter ?? ""),
40
41
  target: reference.script !== NONE ? files[reference.script] ?? null : null,
41
42
  attachment: reference.attachment !== NONE ? attachments[reference.attachment] ?? null : null,
42
- kind,
43
+ kind: REFERENCE_KINDS[reference.kind] ?? ScriptReferenceKind.Inline,
43
44
  errors: reference.errors.map(String)
44
45
  };
45
46
  });
@@ -31,6 +31,7 @@ export interface ScriptAnnotations {
31
31
  visualizeQuery: ResolvedVisualizeQuery | null;
32
32
  flowPosition?: FlowPosition | null;
33
33
  boardPosition?: BoardPosition | null;
34
+ lastStatementId?: number | null;
34
35
  lastStatementIsQuery?: boolean;
35
36
  manual?: boolean;
36
37
  }
@@ -48,6 +49,5 @@ export interface ScriptRef {
48
49
  scriptId: number;
49
50
  fileName: string;
50
51
  }
51
- export declare function createEmptyAnnotations(): ScriptAnnotations;
52
52
  export declare function scriptDisplayName(fileName: string): string;
53
53
  export declare function createScriptRef(scriptId: number, fileName: string): ScriptRef;
@@ -1,13 +1,4 @@
1
1
  // dist/.stage/src/platform/workbook/script_types.ts
2
- function createEmptyAnnotations() {
3
- return {
4
- tableDefs: [],
5
- visualizeQuery: null,
6
- flowPosition: null,
7
- boardPosition: null,
8
- lastStatementIsQuery: false
9
- };
10
- }
11
2
  var SCRIPT_EXTENSION_RE = /\.sql$/i;
12
3
  function scriptDisplayName(fileName) {
13
4
  return fileName.replace(SCRIPT_EXTENSION_RE, "");
@@ -18,4 +9,4 @@ function createScriptRef(scriptId, fileName) {
18
9
  fileName
19
10
  };
20
11
  }
21
- export { createEmptyAnnotations, createScriptRef, scriptDisplayName };
12
+ export { createScriptRef, scriptDisplayName };
@@ -1,6 +1,4 @@
1
1
  import type * as core from '../../core/index.js';
2
- export type WorkbookExecutionState = core.WorkbookRunState;
3
- export declare function workbookExecutionIsBusy(state: WorkbookExecutionState | null | undefined): boolean;
4
2
  export type ScriptRunEvent = {
5
3
  type: 'planned';
6
4
  follows: string[];
@@ -1,8 +1,5 @@
1
1
  import { LoggableException } from "../logger/logger.js";
2
2
  // dist/.stage/src/platform/workbook/workbook_execution.ts
3
- function workbookExecutionIsBusy(state) {
4
- return state?.phase === "planning" || state?.phase === "running" || state?.phase === "stopping";
5
- }
6
3
  var ScriptPlanError = class extends Error {
7
4
  constructor(message) {
8
5
  super(message);
@@ -25,4 +22,4 @@ function scriptRunEvent(event, value) {
25
22
  };
26
23
  return event;
27
24
  }
28
- export { ScriptPlanError, scriptRunEvent, workbookExecutionIsBusy, workbookRunError };
25
+ export { ScriptPlanError, scriptRunEvent, workbookRunError };
@@ -16,23 +16,23 @@ export interface WorkbookInputType {
16
16
  cast: boolean;
17
17
  known: boolean;
18
18
  }
19
- export interface SessionInputConsumer {
19
+ export interface WorkbookInputConsumer {
20
20
  scriptKey: number;
21
21
  statementId: number;
22
22
  }
23
- export interface SessionInput {
23
+ export interface WorkbookInput {
24
24
  name: string;
25
25
  type: WorkbookInputType;
26
26
  value: string | null;
27
27
  literal: string | null;
28
- consumers: SessionInputConsumer[];
28
+ consumers: WorkbookInputConsumer[];
29
29
  warnings: string[];
30
30
  }
31
31
  export declare function readWorkbookInputType(type: core.buffers.analyzer.SqlTypeT | null, source: core.buffers.execution.SessionInputTypeSource): WorkbookInputType;
32
- export declare function readSessionInputs(collected: core.buffers.execution.SessionInputsT, scriptKeys: readonly number[]): SessionInput[];
33
- export declare function collectDraftInputs(instance: core.DashQL, draft: core.DashQLScriptSession, catalog: core.DashQLCatalog): SessionInput[];
34
- export declare function inputConsumerScripts(input: SessionInput): number[];
35
- export declare function sameInputs(l: SessionInput[], r: SessionInput[]): boolean;
32
+ export declare function readWorkbookInputs(collected: core.buffers.execution.SessionInputsT, scriptKeys: readonly number[]): WorkbookInput[];
33
+ export declare function collectDraftInputs(instance: core.DashQL, draft: core.DashQLScriptSession, catalog: core.DashQLCatalog): WorkbookInput[];
34
+ export declare function inputConsumerScripts(input: WorkbookInput): number[];
35
+ export declare function sameInputs(l: WorkbookInput[], r: WorkbookInput[]): boolean;
36
36
  export declare function workbookInputControl(type: WorkbookInputType): WorkbookInputControl;
37
37
  export declare function workbookInputLiteral(instance: core.DashQL, type: WorkbookInputType, value: string): {
38
38
  literal: string;
@@ -24,7 +24,7 @@ function readWorkbookInputType(type, source) {
24
24
  known: source !== SessionInputTypeSource.NONE
25
25
  };
26
26
  }
27
- function readSessionInputs(collected, scriptKeys) {
27
+ function readWorkbookInputs(collected, scriptKeys) {
28
28
  return collected.inputs.map((input) => ({
29
29
  name: String(input.name ?? ""),
30
30
  type: readWorkbookInputType(input.sqlType, input.typeSource),
@@ -54,7 +54,7 @@ function collectDraftInputs(instance, draft, catalog) {
54
54
  session: draft
55
55
  }]
56
56
  };
57
- return readSessionInputs(instance.collectSessionInputs(request).unpack(), []);
57
+ return readWorkbookInputs(instance.collectSessionInputs(request).unpack(), []);
58
58
  } catch (e) {
59
59
  console.warn("cannot collect the inputs of the draft", e);
60
60
  return NO_INPUTS;
@@ -88,7 +88,7 @@ function workbookInputLiteral(instance, type, value) {
88
88
  try {
89
89
  return { literal: instance.inputLiteral(value, type.known ? type.sql : null) };
90
90
  } catch (e) {
91
- return { error: String(e?.message ?? e) };
91
+ return { error: e instanceof Error ? e.message : String(e) };
92
92
  }
93
93
  }
94
- export { WorkbookInputControl, collectDraftInputs, inputConsumerScripts, readSessionInputs, readWorkbookInputType, sameInputs, workbookInputControl, workbookInputLiteral };
94
+ export { WorkbookInputControl, collectDraftInputs, inputConsumerScripts, readWorkbookInputType, readWorkbookInputs, sameInputs, workbookInputControl, workbookInputLiteral };
@@ -4,7 +4,7 @@ import type { DashQLPendingDiff } from './script_editor_state.js';
4
4
  import type { WorkbookCloudLink } from '../storage/storage_backend.js';
5
5
  import type { ScriptAnnotations, ScriptRef, WorkbookMetadata } from './script_types.js';
6
6
  import type { ScriptReferenceReport, ScriptTextChange } from './script_reference_check.js';
7
- import type { SessionInput } from './workbook_inputs.js';
7
+ import type { WorkbookInput } from './workbook_inputs.js';
8
8
  export type ScriptKey = number;
9
9
  export declare function scriptResultOwner(workbookId: string, scriptKey: ScriptKey): string;
10
10
  export interface WorkbookScripts extends Omit<core.WorkbookView, 'workbookMetadata'> {
@@ -42,7 +42,7 @@ export interface WorkbookDerived {
42
42
  scriptKeys: number[];
43
43
  references: Map<number, ScriptReferenceReport>;
44
44
  dataflow: core.buffers.execution.SessionDataflowT;
45
- inputs: SessionInput[];
45
+ inputs: WorkbookInput[];
46
46
  }
47
47
  export type WorkbookAction = core.WorkbookAction;
48
48
  export type ModifyWorkbookScripts = (action: WorkbookAction) => core.DispatchOutcome;
@@ -65,8 +65,8 @@ function createComputePlatform(database) {
65
65
  queryTable: async (sql, context) => {
66
66
  return await inRun(context.run, (signal) => withConnection(clientContextOf(context.clientContext), (conn) => conn.query(sql, signal)));
67
67
  },
68
- dropTable: async (_dataFrame, tableName) => {
69
- await withConnection(null, (conn) => conn.execute(`DROP TABLE IF EXISTS "${tableName}"`));
68
+ dropTable: async (_dataFrame, _tableName, sql) => {
69
+ await withConnection(null, (conn) => conn.execute(sql));
70
70
  },
71
71
  cancel: (run) => {
72
72
  for (const controller of runs.get(run) ?? []) controller.abort(new DOMException("The task was cancelled", "AbortError"));
@@ -14,7 +14,7 @@ async function createNodePlatform(options) {
14
14
  return {
15
15
  logger: options.logger,
16
16
  storage: options.storage,
17
- http: new WebHttpClient(options.logger),
17
+ http: new WebHttpClient(),
18
18
  scheduler: TASK_UPDATE_SCHEDULER,
19
19
  oauthFlow: options.oauthFlow ?? NO_OAUTH_FLOW,
20
20
  core: options.core ?? await createDashQLCoreSetup()("runtime")