UNPKG

@trap_stevo/star-vault

Version:

Deterministic data engine that eliminates query-time joins and enables normalized data execution. Architect secure, scalable, real-time systems with integrated sharding, encryption, and event-driven data flows. Manage hierarchical structures, execute adva

639 lines (637 loc) 170 kB
"use strict"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); } function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); } function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); } function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; } function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } var _require = require("async_hooks"), AsyncLocalStorage = _require.AsyncLocalStorage; var path = require("path"); var fs = require("fs"); var ShardLockManager = require("../HUDManagers/ShardLockManager.js"); var AsyncMutex = require("./AsyncMutex.js"); var shardLockContext = new AsyncLocalStorage(); var PendingWrite = /*#__PURE__*/_createClass(function PendingWrite(buffer) { _classCallCheck(this, PendingWrite); this.promise = null; this.resolve = null; this.reject = null; this.filePath = null; this.offset = null; this.buffer = buffer; }); var _dbPath = /*#__PURE__*/new WeakMap(); var _shardCount = /*#__PURE__*/new WeakMap(); var _fileMode = /*#__PURE__*/new WeakMap(); var _dirMode = /*#__PURE__*/new WeakMap(); var _indexByCollection = /*#__PURE__*/new WeakMap(); var _pendingWritesByCollection = /*#__PURE__*/new WeakMap(); var _pendingCollections = /*#__PURE__*/new WeakMap(); var _collectionMatchCacheTTLms = /*#__PURE__*/new WeakMap(); var _collectionMatchCache = /*#__PURE__*/new WeakMap(); var _collectionsCacheTTLms = /*#__PURE__*/new WeakMap(); var _collectionsCache = /*#__PURE__*/new WeakMap(); var _knownCollections = /*#__PURE__*/new WeakMap(); var _collectionsEpoch = /*#__PURE__*/new WeakMap(); var _metaDir = /*#__PURE__*/new WeakMap(); var _compactionDir = /*#__PURE__*/new WeakMap(); var _metricsFile = /*#__PURE__*/new WeakMap(); var _countersDir = /*#__PURE__*/new WeakMap(); var _locksDir = /*#__PURE__*/new WeakMap(); var _compaction = /*#__PURE__*/new WeakMap(); var _metrics = /*#__PURE__*/new WeakMap(); var _metricsDirty = /*#__PURE__*/new WeakMap(); var _metricsDirtyCollections = /*#__PURE__*/new WeakMap(); var _metricsFlushTimer = /*#__PURE__*/new WeakMap(); var _lastMetricsFlushAt = /*#__PURE__*/new WeakMap(); var _metricsFlushIntervalMs = /*#__PURE__*/new WeakMap(); var _shardSizeCache = /*#__PURE__*/new WeakMap(); var _counters = /*#__PURE__*/new WeakMap(); var _opts = /*#__PURE__*/new WeakMap(); var _compactionEnabled = /*#__PURE__*/new WeakMap(); var _compactionIdleMs = /*#__PURE__*/new WeakMap(); var _compactionCooldownMs = /*#__PURE__*/new WeakMap(); var _compactionTickMs = /*#__PURE__*/new WeakMap(); var _compactionMaxCollectionsPerTick = /*#__PURE__*/new WeakMap(); var _compactionMaxShardsPerCollectionPerTick = /*#__PURE__*/new WeakMap(); var _compactionLastWriteAtByCollection = /*#__PURE__*/new WeakMap(); var _compactionLastCompactionAtByCollection = /*#__PURE__*/new WeakMap(); var _compactionPendingCollections = /*#__PURE__*/new WeakMap(); var _compactionTickTimer = /*#__PURE__*/new WeakMap(); var _fdCache = /*#__PURE__*/new WeakMap(); var _fdCacheMax = /*#__PURE__*/new WeakMap(); var _fdCacheTTLms = /*#__PURE__*/new WeakMap(); var _idxFdCache = /*#__PURE__*/new WeakMap(); var _idxFdCacheMax = /*#__PURE__*/new WeakMap(); var _idxFdCacheTTLms = /*#__PURE__*/new WeakMap(); var _idxLastCheckAtByShard = /*#__PURE__*/new WeakMap(); var _idxCheckIntervalMs = /*#__PURE__*/new WeakMap(); var _idxSizeCache = /*#__PURE__*/new WeakMap(); var _idxDirtyShards = /*#__PURE__*/new WeakMap(); var _idxDirtyPaths = /*#__PURE__*/new WeakMap(); var _idxFlushTimer = /*#__PURE__*/new WeakMap(); var _lastIDXFlushAt = /*#__PURE__*/new WeakMap(); var _idxFlushIntervalMs = /*#__PURE__*/new WeakMap(); var _idxSeenSizeByShard = /*#__PURE__*/new WeakMap(); var _idxResyncTimer = /*#__PURE__*/new WeakMap(); var _idxFsyncMode = /*#__PURE__*/new WeakMap(); var _fdReaperTimer = /*#__PURE__*/new WeakMap(); var _u = /*#__PURE__*/new WeakMap(); var _u2 = /*#__PURE__*/new WeakMap(); var _shardLockManager = /*#__PURE__*/new WeakMap(); var _mutexByShard = /*#__PURE__*/new WeakMap(); var _leaseStateByShardKey = /*#__PURE__*/new WeakMap(); var _debugStats = /*#__PURE__*/new WeakMap(); var _StorageEngine_brand = /*#__PURE__*/new WeakSet(); var StorageEngine = /*#__PURE__*/function () { function StorageEngine(dbPath) { var _this = this; var shardCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; _classCallCheck(this, StorageEngine); _classPrivateMethodInitSpec(this, _StorageEngine_brand); _classPrivateFieldInitSpec(this, _dbPath, void 0); _classPrivateFieldInitSpec(this, _shardCount, void 0); _classPrivateFieldInitSpec(this, _fileMode, void 0); _classPrivateFieldInitSpec(this, _dirMode, void 0); _classPrivateFieldInitSpec(this, _indexByCollection, void 0); _classPrivateFieldInitSpec(this, _pendingWritesByCollection, new Map()); _classPrivateFieldInitSpec(this, _pendingCollections, new Set()); _classPrivateFieldInitSpec(this, _collectionMatchCacheTTLms, void 0); _classPrivateFieldInitSpec(this, _collectionMatchCache, void 0); _classPrivateFieldInitSpec(this, _collectionsCacheTTLms, void 0); _classPrivateFieldInitSpec(this, _collectionsCache, void 0); _classPrivateFieldInitSpec(this, _knownCollections, void 0); _classPrivateFieldInitSpec(this, _collectionsEpoch, void 0); _classPrivateFieldInitSpec(this, _metaDir, void 0); _classPrivateFieldInitSpec(this, _compactionDir, void 0); _classPrivateFieldInitSpec(this, _metricsFile, void 0); _classPrivateFieldInitSpec(this, _countersDir, void 0); _classPrivateFieldInitSpec(this, _locksDir, void 0); _classPrivateFieldInitSpec(this, _compaction, void 0); _classPrivateFieldInitSpec(this, _metrics, void 0); _classPrivateFieldInitSpec(this, _metricsDirty, void 0); _classPrivateFieldInitSpec(this, _metricsDirtyCollections, void 0); _classPrivateFieldInitSpec(this, _metricsFlushTimer, void 0); _classPrivateFieldInitSpec(this, _lastMetricsFlushAt, void 0); _classPrivateFieldInitSpec(this, _metricsFlushIntervalMs, void 0); _classPrivateFieldInitSpec(this, _shardSizeCache, void 0); _classPrivateFieldInitSpec(this, _counters, void 0); _classPrivateFieldInitSpec(this, _opts, void 0); _classPrivateFieldInitSpec(this, _compactionEnabled, void 0); _classPrivateFieldInitSpec(this, _compactionIdleMs, void 0); _classPrivateFieldInitSpec(this, _compactionCooldownMs, void 0); _classPrivateFieldInitSpec(this, _compactionTickMs, void 0); _classPrivateFieldInitSpec(this, _compactionMaxCollectionsPerTick, void 0); _classPrivateFieldInitSpec(this, _compactionMaxShardsPerCollectionPerTick, void 0); _classPrivateFieldInitSpec(this, _compactionLastWriteAtByCollection, void 0); _classPrivateFieldInitSpec(this, _compactionLastCompactionAtByCollection, void 0); _classPrivateFieldInitSpec(this, _compactionPendingCollections, void 0); _classPrivateFieldInitSpec(this, _compactionTickTimer, void 0); _classPrivateFieldInitSpec(this, _fdCache, void 0); _classPrivateFieldInitSpec(this, _fdCacheMax, void 0); _classPrivateFieldInitSpec(this, _fdCacheTTLms, void 0); _classPrivateFieldInitSpec(this, _idxFdCache, void 0); _classPrivateFieldInitSpec(this, _idxFdCacheMax, void 0); _classPrivateFieldInitSpec(this, _idxFdCacheTTLms, void 0); _classPrivateFieldInitSpec(this, _idxLastCheckAtByShard, void 0); _classPrivateFieldInitSpec(this, _idxCheckIntervalMs, void 0); _classPrivateFieldInitSpec(this, _idxSizeCache, void 0); _classPrivateFieldInitSpec(this, _idxDirtyShards, void 0); _classPrivateFieldInitSpec(this, _idxDirtyPaths, void 0); _classPrivateFieldInitSpec(this, _idxFlushTimer, void 0); _classPrivateFieldInitSpec(this, _lastIDXFlushAt, void 0); _classPrivateFieldInitSpec(this, _idxFlushIntervalMs, void 0); _classPrivateFieldInitSpec(this, _idxSeenSizeByShard, void 0); _classPrivateFieldInitSpec(this, _idxResyncTimer, void 0); _classPrivateFieldInitSpec(this, _idxFsyncMode, void 0); _classPrivateFieldInitSpec(this, _fdReaperTimer, void 0); _classPrivateFieldInitSpec(this, _u, void 0); _classPrivateFieldInitSpec(this, _u2, void 0); _classPrivateFieldInitSpec(this, _shardLockManager, void 0); _classPrivateFieldInitSpec(this, _mutexByShard, void 0); _classPrivateFieldInitSpec(this, _leaseStateByShardKey, void 0); _classPrivateFieldInitSpec(this, _debugStats, void 0); var _options$dirMode = options.dirMode, _dirMode2 = _options$dirMode === void 0 ? 448 : _options$dirMode, _options$fileMode = options.fileMode, _fileMode2 = _options$fileMode === void 0 ? 384 : _options$fileMode; _classPrivateFieldSet(_dbPath, this, dbPath); _classPrivateFieldSet(_shardCount, this, shardCount); _classPrivateFieldSet(_fileMode, this, _fileMode2); _classPrivateFieldSet(_dirMode, this, _dirMode2); _classPrivateFieldSet(_opts, this, options); if (!fs.existsSync(dbPath)) { fs.mkdirSync(dbPath, { recursive: true, mode: _classPrivateFieldGet(_dirMode, this) }); } _classPrivateFieldSet(_indexByCollection, this, new Map()); _classPrivateFieldSet(_collectionMatchCacheTTLms, this, typeof _classPrivateFieldGet(_opts, this).collectionMatchCacheTTLms === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).collectionMatchCacheTTLms) ? Math.max(0, Math.floor(_classPrivateFieldGet(_opts, this).collectionMatchCacheTTLms)) : 1000); _classPrivateFieldSet(_collectionMatchCache, this, null); _classPrivateFieldSet(_collectionsCacheTTLms, this, typeof _classPrivateFieldGet(_opts, this).collectionsCacheTTLms === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).collectionsCacheTTLms) ? Math.max(0, Math.floor(_classPrivateFieldGet(_opts, this).collectionsCacheTTLms)) : 1000); _classPrivateFieldSet(_collectionsCache, this, null); _classPrivateFieldSet(_knownCollections, this, new Set()); _classPrivateFieldSet(_collectionsEpoch, this, 0); _classPrivateFieldSet(_debugStats, this, { listCollections: { calls: 0, cacheHits: 0, cacheMisses: 0, uncachedCalls: 0, uncachedMsTotal: 0, uncachedMsBest: Infinity, uncachedMsWorst: 0 }, getMatchingCollections: { calls: 0, cacheHits: 0, cacheMisses: 0 } }); _classPrivateFieldSet(_compaction, this, new Map()); _classPrivateFieldSet(_counters, this, new Map()); _classPrivateFieldSet(_metaDir, this, path.join(_classPrivateFieldGet(_dbPath, this), ".meta")); _classPrivateFieldSet(_compactionDir, this, path.join(_classPrivateFieldGet(_dbPath, this), ".compaction")); _assertClassBrand(_StorageEngine_brand, this, _ensureDir).call(this, _classPrivateFieldGet(_metaDir, this), _classPrivateFieldGet(_dirMode, this)); _assertClassBrand(_StorageEngine_brand, this, _ensureDir).call(this, _classPrivateFieldGet(_compactionDir, this), _classPrivateFieldGet(_dirMode, this)); _classPrivateFieldSet(_metricsFile, this, path.join(_classPrivateFieldGet(_metaDir, this), "metrics.json")); _classPrivateFieldSet(_countersDir, this, path.join(_classPrivateFieldGet(_metaDir, this), "counters")); _assertClassBrand(_StorageEngine_brand, this, _ensureDir).call(this, _classPrivateFieldGet(_countersDir, this), _classPrivateFieldGet(_dirMode, this)); _classPrivateFieldSet(_locksDir, this, path.join(_classPrivateFieldGet(_metaDir, this), "locks")); _assertClassBrand(_StorageEngine_brand, this, _ensureDir).call(this, _classPrivateFieldGet(_locksDir, this), _classPrivateFieldGet(_dirMode, this)); _classPrivateFieldSet(_shardLockManager, this, new ShardLockManager(_classPrivateFieldGet(_locksDir, this), { instanceId: typeof _classPrivateFieldGet(_opts, this).instanceId === "string" && _classPrivateFieldGet(_opts, this).instanceId ? _classPrivateFieldGet(_opts, this).instanceId : null, leaseTTLms: typeof _classPrivateFieldGet(_opts, this).leaseTTLms === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).leaseTTLms) ? Math.max(10, Math.floor(_classPrivateFieldGet(_opts, this).leaseTTLms)) : 250, retryDelayMs: typeof _classPrivateFieldGet(_opts, this).leaseRetryDelayMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).leaseRetryDelayMs) ? Math.max(0, Math.floor(_classPrivateFieldGet(_opts, this).leaseRetryDelayMs)) : 3 })); _classPrivateFieldSet(_mutexByShard, this, new Map()); _classPrivateFieldSet(_leaseStateByShardKey, this, new Map()); _classPrivateFieldSet(_fdCache, this, new Map()); _classPrivateFieldSet(_fdCacheMax, this, typeof _classPrivateFieldGet(_opts, this).fdCacheMax === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).fdCacheMax) ? Math.max(8, Math.floor(_classPrivateFieldGet(_opts, this).fdCacheMax)) : 128); _classPrivateFieldSet(_fdCacheTTLms, this, typeof _classPrivateFieldGet(_opts, this).fdCacheTTLms === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).fdCacheTTLms) ? Math.max(25, Math.floor(_classPrivateFieldGet(_opts, this).fdCacheTTLms)) : 30000); _classPrivateFieldSet(_idxFdCache, this, new Map()); _classPrivateFieldSet(_idxFdCacheMax, this, typeof _classPrivateFieldGet(_opts, this).idxFdCacheMax === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).idxFdCacheMax) ? Math.max(8, Math.floor(_classPrivateFieldGet(_opts, this).idxFdCacheMax)) : 128); _classPrivateFieldSet(_idxFdCacheTTLms, this, typeof _classPrivateFieldGet(_opts, this).idxFdCacheTTLms === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).idxFdCacheTTLms) ? Math.max(25, Math.floor(_classPrivateFieldGet(_opts, this).idxFdCacheTTLms)) : 30000); _classPrivateFieldSet(_idxLastCheckAtByShard, this, new Map()); _classPrivateFieldSet(_idxCheckIntervalMs, this, 25); _classPrivateFieldSet(_idxSizeCache, this, new Map()); _classPrivateFieldSet(_idxSeenSizeByShard, this, new Map()); _classPrivateFieldSet(_idxDirtyShards, this, new Set()); _classPrivateFieldSet(_idxDirtyPaths, this, new Set()); _classPrivateFieldSet(_idxFlushTimer, this, null); _classPrivateFieldSet(_lastIDXFlushAt, this, 0); _classPrivateFieldSet(_idxFlushIntervalMs, this, typeof _classPrivateFieldGet(_opts, this).idxFlushIntervalMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).idxFlushIntervalMs) ? Math.max(10, Math.floor(_classPrivateFieldGet(_opts, this).idxFlushIntervalMs)) : 50); _classPrivateFieldSet(_idxFsyncMode, this, typeof _classPrivateFieldGet(_opts, this).idxSyncMode === "string" ? String(_classPrivateFieldGet(_opts, this).idxSyncMode) : "interval"); _classPrivateFieldSet(_u, this, Buffer.alloc(4)); _classPrivateFieldSet(_u2, this, Buffer.alloc(8)); this.loadIndexes(); var loadedMetrics = _assertClassBrand(_StorageEngine_brand, this, _readJSON).call(this, _classPrivateFieldGet(_metricsFile, this)); if (loadedMetrics && loadedMetrics.collections) { _classPrivateFieldSet(_metrics, this, { collections: new Map(Object.entries(loadedMetrics.collections)) }); } else { _classPrivateFieldSet(_metrics, this, { collections: new Map() }); } _classPrivateFieldSet(_metricsDirty, this, false); _classPrivateFieldSet(_metricsDirtyCollections, this, new Set()); _classPrivateFieldSet(_metricsFlushTimer, this, null); _classPrivateFieldSet(_lastMetricsFlushAt, this, 0); _classPrivateFieldSet(_metricsFlushIntervalMs, this, typeof _classPrivateFieldGet(_opts, this).metricsFlushIntervalMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).metricsFlushIntervalMs) ? Math.max(10, Math.floor(_classPrivateFieldGet(_opts, this).metricsFlushIntervalMs)) : 50); _classPrivateFieldSet(_shardSizeCache, this, new Map()); _assertClassBrand(_StorageEngine_brand, this, _recoverCompactionResidues).call(this); try { var _iterator = _createForOfIteratorHelper(_assertClassBrand(_StorageEngine_brand, this, _listCollectionsUncached).call(this, _classPrivateFieldGet(_dbPath, this), "")), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var collection = _step.value; _assertClassBrand(_StorageEngine_brand, this, _refreshFileBytes).call(this, collection); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } catch (_unused) {} _classPrivateFieldSet(_compactionEnabled, this, _classPrivateFieldGet(_opts, this).compactionEnabled !== false); _classPrivateFieldSet(_compactionIdleMs, this, typeof _classPrivateFieldGet(_opts, this).compactionIdleMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).compactionIdleMs) ? Math.max(50, Math.floor(_classPrivateFieldGet(_opts, this).compactionIdleMs)) : 2500); _classPrivateFieldSet(_compactionCooldownMs, this, typeof _classPrivateFieldGet(_opts, this).compactionCooldownMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).compactionCooldownMs) ? Math.max(0, Math.floor(_classPrivateFieldGet(_opts, this).compactionCooldownMs)) : 60000); _classPrivateFieldSet(_compactionTickMs, this, typeof _classPrivateFieldGet(_opts, this).compactionTickMs === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).compactionTickMs) ? Math.max(25, Math.floor(_classPrivateFieldGet(_opts, this).compactionTickMs)) : 200); _classPrivateFieldSet(_compactionMaxCollectionsPerTick, this, typeof _classPrivateFieldGet(_opts, this).compactionMaxCollectionsPerTick === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).compactionMaxCollectionsPerTick) ? Math.max(1, Math.floor(_classPrivateFieldGet(_opts, this).compactionMaxCollectionsPerTick)) : 1); _classPrivateFieldSet(_compactionMaxShardsPerCollectionPerTick, this, typeof _classPrivateFieldGet(_opts, this).compactionMaxShardsPerCollectionPerTick === "number" && Number.isFinite(_classPrivateFieldGet(_opts, this).compactionMaxShardsPerCollectionPerTick) ? Math.max(1, Math.floor(_classPrivateFieldGet(_opts, this).compactionMaxShardsPerCollectionPerTick)) : 1); _classPrivateFieldSet(_compactionLastWriteAtByCollection, this, new Map()); _classPrivateFieldSet(_compactionLastCompactionAtByCollection, this, new Map()); _classPrivateFieldSet(_compactionPendingCollections, this, new Set()); _classPrivateFieldSet(_compactionTickTimer, this, null); if (_classPrivateFieldGet(_compactionEnabled, this) === true) { _assertClassBrand(_StorageEngine_brand, this, _scheduleCompactionTick).call(this); } _classPrivateFieldSet(_idxResyncTimer, this, setInterval(function () { try { var batch = Array.from(_classPrivateFieldGet(_idxDirtyShards, _this).values()); _classPrivateFieldGet(_idxDirtyShards, _this).clear(); for (var _i = 0, _batch = batch; _i < _batch.length; _i++) { var shardKey = _batch[_i]; var parts = String(shardKey).split("::"); var _collection = parts[0]; var shard = Number(parts[1]); _assertClassBrand(_StorageEngine_brand, _this, _tailSyncIDXIntoMaps).call(_this, _collection, shard); } } catch (_unused2) {} }, 250)); try { _classPrivateFieldGet(_idxResyncTimer, this).unref(); } catch (_unused3) {} _classPrivateFieldSet(_fdReaperTimer, this, setInterval(function () { try { _assertClassBrand(_StorageEngine_brand, _this, _releaseFDsNow).call(_this); } catch (_unused4) {} try { _assertClassBrand(_StorageEngine_brand, _this, _releaseIDXFDsNow).call(_this); } catch (_unused5) {} }, Math.max(50, Math.floor(Math.min(_classPrivateFieldGet(_fdCacheTTLms, this), _classPrivateFieldGet(_idxFdCacheTTLms, this)) / 2)))); try { _classPrivateFieldGet(_fdReaperTimer, this).unref(); } catch (_unused6) {} } return _createClass(StorageEngine, [{ key: "getShardFile", value: function getShardFile(collection, shard) { return path.join(_classPrivateFieldGet(_dbPath, this), "".concat(collection, "_shard_").concat(shard, ".ldb")); } }, { key: "getIndexFile", value: function getIndexFile(collection, shard) { return path.join(_classPrivateFieldGet(_dbPath, this), "".concat(collection, "_shard_").concat(shard, ".idx")); } }, { key: "getShardID", value: function getShardID(id) { var _classPrivateFieldGet2; if (typeof id === "number" && Number.isFinite(id)) { return Math.abs(id) % _classPrivateFieldGet(_shardCount, this); } if ((_classPrivateFieldGet2 = _classPrivateFieldGet(_opts, this)) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.shardHashFn) { var _h = _classPrivateFieldGet(_opts, this).shardHashFn(String(id)); return (_h >>> 0) % _classPrivateFieldGet(_shardCount, this); } var s = String(id); if (s.length <= 8 && /^[0-9a-z]+$/i.test(s)) { var n = parseInt(s, 36); if (Number.isFinite(n)) { return n % _classPrivateFieldGet(_shardCount, this); } } var h = 2166136261; for (var i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); } return (h >>> 0) % _classPrivateFieldGet(_shardCount, this); } }, { key: "write", value: function () { var _write = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(collection, id, value) { var _this2 = this; var shard, shardKey, colPending, valueBuffer, pw; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: shard = this.getShardID(id); shardKey = "".concat(collection, "::").concat(shard); colPending = _classPrivateFieldGet(_pendingWritesByCollection, this).get(collection); if (!colPending) { colPending = new Map(); _classPrivateFieldGet(_pendingWritesByCollection, this).set(collection, colPending); } _context2.prev = 4; valueBuffer = Buffer.from(JSON.stringify(value)); _context2.next = 12; break; case 8: _context2.prev = 8; _context2.t0 = _context2["catch"](4); if (typeof _classPrivateFieldGet(_opts, this).onWriteError === "function") { _classPrivateFieldGet(_opts, this).onWriteError(_context2.t0, { collection: collection, id: id, value: value }); } return _context2.abrupt("return", { id: id, error: "serialization_failed" }); case 12: pw = new PendingWrite(valueBuffer); pw.promise = new Promise(function (resolve, reject) { pw.resolve = resolve; pw.reject = reject; }); colPending.set(String(id), pw); _classPrivateFieldGet(_pendingCollections, this).add(collection); _assertClassBrand(_StorageEngine_brand, this, _invalidateCollectionsCache).call(this); return _context2.abrupt("return", _assertClassBrand(_StorageEngine_brand, this, _withShardLeaseLock).call(this, shardKey, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { var _c$shards, prevPointer, prevLen, m, filePath, indexPath, knownCollection, appendRes, offset, appendedBytes, pendingNow, pw2, c, shardState, _pendingNow, _pw; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.prev = 0; _assertClassBrand(_StorageEngine_brand, _this2, _noteWriteActivity).call(_this2, collection); prevPointer = _assertClassBrand(_StorageEngine_brand, _this2, _getPointer).call(_this2, collection, id); prevLen = prevPointer ? _assertClassBrand(_StorageEngine_brand, _this2, _readValueLength).call(_this2, prevPointer.filePath, prevPointer.offset) : 0; m = _classPrivateFieldGet(_metrics, _this2).collections.get(collection) || { fileBytes: 0, liveBytes: 0, updates: 0, lastVacuumAt: 0 }; m.liveBytes += Math.max(0, valueBuffer.length - prevLen); m.updates += 1; _classPrivateFieldGet(_metrics, _this2).collections.set(collection, m); filePath = _this2.getShardFile(collection, shard); indexPath = _this2.getIndexFile(collection, shard); knownCollection = _classPrivateFieldGet(_knownCollections, _this2).has(String(collection)); appendRes = _assertClassBrand(_StorageEngine_brand, _this2, _appendRecord).call(_this2, filePath, indexPath, id, valueBuffer, { updateIndexMap: true, collection: collection }); if (knownCollection !== true) { _classPrivateFieldGet(_knownCollections, _this2).add(String(collection)); _assertClassBrand(_StorageEngine_brand, _this2, _invalidateCollectionsCache).call(_this2); } offset = appendRes && typeof appendRes.offset === "number" ? appendRes.offset : 0; appendedBytes = appendRes && typeof appendRes.bytes === "number" ? appendRes.bytes : 0; m.fileBytes = (m.fileBytes || 0) + appendedBytes; _classPrivateFieldGet(_metrics, _this2).collections.set(collection, m); _assertClassBrand(_StorageEngine_brand, _this2, _markMetricsDirty).call(_this2, collection); if (appendRes && appendRes.updatedIndexMap !== true) { _classPrivateFieldGet(_idxDirtyShards, _this2).add("".concat(collection, "::").concat(shard)); } pendingNow = _classPrivateFieldGet(_pendingWritesByCollection, _this2).get(collection); if (pendingNow) { pw2 = pendingNow.get(String(id)); if (pw2 && _typeof(pw2) === "object") { pw2.filePath = filePath; pw2.offset = offset; if (pw2.resolve) { try { pw2.resolve({ id: id, offset: offset }); } catch (_unused7) {} } } } c = _classPrivateFieldGet(_compaction, _this2).get(collection); shardState = c === null || c === void 0 || (_c$shards = c.shards) === null || _c$shards === void 0 ? void 0 : _c$shards.get(shard); if (shardState && shardState.phase === "copying" && shardState.doubleWrite === true && shardState.tmpLDB && shardState.tmpIDX) { try { _assertClassBrand(_StorageEngine_brand, _this2, _appendRecord).call(_this2, shardState.tmpLDB, shardState.tmpIDX, id, valueBuffer, { updateIndexMap: false, collection: collection }); shardState.relocated.add(id); _assertClassBrand(_StorageEngine_brand, _this2, _writeCompactionState).call(_this2, collection, shard, _assertClassBrand(_StorageEngine_brand, _this2, _exportShardState).call(_this2, collection, shard, shardState)); } catch (_unused8) { shardState.relocated.add(id); _assertClassBrand(_StorageEngine_brand, _this2, _writeCompactionState).call(_this2, collection, shard, _assertClassBrand(_StorageEngine_brand, _this2, _exportShardState).call(_this2, collection, shard, shardState)); } } _assertClassBrand(_StorageEngine_brand, _this2, _clearPendingWrite).call(_this2, collection, String(id)); return _context.abrupt("return", { id: id, value: value, offset: offset }); case 28: _context.prev = 28; _context.t0 = _context["catch"](0); _pendingNow = _classPrivateFieldGet(_pendingWritesByCollection, _this2).get(collection); if (_pendingNow) { _pw = _pendingNow.get(String(id)); if (_pw && _pw.reject) { try { _pw.reject(_context.t0); } catch (_unused9) {} } } _assertClassBrand(_StorageEngine_brand, _this2, _clearPendingWrite).call(_this2, collection, String(id)); throw _context.t0; case 34: case "end": return _context.stop(); } }, _callee, null, [[0, 28]]); })))); case 18: case "end": return _context2.stop(); } }, _callee2, this, [[4, 8]]); })); function write(_x, _x2, _x3) { return _write.apply(this, arguments); } return write; }() }, { key: "read", value: function read(collection, id) { var _classPrivateFieldGet3; var sid = String(id); var pw = (_classPrivateFieldGet3 = _classPrivateFieldGet(_pendingWritesByCollection, this).get(collection)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.get(sid); if (pw) { if (pw.buffer) { try { return JSON.parse(pw.buffer.toString("utf8")); } catch (_unused10) { return null; } } if (pw.filePath != null && pw.offset != null) { return _assertClassBrand(_StorageEngine_brand, this, _readRecordCached).call(this, pw.filePath, pw.offset, sid); } return null; } var pointer = _assertClassBrand(_StorageEngine_brand, this, _getPointer).call(this, collection, sid); if (!pointer) { return null; } return _assertClassBrand(_StorageEngine_brand, this, _readRecordCached).call(this, pointer.filePath, pointer.offset, sid); } }, { key: "readMany", value: function readMany(collection, ids) { var _this3 = this; var groups = new Map(); var _iterator2 = _createForOfIteratorHelper(ids), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var id = _step2.value; var sid = String(id); var s = this.getShardID(sid); if (!groups.has(s)) { groups.set(s, []); } groups.get(s).push(sid); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } var out = new Map(); var _iterator3 = _createForOfIteratorHelper(groups.entries()), _step3; try { var _loop = function _loop() { var _step3$value = _slicedToArray(_step3.value, 2), shard = _step3$value[0], bucket = _step3$value[1]; var ldb = _this3.getShardFile(collection, shard); var pending = _classPrivateFieldGet(_pendingWritesByCollection, _this3).get(collection); var hasPendingForShard = pending ? bucket.some(function (id) { return pending.has(String(id)); }) : false; if (!fs.existsSync(ldb) && !hasPendingForShard) { return 1; // continue } var _iterator4 = _createForOfIteratorHelper(bucket), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var _id = _step4.value; var raw = _this3.read(collection, _id); if (raw !== null) { out.set(_id, raw); } } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } }; for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { if (_loop()) continue; } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } return out; } }, { key: "iterate", value: function iterate(collection) { var _this4 = this; var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref2$strictMatch = _ref2.strictMatch, strictMatch = _ref2$strictMatch === void 0 ? false : _ref2$strictMatch, _ref2$shards = _ref2.shards, shards = _ref2$shards === void 0 ? null : _ref2$shards, _ref2$max = _ref2.max, max = _ref2$max === void 0 ? Infinity : _ref2$max; var visitor = arguments.length > 2 ? arguments[2] : undefined; var normalized = String(collection).replace(/\\/g, "/"); var visited = 0; var matchedCollections = this.getMatchingCollections(normalized, strictMatch); var _iterator5 = _createForOfIteratorHelper(matchedCollections), _step5; try { var _loop2 = function _loop2() { var col = _step5.value; var colMap = _classPrivateFieldGet(_indexByCollection, _this4).get(col); var pending = _classPrivateFieldGet(_pendingWritesByCollection, _this4).get(col); var ids = new Set(); if (colMap) { var _iterator6 = _createForOfIteratorHelper(colMap.keys()), _step6; try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { var id = _step6.value; ids.add(String(id)); } } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } } if (pending) { var _iterator7 = _createForOfIteratorHelper(pending.keys()), _step7;