@agoric/swing-store 0.9.2-dev-d6fae11.0.d6fae11 → 0.9.2-dev-64cee5a.0.64cee5a
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/package.json +3 -3
- package/src/assertComplete.js +7 -2
- package/src/exporter.js +5 -1
- package/src/importer.js +9 -3
- package/src/internal.js +5 -1
- package/src/repairMetadata.js +9 -3
- package/src/snapStore.js +3 -2
- package/src/swingStore.js +16 -9
- package/src/transcriptStore.js +1 -1
- package/src/util.js +5 -1
- package/test/bundles.test.js +7 -3
- package/test/deletion.test.js +5 -1
- package/test/export.test.js +6 -2
- package/test/exports.js +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/swing-store",
|
|
3
|
-
"version": "0.9.2-dev-
|
|
3
|
+
"version": "0.9.2-dev-64cee5a.0.64cee5a",
|
|
4
4
|
"description": "Persistent storage for SwingSet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"lint:eslint": "yarn run -T eslint ."
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agoric/internal": "0.3.3-dev-
|
|
24
|
+
"@agoric/internal": "0.3.3-dev-64cee5a.0.64cee5a",
|
|
25
25
|
"@endo/base64": "^1.0.12",
|
|
26
26
|
"@endo/bundle-source": "^4.1.2",
|
|
27
27
|
"@endo/check-bundle": "^1.0.17",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": "^20.9 || ^22.11"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "64cee5ae5d1a3488a30ce042d6f3f561ac2a6e82"
|
|
60
60
|
}
|
package/src/assertComplete.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {Pick<
|
|
3
|
-
* @param {Exclude<
|
|
2
|
+
* @param {Pick<SwingStoreInternal, 'bundleStore' | 'transcriptStore' | 'snapStore'>} internal
|
|
3
|
+
* @param {Exclude<ArtifactMode, 'debug'>} checkMode
|
|
4
4
|
* @returns {void}
|
|
5
5
|
*/
|
|
6
6
|
export function assertComplete(internal, checkMode) {
|
|
7
7
|
// every bundle must be populated
|
|
8
8
|
internal.bundleStore.assertComplete(checkMode);
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @import {SwingStoreInternal} from './internal.js';
|
|
12
|
+
* @import {ArtifactMode} from './internal.js';
|
|
13
|
+
*/
|
|
14
|
+
|
|
10
15
|
// every 'isCurrent' transcript span must have all items
|
|
11
16
|
// TODO: every vat with any data must have a isCurrent transcript
|
|
12
17
|
// span
|
package/src/exporter.js
CHANGED
|
@@ -11,6 +11,10 @@ import { makeTranscriptStore } from './transcriptStore.js';
|
|
|
11
11
|
import { assertComplete } from './assertComplete.js';
|
|
12
12
|
import { validateArtifactMode } from './internal.js';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @import {ArtifactMode} from './internal.js';
|
|
16
|
+
*/
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* @template T
|
|
16
20
|
* @typedef { Iterable<T> | AsyncIterable<T> } AnyIterable
|
|
@@ -79,7 +83,7 @@ import { validateArtifactMode } from './internal.js';
|
|
|
79
83
|
|
|
80
84
|
/**
|
|
81
85
|
* @typedef { object } ExportSwingStoreOptions
|
|
82
|
-
* @property {
|
|
86
|
+
* @property { ArtifactMode } [artifactMode] What artifacts should/must the exporter provide?
|
|
83
87
|
*/
|
|
84
88
|
|
|
85
89
|
/**
|
package/src/importer.js
CHANGED
|
@@ -5,9 +5,15 @@ import { buffer } from './util.js';
|
|
|
5
5
|
import { validateArtifactMode } from './internal.js';
|
|
6
6
|
import { assertComplete } from './assertComplete.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @import {ArtifactMode} from './internal.js';
|
|
10
|
+
* @import {SwingStoreExporter} from './exporter.js';
|
|
11
|
+
* @import {SwingStore} from './swingStore.js';
|
|
12
|
+
*/
|
|
13
|
+
|
|
8
14
|
/**
|
|
9
15
|
* @typedef { object } ImportSwingStoreOptions
|
|
10
|
-
* @property {
|
|
16
|
+
* @property { ArtifactMode } [artifactMode] What artifacts should the importer use and require?
|
|
11
17
|
*/
|
|
12
18
|
|
|
13
19
|
/**
|
|
@@ -17,10 +23,10 @@ import { assertComplete } from './assertComplete.js';
|
|
|
17
23
|
* returned swingStore is not suitable for execution, and thus only contains
|
|
18
24
|
* the host facet for committing the populated swingStore.
|
|
19
25
|
*
|
|
20
|
-
* @param {
|
|
26
|
+
* @param {SwingStoreExporter} exporter
|
|
21
27
|
* @param {string | null} [dirPath]
|
|
22
28
|
* @param {ImportSwingStoreOptions} [options]
|
|
23
|
-
* @returns {Promise<Pick<
|
|
29
|
+
* @returns {Promise<Pick<SwingStore, 'hostStorage' | 'debug'>>}
|
|
24
30
|
*/
|
|
25
31
|
export async function importSwingStore(exporter, dirPath = null, options = {}) {
|
|
26
32
|
if (dirPath && typeof dirPath !== 'string') {
|
package/src/internal.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Fail, q } from '@endo/errors';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @import {KVStore} from './kvStore.js';
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* @import {SnapStoreInternal} from './snapStore.js';
|
|
5
9
|
* @import {TranscriptStoreInternal} from './transcriptStore.js';
|
|
@@ -8,7 +12,7 @@ import { Fail, q } from '@endo/errors';
|
|
|
8
12
|
* @typedef {{
|
|
9
13
|
* dirPath: string | null,
|
|
10
14
|
* db: ReturnType<import('better-sqlite3')>,
|
|
11
|
-
* kvStore:
|
|
15
|
+
* kvStore: KVStore,
|
|
12
16
|
* transcriptStore: TranscriptStoreInternal,
|
|
13
17
|
* snapStore: SnapStoreInternal,
|
|
14
18
|
* bundleStore: BundleStoreInternal,
|
package/src/repairMetadata.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Fail, q } from '@endo/errors';
|
|
2
2
|
import { assertComplete } from './assertComplete.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @import {SwingStoreInternal} from './internal.js';
|
|
6
|
+
* @import {SwingStoreExporter} from './exporter.js';
|
|
7
|
+
* @import {ArtifactMode} from './internal.js';
|
|
8
|
+
*/
|
|
9
|
+
|
|
4
10
|
/**
|
|
5
11
|
* Given a pre-existing swingstore and a SwingStoreExporter, read in
|
|
6
12
|
* all the metadata from the exporter and use it to regenerate any
|
|
@@ -24,8 +30,8 @@ import { assertComplete } from './assertComplete.js';
|
|
|
24
30
|
* an open transaction. The caller is responsible for calling
|
|
25
31
|
* `hostStorage.commit()` when they are ready.
|
|
26
32
|
*
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
33
|
+
* @param {SwingStoreInternal} internal
|
|
34
|
+
* @param {SwingStoreExporter} exporter
|
|
29
35
|
* @returns {Promise<void>}
|
|
30
36
|
*/
|
|
31
37
|
export async function doRepairMetadata(internal, exporter) {
|
|
@@ -60,7 +66,7 @@ export async function doRepairMetadata(internal, exporter) {
|
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
// and do a completeness check
|
|
63
|
-
/** @type {
|
|
69
|
+
/** @type { ArtifactMode } */
|
|
64
70
|
const artifactMode = 'operational';
|
|
65
71
|
assertComplete(internal, artifactMode);
|
|
66
72
|
await exporter.close();
|
package/src/snapStore.js
CHANGED
|
@@ -10,6 +10,7 @@ import { buffer } from './util.js';
|
|
|
10
10
|
/**
|
|
11
11
|
* @import { AnyIterable, SwingStoreExporter } from './exporter.js';
|
|
12
12
|
* @import { ArtifactMode } from './internal.js';
|
|
13
|
+
* @import {makeMeasureSeconds} from '@agoric/internal';
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -68,7 +69,7 @@ import { buffer } from './util.js';
|
|
|
68
69
|
* @callback SnapshotCallback
|
|
69
70
|
* Called with the gzipped contents of a new heap snapshot.
|
|
70
71
|
* @param {string} name an export key, e.g. `snapshot.${vatID}.${deliveryCount}`
|
|
71
|
-
* @param {Parameters<
|
|
72
|
+
* @param {Parameters<typeof Readable.from>[0]} compressedData
|
|
72
73
|
* @returns {Promise<void>}
|
|
73
74
|
*/
|
|
74
75
|
|
|
@@ -78,7 +79,7 @@ const finished = promisify(finishedCallback);
|
|
|
78
79
|
* @param {*} db
|
|
79
80
|
* @param {() => void} ensureTxn
|
|
80
81
|
* @param {{
|
|
81
|
-
* measureSeconds: ReturnType<typeof
|
|
82
|
+
* measureSeconds: ReturnType<typeof makeMeasureSeconds>,
|
|
82
83
|
* }} io
|
|
83
84
|
* @param {(key: string, value: string | undefined) => void} noteExport
|
|
84
85
|
* @param {object} [options]
|
package/src/swingStore.js
CHANGED
|
@@ -27,6 +27,13 @@ const IN_MEMORY = ':memory:';
|
|
|
27
27
|
* @typedef {(input: T) => T} Replacer
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @import {SwingStoreExporter} from './exporter.js';
|
|
32
|
+
* @import {SwingStoreInternal} from './internal.js';
|
|
33
|
+
* @import {SnapshotCallback} from './snapStore.js';
|
|
34
|
+
* @import {TranscriptCallback} from './transcriptStore.js';
|
|
35
|
+
*/
|
|
36
|
+
|
|
30
37
|
/**
|
|
31
38
|
* @import {KVStore} from './kvStore.js';
|
|
32
39
|
*
|
|
@@ -59,7 +66,7 @@ const IN_MEMORY = ':memory:';
|
|
|
59
66
|
* commit: () => Promise<void>, // commit changes made since the last commit
|
|
60
67
|
* close: () => Promise<void>, // shutdown the store, abandoning any uncommitted changes
|
|
61
68
|
* diskUsage?: () => number, // optional stats method
|
|
62
|
-
* repairMetadata: (exporter:
|
|
69
|
+
* repairMetadata: (exporter: SwingStoreExporter) => Promise<void>,
|
|
63
70
|
* }} SwingStoreHostStorage
|
|
64
71
|
*/
|
|
65
72
|
|
|
@@ -79,7 +86,7 @@ const IN_MEMORY = ':memory:';
|
|
|
79
86
|
* kernelStorage: SwingStoreKernelStorage,
|
|
80
87
|
* hostStorage: SwingStoreHostStorage,
|
|
81
88
|
* debug: SwingStoreDebugTools,
|
|
82
|
-
* internal:
|
|
89
|
+
* internal: SwingStoreInternal,
|
|
83
90
|
* }} SwingStore
|
|
84
91
|
*/
|
|
85
92
|
|
|
@@ -139,13 +146,13 @@ const IN_MEMORY = ':memory:';
|
|
|
139
146
|
* @property {string} [traceFile] Path at which to record KVStore set/delete activity
|
|
140
147
|
* @property {boolean} [keepSnapshots] Retain old heap snapshots
|
|
141
148
|
* @property {boolean} [keepTranscripts] Retain old transcript span items
|
|
142
|
-
* @property {
|
|
143
|
-
* @property {
|
|
149
|
+
* @property {SnapshotCallback} [archiveSnapshot] Called after creation of a new heap snapshot
|
|
150
|
+
* @property {TranscriptCallback} [archiveTranscript] Called after a formerly-current transcript span is finalized
|
|
144
151
|
* @property {(pendingExports: Iterable<[key: string, value: string | null]>) => void} [exportCallback]
|
|
145
|
-
* @property {Replacer<ReturnType<makeKVStore>>} [wrapKvStore]
|
|
146
|
-
* @property {Replacer<ReturnType<makeTranscriptStore>>} [wrapTranscriptStore]
|
|
147
|
-
* @property {Replacer<ReturnType<makeSnapStore>>} [wrapSnapStore]
|
|
148
|
-
* @property {Replacer<ReturnType<makeBundleStore>>} [wrapBundleStore]
|
|
152
|
+
* @property {Replacer<ReturnType<typeof makeKVStore>>} [wrapKvStore]
|
|
153
|
+
* @property {Replacer<ReturnType<typeof makeTranscriptStore>>} [wrapTranscriptStore]
|
|
154
|
+
* @property {Replacer<ReturnType<typeof makeSnapStore>>} [wrapSnapStore]
|
|
155
|
+
* @property {Replacer<ReturnType<typeof makeBundleStore>>} [wrapBundleStore]
|
|
149
156
|
*/
|
|
150
157
|
|
|
151
158
|
/**
|
|
@@ -515,7 +522,7 @@ export function makeSwingStore(path, forceReset, options = {}) {
|
|
|
515
522
|
stopTrace();
|
|
516
523
|
}
|
|
517
524
|
|
|
518
|
-
/** @type {
|
|
525
|
+
/** @type {SwingStoreInternal} */
|
|
519
526
|
const internal = harden({
|
|
520
527
|
dirPath: asFile ? null : path,
|
|
521
528
|
asFile,
|
package/src/transcriptStore.js
CHANGED
|
@@ -374,7 +374,7 @@ export function makeTranscriptStore(
|
|
|
374
374
|
* transcript.${vatID}.current export record are responsibility of the caller.
|
|
375
375
|
*
|
|
376
376
|
* @param {string} vatID
|
|
377
|
-
* @param {ReturnType<getCurrentSpanBounds>} bounds
|
|
377
|
+
* @param {ReturnType<typeof getCurrentSpanBounds>} bounds
|
|
378
378
|
* @returns {{deferredTask: Promise<void>}}
|
|
379
379
|
*/
|
|
380
380
|
function closeSpan(vatID, bounds) {
|
package/src/util.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { Buffer } from 'buffer';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @import {AnyIterable} from './exporter.js';
|
|
6
|
+
*/
|
|
7
|
+
|
|
4
8
|
/**
|
|
5
9
|
* This is a polyfill for the `buffer` function from Node's
|
|
6
10
|
* 'stream/consumers' package, which unfortunately only exists in newer versions
|
|
7
11
|
* of Node.
|
|
8
12
|
*
|
|
9
|
-
* @param {
|
|
13
|
+
* @param {AnyIterable<Uint8Array>} inStream
|
|
10
14
|
*/
|
|
11
15
|
export const buffer = async inStream => {
|
|
12
16
|
const chunks = [];
|
package/test/bundles.test.js
CHANGED
|
@@ -9,6 +9,10 @@ import { makeSwingStoreExporter } from '../src/exporter.js';
|
|
|
9
9
|
import { importSwingStore } from '../src/importer.js';
|
|
10
10
|
import { buffer } from '../src/util.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @import {Bundle} from '../src/bundleStore.js';
|
|
14
|
+
*/
|
|
15
|
+
|
|
12
16
|
const tmpDir = makeTempDirFactory(tmp);
|
|
13
17
|
|
|
14
18
|
function makeB0ID(bundle) {
|
|
@@ -19,7 +23,7 @@ test('b0 format', t => {
|
|
|
19
23
|
const { kernelStorage } = initSwingStore();
|
|
20
24
|
const { bundleStore } = kernelStorage;
|
|
21
25
|
|
|
22
|
-
/** @type {
|
|
26
|
+
/** @type {Bundle} */
|
|
23
27
|
const b0A = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
24
28
|
const idA = makeB0ID(b0A);
|
|
25
29
|
bundleStore.addBundle(idA, b0A);
|
|
@@ -32,7 +36,7 @@ test('b0 format', t => {
|
|
|
32
36
|
});
|
|
33
37
|
t.falsy(bundleStore.hasBundle(idBogus));
|
|
34
38
|
|
|
35
|
-
/** @type {
|
|
39
|
+
/** @type {Bundle} */
|
|
36
40
|
const b0B = { moduleFormat: 'getExport', source: '1+1' };
|
|
37
41
|
const idB = makeB0ID(b0B);
|
|
38
42
|
t.throws(() => bundleStore.addBundle(idB, b0B), {
|
|
@@ -73,7 +77,7 @@ test('b0 export', async t => {
|
|
|
73
77
|
});
|
|
74
78
|
const { bundleStore } = kernelStorage;
|
|
75
79
|
|
|
76
|
-
/** @type {
|
|
80
|
+
/** @type {Bundle} */
|
|
77
81
|
const b0A = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
78
82
|
const idA = makeB0ID(b0A);
|
|
79
83
|
bundleStore.addBundle(idA, b0A);
|
package/test/deletion.test.js
CHANGED
|
@@ -14,6 +14,10 @@ import { makeArchiveSnapshot, makeArchiveTranscript } from '../src/archiver.js';
|
|
|
14
14
|
import { makeSwingStoreExporter } from '../src/exporter.js';
|
|
15
15
|
import { importSwingStore } from '../src/importer.js';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @import {ExecutionContext} from 'ava';
|
|
19
|
+
*/
|
|
20
|
+
|
|
17
21
|
const tmpDir = makeTempDirFactory(tmp);
|
|
18
22
|
|
|
19
23
|
async function* getSnapshotStream() {
|
|
@@ -219,7 +223,7 @@ const setupTranscript = async (t, keepTranscripts) => {
|
|
|
219
223
|
};
|
|
220
224
|
|
|
221
225
|
/**
|
|
222
|
-
* @param {
|
|
226
|
+
* @param {ExecutionContext} t
|
|
223
227
|
* @param {{ keepTranscripts: boolean }} config
|
|
224
228
|
*/
|
|
225
229
|
const execSlowTranscriptDeletion = async (t, { keepTranscripts }) => {
|
package/test/export.test.js
CHANGED
|
@@ -8,6 +8,11 @@ import { initSwingStore, makeSwingStoreExporter } from '../src/index.js';
|
|
|
8
8
|
|
|
9
9
|
import { getSnapshotStream, makeB0ID } from './util.js';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @import {ArtifactMode} from '../src/internal.js'
|
|
13
|
+
* @import {Bundle} from '../src/bundleStore.js';
|
|
14
|
+
*/
|
|
15
|
+
|
|
11
16
|
const tmpDir = makeTempDirFactory(tmp);
|
|
12
17
|
|
|
13
18
|
const rank = {
|
|
@@ -23,7 +28,7 @@ const snapshotData = 'snapshot data';
|
|
|
23
28
|
const snapHash =
|
|
24
29
|
'e7dee7266896538616b630a5da40a90e007726a383e005a9c9c5dd0c2daf9329';
|
|
25
30
|
|
|
26
|
-
/** @type {
|
|
31
|
+
/** @type {Bundle} */
|
|
27
32
|
const bundle0 = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
28
33
|
const bundle0ID = makeB0ID(bundle0);
|
|
29
34
|
|
|
@@ -86,7 +91,6 @@ const exportTest = test.macro(async (t, mode) => {
|
|
|
86
91
|
// historical transcript spans, and no historical snapshots
|
|
87
92
|
|
|
88
93
|
assert.typeof(mode, 'string');
|
|
89
|
-
/** @import {ArtifactMode} from '../src/internal.js' */
|
|
90
94
|
let artifactMode = /** @type {ArtifactMode} */ (mode);
|
|
91
95
|
if (mode === 'debug-on-pruned') {
|
|
92
96
|
artifactMode = 'debug';
|
package/test/exports.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { makeB0ID } from './util.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @import {Bundle} from '../src/bundleStore.js';
|
|
6
|
+
* @import {KVPair} from '../src/exporter.js';
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
export const snapshotData = 'snapshot data';
|
|
5
10
|
// this snapHash was computed manually
|
|
6
11
|
export const snapHash =
|
|
7
12
|
'e7dee7266896538616b630a5da40a90e007726a383e005a9c9c5dd0c2daf9329';
|
|
8
13
|
|
|
9
|
-
/** @type {
|
|
14
|
+
/** @type {Bundle} */
|
|
10
15
|
export const bundle0 = { moduleFormat: 'nestedEvaluate', source: '1+1' };
|
|
11
16
|
export const bundle0ID = makeB0ID(bundle0);
|
|
12
17
|
|
|
@@ -81,7 +86,7 @@ export function makeExporter(exportData, artifacts) {
|
|
|
81
86
|
},
|
|
82
87
|
async *getExportData() {
|
|
83
88
|
for (const [key, value] of exportData.entries()) {
|
|
84
|
-
/** @type {
|
|
89
|
+
/** @type { KVPair } */
|
|
85
90
|
const pair = [key, value];
|
|
86
91
|
yield pair;
|
|
87
92
|
}
|