@agoric/swing-store-simple
Advanced tools
Comparing version 0.3.9 to 0.4.0
@@ -6,2 +6,35 @@ # Change Log | ||
## [0.4.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swing-store-simple@0.3.9...@agoric/swing-store-simple@0.4.0) (2021-06-15) | ||
### ⚠ BREAKING CHANGES | ||
* **swing-store-simple:** This includes a renaming and refactoring of the constructors to | ||
acknowledge that the different SwingStore constructors are not polymorphic. | ||
* **swing-store-simple:** most uses of simple swing store use it to get a purely | ||
in-memory store for testing purposes, but a few places used the older .jsonlines | ||
thing for simple persistence. Any existing code that did that requires revision | ||
to use swing-store-lmdb or another persistence mechanism, though all the known | ||
cases that did that have been so revised as part of this update. | ||
### Features | ||
* **swing-store-simple:** refactor and rename constructors ([1c986ba](https://github.com/Agoric/agoric-sdk/commit/1c986baf778f1621328a42d7b4454c196f7befd7)) | ||
* **swing-store-simple:** remove .jsonlines hack from simple swing store ([f3b020a](https://github.com/Agoric/agoric-sdk/commit/f3b020a720bfe33ce67764dceb89b5aeb698855a)) | ||
* greater paranoia about concurrent access ([e67c4ef](https://github.com/Agoric/agoric-sdk/commit/e67c4ef37d2a0d9361612401b43c2b81a4ebc66d)) | ||
* move transcripts out of key-value store and into stream stores ([a128e93](https://github.com/Agoric/agoric-sdk/commit/a128e93803344d8a36140d53d3e7711bec5c2511)) | ||
* overhaul stream store API to better fit actual use in kernel ([c5cc00a](https://github.com/Agoric/agoric-sdk/commit/c5cc00a9e0f1c90ee2cb57fe6c3767a285f4d8e3)) | ||
* provide streamStore implementations ([e094914](https://github.com/Agoric/agoric-sdk/commit/e094914ad5ceec3d1131270e5943c6f0df267cac)) | ||
* remove .jsonlines hack from simple swing store ([ef87997](https://github.com/Agoric/agoric-sdk/commit/ef87997a1519b18f23656b57bf38055fea203f9a)) | ||
### Bug Fixes | ||
* convert swing-store-simple to "type": "module" ([93279c1](https://github.com/Agoric/agoric-sdk/commit/93279c10a01ce55790a0aa8b5f9e2b2ce7e1732e)) | ||
* Pin ESM to forked version ([54dbb55](https://github.com/Agoric/agoric-sdk/commit/54dbb55d64d7ff7adb395bc4bd9d1461dd2d3c17)) | ||
* tweaks and cleanup based on review feedback ([ba95e34](https://github.com/Agoric/agoric-sdk/commit/ba95e34622063eaae47335a0260a004a3a159807)) | ||
* undo 93279c10a01ce55790a0aa8b5f9e2b2ce7e1732e which broke things ([609c973](https://github.com/Agoric/agoric-sdk/commit/609c973bff5f40fe52f054b97fb3518e08022afc)) | ||
## [0.3.9](https://github.com/Agoric/agoric-sdk/compare/@agoric/swing-store-simple@0.3.8...@agoric/swing-store-simple@0.3.9) (2021-05-10) | ||
@@ -8,0 +41,0 @@ |
{ | ||
"name": "@agoric/swing-store-simple", | ||
"version": "0.3.9", | ||
"version": "0.4.0", | ||
"description": "Persistent storage for SwingSet, based on a Map, optionally backed by a simple JSON file", | ||
@@ -8,3 +8,3 @@ "parsers": { | ||
}, | ||
"main": "simpleSwingStore.js", | ||
"main": "src/simpleSwingStore.js", | ||
"repository": "https://github.com/Agoric/agoric-sdk", | ||
@@ -16,14 +16,17 @@ "author": "Agoric", | ||
"test": "ava", | ||
"test:nyc": "nyc ava", | ||
"test:xs": "exit 0", | ||
"lint-fix": "eslint --fix '**/*.js'", | ||
"lint-check": "eslint '**/*.js'" | ||
"lint-fix": "yarn lint:eslint --fix && yarn lint:types", | ||
"lint-check": "yarn lint", | ||
"lint": "yarn lint:types && yarn lint:eslint", | ||
"lint:types": "tsc -p jsconfig.json", | ||
"lint:eslint": "eslint '**/*.js'" | ||
}, | ||
"dependencies": { | ||
"@agoric/assert": "^0.3.0", | ||
"n-readlines": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@agoric/install-ses": "^0.5.14", | ||
"ava": "^3.12.1", | ||
"esm": "^3.2.25", | ||
"nyc": "^15.1.0" | ||
"esm": "agoric-labs/esm#Agoric-built" | ||
}, | ||
@@ -51,3 +54,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "d8f34ff1881b4f7e627f3fdab6888e9ef711bab6" | ||
"gitHead": "9ca63a63f1a46b3564785cb3227010f2ae4e98fa" | ||
} |
@@ -1,25 +0,22 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import '@agoric/install-ses'; | ||
import test from 'ava'; | ||
import { | ||
initSwingStore, | ||
openSwingStore, | ||
getAllState, | ||
isSwingStore, | ||
} from '../simpleSwingStore'; | ||
import { initSimpleSwingStore, getAllState } from '../src/simpleSwingStore.js'; | ||
function testStorage(t, storage) { | ||
t.falsy(storage.has('missing')); | ||
t.is(storage.get('missing'), undefined); | ||
test('kvStore read/write', t => { | ||
const store = initSimpleSwingStore(); | ||
const kvStore = store.kvStore; | ||
storage.set('foo', 'f'); | ||
t.truthy(storage.has('foo')); | ||
t.is(storage.get('foo'), 'f'); | ||
t.falsy(kvStore.has('missing')); | ||
t.is(kvStore.get('missing'), undefined); | ||
storage.set('foo2', 'f2'); | ||
storage.set('foo1', 'f1'); | ||
storage.set('foo3', 'f3'); | ||
t.deepEqual(Array.from(storage.getKeys('foo1', 'foo3')), ['foo1', 'foo2']); | ||
t.deepEqual(Array.from(storage.getKeys('foo1', 'foo4')), [ | ||
kvStore.set('foo', 'f'); | ||
t.truthy(kvStore.has('foo')); | ||
t.is(kvStore.get('foo'), 'f'); | ||
kvStore.set('foo2', 'f2'); | ||
kvStore.set('foo1', 'f1'); | ||
kvStore.set('foo3', 'f3'); | ||
t.deepEqual(Array.from(kvStore.getKeys('foo1', 'foo3')), ['foo1', 'foo2']); | ||
t.deepEqual(Array.from(kvStore.getKeys('foo1', 'foo4')), [ | ||
'foo1', | ||
@@ -30,44 +27,84 @@ 'foo2', | ||
storage.delete('foo2'); | ||
t.falsy(storage.has('foo2')); | ||
t.is(storage.get('foo2'), undefined); | ||
t.deepEqual(Array.from(storage.getKeys('foo1', 'foo4')), ['foo1', 'foo3']); | ||
kvStore.delete('foo2'); | ||
t.falsy(kvStore.has('foo2')); | ||
t.is(kvStore.get('foo2'), undefined); | ||
t.deepEqual(Array.from(kvStore.getKeys('foo1', 'foo4')), ['foo1', 'foo3']); | ||
const reference = { | ||
foo: 'f', | ||
foo1: 'f1', | ||
foo3: 'f3', | ||
kvStuff: { | ||
foo: 'f', | ||
foo1: 'f1', | ||
foo3: 'f3', | ||
}, | ||
streamStuff: new Map(), | ||
}; | ||
t.deepEqual(getAllState(storage), reference, 'check state after changes'); | ||
} | ||
test('storageInMemory', t => { | ||
const { storage } = initSwingStore(); | ||
testStorage(t, storage); | ||
t.deepEqual(getAllState(store), reference, 'check state after changes'); | ||
}); | ||
test('storageInFile', t => { | ||
const dbDir = 'testdb'; | ||
t.teardown(() => fs.rmdirSync(dbDir, { recursive: true })); | ||
fs.rmdirSync(dbDir, { recursive: true }); | ||
t.is(isSwingStore(dbDir), false); | ||
const { storage, commit, close } = initSwingStore(dbDir); | ||
testStorage(t, storage); | ||
test('streamStore read/write', t => { | ||
const { streamStore, commit, close } = initSimpleSwingStore(); | ||
const start = streamStore.STREAM_START; | ||
let s1pos = start; | ||
s1pos = streamStore.writeStreamItem('st1', 'first', s1pos); | ||
s1pos = streamStore.writeStreamItem('st1', 'second', s1pos); | ||
const s1posAlt = { ...s1pos }; | ||
s1pos = streamStore.writeStreamItem('st1', 'third', s1pos); | ||
let s2pos = streamStore.STREAM_START; | ||
s2pos = streamStore.writeStreamItem('st2', 'oneth', s2pos); | ||
s1pos = streamStore.writeStreamItem('st1', 'fourth', s1pos); | ||
s2pos = streamStore.writeStreamItem('st2', 'twoth', s2pos); | ||
const s2posAlt = { ...s2pos }; | ||
s2pos = streamStore.writeStreamItem('st2', 'threeth', s2pos); | ||
s2pos = streamStore.writeStreamItem('st2', 'fourst', s2pos); | ||
streamStore.closeStream('st1'); | ||
streamStore.closeStream('st2'); | ||
const reader1 = streamStore.readStream('st1', start, s1pos); | ||
t.deepEqual(Array.from(reader1), ['first', 'second', 'third', 'fourth']); | ||
s2pos = streamStore.writeStreamItem('st2', 're3', s2posAlt); | ||
streamStore.closeStream('st2'); | ||
const reader2 = streamStore.readStream('st2', start, s2pos); | ||
t.deepEqual(Array.from(reader2), ['oneth', 'twoth', 're3']); | ||
const reader1alt = streamStore.readStream('st1', s1posAlt, s1pos); | ||
t.deepEqual(Array.from(reader1alt), ['third', 'fourth']); | ||
const emptyPos = streamStore.writeStreamItem('empty', 'filler', start); | ||
streamStore.closeStream('empty'); | ||
const readerEmpty = streamStore.readStream('empty', emptyPos, emptyPos); | ||
t.deepEqual(Array.from(readerEmpty), []); | ||
const readerEmpty2 = streamStore.readStream('empty', start, start); | ||
t.deepEqual(Array.from(readerEmpty2), []); | ||
commit(); | ||
const before = getAllState(storage); | ||
close(); | ||
t.is(isSwingStore(dbDir), true); | ||
const { storage: after } = openSwingStore(dbDir); | ||
t.deepEqual(getAllState(after), before, 'check state after reread'); | ||
t.is(isSwingStore(dbDir), true); | ||
}); | ||
test('rejectLMDB', t => { | ||
const notSimpleDir = 'testdb-lmdb'; | ||
t.teardown(() => fs.rmdirSync(notSimpleDir, { recursive: true })); | ||
fs.mkdirSync(notSimpleDir, { recursive: true }); | ||
fs.writeFileSync(path.resolve(notSimpleDir, 'data.mdb'), 'some data\n'); | ||
fs.writeFileSync(path.resolve(notSimpleDir, 'lock.mdb'), 'lock stuff\n'); | ||
t.is(isSwingStore(notSimpleDir), false); | ||
test('streamStore mode interlock', t => { | ||
const { streamStore, commit, close } = initSimpleSwingStore(); | ||
const start = streamStore.STREAM_START; | ||
const s1pos = streamStore.writeStreamItem('st1', 'first', start); | ||
t.throws(() => streamStore.readStream('st1', start, s1pos), { | ||
message: `can't read stream "st1" because it's already in use`, | ||
}); | ||
streamStore.closeStream('st1'); | ||
const reader = streamStore.readStream('st1', start, s1pos); | ||
t.throws(() => streamStore.readStream('st1', start, s1pos), { | ||
message: `can't read stream "st1" because it's already in use`, | ||
}); | ||
t.throws(() => streamStore.writeStreamItem('st1', start, s1pos), { | ||
message: `can't write stream "st1" because it's already in use`, | ||
}); | ||
streamStore.closeStream('st1'); | ||
t.throws(() => reader.next(), { | ||
message: `can't read stream "st1", it's been closed`, | ||
}); | ||
streamStore.closeStream('nonexistent'); | ||
commit(); | ||
close(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
35567
9
422
1
2
1
+ Added@agoric/assert@^0.3.0
+ Added@agoric/assert@0.3.16(transitive)