@akohn/dashql 0.0.19-dev.268.g2efe9377d → 0.0.19-dev.299.g3adbd8a4b

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 CHANGED
@@ -151,6 +151,6 @@ and `NOTICE`. Both files are copied unchanged into the package; `NOTICE` is
151
151
  the repository-wide third-party notice.
152
152
  Source is available at <https://github.com/ankoh/dashql>, including this package
153
153
  under `packages/dashql`, the Rust core under `packages/dashql-core` and
154
- `packages/dashql-parser`, its wasm-bindgen module under `packages/dashql-core-wasm`,
154
+ `packages/dashql-parser`, its wasm-bindgen module under `packages/dashql-core-bindings`,
155
155
  and generated binding schemas under `proto/fb`. Third-party components retain
156
156
  their own licenses.
@@ -4,7 +4,13 @@ import * as glue from '../wasm/dashql_core.js';
4
4
  import type { BatchRequest, BatchResult } from './batch.js';
5
5
  import type { ScriptAnnotation } from './comment_tags.js';
6
6
  import { DashQLQueryProgressFollower } from './query_history.js';
7
- export type DashQLBindings = Pick<typeof glue, 'Catalog' | 'Script' | 'ScriptBatch' | 'ScriptSession' | 'QueryProfile' | 'SessionPlanRequest' | 'TableParameters' | 'planSession' | 'checkScriptReferences' | 'deriveSessionDataflow' | 'collectSessionInputs' | 'inputLiteral' | 'textChange' | 'quoteIdentifier' | 'quoteColumnName' | 'processBatch' | 'touchedRelations' | 'installPanicHook' | 'Shell' | 'QueryProgressFollower' | 'replayQueryProgress' | 'Runtime'>;
7
+ export interface DashQLFeatureClasses {
8
+ shell: 'Shell';
9
+ }
10
+ export type DashQLFeature = keyof DashQLFeatureClasses;
11
+ type FeatureClass = DashQLFeatureClasses[DashQLFeature];
12
+ export type DashQLBindings = DashQLCoreBindings & Partial<Pick<typeof glue, Extract<FeatureClass, keyof typeof glue>>>;
13
+ type DashQLCoreBindings = Pick<typeof glue, 'Catalog' | 'Script' | 'ScriptBatch' | 'ScriptSession' | 'QueryProfile' | 'SessionPlanRequest' | 'TableParameters' | 'planSession' | 'checkScriptReferences' | 'deriveSessionDataflow' | 'collectSessionInputs' | 'inputLiteral' | 'textChange' | 'quoteIdentifier' | 'quoteColumnName' | 'processBatch' | 'touchedRelations' | 'installPanicHook' | 'QueryProgressFollower' | 'replayQueryProgress' | 'Runtime'>;
8
14
  export type { Shell, ShellCompletionCandidate, ShellOperation, ShellPromptResult, ShellTerminalResult } from '../wasm/dashql_core.js';
9
15
  export interface DataflowPlacement {
10
16
  position?: {
@@ -74,6 +80,8 @@ export declare class DashQL {
74
80
  registeredMemory: Set<WeakRef<Ptr<symbol>>>;
75
81
  registeredMemoryRefs: WeakMap<Ptr<symbol>, WeakRef<Ptr<symbol>>>;
76
82
  registeredMemoryCleanup: FinalizationRegistry<WeakRef<Ptr<symbol>>>;
83
+ hasFeature(feature: DashQLFeature): boolean;
84
+ feature<F extends DashQLFeature>(feature: F): NonNullable<DashQLBindings[DashQLFeatureClasses[F] & keyof DashQLBindings]>;
77
85
  constructor(bindings: DashQLBindings);
78
86
  static create(options?: DashQLModuleOptions): Promise<DashQL>;
79
87
  static instantiated(): DashQL | null;
package/dist/core/api.js CHANGED
@@ -29,6 +29,7 @@ import { decodeBatchResult, encodeBatchRequest } from "./batch.js";
29
29
  import { DashQLQueryProgressFollower } from "./query_history.js";
30
30
  import * as flatbuffers from "flatbuffers";
31
31
  // dist/.stage/src/core/api.ts
32
+ var FEATURE_CLASSES = { shell: "Shell" };
32
33
  var corePanicListeners = /* @__PURE__ */ new Set();
33
34
  var corePanicMessage = null;
34
35
  function onCorePanic(listener) {
@@ -92,6 +93,15 @@ var DashQL = class DashQL {
92
93
  registeredMemory;
93
94
  registeredMemoryRefs;
94
95
  registeredMemoryCleanup;
96
+ hasFeature(feature) {
97
+ return FEATURE_CLASSES[feature] in this.bindings;
98
+ }
99
+ feature(feature) {
100
+ const name = FEATURE_CLASSES[feature];
101
+ const value = this.bindings[name];
102
+ if (value == null) throw new Error(`the core module was built without the feature ${feature}`);
103
+ return value;
104
+ }
95
105
  constructor(bindings) {
96
106
  this.encoder = new TextEncoder();
97
107
  this.decoder = new TextDecoder();
@@ -1,2 +1,2 @@
1
- export type { Runtime, RuntimePlatform, RuntimeHandles, RuntimeTables, RuntimeHttp, RuntimeHttpRequest, RuntimeHttpResponse, RuntimeChannels, RuntimeChannelMessage, RuntimeChannelTarget, RuntimeChannelRequest, RuntimeChannelQuery, RuntimeOAuth, RuntimeOAuthFlowInfo, RuntimeResultCache, RuntimeCachedTable, RuntimeMounts, RuntimeStorage, RuntimeStorageRoot, RuntimeFolder, RuntimeFolderStamps, RuntimeFileStamp, RuntimeWorkbookFolder, StorageMigrationOutcome, StorageVersions, WorkbookTableSchema, WorkbookTableColumn, WorkbookTableColumnType, ExternalChangeView, StorageView, StorageCommand, StorageWriteOutcome, StorageWriteStatistics, StorageHoldReason, StorageHoldView, StorageKeyStatistics, FailedStorageWriteView, RestoreOutcome, RestoreProgress, RestoreProgressCounter, RestoredInvalidWorkbook, RestoreScriptFile, RuntimeArchives, RuntimeArchiveEntry, RuntimeImportFolder, AttachedFile, AttachedFileName, AttachFilesOutcome, ImportSource, ImportStep, ImportPreview, ImportConflict, ImportQuestion, ImportCandidate, ImportResultFiles, ImportChoice, ImportConflictChoice, ImportAnswers, ImportedResults, ImportOutcome, ExportFormat, ExportOptions, ExportOutcome, ExportedResults, ExportedTables, ConnectionLinkOptions, SetupOptions, SetupOutcome, SetupAuthentication, QueryArgs, QueryOptions, QueryCacheOptions, QueryTicket, QueryRunOutcome, QueryRunFailure, QueryRunFailureKind, QueryCallerEvent, SliceId, RuntimeViews, ViewKind, BusyView, ViewId, ViewOf, KnownKeys, Target, RuntimeAction, DispatchOutcome, ChangeSet, SliceChange, HandleEffect, ComputePlatform, ComputeCallContext, AnalyzeTableOptions, ComputationView, ComputationTasks, ComputationTrackedTask, ComputationTaskProgress, ComputationVersionValue, ComputationColumnGroup, ComputationValueColumn, ComputationStatsFields, ComputationScalarFilter, ComputationFilterOp, ComputationOrderBy, ComputationCrossFilter, ComputationTableAggregation, ComputationColumnAggregate, ComputationColumnSummary, ComputationSummaryAnalysis, ComputationBinBounds, ComputationFilteredAggregate, ComputationSearch, ComputationSearchKind, ComputationFilterTable, ComputationOrderingTable, ComputationDataSearchTable, } from '../wasm/dashql_core.js';
1
+ export type { Runtime, RuntimePlatform, RuntimeSettings, RuntimeHandles, RuntimeTables, RuntimeHttp, RuntimeHttpRequest, RuntimeHttpResponse, RuntimeChannels, RuntimeChannelMessage, RuntimeChannelTarget, RuntimeChannelRequest, RuntimeChannelQuery, RuntimeOAuth, RuntimeOAuthFlowInfo, RuntimeResultCache, RuntimeCachedTable, RuntimeMounts, RuntimeMemoryFile, RuntimeStorage, RuntimeStorageRoot, RuntimeFolder, RuntimeFolderStamps, RuntimeFileStamp, RuntimeWorkbookFolder, StorageMigrationOutcome, StorageVersions, WorkbookTableSchema, WorkbookTableColumn, WorkbookTableColumnType, ExternalChangeView, StorageView, StorageCommand, StorageWriteOutcome, StorageWriteStatistics, StorageHoldReason, StorageHoldView, StorageKeyStatistics, FailedStorageWriteView, RestoreOutcome, RestoreProgress, RestoreProgressCounter, RestoredInvalidWorkbook, RestoreScriptFile, RuntimeArchives, RuntimeArchiveEntry, RuntimeImportFolder, AttachedFile, AttachedFileName, AttachFilesOutcome, ImportSource, ImportStep, ImportPreview, ImportConflict, ImportQuestion, ImportCandidate, ImportResultFiles, ImportChoice, ImportConflictChoice, ImportAnswers, ImportedResults, ImportOutcome, ExportFormat, ExportOptions, ExportOutcome, ExportedResults, ExportedTables, ConnectionLinkOptions, SetupOptions, SetupOutcome, SetupAuthentication, QueryArgs, QueryOptions, QueryCacheOptions, QueryTicket, QueryRunOutcome, QueryRunFailure, QueryRunFailureKind, QueryCallerEvent, SliceId, RuntimeViews, ViewKind, BusyView, ViewId, ViewOf, KnownKeys, Target, RuntimeAction, ActionOf, AppAction, ComputationAction, ConnectionAction, WorkbookAction, DispatchOutcome, ChangeSet, SliceChange, HandleEffect, ComputePlatform, ComputeCallContext, AnalyzeTableOptions, ComputationView, ComputationTasks, ComputationTrackedTask, ComputationTaskProgress, ComputationVersionValue, ComputationColumnGroup, ComputationValueColumn, ComputationStatsFields, ComputationScalarFilter, ComputationFilterOp, ComputationOrderBy, ComputationCrossFilter, ComputationTableAggregation, ComputationColumnAggregate, ComputationColumnSummary, ComputationSummaryAnalysis, ComputationBinBounds, ComputationFilteredAggregate, ComputationSearch, ComputationSearchKind, ComputationFilterTable, ComputationOrderingTable, ComputationDataSearchTable, } from '../wasm/dashql_core.js';
2
2
  export { TaskStatus } from '../wasm/dashql_core.js';
@@ -21,4 +21,4 @@ export interface NewConnection {
21
21
  }
22
22
  export type ConnectionAllocator = (connection: NewConnection, connectionId?: string) => ConnectionState;
23
23
  export declare function findWorkbookQueries(connection: Pick<ConnectionState, 'queriesActiveOrdered' | 'queriesFinishedOrdered'>, workbookId: string, queryOf: (queryId: number) => Pick<core.QueryView, 'queryMetadata'> | null, includeFinished?: boolean): number[];
24
- export declare function createConnectionAction(connection: NewConnection, connectionId?: string): core.RuntimeAction;
24
+ export declare function createConnectionAction(connection: NewConnection, connectionId?: string): core.AppAction;
@@ -41,6 +41,12 @@ export interface EmbeddedAttachedDatabases {
41
41
  dropAttachedDatabase(path: string): Promise<void>;
42
42
  }
43
43
  export declare function dropsAttachedDatabases(database: object): database is EmbeddedAttachedDatabases;
44
+ /** Optional capability: mount files in memory as a directory, e.g. the attachments of a workbook of a runtime without storage. */
45
+ export interface EmbeddedMemoryDirectoryDatabase extends EmbeddedExternalDirectoryDatabase {
46
+ registerMemoryDirectory(files: Readonly<Record<string, Blob>>, path: string): Promise<string>;
47
+ }
48
+ /** Can a database mount files in memory as a directory? */
49
+ export declare function supportsMemoryDirectories(database: EmbeddedExternalDirectoryDatabase): database is EmbeddedMemoryDirectoryDatabase;
44
50
  /** Optional browser directory registration capability. */
45
51
  export interface EmbeddedExternalDirectoryDatabase {
46
52
  registerExternalDirectory(handle: FileSystemDirectoryHandle, path: string | undefined, mode: ExternalDirectoryMode): Promise<string>;
@@ -2,4 +2,8 @@
2
2
  function dropsAttachedDatabases(database) {
3
3
  return typeof database.dropAttachedDatabase === "function";
4
4
  }
5
- export { dropsAttachedDatabases };
5
+ /** Can a database mount files in memory as a directory? */
6
+ function supportsMemoryDirectories(database) {
7
+ return typeof database.registerMemoryDirectory === "function";
8
+ }
9
+ export { dropsAttachedDatabases, supportsMemoryDirectories };
@@ -1,10 +1,11 @@
1
1
  import * as arrow from 'apache-arrow';
2
- import type { HyperDB as BrowserHyperDBEngine, HyperDBConnection as HyperDBEngineConnection, MountedResource, MountOptions } from 'hyperdb-wasm';
3
- import type { EmbeddedAttachedDatabases, EmbeddedComputeDatabase, EmbeddedConnectionOptions, EmbeddedExternalDirectoryDatabase, EmbeddedExternalFileDatabase, EmbeddedResultStream, ExternalDirectoryMode, EmbeddedTableImportConnection, EmbeddedTableInsertOptions } from '../embedded_database.js';
2
+ import type { HyperDB as BrowserHyperDBEngine, HyperDBConnection as HyperDBEngineConnection, MemoryDirectory, MountedResource, MountOptions } from 'hyperdb-wasm';
3
+ import type { EmbeddedAttachedDatabases, EmbeddedComputeDatabase, EmbeddedConnectionOptions, EmbeddedExternalFileDatabase, EmbeddedMemoryDirectoryDatabase, EmbeddedResultStream, ExternalDirectoryMode, EmbeddedTableImportConnection, EmbeddedTableInsertOptions } from '../embedded_database.js';
4
4
  export type { HyperDBSettings } from 'hyperdb-wasm';
5
5
  export type HyperDBEngine = Omit<BrowserHyperDBEngine, 'mount'> & {
6
- mount(source: File | FileSystemDirectoryHandle | string, options: MountOptions): Promise<MountedResource>;
6
+ mount(source: File | FileSystemDirectoryHandle | string | MemoryDirectorySource, options: MountOptions): Promise<MountedResource>;
7
7
  };
8
+ type MemoryDirectorySource = Pick<MemoryDirectory, 'kind' | 'files'>;
8
9
  export type HyperDBClient = ConstructorParameters<typeof BrowserHyperDBEngine>[0];
9
10
  export type HyperDBResult = Awaited<ReturnType<HyperDBClient['connect']>>;
10
11
  export interface HyperDBOptions {
@@ -15,7 +16,7 @@ export interface HyperDBOptions {
15
16
  mountFile?: MountFile;
16
17
  }
17
18
  export type MountFile = (engine: HyperDBEngine, file: File, path: string) => Promise<MountedResource>;
18
- export declare class HyperDB implements EmbeddedComputeDatabase, EmbeddedExternalFileDatabase, EmbeddedExternalDirectoryDatabase, EmbeddedAttachedDatabases {
19
+ export declare class HyperDB implements EmbeddedComputeDatabase, EmbeddedExternalFileDatabase, EmbeddedMemoryDirectoryDatabase, EmbeddedAttachedDatabases {
19
20
  private readonly engine;
20
21
  private readonly sessions;
21
22
  private readonly idleSessions;
@@ -46,6 +47,7 @@ export declare class HyperDB implements EmbeddedComputeDatabase, EmbeddedExterna
46
47
  registerExternalFile(name: string, blob: Blob, path?: string, signal?: AbortSignal): Promise<string>;
47
48
  removeExternalFile(path: string): Promise<void>;
48
49
  registerExternalDirectory(handle: FileSystemDirectoryHandle, path: string | undefined, mode: ExternalDirectoryMode): Promise<string>;
50
+ registerMemoryDirectory(files: Readonly<Record<string, Blob>>, path: string): Promise<string>;
49
51
  removeExternalDirectory(path: string): Promise<void>;
50
52
  refreshExternalDirectory(path: string): Promise<void>;
51
53
  terminate(): Promise<void>;
@@ -197,6 +197,20 @@ var HyperDB = class HyperDB {
197
197
  return path;
198
198
  });
199
199
  }
200
+ async registerMemoryDirectory(files, path) {
201
+ return await this.runDatabaseOperation(async () => {
202
+ validateExternalMountPath(path);
203
+ const resource = await this.engine.mount({
204
+ kind: "memory-directory",
205
+ files
206
+ }, {
207
+ path,
208
+ mode: "read"
209
+ });
210
+ this.externalDirectories.set(path, resource);
211
+ return path;
212
+ });
213
+ }
200
214
  async removeExternalDirectory(path) {
201
215
  await this.runDatabaseOperation(async () => {
202
216
  const resource = this.externalDirectories.get(path);
@@ -1,5 +1,6 @@
1
1
  import type { ParquetDatabase } from '../hyperdb/hyperdb_parquet_export.js';
2
- export declare function mountWorkbookAttachments(database: ParquetDatabase, workbookId: string, getRoot?: () => Promise<FileSystemDirectoryHandle>): Promise<string>;
2
+ export type AttachmentFiles = ReadonlyMap<string, Blob>;
3
+ export declare function mountWorkbookAttachments(database: ParquetDatabase, workbookId: string, files?: AttachmentFiles | null, getRoot?: () => Promise<FileSystemDirectoryHandle>): Promise<string>;
3
4
  export declare function markWorkbookAttachmentsChanged(workbookId: string): void;
4
5
  export declare function unmountWorkbookAttachments(workbookId: string): Promise<void>;
5
- export declare function readAttachmentColumns(database: ParquetDatabase, workbookId: string, fileName: string): Promise<string[]>;
6
+ export declare function readAttachmentColumns(database: ParquetDatabase, workbookId: string, fileName: string, files?: AttachmentFiles | null): Promise<string[]>;
@@ -1,7 +1,12 @@
1
1
  import { getOPFSRoot } from "../opfs_root.js";
2
+ import { supportsMemoryDirectories } from "../embedded_database.js";
2
3
  import { STORAGE_ATTACHMENTS_FOLDER, STORAGE_WORKBOOKS_FOLDER } from "../storage/storage_backend.js";
3
4
  import { attachmentPath, attachmentPrefix } from "./workbook_attachments.js";
4
5
  // dist/.stage/src/platform/workbook/attachment_mounts.ts
6
+ function sameFiles(left, right) {
7
+ if (left == null || right == null) return left === right;
8
+ return left.size === right.size && [...left].every(([name, file]) => right.get(name) === file);
9
+ }
5
10
  var MOUNTS = /* @__PURE__ */ new Map();
6
11
  var pending = Promise.resolve();
7
12
  function serialize(f) {
@@ -9,23 +14,29 @@ function serialize(f) {
9
14
  pending = next.catch(() => {});
10
15
  return next;
11
16
  }
12
- function mountWorkbookAttachments(database, workbookId, getRoot = getOPFSRoot) {
17
+ function mountWorkbookAttachments(database, workbookId, files = null, getRoot = getOPFSRoot) {
13
18
  return serialize(async () => {
14
19
  const path = attachmentPrefix(workbookId);
15
20
  let mount = MOUNTS.get(workbookId);
16
- if (mount != null && mount.database !== database) {
21
+ if (mount != null && (mount.database !== database || !sameFiles(mount.files, files))) {
17
22
  await mount.database.removeExternalDirectory(path).catch(() => {});
18
23
  MOUNTS.delete(workbookId);
19
24
  mount = void 0;
20
25
  }
21
26
  if (mount == null) {
22
- const folder = await (await (await (await getRoot()).getDirectoryHandle(STORAGE_WORKBOOKS_FOLDER, { create: true })).getDirectoryHandle(workbookId, { create: true })).getDirectoryHandle(STORAGE_ATTACHMENTS_FOLDER, { create: true });
23
- await database.registerExternalDirectory(folder, path, "read");
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);
33
+ }
24
34
  MOUNTS.set(workbookId, {
25
35
  database,
36
+ files,
26
37
  stale: false
27
38
  });
28
- } else if (mount.stale) {
39
+ } else if (mount.stale && mount.files == null) {
29
40
  mount.stale = false;
30
41
  try {
31
42
  await database.refreshExternalDirectory(path);
@@ -49,8 +60,8 @@ function unmountWorkbookAttachments(workbookId) {
49
60
  await mount.database.removeExternalDirectory(attachmentPrefix(workbookId)).catch(() => {});
50
61
  });
51
62
  }
52
- async function readAttachmentColumns(database, workbookId, fileName) {
53
- await mountWorkbookAttachments(database, workbookId);
63
+ async function readAttachmentColumns(database, workbookId, fileName, files = null) {
64
+ await mountWorkbookAttachments(database, workbookId, files);
54
65
  const connection = await database.connect({ pooled: true });
55
66
  try {
56
67
  const path = attachmentPath(workbookId, fileName).replace(/'/g, "''");
@@ -44,10 +44,7 @@ export interface WorkbookDerived {
44
44
  dataflow: core.buffers.execution.SessionDataflowT;
45
45
  inputs: SessionInput[];
46
46
  }
47
- export type WorkbookAction = Extract<core.RuntimeAction, {
48
- kind: WorkbookActionKind;
49
- }>;
50
- type WorkbookActionKind = 'createScript' | 'deleteScript' | 'renameScript' | 'reorderScripts' | 'setScriptText' | 'acceptPendingDiff' | 'rejectPendingDiff' | 'setScriptVisSpec' | 'setWorkbookInput' | 'analyzeOutdatedScript' | 'showScript' | 'hideScript' | 'renameWorkbook' | 'setScriptConnection' | 'setPendingConnection' | 'replaceConnection' | 'detachConnection' | 'setWorkbookAttachments' | 'setCloudLink';
47
+ export type WorkbookAction = core.WorkbookAction;
51
48
  export type ModifyWorkbookScripts = (action: WorkbookAction) => core.DispatchOutcome;
52
49
  export declare const EPHEMERAL_WORKBOOK_NAME = "New Workbook";
53
50
  export declare function workbookCloudLink(state: Pick<WorkbookScripts, 'workbookMetadata'>): WorkbookCloudLink | null;
@@ -55,4 +52,3 @@ export declare function isCloudPreview(state: Pick<WorkbookScripts, 'cloud'>): b
55
52
  export declare function scriptConnectionIds(state: Pick<WorkbookScripts, 'scriptConnections'>): string[];
56
53
  export declare function scriptsOnConnection(state: Pick<WorkbookScripts, 'scriptConnections'>, connectionId: string): number;
57
54
  export declare function getScriptRefs(state: Pick<WorkbookScripts, 'scriptOrder' | 'scriptRefs'>): ScriptRef[];
58
- export {};
@@ -1,6 +1,16 @@
1
1
  import { supportsParquet } from "../platform/hyperdb/hyperdb_parquet_export.js";
2
2
  import { mountWorkbookAttachments, readAttachmentColumns, unmountWorkbookAttachments } from "../platform/workbook/attachment_mounts.js";
3
3
  // dist/.stage/src/runtime/run_mounts.ts
4
+ function memoryFiles(handles, files) {
5
+ if (files == null) return null;
6
+ const blobs = /* @__PURE__ */ new Map();
7
+ for (const { fileName, file } of files) {
8
+ const content = handles.get(file);
9
+ if (content == null) throw new Error(`The attachment ${fileName} is no longer in memory`);
10
+ blobs.set(fileName, content instanceof Blob ? content : new Blob([content]));
11
+ }
12
+ return blobs;
13
+ }
4
14
  function createRunMounts(computeDatabase, cache, handles, pins) {
5
15
  const database = async () => {
6
16
  const database = await computeDatabase();
@@ -34,10 +44,10 @@ function createRunMounts(computeDatabase, cache, handles, pins) {
34
44
  await cache.writeTable(await database(), table, nameOf(cache, path));
35
45
  return table.numRows;
36
46
  },
37
- attachments: async (workbookId) => {
38
- await mountWorkbookAttachments(await database(), workbookId);
47
+ attachments: async (workbookId, files) => {
48
+ await mountWorkbookAttachments(await database(), workbookId, memoryFiles(handles, files));
39
49
  },
40
- attachmentColumns: async (workbookId, fileName) => readAttachmentColumns(await database(), workbookId, fileName),
50
+ attachmentColumns: async (workbookId, fileName, files) => readAttachmentColumns(await database(), workbookId, fileName, memoryFiles(handles, files)),
41
51
  dropAttachments: (workbookId) => unmountWorkbookAttachments(workbookId)
42
52
  };
43
53
  }
@@ -37,8 +37,12 @@ export interface RuntimeOptions {
37
37
  archives?: RuntimeArchivesFactory | null;
38
38
  catalogLoader?: boolean;
39
39
  queryCommands?: Partial<QueryCommands> | null;
40
+ settings?: core.RuntimeSettings | null;
40
41
  }
41
42
  export type RuntimeArchivesFactory = (handles: HandleTable) => core.RuntimeArchives;
43
+ export type Settled = core.DispatchOutcome & {
44
+ settled: Promise<void>;
45
+ };
42
46
  export type ImportSource = {
43
47
  archive: Blob;
44
48
  } | {
@@ -100,12 +104,17 @@ export declare class Runtime {
100
104
  private live;
101
105
  private modulePlatform;
102
106
  private settled;
103
- dispatch(target: core.Target, action: core.RuntimeAction): core.DispatchOutcome;
107
+ dispatch<T extends core.Target>(target: T, action: core.ActionOf<T>): Settled;
108
+ cancelScript(workbookId: string, scriptKey: number): Promise<void>;
104
109
  analyzeTable(tableId: number, table: arrow.Table, options?: AnalyzeTableOptions): Promise<void>;
105
110
  previewResult(tableId: number, limit: number): Promise<Uint8Array>;
106
111
  table(handle: number | null | undefined): arrow.Table | undefined;
107
112
  createConnection(connection: NewConnection, connectionId?: string): ConnectionState;
108
113
  connection(connectionId: string): ConnectionState | null;
114
+ allocateId(): number;
115
+ catalogRelationsFile(connectionId: string): string | null;
116
+ revealConnectionSecrets(connectionId: string): core.ConnectionSecrets | null;
117
+ exportConnection(connectionId: string, options: core.ConnectionLinkOptions): Promise<string>;
109
118
  catalog(connectionId: string): core.DashQLCatalog | null;
110
119
  channel<T>(connection: Pick<ConnectionState, 'details'> | null | undefined): T | null;
111
120
  saveConnection(connectionId: string, params?: ConnectionParams): Promise<core.ConnectionSaveOutcome>;
@@ -134,6 +143,9 @@ export declare class Runtime {
134
143
  runWorkbook(workbookId: string, options?: core.RunWorkbookOptions, listener?: RunWorkbookListener): Promise<RunResult>;
135
144
  runScript(workbookId: string, scriptKey: number, options?: core.RunScriptOptions): Promise<RunResult>;
136
145
  stopRun(workbookId: string): void;
146
+ checkWorkbookFolders(workbookIds: string[]): void;
147
+ answerExternalChange(workbookId: string, prompt: number, reload: boolean | null): void;
148
+ exportedResults(workbookId: string): Promise<core.ExportedResults>;
137
149
  exportArchive(workbookId: string, options?: ExportOptions): Promise<{
138
150
  archive: Blob;
139
151
  results: core.ExportedResults;
@@ -142,6 +154,7 @@ export declare class Runtime {
142
154
  exportTables(workbookId: string, options: ExportOptions, consume: (tables: WorkbookTables) => Promise<void>): Promise<core.ExportedResults>;
143
155
  readImport(source: ImportSource): Promise<core.ImportPreview>;
144
156
  commitImport(importId: number, answers: core.ImportAnswers, onStep?: (step: core.ImportStep, results: core.ImportedResults | null) => void): Promise<core.ImportOutcome>;
157
+ dropImport(importId: number): void;
145
158
  get destroyed(): boolean;
146
159
  flush(): void;
147
160
  destroy(): Promise<void>;
@@ -122,7 +122,8 @@ var Runtime = class {
122
122
  extensions: { loadSpec: async (extension) => JSON.stringify(await loadClientFunctionSpec(extension)) },
123
123
  storage: platform.storage == null ? null : createRuntimeStorage(platform.storage),
124
124
  archives: platform.archives?.(this.handles) ?? null,
125
- changed: (urgent) => this.store.changed(urgent)
125
+ changed: (urgent) => this.store.changed(urgent),
126
+ settings: platform.settings ?? void 0
126
127
  };
127
128
  }
128
129
  async settled(command) {
@@ -137,9 +138,17 @@ var Runtime = class {
137
138
  ok: false,
138
139
  changed: false,
139
140
  error: destroyedError().message,
140
- id: null
141
+ id: null,
142
+ settled: Promise.resolve()
141
143
  };
142
- return this.module.dispatch(target, action);
144
+ return {
145
+ ...this.module.dispatch(target, action),
146
+ settled: this.store.afterFlush()
147
+ };
148
+ }
149
+ async cancelScript(workbookId, scriptKey) {
150
+ if (this.stopping) return;
151
+ await this.module.cancelScript(workbookId, scriptKey);
143
152
  }
144
153
  async analyzeTable(tableId, table, options = {}) {
145
154
  const module = this.live();
@@ -172,6 +181,20 @@ var Runtime = class {
172
181
  const view = this.module.views("connection", [connectionId])[0] ?? null;
173
182
  return view === "busy" ? this.store.get("connection", connectionId) : view;
174
183
  }
184
+ allocateId() {
185
+ return this.live().allocateId();
186
+ }
187
+ catalogRelationsFile(connectionId) {
188
+ if (this.stopping) return null;
189
+ return this.module.catalogRelationsFile(connectionId) ?? null;
190
+ }
191
+ revealConnectionSecrets(connectionId) {
192
+ if (this.stopping) return null;
193
+ return this.module.revealConnectionSecrets(connectionId);
194
+ }
195
+ async exportConnection(connectionId, options) {
196
+ return await this.live().exportConnection(connectionId, options);
197
+ }
175
198
  catalog(connectionId) {
176
199
  if (this.freed) return null;
177
200
  const catalogId = this.module.catalogId(connectionId);
@@ -330,6 +353,15 @@ var Runtime = class {
330
353
  stopRun(workbookId) {
331
354
  if (!this.stopping) this.module.stopRun(workbookId);
332
355
  }
356
+ checkWorkbookFolders(workbookIds) {
357
+ if (!this.stopping) this.module.checkWorkbookFolders(workbookIds);
358
+ }
359
+ answerExternalChange(workbookId, prompt, reload) {
360
+ if (!this.stopping) this.module.answerExternalChange(workbookId, prompt, reload);
361
+ }
362
+ async exportedResults(workbookId) {
363
+ return await this.live().exportedResults(workbookId);
364
+ }
333
365
  async exportArchive(workbookId, options = {}) {
334
366
  const outcome = await this.live().exportWorkbook(workbookId, {
335
367
  ...options,
@@ -384,6 +416,9 @@ var Runtime = class {
384
416
  async commitImport(importId, answers, onStep) {
385
417
  return await this.settled(this.live().commitImport(importId, answers, onStep ?? null));
386
418
  }
419
+ dropImport(importId) {
420
+ if (!this.stopping) this.module.dropImport(importId);
421
+ }
387
422
  get destroyed() {
388
423
  return this.stopping;
389
424
  }
@@ -37,10 +37,13 @@ export declare class RuntimeStore {
37
37
  private disposed;
38
38
  private readonly failures;
39
39
  private releases;
40
+ private waiting;
40
41
  constructor(handles: HandleTable, scheduler: UpdateScheduler, logger?: ((message: string) => void) | null);
41
42
  attach(source: RuntimeViewSource, projections?: Projections): void;
42
43
  changed: (urgent: boolean) => void;
44
+ afterFlush(): Promise<void>;
43
45
  flush: () => void;
46
+ private take;
44
47
  private failed;
45
48
  private drop;
46
49
  get<K extends core.ViewKind>(kind: K, id: core.ViewId<K>): StoreView<K> | null;
@@ -15,6 +15,7 @@ var RuntimeStore = class {
15
15
  disposed = false;
16
16
  failures = /* @__PURE__ */ new Map();
17
17
  releases = [];
18
+ waiting = [];
18
19
  constructor(handles, scheduler, logger = null) {
19
20
  this.handles = handles;
20
21
  this.scheduler = scheduler;
@@ -40,7 +41,20 @@ var RuntimeStore = class {
40
41
  handle: this.scheduler.beforeFrame(this.flush)
41
42
  };
42
43
  };
44
+ afterFlush() {
45
+ if (this.scheduled == null || this.disposed) return Promise.resolve();
46
+ return new Promise((resolve) => this.waiting.push(resolve));
47
+ }
43
48
  flush = () => {
49
+ const waiting = this.waiting;
50
+ this.waiting = [];
51
+ try {
52
+ this.take();
53
+ } finally {
54
+ for (const resolve of waiting) resolve();
55
+ }
56
+ };
57
+ take() {
44
58
  if (this.scheduled?.type === "frame") this.scheduler.cancelFrame(this.scheduled.handle);
45
59
  this.scheduled = null;
46
60
  const source = this.source;
@@ -124,7 +138,7 @@ var RuntimeStore = class {
124
138
  }
125
139
  for (const key of notify) for (const listener of [...this.listeners.get(key) ?? []]) listener();
126
140
  for (const kind of notifyKinds) for (const listener of [...this.kindListeners.get(kind) ?? []]) listener();
127
- };
141
+ }
128
142
  failed(source, kind, ids) {
129
143
  const again = ids.filter((id) => {
130
144
  const key = sliceKey(kind, id);
@@ -175,6 +189,9 @@ var RuntimeStore = class {
175
189
  this.scheduled = null;
176
190
  this.disposed = true;
177
191
  this.source = null;
192
+ const waiting = this.waiting;
193
+ this.waiting = [];
194
+ for (const resolve of waiting) resolve();
178
195
  }
179
196
  };
180
197
  function subscribeTo(listeners, key, listener) {