@leofcoin/peernet 0.14.10 → 0.14.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -788,8 +788,8 @@ class Peernet {
788
788
  if (!options.storePrefix) options.storePrefix = 'lfc';
789
789
  if (!options.port) options.port = 2000;
790
790
  if (!options.root) {
791
- if (parts[1]) options.root = `.${parts[0]}/peernet/${parts[1]}`;
792
- else options.root = `.${this.network}/peernet`;
791
+ if (parts[1]) options.root = `.${parts[0]}/${parts[1]}`;
792
+ else options.root = `.${this.network}`;
793
793
  }
794
794
  globalThis.peernet = this;
795
795
  this.bw = {
@@ -817,7 +817,7 @@ class Peernet {
817
817
 
818
818
  async addStore(name, prefix, root, isPrivate = true) {
819
819
  if (!globalThis.LeofcoinStorage) {
820
- const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(__webpack_require__(/* webpackChunkName: "storage" */ 3613)); });
820
+ const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(__webpack_require__(/* webpackChunkName: "storage" */ 4110)); });
821
821
  globalThis.LeofcoinStorage = importee.default;
822
822
  }
823
823
  if (name === 'block' || name === 'transaction' || name === 'chain' ||
@@ -2797,7 +2797,7 @@ class Client {
2797
2797
 
2798
2798
  /***/ }),
2799
2799
 
2800
- /***/ 3613:
2800
+ /***/ 4110:
2801
2801
  /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2802
2802
 
2803
2803
  "use strict";
@@ -2805,6 +2805,31 @@ __webpack_require__.r(__webpack_exports__);
2805
2805
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2806
2806
  /* harmony export */ "default": function() { return /* binding */ LeofcoinStorage; }
2807
2807
  /* harmony export */ });
2808
+ /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6470);
2809
+ /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
2810
+ /* harmony import */ var buffer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8764);
2811
+ /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7187);
2812
+ /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_2__);
2813
+ /* provided dependency */ var process = __webpack_require__(4406);
2814
+
2815
+
2816
+
2817
+
2818
+ function _mergeNamespaces(n, m) {
2819
+ m.forEach(function (e) {
2820
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
2821
+ if (k !== 'default' && !(k in n)) {
2822
+ var d = Object.getOwnPropertyDescriptor(e, k);
2823
+ Object.defineProperty(n, k, d.get ? d : {
2824
+ enumerable: true,
2825
+ get: function () { return e[k]; }
2826
+ });
2827
+ }
2828
+ });
2829
+ });
2830
+ return Object.freeze(n);
2831
+ }
2832
+
2808
2833
  // import base32 from '@vandeurenglenn/base32'
2809
2834
  // import base58 from '@vandeurenglenn/base58'
2810
2835
 
@@ -2909,312 +2934,3517 @@ class KeyValue {
2909
2934
 
2910
2935
  }
2911
2936
 
2912
- const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
2913
-
2914
- let idbProxyableTypes;
2915
- let cursorAdvanceMethods;
2916
- // This is a function to prevent it throwing up in node environments.
2917
- function getIdbProxyableTypes() {
2918
- return (idbProxyableTypes ||
2919
- (idbProxyableTypes = [
2920
- IDBDatabase,
2921
- IDBObjectStore,
2922
- IDBIndex,
2923
- IDBCursor,
2924
- IDBTransaction,
2925
- ]));
2926
- }
2927
- // This is a function to prevent it throwing up in node environments.
2928
- function getCursorAdvanceMethods() {
2929
- return (cursorAdvanceMethods ||
2930
- (cursorAdvanceMethods = [
2931
- IDBCursor.prototype.advance,
2932
- IDBCursor.prototype.continue,
2933
- IDBCursor.prototype.continuePrimaryKey,
2934
- ]));
2935
- }
2936
- const cursorRequestMap = new WeakMap();
2937
- const transactionDoneMap = new WeakMap();
2938
- const transactionStoreNamesMap = new WeakMap();
2939
- const transformCache = new WeakMap();
2940
- const reverseTransformCache = new WeakMap();
2941
- function promisifyRequest(request) {
2942
- const promise = new Promise((resolve, reject) => {
2943
- const unlisten = () => {
2944
- request.removeEventListener('success', success);
2945
- request.removeEventListener('error', error);
2946
- };
2947
- const success = () => {
2948
- resolve(wrap(request.result));
2949
- unlisten();
2950
- };
2951
- const error = () => {
2952
- reject(request.error);
2953
- unlisten();
2954
- };
2955
- request.addEventListener('success', success);
2956
- request.addEventListener('error', error);
2957
- });
2958
- promise
2959
- .then((value) => {
2960
- // Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
2961
- // (see wrapFunction).
2962
- if (value instanceof IDBCursor) {
2963
- cursorRequestMap.set(value, request);
2964
- }
2965
- // Catching to avoid "Uncaught Promise exceptions"
2937
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof __webpack_require__.g !== 'undefined' ? __webpack_require__.g : typeof self !== 'undefined' ? self : {};
2938
+
2939
+ var browserLevel = {};
2940
+
2941
+ var abstractLevel$1 = {};
2942
+
2943
+ var abstractLevel = {};
2944
+
2945
+ var levelSupports = {};
2946
+
2947
+ levelSupports.supports = function supports (...manifests) {
2948
+ const manifest = manifests.reduce((acc, m) => Object.assign(acc, m), {});
2949
+
2950
+ return Object.assign(manifest, {
2951
+ snapshots: manifest.snapshots || false,
2952
+ permanence: manifest.permanence || false,
2953
+ seek: manifest.seek || false,
2954
+ clear: manifest.clear || false,
2955
+ getMany: manifest.getMany || false,
2956
+ keyIterator: manifest.keyIterator || false,
2957
+ valueIterator: manifest.valueIterator || false,
2958
+ iteratorNextv: manifest.iteratorNextv || false,
2959
+ iteratorAll: manifest.iteratorAll || false,
2960
+ status: manifest.status || false,
2961
+ createIfMissing: manifest.createIfMissing || false,
2962
+ errorIfExists: manifest.errorIfExists || false,
2963
+ deferredOpen: manifest.deferredOpen || false,
2964
+ promises: manifest.promises || false,
2965
+ streams: manifest.streams || false,
2966
+ encodings: Object.assign({}, manifest.encodings),
2967
+ events: Object.assign({}, manifest.events),
2968
+ additionalMethods: Object.assign({}, manifest.additionalMethods)
2969
+ })
2970
+ };
2971
+
2972
+ var levelTranscoder = {};
2973
+
2974
+ var moduleError = class ModuleError extends Error {
2975
+ /**
2976
+ * @param {string} message Error message
2977
+ * @param {{ code?: string, cause?: Error, expected?: boolean, transient?: boolean }} [options]
2978
+ */
2979
+ constructor (message, options) {
2980
+ super(message || '');
2981
+
2982
+ if (typeof options === 'object' && options !== null) {
2983
+ if (options.code) this.code = String(options.code);
2984
+ if (options.expected) this.expected = true;
2985
+ if (options.transient) this.transient = true;
2986
+ if (options.cause) this.cause = options.cause;
2987
+ }
2988
+
2989
+ if (Error.captureStackTrace) {
2990
+ Error.captureStackTrace(this, this.constructor);
2991
+ }
2992
+ }
2993
+ };
2994
+
2995
+ var encodings$1 = {};
2996
+
2997
+ /** @type {{ textEncoder: TextEncoder, textDecoder: TextDecoder }|null} */
2998
+ let lazy = null;
2999
+
3000
+ /**
3001
+ * Get semi-global instances of TextEncoder and TextDecoder.
3002
+ * @returns {{ textEncoder: TextEncoder, textDecoder: TextDecoder }}
3003
+ */
3004
+ var textEndec$1 = function () {
3005
+ if (lazy === null) {
3006
+ lazy = {
3007
+ textEncoder: new TextEncoder(),
3008
+ textDecoder: new TextDecoder()
3009
+ };
3010
+ }
3011
+
3012
+ return lazy
3013
+ };
3014
+
3015
+ var formats$2 = {};
3016
+
3017
+ var encoding = {};
3018
+
3019
+ const ModuleError$8 = moduleError;
3020
+ const formats$1 = new Set(['buffer', 'view', 'utf8']);
3021
+
3022
+ /**
3023
+ * @template TIn, TFormat, TOut
3024
+ * @abstract
3025
+ */
3026
+ class Encoding$2 {
3027
+ /**
3028
+ * @param {IEncoding<TIn,TFormat,TOut>} options
3029
+ */
3030
+ constructor (options) {
3031
+ /** @type {(data: TIn) => TFormat} */
3032
+ this.encode = options.encode || this.encode;
3033
+
3034
+ /** @type {(data: TFormat) => TOut} */
3035
+ this.decode = options.decode || this.decode;
3036
+
3037
+ /** @type {string} */
3038
+ this.name = options.name || this.name;
3039
+
3040
+ /** @type {string} */
3041
+ this.format = options.format || this.format;
3042
+
3043
+ if (typeof this.encode !== 'function') {
3044
+ throw new TypeError("The 'encode' property must be a function")
3045
+ }
3046
+
3047
+ if (typeof this.decode !== 'function') {
3048
+ throw new TypeError("The 'decode' property must be a function")
3049
+ }
3050
+
3051
+ this.encode = this.encode.bind(this);
3052
+ this.decode = this.decode.bind(this);
3053
+
3054
+ if (typeof this.name !== 'string' || this.name === '') {
3055
+ throw new TypeError("The 'name' property must be a string")
3056
+ }
3057
+
3058
+ if (typeof this.format !== 'string' || !formats$1.has(this.format)) {
3059
+ throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'")
3060
+ }
3061
+
3062
+ if (options.createViewTranscoder) {
3063
+ this.createViewTranscoder = options.createViewTranscoder;
3064
+ }
3065
+
3066
+ if (options.createBufferTranscoder) {
3067
+ this.createBufferTranscoder = options.createBufferTranscoder;
3068
+ }
3069
+
3070
+ if (options.createUTF8Transcoder) {
3071
+ this.createUTF8Transcoder = options.createUTF8Transcoder;
3072
+ }
3073
+ }
3074
+
3075
+ get commonName () {
3076
+ return /** @type {string} */ (this.name.split('+')[0])
3077
+ }
3078
+
3079
+ /** @return {BufferFormat<TIn,TOut>} */
3080
+ createBufferTranscoder () {
3081
+ throw new ModuleError$8(`Encoding '${this.name}' cannot be transcoded to 'buffer'`, {
3082
+ code: 'LEVEL_ENCODING_NOT_SUPPORTED'
2966
3083
  })
2967
- .catch(() => { });
2968
- // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
2969
- // is because we create many promises from a single IDBRequest.
2970
- reverseTransformCache.set(promise, request);
2971
- return promise;
3084
+ }
3085
+
3086
+ /** @return {ViewFormat<TIn,TOut>} */
3087
+ createViewTranscoder () {
3088
+ throw new ModuleError$8(`Encoding '${this.name}' cannot be transcoded to 'view'`, {
3089
+ code: 'LEVEL_ENCODING_NOT_SUPPORTED'
3090
+ })
3091
+ }
3092
+
3093
+ /** @return {UTF8Format<TIn,TOut>} */
3094
+ createUTF8Transcoder () {
3095
+ throw new ModuleError$8(`Encoding '${this.name}' cannot be transcoded to 'utf8'`, {
3096
+ code: 'LEVEL_ENCODING_NOT_SUPPORTED'
3097
+ })
3098
+ }
2972
3099
  }
2973
- function cacheDonePromiseForTransaction(tx) {
2974
- // Early bail if we've already created a done promise for this transaction.
2975
- if (transactionDoneMap.has(tx))
2976
- return;
2977
- const done = new Promise((resolve, reject) => {
2978
- const unlisten = () => {
2979
- tx.removeEventListener('complete', complete);
2980
- tx.removeEventListener('error', error);
2981
- tx.removeEventListener('abort', error);
2982
- };
2983
- const complete = () => {
2984
- resolve();
2985
- unlisten();
2986
- };
2987
- const error = () => {
2988
- reject(tx.error || new DOMException('AbortError', 'AbortError'));
2989
- unlisten();
3100
+
3101
+ encoding.Encoding = Encoding$2;
3102
+
3103
+ const { Buffer: Buffer$1 } = buffer__WEBPACK_IMPORTED_MODULE_1__ || {};
3104
+ const { Encoding: Encoding$1 } = encoding;
3105
+ const textEndec = textEndec$1;
3106
+
3107
+ /**
3108
+ * @template TIn, TOut
3109
+ * @extends {Encoding<TIn,Buffer,TOut>}
3110
+ */
3111
+ class BufferFormat$2 extends Encoding$1 {
3112
+ /**
3113
+ * @param {Omit<IEncoding<TIn, Buffer, TOut>, 'format'>} options
3114
+ */
3115
+ constructor (options) {
3116
+ super({ ...options, format: 'buffer' });
3117
+ }
3118
+
3119
+ /** @override */
3120
+ createViewTranscoder () {
3121
+ return new ViewFormat$2({
3122
+ encode: this.encode, // Buffer is a view (UInt8Array)
3123
+ decode: (data) => this.decode(
3124
+ Buffer$1.from(data.buffer, data.byteOffset, data.byteLength)
3125
+ ),
3126
+ name: `${this.name}+view`
3127
+ })
3128
+ }
3129
+
3130
+ /** @override */
3131
+ createBufferTranscoder () {
3132
+ return this
3133
+ }
3134
+ }
3135
+
3136
+ /**
3137
+ * @extends {Encoding<TIn,Uint8Array,TOut>}
3138
+ * @template TIn, TOut
3139
+ */
3140
+ class ViewFormat$2 extends Encoding$1 {
3141
+ /**
3142
+ * @param {Omit<IEncoding<TIn, Uint8Array, TOut>, 'format'>} options
3143
+ */
3144
+ constructor (options) {
3145
+ super({ ...options, format: 'view' });
3146
+ }
3147
+
3148
+ /** @override */
3149
+ createBufferTranscoder () {
3150
+ return new BufferFormat$2({
3151
+ encode: (data) => {
3152
+ const view = this.encode(data);
3153
+ return Buffer$1.from(view.buffer, view.byteOffset, view.byteLength)
3154
+ },
3155
+ decode: this.decode, // Buffer is a view (UInt8Array)
3156
+ name: `${this.name}+buffer`
3157
+ })
3158
+ }
3159
+
3160
+ /** @override */
3161
+ createViewTranscoder () {
3162
+ return this
3163
+ }
3164
+ }
3165
+
3166
+ /**
3167
+ * @extends {Encoding<TIn,string,TOut>}
3168
+ * @template TIn, TOut
3169
+ */
3170
+ class UTF8Format$2 extends Encoding$1 {
3171
+ /**
3172
+ * @param {Omit<IEncoding<TIn, string, TOut>, 'format'>} options
3173
+ */
3174
+ constructor (options) {
3175
+ super({ ...options, format: 'utf8' });
3176
+ }
3177
+
3178
+ /** @override */
3179
+ createBufferTranscoder () {
3180
+ return new BufferFormat$2({
3181
+ encode: (data) => Buffer$1.from(this.encode(data), 'utf8'),
3182
+ decode: (data) => this.decode(data.toString('utf8')),
3183
+ name: `${this.name}+buffer`
3184
+ })
3185
+ }
3186
+
3187
+ /** @override */
3188
+ createViewTranscoder () {
3189
+ const { textEncoder, textDecoder } = textEndec();
3190
+
3191
+ return new ViewFormat$2({
3192
+ encode: (data) => textEncoder.encode(this.encode(data)),
3193
+ decode: (data) => this.decode(textDecoder.decode(data)),
3194
+ name: `${this.name}+view`
3195
+ })
3196
+ }
3197
+
3198
+ /** @override */
3199
+ createUTF8Transcoder () {
3200
+ return this
3201
+ }
3202
+ }
3203
+
3204
+ formats$2.BufferFormat = BufferFormat$2;
3205
+ formats$2.ViewFormat = ViewFormat$2;
3206
+ formats$2.UTF8Format = UTF8Format$2;
3207
+
3208
+ const { Buffer } = buffer__WEBPACK_IMPORTED_MODULE_1__ || { Buffer: { isBuffer: () => false } };
3209
+ const { textEncoder: textEncoder$1, textDecoder } = textEndec$1();
3210
+ const { BufferFormat: BufferFormat$1, ViewFormat: ViewFormat$1, UTF8Format: UTF8Format$1 } = formats$2;
3211
+
3212
+ /** @type {<T>(v: T) => v} */
3213
+ const identity = (v) => v;
3214
+
3215
+ /**
3216
+ * @type {typeof import('./encodings').utf8}
3217
+ */
3218
+ encodings$1.utf8 = new UTF8Format$1({
3219
+ encode: function (data) {
3220
+ // On node 16.9.1 buffer.toString() is 5x faster than TextDecoder
3221
+ return Buffer.isBuffer(data)
3222
+ ? data.toString('utf8')
3223
+ : ArrayBuffer.isView(data)
3224
+ ? textDecoder.decode(data)
3225
+ : String(data)
3226
+ },
3227
+ decode: identity,
3228
+ name: 'utf8',
3229
+ createViewTranscoder () {
3230
+ return new ViewFormat$1({
3231
+ encode: function (data) {
3232
+ return ArrayBuffer.isView(data) ? data : textEncoder$1.encode(data)
3233
+ },
3234
+ decode: function (data) {
3235
+ return textDecoder.decode(data)
3236
+ },
3237
+ name: `${this.name}+view`
3238
+ })
3239
+ },
3240
+ createBufferTranscoder () {
3241
+ return new BufferFormat$1({
3242
+ encode: function (data) {
3243
+ return Buffer.isBuffer(data)
3244
+ ? data
3245
+ : ArrayBuffer.isView(data)
3246
+ ? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
3247
+ : Buffer.from(String(data), 'utf8')
3248
+ },
3249
+ decode: function (data) {
3250
+ return data.toString('utf8')
3251
+ },
3252
+ name: `${this.name}+buffer`
3253
+ })
3254
+ }
3255
+ });
3256
+
3257
+ /**
3258
+ * @type {typeof import('./encodings').json}
3259
+ */
3260
+ encodings$1.json = new UTF8Format$1({
3261
+ encode: JSON.stringify,
3262
+ decode: JSON.parse,
3263
+ name: 'json'
3264
+ });
3265
+
3266
+ /**
3267
+ * @type {typeof import('./encodings').buffer}
3268
+ */
3269
+ encodings$1.buffer = new BufferFormat$1({
3270
+ encode: function (data) {
3271
+ return Buffer.isBuffer(data)
3272
+ ? data
3273
+ : ArrayBuffer.isView(data)
3274
+ ? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
3275
+ : Buffer.from(String(data), 'utf8')
3276
+ },
3277
+ decode: identity,
3278
+ name: 'buffer',
3279
+ createViewTranscoder () {
3280
+ return new ViewFormat$1({
3281
+ encode: function (data) {
3282
+ return ArrayBuffer.isView(data) ? data : Buffer.from(String(data), 'utf8')
3283
+ },
3284
+ decode: function (data) {
3285
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength)
3286
+ },
3287
+ name: `${this.name}+view`
3288
+ })
3289
+ }
3290
+ });
3291
+
3292
+ /**
3293
+ * @type {typeof import('./encodings').view}
3294
+ */
3295
+ encodings$1.view = new ViewFormat$1({
3296
+ encode: function (data) {
3297
+ return ArrayBuffer.isView(data) ? data : textEncoder$1.encode(data)
3298
+ },
3299
+ decode: identity,
3300
+ name: 'view',
3301
+ createBufferTranscoder () {
3302
+ return new BufferFormat$1({
3303
+ encode: function (data) {
3304
+ return Buffer.isBuffer(data)
3305
+ ? data
3306
+ : ArrayBuffer.isView(data)
3307
+ ? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
3308
+ : Buffer.from(String(data), 'utf8')
3309
+ },
3310
+ decode: identity,
3311
+ name: `${this.name}+buffer`
3312
+ })
3313
+ }
3314
+ });
3315
+
3316
+ /**
3317
+ * @type {typeof import('./encodings').hex}
3318
+ */
3319
+ encodings$1.hex = new BufferFormat$1({
3320
+ encode: function (data) {
3321
+ return Buffer.isBuffer(data) ? data : Buffer.from(String(data), 'hex')
3322
+ },
3323
+ decode: function (buffer) {
3324
+ return buffer.toString('hex')
3325
+ },
3326
+ name: 'hex'
3327
+ });
3328
+
3329
+ /**
3330
+ * @type {typeof import('./encodings').base64}
3331
+ */
3332
+ encodings$1.base64 = new BufferFormat$1({
3333
+ encode: function (data) {
3334
+ return Buffer.isBuffer(data) ? data : Buffer.from(String(data), 'base64')
3335
+ },
3336
+ decode: function (buffer) {
3337
+ return buffer.toString('base64')
3338
+ },
3339
+ name: 'base64'
3340
+ });
3341
+
3342
+ const ModuleError$7 = moduleError;
3343
+ const encodings = encodings$1;
3344
+ const { Encoding } = encoding;
3345
+ const { BufferFormat, ViewFormat, UTF8Format } = formats$2;
3346
+
3347
+ const kFormats = Symbol('formats');
3348
+ const kEncodings = Symbol('encodings');
3349
+ const validFormats = new Set(['buffer', 'view', 'utf8']);
3350
+
3351
+ /** @template T */
3352
+ class Transcoder$1 {
3353
+ /**
3354
+ * @param {Array<'buffer'|'view'|'utf8'>} formats
3355
+ */
3356
+ constructor (formats) {
3357
+ if (!Array.isArray(formats)) {
3358
+ throw new TypeError("The first argument 'formats' must be an array")
3359
+ } else if (!formats.every(f => validFormats.has(f))) {
3360
+ // Note: we only only support aliases in key- and valueEncoding options (where we already did)
3361
+ throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")
3362
+ }
3363
+
3364
+ /** @type {Map<string|MixedEncoding<any, any, any>, Encoding<any, any, any>>} */
3365
+ this[kEncodings] = new Map();
3366
+ this[kFormats] = new Set(formats);
3367
+
3368
+ // Register encodings (done early in order to populate encodings())
3369
+ for (const k in encodings) {
3370
+ try {
3371
+ this.encoding(k);
3372
+ } catch (err) {
3373
+ /* istanbul ignore if: assertion */
3374
+ if (err.code !== 'LEVEL_ENCODING_NOT_SUPPORTED') throw err
3375
+ }
3376
+ }
3377
+ }
3378
+
3379
+ /**
3380
+ * @returns {Array<Encoding<any,T,any>>}
3381
+ */
3382
+ encodings () {
3383
+ return Array.from(new Set(this[kEncodings].values()))
3384
+ }
3385
+
3386
+ /**
3387
+ * @param {string|MixedEncoding<any, any, any>} encoding
3388
+ * @returns {Encoding<any, T, any>}
3389
+ */
3390
+ encoding (encoding) {
3391
+ let resolved = this[kEncodings].get(encoding);
3392
+
3393
+ if (resolved === undefined) {
3394
+ if (typeof encoding === 'string' && encoding !== '') {
3395
+ resolved = lookup[encoding];
3396
+
3397
+ if (!resolved) {
3398
+ throw new ModuleError$7(`Encoding '${encoding}' is not found`, {
3399
+ code: 'LEVEL_ENCODING_NOT_FOUND'
3400
+ })
3401
+ }
3402
+ } else if (typeof encoding !== 'object' || encoding === null) {
3403
+ throw new TypeError("First argument 'encoding' must be a string or object")
3404
+ } else {
3405
+ resolved = from(encoding);
3406
+ }
3407
+
3408
+ const { name, format } = resolved;
3409
+
3410
+ if (!this[kFormats].has(format)) {
3411
+ if (this[kFormats].has('view')) {
3412
+ resolved = resolved.createViewTranscoder();
3413
+ } else if (this[kFormats].has('buffer')) {
3414
+ resolved = resolved.createBufferTranscoder();
3415
+ } else if (this[kFormats].has('utf8')) {
3416
+ resolved = resolved.createUTF8Transcoder();
3417
+ } else {
3418
+ throw new ModuleError$7(`Encoding '${name}' cannot be transcoded`, {
3419
+ code: 'LEVEL_ENCODING_NOT_SUPPORTED'
3420
+ })
3421
+ }
3422
+ }
3423
+
3424
+ for (const k of [encoding, name, resolved.name, resolved.commonName]) {
3425
+ this[kEncodings].set(k, resolved);
3426
+ }
3427
+ }
3428
+
3429
+ return resolved
3430
+ }
3431
+ }
3432
+
3433
+ levelTranscoder.Transcoder = Transcoder$1;
3434
+
3435
+ /**
3436
+ * @param {MixedEncoding<any, any, any>} options
3437
+ * @returns {Encoding<any, any, any>}
3438
+ */
3439
+ function from (options) {
3440
+ if (options instanceof Encoding) {
3441
+ return options
3442
+ }
3443
+
3444
+ // Loosely typed for ecosystem compatibility
3445
+ const maybeType = 'type' in options && typeof options.type === 'string' ? options.type : undefined;
3446
+ const name = options.name || maybeType || `anonymous-${anonymousCount++}`;
3447
+
3448
+ switch (detectFormat(options)) {
3449
+ case 'view': return new ViewFormat({ ...options, name })
3450
+ case 'utf8': return new UTF8Format({ ...options, name })
3451
+ case 'buffer': return new BufferFormat({ ...options, name })
3452
+ default: {
3453
+ throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")
3454
+ }
3455
+ }
3456
+ }
3457
+
3458
+ /**
3459
+ * If format is not provided, fallback to detecting `level-codec`
3460
+ * or `multiformats` encodings, else assume a format of buffer.
3461
+ * @param {MixedEncoding<any, any, any>} options
3462
+ * @returns {string}
3463
+ */
3464
+ function detectFormat (options) {
3465
+ if ('format' in options && options.format !== undefined) {
3466
+ return options.format
3467
+ } else if ('buffer' in options && typeof options.buffer === 'boolean') {
3468
+ return options.buffer ? 'buffer' : 'utf8' // level-codec
3469
+ } else if ('code' in options && Number.isInteger(options.code)) {
3470
+ return 'view' // multiformats
3471
+ } else {
3472
+ return 'buffer'
3473
+ }
3474
+ }
3475
+
3476
+ /**
3477
+ * @typedef {import('./lib/encoding').MixedEncoding<TIn,TFormat,TOut>} MixedEncoding
3478
+ * @template TIn, TFormat, TOut
3479
+ */
3480
+
3481
+ /**
3482
+ * @type {Object.<string, Encoding<any, any, any>>}
3483
+ */
3484
+ const aliases = {
3485
+ binary: encodings.buffer,
3486
+ 'utf-8': encodings.utf8
3487
+ };
3488
+
3489
+ /**
3490
+ * @type {Object.<string, Encoding<any, any, any>>}
3491
+ */
3492
+ const lookup = {
3493
+ ...encodings,
3494
+ ...aliases
3495
+ };
3496
+
3497
+ let anonymousCount = 0;
3498
+
3499
+ var catering = {};
3500
+
3501
+ var nextTick$2 = process.nextTick.bind(process);
3502
+
3503
+ var nextTick$1 = nextTick$2;
3504
+
3505
+ catering.fromCallback = function (callback, symbol) {
3506
+ if (callback === undefined) {
3507
+ var promise = new Promise(function (resolve, reject) {
3508
+ callback = function (err, res) {
3509
+ if (err) reject(err);
3510
+ else resolve(res);
3511
+ };
3512
+ });
3513
+
3514
+ callback[symbol !== undefined ? symbol : 'promise'] = promise;
3515
+ } else if (typeof callback !== 'function') {
3516
+ throw new TypeError('Callback must be a function')
3517
+ }
3518
+
3519
+ return callback
3520
+ };
3521
+
3522
+ catering.fromPromise = function (promise, callback) {
3523
+ if (callback === undefined) return promise
3524
+
3525
+ promise
3526
+ .then(function (res) { nextTick$1(() => callback(null, res)); })
3527
+ .catch(function (err) { nextTick$1(() => callback(err)); });
3528
+ };
3529
+
3530
+ var abstractIterator = {};
3531
+
3532
+ var common = {};
3533
+
3534
+ common.getCallback = function (options, callback) {
3535
+ return typeof options === 'function' ? options : callback
3536
+ };
3537
+
3538
+ common.getOptions = function (options, def) {
3539
+ if (typeof options === 'object' && options !== null) {
3540
+ return options
3541
+ }
3542
+
3543
+ if (def !== undefined) {
3544
+ return def
3545
+ }
3546
+
3547
+ return {}
3548
+ };
3549
+
3550
+ const { fromCallback: fromCallback$3 } = catering;
3551
+ const ModuleError$6 = moduleError;
3552
+ const { getOptions: getOptions$2, getCallback: getCallback$2 } = common;
3553
+
3554
+ const kPromise$3 = Symbol('promise');
3555
+ const kCallback$1 = Symbol('callback');
3556
+ const kWorking = Symbol('working');
3557
+ const kHandleOne$1 = Symbol('handleOne');
3558
+ const kHandleMany$1 = Symbol('handleMany');
3559
+ const kAutoClose = Symbol('autoClose');
3560
+ const kFinishWork = Symbol('finishWork');
3561
+ const kReturnMany = Symbol('returnMany');
3562
+ const kClosing = Symbol('closing');
3563
+ const kHandleClose = Symbol('handleClose');
3564
+ const kClosed = Symbol('closed');
3565
+ const kCloseCallbacks$1 = Symbol('closeCallbacks');
3566
+ const kKeyEncoding$1 = Symbol('keyEncoding');
3567
+ const kValueEncoding$1 = Symbol('valueEncoding');
3568
+ const kAbortOnClose = Symbol('abortOnClose');
3569
+ const kLegacy = Symbol('legacy');
3570
+ const kKeys = Symbol('keys');
3571
+ const kValues = Symbol('values');
3572
+ const kLimit = Symbol('limit');
3573
+ const kCount = Symbol('count');
3574
+
3575
+ const emptyOptions$1 = Object.freeze({});
3576
+ const noop$1 = () => {};
3577
+ let warnedEnd = false;
3578
+
3579
+ // This class is an internal utility for common functionality between AbstractIterator,
3580
+ // AbstractKeyIterator and AbstractValueIterator. It's not exported.
3581
+ class CommonIterator {
3582
+ constructor (db, options, legacy) {
3583
+ if (typeof db !== 'object' || db === null) {
3584
+ const hint = db === null ? 'null' : typeof db;
3585
+ throw new TypeError(`The first argument must be an abstract-level database, received ${hint}`)
3586
+ }
3587
+
3588
+ if (typeof options !== 'object' || options === null) {
3589
+ throw new TypeError('The second argument must be an options object')
3590
+ }
3591
+
3592
+ this[kClosed] = false;
3593
+ this[kCloseCallbacks$1] = [];
3594
+ this[kWorking] = false;
3595
+ this[kClosing] = false;
3596
+ this[kAutoClose] = false;
3597
+ this[kCallback$1] = null;
3598
+ this[kHandleOne$1] = this[kHandleOne$1].bind(this);
3599
+ this[kHandleMany$1] = this[kHandleMany$1].bind(this);
3600
+ this[kHandleClose] = this[kHandleClose].bind(this);
3601
+ this[kKeyEncoding$1] = options[kKeyEncoding$1];
3602
+ this[kValueEncoding$1] = options[kValueEncoding$1];
3603
+ this[kLegacy] = legacy;
3604
+ this[kLimit] = Number.isInteger(options.limit) && options.limit >= 0 ? options.limit : Infinity;
3605
+ this[kCount] = 0;
3606
+
3607
+ // Undocumented option to abort pending work on close(). Used by the
3608
+ // many-level module as a temporary solution to a blocked close().
3609
+ // TODO (next major): consider making this the default behavior. Native
3610
+ // implementations should have their own logic to safely close iterators.
3611
+ this[kAbortOnClose] = !!options.abortOnClose;
3612
+
3613
+ this.db = db;
3614
+ this.db.attachResource(this);
3615
+ this.nextTick = db.nextTick;
3616
+ }
3617
+
3618
+ get count () {
3619
+ return this[kCount]
3620
+ }
3621
+
3622
+ get limit () {
3623
+ return this[kLimit]
3624
+ }
3625
+
3626
+ next (callback) {
3627
+ let promise;
3628
+
3629
+ if (callback === undefined) {
3630
+ promise = new Promise((resolve, reject) => {
3631
+ callback = (err, key, value) => {
3632
+ if (err) reject(err);
3633
+ else if (!this[kLegacy]) resolve(key);
3634
+ else if (key === undefined && value === undefined) resolve();
3635
+ else resolve([key, value]);
2990
3636
  };
2991
- tx.addEventListener('complete', complete);
2992
- tx.addEventListener('error', error);
2993
- tx.addEventListener('abort', error);
3637
+ });
3638
+ } else if (typeof callback !== 'function') {
3639
+ throw new TypeError('Callback must be a function')
3640
+ }
3641
+
3642
+ if (this[kClosing]) {
3643
+ this.nextTick(callback, new ModuleError$6('Iterator is not open: cannot call next() after close()', {
3644
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
3645
+ }));
3646
+ } else if (this[kWorking]) {
3647
+ this.nextTick(callback, new ModuleError$6('Iterator is busy: cannot call next() until previous call has completed', {
3648
+ code: 'LEVEL_ITERATOR_BUSY'
3649
+ }));
3650
+ } else {
3651
+ this[kWorking] = true;
3652
+ this[kCallback$1] = callback;
3653
+
3654
+ if (this[kCount] >= this[kLimit]) this.nextTick(this[kHandleOne$1], null);
3655
+ else this._next(this[kHandleOne$1]);
3656
+ }
3657
+
3658
+ return promise
3659
+ }
3660
+
3661
+ _next (callback) {
3662
+ this.nextTick(callback);
3663
+ }
3664
+
3665
+ nextv (size, options, callback) {
3666
+ callback = getCallback$2(options, callback);
3667
+ callback = fromCallback$3(callback, kPromise$3);
3668
+ options = getOptions$2(options, emptyOptions$1);
3669
+
3670
+ if (!Number.isInteger(size)) {
3671
+ this.nextTick(callback, new TypeError("The first argument 'size' must be an integer"));
3672
+ return callback[kPromise$3]
3673
+ }
3674
+
3675
+ if (this[kClosing]) {
3676
+ this.nextTick(callback, new ModuleError$6('Iterator is not open: cannot call nextv() after close()', {
3677
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
3678
+ }));
3679
+ } else if (this[kWorking]) {
3680
+ this.nextTick(callback, new ModuleError$6('Iterator is busy: cannot call nextv() until previous call has completed', {
3681
+ code: 'LEVEL_ITERATOR_BUSY'
3682
+ }));
3683
+ } else {
3684
+ if (size < 1) size = 1;
3685
+ if (this[kLimit] < Infinity) size = Math.min(size, this[kLimit] - this[kCount]);
3686
+
3687
+ this[kWorking] = true;
3688
+ this[kCallback$1] = callback;
3689
+
3690
+ if (size <= 0) this.nextTick(this[kHandleMany$1], null, []);
3691
+ else this._nextv(size, options, this[kHandleMany$1]);
3692
+ }
3693
+
3694
+ return callback[kPromise$3]
3695
+ }
3696
+
3697
+ _nextv (size, options, callback) {
3698
+ const acc = [];
3699
+ const onnext = (err, key, value) => {
3700
+ if (err) {
3701
+ return callback(err)
3702
+ } else if (this[kLegacy] ? key === undefined && value === undefined : key === undefined) {
3703
+ return callback(null, acc)
3704
+ }
3705
+
3706
+ acc.push(this[kLegacy] ? [key, value] : key);
3707
+
3708
+ if (acc.length === size) {
3709
+ callback(null, acc);
3710
+ } else {
3711
+ this._next(onnext);
3712
+ }
3713
+ };
3714
+
3715
+ this._next(onnext);
3716
+ }
3717
+
3718
+ all (options, callback) {
3719
+ callback = getCallback$2(options, callback);
3720
+ callback = fromCallback$3(callback, kPromise$3);
3721
+ options = getOptions$2(options, emptyOptions$1);
3722
+
3723
+ if (this[kClosing]) {
3724
+ this.nextTick(callback, new ModuleError$6('Iterator is not open: cannot call all() after close()', {
3725
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
3726
+ }));
3727
+ } else if (this[kWorking]) {
3728
+ this.nextTick(callback, new ModuleError$6('Iterator is busy: cannot call all() until previous call has completed', {
3729
+ code: 'LEVEL_ITERATOR_BUSY'
3730
+ }));
3731
+ } else {
3732
+ this[kWorking] = true;
3733
+ this[kCallback$1] = callback;
3734
+ this[kAutoClose] = true;
3735
+
3736
+ if (this[kCount] >= this[kLimit]) this.nextTick(this[kHandleMany$1], null, []);
3737
+ else this._all(options, this[kHandleMany$1]);
3738
+ }
3739
+
3740
+ return callback[kPromise$3]
3741
+ }
3742
+
3743
+ _all (options, callback) {
3744
+ // Must count here because we're directly calling _nextv()
3745
+ let count = this[kCount];
3746
+ const acc = [];
3747
+
3748
+ const nextv = () => {
3749
+ // Not configurable, because implementations should optimize _all().
3750
+ const size = this[kLimit] < Infinity ? Math.min(1e3, this[kLimit] - count) : 1e3;
3751
+
3752
+ if (size <= 0) {
3753
+ this.nextTick(callback, null, acc);
3754
+ } else {
3755
+ this._nextv(size, emptyOptions$1, onnextv);
3756
+ }
3757
+ };
3758
+
3759
+ const onnextv = (err, items) => {
3760
+ if (err) {
3761
+ callback(err);
3762
+ } else if (items.length === 0) {
3763
+ callback(null, acc);
3764
+ } else {
3765
+ acc.push.apply(acc, items);
3766
+ count += items.length;
3767
+ nextv();
3768
+ }
3769
+ };
3770
+
3771
+ nextv();
3772
+ }
3773
+
3774
+ [kFinishWork] () {
3775
+ const cb = this[kCallback$1];
3776
+
3777
+ // Callback will be null if work was aborted on close
3778
+ if (this[kAbortOnClose] && cb === null) return noop$1
3779
+
3780
+ this[kWorking] = false;
3781
+ this[kCallback$1] = null;
3782
+
3783
+ if (this[kClosing]) this._close(this[kHandleClose]);
3784
+
3785
+ return cb
3786
+ }
3787
+
3788
+ [kReturnMany] (cb, err, items) {
3789
+ if (this[kAutoClose]) {
3790
+ this.close(cb.bind(null, err, items));
3791
+ } else {
3792
+ cb(err, items);
3793
+ }
3794
+ }
3795
+
3796
+ seek (target, options) {
3797
+ options = getOptions$2(options, emptyOptions$1);
3798
+
3799
+ if (this[kClosing]) ; else if (this[kWorking]) {
3800
+ throw new ModuleError$6('Iterator is busy: cannot call seek() until next() has completed', {
3801
+ code: 'LEVEL_ITERATOR_BUSY'
3802
+ })
3803
+ } else {
3804
+ const keyEncoding = this.db.keyEncoding(options.keyEncoding || this[kKeyEncoding$1]);
3805
+ const keyFormat = keyEncoding.format;
3806
+
3807
+ if (options.keyEncoding !== keyFormat) {
3808
+ options = { ...options, keyEncoding: keyFormat };
3809
+ }
3810
+
3811
+ const mapped = this.db.prefixKey(keyEncoding.encode(target), keyFormat);
3812
+ this._seek(mapped, options);
3813
+ }
3814
+ }
3815
+
3816
+ _seek (target, options) {
3817
+ throw new ModuleError$6('Iterator does not support seek()', {
3818
+ code: 'LEVEL_NOT_SUPPORTED'
3819
+ })
3820
+ }
3821
+
3822
+ close (callback) {
3823
+ callback = fromCallback$3(callback, kPromise$3);
3824
+
3825
+ if (this[kClosed]) {
3826
+ this.nextTick(callback);
3827
+ } else if (this[kClosing]) {
3828
+ this[kCloseCallbacks$1].push(callback);
3829
+ } else {
3830
+ this[kClosing] = true;
3831
+ this[kCloseCallbacks$1].push(callback);
3832
+
3833
+ if (!this[kWorking]) {
3834
+ this._close(this[kHandleClose]);
3835
+ } else if (this[kAbortOnClose]) {
3836
+ // Don't wait for work to finish. Subsequently ignore the result.
3837
+ const cb = this[kFinishWork]();
3838
+
3839
+ cb(new ModuleError$6('Aborted on iterator close()', {
3840
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
3841
+ }));
3842
+ }
3843
+ }
3844
+
3845
+ return callback[kPromise$3]
3846
+ }
3847
+
3848
+ _close (callback) {
3849
+ this.nextTick(callback);
3850
+ }
3851
+
3852
+ [kHandleClose] () {
3853
+ this[kClosed] = true;
3854
+ this.db.detachResource(this);
3855
+
3856
+ const callbacks = this[kCloseCallbacks$1];
3857
+ this[kCloseCallbacks$1] = [];
3858
+
3859
+ for (const cb of callbacks) {
3860
+ cb();
3861
+ }
3862
+ }
3863
+
3864
+ async * [Symbol.asyncIterator] () {
3865
+ try {
3866
+ let item;
3867
+
3868
+ while ((item = (await this.next())) !== undefined) {
3869
+ yield item;
3870
+ }
3871
+ } finally {
3872
+ if (!this[kClosed]) await this.close();
3873
+ }
3874
+ }
3875
+ }
3876
+
3877
+ // For backwards compatibility this class is not (yet) called AbstractEntryIterator.
3878
+ class AbstractIterator$3 extends CommonIterator {
3879
+ constructor (db, options) {
3880
+ super(db, options, true);
3881
+ this[kKeys] = options.keys !== false;
3882
+ this[kValues] = options.values !== false;
3883
+ }
3884
+
3885
+ [kHandleOne$1] (err, key, value) {
3886
+ const cb = this[kFinishWork]();
3887
+ if (err) return cb(err)
3888
+
3889
+ try {
3890
+ key = this[kKeys] && key !== undefined ? this[kKeyEncoding$1].decode(key) : undefined;
3891
+ value = this[kValues] && value !== undefined ? this[kValueEncoding$1].decode(value) : undefined;
3892
+ } catch (err) {
3893
+ return cb(new IteratorDecodeError('entry', err))
3894
+ }
3895
+
3896
+ if (!(key === undefined && value === undefined)) {
3897
+ this[kCount]++;
3898
+ }
3899
+
3900
+ cb(null, key, value);
3901
+ }
3902
+
3903
+ [kHandleMany$1] (err, entries) {
3904
+ const cb = this[kFinishWork]();
3905
+ if (err) return this[kReturnMany](cb, err)
3906
+
3907
+ try {
3908
+ for (const entry of entries) {
3909
+ const key = entry[0];
3910
+ const value = entry[1];
3911
+
3912
+ entry[0] = this[kKeys] && key !== undefined ? this[kKeyEncoding$1].decode(key) : undefined;
3913
+ entry[1] = this[kValues] && value !== undefined ? this[kValueEncoding$1].decode(value) : undefined;
3914
+ }
3915
+ } catch (err) {
3916
+ return this[kReturnMany](cb, new IteratorDecodeError('entries', err))
3917
+ }
3918
+
3919
+ this[kCount] += entries.length;
3920
+ this[kReturnMany](cb, null, entries);
3921
+ }
3922
+
3923
+ end (callback) {
3924
+ if (!warnedEnd && typeof console !== 'undefined') {
3925
+ warnedEnd = true;
3926
+ console.warn(new ModuleError$6(
3927
+ 'The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version',
3928
+ { code: 'LEVEL_LEGACY' }
3929
+ ));
3930
+ }
3931
+
3932
+ return this.close(callback)
3933
+ }
3934
+ }
3935
+
3936
+ class AbstractKeyIterator$2 extends CommonIterator {
3937
+ constructor (db, options) {
3938
+ super(db, options, false);
3939
+ }
3940
+
3941
+ [kHandleOne$1] (err, key) {
3942
+ const cb = this[kFinishWork]();
3943
+ if (err) return cb(err)
3944
+
3945
+ try {
3946
+ key = key !== undefined ? this[kKeyEncoding$1].decode(key) : undefined;
3947
+ } catch (err) {
3948
+ return cb(new IteratorDecodeError('key', err))
3949
+ }
3950
+
3951
+ if (key !== undefined) this[kCount]++;
3952
+ cb(null, key);
3953
+ }
3954
+
3955
+ [kHandleMany$1] (err, keys) {
3956
+ const cb = this[kFinishWork]();
3957
+ if (err) return this[kReturnMany](cb, err)
3958
+
3959
+ try {
3960
+ for (let i = 0; i < keys.length; i++) {
3961
+ const key = keys[i];
3962
+ keys[i] = key !== undefined ? this[kKeyEncoding$1].decode(key) : undefined;
3963
+ }
3964
+ } catch (err) {
3965
+ return this[kReturnMany](cb, new IteratorDecodeError('keys', err))
3966
+ }
3967
+
3968
+ this[kCount] += keys.length;
3969
+ this[kReturnMany](cb, null, keys);
3970
+ }
3971
+ }
3972
+
3973
+ class AbstractValueIterator$2 extends CommonIterator {
3974
+ constructor (db, options) {
3975
+ super(db, options, false);
3976
+ }
3977
+
3978
+ [kHandleOne$1] (err, value) {
3979
+ const cb = this[kFinishWork]();
3980
+ if (err) return cb(err)
3981
+
3982
+ try {
3983
+ value = value !== undefined ? this[kValueEncoding$1].decode(value) : undefined;
3984
+ } catch (err) {
3985
+ return cb(new IteratorDecodeError('value', err))
3986
+ }
3987
+
3988
+ if (value !== undefined) this[kCount]++;
3989
+ cb(null, value);
3990
+ }
3991
+
3992
+ [kHandleMany$1] (err, values) {
3993
+ const cb = this[kFinishWork]();
3994
+ if (err) return this[kReturnMany](cb, err)
3995
+
3996
+ try {
3997
+ for (let i = 0; i < values.length; i++) {
3998
+ const value = values[i];
3999
+ values[i] = value !== undefined ? this[kValueEncoding$1].decode(value) : undefined;
4000
+ }
4001
+ } catch (err) {
4002
+ return this[kReturnMany](cb, new IteratorDecodeError('values', err))
4003
+ }
4004
+
4005
+ this[kCount] += values.length;
4006
+ this[kReturnMany](cb, null, values);
4007
+ }
4008
+ }
4009
+
4010
+ // Internal utility, not typed or exported
4011
+ class IteratorDecodeError extends ModuleError$6 {
4012
+ constructor (subject, cause) {
4013
+ super(`Iterator could not decode ${subject}`, {
4014
+ code: 'LEVEL_DECODE_ERROR',
4015
+ cause
4016
+ });
4017
+ }
4018
+ }
4019
+
4020
+ // To help migrating to abstract-level
4021
+ for (const k of ['_ended property', '_nexting property', '_end method']) {
4022
+ Object.defineProperty(AbstractIterator$3.prototype, k.split(' ')[0], {
4023
+ get () { throw new ModuleError$6(`The ${k} has been removed`, { code: 'LEVEL_LEGACY' }) },
4024
+ set () { throw new ModuleError$6(`The ${k} has been removed`, { code: 'LEVEL_LEGACY' }) }
4025
+ });
4026
+ }
4027
+
4028
+ // Exposed so that AbstractLevel can set these options
4029
+ AbstractIterator$3.keyEncoding = kKeyEncoding$1;
4030
+ AbstractIterator$3.valueEncoding = kValueEncoding$1;
4031
+
4032
+ abstractIterator.AbstractIterator = AbstractIterator$3;
4033
+ abstractIterator.AbstractKeyIterator = AbstractKeyIterator$2;
4034
+ abstractIterator.AbstractValueIterator = AbstractValueIterator$2;
4035
+
4036
+ var defaultKvIterator = {};
4037
+
4038
+ const { AbstractKeyIterator: AbstractKeyIterator$1, AbstractValueIterator: AbstractValueIterator$1 } = abstractIterator;
4039
+
4040
+ const kIterator = Symbol('iterator');
4041
+ const kCallback = Symbol('callback');
4042
+ const kHandleOne = Symbol('handleOne');
4043
+ const kHandleMany = Symbol('handleMany');
4044
+
4045
+ class DefaultKeyIterator$1 extends AbstractKeyIterator$1 {
4046
+ constructor (db, options) {
4047
+ super(db, options);
4048
+
4049
+ this[kIterator] = db.iterator({ ...options, keys: true, values: false });
4050
+ this[kHandleOne] = this[kHandleOne].bind(this);
4051
+ this[kHandleMany] = this[kHandleMany].bind(this);
4052
+ }
4053
+ }
4054
+
4055
+ class DefaultValueIterator$1 extends AbstractValueIterator$1 {
4056
+ constructor (db, options) {
4057
+ super(db, options);
4058
+
4059
+ this[kIterator] = db.iterator({ ...options, keys: false, values: true });
4060
+ this[kHandleOne] = this[kHandleOne].bind(this);
4061
+ this[kHandleMany] = this[kHandleMany].bind(this);
4062
+ }
4063
+ }
4064
+
4065
+ for (const Iterator of [DefaultKeyIterator$1, DefaultValueIterator$1]) {
4066
+ const keys = Iterator === DefaultKeyIterator$1;
4067
+ const mapEntry = keys ? (entry) => entry[0] : (entry) => entry[1];
4068
+
4069
+ Iterator.prototype._next = function (callback) {
4070
+ this[kCallback] = callback;
4071
+ this[kIterator].next(this[kHandleOne]);
4072
+ };
4073
+
4074
+ Iterator.prototype[kHandleOne] = function (err, key, value) {
4075
+ const callback = this[kCallback];
4076
+ if (err) callback(err);
4077
+ else callback(null, keys ? key : value);
4078
+ };
4079
+
4080
+ Iterator.prototype._nextv = function (size, options, callback) {
4081
+ this[kCallback] = callback;
4082
+ this[kIterator].nextv(size, options, this[kHandleMany]);
4083
+ };
4084
+
4085
+ Iterator.prototype._all = function (options, callback) {
4086
+ this[kCallback] = callback;
4087
+ this[kIterator].all(options, this[kHandleMany]);
4088
+ };
4089
+
4090
+ Iterator.prototype[kHandleMany] = function (err, entries) {
4091
+ const callback = this[kCallback];
4092
+ if (err) callback(err);
4093
+ else callback(null, entries.map(mapEntry));
4094
+ };
4095
+
4096
+ Iterator.prototype._seek = function (target, options) {
4097
+ this[kIterator].seek(target, options);
4098
+ };
4099
+
4100
+ Iterator.prototype._close = function (callback) {
4101
+ this[kIterator].close(callback);
4102
+ };
4103
+ }
4104
+
4105
+ // Internal utilities, should be typed as AbstractKeyIterator and AbstractValueIterator
4106
+ defaultKvIterator.DefaultKeyIterator = DefaultKeyIterator$1;
4107
+ defaultKvIterator.DefaultValueIterator = DefaultValueIterator$1;
4108
+
4109
+ var deferredIterator = {};
4110
+
4111
+ const { AbstractIterator: AbstractIterator$2, AbstractKeyIterator, AbstractValueIterator } = abstractIterator;
4112
+ const ModuleError$5 = moduleError;
4113
+
4114
+ const kNut = Symbol('nut');
4115
+ const kUndefer$1 = Symbol('undefer');
4116
+ const kFactory = Symbol('factory');
4117
+
4118
+ class DeferredIterator$1 extends AbstractIterator$2 {
4119
+ constructor (db, options) {
4120
+ super(db, options);
4121
+
4122
+ this[kNut] = null;
4123
+ this[kFactory] = () => db.iterator(options);
4124
+
4125
+ this.db.defer(() => this[kUndefer$1]());
4126
+ }
4127
+ }
4128
+
4129
+ class DeferredKeyIterator$1 extends AbstractKeyIterator {
4130
+ constructor (db, options) {
4131
+ super(db, options);
4132
+
4133
+ this[kNut] = null;
4134
+ this[kFactory] = () => db.keys(options);
4135
+
4136
+ this.db.defer(() => this[kUndefer$1]());
4137
+ }
4138
+ }
4139
+
4140
+ class DeferredValueIterator$1 extends AbstractValueIterator {
4141
+ constructor (db, options) {
4142
+ super(db, options);
4143
+
4144
+ this[kNut] = null;
4145
+ this[kFactory] = () => db.values(options);
4146
+
4147
+ this.db.defer(() => this[kUndefer$1]());
4148
+ }
4149
+ }
4150
+
4151
+ for (const Iterator of [DeferredIterator$1, DeferredKeyIterator$1, DeferredValueIterator$1]) {
4152
+ Iterator.prototype[kUndefer$1] = function () {
4153
+ if (this.db.status === 'open') {
4154
+ this[kNut] = this[kFactory]();
4155
+ }
4156
+ };
4157
+
4158
+ Iterator.prototype._next = function (callback) {
4159
+ if (this[kNut] !== null) {
4160
+ this[kNut].next(callback);
4161
+ } else if (this.db.status === 'opening') {
4162
+ this.db.defer(() => this._next(callback));
4163
+ } else {
4164
+ this.nextTick(callback, new ModuleError$5('Iterator is not open: cannot call next() after close()', {
4165
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
4166
+ }));
4167
+ }
4168
+ };
4169
+
4170
+ Iterator.prototype._nextv = function (size, options, callback) {
4171
+ if (this[kNut] !== null) {
4172
+ this[kNut].nextv(size, options, callback);
4173
+ } else if (this.db.status === 'opening') {
4174
+ this.db.defer(() => this._nextv(size, options, callback));
4175
+ } else {
4176
+ this.nextTick(callback, new ModuleError$5('Iterator is not open: cannot call nextv() after close()', {
4177
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
4178
+ }));
4179
+ }
4180
+ };
4181
+
4182
+ Iterator.prototype._all = function (options, callback) {
4183
+ if (this[kNut] !== null) {
4184
+ this[kNut].all(callback);
4185
+ } else if (this.db.status === 'opening') {
4186
+ this.db.defer(() => this._all(options, callback));
4187
+ } else {
4188
+ this.nextTick(callback, new ModuleError$5('Iterator is not open: cannot call all() after close()', {
4189
+ code: 'LEVEL_ITERATOR_NOT_OPEN'
4190
+ }));
4191
+ }
4192
+ };
4193
+
4194
+ Iterator.prototype._seek = function (target, options) {
4195
+ if (this[kNut] !== null) {
4196
+ // TODO: explain why we need _seek() rather than seek() here
4197
+ this[kNut]._seek(target, options);
4198
+ } else if (this.db.status === 'opening') {
4199
+ this.db.defer(() => this._seek(target, options));
4200
+ }
4201
+ };
4202
+
4203
+ Iterator.prototype._close = function (callback) {
4204
+ if (this[kNut] !== null) {
4205
+ this[kNut].close(callback);
4206
+ } else if (this.db.status === 'opening') {
4207
+ this.db.defer(() => this._close(callback));
4208
+ } else {
4209
+ this.nextTick(callback);
4210
+ }
4211
+ };
4212
+ }
4213
+
4214
+ deferredIterator.DeferredIterator = DeferredIterator$1;
4215
+ deferredIterator.DeferredKeyIterator = DeferredKeyIterator$1;
4216
+ deferredIterator.DeferredValueIterator = DeferredValueIterator$1;
4217
+
4218
+ var defaultChainedBatch = {};
4219
+
4220
+ var abstractChainedBatch = {};
4221
+
4222
+ const { fromCallback: fromCallback$2 } = catering;
4223
+ const ModuleError$4 = moduleError;
4224
+ const { getCallback: getCallback$1, getOptions: getOptions$1 } = common;
4225
+
4226
+ const kPromise$2 = Symbol('promise');
4227
+ const kStatus$1 = Symbol('status');
4228
+ const kOperations$1 = Symbol('operations');
4229
+ const kFinishClose = Symbol('finishClose');
4230
+ const kCloseCallbacks = Symbol('closeCallbacks');
4231
+
4232
+ class AbstractChainedBatch$1 {
4233
+ constructor (db) {
4234
+ if (typeof db !== 'object' || db === null) {
4235
+ const hint = db === null ? 'null' : typeof db;
4236
+ throw new TypeError(`The first argument must be an abstract-level database, received ${hint}`)
4237
+ }
4238
+
4239
+ this[kOperations$1] = [];
4240
+ this[kCloseCallbacks] = [];
4241
+ this[kStatus$1] = 'open';
4242
+ this[kFinishClose] = this[kFinishClose].bind(this);
4243
+
4244
+ this.db = db;
4245
+ this.db.attachResource(this);
4246
+ this.nextTick = db.nextTick;
4247
+ }
4248
+
4249
+ get length () {
4250
+ return this[kOperations$1].length
4251
+ }
4252
+
4253
+ put (key, value, options) {
4254
+ if (this[kStatus$1] !== 'open') {
4255
+ throw new ModuleError$4('Batch is not open: cannot call put() after write() or close()', {
4256
+ code: 'LEVEL_BATCH_NOT_OPEN'
4257
+ })
4258
+ }
4259
+
4260
+ const err = this.db._checkKey(key) || this.db._checkValue(value);
4261
+ if (err) throw err
4262
+
4263
+ const db = options && options.sublevel != null ? options.sublevel : this.db;
4264
+ const original = options;
4265
+ const keyEncoding = db.keyEncoding(options && options.keyEncoding);
4266
+ const valueEncoding = db.valueEncoding(options && options.valueEncoding);
4267
+ const keyFormat = keyEncoding.format;
4268
+
4269
+ // Forward encoding options
4270
+ options = { ...options, keyEncoding: keyFormat, valueEncoding: valueEncoding.format };
4271
+
4272
+ // Prevent double prefixing
4273
+ if (db !== this.db) {
4274
+ options.sublevel = null;
4275
+ }
4276
+
4277
+ const mappedKey = db.prefixKey(keyEncoding.encode(key), keyFormat);
4278
+ const mappedValue = valueEncoding.encode(value);
4279
+
4280
+ this._put(mappedKey, mappedValue, options);
4281
+ this[kOperations$1].push({ ...original, type: 'put', key, value });
4282
+
4283
+ return this
4284
+ }
4285
+
4286
+ _put (key, value, options) {}
4287
+
4288
+ del (key, options) {
4289
+ if (this[kStatus$1] !== 'open') {
4290
+ throw new ModuleError$4('Batch is not open: cannot call del() after write() or close()', {
4291
+ code: 'LEVEL_BATCH_NOT_OPEN'
4292
+ })
4293
+ }
4294
+
4295
+ const err = this.db._checkKey(key);
4296
+ if (err) throw err
4297
+
4298
+ const db = options && options.sublevel != null ? options.sublevel : this.db;
4299
+ const original = options;
4300
+ const keyEncoding = db.keyEncoding(options && options.keyEncoding);
4301
+ const keyFormat = keyEncoding.format;
4302
+
4303
+ // Forward encoding options
4304
+ options = { ...options, keyEncoding: keyFormat };
4305
+
4306
+ // Prevent double prefixing
4307
+ if (db !== this.db) {
4308
+ options.sublevel = null;
4309
+ }
4310
+
4311
+ this._del(db.prefixKey(keyEncoding.encode(key), keyFormat), options);
4312
+ this[kOperations$1].push({ ...original, type: 'del', key });
4313
+
4314
+ return this
4315
+ }
4316
+
4317
+ _del (key, options) {}
4318
+
4319
+ clear () {
4320
+ if (this[kStatus$1] !== 'open') {
4321
+ throw new ModuleError$4('Batch is not open: cannot call clear() after write() or close()', {
4322
+ code: 'LEVEL_BATCH_NOT_OPEN'
4323
+ })
4324
+ }
4325
+
4326
+ this._clear();
4327
+ this[kOperations$1] = [];
4328
+
4329
+ return this
4330
+ }
4331
+
4332
+ _clear () {}
4333
+
4334
+ write (options, callback) {
4335
+ callback = getCallback$1(options, callback);
4336
+ callback = fromCallback$2(callback, kPromise$2);
4337
+ options = getOptions$1(options);
4338
+
4339
+ if (this[kStatus$1] !== 'open') {
4340
+ this.nextTick(callback, new ModuleError$4('Batch is not open: cannot call write() after write() or close()', {
4341
+ code: 'LEVEL_BATCH_NOT_OPEN'
4342
+ }));
4343
+ } else if (this.length === 0) {
4344
+ this.close(callback);
4345
+ } else {
4346
+ this[kStatus$1] = 'writing';
4347
+ this._write(options, (err) => {
4348
+ this[kStatus$1] = 'closing';
4349
+ this[kCloseCallbacks].push(() => callback(err));
4350
+
4351
+ // Emit after setting 'closing' status, because event may trigger a
4352
+ // db close which in turn triggers (idempotently) closing this batch.
4353
+ if (!err) this.db.emit('batch', this[kOperations$1]);
4354
+
4355
+ this._close(this[kFinishClose]);
4356
+ });
4357
+ }
4358
+
4359
+ return callback[kPromise$2]
4360
+ }
4361
+
4362
+ _write (options, callback) {}
4363
+
4364
+ close (callback) {
4365
+ callback = fromCallback$2(callback, kPromise$2);
4366
+
4367
+ if (this[kStatus$1] === 'closing') {
4368
+ this[kCloseCallbacks].push(callback);
4369
+ } else if (this[kStatus$1] === 'closed') {
4370
+ this.nextTick(callback);
4371
+ } else {
4372
+ this[kCloseCallbacks].push(callback);
4373
+
4374
+ if (this[kStatus$1] !== 'writing') {
4375
+ this[kStatus$1] = 'closing';
4376
+ this._close(this[kFinishClose]);
4377
+ }
4378
+ }
4379
+
4380
+ return callback[kPromise$2]
4381
+ }
4382
+
4383
+ _close (callback) {
4384
+ this.nextTick(callback);
4385
+ }
4386
+
4387
+ [kFinishClose] () {
4388
+ this[kStatus$1] = 'closed';
4389
+ this.db.detachResource(this);
4390
+
4391
+ const callbacks = this[kCloseCallbacks];
4392
+ this[kCloseCallbacks] = [];
4393
+
4394
+ for (const cb of callbacks) {
4395
+ cb();
4396
+ }
4397
+ }
4398
+ }
4399
+
4400
+ abstractChainedBatch.AbstractChainedBatch = AbstractChainedBatch$1;
4401
+
4402
+ const { AbstractChainedBatch } = abstractChainedBatch;
4403
+ const ModuleError$3 = moduleError;
4404
+ const kEncoded = Symbol('encoded');
4405
+
4406
+ // Functional default for chained batch, with support of deferred open
4407
+ class DefaultChainedBatch$1 extends AbstractChainedBatch {
4408
+ constructor (db) {
4409
+ super(db);
4410
+ this[kEncoded] = [];
4411
+ }
4412
+
4413
+ _put (key, value, options) {
4414
+ this[kEncoded].push({ ...options, type: 'put', key, value });
4415
+ }
4416
+
4417
+ _del (key, options) {
4418
+ this[kEncoded].push({ ...options, type: 'del', key });
4419
+ }
4420
+
4421
+ _clear () {
4422
+ this[kEncoded] = [];
4423
+ }
4424
+
4425
+ // Assumes this[kEncoded] cannot change after write()
4426
+ _write (options, callback) {
4427
+ if (this.db.status === 'opening') {
4428
+ this.db.defer(() => this._write(options, callback));
4429
+ } else if (this.db.status === 'open') {
4430
+ if (this[kEncoded].length === 0) this.nextTick(callback);
4431
+ else this.db._batch(this[kEncoded], options, callback);
4432
+ } else {
4433
+ this.nextTick(callback, new ModuleError$3('Batch is not open: cannot call write() after write() or close()', {
4434
+ code: 'LEVEL_BATCH_NOT_OPEN'
4435
+ }));
4436
+ }
4437
+ }
4438
+ }
4439
+
4440
+ defaultChainedBatch.DefaultChainedBatch = DefaultChainedBatch$1;
4441
+
4442
+ const ModuleError$2 = moduleError;
4443
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
4444
+ const rangeOptions$1 = new Set(['lt', 'lte', 'gt', 'gte']);
4445
+
4446
+ var rangeOptions_1 = function (options, keyEncoding) {
4447
+ const result = {};
4448
+
4449
+ for (const k in options) {
4450
+ if (!hasOwnProperty.call(options, k)) continue
4451
+ if (k === 'keyEncoding' || k === 'valueEncoding') continue
4452
+
4453
+ if (k === 'start' || k === 'end') {
4454
+ throw new ModuleError$2(`The legacy range option '${k}' has been removed`, {
4455
+ code: 'LEVEL_LEGACY'
4456
+ })
4457
+ } else if (k === 'encoding') {
4458
+ // To help migrating to abstract-level
4459
+ throw new ModuleError$2("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead", {
4460
+ code: 'LEVEL_LEGACY'
4461
+ })
4462
+ }
4463
+
4464
+ if (rangeOptions$1.has(k)) {
4465
+ // Note that we don't reject nullish and empty options here. While
4466
+ // those types are invalid as keys, they are valid as range options.
4467
+ result[k] = keyEncoding.encode(options[k]);
4468
+ } else {
4469
+ result[k] = options[k];
4470
+ }
4471
+ }
4472
+
4473
+ result.reverse = !!result.reverse;
4474
+ result.limit = Number.isInteger(result.limit) && result.limit >= 0 ? result.limit : -1;
4475
+
4476
+ return result
4477
+ };
4478
+
4479
+ var nextTick;
4480
+ var hasRequiredNextTick;
4481
+
4482
+ function requireNextTick () {
4483
+ if (hasRequiredNextTick) return nextTick;
4484
+ hasRequiredNextTick = 1;
4485
+
4486
+ nextTick = process.nextTick;
4487
+ return nextTick;
4488
+ }
4489
+
4490
+ var abstractSublevelIterator = {};
4491
+
4492
+ var hasRequiredAbstractSublevelIterator;
4493
+
4494
+ function requireAbstractSublevelIterator () {
4495
+ if (hasRequiredAbstractSublevelIterator) return abstractSublevelIterator;
4496
+ hasRequiredAbstractSublevelIterator = 1;
4497
+
4498
+ const { AbstractIterator, AbstractKeyIterator, AbstractValueIterator } = abstractIterator;
4499
+
4500
+ const kUnfix = Symbol('unfix');
4501
+ const kIterator = Symbol('iterator');
4502
+ const kHandleOne = Symbol('handleOne');
4503
+ const kHandleMany = Symbol('handleMany');
4504
+ const kCallback = Symbol('callback');
4505
+
4506
+ // TODO: unfix natively if db supports it
4507
+ class AbstractSublevelIterator extends AbstractIterator {
4508
+ constructor (db, options, iterator, unfix) {
4509
+ super(db, options);
4510
+
4511
+ this[kIterator] = iterator;
4512
+ this[kUnfix] = unfix;
4513
+ this[kHandleOne] = this[kHandleOne].bind(this);
4514
+ this[kHandleMany] = this[kHandleMany].bind(this);
4515
+ this[kCallback] = null;
4516
+ }
4517
+
4518
+ [kHandleOne] (err, key, value) {
4519
+ const callback = this[kCallback];
4520
+ if (err) return callback(err)
4521
+ if (key !== undefined) key = this[kUnfix](key);
4522
+ callback(err, key, value);
4523
+ }
4524
+
4525
+ [kHandleMany] (err, entries) {
4526
+ const callback = this[kCallback];
4527
+ if (err) return callback(err)
4528
+
4529
+ for (const entry of entries) {
4530
+ const key = entry[0];
4531
+ if (key !== undefined) entry[0] = this[kUnfix](key);
4532
+ }
4533
+
4534
+ callback(err, entries);
4535
+ }
4536
+ }
4537
+
4538
+ class AbstractSublevelKeyIterator extends AbstractKeyIterator {
4539
+ constructor (db, options, iterator, unfix) {
4540
+ super(db, options);
4541
+
4542
+ this[kIterator] = iterator;
4543
+ this[kUnfix] = unfix;
4544
+ this[kHandleOne] = this[kHandleOne].bind(this);
4545
+ this[kHandleMany] = this[kHandleMany].bind(this);
4546
+ this[kCallback] = null;
4547
+ }
4548
+
4549
+ [kHandleOne] (err, key) {
4550
+ const callback = this[kCallback];
4551
+ if (err) return callback(err)
4552
+ if (key !== undefined) key = this[kUnfix](key);
4553
+ callback(err, key);
4554
+ }
4555
+
4556
+ [kHandleMany] (err, keys) {
4557
+ const callback = this[kCallback];
4558
+ if (err) return callback(err)
4559
+
4560
+ for (let i = 0; i < keys.length; i++) {
4561
+ const key = keys[i];
4562
+ if (key !== undefined) keys[i] = this[kUnfix](key);
4563
+ }
4564
+
4565
+ callback(err, keys);
4566
+ }
4567
+ }
4568
+
4569
+ class AbstractSublevelValueIterator extends AbstractValueIterator {
4570
+ constructor (db, options, iterator) {
4571
+ super(db, options);
4572
+ this[kIterator] = iterator;
4573
+ }
4574
+ }
4575
+
4576
+ for (const Iterator of [AbstractSublevelIterator, AbstractSublevelKeyIterator]) {
4577
+ Iterator.prototype._next = function (callback) {
4578
+ this[kCallback] = callback;
4579
+ this[kIterator].next(this[kHandleOne]);
4580
+ };
4581
+
4582
+ Iterator.prototype._nextv = function (size, options, callback) {
4583
+ this[kCallback] = callback;
4584
+ this[kIterator].nextv(size, options, this[kHandleMany]);
4585
+ };
4586
+
4587
+ Iterator.prototype._all = function (options, callback) {
4588
+ this[kCallback] = callback;
4589
+ this[kIterator].all(options, this[kHandleMany]);
4590
+ };
4591
+ }
4592
+
4593
+ for (const Iterator of [AbstractSublevelValueIterator]) {
4594
+ Iterator.prototype._next = function (callback) {
4595
+ this[kIterator].next(callback);
4596
+ };
4597
+
4598
+ Iterator.prototype._nextv = function (size, options, callback) {
4599
+ this[kIterator].nextv(size, options, callback);
4600
+ };
4601
+
4602
+ Iterator.prototype._all = function (options, callback) {
4603
+ this[kIterator].all(options, callback);
4604
+ };
4605
+ }
4606
+
4607
+ for (const Iterator of [AbstractSublevelIterator, AbstractSublevelKeyIterator, AbstractSublevelValueIterator]) {
4608
+ Iterator.prototype._seek = function (target, options) {
4609
+ this[kIterator].seek(target, options);
4610
+ };
4611
+
4612
+ Iterator.prototype._close = function (callback) {
4613
+ this[kIterator].close(callback);
4614
+ };
4615
+ }
4616
+
4617
+ abstractSublevelIterator.AbstractSublevelIterator = AbstractSublevelIterator;
4618
+ abstractSublevelIterator.AbstractSublevelKeyIterator = AbstractSublevelKeyIterator;
4619
+ abstractSublevelIterator.AbstractSublevelValueIterator = AbstractSublevelValueIterator;
4620
+ return abstractSublevelIterator;
4621
+ }
4622
+
4623
+ var abstractSublevel;
4624
+ var hasRequiredAbstractSublevel;
4625
+
4626
+ function requireAbstractSublevel () {
4627
+ if (hasRequiredAbstractSublevel) return abstractSublevel;
4628
+ hasRequiredAbstractSublevel = 1;
4629
+
4630
+ const ModuleError = moduleError;
4631
+ const { Buffer } = buffer__WEBPACK_IMPORTED_MODULE_1__ || {};
4632
+ const {
4633
+ AbstractSublevelIterator,
4634
+ AbstractSublevelKeyIterator,
4635
+ AbstractSublevelValueIterator
4636
+ } = requireAbstractSublevelIterator();
4637
+
4638
+ const kPrefix = Symbol('prefix');
4639
+ const kUpperBound = Symbol('upperBound');
4640
+ const kPrefixRange = Symbol('prefixRange');
4641
+ const kParent = Symbol('parent');
4642
+ const kUnfix = Symbol('unfix');
4643
+
4644
+ const textEncoder = new TextEncoder();
4645
+ const defaults = { separator: '!' };
4646
+
4647
+ // Wrapped to avoid circular dependency
4648
+ abstractSublevel = function ({ AbstractLevel }) {
4649
+ class AbstractSublevel extends AbstractLevel {
4650
+ static defaults (options) {
4651
+ // To help migrating from subleveldown to abstract-level
4652
+ if (typeof options === 'string') {
4653
+ throw new ModuleError('The subleveldown string shorthand for { separator } has been removed', {
4654
+ code: 'LEVEL_LEGACY'
4655
+ })
4656
+ } else if (options && options.open) {
4657
+ throw new ModuleError('The subleveldown open option has been removed', {
4658
+ code: 'LEVEL_LEGACY'
4659
+ })
4660
+ }
4661
+
4662
+ if (options == null) {
4663
+ return defaults
4664
+ } else if (!options.separator) {
4665
+ return { ...options, separator: '!' }
4666
+ } else {
4667
+ return options
4668
+ }
4669
+ }
4670
+
4671
+ // TODO: add autoClose option, which if true, does parent.attachResource(this)
4672
+ constructor (db, name, options) {
4673
+ // Don't forward AbstractSublevel options to AbstractLevel
4674
+ const { separator, manifest, ...forward } = AbstractSublevel.defaults(options);
4675
+ name = trim(name, separator);
4676
+
4677
+ // Reserve one character between separator and name to give us an upper bound
4678
+ const reserved = separator.charCodeAt(0) + 1;
4679
+ const parent = db[kParent] || db;
4680
+
4681
+ // Keys should sort like ['!a!', '!a!!a!', '!a"', '!aa!', '!b!'].
4682
+ // Use ASCII for consistent length between string, Buffer and Uint8Array
4683
+ if (!textEncoder.encode(name).every(x => x > reserved && x < 127)) {
4684
+ throw new ModuleError(`Prefix must use bytes > ${reserved} < ${127}`, {
4685
+ code: 'LEVEL_INVALID_PREFIX'
4686
+ })
4687
+ }
4688
+
4689
+ super(mergeManifests(parent, manifest), forward);
4690
+
4691
+ const prefix = (db.prefix || '') + separator + name + separator;
4692
+ const upperBound = prefix.slice(0, -1) + String.fromCharCode(reserved);
4693
+
4694
+ this[kParent] = parent;
4695
+ this[kPrefix] = new MultiFormat(prefix);
4696
+ this[kUpperBound] = new MultiFormat(upperBound);
4697
+ this[kUnfix] = new Unfixer();
4698
+
4699
+ this.nextTick = parent.nextTick;
4700
+ }
4701
+
4702
+ prefixKey (key, keyFormat) {
4703
+ if (keyFormat === 'utf8') {
4704
+ return this[kPrefix].utf8 + key
4705
+ } else if (key.byteLength === 0) {
4706
+ // Fast path for empty key (no copy)
4707
+ return this[kPrefix][keyFormat]
4708
+ } else if (keyFormat === 'view') {
4709
+ const view = this[kPrefix].view;
4710
+ const result = new Uint8Array(view.byteLength + key.byteLength);
4711
+
4712
+ result.set(view, 0);
4713
+ result.set(key, view.byteLength);
4714
+
4715
+ return result
4716
+ } else {
4717
+ const buffer = this[kPrefix].buffer;
4718
+ return Buffer.concat([buffer, key], buffer.byteLength + key.byteLength)
4719
+ }
4720
+ }
4721
+
4722
+ // Not exposed for now.
4723
+ [kPrefixRange] (range, keyFormat) {
4724
+ if (range.gte !== undefined) {
4725
+ range.gte = this.prefixKey(range.gte, keyFormat);
4726
+ } else if (range.gt !== undefined) {
4727
+ range.gt = this.prefixKey(range.gt, keyFormat);
4728
+ } else {
4729
+ range.gte = this[kPrefix][keyFormat];
4730
+ }
4731
+
4732
+ if (range.lte !== undefined) {
4733
+ range.lte = this.prefixKey(range.lte, keyFormat);
4734
+ } else if (range.lt !== undefined) {
4735
+ range.lt = this.prefixKey(range.lt, keyFormat);
4736
+ } else {
4737
+ range.lte = this[kUpperBound][keyFormat];
4738
+ }
4739
+ }
4740
+
4741
+ get prefix () {
4742
+ return this[kPrefix].utf8
4743
+ }
4744
+
4745
+ get db () {
4746
+ return this[kParent]
4747
+ }
4748
+
4749
+ _open (options, callback) {
4750
+ // The parent db must open itself or be (re)opened by the user because
4751
+ // a sublevel should not initiate state changes on the rest of the db.
4752
+ this[kParent].open({ passive: true }, callback);
4753
+ }
4754
+
4755
+ _put (key, value, options, callback) {
4756
+ this[kParent].put(key, value, options, callback);
4757
+ }
4758
+
4759
+ _get (key, options, callback) {
4760
+ this[kParent].get(key, options, callback);
4761
+ }
4762
+
4763
+ _getMany (keys, options, callback) {
4764
+ this[kParent].getMany(keys, options, callback);
4765
+ }
4766
+
4767
+ _del (key, options, callback) {
4768
+ this[kParent].del(key, options, callback);
4769
+ }
4770
+
4771
+ _batch (operations, options, callback) {
4772
+ this[kParent].batch(operations, options, callback);
4773
+ }
4774
+
4775
+ _clear (options, callback) {
4776
+ // TODO (refactor): move to AbstractLevel
4777
+ this[kPrefixRange](options, options.keyEncoding);
4778
+ this[kParent].clear(options, callback);
4779
+ }
4780
+
4781
+ _iterator (options) {
4782
+ // TODO (refactor): move to AbstractLevel
4783
+ this[kPrefixRange](options, options.keyEncoding);
4784
+ const iterator = this[kParent].iterator(options);
4785
+ const unfix = this[kUnfix].get(this[kPrefix].utf8.length, options.keyEncoding);
4786
+ return new AbstractSublevelIterator(this, options, iterator, unfix)
4787
+ }
4788
+
4789
+ _keys (options) {
4790
+ this[kPrefixRange](options, options.keyEncoding);
4791
+ const iterator = this[kParent].keys(options);
4792
+ const unfix = this[kUnfix].get(this[kPrefix].utf8.length, options.keyEncoding);
4793
+ return new AbstractSublevelKeyIterator(this, options, iterator, unfix)
4794
+ }
4795
+
4796
+ _values (options) {
4797
+ this[kPrefixRange](options, options.keyEncoding);
4798
+ const iterator = this[kParent].values(options);
4799
+ return new AbstractSublevelValueIterator(this, options, iterator)
4800
+ }
4801
+ }
4802
+
4803
+ return { AbstractSublevel }
4804
+ };
4805
+
4806
+ const mergeManifests = function (parent, manifest) {
4807
+ return {
4808
+ // Inherit manifest of parent db
4809
+ ...parent.supports,
4810
+
4811
+ // Disable unsupported features
4812
+ createIfMissing: false,
4813
+ errorIfExists: false,
4814
+
4815
+ // Unset additional events because we're not forwarding them
4816
+ events: {},
4817
+
4818
+ // Unset additional methods (like approximateSize) which we can't support here unless
4819
+ // the AbstractSublevel class is overridden by an implementation of `abstract-level`.
4820
+ additionalMethods: {},
4821
+
4822
+ // Inherit manifest of custom AbstractSublevel subclass. Such a class is not
4823
+ // allowed to override encodings.
4824
+ ...manifest,
4825
+
4826
+ encodings: {
4827
+ utf8: supportsEncoding(parent, 'utf8'),
4828
+ buffer: supportsEncoding(parent, 'buffer'),
4829
+ view: supportsEncoding(parent, 'view')
4830
+ }
4831
+ }
4832
+ };
4833
+
4834
+ const supportsEncoding = function (parent, encoding) {
4835
+ // Prefer a non-transcoded encoding for optimal performance
4836
+ return parent.supports.encodings[encoding]
4837
+ ? parent.keyEncoding(encoding).name === encoding
4838
+ : false
4839
+ };
4840
+
4841
+ class MultiFormat {
4842
+ constructor (key) {
4843
+ this.utf8 = key;
4844
+ this.view = textEncoder.encode(key);
4845
+ this.buffer = Buffer ? Buffer.from(this.view.buffer, 0, this.view.byteLength) : {};
4846
+ }
4847
+ }
4848
+
4849
+ class Unfixer {
4850
+ constructor () {
4851
+ this.cache = new Map();
4852
+ }
4853
+
4854
+ get (prefixLength, keyFormat) {
4855
+ let unfix = this.cache.get(keyFormat);
4856
+
4857
+ if (unfix === undefined) {
4858
+ if (keyFormat === 'view') {
4859
+ unfix = function (prefixLength, key) {
4860
+ // Avoid Uint8Array#slice() because it copies
4861
+ return key.subarray(prefixLength)
4862
+ }.bind(null, prefixLength);
4863
+ } else {
4864
+ unfix = function (prefixLength, key) {
4865
+ // Avoid Buffer#subarray() because it's slow
4866
+ return key.slice(prefixLength)
4867
+ }.bind(null, prefixLength);
4868
+ }
4869
+
4870
+ this.cache.set(keyFormat, unfix);
4871
+ }
4872
+
4873
+ return unfix
4874
+ }
4875
+ }
4876
+
4877
+ const trim = function (str, char) {
4878
+ let start = 0;
4879
+ let end = str.length;
4880
+
4881
+ while (start < end && str[start] === char) start++;
4882
+ while (end > start && str[end - 1] === char) end--;
4883
+
4884
+ return str.slice(start, end)
4885
+ };
4886
+ return abstractSublevel;
4887
+ }
4888
+
4889
+ const { supports } = levelSupports;
4890
+ const { Transcoder } = levelTranscoder;
4891
+ const { EventEmitter } = (events__WEBPACK_IMPORTED_MODULE_2___default());
4892
+ const { fromCallback: fromCallback$1 } = catering;
4893
+ const ModuleError$1 = moduleError;
4894
+ const { AbstractIterator: AbstractIterator$1 } = abstractIterator;
4895
+ const { DefaultKeyIterator, DefaultValueIterator } = defaultKvIterator;
4896
+ const { DeferredIterator, DeferredKeyIterator, DeferredValueIterator } = deferredIterator;
4897
+ const { DefaultChainedBatch } = defaultChainedBatch;
4898
+ const { getCallback, getOptions } = common;
4899
+ const rangeOptions = rangeOptions_1;
4900
+
4901
+ const kPromise$1 = Symbol('promise');
4902
+ const kLanded = Symbol('landed');
4903
+ const kResources = Symbol('resources');
4904
+ const kCloseResources = Symbol('closeResources');
4905
+ const kOperations = Symbol('operations');
4906
+ const kUndefer = Symbol('undefer');
4907
+ const kDeferOpen = Symbol('deferOpen');
4908
+ const kOptions$1 = Symbol('options');
4909
+ const kStatus = Symbol('status');
4910
+ const kDefaultOptions = Symbol('defaultOptions');
4911
+ const kTranscoder = Symbol('transcoder');
4912
+ const kKeyEncoding = Symbol('keyEncoding');
4913
+ const kValueEncoding = Symbol('valueEncoding');
4914
+ const noop = () => {};
4915
+
4916
+ class AbstractLevel$1 extends EventEmitter {
4917
+ constructor (manifest, options) {
4918
+ super();
4919
+
4920
+ if (typeof manifest !== 'object' || manifest === null) {
4921
+ throw new TypeError("The first argument 'manifest' must be an object")
4922
+ }
4923
+
4924
+ options = getOptions(options);
4925
+ const { keyEncoding, valueEncoding, passive, ...forward } = options;
4926
+
4927
+ this[kResources] = new Set();
4928
+ this[kOperations] = [];
4929
+ this[kDeferOpen] = true;
4930
+ this[kOptions$1] = forward;
4931
+ this[kStatus] = 'opening';
4932
+
4933
+ this.supports = supports(manifest, {
4934
+ status: true,
4935
+ promises: true,
4936
+ clear: true,
4937
+ getMany: true,
4938
+ deferredOpen: true,
4939
+
4940
+ // TODO (next major): add seek
4941
+ snapshots: manifest.snapshots !== false,
4942
+ permanence: manifest.permanence !== false,
4943
+
4944
+ // TODO: remove from level-supports because it's always supported
4945
+ keyIterator: true,
4946
+ valueIterator: true,
4947
+ iteratorNextv: true,
4948
+ iteratorAll: true,
4949
+
4950
+ encodings: manifest.encodings || {},
4951
+ events: Object.assign({}, manifest.events, {
4952
+ opening: true,
4953
+ open: true,
4954
+ closing: true,
4955
+ closed: true,
4956
+ put: true,
4957
+ del: true,
4958
+ batch: true,
4959
+ clear: true
4960
+ })
4961
+ });
4962
+
4963
+ this[kTranscoder] = new Transcoder(formats(this));
4964
+ this[kKeyEncoding] = this[kTranscoder].encoding(keyEncoding || 'utf8');
4965
+ this[kValueEncoding] = this[kTranscoder].encoding(valueEncoding || 'utf8');
4966
+
4967
+ // Add custom and transcoder encodings to manifest
4968
+ for (const encoding of this[kTranscoder].encodings()) {
4969
+ if (!this.supports.encodings[encoding.commonName]) {
4970
+ this.supports.encodings[encoding.commonName] = true;
4971
+ }
4972
+ }
4973
+
4974
+ this[kDefaultOptions] = {
4975
+ empty: Object.freeze({}),
4976
+ entry: Object.freeze({
4977
+ keyEncoding: this[kKeyEncoding].commonName,
4978
+ valueEncoding: this[kValueEncoding].commonName
4979
+ }),
4980
+ key: Object.freeze({
4981
+ keyEncoding: this[kKeyEncoding].commonName
4982
+ })
4983
+ };
4984
+
4985
+ // Let subclass finish its constructor
4986
+ this.nextTick(() => {
4987
+ if (this[kDeferOpen]) {
4988
+ this.open({ passive: false }, noop);
4989
+ }
4990
+ });
4991
+ }
4992
+
4993
+ get status () {
4994
+ return this[kStatus]
4995
+ }
4996
+
4997
+ keyEncoding (encoding) {
4998
+ return this[kTranscoder].encoding(encoding != null ? encoding : this[kKeyEncoding])
4999
+ }
5000
+
5001
+ valueEncoding (encoding) {
5002
+ return this[kTranscoder].encoding(encoding != null ? encoding : this[kValueEncoding])
5003
+ }
5004
+
5005
+ open (options, callback) {
5006
+ callback = getCallback(options, callback);
5007
+ callback = fromCallback$1(callback, kPromise$1);
5008
+
5009
+ options = { ...this[kOptions$1], ...getOptions(options) };
5010
+
5011
+ options.createIfMissing = options.createIfMissing !== false;
5012
+ options.errorIfExists = !!options.errorIfExists;
5013
+
5014
+ const maybeOpened = (err) => {
5015
+ if (this[kStatus] === 'closing' || this[kStatus] === 'opening') {
5016
+ // Wait until pending state changes are done
5017
+ this.once(kLanded, err ? () => maybeOpened(err) : maybeOpened);
5018
+ } else if (this[kStatus] !== 'open') {
5019
+ callback(new ModuleError$1('Database is not open', {
5020
+ code: 'LEVEL_DATABASE_NOT_OPEN',
5021
+ cause: err
5022
+ }));
5023
+ } else {
5024
+ callback();
5025
+ }
5026
+ };
5027
+
5028
+ if (options.passive) {
5029
+ if (this[kStatus] === 'opening') {
5030
+ this.once(kLanded, maybeOpened);
5031
+ } else {
5032
+ this.nextTick(maybeOpened);
5033
+ }
5034
+ } else if (this[kStatus] === 'closed' || this[kDeferOpen]) {
5035
+ this[kDeferOpen] = false;
5036
+ this[kStatus] = 'opening';
5037
+ this.emit('opening');
5038
+
5039
+ this._open(options, (err) => {
5040
+ if (err) {
5041
+ this[kStatus] = 'closed';
5042
+
5043
+ // Resources must be safe to close in any db state
5044
+ this[kCloseResources](() => {
5045
+ this.emit(kLanded);
5046
+ maybeOpened(err);
5047
+ });
5048
+
5049
+ this[kUndefer]();
5050
+ return
5051
+ }
5052
+
5053
+ this[kStatus] = 'open';
5054
+ this[kUndefer]();
5055
+ this.emit(kLanded);
5056
+
5057
+ // Only emit public event if pending state changes are done
5058
+ if (this[kStatus] === 'open') this.emit('open');
5059
+
5060
+ // TODO (next major): remove this alias
5061
+ if (this[kStatus] === 'open') this.emit('ready');
5062
+
5063
+ maybeOpened();
5064
+ });
5065
+ } else if (this[kStatus] === 'open') {
5066
+ this.nextTick(maybeOpened);
5067
+ } else {
5068
+ this.once(kLanded, () => this.open(options, callback));
5069
+ }
5070
+
5071
+ return callback[kPromise$1]
5072
+ }
5073
+
5074
+ _open (options, callback) {
5075
+ this.nextTick(callback);
5076
+ }
5077
+
5078
+ close (callback) {
5079
+ callback = fromCallback$1(callback, kPromise$1);
5080
+
5081
+ const maybeClosed = (err) => {
5082
+ if (this[kStatus] === 'opening' || this[kStatus] === 'closing') {
5083
+ // Wait until pending state changes are done
5084
+ this.once(kLanded, err ? maybeClosed(err) : maybeClosed);
5085
+ } else if (this[kStatus] !== 'closed') {
5086
+ callback(new ModuleError$1('Database is not closed', {
5087
+ code: 'LEVEL_DATABASE_NOT_CLOSED',
5088
+ cause: err
5089
+ }));
5090
+ } else {
5091
+ callback();
5092
+ }
5093
+ };
5094
+
5095
+ if (this[kStatus] === 'open') {
5096
+ this[kStatus] = 'closing';
5097
+ this.emit('closing');
5098
+
5099
+ const cancel = (err) => {
5100
+ this[kStatus] = 'open';
5101
+ this[kUndefer]();
5102
+ this.emit(kLanded);
5103
+ maybeClosed(err);
5104
+ };
5105
+
5106
+ this[kCloseResources](() => {
5107
+ this._close((err) => {
5108
+ if (err) return cancel(err)
5109
+
5110
+ this[kStatus] = 'closed';
5111
+ this[kUndefer]();
5112
+ this.emit(kLanded);
5113
+
5114
+ // Only emit public event if pending state changes are done
5115
+ if (this[kStatus] === 'closed') this.emit('closed');
5116
+
5117
+ maybeClosed();
5118
+ });
5119
+ });
5120
+ } else if (this[kStatus] === 'closed') {
5121
+ this.nextTick(maybeClosed);
5122
+ } else {
5123
+ this.once(kLanded, () => this.close(callback));
5124
+ }
5125
+
5126
+ return callback[kPromise$1]
5127
+ }
5128
+
5129
+ [kCloseResources] (callback) {
5130
+ if (this[kResources].size === 0) {
5131
+ return this.nextTick(callback)
5132
+ }
5133
+
5134
+ let pending = this[kResources].size;
5135
+ let sync = true;
5136
+
5137
+ const next = () => {
5138
+ if (--pending === 0) {
5139
+ // We don't have tests for generic resources, so dezalgo
5140
+ if (sync) this.nextTick(callback);
5141
+ else callback();
5142
+ }
5143
+ };
5144
+
5145
+ // In parallel so that all resources know they are closed
5146
+ for (const resource of this[kResources]) {
5147
+ resource.close(next);
5148
+ }
5149
+
5150
+ sync = false;
5151
+ this[kResources].clear();
5152
+ }
5153
+
5154
+ _close (callback) {
5155
+ this.nextTick(callback);
5156
+ }
5157
+
5158
+ get (key, options, callback) {
5159
+ callback = getCallback(options, callback);
5160
+ callback = fromCallback$1(callback, kPromise$1);
5161
+ options = getOptions(options, this[kDefaultOptions].entry);
5162
+
5163
+ if (this[kStatus] === 'opening') {
5164
+ this.defer(() => this.get(key, options, callback));
5165
+ return callback[kPromise$1]
5166
+ }
5167
+
5168
+ if (maybeError(this, callback)) {
5169
+ return callback[kPromise$1]
5170
+ }
5171
+
5172
+ const err = this._checkKey(key);
5173
+
5174
+ if (err) {
5175
+ this.nextTick(callback, err);
5176
+ return callback[kPromise$1]
5177
+ }
5178
+
5179
+ const keyEncoding = this.keyEncoding(options.keyEncoding);
5180
+ const valueEncoding = this.valueEncoding(options.valueEncoding);
5181
+ const keyFormat = keyEncoding.format;
5182
+ const valueFormat = valueEncoding.format;
5183
+
5184
+ // Forward encoding options to the underlying store
5185
+ if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
5186
+ // Avoid spread operator because of https://bugs.chromium.org/p/chromium/issues/detail?id=1204540
5187
+ options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat });
5188
+ }
5189
+
5190
+ this._get(this.prefixKey(keyEncoding.encode(key), keyFormat), options, (err, value) => {
5191
+ if (err) {
5192
+ // Normalize not found error for backwards compatibility with abstract-leveldown and level(up)
5193
+ if (err.code === 'LEVEL_NOT_FOUND' || err.notFound || /NotFound/i.test(err)) {
5194
+ if (!err.code) err.code = 'LEVEL_NOT_FOUND'; // Preferred way going forward
5195
+ if (!err.notFound) err.notFound = true; // Same as level-errors
5196
+ if (!err.status) err.status = 404; // Same as level-errors
5197
+ }
5198
+
5199
+ return callback(err)
5200
+ }
5201
+
5202
+ try {
5203
+ value = valueEncoding.decode(value);
5204
+ } catch (err) {
5205
+ return callback(new ModuleError$1('Could not decode value', {
5206
+ code: 'LEVEL_DECODE_ERROR',
5207
+ cause: err
5208
+ }))
5209
+ }
5210
+
5211
+ callback(null, value);
5212
+ });
5213
+
5214
+ return callback[kPromise$1]
5215
+ }
5216
+
5217
+ _get (key, options, callback) {
5218
+ this.nextTick(callback, new Error('NotFound'));
5219
+ }
5220
+
5221
+ getMany (keys, options, callback) {
5222
+ callback = getCallback(options, callback);
5223
+ callback = fromCallback$1(callback, kPromise$1);
5224
+ options = getOptions(options, this[kDefaultOptions].entry);
5225
+
5226
+ if (this[kStatus] === 'opening') {
5227
+ this.defer(() => this.getMany(keys, options, callback));
5228
+ return callback[kPromise$1]
5229
+ }
5230
+
5231
+ if (maybeError(this, callback)) {
5232
+ return callback[kPromise$1]
5233
+ }
5234
+
5235
+ if (!Array.isArray(keys)) {
5236
+ this.nextTick(callback, new TypeError("The first argument 'keys' must be an array"));
5237
+ return callback[kPromise$1]
5238
+ }
5239
+
5240
+ if (keys.length === 0) {
5241
+ this.nextTick(callback, null, []);
5242
+ return callback[kPromise$1]
5243
+ }
5244
+
5245
+ const keyEncoding = this.keyEncoding(options.keyEncoding);
5246
+ const valueEncoding = this.valueEncoding(options.valueEncoding);
5247
+ const keyFormat = keyEncoding.format;
5248
+ const valueFormat = valueEncoding.format;
5249
+
5250
+ // Forward encoding options
5251
+ if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
5252
+ options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat });
5253
+ }
5254
+
5255
+ const mappedKeys = new Array(keys.length);
5256
+
5257
+ for (let i = 0; i < keys.length; i++) {
5258
+ const key = keys[i];
5259
+ const err = this._checkKey(key);
5260
+
5261
+ if (err) {
5262
+ this.nextTick(callback, err);
5263
+ return callback[kPromise$1]
5264
+ }
5265
+
5266
+ mappedKeys[i] = this.prefixKey(keyEncoding.encode(key), keyFormat);
5267
+ }
5268
+
5269
+ this._getMany(mappedKeys, options, (err, values) => {
5270
+ if (err) return callback(err)
5271
+
5272
+ try {
5273
+ for (let i = 0; i < values.length; i++) {
5274
+ if (values[i] !== undefined) {
5275
+ values[i] = valueEncoding.decode(values[i]);
5276
+ }
5277
+ }
5278
+ } catch (err) {
5279
+ return callback(new ModuleError$1(`Could not decode one or more of ${values.length} value(s)`, {
5280
+ code: 'LEVEL_DECODE_ERROR',
5281
+ cause: err
5282
+ }))
5283
+ }
5284
+
5285
+ callback(null, values);
5286
+ });
5287
+
5288
+ return callback[kPromise$1]
5289
+ }
5290
+
5291
+ _getMany (keys, options, callback) {
5292
+ this.nextTick(callback, null, new Array(keys.length).fill(undefined));
5293
+ }
5294
+
5295
+ put (key, value, options, callback) {
5296
+ callback = getCallback(options, callback);
5297
+ callback = fromCallback$1(callback, kPromise$1);
5298
+ options = getOptions(options, this[kDefaultOptions].entry);
5299
+
5300
+ if (this[kStatus] === 'opening') {
5301
+ this.defer(() => this.put(key, value, options, callback));
5302
+ return callback[kPromise$1]
5303
+ }
5304
+
5305
+ if (maybeError(this, callback)) {
5306
+ return callback[kPromise$1]
5307
+ }
5308
+
5309
+ const err = this._checkKey(key) || this._checkValue(value);
5310
+
5311
+ if (err) {
5312
+ this.nextTick(callback, err);
5313
+ return callback[kPromise$1]
5314
+ }
5315
+
5316
+ const keyEncoding = this.keyEncoding(options.keyEncoding);
5317
+ const valueEncoding = this.valueEncoding(options.valueEncoding);
5318
+ const keyFormat = keyEncoding.format;
5319
+ const valueFormat = valueEncoding.format;
5320
+
5321
+ // Forward encoding options
5322
+ if (options.keyEncoding !== keyFormat || options.valueEncoding !== valueFormat) {
5323
+ options = Object.assign({}, options, { keyEncoding: keyFormat, valueEncoding: valueFormat });
5324
+ }
5325
+
5326
+ const mappedKey = this.prefixKey(keyEncoding.encode(key), keyFormat);
5327
+ const mappedValue = valueEncoding.encode(value);
5328
+
5329
+ this._put(mappedKey, mappedValue, options, (err) => {
5330
+ if (err) return callback(err)
5331
+ this.emit('put', key, value);
5332
+ callback();
5333
+ });
5334
+
5335
+ return callback[kPromise$1]
5336
+ }
5337
+
5338
+ _put (key, value, options, callback) {
5339
+ this.nextTick(callback);
5340
+ }
5341
+
5342
+ del (key, options, callback) {
5343
+ callback = getCallback(options, callback);
5344
+ callback = fromCallback$1(callback, kPromise$1);
5345
+ options = getOptions(options, this[kDefaultOptions].key);
5346
+
5347
+ if (this[kStatus] === 'opening') {
5348
+ this.defer(() => this.del(key, options, callback));
5349
+ return callback[kPromise$1]
5350
+ }
5351
+
5352
+ if (maybeError(this, callback)) {
5353
+ return callback[kPromise$1]
5354
+ }
5355
+
5356
+ const err = this._checkKey(key);
5357
+
5358
+ if (err) {
5359
+ this.nextTick(callback, err);
5360
+ return callback[kPromise$1]
5361
+ }
5362
+
5363
+ const keyEncoding = this.keyEncoding(options.keyEncoding);
5364
+ const keyFormat = keyEncoding.format;
5365
+
5366
+ // Forward encoding options
5367
+ if (options.keyEncoding !== keyFormat) {
5368
+ options = Object.assign({}, options, { keyEncoding: keyFormat });
5369
+ }
5370
+
5371
+ this._del(this.prefixKey(keyEncoding.encode(key), keyFormat), options, (err) => {
5372
+ if (err) return callback(err)
5373
+ this.emit('del', key);
5374
+ callback();
5375
+ });
5376
+
5377
+ return callback[kPromise$1]
5378
+ }
5379
+
5380
+ _del (key, options, callback) {
5381
+ this.nextTick(callback);
5382
+ }
5383
+
5384
+ batch (operations, options, callback) {
5385
+ if (!arguments.length) {
5386
+ if (this[kStatus] === 'opening') return new DefaultChainedBatch(this)
5387
+ if (this[kStatus] !== 'open') {
5388
+ throw new ModuleError$1('Database is not open', {
5389
+ code: 'LEVEL_DATABASE_NOT_OPEN'
5390
+ })
5391
+ }
5392
+ return this._chainedBatch()
5393
+ }
5394
+
5395
+ if (typeof operations === 'function') callback = operations;
5396
+ else callback = getCallback(options, callback);
5397
+
5398
+ callback = fromCallback$1(callback, kPromise$1);
5399
+ options = getOptions(options, this[kDefaultOptions].empty);
5400
+
5401
+ if (this[kStatus] === 'opening') {
5402
+ this.defer(() => this.batch(operations, options, callback));
5403
+ return callback[kPromise$1]
5404
+ }
5405
+
5406
+ if (maybeError(this, callback)) {
5407
+ return callback[kPromise$1]
5408
+ }
5409
+
5410
+ if (!Array.isArray(operations)) {
5411
+ this.nextTick(callback, new TypeError("The first argument 'operations' must be an array"));
5412
+ return callback[kPromise$1]
5413
+ }
5414
+
5415
+ if (operations.length === 0) {
5416
+ this.nextTick(callback);
5417
+ return callback[kPromise$1]
5418
+ }
5419
+
5420
+ const mapped = new Array(operations.length);
5421
+ const { keyEncoding: ke, valueEncoding: ve, ...forward } = options;
5422
+
5423
+ for (let i = 0; i < operations.length; i++) {
5424
+ if (typeof operations[i] !== 'object' || operations[i] === null) {
5425
+ this.nextTick(callback, new TypeError('A batch operation must be an object'));
5426
+ return callback[kPromise$1]
5427
+ }
5428
+
5429
+ const op = Object.assign({}, operations[i]);
5430
+
5431
+ if (op.type !== 'put' && op.type !== 'del') {
5432
+ this.nextTick(callback, new TypeError("A batch operation must have a type property that is 'put' or 'del'"));
5433
+ return callback[kPromise$1]
5434
+ }
5435
+
5436
+ const err = this._checkKey(op.key);
5437
+
5438
+ if (err) {
5439
+ this.nextTick(callback, err);
5440
+ return callback[kPromise$1]
5441
+ }
5442
+
5443
+ const db = op.sublevel != null ? op.sublevel : this;
5444
+ const keyEncoding = db.keyEncoding(op.keyEncoding || ke);
5445
+ const keyFormat = keyEncoding.format;
5446
+
5447
+ op.key = db.prefixKey(keyEncoding.encode(op.key), keyFormat);
5448
+ op.keyEncoding = keyFormat;
5449
+
5450
+ if (op.type === 'put') {
5451
+ const valueErr = this._checkValue(op.value);
5452
+
5453
+ if (valueErr) {
5454
+ this.nextTick(callback, valueErr);
5455
+ return callback[kPromise$1]
5456
+ }
5457
+
5458
+ const valueEncoding = db.valueEncoding(op.valueEncoding || ve);
5459
+
5460
+ op.value = valueEncoding.encode(op.value);
5461
+ op.valueEncoding = valueEncoding.format;
5462
+ }
5463
+
5464
+ // Prevent double prefixing
5465
+ if (db !== this) {
5466
+ op.sublevel = null;
5467
+ }
5468
+
5469
+ mapped[i] = op;
5470
+ }
5471
+
5472
+ this._batch(mapped, forward, (err) => {
5473
+ if (err) return callback(err)
5474
+ this.emit('batch', operations);
5475
+ callback();
5476
+ });
5477
+
5478
+ return callback[kPromise$1]
5479
+ }
5480
+
5481
+ _batch (operations, options, callback) {
5482
+ this.nextTick(callback);
5483
+ }
5484
+
5485
+ sublevel (name, options) {
5486
+ return this._sublevel(name, AbstractSublevel.defaults(options))
5487
+ }
5488
+
5489
+ _sublevel (name, options) {
5490
+ return new AbstractSublevel(this, name, options)
5491
+ }
5492
+
5493
+ prefixKey (key, keyFormat) {
5494
+ return key
5495
+ }
5496
+
5497
+ clear (options, callback) {
5498
+ callback = getCallback(options, callback);
5499
+ callback = fromCallback$1(callback, kPromise$1);
5500
+ options = getOptions(options, this[kDefaultOptions].empty);
5501
+
5502
+ if (this[kStatus] === 'opening') {
5503
+ this.defer(() => this.clear(options, callback));
5504
+ return callback[kPromise$1]
5505
+ }
5506
+
5507
+ if (maybeError(this, callback)) {
5508
+ return callback[kPromise$1]
5509
+ }
5510
+
5511
+ const original = options;
5512
+ const keyEncoding = this.keyEncoding(options.keyEncoding);
5513
+
5514
+ options = rangeOptions(options, keyEncoding);
5515
+ options.keyEncoding = keyEncoding.format;
5516
+
5517
+ if (options.limit === 0) {
5518
+ this.nextTick(callback);
5519
+ } else {
5520
+ this._clear(options, (err) => {
5521
+ if (err) return callback(err)
5522
+ this.emit('clear', original);
5523
+ callback();
5524
+ });
5525
+ }
5526
+
5527
+ return callback[kPromise$1]
5528
+ }
5529
+
5530
+ _clear (options, callback) {
5531
+ this.nextTick(callback);
5532
+ }
5533
+
5534
+ iterator (options) {
5535
+ const keyEncoding = this.keyEncoding(options && options.keyEncoding);
5536
+ const valueEncoding = this.valueEncoding(options && options.valueEncoding);
5537
+
5538
+ options = rangeOptions(options, keyEncoding);
5539
+ options.keys = options.keys !== false;
5540
+ options.values = options.values !== false;
5541
+
5542
+ // We need the original encoding options in AbstractIterator in order to decode data
5543
+ options[AbstractIterator$1.keyEncoding] = keyEncoding;
5544
+ options[AbstractIterator$1.valueEncoding] = valueEncoding;
5545
+
5546
+ // Forward encoding options to private API
5547
+ options.keyEncoding = keyEncoding.format;
5548
+ options.valueEncoding = valueEncoding.format;
5549
+
5550
+ if (this[kStatus] === 'opening') {
5551
+ return new DeferredIterator(this, options)
5552
+ } else if (this[kStatus] !== 'open') {
5553
+ throw new ModuleError$1('Database is not open', {
5554
+ code: 'LEVEL_DATABASE_NOT_OPEN'
5555
+ })
5556
+ }
5557
+
5558
+ return this._iterator(options)
5559
+ }
5560
+
5561
+ _iterator (options) {
5562
+ return new AbstractIterator$1(this, options)
5563
+ }
5564
+
5565
+ keys (options) {
5566
+ // Also include valueEncoding (though unused) because we may fallback to _iterator()
5567
+ const keyEncoding = this.keyEncoding(options && options.keyEncoding);
5568
+ const valueEncoding = this.valueEncoding(options && options.valueEncoding);
5569
+
5570
+ options = rangeOptions(options, keyEncoding);
5571
+
5572
+ // We need the original encoding options in AbstractKeyIterator in order to decode data
5573
+ options[AbstractIterator$1.keyEncoding] = keyEncoding;
5574
+ options[AbstractIterator$1.valueEncoding] = valueEncoding;
5575
+
5576
+ // Forward encoding options to private API
5577
+ options.keyEncoding = keyEncoding.format;
5578
+ options.valueEncoding = valueEncoding.format;
5579
+
5580
+ if (this[kStatus] === 'opening') {
5581
+ return new DeferredKeyIterator(this, options)
5582
+ } else if (this[kStatus] !== 'open') {
5583
+ throw new ModuleError$1('Database is not open', {
5584
+ code: 'LEVEL_DATABASE_NOT_OPEN'
5585
+ })
5586
+ }
5587
+
5588
+ return this._keys(options)
5589
+ }
5590
+
5591
+ _keys (options) {
5592
+ return new DefaultKeyIterator(this, options)
5593
+ }
5594
+
5595
+ values (options) {
5596
+ const keyEncoding = this.keyEncoding(options && options.keyEncoding);
5597
+ const valueEncoding = this.valueEncoding(options && options.valueEncoding);
5598
+
5599
+ options = rangeOptions(options, keyEncoding);
5600
+
5601
+ // We need the original encoding options in AbstractValueIterator in order to decode data
5602
+ options[AbstractIterator$1.keyEncoding] = keyEncoding;
5603
+ options[AbstractIterator$1.valueEncoding] = valueEncoding;
5604
+
5605
+ // Forward encoding options to private API
5606
+ options.keyEncoding = keyEncoding.format;
5607
+ options.valueEncoding = valueEncoding.format;
5608
+
5609
+ if (this[kStatus] === 'opening') {
5610
+ return new DeferredValueIterator(this, options)
5611
+ } else if (this[kStatus] !== 'open') {
5612
+ throw new ModuleError$1('Database is not open', {
5613
+ code: 'LEVEL_DATABASE_NOT_OPEN'
5614
+ })
5615
+ }
5616
+
5617
+ return this._values(options)
5618
+ }
5619
+
5620
+ _values (options) {
5621
+ return new DefaultValueIterator(this, options)
5622
+ }
5623
+
5624
+ defer (fn) {
5625
+ if (typeof fn !== 'function') {
5626
+ throw new TypeError('The first argument must be a function')
5627
+ }
5628
+
5629
+ this[kOperations].push(fn);
5630
+ }
5631
+
5632
+ [kUndefer] () {
5633
+ if (this[kOperations].length === 0) {
5634
+ return
5635
+ }
5636
+
5637
+ const operations = this[kOperations];
5638
+ this[kOperations] = [];
5639
+
5640
+ for (const op of operations) {
5641
+ op();
5642
+ }
5643
+ }
5644
+
5645
+ // TODO: docs and types
5646
+ attachResource (resource) {
5647
+ if (typeof resource !== 'object' || resource === null ||
5648
+ typeof resource.close !== 'function') {
5649
+ throw new TypeError('The first argument must be a resource object')
5650
+ }
5651
+
5652
+ this[kResources].add(resource);
5653
+ }
5654
+
5655
+ // TODO: docs and types
5656
+ detachResource (resource) {
5657
+ this[kResources].delete(resource);
5658
+ }
5659
+
5660
+ _chainedBatch () {
5661
+ return new DefaultChainedBatch(this)
5662
+ }
5663
+
5664
+ _checkKey (key) {
5665
+ if (key === null || key === undefined) {
5666
+ return new ModuleError$1('Key cannot be null or undefined', {
5667
+ code: 'LEVEL_INVALID_KEY'
5668
+ })
5669
+ }
5670
+ }
5671
+
5672
+ _checkValue (value) {
5673
+ if (value === null || value === undefined) {
5674
+ return new ModuleError$1('Value cannot be null or undefined', {
5675
+ code: 'LEVEL_INVALID_VALUE'
5676
+ })
5677
+ }
5678
+ }
5679
+ }
5680
+
5681
+ // Expose browser-compatible nextTick for dependents
5682
+ // TODO: after we drop node 10, also use queueMicrotask in node
5683
+ AbstractLevel$1.prototype.nextTick = requireNextTick();
5684
+
5685
+ const { AbstractSublevel } = requireAbstractSublevel()({ AbstractLevel: AbstractLevel$1 });
5686
+
5687
+ abstractLevel.AbstractLevel = AbstractLevel$1;
5688
+ abstractLevel.AbstractSublevel = AbstractSublevel;
5689
+
5690
+ const maybeError = function (db, callback) {
5691
+ if (db[kStatus] !== 'open') {
5692
+ db.nextTick(callback, new ModuleError$1('Database is not open', {
5693
+ code: 'LEVEL_DATABASE_NOT_OPEN'
5694
+ }));
5695
+ return true
5696
+ }
5697
+
5698
+ return false
5699
+ };
5700
+
5701
+ const formats = function (db) {
5702
+ return Object.keys(db.supports.encodings)
5703
+ .filter(k => !!db.supports.encodings[k])
5704
+ };
5705
+
5706
+ abstractLevel$1.AbstractLevel = abstractLevel.AbstractLevel;
5707
+ abstractLevel$1.AbstractSublevel = abstractLevel.AbstractSublevel;
5708
+ abstractLevel$1.AbstractIterator = abstractIterator.AbstractIterator;
5709
+ abstractLevel$1.AbstractKeyIterator = abstractIterator.AbstractKeyIterator;
5710
+ abstractLevel$1.AbstractValueIterator = abstractIterator.AbstractValueIterator;
5711
+ abstractLevel$1.AbstractChainedBatch = abstractChainedBatch.AbstractChainedBatch;
5712
+
5713
+ /*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
5714
+
5715
+ let promise;
5716
+
5717
+ var queueMicrotask_1 = typeof queueMicrotask === 'function'
5718
+ ? queueMicrotask.bind(typeof window !== 'undefined' ? window : commonjsGlobal)
5719
+ // reuse resolved promise, and allocate it lazily
5720
+ : cb => (promise || (promise = Promise.resolve()))
5721
+ .then(cb)
5722
+ .catch(err => setTimeout(() => { throw err }, 0));
5723
+
5724
+ /*! run-parallel-limit. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
5725
+
5726
+ var runParallelLimit_1 = runParallelLimit;
5727
+
5728
+ const queueMicrotask$1 = queueMicrotask_1;
5729
+
5730
+ function runParallelLimit (tasks, limit, cb) {
5731
+ if (typeof limit !== 'number') throw new Error('second argument must be a Number')
5732
+ let results, len, pending, keys, isErrored;
5733
+ let isSync = true;
5734
+ let next;
5735
+
5736
+ if (Array.isArray(tasks)) {
5737
+ results = [];
5738
+ pending = len = tasks.length;
5739
+ } else {
5740
+ keys = Object.keys(tasks);
5741
+ results = {};
5742
+ pending = len = keys.length;
5743
+ }
5744
+
5745
+ function done (err) {
5746
+ function end () {
5747
+ if (cb) cb(err, results);
5748
+ cb = null;
5749
+ }
5750
+ if (isSync) queueMicrotask$1(end);
5751
+ else end();
5752
+ }
5753
+
5754
+ function each (i, err, result) {
5755
+ results[i] = result;
5756
+ if (err) isErrored = true;
5757
+ if (--pending === 0 || err) {
5758
+ done(err);
5759
+ } else if (!isErrored && next < len) {
5760
+ let key;
5761
+ if (keys) {
5762
+ key = keys[next];
5763
+ next += 1;
5764
+ tasks[key](function (err, result) { each(key, err, result); });
5765
+ } else {
5766
+ key = next;
5767
+ next += 1;
5768
+ tasks[key](function (err, result) { each(key, err, result); });
5769
+ }
5770
+ }
5771
+ }
5772
+
5773
+ next = limit;
5774
+ if (!pending) {
5775
+ // empty
5776
+ done(null);
5777
+ } else if (keys) {
5778
+ // object
5779
+ keys.some(function (key, i) {
5780
+ tasks[key](function (err, result) { each(key, err, result); });
5781
+ if (i === limit - 1) return true // early return
5782
+ return false
5783
+ });
5784
+ } else {
5785
+ // array
5786
+ tasks.some(function (task, i) {
5787
+ task(function (err, result) { each(i, err, result); });
5788
+ if (i === limit - 1) return true // early return
5789
+ return false
5790
+ });
5791
+ }
5792
+
5793
+ isSync = false;
5794
+ }
5795
+
5796
+ var iterator = {};
5797
+
5798
+ /* global IDBKeyRange */
5799
+
5800
+ var keyRange = function createKeyRange (options) {
5801
+ const lower = options.gte !== undefined ? options.gte : options.gt !== undefined ? options.gt : undefined;
5802
+ const upper = options.lte !== undefined ? options.lte : options.lt !== undefined ? options.lt : undefined;
5803
+ const lowerExclusive = options.gte === undefined;
5804
+ const upperExclusive = options.lte === undefined;
5805
+
5806
+ if (lower !== undefined && upper !== undefined) {
5807
+ return IDBKeyRange.bound(lower, upper, lowerExclusive, upperExclusive)
5808
+ } else if (lower !== undefined) {
5809
+ return IDBKeyRange.lowerBound(lower, lowerExclusive)
5810
+ } else if (upper !== undefined) {
5811
+ return IDBKeyRange.upperBound(upper, upperExclusive)
5812
+ } else {
5813
+ return null
5814
+ }
5815
+ };
5816
+
5817
+ const textEncoder = new TextEncoder();
5818
+
5819
+ var deserialize$2 = function (data) {
5820
+ if (data instanceof Uint8Array) {
5821
+ return data
5822
+ } else if (data instanceof ArrayBuffer) {
5823
+ return new Uint8Array(data)
5824
+ } else {
5825
+ // Non-binary data stored with an old version (level-js < 5.0.0)
5826
+ return textEncoder.encode(data)
5827
+ }
5828
+ };
5829
+
5830
+ const { AbstractIterator } = abstractLevel$1;
5831
+ const createKeyRange$1 = keyRange;
5832
+ const deserialize$1 = deserialize$2;
5833
+
5834
+ const kCache = Symbol('cache');
5835
+ const kFinished = Symbol('finished');
5836
+ const kOptions = Symbol('options');
5837
+ const kCurrentOptions = Symbol('currentOptions');
5838
+ const kPosition = Symbol('position');
5839
+ const kLocation$1 = Symbol('location');
5840
+ const kFirst = Symbol('first');
5841
+ const emptyOptions = {};
5842
+
5843
+ class Iterator$1 extends AbstractIterator {
5844
+ constructor (db, location, options) {
5845
+ super(db, options);
5846
+
5847
+ this[kCache] = [];
5848
+ this[kFinished] = this.limit === 0;
5849
+ this[kOptions] = options;
5850
+ this[kCurrentOptions] = { ...options };
5851
+ this[kPosition] = undefined;
5852
+ this[kLocation$1] = location;
5853
+ this[kFirst] = true;
5854
+ }
5855
+
5856
+ // Note: if called by _all() then size can be Infinity. This is an internal
5857
+ // detail; by design AbstractIterator.nextv() does not support Infinity.
5858
+ _nextv (size, options, callback) {
5859
+ this[kFirst] = false;
5860
+
5861
+ if (this[kFinished]) {
5862
+ return this.nextTick(callback, null, [])
5863
+ } else if (this[kCache].length > 0) {
5864
+ // TODO: mixing next and nextv is not covered by test suite
5865
+ size = Math.min(size, this[kCache].length);
5866
+ return this.nextTick(callback, null, this[kCache].splice(0, size))
5867
+ }
5868
+
5869
+ // Adjust range by what we already visited
5870
+ if (this[kPosition] !== undefined) {
5871
+ if (this[kOptions].reverse) {
5872
+ this[kCurrentOptions].lt = this[kPosition];
5873
+ this[kCurrentOptions].lte = undefined;
5874
+ } else {
5875
+ this[kCurrentOptions].gt = this[kPosition];
5876
+ this[kCurrentOptions].gte = undefined;
5877
+ }
5878
+ }
5879
+
5880
+ let keyRange;
5881
+
5882
+ try {
5883
+ keyRange = createKeyRange$1(this[kCurrentOptions]);
5884
+ } catch (_) {
5885
+ // The lower key is greater than the upper key.
5886
+ // IndexedDB throws an error, but we'll just return 0 results.
5887
+ this[kFinished] = true;
5888
+ return this.nextTick(callback, null, [])
5889
+ }
5890
+
5891
+ const transaction = this.db.db.transaction([this[kLocation$1]], 'readonly');
5892
+ const store = transaction.objectStore(this[kLocation$1]);
5893
+ const entries = [];
5894
+
5895
+ if (!this[kOptions].reverse) {
5896
+ let keys;
5897
+ let values;
5898
+
5899
+ const complete = () => {
5900
+ // Wait for both requests to complete
5901
+ if (keys === undefined || values === undefined) return
5902
+
5903
+ const length = Math.max(keys.length, values.length);
5904
+
5905
+ if (length === 0 || size === Infinity) {
5906
+ this[kFinished] = true;
5907
+ } else {
5908
+ this[kPosition] = keys[length - 1];
5909
+ }
5910
+
5911
+ // Resize
5912
+ entries.length = length;
5913
+
5914
+ // Merge keys and values
5915
+ for (let i = 0; i < length; i++) {
5916
+ const key = keys[i];
5917
+ const value = values[i];
5918
+
5919
+ entries[i] = [
5920
+ this[kOptions].keys && key !== undefined ? deserialize$1(key) : undefined,
5921
+ this[kOptions].values && value !== undefined ? deserialize$1(value) : undefined
5922
+ ];
5923
+ }
5924
+
5925
+ maybeCommit(transaction);
5926
+ };
5927
+
5928
+ // If keys were not requested and size is Infinity, we don't have to keep
5929
+ // track of position and can thus skip getting keys.
5930
+ if (this[kOptions].keys || size < Infinity) {
5931
+ store.getAllKeys(keyRange, size < Infinity ? size : undefined).onsuccess = (ev) => {
5932
+ keys = ev.target.result;
5933
+ complete();
5934
+ };
5935
+ } else {
5936
+ keys = [];
5937
+ this.nextTick(complete);
5938
+ }
5939
+
5940
+ if (this[kOptions].values) {
5941
+ store.getAll(keyRange, size < Infinity ? size : undefined).onsuccess = (ev) => {
5942
+ values = ev.target.result;
5943
+ complete();
5944
+ };
5945
+ } else {
5946
+ values = [];
5947
+ this.nextTick(complete);
5948
+ }
5949
+ } else {
5950
+ // Can't use getAll() in reverse, so use a slower cursor that yields one item at a time
5951
+ // TODO: test if all target browsers support openKeyCursor
5952
+ const method = !this[kOptions].values && store.openKeyCursor ? 'openKeyCursor' : 'openCursor';
5953
+
5954
+ store[method](keyRange, 'prev').onsuccess = (ev) => {
5955
+ const cursor = ev.target.result;
5956
+
5957
+ if (cursor) {
5958
+ const { key, value } = cursor;
5959
+ this[kPosition] = key;
5960
+
5961
+ entries.push([
5962
+ this[kOptions].keys && key !== undefined ? deserialize$1(key) : undefined,
5963
+ this[kOptions].values && value !== undefined ? deserialize$1(value) : undefined
5964
+ ]);
5965
+
5966
+ if (entries.length < size) {
5967
+ cursor.continue();
5968
+ } else {
5969
+ maybeCommit(transaction);
5970
+ }
5971
+ } else {
5972
+ this[kFinished] = true;
5973
+ }
5974
+ };
5975
+ }
5976
+
5977
+ // If an error occurs (on the request), the transaction will abort.
5978
+ transaction.onabort = () => {
5979
+ callback(transaction.error || new Error('aborted by user'));
5980
+ callback = null;
5981
+ };
5982
+
5983
+ transaction.oncomplete = () => {
5984
+ callback(null, entries);
5985
+ callback = null;
5986
+ };
5987
+ }
5988
+
5989
+ _next (callback) {
5990
+ if (this[kCache].length > 0) {
5991
+ const [key, value] = this[kCache].shift();
5992
+ this.nextTick(callback, null, key, value);
5993
+ } else if (this[kFinished]) {
5994
+ this.nextTick(callback);
5995
+ } else {
5996
+ let size = Math.min(100, this.limit - this.count);
5997
+
5998
+ if (this[kFirst]) {
5999
+ // It's common to only want one entry initially or after a seek()
6000
+ this[kFirst] = false;
6001
+ size = 1;
6002
+ }
6003
+
6004
+ this._nextv(size, emptyOptions, (err, entries) => {
6005
+ if (err) return callback(err)
6006
+ this[kCache] = entries;
6007
+ this._next(callback);
6008
+ });
6009
+ }
6010
+ }
6011
+
6012
+ _all (options, callback) {
6013
+ this[kFirst] = false;
6014
+
6015
+ // TODO: mixing next and all is not covered by test suite
6016
+ const cache = this[kCache].splice(0, this[kCache].length);
6017
+ const size = this.limit - this.count - cache.length;
6018
+
6019
+ if (size <= 0) {
6020
+ return this.nextTick(callback, null, cache)
6021
+ }
6022
+
6023
+ this._nextv(size, emptyOptions, (err, entries) => {
6024
+ if (err) return callback(err)
6025
+ if (cache.length > 0) entries = cache.concat(entries);
6026
+ callback(null, entries);
6027
+ });
6028
+ }
6029
+
6030
+ _seek (target, options) {
6031
+ this[kFirst] = true;
6032
+ this[kCache] = [];
6033
+ this[kFinished] = false;
6034
+ this[kPosition] = undefined;
6035
+
6036
+ // TODO: not covered by test suite
6037
+ this[kCurrentOptions] = { ...this[kOptions] };
6038
+
6039
+ let keyRange;
6040
+
6041
+ try {
6042
+ keyRange = createKeyRange$1(this[kOptions]);
6043
+ } catch (_) {
6044
+ this[kFinished] = true;
6045
+ return
6046
+ }
6047
+
6048
+ if (keyRange !== null && !keyRange.includes(target)) {
6049
+ this[kFinished] = true;
6050
+ } else if (this[kOptions].reverse) {
6051
+ this[kCurrentOptions].lte = target;
6052
+ } else {
6053
+ this[kCurrentOptions].gte = target;
6054
+ }
6055
+ }
6056
+ }
6057
+
6058
+ iterator.Iterator = Iterator$1;
6059
+
6060
+ function maybeCommit (transaction) {
6061
+ // Commit (meaning close) now instead of waiting for auto-commit
6062
+ if (typeof transaction.commit === 'function') {
6063
+ transaction.commit();
6064
+ }
6065
+ }
6066
+
6067
+ var clear$1 = function clear (db, location, keyRange, options, callback) {
6068
+ if (options.limit === 0) return db.nextTick(callback)
6069
+
6070
+ const transaction = db.db.transaction([location], 'readwrite');
6071
+ const store = transaction.objectStore(location);
6072
+ let count = 0;
6073
+
6074
+ transaction.oncomplete = function () {
6075
+ callback();
6076
+ };
6077
+
6078
+ transaction.onabort = function () {
6079
+ callback(transaction.error || new Error('aborted by user'));
6080
+ };
6081
+
6082
+ // A key cursor is faster (skips reading values) but not supported by IE
6083
+ // TODO: we no longer support IE. Test others
6084
+ const method = store.openKeyCursor ? 'openKeyCursor' : 'openCursor';
6085
+ const direction = options.reverse ? 'prev' : 'next';
6086
+
6087
+ store[method](keyRange, direction).onsuccess = function (ev) {
6088
+ const cursor = ev.target.result;
6089
+
6090
+ if (cursor) {
6091
+ // Wait for a request to complete before continuing, saving CPU.
6092
+ store.delete(cursor.key).onsuccess = function () {
6093
+ if (options.limit <= 0 || ++count < options.limit) {
6094
+ cursor.continue();
6095
+ }
6096
+ };
6097
+ }
6098
+ };
6099
+ };
6100
+
6101
+ /* global indexedDB */
6102
+
6103
+ const { AbstractLevel } = abstractLevel$1;
6104
+ const ModuleError = moduleError;
6105
+ const parallel = runParallelLimit_1;
6106
+ const { fromCallback } = catering;
6107
+ const { Iterator } = iterator;
6108
+ const deserialize = deserialize$2;
6109
+ const clear = clear$1;
6110
+ const createKeyRange = keyRange;
6111
+
6112
+ // Keep as-is for compatibility with existing level-js databases
6113
+ const DEFAULT_PREFIX = 'level-js-';
6114
+
6115
+ const kIDB = Symbol('idb');
6116
+ const kNamePrefix = Symbol('namePrefix');
6117
+ const kLocation = Symbol('location');
6118
+ const kVersion = Symbol('version');
6119
+ const kStore = Symbol('store');
6120
+ const kOnComplete = Symbol('onComplete');
6121
+ const kPromise = Symbol('promise');
6122
+
6123
+ class BrowserLevel extends AbstractLevel {
6124
+ constructor (location, options, _) {
6125
+ // To help migrating to abstract-level
6126
+ if (typeof options === 'function' || typeof _ === 'function') {
6127
+ throw new ModuleError('The levelup-style callback argument has been removed', {
6128
+ code: 'LEVEL_LEGACY'
6129
+ })
6130
+ }
6131
+
6132
+ const { prefix, version, ...forward } = options || {};
6133
+
6134
+ super({
6135
+ encodings: { view: true },
6136
+ snapshots: false,
6137
+ createIfMissing: false,
6138
+ errorIfExists: false,
6139
+ seek: true
6140
+ }, forward);
6141
+
6142
+ if (typeof location !== 'string') {
6143
+ throw new Error('constructor requires a location string argument')
6144
+ }
6145
+
6146
+ // TODO (next major): remove default prefix
6147
+ this[kLocation] = location;
6148
+ this[kNamePrefix] = prefix == null ? DEFAULT_PREFIX : prefix;
6149
+ this[kVersion] = parseInt(version || 1, 10);
6150
+ this[kIDB] = null;
6151
+ }
6152
+
6153
+ get location () {
6154
+ return this[kLocation]
6155
+ }
6156
+
6157
+ get namePrefix () {
6158
+ return this[kNamePrefix]
6159
+ }
6160
+
6161
+ get version () {
6162
+ return this[kVersion]
6163
+ }
6164
+
6165
+ // Exposed for backwards compat and unit tests
6166
+ get db () {
6167
+ return this[kIDB]
6168
+ }
6169
+
6170
+ get type () {
6171
+ return 'browser-level'
6172
+ }
6173
+
6174
+ _open (options, callback) {
6175
+ const req = indexedDB.open(this[kNamePrefix] + this[kLocation], this[kVersion]);
6176
+
6177
+ req.onerror = function () {
6178
+ callback(req.error || new Error('unknown error'));
6179
+ };
6180
+
6181
+ req.onsuccess = () => {
6182
+ this[kIDB] = req.result;
6183
+ callback();
6184
+ };
6185
+
6186
+ req.onupgradeneeded = (ev) => {
6187
+ const db = ev.target.result;
6188
+
6189
+ if (!db.objectStoreNames.contains(this[kLocation])) {
6190
+ db.createObjectStore(this[kLocation]);
6191
+ }
6192
+ };
6193
+ }
6194
+
6195
+ [kStore] (mode) {
6196
+ const transaction = this[kIDB].transaction([this[kLocation]], mode);
6197
+ return transaction.objectStore(this[kLocation])
6198
+ }
6199
+
6200
+ [kOnComplete] (request, callback) {
6201
+ const transaction = request.transaction;
6202
+
6203
+ // Take advantage of the fact that a non-canceled request error aborts
6204
+ // the transaction. I.e. no need to listen for "request.onerror".
6205
+ transaction.onabort = function () {
6206
+ callback(transaction.error || new Error('aborted by user'));
6207
+ };
6208
+
6209
+ transaction.oncomplete = function () {
6210
+ callback(null, request.result);
6211
+ };
6212
+ }
6213
+
6214
+ _get (key, options, callback) {
6215
+ const store = this[kStore]('readonly');
6216
+ let req;
6217
+
6218
+ try {
6219
+ req = store.get(key);
6220
+ } catch (err) {
6221
+ return this.nextTick(callback, err)
6222
+ }
6223
+
6224
+ this[kOnComplete](req, function (err, value) {
6225
+ if (err) return callback(err)
6226
+
6227
+ if (value === undefined) {
6228
+ return callback(new ModuleError('Entry not found', {
6229
+ code: 'LEVEL_NOT_FOUND'
6230
+ }))
6231
+ }
6232
+
6233
+ callback(null, deserialize(value));
6234
+ });
6235
+ }
6236
+
6237
+ _getMany (keys, options, callback) {
6238
+ const store = this[kStore]('readonly');
6239
+ const tasks = keys.map((key) => (next) => {
6240
+ let request;
6241
+
6242
+ try {
6243
+ request = store.get(key);
6244
+ } catch (err) {
6245
+ return next(err)
6246
+ }
6247
+
6248
+ request.onsuccess = () => {
6249
+ const value = request.result;
6250
+ next(null, value === undefined ? value : deserialize(value));
6251
+ };
6252
+
6253
+ request.onerror = (ev) => {
6254
+ ev.stopPropagation();
6255
+ next(request.error);
6256
+ };
2994
6257
  });
2995
- // Cache it for later retrieval.
2996
- transactionDoneMap.set(tx, done);
2997
- }
2998
- let idbProxyTraps = {
2999
- get(target, prop, receiver) {
3000
- if (target instanceof IDBTransaction) {
3001
- // Special handling for transaction.done.
3002
- if (prop === 'done')
3003
- return transactionDoneMap.get(target);
3004
- // Polyfill for objectStoreNames because of Edge.
3005
- if (prop === 'objectStoreNames') {
3006
- return target.objectStoreNames || transactionStoreNamesMap.get(target);
3007
- }
3008
- // Make tx.store return the only store in the transaction, or undefined if there are many.
3009
- if (prop === 'store') {
3010
- return receiver.objectStoreNames[1]
3011
- ? undefined
3012
- : receiver.objectStore(receiver.objectStoreNames[0]);
3013
- }
3014
- }
3015
- // Else transform whatever we get back.
3016
- return wrap(target[prop]);
3017
- },
3018
- set(target, prop, value) {
3019
- target[prop] = value;
3020
- return true;
3021
- },
3022
- has(target, prop) {
3023
- if (target instanceof IDBTransaction &&
3024
- (prop === 'done' || prop === 'store')) {
3025
- return true;
3026
- }
3027
- return prop in target;
3028
- },
3029
- };
3030
- function replaceTraps(callback) {
3031
- idbProxyTraps = callback(idbProxyTraps);
3032
- }
3033
- function wrapFunction(func) {
3034
- // Due to expected object equality (which is enforced by the caching in `wrap`), we
3035
- // only create one new func per func.
3036
- // Edge doesn't support objectStoreNames (booo), so we polyfill it here.
3037
- if (func === IDBDatabase.prototype.transaction &&
3038
- !('objectStoreNames' in IDBTransaction.prototype)) {
3039
- return function (storeNames, ...args) {
3040
- const tx = func.call(unwrap(this), storeNames, ...args);
3041
- transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
3042
- return wrap(tx);
3043
- };
6258
+
6259
+ parallel(tasks, 16, callback);
6260
+ }
6261
+
6262
+ _del (key, options, callback) {
6263
+ const store = this[kStore]('readwrite');
6264
+ let req;
6265
+
6266
+ try {
6267
+ req = store.delete(key);
6268
+ } catch (err) {
6269
+ return this.nextTick(callback, err)
3044
6270
  }
3045
- // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
3046
- // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
3047
- // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
3048
- // with real promises, so each advance methods returns a new promise for the cursor object, or
3049
- // undefined if the end of the cursor has been reached.
3050
- if (getCursorAdvanceMethods().includes(func)) {
3051
- return function (...args) {
3052
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3053
- // the original object.
3054
- func.apply(unwrap(this), args);
3055
- return wrap(cursorRequestMap.get(this));
3056
- };
6271
+
6272
+ this[kOnComplete](req, callback);
6273
+ }
6274
+
6275
+ _put (key, value, options, callback) {
6276
+ const store = this[kStore]('readwrite');
6277
+ let req;
6278
+
6279
+ try {
6280
+ // Will throw a DataError or DataCloneError if the environment
6281
+ // does not support serializing the key or value respectively.
6282
+ req = store.put(value, key);
6283
+ } catch (err) {
6284
+ return this.nextTick(callback, err)
3057
6285
  }
3058
- return function (...args) {
3059
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3060
- // the original object.
3061
- return wrap(func.apply(unwrap(this), args));
6286
+
6287
+ this[kOnComplete](req, callback);
6288
+ }
6289
+
6290
+ // TODO: implement key and value iterators
6291
+ _iterator (options) {
6292
+ return new Iterator(this, this[kLocation], options)
6293
+ }
6294
+
6295
+ _batch (operations, options, callback) {
6296
+ const store = this[kStore]('readwrite');
6297
+ const transaction = store.transaction;
6298
+ let index = 0;
6299
+ let error;
6300
+
6301
+ transaction.onabort = function () {
6302
+ callback(error || transaction.error || new Error('aborted by user'));
3062
6303
  };
3063
- }
3064
- function transformCachableValue(value) {
3065
- if (typeof value === 'function')
3066
- return wrapFunction(value);
3067
- // This doesn't return, it just creates a 'done' promise for the transaction,
3068
- // which is later returned for transaction.done (see idbObjectHandler).
3069
- if (value instanceof IDBTransaction)
3070
- cacheDonePromiseForTransaction(value);
3071
- if (instanceOfAny(value, getIdbProxyableTypes()))
3072
- return new Proxy(value, idbProxyTraps);
3073
- // Return the same value back if we're not going to transform it.
3074
- return value;
3075
- }
3076
- function wrap(value) {
3077
- // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
3078
- // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
3079
- if (value instanceof IDBRequest)
3080
- return promisifyRequest(value);
3081
- // If we've already transformed this value before, reuse the transformed value.
3082
- // This is faster, but it also provides object equality.
3083
- if (transformCache.has(value))
3084
- return transformCache.get(value);
3085
- const newValue = transformCachableValue(value);
3086
- // Not all types are transformed.
3087
- // These may be primitive types, so they can't be WeakMap keys.
3088
- if (newValue !== value) {
3089
- transformCache.set(value, newValue);
3090
- reverseTransformCache.set(newValue, value);
3091
- }
3092
- return newValue;
3093
- }
3094
- const unwrap = (value) => reverseTransformCache.get(value);
3095
6304
 
3096
- /**
3097
- * Open a database.
3098
- *
3099
- * @param name Name of the database.
3100
- * @param version Schema version.
3101
- * @param callbacks Additional callbacks.
3102
- */
3103
- function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
3104
- const request = indexedDB.open(name, version);
3105
- const openPromise = wrap(request);
3106
- if (upgrade) {
3107
- request.addEventListener('upgradeneeded', (event) => {
3108
- upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction));
3109
- });
6305
+ transaction.oncomplete = function () {
6306
+ callback();
6307
+ };
6308
+
6309
+ // Wait for a request to complete before making the next, saving CPU.
6310
+ function loop () {
6311
+ const op = operations[index++];
6312
+ const key = op.key;
6313
+
6314
+ let req;
6315
+
6316
+ try {
6317
+ req = op.type === 'del' ? store.delete(key) : store.put(op.value, key);
6318
+ } catch (err) {
6319
+ error = err;
6320
+ transaction.abort();
6321
+ return
6322
+ }
6323
+
6324
+ if (index < operations.length) {
6325
+ req.onsuccess = loop;
6326
+ } else if (typeof transaction.commit === 'function') {
6327
+ // Commit now instead of waiting for auto-commit
6328
+ transaction.commit();
6329
+ }
3110
6330
  }
3111
- if (blocked)
3112
- request.addEventListener('blocked', () => blocked());
3113
- openPromise
3114
- .then((db) => {
3115
- if (terminated)
3116
- db.addEventListener('close', () => terminated());
3117
- if (blocking)
3118
- db.addEventListener('versionchange', () => blocking());
3119
- })
3120
- .catch(() => { });
3121
- return openPromise;
3122
- }
3123
6331
 
3124
- const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
3125
- const writeMethods = ['put', 'add', 'delete', 'clear'];
3126
- const cachedMethods = new Map();
3127
- function getMethod(target, prop) {
3128
- if (!(target instanceof IDBDatabase &&
3129
- !(prop in target) &&
3130
- typeof prop === 'string')) {
3131
- return;
6332
+ loop();
6333
+ }
6334
+
6335
+ _clear (options, callback) {
6336
+ let keyRange;
6337
+ let req;
6338
+
6339
+ try {
6340
+ keyRange = createKeyRange(options);
6341
+ } catch (e) {
6342
+ // The lower key is greater than the upper key.
6343
+ // IndexedDB throws an error, but we'll just do nothing.
6344
+ return this.nextTick(callback)
3132
6345
  }
3133
- if (cachedMethods.get(prop))
3134
- return cachedMethods.get(prop);
3135
- const targetFuncName = prop.replace(/FromIndex$/, '');
3136
- const useIndex = prop !== targetFuncName;
3137
- const isWrite = writeMethods.includes(targetFuncName);
3138
- if (
3139
- // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
3140
- !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
3141
- !(isWrite || readMethods.includes(targetFuncName))) {
3142
- return;
6346
+
6347
+ if (options.limit >= 0) {
6348
+ // IDBObjectStore#delete(range) doesn't have such an option.
6349
+ // Fall back to cursor-based implementation.
6350
+ return clear(this, this[kLocation], keyRange, options, callback)
3143
6351
  }
3144
- const method = async function (storeName, ...args) {
3145
- // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
3146
- const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
3147
- let target = tx.store;
3148
- if (useIndex)
3149
- target = target.index(args.shift());
3150
- // Must reject if op rejects.
3151
- // If it's a write operation, must reject if tx.done rejects.
3152
- // Must reject with op rejection first.
3153
- // Must resolve with op value.
3154
- // Must handle both promises (no unhandled rejections)
3155
- return (await Promise.all([
3156
- target[targetFuncName](...args),
3157
- isWrite && tx.done,
3158
- ]))[0];
3159
- };
3160
- cachedMethods.set(prop, method);
3161
- return method;
6352
+
6353
+ try {
6354
+ const store = this[kStore]('readwrite');
6355
+ req = keyRange ? store.delete(keyRange) : store.clear();
6356
+ } catch (err) {
6357
+ return this.nextTick(callback, err)
6358
+ }
6359
+
6360
+ this[kOnComplete](req, callback);
6361
+ }
6362
+
6363
+ _close (callback) {
6364
+ this[kIDB].close();
6365
+ this.nextTick(callback);
6366
+ }
3162
6367
  }
3163
- replaceTraps((oldTraps) => ({
3164
- ...oldTraps,
3165
- get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
3166
- has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
3167
- }));
6368
+
6369
+ BrowserLevel.destroy = function (location, prefix, callback) {
6370
+ if (typeof prefix === 'function') {
6371
+ callback = prefix;
6372
+ prefix = DEFAULT_PREFIX;
6373
+ }
6374
+
6375
+ callback = fromCallback(callback, kPromise);
6376
+ const request = indexedDB.deleteDatabase(prefix + location);
6377
+
6378
+ request.onsuccess = function () {
6379
+ callback();
6380
+ };
6381
+
6382
+ request.onerror = function (err) {
6383
+ callback(err);
6384
+ };
6385
+
6386
+ return callback[kPromise]
6387
+ };
6388
+
6389
+ var BrowserLevel_1 = browserLevel.BrowserLevel = BrowserLevel;
6390
+
6391
+ var BrowserLevel$1 = /*#__PURE__*/_mergeNamespaces({
6392
+ __proto__: null,
6393
+ BrowserLevel: BrowserLevel_1,
6394
+ 'default': browserLevel
6395
+ }, [browserLevel]);
3168
6396
 
3169
6397
  class Store {
3170
- constructor(name = 'storage', root = '.leofcoin', version = 1) {
3171
- this.version = version;
6398
+ constructor(name = 'storage', root, version = 'v1.0.0') {
3172
6399
  this.name = name;
3173
6400
  this.root = root;
3174
- this.db = openDB(`${root}/${name}`, version, {
3175
- upgrade(db) {
3176
- db.createObjectStore(name);
3177
- }
3178
- });
6401
+ this.version = version;
6402
+
6403
+ this.db = new BrowserLevel$1(
6404
+ this.name,
6405
+ { valueEncoding: 'view'}
6406
+ );
3179
6407
  }
6408
+
3180
6409
  toKeyPath(key) {
3181
- return key.toString('base32')
6410
+ return key ? key.toString('base32') : key
3182
6411
  }
3183
-
6412
+
3184
6413
  toKeyValue(value) {
3185
6414
  return value.uint8Array
3186
6415
  }
3187
6416
 
3188
6417
  async get(key) {
3189
- return (await this.db).get(this.name, this.toKeyPath(key))
6418
+ return this.db.get(this.toKeyPath(key))
3190
6419
  }
3191
6420
 
3192
6421
  async put(key, value) {
3193
- return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key))
6422
+ return this.db.put(this.toKeyPath(key), this.toKeyValue(value))
3194
6423
  }
3195
6424
 
3196
6425
  async delete(key) {
3197
- return (await this.db).delete(this.name, this.toKeyPath(key))
6426
+ return this.db.del(this.toKeyPath(key))
3198
6427
  }
3199
6428
 
3200
6429
  async clear() {
3201
- return (await this.db).clear(this.name)
3202
- }
3203
-
3204
- async keys() {
3205
- return (await this.db).getAllKeys(this.name)
6430
+ return this.db.clear()
3206
6431
  }
3207
6432
 
3208
- async values() {
3209
- const keys = await this.keys();
3210
-
6433
+ async values(limit = -1) {
3211
6434
  const values = [];
3212
- for (const key of keys) {
3213
- values.push(this.db.get(key));
6435
+ for await (const value of this.db.values({limit})) {
6436
+ values.push(value);
3214
6437
  }
3215
- return Promise.all(values)
6438
+ return values
3216
6439
  }
3217
6440
 
6441
+ async keys(limit = -1) {
6442
+ const keys = [];
6443
+ for await (const key of this.db.keys({limit})) {
6444
+ keys.push(key);
6445
+ }
6446
+ return keys
6447
+ }
3218
6448
 
3219
6449
  }
3220
6450
 
@@ -3258,8 +6488,8 @@ class LeofcoinStorage {
3258
6488
  return this.db.delete(new KeyPath(key))
3259
6489
  }
3260
6490
 
3261
- keys() {
3262
- return this.db.keys()
6491
+ keys(limit = -1) {
6492
+ return this.db.keys({limit})
3263
6493
  }
3264
6494
 
3265
6495
  async #queryJob(key) {
@@ -3276,8 +6506,8 @@ class LeofcoinStorage {
3276
6506
  return Promise.all(promises)
3277
6507
  }
3278
6508
 
3279
- async values() {
3280
- return this.db.values()
6509
+ async values(limit = -1) {
6510
+ return this.db.values({limit})
3281
6511
  }
3282
6512
 
3283
6513
  async many(type, _value) {
@@ -7014,6 +10244,544 @@ Keccak.prototype.copy = function (dest) {
7014
10244
  module.exports = Keccak
7015
10245
 
7016
10246
 
10247
+ /***/ }),
10248
+
10249
+ /***/ 6470:
10250
+ /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
10251
+
10252
+ "use strict";
10253
+ /* provided dependency */ var process = __webpack_require__(4406);
10254
+ // 'path' module extracted from Node.js v8.11.1 (only the posix part)
10255
+ // transplited with Babel
10256
+
10257
+ // Copyright Joyent, Inc. and other Node contributors.
10258
+ //
10259
+ // Permission is hereby granted, free of charge, to any person obtaining a
10260
+ // copy of this software and associated documentation files (the
10261
+ // "Software"), to deal in the Software without restriction, including
10262
+ // without limitation the rights to use, copy, modify, merge, publish,
10263
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10264
+ // persons to whom the Software is furnished to do so, subject to the
10265
+ // following conditions:
10266
+ //
10267
+ // The above copyright notice and this permission notice shall be included
10268
+ // in all copies or substantial portions of the Software.
10269
+ //
10270
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
10271
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10272
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
10273
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
10274
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
10275
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
10276
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
10277
+
10278
+
10279
+
10280
+ function assertPath(path) {
10281
+ if (typeof path !== 'string') {
10282
+ throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
10283
+ }
10284
+ }
10285
+
10286
+ // Resolves . and .. elements in a path with directory names
10287
+ function normalizeStringPosix(path, allowAboveRoot) {
10288
+ var res = '';
10289
+ var lastSegmentLength = 0;
10290
+ var lastSlash = -1;
10291
+ var dots = 0;
10292
+ var code;
10293
+ for (var i = 0; i <= path.length; ++i) {
10294
+ if (i < path.length)
10295
+ code = path.charCodeAt(i);
10296
+ else if (code === 47 /*/*/)
10297
+ break;
10298
+ else
10299
+ code = 47 /*/*/;
10300
+ if (code === 47 /*/*/) {
10301
+ if (lastSlash === i - 1 || dots === 1) {
10302
+ // NOOP
10303
+ } else if (lastSlash !== i - 1 && dots === 2) {
10304
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
10305
+ if (res.length > 2) {
10306
+ var lastSlashIndex = res.lastIndexOf('/');
10307
+ if (lastSlashIndex !== res.length - 1) {
10308
+ if (lastSlashIndex === -1) {
10309
+ res = '';
10310
+ lastSegmentLength = 0;
10311
+ } else {
10312
+ res = res.slice(0, lastSlashIndex);
10313
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
10314
+ }
10315
+ lastSlash = i;
10316
+ dots = 0;
10317
+ continue;
10318
+ }
10319
+ } else if (res.length === 2 || res.length === 1) {
10320
+ res = '';
10321
+ lastSegmentLength = 0;
10322
+ lastSlash = i;
10323
+ dots = 0;
10324
+ continue;
10325
+ }
10326
+ }
10327
+ if (allowAboveRoot) {
10328
+ if (res.length > 0)
10329
+ res += '/..';
10330
+ else
10331
+ res = '..';
10332
+ lastSegmentLength = 2;
10333
+ }
10334
+ } else {
10335
+ if (res.length > 0)
10336
+ res += '/' + path.slice(lastSlash + 1, i);
10337
+ else
10338
+ res = path.slice(lastSlash + 1, i);
10339
+ lastSegmentLength = i - lastSlash - 1;
10340
+ }
10341
+ lastSlash = i;
10342
+ dots = 0;
10343
+ } else if (code === 46 /*.*/ && dots !== -1) {
10344
+ ++dots;
10345
+ } else {
10346
+ dots = -1;
10347
+ }
10348
+ }
10349
+ return res;
10350
+ }
10351
+
10352
+ function _format(sep, pathObject) {
10353
+ var dir = pathObject.dir || pathObject.root;
10354
+ var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
10355
+ if (!dir) {
10356
+ return base;
10357
+ }
10358
+ if (dir === pathObject.root) {
10359
+ return dir + base;
10360
+ }
10361
+ return dir + sep + base;
10362
+ }
10363
+
10364
+ var posix = {
10365
+ // path.resolve([from ...], to)
10366
+ resolve: function resolve() {
10367
+ var resolvedPath = '';
10368
+ var resolvedAbsolute = false;
10369
+ var cwd;
10370
+
10371
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
10372
+ var path;
10373
+ if (i >= 0)
10374
+ path = arguments[i];
10375
+ else {
10376
+ if (cwd === undefined)
10377
+ cwd = process.cwd();
10378
+ path = cwd;
10379
+ }
10380
+
10381
+ assertPath(path);
10382
+
10383
+ // Skip empty entries
10384
+ if (path.length === 0) {
10385
+ continue;
10386
+ }
10387
+
10388
+ resolvedPath = path + '/' + resolvedPath;
10389
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
10390
+ }
10391
+
10392
+ // At this point the path should be resolved to a full absolute path, but
10393
+ // handle relative paths to be safe (might happen when process.cwd() fails)
10394
+
10395
+ // Normalize the path
10396
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
10397
+
10398
+ if (resolvedAbsolute) {
10399
+ if (resolvedPath.length > 0)
10400
+ return '/' + resolvedPath;
10401
+ else
10402
+ return '/';
10403
+ } else if (resolvedPath.length > 0) {
10404
+ return resolvedPath;
10405
+ } else {
10406
+ return '.';
10407
+ }
10408
+ },
10409
+
10410
+ normalize: function normalize(path) {
10411
+ assertPath(path);
10412
+
10413
+ if (path.length === 0) return '.';
10414
+
10415
+ var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
10416
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
10417
+
10418
+ // Normalize the path
10419
+ path = normalizeStringPosix(path, !isAbsolute);
10420
+
10421
+ if (path.length === 0 && !isAbsolute) path = '.';
10422
+ if (path.length > 0 && trailingSeparator) path += '/';
10423
+
10424
+ if (isAbsolute) return '/' + path;
10425
+ return path;
10426
+ },
10427
+
10428
+ isAbsolute: function isAbsolute(path) {
10429
+ assertPath(path);
10430
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
10431
+ },
10432
+
10433
+ join: function join() {
10434
+ if (arguments.length === 0)
10435
+ return '.';
10436
+ var joined;
10437
+ for (var i = 0; i < arguments.length; ++i) {
10438
+ var arg = arguments[i];
10439
+ assertPath(arg);
10440
+ if (arg.length > 0) {
10441
+ if (joined === undefined)
10442
+ joined = arg;
10443
+ else
10444
+ joined += '/' + arg;
10445
+ }
10446
+ }
10447
+ if (joined === undefined)
10448
+ return '.';
10449
+ return posix.normalize(joined);
10450
+ },
10451
+
10452
+ relative: function relative(from, to) {
10453
+ assertPath(from);
10454
+ assertPath(to);
10455
+
10456
+ if (from === to) return '';
10457
+
10458
+ from = posix.resolve(from);
10459
+ to = posix.resolve(to);
10460
+
10461
+ if (from === to) return '';
10462
+
10463
+ // Trim any leading backslashes
10464
+ var fromStart = 1;
10465
+ for (; fromStart < from.length; ++fromStart) {
10466
+ if (from.charCodeAt(fromStart) !== 47 /*/*/)
10467
+ break;
10468
+ }
10469
+ var fromEnd = from.length;
10470
+ var fromLen = fromEnd - fromStart;
10471
+
10472
+ // Trim any leading backslashes
10473
+ var toStart = 1;
10474
+ for (; toStart < to.length; ++toStart) {
10475
+ if (to.charCodeAt(toStart) !== 47 /*/*/)
10476
+ break;
10477
+ }
10478
+ var toEnd = to.length;
10479
+ var toLen = toEnd - toStart;
10480
+
10481
+ // Compare paths to find the longest common path from root
10482
+ var length = fromLen < toLen ? fromLen : toLen;
10483
+ var lastCommonSep = -1;
10484
+ var i = 0;
10485
+ for (; i <= length; ++i) {
10486
+ if (i === length) {
10487
+ if (toLen > length) {
10488
+ if (to.charCodeAt(toStart + i) === 47 /*/*/) {
10489
+ // We get here if `from` is the exact base path for `to`.
10490
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
10491
+ return to.slice(toStart + i + 1);
10492
+ } else if (i === 0) {
10493
+ // We get here if `from` is the root
10494
+ // For example: from='/'; to='/foo'
10495
+ return to.slice(toStart + i);
10496
+ }
10497
+ } else if (fromLen > length) {
10498
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
10499
+ // We get here if `to` is the exact base path for `from`.
10500
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
10501
+ lastCommonSep = i;
10502
+ } else if (i === 0) {
10503
+ // We get here if `to` is the root.
10504
+ // For example: from='/foo'; to='/'
10505
+ lastCommonSep = 0;
10506
+ }
10507
+ }
10508
+ break;
10509
+ }
10510
+ var fromCode = from.charCodeAt(fromStart + i);
10511
+ var toCode = to.charCodeAt(toStart + i);
10512
+ if (fromCode !== toCode)
10513
+ break;
10514
+ else if (fromCode === 47 /*/*/)
10515
+ lastCommonSep = i;
10516
+ }
10517
+
10518
+ var out = '';
10519
+ // Generate the relative path based on the path difference between `to`
10520
+ // and `from`
10521
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
10522
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
10523
+ if (out.length === 0)
10524
+ out += '..';
10525
+ else
10526
+ out += '/..';
10527
+ }
10528
+ }
10529
+
10530
+ // Lastly, append the rest of the destination (`to`) path that comes after
10531
+ // the common path parts
10532
+ if (out.length > 0)
10533
+ return out + to.slice(toStart + lastCommonSep);
10534
+ else {
10535
+ toStart += lastCommonSep;
10536
+ if (to.charCodeAt(toStart) === 47 /*/*/)
10537
+ ++toStart;
10538
+ return to.slice(toStart);
10539
+ }
10540
+ },
10541
+
10542
+ _makeLong: function _makeLong(path) {
10543
+ return path;
10544
+ },
10545
+
10546
+ dirname: function dirname(path) {
10547
+ assertPath(path);
10548
+ if (path.length === 0) return '.';
10549
+ var code = path.charCodeAt(0);
10550
+ var hasRoot = code === 47 /*/*/;
10551
+ var end = -1;
10552
+ var matchedSlash = true;
10553
+ for (var i = path.length - 1; i >= 1; --i) {
10554
+ code = path.charCodeAt(i);
10555
+ if (code === 47 /*/*/) {
10556
+ if (!matchedSlash) {
10557
+ end = i;
10558
+ break;
10559
+ }
10560
+ } else {
10561
+ // We saw the first non-path separator
10562
+ matchedSlash = false;
10563
+ }
10564
+ }
10565
+
10566
+ if (end === -1) return hasRoot ? '/' : '.';
10567
+ if (hasRoot && end === 1) return '//';
10568
+ return path.slice(0, end);
10569
+ },
10570
+
10571
+ basename: function basename(path, ext) {
10572
+ if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
10573
+ assertPath(path);
10574
+
10575
+ var start = 0;
10576
+ var end = -1;
10577
+ var matchedSlash = true;
10578
+ var i;
10579
+
10580
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
10581
+ if (ext.length === path.length && ext === path) return '';
10582
+ var extIdx = ext.length - 1;
10583
+ var firstNonSlashEnd = -1;
10584
+ for (i = path.length - 1; i >= 0; --i) {
10585
+ var code = path.charCodeAt(i);
10586
+ if (code === 47 /*/*/) {
10587
+ // If we reached a path separator that was not part of a set of path
10588
+ // separators at the end of the string, stop now
10589
+ if (!matchedSlash) {
10590
+ start = i + 1;
10591
+ break;
10592
+ }
10593
+ } else {
10594
+ if (firstNonSlashEnd === -1) {
10595
+ // We saw the first non-path separator, remember this index in case
10596
+ // we need it if the extension ends up not matching
10597
+ matchedSlash = false;
10598
+ firstNonSlashEnd = i + 1;
10599
+ }
10600
+ if (extIdx >= 0) {
10601
+ // Try to match the explicit extension
10602
+ if (code === ext.charCodeAt(extIdx)) {
10603
+ if (--extIdx === -1) {
10604
+ // We matched the extension, so mark this as the end of our path
10605
+ // component
10606
+ end = i;
10607
+ }
10608
+ } else {
10609
+ // Extension does not match, so our result is the entire path
10610
+ // component
10611
+ extIdx = -1;
10612
+ end = firstNonSlashEnd;
10613
+ }
10614
+ }
10615
+ }
10616
+ }
10617
+
10618
+ if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
10619
+ return path.slice(start, end);
10620
+ } else {
10621
+ for (i = path.length - 1; i >= 0; --i) {
10622
+ if (path.charCodeAt(i) === 47 /*/*/) {
10623
+ // If we reached a path separator that was not part of a set of path
10624
+ // separators at the end of the string, stop now
10625
+ if (!matchedSlash) {
10626
+ start = i + 1;
10627
+ break;
10628
+ }
10629
+ } else if (end === -1) {
10630
+ // We saw the first non-path separator, mark this as the end of our
10631
+ // path component
10632
+ matchedSlash = false;
10633
+ end = i + 1;
10634
+ }
10635
+ }
10636
+
10637
+ if (end === -1) return '';
10638
+ return path.slice(start, end);
10639
+ }
10640
+ },
10641
+
10642
+ extname: function extname(path) {
10643
+ assertPath(path);
10644
+ var startDot = -1;
10645
+ var startPart = 0;
10646
+ var end = -1;
10647
+ var matchedSlash = true;
10648
+ // Track the state of characters (if any) we see before our first dot and
10649
+ // after any path separator we find
10650
+ var preDotState = 0;
10651
+ for (var i = path.length - 1; i >= 0; --i) {
10652
+ var code = path.charCodeAt(i);
10653
+ if (code === 47 /*/*/) {
10654
+ // If we reached a path separator that was not part of a set of path
10655
+ // separators at the end of the string, stop now
10656
+ if (!matchedSlash) {
10657
+ startPart = i + 1;
10658
+ break;
10659
+ }
10660
+ continue;
10661
+ }
10662
+ if (end === -1) {
10663
+ // We saw the first non-path separator, mark this as the end of our
10664
+ // extension
10665
+ matchedSlash = false;
10666
+ end = i + 1;
10667
+ }
10668
+ if (code === 46 /*.*/) {
10669
+ // If this is our first dot, mark it as the start of our extension
10670
+ if (startDot === -1)
10671
+ startDot = i;
10672
+ else if (preDotState !== 1)
10673
+ preDotState = 1;
10674
+ } else if (startDot !== -1) {
10675
+ // We saw a non-dot and non-path separator before our dot, so we should
10676
+ // have a good chance at having a non-empty extension
10677
+ preDotState = -1;
10678
+ }
10679
+ }
10680
+
10681
+ if (startDot === -1 || end === -1 ||
10682
+ // We saw a non-dot character immediately before the dot
10683
+ preDotState === 0 ||
10684
+ // The (right-most) trimmed path component is exactly '..'
10685
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
10686
+ return '';
10687
+ }
10688
+ return path.slice(startDot, end);
10689
+ },
10690
+
10691
+ format: function format(pathObject) {
10692
+ if (pathObject === null || typeof pathObject !== 'object') {
10693
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
10694
+ }
10695
+ return _format('/', pathObject);
10696
+ },
10697
+
10698
+ parse: function parse(path) {
10699
+ assertPath(path);
10700
+
10701
+ var ret = { root: '', dir: '', base: '', ext: '', name: '' };
10702
+ if (path.length === 0) return ret;
10703
+ var code = path.charCodeAt(0);
10704
+ var isAbsolute = code === 47 /*/*/;
10705
+ var start;
10706
+ if (isAbsolute) {
10707
+ ret.root = '/';
10708
+ start = 1;
10709
+ } else {
10710
+ start = 0;
10711
+ }
10712
+ var startDot = -1;
10713
+ var startPart = 0;
10714
+ var end = -1;
10715
+ var matchedSlash = true;
10716
+ var i = path.length - 1;
10717
+
10718
+ // Track the state of characters (if any) we see before our first dot and
10719
+ // after any path separator we find
10720
+ var preDotState = 0;
10721
+
10722
+ // Get non-dir info
10723
+ for (; i >= start; --i) {
10724
+ code = path.charCodeAt(i);
10725
+ if (code === 47 /*/*/) {
10726
+ // If we reached a path separator that was not part of a set of path
10727
+ // separators at the end of the string, stop now
10728
+ if (!matchedSlash) {
10729
+ startPart = i + 1;
10730
+ break;
10731
+ }
10732
+ continue;
10733
+ }
10734
+ if (end === -1) {
10735
+ // We saw the first non-path separator, mark this as the end of our
10736
+ // extension
10737
+ matchedSlash = false;
10738
+ end = i + 1;
10739
+ }
10740
+ if (code === 46 /*.*/) {
10741
+ // If this is our first dot, mark it as the start of our extension
10742
+ if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
10743
+ } else if (startDot !== -1) {
10744
+ // We saw a non-dot and non-path separator before our dot, so we should
10745
+ // have a good chance at having a non-empty extension
10746
+ preDotState = -1;
10747
+ }
10748
+ }
10749
+
10750
+ if (startDot === -1 || end === -1 ||
10751
+ // We saw a non-dot character immediately before the dot
10752
+ preDotState === 0 ||
10753
+ // The (right-most) trimmed path component is exactly '..'
10754
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
10755
+ if (end !== -1) {
10756
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
10757
+ }
10758
+ } else {
10759
+ if (startPart === 0 && isAbsolute) {
10760
+ ret.name = path.slice(1, startDot);
10761
+ ret.base = path.slice(1, end);
10762
+ } else {
10763
+ ret.name = path.slice(startPart, startDot);
10764
+ ret.base = path.slice(startPart, end);
10765
+ }
10766
+ ret.ext = path.slice(startDot, end);
10767
+ }
10768
+
10769
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
10770
+
10771
+ return ret;
10772
+ },
10773
+
10774
+ sep: '/',
10775
+ delimiter: ':',
10776
+ win32: null,
10777
+ posix: null
10778
+ };
10779
+
10780
+ posix.posix = posix;
10781
+
10782
+ module.exports = posix;
10783
+
10784
+
7017
10785
  /***/ }),
7018
10786
 
7019
10787
  /***/ 4281:
@@ -11095,6 +14863,18 @@ module.exports = {"version":"1.0.34"};
11095
14863
  /******/ __webpack_require__.m = __webpack_modules__;
11096
14864
  /******/
11097
14865
  /************************************************************************/
14866
+ /******/ /* webpack/runtime/compat get default export */
14867
+ /******/ !function() {
14868
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
14869
+ /******/ __webpack_require__.n = function(module) {
14870
+ /******/ var getter = module && module.__esModule ?
14871
+ /******/ function() { return module['default']; } :
14872
+ /******/ function() { return module; };
14873
+ /******/ __webpack_require__.d(getter, { a: getter });
14874
+ /******/ return getter;
14875
+ /******/ };
14876
+ /******/ }();
14877
+ /******/
11098
14878
  /******/ /* webpack/runtime/create fake namespace object */
11099
14879
  /******/ !function() {
11100
14880
  /******/ var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__; };