@agoric/swing-store 0.9.2-dev-1b5e57f.0 → 0.9.2-dev-414e88b.0
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 +4 -4
- package/src/exporter.js +33 -0
- package/test/exports.js +3 -0
- package/test/test-bundles.js +6 -0
- package/test/test-export.js +9 -0
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-414e88b.0+414e88b",
|
|
4
4
|
"description": "Persistent storage for SwingSet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"lint:eslint": "eslint ."
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agoric/assert": "0.6.1-dev-
|
|
25
|
-
"@agoric/internal": "0.3.3-dev-
|
|
24
|
+
"@agoric/assert": "0.6.1-dev-414e88b.0+414e88b",
|
|
25
|
+
"@agoric/internal": "0.3.3-dev-414e88b.0+414e88b",
|
|
26
26
|
"@endo/base64": "^0.2.34",
|
|
27
27
|
"@endo/bundle-source": "^2.7.0",
|
|
28
28
|
"@endo/check-bundle": "^0.2.21",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"typeCoverage": {
|
|
52
52
|
"atLeast": 75.52
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "414e88b972e607d7e41cee57c0fc080f62e81f38"
|
|
55
55
|
}
|
package/src/exporter.js
CHANGED
|
@@ -36,6 +36,11 @@ import { validateArtifactMode } from './internal.js';
|
|
|
36
36
|
* the concurrent activity of other swingStore instances, the data representing
|
|
37
37
|
* the commit point will stay consistent and available.
|
|
38
38
|
*
|
|
39
|
+
* @property {(key: string) => string | undefined} getHostKV
|
|
40
|
+
*
|
|
41
|
+
* Retrieve a value from the "host" portion of the kvStore, just like
|
|
42
|
+
* hostStorage.hostKVStore.get() would do.
|
|
43
|
+
*
|
|
39
44
|
* @property {() => AnyIterableIterator<KVPair>} getExportData
|
|
40
45
|
*
|
|
41
46
|
* Get a full copy of the first-stage export data (key-value pairs) from the
|
|
@@ -112,6 +117,33 @@ export function makeSwingStoreExporter(dirPath, options = {}) {
|
|
|
112
117
|
assertComplete(internal, artifactMode);
|
|
113
118
|
}
|
|
114
119
|
|
|
120
|
+
const sqlKVGet = db.prepare(`
|
|
121
|
+
SELECT value
|
|
122
|
+
FROM kvStore
|
|
123
|
+
WHERE key = ?
|
|
124
|
+
`);
|
|
125
|
+
sqlKVGet.pluck(true);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Obtain the value stored for a given host key. This is for the
|
|
129
|
+
* benefit of clients who need to briefly query the DB to ensure
|
|
130
|
+
* they are exporting the right thing, and need to avoid modifying
|
|
131
|
+
* anything (or creating a read-write DB lock) in the process.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} key The key whose value is sought.
|
|
134
|
+
*
|
|
135
|
+
* @returns {string | undefined} the (string) value for the given key, or
|
|
136
|
+
* undefined if there is no such value.
|
|
137
|
+
*
|
|
138
|
+
* @throws if key is not a string, or the key is not in the host
|
|
139
|
+
* section
|
|
140
|
+
*/
|
|
141
|
+
function getHostKV(key) {
|
|
142
|
+
typeof key === 'string' || Fail`key must be a string`;
|
|
143
|
+
getKeyType(key) === 'host' || Fail`getHostKV requires host keys`;
|
|
144
|
+
return sqlKVGet.get(key);
|
|
145
|
+
}
|
|
146
|
+
|
|
115
147
|
const sqlGetAllKVData = db.prepare(`
|
|
116
148
|
SELECT key, value
|
|
117
149
|
FROM kvStore
|
|
@@ -173,6 +205,7 @@ export function makeSwingStoreExporter(dirPath, options = {}) {
|
|
|
173
205
|
}
|
|
174
206
|
|
|
175
207
|
return harden({
|
|
208
|
+
getHostKV,
|
|
176
209
|
getExportData,
|
|
177
210
|
getArtifactNames,
|
|
178
211
|
getArtifact,
|
package/test/exports.js
CHANGED
|
@@ -76,6 +76,9 @@ export function buildData() {
|
|
|
76
76
|
*/
|
|
77
77
|
export function makeExporter(exportData, artifacts) {
|
|
78
78
|
return {
|
|
79
|
+
getHostKV(_key) {
|
|
80
|
+
return undefined;
|
|
81
|
+
},
|
|
79
82
|
async *getExportData() {
|
|
80
83
|
for (const [key, value] of exportData.entries()) {
|
|
81
84
|
/** @type { import('../src/exporter.js').KVPair } */
|
package/test/test-bundles.js
CHANGED
|
@@ -106,6 +106,9 @@ test('b0 import', async t => {
|
|
|
106
106
|
const idA = makeB0ID(b0A);
|
|
107
107
|
const nameA = `bundle.${idA}`;
|
|
108
108
|
const exporter = {
|
|
109
|
+
getHostKV(_key) {
|
|
110
|
+
return undefined;
|
|
111
|
+
},
|
|
109
112
|
async *getExportData() {
|
|
110
113
|
yield /** @type {const} */ ([nameA, idA]);
|
|
111
114
|
},
|
|
@@ -134,6 +137,9 @@ test('b0 bad import', async t => {
|
|
|
134
137
|
const idA = makeB0ID(b0A);
|
|
135
138
|
const nameA = `bundle.${idA}`;
|
|
136
139
|
const exporter = {
|
|
140
|
+
getHostKV(_key) {
|
|
141
|
+
return undefined;
|
|
142
|
+
},
|
|
137
143
|
async *getExportData() {
|
|
138
144
|
yield /** @type {const} */ ([nameA, idA]);
|
|
139
145
|
},
|
package/test/test-export.js
CHANGED
|
@@ -34,6 +34,8 @@ const exportTest = test.macro(async (t, mode) => {
|
|
|
34
34
|
const ss1 = initSwingStore(dbDir, options);
|
|
35
35
|
const ks = ss1.kernelStorage;
|
|
36
36
|
|
|
37
|
+
ss1.hostStorage.kvStore.set('host.h1', 'hostvalue1');
|
|
38
|
+
|
|
37
39
|
// build a DB with four spans (one in an old incarnation, two
|
|
38
40
|
// historical but current incarnation, only one inUse) and two
|
|
39
41
|
// snapshots (only one inUSe)
|
|
@@ -86,6 +88,13 @@ const exportTest = test.macro(async (t, mode) => {
|
|
|
86
88
|
}
|
|
87
89
|
const exporter = makeSwingStoreExporter(dbDir, { artifactMode });
|
|
88
90
|
|
|
91
|
+
// hostKV
|
|
92
|
+
t.is(exporter.getHostKV('host.h1'), 'hostvalue1');
|
|
93
|
+
t.is(exporter.getHostKV('host.hmissing'), undefined);
|
|
94
|
+
t.throws(() => exporter.getHostKV('nonhost'), {
|
|
95
|
+
message: 'getHostKV requires host keys',
|
|
96
|
+
});
|
|
97
|
+
|
|
89
98
|
// exportData
|
|
90
99
|
{
|
|
91
100
|
const exportData = new Map();
|