Skip to content

Commit

Permalink
pkg: change exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Sep 25, 2023
1 parent 198731e commit 5c31a63
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
33 changes: 28 additions & 5 deletions lib/bdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@
'use strict';

const assert = require('bsert');
const DB = require('./db');
const Key = require('./key');
const MemDB = require('./memdb');
const Level = require('./level');
const {DB} = require('./db');
const {Key} = require('./key');
const {MemDB} = require('./memdb');
const {Level} = require('./level');

exports.DB = DB;
exports.Key = Key;

/**
* Create a database.
* @param {Object} [options={}]
* @property {String} [options.location] - Database location.
* @property {Boolean} [options.memory=false] - Use an in-memory database.
* @property {Boolean} [options.createIfMissing=true] - Create database if it
* does not exist.
* @property {Boolean} [options.errorIfExists=false] - Error on open if
* database exists.
* @property {Boolean} [options.compression=true] - Enable snappy compression.
* @property {Number} [options.cacheSize=8 << 20] - LRU cache and write buffer
* size.
* @property {Number} [options.maxFiles=64] - Maximum open files.
* @property {Number} [options.maxFileSize=2 << 20] - Maximum file size.
* @returns {DB}
*/

exports.create = (options) => {
if (options == null)
options = {};
Expand All @@ -35,4 +52,10 @@ exports.create = (options) => {
return new DB(Level, location, options);
};

exports.key = (id, args) => new Key(id, args);
/**
* @param {Number|String} id
* @param {String[]|null} [ops=[]]
* @returns {Key}
*/

exports.key = (id, ops) => new Key(id, ops);
14 changes: 4 additions & 10 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const iteratorTypes = {
ITER_TYPE_KEY_VAL
};

/** @typedef {import('./memdb')} MemDB */
/** @typedef {import('./level')} LevelDB */
/** @typedef {import('./memdb').MemDB} MemDB */
/** @typedef {import('./level').Level} Level */

/**
* @typedef {Object} MemDBClass
Expand Down Expand Up @@ -148,7 +148,7 @@ class DB {
/** @type {boolean} */
leveldown;

/** @type {LevelDB|MemDB} */
/** @type {Level|MemDB} */
binding;

/**
Expand Down Expand Up @@ -1762,12 +1762,6 @@ class DBOptions {
this.maxFileSize = options.maxFileSize;
}

if (options.paranoidChecks != null) {
assert(typeof options.paranoidChecks === 'boolean',
'`paranoidChecks` must be a boolean.');
this.paranoidChecks = options.paranoidChecks;
}

if (options.memory != null) {
assert(typeof options.memory === 'boolean',
'`memory` must be a boolean.');
Expand Down Expand Up @@ -1971,4 +1965,4 @@ function versionError(name) {
* Expose
*/

module.exports = DB;
exports.DB = DB;
2 changes: 1 addition & 1 deletion lib/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,4 @@ function writeU16BE(dst, num, off) {
* Expose
*/

module.exports = Key;
exports.Key = Key;
2 changes: 1 addition & 1 deletion lib/level-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,4 @@ function createErrback(callback) {
* Expose
*/

module.exports = Level;
exports.Level = Level;
2 changes: 1 addition & 1 deletion lib/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ function isValue(key) {
* Expose
*/

module.exports = LevelDOWN;
exports.Level = LevelDOWN;
4 changes: 2 additions & 2 deletions lib/memdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict';

const assert = require('bsert');
const RBT = require('./rbt');
const {RBT} = require('./rbt');
const DUMMY = Buffer.alloc(0);

/** @typedef {import('./rbt').RBTData} RBTData */
Expand Down Expand Up @@ -670,4 +670,4 @@ function cmp(a, b) {
* Expose
*/

module.exports = MemDB;
exports.MemDB = MemDB;
4 changes: 2 additions & 2 deletions lib/rbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,5 +963,5 @@ function copyRight(parent, node) {
* Expose
*/

RBT.RBTData = RBTData;
module.exports = RBT;
exports.RBTData = RBTData;
exports.RBT = RBT;

0 comments on commit 5c31a63

Please sign in to comment.