Skip to content

Commit

Permalink
fix(swing-store)!: Remove unsafe hostStorage.setExportCallback method
Browse files Browse the repository at this point in the history
Fixes #10062
  • Loading branch information
gibson042 committed Sep 25, 2024
1 parent 4a1e4c3 commit c24e990
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 0 additions & 2 deletions packages/swing-store/docs/swingstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ If, for some reason, the host wants to abandon execution, it can call `hostStora

`hostStorage.kvStore` is also available to let the host add items to a separate portion of the kvStore, using keys which start with a `host.` prefix. It can use this to coordinate with a separately-committed host database (e.g. to remember how much work has been given to the kernel, and how much has been successfully executed). This portion of the kvStore is unreachable by the kernel.

`hostStorage.setExportCallback()` is used to register an export callback after swingstore creation, see [data-export.md](./data-export.md) for details. Most applications will instead provide `options.exportCallback` to `openSwingStore()`.

`hostStorage.repairMetadata()` was used to repair a historical flaw in the database format, and is not needed by new installations.

## KernelStorage
Expand Down
14 changes: 4 additions & 10 deletions packages/swing-store/src/swingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { doRepairMetadata } from './repairMetadata.js';
* commit: () => Promise<void>, // commit changes made since the last commit
* close: () => Promise<void>, // shutdown the store, abandoning any uncommitted changes
* diskUsage?: () => number, // optional stats method
* setExportCallback: (cb: (updates: KVPair[]) => void) => void, // Set a callback invoked by swingStore when new serializable data is available for export
* repairMetadata: (exporter: import('./exporter.js').SwingStoreExporter) => Promise<void>,
* }} SwingStoreHostStorage
*/
Expand Down Expand Up @@ -274,14 +273,10 @@ export function makeSwingStore(dirPath, forceReset, options = {}) {
)
`);

let exportCallback;
function setExportCallback(cb) {
typeof cb === 'function' || Fail`callback must be a function`;
exportCallback = cb;
}
if (options.exportCallback) {
setExportCallback(options.exportCallback);
}
const { exportCallback } = options;
exportCallback === undefined ||
typeof exportCallback === 'function' ||
Fail`export callback must be a function`;

const sqlAddPendingExport = db.prepare(`
INSERT INTO pendingExports (key, value)
Expand Down Expand Up @@ -600,7 +595,6 @@ export function makeSwingStore(dirPath, forceReset, options = {}) {
commit,
close,
diskUsage,
setExportCallback,
};
const debug = {
serialize,
Expand Down

0 comments on commit c24e990

Please sign in to comment.