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

740 lines (739 loc) 197 kB
"use strict"; var _excluded = ["deleted", "deletedAt", "deletedReason", "deletedBy"], _excluded2 = ["pretty"], _excluded3 = ["deleted", "deletedAt", "deletedReason", "deletedBy"]; 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 _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 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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; } 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 _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 _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 _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 _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 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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } 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 _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"); } var path = require("path"); var fs = require("fs"); var StarQueryMetrics = require("./HUDControllers/StarQueryMetrics"); var StorageEngine = require("./HUDControllers/StorageEngine"); var _require = require("./HUDControllers/StarIndexer"), StarIndexer = _require.StarIndexer; var SecurityCore = require("./HUDControllers/SecurityCore"); var QueryEngine = require("./HUDControllers/QueryEngine"); var StarLogger = require("./HUDControllers/StarLogger"); var StarCache = require("./HUDControllers/StarCache"); var Starchive = require("./HUDControllers/Starchive"); var StarAuth = require("./HUDControllers/StarAuth"); var StarMesh = require("./HUDControllers/StarMesh"); var _txnStage = /*#__PURE__*/new WeakMap(); var _masterKey = /*#__PURE__*/new WeakMap(); var _idem = /*#__PURE__*/new WeakMap(); var _lastGeneratedIDTimestamp = /*#__PURE__*/new WeakMap(); var _lastGeneratedIDSequence = /*#__PURE__*/new WeakMap(); var _defaultIDProcessPart = /*#__PURE__*/new WeakMap(); var _qmHookHandlers = /*#__PURE__*/new WeakMap(); var _qmHooksArmed = /*#__PURE__*/new WeakMap(); var _queryMetrics = /*#__PURE__*/new WeakMap(); var _vacuumPolicy = /*#__PURE__*/new WeakMap(); var _starchive = /*#__PURE__*/new WeakMap(); var _decCache = /*#__PURE__*/new WeakMap(); var _indexer = /*#__PURE__*/new WeakMap(); var _options = /*#__PURE__*/new WeakMap(); var _dbPath = /*#__PURE__*/new WeakMap(); var _StarVault_brand = /*#__PURE__*/new WeakSet(); var StarVault = /*#__PURE__*/function () { function StarVault(dbPath, logPath) { var _this = this, _options2$indexer, _options2$indexer2, _authOptions$strictSe, _authOptions$enableGe, _this$handleSuspiciou, _this$handleSessionHi, _options2$starchive, _options2$starchive2, _options2$starchive3, _options2$starchive$r, _options2$starchive4, _options2$starchive5; var shardCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4; var maxLogSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "869MB"; var logRetention = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "1w"; var _options2 = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; _classCallCheck(this, StarVault); _classPrivateMethodInitSpec(this, _StarVault_brand); _classPrivateFieldInitSpec(this, _txnStage, new Map()); _classPrivateFieldInitSpec(this, _masterKey, null); _classPrivateFieldInitSpec(this, _idem, new Set()); _classPrivateFieldInitSpec(this, _lastGeneratedIDTimestamp, void 0); _classPrivateFieldInitSpec(this, _lastGeneratedIDSequence, void 0); _classPrivateFieldInitSpec(this, _defaultIDProcessPart, void 0); _classPrivateFieldInitSpec(this, _qmHookHandlers, null); _classPrivateFieldInitSpec(this, _qmHooksArmed, false); _classPrivateFieldInitSpec(this, _queryMetrics, null); _classPrivateFieldInitSpec(this, _vacuumPolicy, void 0); _classPrivateFieldInitSpec(this, _starchive, void 0); _classPrivateFieldInitSpec(this, _decCache, void 0); _classPrivateFieldInitSpec(this, _indexer, void 0); _classPrivateFieldInitSpec(this, _options, void 0); _classPrivateFieldInitSpec(this, _dbPath, void 0); var _options2$enableEncry = _options2.enableEncryption, enableEncryption = _options2$enableEncry === void 0 ? false : _options2$enableEncry, _options2$vaultPath = _options2.vaultPath, vaultPath = _options2$vaultPath === void 0 ? "./star-vault.json" : _options2$vaultPath, _options2$masterKey = _options2.masterKey, masterKey = _options2$masterKey === void 0 ? null : _options2$masterKey, _options2$authHandler = _options2.authHandler, authHandler = _options2$authHandler === void 0 ? null : _options2$authHandler, _options2$authOptions = _options2.authOptions, authOptions = _options2$authOptions === void 0 ? {} : _options2$authOptions, _options2$auditHistor = _options2.auditHistory, auditHistory = _options2$auditHistor === void 0 ? false : _options2$auditHistor, _options2$enableMesh = _options2.enableMesh, enableMesh = _options2$enableMesh === void 0 ? false : _options2$enableMesh, _options2$storageOpti = _options2.storageOptions, storageOptions = _options2$storageOpti === void 0 ? {} : _options2$storageOpti, _options2$meshOptions = _options2.meshOptions, meshOptions = _options2$meshOptions === void 0 ? {} : _options2$meshOptions, _options2$dirMode = _options2.dirMode, dirMode = _options2$dirMode === void 0 ? 448 : _options2$dirMode, _options2$fileMode = _options2.fileMode, fileMode = _options2$fileMode === void 0 ? 384 : _options2$fileMode; _classPrivateFieldSet(_masterKey, this, masterKey); this.storage = new StorageEngine(dbPath, shardCount, _objectSpread({ dirMode: dirMode, fileMode: fileMode }, storageOptions || {})); this.security = enableEncryption ? new SecurityCore({ masterKey: masterKey, vaultPath: vaultPath, dirMode: dirMode, fileMode: fileMode }) : null; _classPrivateFieldSet(_options, this, _options2); _classPrivateFieldSet(_lastGeneratedIDTimestamp, this, 0); _classPrivateFieldSet(_lastGeneratedIDSequence, this, -1); _classPrivateFieldSet(_defaultIDProcessPart, this, String(process.pid % 100000).padStart(5, "0")); _classPrivateFieldSet(_indexer, this, new StarIndexer(this.storage, this.security, _options2.indexerOptions || {})); _classPrivateFieldGet(_indexer, this).setAutoIndexPredicate(function (collection, field, stats) { var _classPrivateFieldGet2, _classPrivateFieldGet3, _stats$churnRate, _stats$cardinalityRat; var f = String(field); if (f === "id") { return true; } if (/(Id|ID)$/.test(f)) { return true; } if (/(?:^|[_-])id$/i.test(f)) { return true; } if ((_classPrivateFieldGet2 = _classPrivateFieldGet(_options, _this)) !== null && _classPrivateFieldGet2 !== void 0 && (_classPrivateFieldGet2 = _classPrivateFieldGet2.indexer) !== null && _classPrivateFieldGet2 !== void 0 && (_classPrivateFieldGet2 = _classPrivateFieldGet2.allow) !== null && _classPrivateFieldGet2 !== void 0 && (_classPrivateFieldGet2 = _classPrivateFieldGet2[collection]) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.includes(f)) { return true; } if ((_classPrivateFieldGet3 = _classPrivateFieldGet(_options, _this)) !== null && _classPrivateFieldGet3 !== void 0 && (_classPrivateFieldGet3 = _classPrivateFieldGet3.indexer) !== null && _classPrivateFieldGet3 !== void 0 && (_classPrivateFieldGet3 = _classPrivateFieldGet3.deny) !== null && _classPrivateFieldGet3 !== void 0 && (_classPrivateFieldGet3 = _classPrivateFieldGet3[collection]) !== null && _classPrivateFieldGet3 !== void 0 && _classPrivateFieldGet3.includes(f)) { return false; } var meta = stats === null || stats === void 0 ? void 0 : stats.fieldSample; if (!meta) { return false; } if (!["string", "number", "boolean"].includes(meta.type)) { return false; } if (meta.type === "string" && meta.avgLen > 96) { return false; } if (((_stats$churnRate = stats === null || stats === void 0 ? void 0 : stats.churnRate) !== null && _stats$churnRate !== void 0 ? _stats$churnRate : 0.00) > 0.15) { return false; } if (((_stats$cardinalityRat = stats === null || stats === void 0 ? void 0 : stats.cardinalityRatio) !== null && _stats$cardinalityRat !== void 0 ? _stats$cardinalityRat : 0.00) < 0.02) { return false; } return true; }); if ((_options2$indexer = _options2.indexer) !== null && _options2$indexer !== void 0 && _options2$indexer.autoFields) { for (var _i = 0, _Object$entries = Object.entries(_options2.indexer.autoFields); _i < _Object$entries.length; _i++) { var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), c = _Object$entries$_i[0], fields = _Object$entries$_i[1]; _classPrivateFieldGet(_indexer, this).addAutoFields(c, fields); } } if ((_options2$indexer2 = _options2.indexer) !== null && _options2$indexer2 !== void 0 && _options2$indexer2.budgets) { _classPrivateFieldGet(_indexer, this).setBudgets({ maxKeys: _options2.indexer.budgets.maxKeys, maxIDsPerKey: _options2.indexer.budgets.maxIDsPerKey, ttlMs: _options2.indexer.budgets.ttlMs, pruneIntervalMs: _options2.indexer.budgets.pruneIntervalMs }); } this.cache = new StarCache(1000); _classPrivateFieldSet(_decCache, this, new StarCache(2000)); this.wal = new StarLogger(logPath, maxLogSize, logRetention, dirMode, fileMode); this.wal.setDecryptor(function (collection, secured) { return _this.unsecureData(secured, _assertClassBrand(_StarVault_brand, _this, _canon).call(_this, collection)); }); this.wal.setEncryptor(function (namespace, plaintext) { return _this.secureData(plaintext, _assertClassBrand(_StarVault_brand, _this, _canon).call(_this, namespace)); }); _assertClassBrand(_StarVault_brand, this, _initQueryMetrics).call(this); this.auditHistoryDefault = auditHistory; this.authHandler = authHandler; this.listeners = new Map(); this.auth = authOptions.starAuthEnabled !== false ? new StarAuth(this, _objectSpread({ collection: authOptions.collection || "auth-users", sessionCollection: authOptions.sessionCollection || "auth-sessions", resetCollection: authOptions.resetCollection || "auth-resets", stellarCollection: authOptions.stellarCollection || "stellar-auths", strictSessionValidation: (_authOptions$strictSe = authOptions.strictSessionValidation) !== null && _authOptions$strictSe !== void 0 ? _authOptions$strictSe : true, enableGeo: (_authOptions$enableGe = authOptions.enableGeo) !== null && _authOptions$enableGe !== void 0 ? _authOptions$enableGe : true, onSuspiciousSession: authOptions.onSuspiciousSession || ((_this$handleSuspiciou = this.handleSuspiciousSession) === null || _this$handleSuspiciou === void 0 ? void 0 : _this$handleSuspiciou.bind(this)), handleHijack: authOptions.handleHijack || ((_this$handleSessionHi = this.handleSessionHijack) === null || _this$handleSessionHi === void 0 ? void 0 : _this$handleSessionHi.bind(this)), vaultID: authOptions.vaultID || "starvault-instance" }, authOptions)) : null; var starchiveOptions = _objectSpread(_objectSpread({}, (_options2$starchive = _options2.starchive) !== null && _options2$starchive !== void 0 ? _options2$starchive : {}), {}, { local: ((_options2$starchive2 = _options2.starchive) === null || _options2$starchive2 === void 0 ? void 0 : _options2$starchive2.local) === false ? false : ((_options2$starchive3 = _options2.starchive) === null || _options2$starchive3 === void 0 ? void 0 : _options2$starchive3.local) || { root: path.join("".concat(process.cwd()), ".starchive") }, remote: (_options2$starchive$r = (_options2$starchive4 = _options2.starchive) === null || _options2$starchive4 === void 0 ? void 0 : _options2$starchive4.remote) !== null && _options2$starchive$r !== void 0 ? _options2$starchive$r : false, defaultTarget: ((_options2$starchive5 = _options2.starchive) === null || _options2$starchive5 === void 0 ? void 0 : _options2$starchive5.defaultTarget) || "local", signingKeyProvider: function signingKeyProvider() { return _classPrivateFieldGet(_masterKey, _this); } }); _classPrivateFieldSet(_starchive, this, new Starchive(this, starchiveOptions)); this.starchive = _assertClassBrand(_StarVault_brand, this, _buildStarchiveNamespace).call(this); _classPrivateFieldSet(_vacuumPolicy, this, { minUpdates: 500, liveRatioThreshold: 0.55, minBytes: 33554432, minIntervalMs: 600000, doubleWrite: true, perRecordMaxUpdates: 2, perRecordAction: "shard" }); this.debugOptions = _objectSpread({ displayQueryRetrievalTimestamps: true, displayCollectionQueryErrors: true, displayEventEmissionTriggers: true, displayEventEmissionMatches: true, displayCollectionMatchLogs: true, displayRecordQueryErrors: true, displayListenerAdditions: true, displayQueryRetrievals: true, displayEventEmissions: true, displayUnsetKeysLogs: true, displayPathMatches: true }, _options2.debugOptions || {}); _classPrivateFieldSet(_dbPath, this, dbPath); if (enableMesh) { this.mesh = new StarMesh(_objectSpread({ vaultID: authOptions.vaultID || "starvault-instance", vault: this }, meshOptions)); this.syncSnapshotToVault = function () { var _this$mesh; return (_this$mesh = _this.mesh).syncSnapshotToVault.apply(_this$mesh, arguments); }; this.setSyncCheckpoint = function () { var _this$mesh2; return (_this$mesh2 = _this.mesh).setSyncCheckpoint.apply(_this$mesh2, arguments); }; this.getSyncCheckpoint = function () { var _this$mesh3; return (_this$mesh3 = _this.mesh).getSyncCheckpoint.apply(_this$mesh3, arguments); }; this.onVaultReconnect = function () { var _this$mesh4; return (_this$mesh4 = _this.mesh).onVaultReconnect.apply(_this$mesh4, arguments); }; } } return _createClass(StarVault, [{ key: "authenticate", value: function authenticate(clientAuth) { if (!this.authHandler) { return; } if (!this.authHandler(clientAuth)) { throw new Error("Unauthorized access."); } } }, { key: "secureData", value: function secureData(data, collection) { return this.security ? this.security.lock(data, _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection)) : data; } }, { key: "unsecureData", value: function unsecureData(data, collection) { if (!this.security || !data) { return data; } var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); try { return this.security.unlock(data, cid); } catch (error) { console.error("Error decrypting data for collection ~ \"".concat(cid, "\" ~"), error.message); throw new Error("Did not decrypt data for collection ~ \"".concat(cid, "\".")); } } }, { key: "create", value: function create(collection, data) { var _this$debugOptions; var actionInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var clientAuth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var providedID = data && typeof data.id === "string" && data.id.length > 0 ? data.id : null; var id = providedID || _assertClassBrand(_StarVault_brand, this, _generateDefaultRecordID).call(this); var record = { id: id, data: data, timestamp: Date.now() }; var securedData = this.secureData(record, cid); this.wal.logWrite(cid, securedData, actionInfo, "WRITE", { recordID: id }); this.storage.write(cid, id, securedData); this.cache.set("".concat(cid, ":").concat(id), securedData); _assertClassBrand(_StarVault_brand, this, _decSet).call(this, cid, id, record); try { _classPrivateFieldGet(_indexer, this).onCreate(cid, record); } catch (_unused) {} _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions = this.debugOptions) === null || _this$debugOptions === void 0 ? void 0 : _this$debugOptions.displayEventEmissions) !== false, "Emitting create event for path ~ ".concat(cid, "/").concat(id)); this.emit("create", "".concat(cid, "/").concat(id), record); return record; } }, { key: "update", value: function update(collection, id, updates) { var _this$debugOptions2; var actionInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var clientAuth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var currentRecord = _assertClassBrand(_StarVault_brand, this, _readFast).call(this, cid, id); if (!currentRecord) { var recordData = this.storage.read(cid, id); if (!recordData) { throw new Error("Record ~ ".concat(id, " not found.")); } currentRecord = this.unsecureData(recordData, cid); } var updatedData = _objectSpread({}, currentRecord.data); for (var key in updates) { if (updates[key] === undefined) { delete updatedData[key]; } else { updatedData[key] = updates[key]; } } var updatedRecord = { id: currentRecord.id, data: updatedData, lastModified: Date.now(), timestamp: currentRecord.timestamp }; var securedData = this.secureData(updatedRecord, cid); this.wal.logWrite(cid, securedData, actionInfo, "UPDATE", { recordID: id }); this.storage.write(cid, id, securedData); this.cache.set("".concat(cid, ":").concat(id), securedData); _assertClassBrand(_StarVault_brand, this, _decSet).call(this, cid, id, updatedRecord); try { _classPrivateFieldGet(_indexer, this).onUpdate(cid, currentRecord, updatedRecord); } catch (_unused2) {} _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions2 = this.debugOptions) === null || _this$debugOptions2 === void 0 ? void 0 : _this$debugOptions2.displayEventEmissions) !== false, "Emitting update event for path ~ ".concat(cid, "/").concat(id)); this.emit("update", "".concat(cid, "/").concat(id), updatedRecord); return updatedRecord; } }, { key: "unset", value: function unset(collection, id) { var _this$debugOptions3; var dotPaths = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; var actionInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var clientAuth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var currentRecord = _assertClassBrand(_StarVault_brand, this, _readFast).call(this, cid, id); if (!currentRecord) { var raw = this.storage.read(cid, id); if (!raw) { throw new Error("Record ~ ".concat(id, " not found.")); } currentRecord = this.unsecureData(raw, cid); } var _iterator = _createForOfIteratorHelper(dotPaths), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _path = _step.value; var keys = _path.split("."); var target = currentRecord.data; for (var i = 0; i < keys.length - 1; i++) { if (!target[keys[i]]) { break; } target = target[keys[i]]; } var finalKey = keys[keys.length - 1]; if (target && _typeof(target) === "object") { delete target[finalKey]; } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } var updatedRecord = { id: currentRecord.id, data: currentRecord.data, lastModified: Date.now(), timestamp: currentRecord.timestamp }; var securedData = this.secureData(updatedRecord, cid); this.wal.logWrite(cid, securedData, actionInfo, "UNSET", { recordID: id }); this.storage.write(cid, id, securedData); this.cache.set("".concat(cid, ":").concat(id), securedData); _assertClassBrand(_StarVault_brand, this, _decSet).call(this, cid, id, updatedRecord); try { _classPrivateFieldGet(_indexer, this).onUpdate(cid, currentRecord, updatedRecord); } catch (_unused3) {} _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions3 = this.debugOptions) === null || _this$debugOptions3 === void 0 ? void 0 : _this$debugOptions3.displayUnsetKeysLogs) !== false, "Unset keys from ~ ".concat(cid, "/").concat(id, " \u2192"), dotPaths); this.emit("update", "".concat(cid, "/").concat(id), updatedRecord); return updatedRecord; } }, { key: "deleteCollection", value: function deleteCollection(collection) { var _this$debugOptions5; var actionInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var clientAuth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var success = this.storage.deleteCollection(cid); if (!success) { var _this$debugOptions4; _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions4 = this.debugOptions) === null || _this$debugOptions4 === void 0 ? void 0 : _this$debugOptions4.displayCollectionQueryErrors) !== false, "Collection ~ ".concat(cid, " not found.")); return { wholeCollection: true, deleted: false }; } _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions5 = this.debugOptions) === null || _this$debugOptions5 === void 0 ? void 0 : _this$debugOptions5.displayEventEmissions) !== false, "Emitting delete event for path ~ ".concat(cid)); this.wal.logSystemAction("DELETE", cid, { wholeCollection: true }, actionInfo); this.emit("delete", "".concat(cid), { wholeCollection: true, deleted: true }); return { wholeCollection: true, deleted: true }; } }, { key: "deleteMany", value: function deleteMany(collection, ids) { var _res$deleted; var actionInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var clientAuth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var list = Array.isArray(ids) ? ids : [ids]; var seen = new Set(); var normalized = []; var _iterator2 = _createForOfIteratorHelper(list), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var x = _step2.value; if (x === null || x === undefined) { continue; } var s = String(x); if (!s) { continue; } if (seen.has(s)) { continue; } seen.add(s); normalized.push(s); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } if (normalized.length === 0) { return { deletedIDs: [], missingIDs: [], deleted: 0, missing: 0, requested: 0 }; } var snapshot = this.storage.readMany(cid, normalized); var deletedIDs = []; var missingIDs = []; var beforeByID = new Map(); for (var _i2 = 0, _normalized = normalized; _i2 < _normalized.length; _i2++) { var id = _normalized[_i2]; if (snapshot && snapshot.has(id)) { var raw = snapshot.get(id); beforeByID.set(id, raw); deletedIDs.push(id); } else { missingIDs.push(id); } } if (deletedIDs.length === 0) { return { deletedIDs: [], missingIDs: missingIDs, deleted: 0, missing: missingIDs.length, requested: normalized.length }; } var res = typeof this.storage.deleteMany === "function" ? this.storage.deleteMany(cid, deletedIDs) : this.storage["delete"](cid, deletedIDs) ? { deleted: deletedIDs.length } : { deleted: 0 }; var actuallyDeleted = Math.min(deletedIDs.length, Number((_res$deleted = res === null || res === void 0 ? void 0 : res.deleted) !== null && _res$deleted !== void 0 ? _res$deleted : deletedIDs.length)); var finalDeletedIDs = deletedIDs.slice(0, actuallyDeleted); var _iterator3 = _createForOfIteratorHelper(finalDeletedIDs), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var _this$cache, _this$cache$delete, _this$cache2, _this$debugOptions6; var _id = _step3.value; var beforeRaw = beforeByID.get(_id); try { if (beforeRaw) { var before = this.unsecureData(beforeRaw, cid); if (before) { _classPrivateFieldGet(_indexer, this).onDelete(cid, before); } } } catch (_unused4) {} (_this$cache = this.cache) === null || _this$cache === void 0 || (_this$cache$delete = (_this$cache2 = _this$cache)["delete"]) === null || _this$cache$delete === void 0 || _this$cache$delete.call(_this$cache2, "".concat(cid, ":").concat(_id)); _assertClassBrand(_StarVault_brand, this, _decDel).call(this, cid, _id); _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions6 = this.debugOptions) === null || _this$debugOptions6 === void 0 ? void 0 : _this$debugOptions6.displayEventEmissions) !== false, "Emitting delete event for path ~ ".concat(cid, "/").concat(_id)); this.emit("delete", "".concat(cid, "/").concat(_id), { id: _id, deleted: true }); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } this.wal.logSystemAction("DELETE", cid, { ids: finalDeletedIDs, many: true }, actionInfo); return { deletedIDs: finalDeletedIDs, missingIDs: missingIDs, deleted: finalDeletedIDs.length, missing: missingIDs.length, requested: normalized.length }; } }, { key: "deleteRecord", value: function deleteRecord(collection, id) { var _this$debugOptions8, _this$cache3, _this$cache3$delete; var actionInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var clientAuth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var beforeRaw = this.storage.read(cid, id); var success = this.storage["delete"](cid, id); if (!success) { var _this$debugOptions7; _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions7 = this.debugOptions) === null || _this$debugOptions7 === void 0 ? void 0 : _this$debugOptions7.displayRecordQueryErrors) !== false, "Record ~ ".concat(id, " not found in collection ~ ").concat(cid, ".")); return { id: id, deleted: false }; } _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions8 = this.debugOptions) === null || _this$debugOptions8 === void 0 ? void 0 : _this$debugOptions8.displayEventEmissions) !== false, "Emitting delete event for path ~ ".concat(cid, "/").concat(id)); try { if (beforeRaw) { var before = this.unsecureData(beforeRaw, cid); if (before) { _classPrivateFieldGet(_indexer, this).onDelete(cid, before); } } } catch (_unused5) {} this.wal.logSystemAction("DELETE", cid, { id: id }, actionInfo); this.emit("delete", "".concat(cid, "/").concat(id), { id: id, deleted: true }); (_this$cache3 = this.cache) === null || _this$cache3 === void 0 || (_this$cache3$delete = _this$cache3["delete"]) === null || _this$cache3$delete === void 0 || _this$cache3$delete.call(_this$cache3, "".concat(cid, ":").concat(id)); _assertClassBrand(_StarVault_brand, this, _decDel).call(this, cid, id); return { id: id, deleted: true }; } }, { key: "delete", value: function _delete(collection, id) { var _this$debugOptions9, _this$cache4, _this$cache4$delete; var actionInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var clientAuth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var allRecords = this.storage.readAll(cid, true) || []; var before = null; var records = allRecords.filter(function (r) { if (r && r.id === id) { before = r; return false; } return true; }); var newRecords = records.map(function (r) { return JSON.stringify(r); }).join("\n"); this.storage.overwrite(cid, newRecords); _assertClassBrand(_StarVault_brand, this, _output).call(this, ((_this$debugOptions9 = this.debugOptions) === null || _this$debugOptions9 === void 0 ? void 0 : _this$debugOptions9.displayEventEmissions) !== false, "Emitting delete event for path ~ ".concat(cid, "/").concat(id)); try { if (before) { _classPrivateFieldGet(_indexer, this).onDelete(cid, before); } } catch (_unused6) {} this.wal.logSystemAction("DELETE", cid, { id: id }, actionInfo); this.emit("delete", "".concat(cid, "/").concat(id), { id: id, deleted: true }); (_this$cache4 = this.cache) === null || _this$cache4 === void 0 || (_this$cache4$delete = _this$cache4["delete"]) === null || _this$cache4$delete === void 0 || _this$cache4$delete.call(_this$cache4, "".concat(cid, ":").concat(id)); _assertClassBrand(_StarVault_brand, this, _decDel).call(this, cid, id); return { id: id, deleted: true }; } }, { key: "softDelete", value: function softDelete(collection, id) { var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref$reason = _ref.reason, reason = _ref$reason === void 0 ? "soft-delete" : _ref$reason, _ref$deletedBy = _ref.deletedBy, deletedBy = _ref$deletedBy === void 0 ? null : _ref$deletedBy; var actionInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var clientAuth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var current = _assertClassBrand(_StarVault_brand, this, _readFast).call(this, cid, id); if (!current) { var raw = this.storage.read(cid, id); if (!raw) { console.warn("[StarVault] ~ Record ~ ".concat(id, " not found in collection ~ ").concat(cid, ".")); return null; } current = this.unsecureData(raw, cid); } var now = Date.now(); var updated = { id: current.id, data: _objectSpread(_objectSpread({}, current.data), {}, { deleted: true, deletedAt: now, deletedReason: reason, deletedBy: deletedBy }), lastModified: now, timestamp: current.timestamp }; var secured = this.secureData(updated, cid); this.wal.logWrite(cid, secured, _objectSpread(_objectSpread({}, actionInfo !== null && actionInfo !== void 0 ? actionInfo : {}), {}, { reason: reason, deletedBy: deletedBy }), "SOFT_DELETE", { recordID: id }); this.storage.write(cid, id, secured); this.cache.set("".concat(cid, ":").concat(id), secured); _assertClassBrand(_StarVault_brand, this, _decSet).call(this, cid, id, updated); try { _classPrivateFieldGet(_indexer, this).onUpdate(cid, current, updated); } catch (_unused7) {} this.emit("update", "".concat(cid, "/").concat(id), updated); return { id: id, softDeleted: true, at: now, reason: reason, deletedBy: deletedBy }; } }, { key: "restore", value: function restore(collection, id) { var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref2$restoredBy = _ref2.restoredBy, restoredBy = _ref2$restoredBy === void 0 ? null : _ref2$restoredBy; var actionInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var clientAuth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; this.authenticate(clientAuth); var cid = _assertClassBrand(_StarVault_brand, this, _canon).call(this, collection); var current = _assertClassBrand(_StarVault_brand, this, _readFast).call(this, cid, id); if (!current) { var raw = this.storage.read(cid, id); if (!raw) { console.warn("[StarVault] ~ Record ~ ".concat(id, " not found in collection ~ ").concat(cid, ".")); return null; } current = this.unsecureData(raw, cid); } var now = Date.now(); var _ref3 = current.data || {}, deleted = _ref3.deleted, deletedAt = _ref3.deletedAt, deletedReason = _ref3.deletedReason, deletedBy = _ref3.