Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrations/migration-8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions migrations/migration-9/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<void>}
*/
async function migrate (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) {
Expand Down Expand Up @@ -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<void>}
*/
async function revert (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/repo/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/repo/lock-memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>}
Expand Down
8 changes: 4 additions & 4 deletions src/repo/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>}
*/
async function getVersion (path, repoOptions) {
Expand All @@ -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))
Expand All @@ -39,15 +39,15 @@ 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<void>}
*/
async function setVersion (path, version, repoOptions) {
if (!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()
Expand Down
7 changes: 2 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'))
Expand Down
6 changes: 3 additions & 3 deletions test/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions test/migrations/migration-8-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/migrations/migration-9-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/test-migrations/migration-2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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'))
Expand Down