diff --git a/migrations/migration-8/index.js b/migrations/migration-8/index.js index 82db4f3..3512a95 100644 --- a/migrations/migration-8/index.js +++ b/migrations/migration-8/index.js @@ -33,7 +33,7 @@ function keyToCid (key) { } async function process (repoPath, repoOptions, onProgress, keyFunction) { - const blockstore = await createStore(repoPath, 'blocks', repoOptions) + const blockstore = createStore(repoPath, 'blocks', repoOptions) await blockstore.open() let blockCount diff --git a/migrations/migration-9/index.js b/migrations/migration-9/index.js index 57d52e9..243e64f 100644 --- a/migrations/migration-9/index.js +++ b/migrations/migration-9/index.js @@ -115,9 +115,9 @@ async function pinsToDAG (blockstore, datastore, pinstore, onProgress) { } async function process (repoPath, repoOptions, onProgress, fn) { - const blockstore = await createStore(repoPath, 'blocks', repoOptions) - const datastore = await createStore(repoPath, 'datastore', repoOptions) - const pinstore = await createStore(repoPath, 'pins', repoOptions) + const blockstore = createStore(repoPath, 'blocks', repoOptions) + const datastore = createStore(repoPath, 'datastore', repoOptions) + const pinstore = createStore(repoPath, 'pins', repoOptions) await blockstore.open() await datastore.open() diff --git a/package.json b/package.json index 06109fd..b4281f1 100644 --- a/package.json +++ b/package.json @@ -41,27 +41,27 @@ "docs": "aegir docs" }, "dependencies": { - "cbor": "^5.0.2", + "cbor": "^6.0.1", "cids": "^1.0.0", - "datastore-core": "^2.0.0", + "datastore-core": "^3.0.0", "debug": "^4.1.0", "fnv1a": "^1.0.1", - "interface-datastore": "^2.0.0", + "interface-datastore": "^3.0.3", "ipld-dag-pb": "^0.20.0", - "it-length": "0.0.2", + "it-length": "^1.0.1", "multibase": "^3.0.0", "multicodec": "^2.0.0", "multihashing-async": "^2.0.0", "proper-lockfile": "^4.1.1", "protons": "^2.0.0", - "uint8arrays": "^1.0.0", - "varint": "^5.0.0" + "uint8arrays": "^2.0.5", + "varint": "^6.0.0" }, "devDependencies": { - "aegir": "^26.0.0", + "aegir": "^30.3.0", "datastore-car": "^1.2.0", - "datastore-fs": "^2.0.1", - "datastore-level": "^2.0.0", + "datastore-fs": "^3.0.0", + "datastore-level": "^3.0.0", "it-all": "^1.0.2", "just-safe-set": "^2.1.0", "ncp": "^2.0.0", diff --git a/src/index.js b/src/index.js index d5089e7..f6ecec3 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,7 @@ exports.errors = errors * Returns the version of latest migration. * If no migrations are present returns 0. * - * @param {array?} migrations - Array of migrations to consider. If undefined, the bundled migrations are used. Mainly for testing purpose. + * @param {?Array} migrations - Array of migrations to consider. If undefined, the bundled migrations are used. Mainly for testing purpose. * @returns {int} */ function getLatestMigrationVersion (migrations) { @@ -40,9 +40,9 @@ exports.getLatestMigrationVersion = getLatestMigrationVersion * @param {int} toVersion - Version to which the repo should be migrated. * @param {Object?} options - Options for migration * @param {boolean?} options.ignoreLock - Won't lock the repo for applying the migrations. Use with caution. - * @param {function?} options.onProgress - Callback which will be called after each executed migration to report progress + * @param {?Function} options.onProgress - Callback which will be called after each executed migration to report progress * @param {boolean?} options.isDryRun - Allows to simulate the execution of the migrations without any effect. - * @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose. + * @param {?Array} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose. * @returns {Promise} */ async function migrate (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) { @@ -141,10 +141,10 @@ exports.migrate = migrate * @param {Object} repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo. * @param {int} toVersion - Version to which the repo will be reverted. * @param {Object?} options - Options for the reversion - * @param {function?} options.onProgress - Callback which will be called after each reverted migration to report progress + * @param {?Function} options.onProgress - Callback which will be called after each reverted migration to report progress * @param {boolean?} options.isDryRun - Allows to simulate the execution of the reversion without any effects. Make sense to utilize onProgress with this argument. * @param {boolean?} options.ignoreLock - Won't lock the repo for reverting the migrations. Use with caution. - * @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose. + * @param {?Array} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose. * @returns {Promise} */ async function revert (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) { @@ -237,7 +237,7 @@ exports.revert = revert /** * Function checks if all migrations in given range are available. * - * @param {array} migrations + * @param {Array} migrations * @param {int} fromVersion * @param {int} toVersion * @param {boolean} checkReversibility - Will additionally checks if all the migrations in the range are reversible diff --git a/src/repo/init.js b/src/repo/init.js index 0b5cb69..edcf184 100644 --- a/src/repo/init.js +++ b/src/repo/init.js @@ -11,7 +11,7 @@ exports.isRepoInitialized = async function isRepoInitialized (path, repoOptions) let root try { - root = await createStore(path, 'root', repoOptions) + root = createStore(path, 'root', repoOptions) await root.open() const versionCheck = await root.has(VERSION_KEY) const configCheck = await root.has(CONFIG_KEY) diff --git a/src/repo/lock-memory.js b/src/repo/lock-memory.js index 25236e0..442367c 100644 --- a/src/repo/lock-memory.js +++ b/src/repo/lock-memory.js @@ -7,6 +7,7 @@ const LOCKS = {} /** * Lock the repo in the given dir and for given repo version. + * * @param {int} version * @param {string} dir * @returns {Promise} diff --git a/src/repo/version.js b/src/repo/version.js index acc2217..ec3d4ad 100644 --- a/src/repo/version.js +++ b/src/repo/version.js @@ -13,7 +13,7 @@ exports.getVersion = getVersion * even in case of change of repo's versioning. * * @param {string} path - * @param {Object} repoOptions Options used to create a repo, the same as pased to ipfs-repo + * @param {Object} repoOptions - Options used to create a repo, the same as pased to ipfs-repo * @returns {Promise} */ async function getVersion (path, repoOptions) { @@ -25,7 +25,7 @@ async function getVersion (path, repoOptions) { throw new MissingRepoOptionsError('Please pass repo options when trying to open a repo') } - const store = await createStore(path, 'root', repoOptions) + const store = createStore(path, 'root', repoOptions) await store.open() const version = parseInt(await store.get(VERSION_KEY)) @@ -39,7 +39,7 @@ async function getVersion (path, repoOptions) { * * @param {string} path * @param {int} version - * @param {Object} repoOptions Options used to create a repo, the same as pased to ipfs-repo + * @param {Object} repoOptions - Options used to create a repo, the same as pased to ipfs-repo * @returns {Promise} */ async function setVersion (path, version, repoOptions) { @@ -47,7 +47,7 @@ async function setVersion (path, version, repoOptions) { throw new MissingRepoOptionsError('Please pass repo options when trying to open a repo') } - const store = await createStore(path, 'root', repoOptions) + const store = createStore(path, 'root', repoOptions) await store.open() await store.put(VERSION_KEY, uint8ArrayFromString(String(version))) await store.close() diff --git a/src/utils.js b/src/utils.js index dda2344..bc24597 100644 --- a/src/utils.js +++ b/src/utils.js @@ -30,7 +30,7 @@ function getDatastoreAndOptions (name, options) { } } -async function createStore (location, name, options) { +function createStore (location, name, options) { const { StorageBackend, storageOptions } = getDatastoreAndOptions(name, options) if (name !== 'root') { @@ -40,12 +40,9 @@ async function createStore (location, name, options) { let store = new StorageBackend(location, storageOptions) if (storageOptions.sharding) { - const shard = new core.shard.NextToLast(2) - store = await ShardingStore.createOrOpen(store, shard) + store = new ShardingStore(store, new core.shard.NextToLast(2)) } - await store.close() - return store } diff --git a/test/fixtures/repo.js b/test/fixtures/repo.js index d38066f..149522c 100644 --- a/test/fixtures/repo.js +++ b/test/fixtures/repo.js @@ -6,7 +6,7 @@ const { CONFIG_KEY, VERSION_KEY, createStore } = require('../../src/utils') async function createRepo (repoOptions, prefix) { const date = Date.now().toString() const dir = `${prefix ? `${prefix}/` : ''}test-repo-for-${date}` - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.close() return dir @@ -15,7 +15,7 @@ async function createRepo (repoOptions, prefix) { async function createAndLoadRepo (repoOptions, prefix) { const date = Date.now().toString() const dir = `${prefix ? `${prefix}/` : ''}test-repo-for-${date}` - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(VERSION_KEY, loadFixture('test/fixtures/test-repo/version')) diff --git a/test/init-test.js b/test/init-test.js index 4125c0e..59d4299 100644 --- a/test/init-test.js +++ b/test/init-test.js @@ -17,7 +17,7 @@ module.exports = (setup, cleanup, repoOptions) => { ) it('should return true with valid initialized repo', async () => { - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(VERSION_KEY, uint8ArrayFromString('7')) await store.put(CONFIG_KEY, uint8ArrayFromString('config')) @@ -27,7 +27,7 @@ module.exports = (setup, cleanup, repoOptions) => { }) it('should return false with missing version key', async () => { - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(CONFIG_KEY, '') await store.close() @@ -36,7 +36,7 @@ module.exports = (setup, cleanup, repoOptions) => { }) it('should return false with missing config key', async () => { - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(VERSION_KEY, '') await store.close() diff --git a/test/integration-test.js b/test/integration-test.js index 262bb25..20d5015 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -23,7 +23,7 @@ module.exports = (setup, cleanup, repoOptions) => { onProgress: () => {} }) - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() const version = await store.get(VERSION_KEY) expect(version.toString()).to.be.equal('2') @@ -45,7 +45,7 @@ module.exports = (setup, cleanup, repoOptions) => { onProgress: () => {} }) - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() const version = await store.get(VERSION_KEY) expect(version.toString()).to.be.equal('1') diff --git a/test/migrations/migration-8-test.js b/test/migrations/migration-8-test.js index 1dc120d..44f4677 100644 --- a/test/migrations/migration-8-test.js +++ b/test/migrations/migration-8-test.js @@ -52,7 +52,7 @@ const blocksFixtures = [ ] async function bootstrapBlocks (dir, encoded, repoOptions) { - const store = await createStore(dir, 'blocks', repoOptions) + const store = createStore(dir, 'blocks', repoOptions) await store.open() for (const blocksNames of blocksFixtures) { @@ -64,7 +64,7 @@ async function bootstrapBlocks (dir, encoded, repoOptions) { } async function validateBlocks (dir, encoded, repoOptions) { - const store = await createStore(dir, 'blocks', repoOptions) + const store = createStore(dir, 'blocks', repoOptions) await store.open() for (const blockNames of blocksFixtures) { diff --git a/test/migrations/migration-9-test.js b/test/migrations/migration-9-test.js index a8a981f..3419765 100644 --- a/test/migrations/migration-9-test.js +++ b/test/migrations/migration-9-test.js @@ -112,9 +112,9 @@ module.exports = (setup, cleanup, repoOptions) => { beforeEach(async () => { dir = await setup() - blockstore = await createStore(dir, 'blocks', repoOptions) - datastore = await createStore(dir, 'datastore', repoOptions) - pinstore = await createStore(dir, 'pins', repoOptions) + blockstore = createStore(dir, 'blocks', repoOptions) + datastore = createStore(dir, 'datastore', repoOptions) + pinstore = createStore(dir, 'pins', repoOptions) }) afterEach(async () => { diff --git a/test/test-migrations/migration-2/index.js b/test/test-migrations/migration-2/index.js index 982f024..b7d7a2a 100644 --- a/test/test-migrations/migration-2/index.js +++ b/test/test-migrations/migration-2/index.js @@ -54,7 +54,7 @@ function removeNewApiAddress (config) { } async function migrate (repoPath, repoOptions, onProgress) { - const store = await createStore(repoPath, 'root', repoOptions) + const store = createStore(repoPath, 'root', repoOptions) await store.open() try { @@ -77,7 +77,7 @@ async function migrate (repoPath, repoOptions, onProgress) { } async function revert (repoPath, repoOptions, onProgress) { - const store = await createStore(repoPath, 'root', repoOptions) + const store = createStore(repoPath, 'root', repoOptions) await store.open() try { diff --git a/test/version-test.js b/test/version-test.js index 1b4e894..76e351c 100644 --- a/test/version-test.js +++ b/test/version-test.js @@ -27,7 +27,7 @@ module.exports = (setup, cleanup, repoOptions) => { describe('version 7 and below', () => { it('should get version number', async () => { // Create version file - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(CONFIG_KEY, uint8ArrayFromString('some dummy config')) await store.put(VERSION_KEY, uint8ArrayFromString('7')) @@ -40,7 +40,7 @@ module.exports = (setup, cleanup, repoOptions) => { await expect(version.getVersion(dir, repoOptions)).to.be.eventually.rejectedWith(errors.NotInitializedRepoError).with.property('code', errors.NotInitializedRepoError.code) // Create version file - const store = await createStore(dir, 'root', repoOptions) + const store = createStore(dir, 'root', repoOptions) await store.open() await store.put(CONFIG_KEY, uint8ArrayFromString('some dummy config')) await store.put(VERSION_KEY, uint8ArrayFromString('5'))