From 51ab0791537401e33a7a5c32034c2ea1d6be7c66 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Fri, 30 Dec 2022 03:07:01 +0000 Subject: [PATCH] fix: pass path to migration. --- package-lock.json | 40 +++++-------------- package.json | 2 +- src/OrbitDB.js | 15 +++---- src/db-manifest.js | 4 +- src/exchange-heads.js | 2 +- .../access-controller-handlers.test.js | 2 +- .../contract-access-controller.test.js | 2 +- test/access-controllers/utils/start-ipfs.js | 2 +- test/re-exports.test.js | 2 +- 9 files changed, 27 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd689ba..300f085 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "go-ipfs": "^0.9.1", "ipfs": "^0.59.0", "ipfsd-ctl": "^10.0.3", - "localstorage-level-migration": "~0.1.0", + "localstorage-level-migration": "github:haydenyoung/localstorage-level-migration#esm", "markdown-toc": "^1.2.0", "mkdirp": "^1.0.4", "mocha": "^9.1.3", @@ -16162,12 +16162,14 @@ }, "node_modules/localstorage-level-migration": { "version": "0.1.0", - "resolved": "https://registry.npmjs.org/localstorage-level-migration/-/localstorage-level-migration-0.1.0.tgz", - "integrity": "sha512-T/FsTw6oDXOD4HZiA+H6IRsZm1laN4C9yYuWYMJeKrpBr0VrcFGRd/kJqf1/DxjNo7Xfp68xmSWEdh6aIt1BqQ==", + "resolved": "git+ssh://git@github.com/haydenyoung/localstorage-level-migration.git#a02a62c2c5e70aaee9b3b8d523be64e3e931cfb8", "dev": true, + "license": "MIT", "dependencies": { "level": "^5.0.0", - "mkdirp": "^0.5.1", + "level-js": "^6.1.0", + "levelup": "^5.1.1", + "mkdirp": "^1.0.4", "node-localstorage": "^1.3.1" } }, @@ -16416,18 +16418,6 @@ "node": ">=6" } }, - "node_modules/localstorage-level-migration/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/localstorage-level-migration/node_modules/node-gyp-build": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", @@ -42788,13 +42778,14 @@ } }, "localstorage-level-migration": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/localstorage-level-migration/-/localstorage-level-migration-0.1.0.tgz", - "integrity": "sha512-T/FsTw6oDXOD4HZiA+H6IRsZm1laN4C9yYuWYMJeKrpBr0VrcFGRd/kJqf1/DxjNo7Xfp68xmSWEdh6aIt1BqQ==", + "version": "git+ssh://git@github.com/haydenyoung/localstorage-level-migration.git#a02a62c2c5e70aaee9b3b8d523be64e3e931cfb8", "dev": true, + "from": "localstorage-level-migration@github:haydenyoung/localstorage-level-migration#esm", "requires": { "level": "^5.0.0", - "mkdirp": "^0.5.1", + "level-js": "^6.1.0", + "levelup": "^5.1.1", + "mkdirp": "^1.0.4", "node-localstorage": "^1.3.1" }, "dependencies": { @@ -42988,15 +42979,6 @@ "xtend": "~4.0.0" } }, - "mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "requires": { - "minimist": "^1.2.6" - } - }, "node-gyp-build": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", diff --git a/package.json b/package.json index 614bed8..89a5a91 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "go-ipfs": "^0.9.1", "ipfs": "^0.59.0", "ipfsd-ctl": "^10.0.3", - "localstorage-level-migration": "~0.1.0", + "localstorage-level-migration": "github:haydenyoung/localstorage-level-migration#esm", "markdown-toc": "^1.2.0", "mkdirp": "^1.0.4", "mocha": "^9.1.3", diff --git a/src/OrbitDB.js b/src/OrbitDB.js index d67a4a9..fbffabf 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -9,7 +9,7 @@ import Pubsub from 'orbit-db-pubsub' import Cache from 'orbit-db-cache' import Keystore from 'orbit-db-keystore' import Identities from 'orbit-db-identity-provider' -import AccessControllers from 'orbit-db-access-controllers' +import DefaultAccessControllers from 'orbit-db-access-controllers' import OrbitDBAddress from './orbit-db-address.js' import createDBManifest from './db-manifest.js' import exchangeHeads from './exchange-heads.js' @@ -31,6 +31,7 @@ const databaseTypes = { } const defaultTimeout = 30000 // 30 seconds +let AccessControllers = DefaultAccessControllers export default class OrbitDB { constructor (ipfs, identity, options = {}) { @@ -43,8 +44,8 @@ export default class OrbitDB { this.id = options.peerId this._pubsub = !options.offline ? new ( - options.broker ? options.broker : Pubsub - )(this._ipfs, this.id) + options.broker ? options.broker : Pubsub + )(this._ipfs, this.id) : null this.directory = options.directory || './orbitdb' this.storage = options.storage @@ -111,7 +112,7 @@ export default class OrbitDB { if (!options.identity) { options.identity = await Identities.createIdentity({ - id: id, + id, keystore: options.keystore }) } @@ -224,7 +225,7 @@ export default class OrbitDB { } const opts = Object.assign({ replicate: true }, options, { - accessController: accessController, + accessController, cache: options.cache, onClose: this._onClose.bind(this), onDrop: this._onDrop.bind(this), @@ -332,7 +333,7 @@ export default class OrbitDB { if (OrbitDBAddress.isValid(name)) { throw new Error('Given database name is an address. Please give only the name of the database!') } // Create an AccessController, use IPFS AC as the default - options.accessController = Object.assign({}, { name: name, type: 'ipfs' }, options.accessController) + options.accessController = Object.assign({}, { name, type: 'ipfs' }, options.accessController) const accessControllerAddress = await AccessControllers.create(this, options.accessController.type, options.accessController || {}) // Save the manifest to IPFS @@ -365,7 +366,7 @@ export default class OrbitDB { if (haveDB && !options.overwrite) { throw new Error(`Database '${dbAddress}' already exists!`) } - await this._migrate(options, dbAddress) + await this._migrate({ ...options, ...{ directory: this.directory } }, dbAddress) // Save the database locally await this._addManifestToCache(options.cache, dbAddress) diff --git a/src/db-manifest.js b/src/db-manifest.js index 797edad..8ce922c 100644 --- a/src/db-manifest.js +++ b/src/db-manifest.js @@ -4,8 +4,8 @@ import * as io from 'orbit-db-io' // Creates a DB manifest file and saves it in IPFS export default async (ipfs, name, type, accessControllerAddress, options) => { const manifest = Object.assign({ - name: name, - type: type, + name, + type, accessController: (path.posix || path).join('/ipfs', accessControllerAddress) }, // meta field is only added to manifest if options.meta is defined diff --git a/src/exchange-heads.js b/src/exchange-heads.js index 77ad7ac..b5d34c6 100644 --- a/src/exchange-heads.js +++ b/src/exchange-heads.js @@ -38,7 +38,7 @@ export default async (ipfs, address, peer, getStore, getDirectConnection, onMess const heads = await getHeadsForDatabase(getStore(address)) logger.debug(`Send latest heads of '${address}':\n`, JSON.stringify(heads.map(e => e.hash), null, 2)) if (heads) { - await channel.send(JSON.stringify({ address: address, heads: heads })) + await channel.send(JSON.stringify({ address, heads })) } return channel diff --git a/test/access-controllers/access-controller-handlers.test.js b/test/access-controllers/access-controller-handlers.test.js index 04acde4..5c79503 100644 --- a/test/access-controllers/access-controller-handlers.test.js +++ b/test/access-controllers/access-controller-handlers.test.js @@ -122,7 +122,7 @@ Object.keys(testAPIs).forEach(API => { } catch (e) { err = e.toString() } - assert.strictEqual(err, 'Error: Given AccessController class needs to implement: static get type() { /* return a string /}.') + assert.strictEqual(err, 'Error: Given AccessController class needs to implement: static get type() { /* return a string */}.') }) it('creates a custom access controller', async () => { diff --git a/test/access-controllers/contract-access-controller.test.js b/test/access-controllers/contract-access-controller.test.js index 8a86f72..1d3cff2 100644 --- a/test/access-controllers/contract-access-controller.test.js +++ b/test/access-controllers/contract-access-controller.test.js @@ -110,7 +110,7 @@ Object.keys(testAPIs).forEach(API => { await accessController.load() }) - it.only('creates an access controller', () => { + it('creates an access controller', () => { assert.notStrictEqual(accessController, null) assert.notStrictEqual(accessController, undefined) }) diff --git a/test/access-controllers/utils/start-ipfs.js b/test/access-controllers/utils/start-ipfs.js index 6685bf3..583ada5 100644 --- a/test/access-controllers/utils/start-ipfs.js +++ b/test/access-controllers/utils/start-ipfs.js @@ -1,4 +1,4 @@ -import IPFSFactory from 'ipfsd-ctl' +import * as IPFSFactory from 'ipfsd-ctl' import { testAPIs } from './test-apis.js' /** diff --git a/test/re-exports.test.js b/test/re-exports.test.js index 1c46398..56bfad9 100644 --- a/test/re-exports.test.js +++ b/test/re-exports.test.js @@ -1,7 +1,7 @@ import assert from 'assert' import OrbitDB from '../src/OrbitDB.js' -const AccessController = OrbitDB.AccessController +const AccessControllers = OrbitDB.AccessControllers const Identities = OrbitDB.Identities const Keystore = OrbitDB.Keystore