diff --git a/.gitignore b/.gitignore index ac10e64..a4faaee 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ dist # Dependency directory node_modules package-lock.json - +yarn.lock # Tests test/test-repo-for* test/sharness/tmp diff --git a/migrations/index.js b/migrations/index.js index d60161b..7d8f06c 100644 --- a/migrations/index.js +++ b/migrations/index.js @@ -7,15 +7,15 @@ const emptyMigration = { description: 'Empty migration.', migrate: () => {}, revert: () => {}, - empty: true, + empty: true } module.exports = [ - Object.assign({}, emptyMigration, {version: 7, revert: undefined}), - Object.assign({}, emptyMigration, {version: 6, revert: undefined}), - Object.assign({}, emptyMigration, {version: 5, revert: undefined}), - Object.assign({}, emptyMigration, {version: 4, revert: undefined}), - Object.assign({}, emptyMigration, {version: 3, revert: undefined}), - Object.assign({}, emptyMigration, {version: 2, revert: undefined}), - Object.assign({}, emptyMigration, {version: 1, revert: undefined}), + Object.assign({}, emptyMigration, { version: 7, revert: undefined }), + Object.assign({}, emptyMigration, { version: 6, revert: undefined }), + Object.assign({}, emptyMigration, { version: 5, revert: undefined }), + Object.assign({}, emptyMigration, { version: 4, revert: undefined }), + Object.assign({}, emptyMigration, { version: 3, revert: undefined }), + Object.assign({}, emptyMigration, { version: 2, revert: undefined }), + Object.assign({}, emptyMigration, { version: 1, revert: undefined }) ] diff --git a/package.json b/package.json index 86b6968..cdffa1e 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "main": "src/index.js", "browser": { "./src/repo/lock.js": "./src/repo/lock-memory.js", - "datastore-fs": "datastore-level" + "datastore-fs": "datastore-idb" }, "bin": { "jsipfs-migrations": "./src/cli.js" @@ -44,17 +44,19 @@ "docs": "aegir docs" }, "dependencies": { - "chalk": "^2.4.2", + "buffer": "^5.5.0", + "chalk": "^4.0.0", "datastore-fs": "~0.9.1", - "datastore-level": "~0.12.1", + "datastore-idb": "^1.0.0", + "datastore-level": "~0.14.1", "debug": "^4.1.0", - "interface-datastore": "~0.8.0", + "interface-datastore": "~0.8.3", "proper-lockfile": "^4.1.1", "yargs": "^14.2.0", "yargs-promise": "^1.1.0" }, "devDependencies": { - "aegir": "^20.4.1", + "aegir": "^21.4.5", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "dirty-chai": "^2.0.1", diff --git a/src/repo/init.js b/src/repo/init.js index ca284e4..bf5b8cb 100644 --- a/src/repo/init.js +++ b/src/repo/init.js @@ -12,7 +12,7 @@ exports.isRepoInitialized = async function isRepoInitialized (path) { let root try { root = new Datastore(path, { extension: '', createIfMissing: false }) - + await root.open() const versionCheck = await root.has(versionKey) const configCheck = await root.has(configKey) if (!versionCheck || !configCheck) { diff --git a/src/repo/version.js b/src/repo/version.js index f79149b..34ec0ff 100644 --- a/src/repo/version.js +++ b/src/repo/version.js @@ -1,5 +1,6 @@ 'use strict' +const { Buffer } = require('buffer') const errors = require('../errors') const repoInit = require('./init') const Datastore = require('datastore-fs') diff --git a/test/browser.js b/test/browser.js index b341bf9..cb707f7 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,8 +1,9 @@ /* eslint-env mocha */ 'use strict' +const { Buffer } = require('buffer') const loadFixture = require('aegir/fixtures') -const Datastore = require('datastore-level') +const Datastore = require('datastore-idb') const Key = require('interface-datastore').Key const CONFIG_KEY = new Key('config') diff --git a/test/init-test.js b/test/init-test.js index e9f79b4..0ceb63d 100644 --- a/test/init-test.js +++ b/test/init-test.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const expect = chai.expect +const { Buffer } = require('buffer') +const { expect } = require('./util') const Datastore = require('datastore-fs') const Key = require('interface-datastore').Key @@ -24,7 +24,7 @@ module.exports = (setup, cleanup) => { const store = new Datastore(dir, { extension: '', createIfMissing: false }) await store.open() await store.put(versionKey, Buffer.from('7')) - await store.put(configKey, '') + await store.put(configKey, Buffer.from('config')) await store.close() expect(await repoInit.isRepoInitialized(dir)).to.be.true() diff --git a/test/integration-test.js b/test/integration-test.js index 0ee4964..e09b929 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -1,8 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const expect = chai.expect +const { expect } = require('./util') const migrator = require('../src') const migrations = require('./test-migrations') @@ -26,7 +25,7 @@ module.exports = (setup, cleanup) => { await migrator.migrate(dir, migrator.getLatestMigrationVersion(migrations), { migrations: migrations }) const store = new Datastore(dir, { extension: '', createIfMissing: false }) - + await store.open() const version = await store.get(VERSION_KEY) expect(version.toString()).to.be.equal('2') @@ -42,7 +41,7 @@ module.exports = (setup, cleanup) => { await migrator.revert(dir, 1, { migrations: migrations }) const store = new Datastore(dir, { extension: '', createIfMissing: false }) - + await store.open() const version = await store.get(VERSION_KEY) expect(version.toString()).to.be.equal('1') diff --git a/test/lock-test.js b/test/lock-test.js index 48a7f10..ed6bd85 100644 --- a/test/lock-test.js +++ b/test/lock-test.js @@ -1,8 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const expect = chai.expect +const { expect } = require('./util') // When new lock mechanism is introduced in new version don't forget to update // the range (from/to) of the previous version test's description diff --git a/test/test-migrations/migration-2/index.js b/test/test-migrations/migration-2/index.js index 2db1555..a5cefce 100644 --- a/test/test-migrations/migration-2/index.js +++ b/test/test-migrations/migration-2/index.js @@ -1,7 +1,7 @@ 'use strict' +const { Buffer } = require('buffer') const Datastore = require('datastore-fs') -const path = require('path') const Key = require('interface-datastore').Key const _set = require('just-safe-set') @@ -37,7 +37,7 @@ function datastoreFactory (repoPath, options) { storageBackendOptions = { extension: '' } } - return new StorageBackend(path.join(repoPath), storageBackendOptions) + return new StorageBackend(repoPath, storageBackendOptions) } function addNewApiAddress (config) { @@ -78,6 +78,7 @@ function removeNewApiAddress (config) { async function migrate (repoPath, options, isBrowser) { const store = datastoreFactory(repoPath, options) + await store.open() try { const rawConfig = await store.get(CONFIG_KEY) let config = JSON.parse(rawConfig.toString()) @@ -97,7 +98,7 @@ async function migrate (repoPath, options, isBrowser) { async function revert (repoPath, options, isBrowser) { const store = datastoreFactory(repoPath, options) - + await store.open() try { const rawConfig = await store.get(CONFIG_KEY) let config = JSON.parse(rawConfig.toString()) diff --git a/test/util.js b/test/util.js new file mode 100644 index 0000000..68cfd2a --- /dev/null +++ b/test/util.js @@ -0,0 +1,11 @@ +'use strict' +const chai = require('chai') +const expect = chai.expect +const sinon = require('sinon') +chai.use(require('chai-as-promised')) +chai.use(require('dirty-chai')) + +module.exports = { + expect, + sinon +} diff --git a/test/version-test.js b/test/version-test.js index ff55231..20aac49 100644 --- a/test/version-test.js +++ b/test/version-test.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const expect = chai.expect +const { Buffer } = require('buffer') +const { expect } = require('./util') const Datastore = require('datastore-fs') const Key = require('interface-datastore').Key