datastore-level
Advanced tools
Comparing version 9.0.0 to 9.0.1
@@ -16,7 +16,9 @@ /** | ||
* @param {string | LevelDb} path | ||
* @param {import('level').DatabaseOptions<string, Uint8Array>} [opts] | ||
* @param {import('level').DatabaseOptions<string, Uint8Array> & import('level').OpenOptions} [opts] | ||
*/ | ||
constructor(path: string | import("abstract-level/types/abstract-level").AbstractLevel<any, string, Uint8Array>, opts?: import("level").DatabaseOptions<string, Uint8Array> | undefined); | ||
constructor(path: string | import("abstract-level/types/abstract-level").AbstractLevel<any, string, Uint8Array>, opts?: (import("classic-level").DatabaseOptions<string, Uint8Array> & import("browser-level").DatabaseOptions<string, Uint8Array> & import("classic-level").OpenOptions & import("abstract-level").AbstractOpenOptions) | undefined); | ||
/** @type {LevelDb} */ | ||
db: import("abstract-level/types/abstract-level").AbstractLevel<any, string, Uint8Array>; | ||
/** @type {import('level').OpenOptions} */ | ||
opts: import('level').OpenOptions; | ||
/** | ||
@@ -61,2 +63,6 @@ * @param {Key} key | ||
} | ||
export type LevelIterator = { | ||
next: (cb: (err: Error, key: string | Uint8Array | null, value: any) => void) => void; | ||
end: (cb: (err: Error) => void) => void; | ||
}; | ||
export type Datastore = import('interface-datastore').Datastore; | ||
@@ -63,0 +69,0 @@ export type Pair = import('interface-datastore').Pair; |
{ | ||
"name": "datastore-level", | ||
"version": "9.0.0", | ||
"version": "9.0.1", | ||
"description": "Datastore implementation with level(up|down) backend", | ||
@@ -5,0 +5,0 @@ "author": "Friedel Ziegelmayer<dignifiedquire@gmail.com>", |
@@ -25,3 +25,3 @@ import { Key } from 'interface-datastore' | ||
* @param {string | LevelDb} path | ||
* @param {import('level').DatabaseOptions<string, Uint8Array>} [opts] | ||
* @param {import('level').DatabaseOptions<string, Uint8Array> & import('level').OpenOptions} [opts] | ||
*/ | ||
@@ -39,2 +39,9 @@ constructor (path, opts = {}) { | ||
: path | ||
/** @type {import('level').OpenOptions} */ | ||
this.opts = { | ||
createIfMissing: true, | ||
compression: false, // same default as go | ||
...opts | ||
} | ||
} | ||
@@ -44,3 +51,3 @@ | ||
try { | ||
await this.db.open() | ||
await this.db.open(this.opts) | ||
} catch (/** @type {any} */ err) { | ||
@@ -217,3 +224,15 @@ throw Errors.dbOpenFailedError(err) | ||
return levelIteratorToIterator(this.db.iterator(iteratorOpts)) | ||
const iterator = this.db.iterator(iteratorOpts) | ||
if (iterator[Symbol.asyncIterator]) { | ||
return levelIteratorToIterator(iterator) | ||
} | ||
// @ts-expect-error support older level | ||
if (iterator.next != null && iterator.end != null) { | ||
// @ts-expect-error support older level | ||
return oldLevelIteratorToIterator(iterator) | ||
} | ||
throw new Error('Level returned incompatible iterator') | ||
} | ||
@@ -233,1 +252,38 @@ } | ||
} | ||
/** | ||
* @typedef {object} LevelIterator | ||
* @property {(cb: (err: Error, key: string | Uint8Array | null, value: any)=> void)=>void} next | ||
* @property {(cb: (err: Error) => void) => void } end | ||
*/ | ||
/** | ||
* @param {LevelIterator} li - Level iterator | ||
* @returns {AsyncIterable<Pair>} | ||
*/ | ||
function oldLevelIteratorToIterator (li) { | ||
return { | ||
[Symbol.asyncIterator] () { | ||
return { | ||
next: () => new Promise((resolve, reject) => { | ||
li.next((err, key, value) => { | ||
if (err) return reject(err) | ||
if (key == null) { | ||
return li.end(err => { | ||
if (err) return reject(err) | ||
resolve({ done: true, value: undefined }) | ||
}) | ||
} | ||
resolve({ done: false, value: { key: new Key(key, false), value } }) | ||
}) | ||
}), | ||
return: () => new Promise((resolve, reject) => { | ||
li.end(err => { | ||
if (err) return reject(err) | ||
resolve({ done: true, value: undefined }) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
131755
774
0