levelgraph
Version:
A graph database for Node.js and the browser built on top of LevelUp
1 lines • 454 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.level=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r}()({1:[function(require,module,exports){"use strict";const{fromCallback}=require("catering");const ModuleError=require("module-error");const{getCallback,getOptions}=require("./lib/common");const kPromise=Symbol("promise");const kStatus=Symbol("status");const kOperations=Symbol("operations");const kFinishClose=Symbol("finishClose");const kCloseCallbacks=Symbol("closeCallbacks");class AbstractChainedBatch{constructor(db){if(typeof db!=="object"||db===null){const hint=db===null?"null":typeof db;throw new TypeError(`The first argument must be an abstract-level database, received ${hint}`)}this[kOperations]=[];this[kCloseCallbacks]=[];this[kStatus]="open";this[kFinishClose]=this[kFinishClose].bind(this);this.db=db;this.db.attachResource(this);this.nextTick=db.nextTick}get length(){return this[kOperations].length}put(key,value,options){if(this[kStatus]!=="open"){throw new ModuleError("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})}const err=this.db._checkKey(key)||this.db._checkValue(value);if(err)throw err;const db=options&&options.sublevel!=null?options.sublevel:this.db;const original=options;const keyEncoding=db.keyEncoding(options&&options.keyEncoding);const valueEncoding=db.valueEncoding(options&&options.valueEncoding);const keyFormat=keyEncoding.format;options={...options,keyEncoding:keyFormat,valueEncoding:valueEncoding.format};if(db!==this.db){options.sublevel=null}const mappedKey=db.prefixKey(keyEncoding.encode(key),keyFormat);const mappedValue=valueEncoding.encode(value);this._put(mappedKey,mappedValue,options);this[kOperations].push({...original,type:"put",key:key,value:value});return this}_put(key,value,options){}del(key,options){if(this[kStatus]!=="open"){throw new ModuleError("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})}const err=this.db._checkKey(key);if(err)throw err;const db=options&&options.sublevel!=null?options.sublevel:this.db;const original=options;const keyEncoding=db.keyEncoding(options&&options.keyEncoding);const keyFormat=keyEncoding.format;options={...options,keyEncoding:keyFormat};if(db!==this.db){options.sublevel=null}this._del(db.prefixKey(keyEncoding.encode(key),keyFormat),options);this[kOperations].push({...original,type:"del",key:key});return this}_del(key,options){}clear(){if(this[kStatus]!=="open"){throw new ModuleError("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})}this._clear();this[kOperations]=[];return this}_clear(){}write(options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options);if(this[kStatus]!=="open"){this.nextTick(callback,new ModuleError("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}else if(this.length===0){this.close(callback)}else{this[kStatus]="writing";this._write(options,err=>{this[kStatus]="closing";this[kCloseCallbacks].push(()=>callback(err));if(!err)this.db.emit("batch",this[kOperations]);this._close(this[kFinishClose])})}return callback[kPromise]}_write(options,callback){}close(callback){callback=fromCallback(callback,kPromise);if(this[kStatus]==="closing"){this[kCloseCallbacks].push(callback)}else if(this[kStatus]==="closed"){this.nextTick(callback)}else{this[kCloseCallbacks].push(callback);if(this[kStatus]!=="writing"){this[kStatus]="closing";this._close(this[kFinishClose])}}return callback[kPromise]}_close(callback){this.nextTick(callback)}[kFinishClose](){this[kStatus]="closed";this.db.detachResource(this);const callbacks=this[kCloseCallbacks];this[kCloseCallbacks]=[];for(const cb of callbacks){cb()}}}exports.AbstractChainedBatch=AbstractChainedBatch},{"./lib/common":7,catering:20,"module-error":31}],2:[function(require,module,exports){"use strict";const{fromCallback}=require("catering");const ModuleError=require("module-error");const{getOptions,getCallback}=require("./lib/common");const kPromise=Symbol("promise");const kCallback=Symbol("callback");const kWorking=Symbol("working");const kHandleOne=Symbol("handleOne");const kHandleMany=Symbol("handleMany");const kAutoClose=Symbol("autoClose");const kFinishWork=Symbol("finishWork");const kReturnMany=Symbol("returnMany");const kClosing=Symbol("closing");const kHandleClose=Symbol("handleClose");const kClosed=Symbol("closed");const kCloseCallbacks=Symbol("closeCallbacks");const kKeyEncoding=Symbol("keyEncoding");const kValueEncoding=Symbol("valueEncoding");const kAbortOnClose=Symbol("abortOnClose");const kLegacy=Symbol("legacy");const kKeys=Symbol("keys");const kValues=Symbol("values");const kLimit=Symbol("limit");const kCount=Symbol("count");const emptyOptions=Object.freeze({});const noop=()=>{};let warnedEnd=false;class CommonIterator{constructor(db,options,legacy){if(typeof db!=="object"||db===null){const hint=db===null?"null":typeof db;throw new TypeError(`The first argument must be an abstract-level database, received ${hint}`)}if(typeof options!=="object"||options===null){throw new TypeError("The second argument must be an options object")}this[kClosed]=false;this[kCloseCallbacks]=[];this[kWorking]=false;this[kClosing]=false;this[kAutoClose]=false;this[kCallback]=null;this[kHandleOne]=this[kHandleOne].bind(this);this[kHandleMany]=this[kHandleMany].bind(this);this[kHandleClose]=this[kHandleClose].bind(this);this[kKeyEncoding]=options[kKeyEncoding];this[kValueEncoding]=options[kValueEncoding];this[kLegacy]=legacy;this[kLimit]=Number.isInteger(options.limit)&&options.limit>=0?options.limit:Infinity;this[kCount]=0;this[kAbortOnClose]=!!options.abortOnClose;this.db=db;this.db.attachResource(this);this.nextTick=db.nextTick}get count(){return this[kCount]}get limit(){return this[kLimit]}next(callback){let promise;if(callback===undefined){promise=new Promise((resolve,reject)=>{callback=(err,key,value)=>{if(err)reject(err);else if(!this[kLegacy])resolve(key);else if(key===undefined&&value===undefined)resolve();else resolve([key,value])}})}else if(typeof callback!=="function"){throw new TypeError("Callback must be a function")}if(this[kClosing]){this.nextTick(callback,new ModuleError("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}else if(this[kWorking]){this.nextTick(callback,new ModuleError("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"}))}else{this[kWorking]=true;this[kCallback]=callback;if(this[kCount]>=this[kLimit])this.nextTick(this[kHandleOne],null);else this._next(this[kHandleOne])}return promise}_next(callback){this.nextTick(callback)}nextv(size,options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,emptyOptions);if(!Number.isInteger(size)){this.nextTick(callback,new TypeError("The first argument 'size' must be an integer"));return callback[kPromise]}if(this[kClosing]){this.nextTick(callback,new ModuleError("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}else if(this[kWorking]){this.nextTick(callback,new ModuleError("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"}))}else{if(size<1)size=1;if(this[kLimit]<Infinity)size=Math.min(size,this[kLimit]-this[kCount]);this[kWorking]=true;this[kCallback]=callback;if(size<=0)this.nextTick(this[kHandleMany],null,[]);else this._nextv(size,options,this[kHandleMany])}return callback[kPromise]}_nextv(size,options,callback){const acc=[];const onnext=(err,key,value)=>{if(err){return callback(err)}else if(this[kLegacy]?key===undefined&&value===undefined:key===undefined){return callback(null,acc)}acc.push(this[kLegacy]?[key,value]:key);if(acc.length===size){callback(null,acc)}else{this._next(onnext)}};this._next(onnext)}all(options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,emptyOptions);if(this[kClosing]){this.nextTick(callback,new ModuleError("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}else if(this[kWorking]){this.nextTick(callback,new ModuleError("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"}))}else{this[kWorking]=true;this[kCallback]=callback;this[kAutoClose]=true;if(this[kCount]>=this[kLimit])this.nextTick(this[kHandleMany],null,[]);else this._all(options,this[kHandleMany])}return callback[kPromise]}_all(options,callback){let count=this[kCount];const acc=[];const nextv=()=>{const size=this[kLimit]<Infinity?Math.min(1e3,this[kLimit]-count):1e3;if(size<=0){this.nextTick(callback,null,acc)}else{this._nextv(size,emptyOptions,onnextv)}};const onnextv=(err,items)=>{if(err){callback(err)}else if(items.length===0){callback(null,acc)}else{acc.push.apply(acc,items);count+=items.length;nextv()}};nextv()}[kFinishWork](){const cb=this[kCallback];if(this[kAbortOnClose]&&cb===null)return noop;this[kWorking]=false;this[kCallback]=null;if(this[kClosing])this._close(this[kHandleClose]);return cb}[kReturnMany](cb,err,items){if(this[kAutoClose]){this.close(cb.bind(null,err,items))}else{cb(err,items)}}seek(target,options){options=getOptions(options,emptyOptions);if(this[kClosing]){}else if(this[kWorking]){throw new ModuleError("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"})}else{const keyEncoding=this.db.keyEncoding(options.keyEncoding||this[kKeyEncoding]);const keyFormat=keyEncoding.format;if(options.keyEncoding!==keyFormat){options={...options,keyEncoding:keyFormat}}const mapped=this.db.prefixKey(keyEncoding.encode(target),keyFormat);this._seek(mapped,options)}}_seek(target,options){throw new ModuleError("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(callback){callback=fromCallback(callback,kPromise);if(this[kClosed]){this.nextTick(callback)}else if(this[kClosing]){this[kCloseCallbacks].push(callback)}else{this[kClosing]=true;this[kCloseCallbacks].push(callback);if(!this[kWorking]){this._close(this[kHandleClose])}else if(this[kAbortOnClose]){const cb=this[kFinishWork]();cb(new ModuleError("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}}return callback[kPromise]}_close(callback){this.nextTick(callback)}[kHandleClose](){this[kClosed]=true;this.db.detachResource(this);const callbacks=this[kCloseCallbacks];this[kCloseCallbacks]=[];for(const cb of callbacks){cb()}}async*[Symbol.asyncIterator](){try{let item;while((item=await this.next())!==undefined){yield item}}finally{if(!this[kClosed])await this.close()}}}class AbstractIterator extends CommonIterator{constructor(db,options){super(db,options,true);this[kKeys]=options.keys!==false;this[kValues]=options.values!==false}[kHandleOne](err,key,value){const cb=this[kFinishWork]();if(err)return cb(err);try{key=this[kKeys]&&key!==undefined?this[kKeyEncoding].decode(key):undefined;value=this[kValues]&&value!==undefined?this[kValueEncoding].decode(value):undefined}catch(err){return cb(new IteratorDecodeError("entry",err))}if(!(key===undefined&&value===undefined)){this[kCount]++}cb(null,key,value)}[kHandleMany](err,entries){const cb=this[kFinishWork]();if(err)return this[kReturnMany](cb,err);try{for(const entry of entries){const key=entry[0];const value=entry[1];entry[0]=this[kKeys]&&key!==undefined?this[kKeyEncoding].decode(key):undefined;entry[1]=this[kValues]&&value!==undefined?this[kValueEncoding].decode(value):undefined}}catch(err){return this[kReturnMany](cb,new IteratorDecodeError("entries",err))}this[kCount]+=entries.length;this[kReturnMany](cb,null,entries)}end(callback){if(!warnedEnd&&typeof console!=="undefined"){warnedEnd=true;console.warn(new ModuleError("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))}return this.close(callback)}}class AbstractKeyIterator extends CommonIterator{constructor(db,options){super(db,options,false)}[kHandleOne](err,key){const cb=this[kFinishWork]();if(err)return cb(err);try{key=key!==undefined?this[kKeyEncoding].decode(key):undefined}catch(err){return cb(new IteratorDecodeError("key",err))}if(key!==undefined)this[kCount]++;cb(null,key)}[kHandleMany](err,keys){const cb=this[kFinishWork]();if(err)return this[kReturnMany](cb,err);try{for(let i=0;i<keys.length;i++){const key=keys[i];keys[i]=key!==undefined?this[kKeyEncoding].decode(key):undefined}}catch(err){return this[kReturnMany](cb,new IteratorDecodeError("keys",err))}this[kCount]+=keys.length;this[kReturnMany](cb,null,keys)}}class AbstractValueIterator extends CommonIterator{constructor(db,options){super(db,options,false)}[kHandleOne](err,value){const cb=this[kFinishWork]();if(err)return cb(err);try{value=value!==undefined?this[kValueEncoding].decode(value):undefined}catch(err){return cb(new IteratorDecodeError("value",err))}if(value!==undefined)this[kCount]++;cb(null,value)}[kHandleMany](err,values){const cb=this[kFinishWork]();if(err)return this[kReturnMany](cb,err);try{for(let i=0;i<values.length;i++){const value=values[i];values[i]=value!==undefined?this[kValueEncoding].decode(value):undefined}}catch(err){return this[kReturnMany](cb,new IteratorDecodeError("values",err))}this[kCount]+=values.length;this[kReturnMany](cb,null,values)}}class IteratorDecodeError extends ModuleError{constructor(subject,cause){super(`Iterator could not decode ${subject}`,{code:"LEVEL_DECODE_ERROR",cause:cause})}}for(const k of["_ended property","_nexting property","_end method"]){Object.defineProperty(AbstractIterator.prototype,k.split(" ")[0],{get(){throw new ModuleError(`The ${k} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new ModuleError(`The ${k} has been removed`,{code:"LEVEL_LEGACY"})}})}AbstractIterator.keyEncoding=kKeyEncoding;AbstractIterator.valueEncoding=kValueEncoding;exports.AbstractIterator=AbstractIterator;exports.AbstractKeyIterator=AbstractKeyIterator;exports.AbstractValueIterator=AbstractValueIterator},{"./lib/common":7,catering:20,"module-error":31}],3:[function(require,module,exports){"use strict";const{supports}=require("level-supports");const{Transcoder}=require("level-transcoder");const{EventEmitter}=require("events");const{fromCallback}=require("catering");const ModuleError=require("module-error");const{AbstractIterator}=require("./abstract-iterator");const{DefaultKeyIterator,DefaultValueIterator}=require("./lib/default-kv-iterator");const{DeferredIterator,DeferredKeyIterator,DeferredValueIterator}=require("./lib/deferred-iterator");const{DefaultChainedBatch}=require("./lib/default-chained-batch");const{getCallback,getOptions}=require("./lib/common");const rangeOptions=require("./lib/range-options");const kPromise=Symbol("promise");const kLanded=Symbol("landed");const kResources=Symbol("resources");const kCloseResources=Symbol("closeResources");const kOperations=Symbol("operations");const kUndefer=Symbol("undefer");const kDeferOpen=Symbol("deferOpen");const kOptions=Symbol("options");const kStatus=Symbol("status");const kDefaultOptions=Symbol("defaultOptions");const kTranscoder=Symbol("transcoder");const kKeyEncoding=Symbol("keyEncoding");const kValueEncoding=Symbol("valueEncoding");const noop=()=>{};class AbstractLevel extends EventEmitter{constructor(manifest,options){super();if(typeof manifest!=="object"||manifest===null){throw new TypeError("The first argument 'manifest' must be an object")}options=getOptions(options);const{keyEncoding,valueEncoding,passive,...forward}=options;this[kResources]=new Set;this[kOperations]=[];this[kDeferOpen]=true;this[kOptions]=forward;this[kStatus]="opening";this.supports=supports(manifest,{status:true,promises:true,clear:true,getMany:true,deferredOpen:true,snapshots:manifest.snapshots!==false,permanence:manifest.permanence!==false,keyIterator:true,valueIterator:true,iteratorNextv:true,iteratorAll:true,encodings:manifest.encodings||{},events:Object.assign({},manifest.events,{opening:true,open:true,closing:true,closed:true,put:true,del:true,batch:true,clear:true})});this[kTranscoder]=new Transcoder(formats(this));this[kKeyEncoding]=this[kTranscoder].encoding(keyEncoding||"utf8");this[kValueEncoding]=this[kTranscoder].encoding(valueEncoding||"utf8");for(const encoding of this[kTranscoder].encodings()){if(!this.supports.encodings[encoding.commonName]){this.supports.encodings[encoding.commonName]=true}}this[kDefaultOptions]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[kKeyEncoding].commonName,valueEncoding:this[kValueEncoding].commonName}),key:Object.freeze({keyEncoding:this[kKeyEncoding].commonName})};this.nextTick(()=>{if(this[kDeferOpen]){this.open({passive:false},noop)}})}get status(){return this[kStatus]}keyEncoding(encoding){return this[kTranscoder].encoding(encoding!=null?encoding:this[kKeyEncoding])}valueEncoding(encoding){return this[kTranscoder].encoding(encoding!=null?encoding:this[kValueEncoding])}open(options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options={...this[kOptions],...getOptions(options)};options.createIfMissing=options.createIfMissing!==false;options.errorIfExists=!!options.errorIfExists;const maybeOpened=err=>{if(this[kStatus]==="closing"||this[kStatus]==="opening"){this.once(kLanded,err?()=>maybeOpened(err):maybeOpened)}else if(this[kStatus]!=="open"){callback(new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:err}))}else{callback()}};if(options.passive){if(this[kStatus]==="opening"){this.once(kLanded,maybeOpened)}else{this.nextTick(maybeOpened)}}else if(this[kStatus]==="closed"||this[kDeferOpen]){this[kDeferOpen]=false;this[kStatus]="opening";this.emit("opening");this._open(options,err=>{if(err){this[kStatus]="closed";this[kCloseResources](()=>{this.emit(kLanded);maybeOpened(err)});this[kUndefer]();return}this[kStatus]="open";this[kUndefer]();this.emit(kLanded);if(this[kStatus]==="open")this.emit("open");if(this[kStatus]==="open")this.emit("ready");maybeOpened()})}else if(this[kStatus]==="open"){this.nextTick(maybeOpened)}else{this.once(kLanded,()=>this.open(options,callback))}return callback[kPromise]}_open(options,callback){this.nextTick(callback)}close(callback){callback=fromCallback(callback,kPromise);const maybeClosed=err=>{if(this[kStatus]==="opening"||this[kStatus]==="closing"){this.once(kLanded,err?maybeClosed(err):maybeClosed)}else if(this[kStatus]!=="closed"){callback(new ModuleError("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:err}))}else{callback()}};if(this[kStatus]==="open"){this[kStatus]="closing";this.emit("closing");const cancel=err=>{this[kStatus]="open";this[kUndefer]();this.emit(kLanded);maybeClosed(err)};this[kCloseResources](()=>{this._close(err=>{if(err)return cancel(err);this[kStatus]="closed";this[kUndefer]();this.emit(kLanded);if(this[kStatus]==="closed")this.emit("closed");maybeClosed()})})}else if(this[kStatus]==="closed"){this.nextTick(maybeClosed)}else{this.once(kLanded,()=>this.close(callback))}return callback[kPromise]}[kCloseResources](callback){if(this[kResources].size===0){return this.nextTick(callback)}let pending=this[kResources].size;let sync=true;const next=()=>{if(--pending===0){if(sync)this.nextTick(callback);else callback()}};for(const resource of this[kResources]){resource.close(next)}sync=false;this[kResources].clear()}_close(callback){this.nextTick(callback)}get(key,options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].entry);if(this[kStatus]==="opening"){this.defer(()=>this.get(key,options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}const err=this._checkKey(key);if(err){this.nextTick(callback,err);return callback[kPromise]}const keyEncoding=this.keyEncoding(options.keyEncoding);const valueEncoding=this.valueEncoding(options.valueEncoding);const keyFormat=keyEncoding.format;const valueFormat=valueEncoding.format;if(options.keyEncoding!==keyFormat||options.valueEncoding!==valueFormat){options=Object.assign({},options,{keyEncoding:keyFormat,valueEncoding:valueFormat})}this._get(this.prefixKey(keyEncoding.encode(key),keyFormat),options,(err,value)=>{if(err){if(err.code==="LEVEL_NOT_FOUND"||err.notFound||/NotFound/i.test(err)){if(!err.code)err.code="LEVEL_NOT_FOUND";if(!err.notFound)err.notFound=true;if(!err.status)err.status=404}return callback(err)}try{value=valueEncoding.decode(value)}catch(err){return callback(new ModuleError("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:err}))}callback(null,value)});return callback[kPromise]}_get(key,options,callback){this.nextTick(callback,new Error("NotFound"))}getMany(keys,options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].entry);if(this[kStatus]==="opening"){this.defer(()=>this.getMany(keys,options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}if(!Array.isArray(keys)){this.nextTick(callback,new TypeError("The first argument 'keys' must be an array"));return callback[kPromise]}if(keys.length===0){this.nextTick(callback,null,[]);return callback[kPromise]}const keyEncoding=this.keyEncoding(options.keyEncoding);const valueEncoding=this.valueEncoding(options.valueEncoding);const keyFormat=keyEncoding.format;const valueFormat=valueEncoding.format;if(options.keyEncoding!==keyFormat||options.valueEncoding!==valueFormat){options=Object.assign({},options,{keyEncoding:keyFormat,valueEncoding:valueFormat})}const mappedKeys=new Array(keys.length);for(let i=0;i<keys.length;i++){const key=keys[i];const err=this._checkKey(key);if(err){this.nextTick(callback,err);return callback[kPromise]}mappedKeys[i]=this.prefixKey(keyEncoding.encode(key),keyFormat)}this._getMany(mappedKeys,options,(err,values)=>{if(err)return callback(err);try{for(let i=0;i<values.length;i++){if(values[i]!==undefined){values[i]=valueEncoding.decode(values[i])}}}catch(err){return callback(new ModuleError(`Could not decode one or more of ${values.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:err}))}callback(null,values)});return callback[kPromise]}_getMany(keys,options,callback){this.nextTick(callback,null,new Array(keys.length).fill(undefined))}put(key,value,options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].entry);if(this[kStatus]==="opening"){this.defer(()=>this.put(key,value,options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}const err=this._checkKey(key)||this._checkValue(value);if(err){this.nextTick(callback,err);return callback[kPromise]}const keyEncoding=this.keyEncoding(options.keyEncoding);const valueEncoding=this.valueEncoding(options.valueEncoding);const keyFormat=keyEncoding.format;const valueFormat=valueEncoding.format;if(options.keyEncoding!==keyFormat||options.valueEncoding!==valueFormat){options=Object.assign({},options,{keyEncoding:keyFormat,valueEncoding:valueFormat})}const mappedKey=this.prefixKey(keyEncoding.encode(key),keyFormat);const mappedValue=valueEncoding.encode(value);this._put(mappedKey,mappedValue,options,err=>{if(err)return callback(err);this.emit("put",key,value);callback()});return callback[kPromise]}_put(key,value,options,callback){this.nextTick(callback)}del(key,options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].key);if(this[kStatus]==="opening"){this.defer(()=>this.del(key,options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}const err=this._checkKey(key);if(err){this.nextTick(callback,err);return callback[kPromise]}const keyEncoding=this.keyEncoding(options.keyEncoding);const keyFormat=keyEncoding.format;if(options.keyEncoding!==keyFormat){options=Object.assign({},options,{keyEncoding:keyFormat})}this._del(this.prefixKey(keyEncoding.encode(key),keyFormat),options,err=>{if(err)return callback(err);this.emit("del",key);callback()});return callback[kPromise]}_del(key,options,callback){this.nextTick(callback)}batch(operations,options,callback){if(!arguments.length){if(this[kStatus]==="opening")return new DefaultChainedBatch(this);if(this[kStatus]!=="open"){throw new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}return this._chainedBatch()}if(typeof operations==="function")callback=operations;else callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].empty);if(this[kStatus]==="opening"){this.defer(()=>this.batch(operations,options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}if(!Array.isArray(operations)){this.nextTick(callback,new TypeError("The first argument 'operations' must be an array"));return callback[kPromise]}if(operations.length===0){this.nextTick(callback);return callback[kPromise]}const mapped=new Array(operations.length);const{keyEncoding:ke,valueEncoding:ve,...forward}=options;for(let i=0;i<operations.length;i++){if(typeof operations[i]!=="object"||operations[i]===null){this.nextTick(callback,new TypeError("A batch operation must be an object"));return callback[kPromise]}const op=Object.assign({},operations[i]);if(op.type!=="put"&&op.type!=="del"){this.nextTick(callback,new TypeError("A batch operation must have a type property that is 'put' or 'del'"));return callback[kPromise]}const err=this._checkKey(op.key);if(err){this.nextTick(callback,err);return callback[kPromise]}const db=op.sublevel!=null?op.sublevel:this;const keyEncoding=db.keyEncoding(op.keyEncoding||ke);const keyFormat=keyEncoding.format;op.key=db.prefixKey(keyEncoding.encode(op.key),keyFormat);op.keyEncoding=keyFormat;if(op.type==="put"){const valueErr=this._checkValue(op.value);if(valueErr){this.nextTick(callback,valueErr);return callback[kPromise]}const valueEncoding=db.valueEncoding(op.valueEncoding||ve);op.value=valueEncoding.encode(op.value);op.valueEncoding=valueEncoding.format}if(db!==this){op.sublevel=null}mapped[i]=op}this._batch(mapped,forward,err=>{if(err)return callback(err);this.emit("batch",operations);callback()});return callback[kPromise]}_batch(operations,options,callback){this.nextTick(callback)}sublevel(name,options){return this._sublevel(name,AbstractSublevel.defaults(options))}_sublevel(name,options){return new AbstractSublevel(this,name,options)}prefixKey(key,keyFormat){return key}clear(options,callback){callback=getCallback(options,callback);callback=fromCallback(callback,kPromise);options=getOptions(options,this[kDefaultOptions].empty);if(this[kStatus]==="opening"){this.defer(()=>this.clear(options,callback));return callback[kPromise]}if(maybeError(this,callback)){return callback[kPromise]}const original=options;const keyEncoding=this.keyEncoding(options.keyEncoding);options=rangeOptions(options,keyEncoding);options.keyEncoding=keyEncoding.format;if(options.limit===0){this.nextTick(callback)}else{this._clear(options,err=>{if(err)return callback(err);this.emit("clear",original);callback()})}return callback[kPromise]}_clear(options,callback){this.nextTick(callback)}iterator(options){const keyEncoding=this.keyEncoding(options&&options.keyEncoding);const valueEncoding=this.valueEncoding(options&&options.valueEncoding);options=rangeOptions(options,keyEncoding);options.keys=options.keys!==false;options.values=options.values!==false;options[AbstractIterator.keyEncoding]=keyEncoding;options[AbstractIterator.valueEncoding]=valueEncoding;options.keyEncoding=keyEncoding.format;options.valueEncoding=valueEncoding.format;if(this[kStatus]==="opening"){return new DeferredIterator(this,options)}else if(this[kStatus]!=="open"){throw new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}return this._iterator(options)}_iterator(options){return new AbstractIterator(this,options)}keys(options){const keyEncoding=this.keyEncoding(options&&options.keyEncoding);const valueEncoding=this.valueEncoding(options&&options.valueEncoding);options=rangeOptions(options,keyEncoding);options[AbstractIterator.keyEncoding]=keyEncoding;options[AbstractIterator.valueEncoding]=valueEncoding;options.keyEncoding=keyEncoding.format;options.valueEncoding=valueEncoding.format;if(this[kStatus]==="opening"){return new DeferredKeyIterator(this,options)}else if(this[kStatus]!=="open"){throw new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}return this._keys(options)}_keys(options){return new DefaultKeyIterator(this,options)}values(options){const keyEncoding=this.keyEncoding(options&&options.keyEncoding);const valueEncoding=this.valueEncoding(options&&options.valueEncoding);options=rangeOptions(options,keyEncoding);options[AbstractIterator.keyEncoding]=keyEncoding;options[AbstractIterator.valueEncoding]=valueEncoding;options.keyEncoding=keyEncoding.format;options.valueEncoding=valueEncoding.format;if(this[kStatus]==="opening"){return new DeferredValueIterator(this,options)}else if(this[kStatus]!=="open"){throw new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}return this._values(options)}_values(options){return new DefaultValueIterator(this,options)}defer(fn){if(typeof fn!=="function"){throw new TypeError("The first argument must be a function")}this[kOperations].push(fn)}[kUndefer](){if(this[kOperations].length===0){return}const operations=this[kOperations];this[kOperations]=[];for(const op of operations){op()}}attachResource(resource){if(typeof resource!=="object"||resource===null||typeof resource.close!=="function"){throw new TypeError("The first argument must be a resource object")}this[kResources].add(resource)}detachResource(resource){this[kResources].delete(resource)}_chainedBatch(){return new DefaultChainedBatch(this)}_checkKey(key){if(key===null||key===undefined){return new ModuleError("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}}_checkValue(value){if(value===null||value===undefined){return new ModuleError("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}}}AbstractLevel.prototype.nextTick=require("./lib/next-tick");const{AbstractSublevel}=require("./lib/abstract-sublevel")({AbstractLevel:AbstractLevel});exports.AbstractLevel=AbstractLevel;exports.AbstractSublevel=AbstractSublevel;const maybeError=function(db,callback){if(db[kStatus]!=="open"){db.nextTick(callback,new ModuleError("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"}));return true}return false};const formats=function(db){return Object.keys(db.supports.encodings).filter(k=>!!db.supports.encodings[k])}},{"./abstract-iterator":2,"./lib/abstract-sublevel":6,"./lib/common":7,"./lib/default-chained-batch":8,"./lib/default-kv-iterator":9,"./lib/deferred-iterator":10,"./lib/next-tick":11,"./lib/range-options":12,catering:20,events:22,"level-supports":24,"level-transcoder":25,"module-error":31}],4:[function(require,module,exports){"use strict";exports.AbstractLevel=require("./abstract-level").AbstractLevel;exports.AbstractSublevel=require("./abstract-level").AbstractSublevel;exports.AbstractIterator=require("./abstract-iterator").AbstractIterator;exports.AbstractKeyIterator=require("./abstract-iterator").AbstractKeyIterator;exports.AbstractValueIterator=require("./abstract-iterator").AbstractValueIterator;exports.AbstractChainedBatch=require("./abstract-chained-batch").AbstractChainedBatch},{"./abstract-chained-batch":1,"./abstract-iterator":2,"./abstract-level":3}],5:[function(require,module,exports){"use strict";const{AbstractIterator,AbstractKeyIterator,AbstractValueIterator}=require("../abstract-iterator");const kUnfix=Symbol("unfix");const kIterator=Symbol("iterator");const kHandleOne=Symbol("handleOne");const kHandleMany=Symbol("handleMany");const kCallback=Symbol("callback");class AbstractSublevelIterator extends AbstractIterator{constructor(db,options,iterator,unfix){super(db,options);this[kIterator]=iterator;this[kUnfix]=unfix;this[kHandleOne]=this[kHandleOne].bind(this);this[kHandleMany]=this[kHandleMany].bind(this);this[kCallback]=null}[kHandleOne](err,key,value){const callback=this[kCallback];if(err)return callback(err);if(key!==undefined)key=this[kUnfix](key);callback(err,key,value)}[kHandleMany](err,entries){const callback=this[kCallback];if(err)return callback(err);for(const entry of entries){const key=entry[0];if(key!==undefined)entry[0]=this[kUnfix](key)}callback(err,entries)}}class AbstractSublevelKeyIterator extends AbstractKeyIterator{constructor(db,options,iterator,unfix){super(db,options);this[kIterator]=iterator;this[kUnfix]=unfix;this[kHandleOne]=this[kHandleOne].bind(this);this[kHandleMany]=this[kHandleMany].bind(this);this[kCallback]=null}[kHandleOne](err,key){const callback=this[kCallback];if(err)return callback(err);if(key!==undefined)key=this[kUnfix](key);callback(err,key)}[kHandleMany](err,keys){const callback=this[kCallback];if(err)return callback(err);for(let i=0;i<keys.length;i++){const key=keys[i];if(key!==undefined)keys[i]=this[kUnfix](key)}callback(err,keys)}}class AbstractSublevelValueIterator extends AbstractValueIterator{constructor(db,options,iterator){super(db,options);this[kIterator]=iterator}}for(const Iterator of[AbstractSublevelIterator,AbstractSublevelKeyIterator]){Iterator.prototype._next=function(callback){this[kCallback]=callback;this[kIterator].next(this[kHandleOne])};Iterator.prototype._nextv=function(size,options,callback){this[kCallback]=callback;this[kIterator].nextv(size,options,this[kHandleMany])};Iterator.prototype._all=function(options,callback){this[kCallback]=callback;this[kIterator].all(options,this[kHandleMany])}}for(const Iterator of[AbstractSublevelValueIterator]){Iterator.prototype._next=function(callback){this[kIterator].next(callback)};Iterator.prototype._nextv=function(size,options,callback){this[kIterator].nextv(size,options,callback)};Iterator.prototype._all=function(options,callback){this[kIterator].all(options,callback)}}for(const Iterator of[AbstractSublevelIterator,AbstractSublevelKeyIterator,AbstractSublevelValueIterator]){Iterator.prototype._seek=function(target,options){this[kIterator].seek(target,options)};Iterator.prototype._close=function(callback){this[kIterator].close(callback)}}exports.AbstractSublevelIterator=AbstractSublevelIterator;exports.AbstractSublevelKeyIterator=AbstractSublevelKeyIterator;exports.AbstractSublevelValueIterator=AbstractSublevelValueIterator},{"../abstract-iterator":2}],6:[function(require,module,exports){"use strict";const ModuleError=require("module-error");const{Buffer}=require("buffer")||{};const{AbstractSublevelIterator,AbstractSublevelKeyIterator,AbstractSublevelValueIterator}=require("./abstract-sublevel-iterator");const kPrefix=Symbol("prefix");const kUpperBound=Symbol("upperBound");const kPrefixRange=Symbol("prefixRange");const kParent=Symbol("parent");const kUnfix=Symbol("unfix");const textEncoder=new TextEncoder;const defaults={separator:"!"};module.exports=function({AbstractLevel}){class AbstractSublevel extends AbstractLevel{static defaults(options){if(typeof options==="string"){throw new ModuleError("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"})}else if(options&&options.open){throw new ModuleError("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"})}if(options==null){return defaults}else if(!options.separator){return{...options,separator:"!"}}else{return options}}constructor(db,name,options){const{separator,manifest,...forward}=AbstractSublevel.defaults(options);name=trim(name,separator);const reserved=separator.charCodeAt(0)+1;const parent=db[kParent]||db;if(!textEncoder.encode(name).every(x=>x>reserved&&x<127)){throw new ModuleError(`Prefix must use bytes > ${reserved} < ${127}`,{code:"LEVEL_INVALID_PREFIX"})}super(mergeManifests(parent,manifest),forward);const prefix=(db.prefix||"")+separator+name+separator;const upperBound=prefix.slice(0,-1)+String.fromCharCode(reserved);this[kParent]=parent;this[kPrefix]=new MultiFormat(prefix);this[kUpperBound]=new MultiFormat(upperBound);this[kUnfix]=new Unfixer;this.nextTick=parent.nextTick}prefixKey(key,keyFormat){if(keyFormat==="utf8"){return this[kPrefix].utf8+key}else if(key.byteLength===0){return this[kPrefix][keyFormat]}else if(keyFormat==="view"){const view=this[kPrefix].view;const result=new Uint8Array(view.byteLength+key.byteLength);result.set(view,0);result.set(key,view.byteLength);return result}else{const buffer=this[kPrefix].buffer;return Buffer.concat([buffer,key],buffer.byteLength+key.byteLength)}}[kPrefixRange](range,keyFormat){if(range.gte!==undefined){range.gte=this.prefixKey(range.gte,keyFormat)}else if(range.gt!==undefined){range.gt=this.prefixKey(range.gt,keyFormat)}else{range.gte=this[kPrefix][keyFormat]}if(range.lte!==undefined){range.lte=this.prefixKey(range.lte,keyFormat)}else if(range.lt!==undefined){range.lt=this.prefixKey(range.lt,keyFormat)}else{range.lte=this[kUpperBound][keyFormat]}}get prefix(){return this[kPrefix].utf8}get db(){return this[kParent]}_open(options,callback){this[kParent].open({passive:true},callback)}_put(key,value,options,callback){this[kParent].put(key,value,options,callback)}_get(key,options,callback){this[kParent].get(key,options,callback)}_getMany(keys,options,callback){this[kParent].getMany(keys,options,callback)}_del(key,options,callback){this[kParent].del(key,options,callback)}_batch(operations,options,callback){this[kParent].batch(operations,options,callback)}_clear(options,callback){this[kPrefixRange](options,options.keyEncoding);this[kParent].clear(options,callback)}_iterator(options){this[kPrefixRange](options,options.keyEncoding);const iterator=this[kParent].iterator(options);const unfix=this[kUnfix].get(this[kPrefix].utf8.length,options.keyEncoding);return new AbstractSublevelIterator(this,options,iterator,unfix)}_keys(options){this[kPrefixRange](options,options.keyEncoding);const iterator=this[kParent].keys(options);const unfix=this[kUnfix].get(this[kPrefix].utf8.length,options.keyEncoding);return new AbstractSublevelKeyIterator(this,options,iterator,unfix)}_values(options){this[kPrefixRange](options,options.keyEncoding);const iterator=this[kParent].values(options);return new AbstractSublevelValueIterator(this,options,iterator)}}return{AbstractSublevel:AbstractSublevel}};const mergeManifests=function(parent,manifest){return{...parent.supports,createIfMissing:false,errorIfExists:false,events:{},additionalMethods:{},...manifest,encodings:{utf8:supportsEncoding(parent,"utf8"),buffer:supportsEncoding(parent,"buffer"),view:supportsEncoding(parent,"view")}}};const supportsEncoding=function(parent,encoding){return parent.supports.encodings[encoding]?parent.keyEncoding(encoding).name===encoding:false};class MultiFormat{constructor(key){this.utf8=key;this.view=textEncoder.encode(key);this.buffer=Buffer?Buffer.from(this.view.buffer,0,this.view.byteLength):{}}}class Unfixer{constructor(){this.cache=new Map}get(prefixLength,keyFormat){let unfix=this.cache.get(keyFormat);if(unfix===undefined){if(keyFormat==="view"){unfix=function(prefixLength,key){return key.subarray(prefixLength)}.bind(null,prefixLength)}else{unfix=function(prefixLength,key){return key.slice(prefixLength)}.bind(null,prefixLength)}this.cache.set(keyFormat,unfix)}return unfix}}const trim=function(str,char){let start=0;let end=str.length;while(start<end&&str[start]===char)start++;while(end>start&&str[end-1]===char)end--;return str.slice(start,end)}},{"./abstract-sublevel-iterator":5,buffer:19,"module-error":31}],7:[function(require,module,exports){"use strict";exports.getCallback=function(options,callback){return typeof options==="function"?options:callback};exports.getOptions=function(options,def){if(typeof options==="object"&&options!==null){return options}if(def!==undefined){return def}return{}}},{}],8:[function(require,module,exports){"use strict";const{AbstractChainedBatch}=require("../abstract-chained-batch");const ModuleError=require("module-error");const kEncoded=Symbol("encoded");class DefaultChainedBatch extends AbstractChainedBatch{constructor(db){super(db);this[kEncoded]=[]}_put(key,value,options){this[kEncoded].push({...options,type:"put",key:key,value:value})}_del(key,options){this[kEncoded].push({...options,type:"del",key:key})}_clear(){this[kEncoded]=[]}_write(options,callback){if(this.db.status==="opening"){this.db.defer(()=>this._write(options,callback))}else if(this.db.status==="open"){if(this[kEncoded].length===0)this.nextTick(callback);else this.db._batch(this[kEncoded],options,callback)}else{this.nextTick(callback,new ModuleError("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}}}exports.DefaultChainedBatch=DefaultChainedBatch},{"../abstract-chained-batch":1,"module-error":31}],9:[function(require,module,exports){"use strict";const{AbstractKeyIterator,AbstractValueIterator}=require("../abstract-iterator");const kIterator=Symbol("iterator");const kCallback=Symbol("callback");const kHandleOne=Symbol("handleOne");const kHandleMany=Symbol("handleMany");class DefaultKeyIterator extends AbstractKeyIterator{constructor(db,options){super(db,options);this[kIterator]=db.iterator({...options,keys:true,values:false});this[kHandleOne]=this[kHandleOne].bind(this);this[kHandleMany]=this[kHandleMany].bind(this)}}class DefaultValueIterator extends AbstractValueIterator{constructor(db,options){super(db,options);this[kIterator]=db.iterator({...options,keys:false,values:true});this[kHandleOne]=this[kHandleOne].bind(this);this[kHandleMany]=this[kHandleMany].bind(this)}}for(const Iterator of[DefaultKeyIterator,DefaultValueIterator]){const keys=Iterator===DefaultKeyIterator;const mapEntry=keys?entry=>entry[0]:entry=>entry[1];Iterator.prototype._next=function(callback){this[kCallback]=callback;this[kIterator].next(this[kHandleOne])};Iterator.prototype[kHandleOne]=function(err,key,value){const callback=this[kCallback];if(err)callback(err);else callback(null,keys?key:value)};Iterator.prototype._nextv=function(size,options,callback){this[kCallback]=callback;this[kIterator].nextv(size,options,this[kHandleMany])};Iterator.prototype._all=function(options,callback){this[kCallback]=callback;this[kIterator].all(options,this[kHandleMany])};Iterator.prototype[kHandleMany]=function(err,entries){const callback=this[kCallback];if(err)callback(err);else callback(null,entries.map(mapEntry))};Iterator.prototype._seek=function(target,options){this[kIterator].seek(target,options)};Iterator.prototype._close=function(callback){this[kIterator].close(callback)}}exports.DefaultKeyIterator=DefaultKeyIterator;exports.DefaultValueIterator=DefaultValueIterator},{"../abstract-iterator":2}],10:[function(require,module,exports){"use strict";const{AbstractIterator,AbstractKeyIterator,AbstractValueIterator}=require("../abstract-iterator");const ModuleError=require("module-error");const kNut=Symbol("nut");const kUndefer=Symbol("undefer");const kFactory=Symbol("factory");class DeferredIterator extends AbstractIterator{constructor(db,options){super(db,options);this[kNut]=null;this[kFactory]=()=>db.iterator(options);this.db.defer(()=>this[kUndefer]())}}class DeferredKeyIterator extends AbstractKeyIterator{constructor(db,options){super(db,options);this[kNut]=null;this[kFactory]=()=>db.keys(options);this.db.defer(()=>this[kUndefer]())}}class DeferredValueIterator extends AbstractValueIterator{constructor(db,options){super(db,options);this[kNut]=null;this[kFactory]=()=>db.values(options);this.db.defer(()=>this[kUndefer]())}}for(const Iterator of[DeferredIterator,DeferredKeyIterator,DeferredValueIterator]){Iterator.prototype[kUndefer]=function(){if(this.db.status==="open"){this[kNut]=this[kFactory]()}};Iterator.prototype._next=function(callback){if(this[kNut]!==null){this[kNut].next(callback)}else if(this.db.status==="opening"){this.db.defer(()=>this._next(callback))}else{this.nextTick(callback,new ModuleError("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}};Iterator.prototype._nextv=function(size,options,callback){if(this[kNut]!==null){this[kNut].nextv(size,options,callback)}else if(this.db.status==="opening"){this.db.defer(()=>this._nextv(size,options,callback))}else{this.nextTick(callback,new ModuleError("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}};Iterator.prototype._all=function(options,callback){if(this[kNut]!==null){this[kNut].all(callback)}else if(this.db.status==="opening"){this.db.defer(()=>this._all(options,callback))}else{this.nextTick(callback,new ModuleError("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))}};Iterator.prototype._seek=function(target,options){if(this[kNut]!==null){this[kNut]._seek(target,options)}else if(this.db.status==="opening"){this.db.defer(()=>this._seek(target,options))}};Iterator.prototype._close=function(callback){if(this[kNut]!==null){this[kNut].close(callback)}else if(this.db.status==="opening"){this.db.defer(()=>this._close(callback))}else{this.nextTick(callback)}}}exports.DeferredIterator=DeferredIterator;exports.DeferredKeyIterator=DeferredKeyIterator;exports.DeferredValueIterator=DeferredValueIterator},{"../abstract-iterator":2,"module-error":31}],11:[function(require,module,exports){"use strict";const queueMicrotask=require("queue-microtask");module.exports=function(fn,...args){if(args.length===0){queueMicrotask(fn)}else{queueMicrotask(()=>fn(...args))}}},{"queue-microtask":32}],12:[function(require,module,exports){"use strict";const ModuleError=require("module-error");const hasOwnProperty=Object.prototype.hasOwnProperty;const rangeOptions=new Set(["lt","lte","gt","gte"]);module.exports=function(options,keyEncoding){const result={};for(const k in options){if(!hasOwnProperty.call(options,k))continue;if(k==="keyEncoding"||k==="valueEncoding")continue;if(k==="start"||k==="end"){throw new ModuleError(`The legacy range option '${k}' has been removed`,{code:"LEVEL_LEGACY"})}else if(k==="encoding"){throw new ModuleError("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"})}if(rangeOptions.has(k)){result[k]=keyEncoding.encode(options[k])}else{result[k]=options[k]}}result.reverse=!!result.reverse;result.limit=Number.isInteger(result.limit)&&result.limit>=0?result.limit:-1;return result}},{"module-error":31}],13:[function(require,module,exports){"use strict";exports.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;var code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,len=code.length;i<len;++i){lookup[i]=code[i];revLookup[code.charCodeAt(i)]=i}revLookup["-".charCodeAt(0)]=62;revLookup["_".charCodeAt(0)]=63;function getLens(b64){var len=b64.length;if(len%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;var i;for(i=0;i<len;i+=4){tmp=revLookup[b64.charCodeAt(i)]<<18|revLookup[b64.charCodeAt(i+1)]<<12|revLookup[b64.charCodeAt(i+2)]<<6|revLookup[b64.charCodeAt(i+3)];arr[curByte++]=tmp>>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;i<end;i+=3){tmp=(uint8[i]<<16&16711680)+(uint8[i+1]<<8&65280)+(uint8[i+2]&255);output.push(tripletToBase64(tmp))}return output.join("")}function fromByteArray(uint8){var tmp;var len=uint8.length;var extraBytes=len%3;var parts=[];var maxChunkLength=16383;for(var i=0,len2=len-extraBytes;i<len2;i+=maxChunkLength){parts.push(encodeChunk(uint8,i,i+maxChunkLength>len2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],14:[function(require,module,exports){"use strict";const{AbstractLevel}=require("abstract-level");const ModuleError=require("module-error");