Skip to content

Commit

Permalink
fix(swing-store)!: Remove unsafe hostStorage.setExportCallback method (
Browse files Browse the repository at this point in the history
…#10063)

Fixes #10062

## Description
Removes `hostStorage.setExportCallback()`, for reasons explained in #10062.

### Security Considerations
This will prevent unlikely but possible uses of the method which would cause misleading behavior.

### Scaling Considerations
n/a

### Documentation Considerations
This removes mention of the method from the only place where it is documented. No historical note is added because we never use it anyway.

### Testing Considerations
n/a

### Upgrade Considerations
None known because the method is not in active use.
  • Loading branch information
mergify[bot] authored Sep 25, 2024
2 parents 4a1e4c3 + c24e990 commit b0e0292
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 b0e0292

Please sign in to comment.