orbit-db-storage-adapter
Advanced tools
Comparing version 0.8.1-75dc731.0 to 0.8.1-7b7166d.0
@@ -1,44 +0,42 @@ | ||
'use strict' | ||
import path from 'path' | ||
import webpack from 'webpack' | ||
import { fileURLToPath } from 'url' | ||
const path = require('path') | ||
const webpack = require('webpack') | ||
export default (env, argv) => { | ||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
module.exports = { | ||
mode: 'production', | ||
entry: './src/index.js', | ||
output: { | ||
libraryTarget: 'var', | ||
library: 'Storage', | ||
filename: '../dist/orbitdb-storage.min.js' | ||
}, | ||
target: 'web', | ||
devtool: 'source-map', | ||
externals: { | ||
fs: '{}', | ||
mkdirp: '{}' | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify(process.env.NODE_ENV) | ||
} | ||
}) | ||
], | ||
resolve: { | ||
modules: [ | ||
'node_modules', | ||
path.resolve(__dirname, '../node_modules') | ||
return { | ||
mode: 'production', | ||
entry: './src/index.js', | ||
output: { | ||
libraryTarget: 'var', | ||
library: 'Storage', | ||
filename: '../dist/orbit-db-storage-adapter.min.js' | ||
}, | ||
target: 'web', | ||
devtool: 'source-map', | ||
externals: { | ||
fs: '{}', | ||
mkdirp: '{}' | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
}) | ||
], | ||
alias: { | ||
leveldown: 'level-js' | ||
resolve: { | ||
modules: [ | ||
'node_modules' | ||
] | ||
}, | ||
resolveLoader: { | ||
modules: [ | ||
'node_modules', | ||
path.resolve(__dirname, '../node_modules') | ||
], | ||
extensions: ['.js', '.json'], | ||
mainFields: ['loader', 'main'] | ||
} | ||
}, | ||
resolveLoader: { | ||
modules: [ | ||
'node_modules', | ||
path.resolve(__dirname, '../node_modules') | ||
], | ||
extensions: ['.js', '.json'], | ||
mainFields: ['loader', 'main'] | ||
} | ||
} |
@@ -1,76 +0,48 @@ | ||
'use strict' | ||
import glob from 'glob' | ||
import webpack from 'webpack' | ||
const glob = require('glob') | ||
const webpack = require('webpack') | ||
const path = require('path') | ||
module.exports = { | ||
// TODO: put all tests in a .js file that webpack can use as entry point | ||
entry: glob.sync('./test/*.spec.js'), | ||
output: { | ||
filename: '../test/browser/bundle.js' | ||
}, | ||
target: 'web', | ||
mode: 'production', | ||
devtool: 'source-map', | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
NODE_ENV: JSON.stringify(process.env.NODE_ENV) | ||
export default (env, argv) => { | ||
return { | ||
// TODO: put all tests in a .js file that webpack can use as entry point | ||
entry: glob.sync('./test/*.spec.js'), | ||
output: { | ||
filename: '../test/browser/bundle.js' | ||
}, | ||
target: 'web', | ||
mode: 'production', | ||
devtool: 'source-map', | ||
plugins: [ | ||
new webpack.ProvidePlugin({ | ||
process: 'process/browser', | ||
Buffer: ['buffer', 'Buffer'] | ||
}) | ||
], | ||
experiments: { | ||
topLevelAwait: true | ||
}, | ||
resolve: { | ||
modules: [ | ||
'node_modules' | ||
], | ||
fallback: { | ||
path: false, | ||
os: false, | ||
fs: false | ||
} | ||
}), | ||
new webpack.IgnorePlugin({ | ||
resourceRegExp: /mongo|redis/, | ||
contextRegExp: /mongo|redis/ | ||
}), | ||
new webpack.ProvidePlugin({ | ||
process: 'process/browser', | ||
Buffer: ['buffer', 'Buffer'] | ||
}) | ||
], | ||
externals: { | ||
fs: '{}', | ||
fatfs: '{}', | ||
runtimejs: '{}', | ||
net: '{}', | ||
tls: '{}', | ||
child_process: {}, | ||
dns: '{}' | ||
}, | ||
resolve: { | ||
modules: [ | ||
'node_modules', | ||
path.resolve(__dirname, '../node_modules') | ||
], | ||
fallback: { | ||
buffer: require.resolve('buffer'), | ||
path: false, | ||
os: false | ||
} | ||
}, | ||
resolveLoader: { | ||
modules: [ | ||
'node_modules', | ||
path.resolve(__dirname, '../node_modules') | ||
], | ||
extensions: ['.js', '.json'], | ||
mainFields: ['loader', 'main'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ | ||
['@babel/preset-env', { modules: false }] | ||
], | ||
plugins: ['@babel/syntax-object-rest-spread', '@babel/transform-runtime', '@babel/plugin-transform-modules-commonjs'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.m?js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: ['@babel/preset-env'] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
{ | ||
"name": "orbit-db-storage-adapter", | ||
"version": "0.8.1-75dc731.0", | ||
"version": "0.8.1-7b7166d.0", | ||
"description": "OrbitDB adapter for any abstract-leveldown compliant storage", | ||
"main": "./src/index.js", | ||
"type": "module", | ||
"scripts": { | ||
@@ -11,3 +12,3 @@ "test": "npm run test:node && npm run test:browser", | ||
"build": "webpack --config ./conf/webpack.config.js", | ||
"build:tests": "webpack --config ./conf/webpack.tests.config.js --mode production", | ||
"build:tests": "webpack --config ./conf/webpack.tests.config.js", | ||
"lint": "standard", | ||
@@ -42,28 +43,21 @@ "lint:fix": "standard --fix" | ||
"level": "^8.0.0", | ||
"level-js": "^6.1.0", | ||
"leveldown": "^6.1.1", | ||
"levelup": "^5.1.1", | ||
"mkdirp": "^1.0.4" | ||
"mkdirp": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.2.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"@babel/plugin-transform-runtime": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/runtime": "^7.4.5", | ||
"@babel/core": "^7.20.12", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.8.3", | ||
"@babel/plugin-transform-modules-commonjs": "^7.20.11", | ||
"@babel/plugin-transform-runtime": "^7.19.6", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/runtime": "^7.20.7", | ||
"assert": "^2.0.0", | ||
"babel-loader": "^8.0.6", | ||
"babel-loader": "^9.1.2", | ||
"buffer": "^6.0.3", | ||
"memdown": "^6.1.1", | ||
"mocha": "^10.0.0", | ||
"mocha": "^10.2.0", | ||
"mocha-headless-chrome": "^4.0.0", | ||
"mongo-unit": "^2.0.1", | ||
"mongodb-memory-server": "^6.9.6", | ||
"mongodown": "^2.0.0", | ||
"process": "^0.11.10", | ||
"standard": "^17.0.0", | ||
"webpack": "^5.74.0", | ||
"webpack-cli": "^4.10.0" | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.1" | ||
} | ||
} |
@@ -31,5 +31,7 @@ # OrbitDB Storage Adapter | ||
// Requirements | ||
const leveldown = require('leveldown') // or any abstract-leveldown complaint store | ||
import leveldown from 'leveldown' // or any abstract-leveldown complaint store | ||
import storageAdapter from 'orbit-db-storage-adapter') | ||
const leveldownOptions = {} | ||
const storage = require('orbit-db-storage-adapter')(leveldown, leveldownOptions) | ||
const storage = storageAdapter(leveldown, leveldownOptions) | ||
@@ -36,0 +38,0 @@ const levelupOptions = {} // see below |
@@ -1,7 +0,4 @@ | ||
'use strict' | ||
import { Level } from 'level' | ||
import * as fs from 'fs' | ||
const levelup = require('levelup') | ||
const { Level } = require('level') | ||
const fs = (typeof window === 'object' || typeof self === 'object') ? null : eval('require("fs")') // eslint-disable-line | ||
// Should work for all abstract-leveldown compliant stores | ||
@@ -29,2 +26,5 @@ | ||
this.storage = storage | ||
// TODO: we can probably remove all of the below as they're related | ||
// to the older versions of leveldb | ||
this.preCreate = options.preCreate ? options.preCreate : () => {} | ||
@@ -38,34 +38,19 @@ | ||
async createStore (directory = './orbitdb', options = {}) { | ||
// TODO: we can probably remove the two lines below as they're | ||
// related to older versions of leveldb | ||
this.options.up = options | ||
await this.preCreate(directory, this.options) | ||
let store, db | ||
if (this.storage) { | ||
db = this.storage(directory, this.options.down) | ||
// For compatibility with older abstract-leveldown stores | ||
if (!db.status) db.status = 'unknown-shim' | ||
if (!db.location) db.location = directory | ||
store = levelup(db, options) | ||
await store.open() // TODO: Is this necessary? https://www.npmjs.com/package/levelup says it is only necessary when reopening a closed db. | ||
// More backwards compatibility | ||
db.status = db && db.status === 'unknown-shim' ? 'open' : db.status | ||
return store // should this not be db? | ||
} else { | ||
// Default leveldown or level-js store with directory creation | ||
if (!this.storage) { | ||
if (fs && fs.mkdirSync) fs.mkdirSync(directory, { recursive: true }) | ||
} | ||
const db = new Level(directory, options) | ||
await db.open() | ||
const db = new Level(directory, options) | ||
await db.open() | ||
return levelup(db) | ||
} | ||
return db | ||
} | ||
async destroy (store) { | ||
if (!this.storage.destory) return | ||
if (!this.storage || !this.storage.destroy) return | ||
@@ -78,2 +63,2 @@ await this.storage.destory(store._db.location) | ||
module.exports = (storage, options) => new Storage(storage, options) | ||
export default (storage, options) => new Storage(storage, options) |
@@ -1,5 +0,4 @@ | ||
const assert = require('assert') | ||
import assert from 'assert' | ||
import Storage from '../src/index.js' | ||
const Storage = require('../src') | ||
const implementations = require('./implementations') | ||
const timeout = 2000 | ||
@@ -26,4 +25,4 @@ | ||
it('creates a level store if no storage is passed', async () => { | ||
assert.strictEqual(store.db.status, 'open') | ||
assert.strictEqual(store.db.location, './orbitdb') | ||
assert.strictEqual(store.status, 'open') | ||
assert.strictEqual(store.location, './orbitdb') | ||
}) | ||
@@ -56,61 +55,49 @@ | ||
implementations.forEach(implementation => { | ||
describe(`Storage Adapters - ${implementation.key}`, function () { | ||
this.timeout(timeout) | ||
describe('Storage Adapters - LevelDB', function () { | ||
this.timeout(timeout) | ||
let storage, store | ||
let storage, store | ||
const location = implementation.fileName | ||
const server = implementation.server | ||
beforeEach(async () => { | ||
storage = Storage() | ||
}) | ||
beforeEach(async () => { | ||
const storageType = implementation.module | ||
storage = Storage(storageType) | ||
if (server && server.start) await implementation.server.start({}) | ||
}) | ||
afterEach(async () => { | ||
await store.close() | ||
await storage.destroy(store) | ||
}) | ||
afterEach(async () => { | ||
await store.close() | ||
await storage.destroy(store) | ||
if (server && server.afterEach) await implementation.server.afterEach() | ||
}) | ||
it('Creates a store in default ./orbitdb directory', async () => { | ||
store = await storage.createStore() | ||
assert.strictEqual(store.status, 'open') | ||
assert.strictEqual(store.location, './orbitdb') | ||
}) | ||
after(async () => { | ||
if (server && server.stop) await implementation.server.stop() | ||
}) | ||
it('Creates a store in a custom directory', async () => { | ||
store = await storage.createStore('./customDir') | ||
assert.strictEqual(store.status, 'open') | ||
assert.strictEqual(store.location, './customDir') | ||
}) | ||
it('Creates a store in default ./orbitdb directory', async () => { | ||
store = await storage.createStore(location, implementation.defaultOptions || {}) | ||
assert.strictEqual(store.db.status, 'open') | ||
assert.strictEqual(store.db.location, location || './orbitdb') | ||
data.forEach(d => { | ||
it(`puts and gets a ${d.key}`, async () => { | ||
store = await storage.createStore() | ||
await store.put(d.key, JSON.stringify(d.value)) | ||
const val = await store.get(d.key) | ||
const decodedVal = JSON.parse(val.toString()) | ||
assert.deepStrictEqual(decodedVal, d.value) | ||
assert.strictEqual(typeof decodedVal, d.type) | ||
}) | ||
it('Creates a store in a custom directory', async () => { | ||
store = await storage.createStore(location || './customDir') | ||
assert.strictEqual(store.db.status, 'open') | ||
assert.strictEqual(store.db.location, location || './customDir') | ||
it('deletes properly', async () => { | ||
store = await storage.createStore() | ||
await store.put(d.key, JSON.stringify(d.value)) | ||
await store.del(d.key, JSON.stringify(d.value)) | ||
try { | ||
await store.get(d.key) | ||
} catch (e) { | ||
assert.strictEqual(true, true) | ||
} | ||
}) | ||
data.forEach(d => { | ||
it(`puts and gets a ${d.key}`, async () => { | ||
store = await storage.createStore(location, implementation.defaultOptions || {}) | ||
await store.put(d.key, JSON.stringify(d.value)) | ||
const val = await store.get(d.key) | ||
const decodedVal = JSON.parse(val.toString()) | ||
assert.deepStrictEqual(decodedVal, d.value) | ||
assert.strictEqual(typeof decodedVal, d.type) | ||
}) | ||
it('deletes properly', async () => { | ||
store = await storage.createStore(location, implementation.defaultOptions || {}) | ||
await store.put(d.key, JSON.stringify(d.value)) | ||
await store.del(d.key, JSON.stringify(d.value)) | ||
try { | ||
await store.get(d.key) | ||
} catch (e) { | ||
assert.strictEqual(true, true) | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
2
15
57
1
2
Yes
99918
32
515
+ Addedmkdirp@2.1.6(transitive)
- Removedlevel-js@^6.1.0
- Removedleveldown@^6.1.1
- Removedlevelup@^5.1.1
- Removedabstract-leveldown@7.2.0(transitive)
- Removeddeferred-leveldown@7.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlevel-concat-iterator@3.1.0(transitive)
- Removedlevel-errors@3.0.1(transitive)
- Removedlevel-iterator-stream@5.0.0(transitive)
- Removedlevel-js@6.1.0(transitive)
- Removedlevel-supports@2.1.0(transitive)
- Removedleveldown@6.1.1(transitive)
- Removedlevelup@5.1.1(transitive)
- Removedltgt@2.2.1(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removednapi-macros@2.0.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedmkdirp@^2.1.1