UNPKG

@firesystem/indexeddb

Version:

IndexedDB implementation of Virtual File System

1,590 lines (1,572 loc) 101 kB
import { __publicField } from "./chunk-JVWSFFO4.js"; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/errors.js var messages = { AbortError: "A request was aborted, for example through a call to IDBTransaction.abort.", ConstraintError: "A mutation operation in the transaction failed because a constraint was not satisfied. For example, an object such as an object store or index already exists and a request attempted to create a new one.", DataCloneError: "The data being stored could not be cloned by the internal structured cloning algorithm.", DataError: "Data provided to an operation does not meet requirements.", InvalidAccessError: "An invalid operation was performed on an object. For example transaction creation attempt was made, but an empty scope was provided.", InvalidStateError: "An operation was called on an object on which it is not allowed or at a time when it is not allowed. Also occurs if a request is made on a source object that has been deleted or removed. Use TransactionInactiveError or ReadOnlyError when possible, as they are more specific variations of InvalidStateError.", NotFoundError: "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.", ReadOnlyError: 'The mutating operation was attempted in a "readonly" transaction.', TransactionInactiveError: "A request was placed against a transaction which is currently not active, or which is finished.", VersionError: "An attempt was made to open a database using a lower version than the existing version.", }; var AbortError = class extends DOMException { constructor(message = messages.AbortError) { super(message, "AbortError"); } }; var ConstraintError = class extends DOMException { constructor(message = messages.ConstraintError) { super(message, "ConstraintError"); } }; var DataError = class extends DOMException { constructor(message = messages.DataError) { super(message, "DataError"); } }; var InvalidAccessError = class extends DOMException { constructor(message = messages.InvalidAccessError) { super(message, "InvalidAccessError"); } }; var InvalidStateError = class extends DOMException { constructor(message = messages.InvalidStateError) { super(message, "InvalidStateError"); } }; var NotFoundError = class extends DOMException { constructor(message = messages.NotFoundError) { super(message, "NotFoundError"); } }; var ReadOnlyError = class extends DOMException { constructor(message = messages.ReadOnlyError) { super(message, "ReadOnlyError"); } }; var TransactionInactiveError = class extends DOMException { constructor(message = messages.TransactionInactiveError) { super(message, "TransactionInactiveError"); } }; var VersionError = class extends DOMException { constructor(message = messages.VersionError) { super(message, "VersionError"); } }; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/valueToKey.js var valueToKey = (input, seen) => { if (typeof input === "number") { if (isNaN(input)) { throw new DataError(); } return input; } else if (Object.prototype.toString.call(input) === "[object Date]") { const ms = input.valueOf(); if (isNaN(ms)) { throw new DataError(); } return new Date(ms); } else if (typeof input === "string") { return input; } else if ( input instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && input instanceof SharedArrayBuffer) || (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView && ArrayBuffer.isView(input)) ) { let arrayBuffer; let offset = 0; let length = 0; if ( input instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && input instanceof SharedArrayBuffer) ) { arrayBuffer = input; length = input.byteLength; } else { arrayBuffer = input.buffer; offset = input.byteOffset; length = input.byteLength; } if (arrayBuffer.detached) { return new ArrayBuffer(0); } return arrayBuffer.slice(offset, offset + length); } else if (Array.isArray(input)) { if (seen === void 0) { seen = /* @__PURE__ */ new Set(); } else if (seen.has(input)) { throw new DataError(); } seen.add(input); const keys = []; for (let i = 0; i < input.length; i++) { const hop = Object.hasOwn(input, i); if (!hop) { throw new DataError(); } const entry = input[i]; const key = valueToKey(entry, seen); keys.push(key); } return keys; } else { throw new DataError(); } }; var valueToKey_default = valueToKey; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/cmp.js var getType = (x) => { if (typeof x === "number") { return "Number"; } if (Object.prototype.toString.call(x) === "[object Date]") { return "Date"; } if (Array.isArray(x)) { return "Array"; } if (typeof x === "string") { return "String"; } if (x instanceof ArrayBuffer) { return "Binary"; } throw new DataError(); }; var cmp = (first, second) => { if (second === void 0) { throw new TypeError(); } first = valueToKey_default(first); second = valueToKey_default(second); const t1 = getType(first); const t2 = getType(second); if (t1 !== t2) { if (t1 === "Array") { return 1; } if ( t1 === "Binary" && (t2 === "String" || t2 === "Date" || t2 === "Number") ) { return 1; } if (t1 === "String" && (t2 === "Date" || t2 === "Number")) { return 1; } if (t1 === "Date" && t2 === "Number") { return 1; } return -1; } if (t1 === "Binary") { first = new Uint8Array(first); second = new Uint8Array(second); } if (t1 === "Array" || t1 === "Binary") { const length = Math.min(first.length, second.length); for (let i = 0; i < length; i++) { const result = cmp(first[i], second[i]); if (result !== 0) { return result; } } if (first.length > second.length) { return 1; } if (first.length < second.length) { return -1; } return 0; } if (t1 === "Date") { if (first.getTime() === second.getTime()) { return 0; } } else { if (first === second) { return 0; } } return first > second ? 1 : -1; }; var cmp_default = cmp; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/FDBKeyRange.js var FDBKeyRange = class _FDBKeyRange { static only(value) { if (arguments.length === 0) { throw new TypeError(); } value = valueToKey_default(value); return new _FDBKeyRange(value, value, false, false); } static lowerBound(lower, open = false) { if (arguments.length === 0) { throw new TypeError(); } lower = valueToKey_default(lower); return new _FDBKeyRange(lower, void 0, open, true); } static upperBound(upper, open = false) { if (arguments.length === 0) { throw new TypeError(); } upper = valueToKey_default(upper); return new _FDBKeyRange(void 0, upper, true, open); } static bound(lower, upper, lowerOpen = false, upperOpen = false) { if (arguments.length < 2) { throw new TypeError(); } const cmpResult = cmp_default(lower, upper); if (cmpResult === 1 || (cmpResult === 0 && (lowerOpen || upperOpen))) { throw new DataError(); } lower = valueToKey_default(lower); upper = valueToKey_default(upper); return new _FDBKeyRange(lower, upper, lowerOpen, upperOpen); } constructor(lower, upper, lowerOpen, upperOpen) { this.lower = lower; this.upper = upper; this.lowerOpen = lowerOpen; this.upperOpen = upperOpen; } // https://w3c.github.io/IndexedDB/#dom-idbkeyrange-includes includes(key) { if (arguments.length === 0) { throw new TypeError(); } key = valueToKey_default(key); if (this.lower !== void 0) { const cmpResult = cmp_default(this.lower, key); if (cmpResult === 1 || (cmpResult === 0 && this.lowerOpen)) { return false; } } if (this.upper !== void 0) { const cmpResult = cmp_default(this.upper, key); if (cmpResult === -1 || (cmpResult === 0 && this.upperOpen)) { return false; } } return true; } toString() { return "[object IDBKeyRange]"; } }; var FDBKeyRange_default = FDBKeyRange; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/extractKey.js var extractKey = (keyPath, value) => { if (Array.isArray(keyPath)) { const result = []; for (let item of keyPath) { if ( item !== void 0 && item !== null && typeof item !== "string" && item.toString ) { item = item.toString(); } const key = extractKey(item, value).key; result.push(valueToKey_default(key)); } return { type: "found", key: result, }; } if (keyPath === "") { return { type: "found", key: value, }; } let remainingKeyPath = keyPath; let object = value; while (remainingKeyPath !== null) { let identifier; const i = remainingKeyPath.indexOf("."); if (i >= 0) { identifier = remainingKeyPath.slice(0, i); remainingKeyPath = remainingKeyPath.slice(i + 1); } else { identifier = remainingKeyPath; remainingKeyPath = null; } if ( object === void 0 || object === null || !Object.hasOwn(object, identifier) ) { return { type: "notFound", }; } object = object[identifier]; } return { type: "found", key: object, }; }; var extractKey_default = extractKey; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/FDBCursor.js var getEffectiveObjectStore = (cursor) => { if (cursor.source instanceof FDBObjectStore_default) { return cursor.source; } return cursor.source.objectStore; }; var makeKeyRange = (range, lowers, uppers) => { let lower = range !== void 0 ? range.lower : void 0; let upper = range !== void 0 ? range.upper : void 0; for (const lowerTemp of lowers) { if (lowerTemp === void 0) { continue; } if (lower === void 0 || cmp_default(lower, lowerTemp) === 1) { lower = lowerTemp; } } for (const upperTemp of uppers) { if (upperTemp === void 0) { continue; } if (upper === void 0 || cmp_default(upper, upperTemp) === -1) { upper = upperTemp; } } if (lower !== void 0 && upper !== void 0) { return FDBKeyRange_default.bound(lower, upper); } if (lower !== void 0) { return FDBKeyRange_default.lowerBound(lower); } if (upper !== void 0) { return FDBKeyRange_default.upperBound(upper); } }; var FDBCursor = class { constructor(source, range, direction = "next", request, keyOnly = false) { __publicField(this, "_gotValue", false); __publicField(this, "_position"); // Key of previously returned record __publicField(this, "_objectStorePosition"); __publicField(this, "_keyOnly", false); __publicField(this, "_key"); __publicField(this, "_primaryKey"); this._range = range; this._source = source; this._direction = direction; this._request = request; this._keyOnly = keyOnly; } // Read only properties get source() { return this._source; } set source(val) {} get request() { return this._request; } set request(val) {} get direction() { return this._direction; } set direction(val) {} get key() { return this._key; } set key(val) {} get primaryKey() { return this._primaryKey; } set primaryKey(val) {} // https://w3c.github.io/IndexedDB/#iterate-a-cursor _iterate(key, primaryKey) { const sourceIsObjectStore = this.source instanceof FDBObjectStore_default; const records = this.source instanceof FDBObjectStore_default ? this.source._rawObjectStore.records : this.source._rawIndex.records; let foundRecord; if (this.direction === "next") { const range = makeKeyRange(this._range, [key, this._position], []); for (const record of records.values(range)) { const cmpResultKey = key !== void 0 ? cmp_default(record.key, key) : void 0; const cmpResultPosition = this._position !== void 0 ? cmp_default(record.key, this._position) : void 0; if (key !== void 0) { if (cmpResultKey === -1) { continue; } } if (primaryKey !== void 0) { if (cmpResultKey === -1) { continue; } const cmpResultPrimaryKey = cmp_default(record.value, primaryKey); if (cmpResultKey === 0 && cmpResultPrimaryKey === -1) { continue; } } if (this._position !== void 0 && sourceIsObjectStore) { if (cmpResultPosition !== 1) { continue; } } if (this._position !== void 0 && !sourceIsObjectStore) { if (cmpResultPosition === -1) { continue; } if ( cmpResultPosition === 0 && cmp_default(record.value, this._objectStorePosition) !== 1 ) { continue; } } if (this._range !== void 0) { if (!this._range.includes(record.key)) { continue; } } foundRecord = record; break; } } else if (this.direction === "nextunique") { const range = makeKeyRange(this._range, [key, this._position], []); for (const record of records.values(range)) { if (key !== void 0) { if (cmp_default(record.key, key) === -1) { continue; } } if (this._position !== void 0) { if (cmp_default(record.key, this._position) !== 1) { continue; } } if (this._range !== void 0) { if (!this._range.includes(record.key)) { continue; } } foundRecord = record; break; } } else if (this.direction === "prev") { const range = makeKeyRange(this._range, [], [key, this._position]); for (const record of records.values(range, "prev")) { const cmpResultKey = key !== void 0 ? cmp_default(record.key, key) : void 0; const cmpResultPosition = this._position !== void 0 ? cmp_default(record.key, this._position) : void 0; if (key !== void 0) { if (cmpResultKey === 1) { continue; } } if (primaryKey !== void 0) { if (cmpResultKey === 1) { continue; } const cmpResultPrimaryKey = cmp_default(record.value, primaryKey); if (cmpResultKey === 0 && cmpResultPrimaryKey === 1) { continue; } } if (this._position !== void 0 && sourceIsObjectStore) { if (cmpResultPosition !== -1) { continue; } } if (this._position !== void 0 && !sourceIsObjectStore) { if (cmpResultPosition === 1) { continue; } if ( cmpResultPosition === 0 && cmp_default(record.value, this._objectStorePosition) !== -1 ) { continue; } } if (this._range !== void 0) { if (!this._range.includes(record.key)) { continue; } } foundRecord = record; break; } } else if (this.direction === "prevunique") { let tempRecord; const range = makeKeyRange(this._range, [], [key, this._position]); for (const record of records.values(range, "prev")) { if (key !== void 0) { if (cmp_default(record.key, key) === 1) { continue; } } if (this._position !== void 0) { if (cmp_default(record.key, this._position) !== -1) { continue; } } if (this._range !== void 0) { if (!this._range.includes(record.key)) { continue; } } tempRecord = record; break; } if (tempRecord) { foundRecord = records.get(tempRecord.key); } } let result; if (!foundRecord) { this._key = void 0; if (!sourceIsObjectStore) { this._objectStorePosition = void 0; } if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") { this.value = void 0; } result = null; } else { this._position = foundRecord.key; if (!sourceIsObjectStore) { this._objectStorePosition = foundRecord.value; } this._key = foundRecord.key; if (sourceIsObjectStore) { this._primaryKey = structuredClone(foundRecord.key); if ( !this._keyOnly && this.toString() === "[object IDBCursorWithValue]" ) { this.value = structuredClone(foundRecord.value); } } else { this._primaryKey = structuredClone(foundRecord.value); if ( !this._keyOnly && this.toString() === "[object IDBCursorWithValue]" ) { if (this.source instanceof FDBObjectStore_default) { throw new Error("This should never happen"); } const value = this.source.objectStore._rawObjectStore.getValue( foundRecord.value, ); this.value = structuredClone(value); } } this._gotValue = true; result = this; } return result; } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-update-IDBRequest-any-value update(value) { if (value === void 0) { throw new TypeError(); } const effectiveObjectStore = getEffectiveObjectStore(this); const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position; const transaction = effectiveObjectStore.transaction; if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (transaction.mode === "readonly") { throw new ReadOnlyError(); } if (effectiveObjectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if ( !(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted ) { throw new InvalidStateError(); } if (!this._gotValue || !Object.hasOwn(this, "value")) { throw new InvalidStateError(); } const clone = structuredClone(value); if (effectiveObjectStore.keyPath !== null) { let tempKey; try { tempKey = extractKey_default(effectiveObjectStore.keyPath, clone).key; } catch (err) {} if (cmp_default(tempKey, effectiveKey) !== 0) { throw new DataError(); } } const record = { key: effectiveKey, value: clone, }; return transaction._execRequestAsync({ operation: effectiveObjectStore._rawObjectStore.storeRecord.bind( effectiveObjectStore._rawObjectStore, record, false, transaction._rollbackLog, ), source: this, }); } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-advance-void-unsigned-long-count advance(count) { if (!Number.isInteger(count) || count <= 0) { throw new TypeError(); } const effectiveObjectStore = getEffectiveObjectStore(this); const transaction = effectiveObjectStore.transaction; if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (effectiveObjectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if ( !(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted ) { throw new InvalidStateError(); } if (!this._gotValue) { throw new InvalidStateError(); } if (this._request) { this._request.readyState = "pending"; } transaction._execRequestAsync({ operation: () => { let result; for (let i = 0; i < count; i++) { result = this._iterate(); if (!result) { break; } } return result; }, request: this._request, source: this.source, }); this._gotValue = false; } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-continue-void-any-key continue(key) { const effectiveObjectStore = getEffectiveObjectStore(this); const transaction = effectiveObjectStore.transaction; if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (effectiveObjectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if ( !(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted ) { throw new InvalidStateError(); } if (!this._gotValue) { throw new InvalidStateError(); } if (key !== void 0) { key = valueToKey_default(key); const cmpResult = cmp_default(key, this._position); if ( (cmpResult <= 0 && (this.direction === "next" || this.direction === "nextunique")) || (cmpResult >= 0 && (this.direction === "prev" || this.direction === "prevunique")) ) { throw new DataError(); } } if (this._request) { this._request.readyState = "pending"; } transaction._execRequestAsync({ operation: this._iterate.bind(this, key), request: this._request, source: this.source, }); this._gotValue = false; } // hthttps://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey continuePrimaryKey(key, primaryKey) { const effectiveObjectStore = getEffectiveObjectStore(this); const transaction = effectiveObjectStore.transaction; if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (effectiveObjectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if ( !(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted ) { throw new InvalidStateError(); } if ( this.source instanceof FDBObjectStore_default || (this.direction !== "next" && this.direction !== "prev") ) { throw new InvalidAccessError(); } if (!this._gotValue) { throw new InvalidStateError(); } if (key === void 0 || primaryKey === void 0) { throw new DataError(); } key = valueToKey_default(key); const cmpResult = cmp_default(key, this._position); if ( (cmpResult === -1 && this.direction === "next") || (cmpResult === 1 && this.direction === "prev") ) { throw new DataError(); } const cmpResult2 = cmp_default(primaryKey, this._objectStorePosition); if (cmpResult === 0) { if ( (cmpResult2 <= 0 && this.direction === "next") || (cmpResult2 >= 0 && this.direction === "prev") ) { throw new DataError(); } } if (this._request) { this._request.readyState = "pending"; } transaction._execRequestAsync({ operation: this._iterate.bind(this, key, primaryKey), request: this._request, source: this.source, }); this._gotValue = false; } delete() { const effectiveObjectStore = getEffectiveObjectStore(this); const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position; const transaction = effectiveObjectStore.transaction; if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (transaction.mode === "readonly") { throw new ReadOnlyError(); } if (effectiveObjectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if ( !(this.source instanceof FDBObjectStore_default) && this.source._rawIndex.deleted ) { throw new InvalidStateError(); } if (!this._gotValue || !Object.hasOwn(this, "value")) { throw new InvalidStateError(); } return transaction._execRequestAsync({ operation: effectiveObjectStore._rawObjectStore.deleteRecord.bind( effectiveObjectStore._rawObjectStore, effectiveKey, transaction._rollbackLog, ), source: this, }); } toString() { return "[object IDBCursor]"; } }; var FDBCursor_default = FDBCursor; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/FDBCursorWithValue.js var FDBCursorWithValue = class extends FDBCursor_default { constructor(source, range, direction, request) { super(source, range, direction, request); __publicField(this, "value"); } toString() { return "[object IDBCursorWithValue]"; } }; var FDBCursorWithValue_default = FDBCursorWithValue; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/FakeEventTarget.js var stopped = (event, listener) => { return ( event.immediatePropagationStopped || (event.eventPhase === event.CAPTURING_PHASE && listener.capture === false) || (event.eventPhase === event.BUBBLING_PHASE && listener.capture === true) ); }; var invokeEventListeners = (event, obj) => { event.currentTarget = obj; for (const listener of obj.listeners.slice()) { if (event.type !== listener.type || stopped(event, listener)) { continue; } listener.callback.call(event.currentTarget, event); } const typeToProp = { abort: "onabort", blocked: "onblocked", complete: "oncomplete", error: "onerror", success: "onsuccess", upgradeneeded: "onupgradeneeded", versionchange: "onversionchange", }; const prop = typeToProp[event.type]; if (prop === void 0) { throw new Error(`Unknown event type: "${event.type}"`); } const callback = event.currentTarget[prop]; if (callback) { const listener = { callback, capture: false, type: event.type, }; if (!stopped(event, listener)) { listener.callback.call(event.currentTarget, event); } } }; var FakeEventTarget = class { constructor() { __publicField(this, "listeners", []); } // These will be overridden in individual subclasses and made not readonly addEventListener(type, callback, capture = false) { this.listeners.push({ callback, capture, type, }); } removeEventListener(type, callback, capture = false) { const i = this.listeners.findIndex((listener) => { return ( listener.type === type && listener.callback === callback && listener.capture === capture ); }); this.listeners.splice(i, 1); } // http://www.w3.org/TR/dom/#dispatching-events dispatchEvent(event) { if (event.dispatched || !event.initialized) { throw new InvalidStateError("The object is in an invalid state."); } event.isTrusted = false; event.dispatched = true; event.target = this; event.eventPhase = event.CAPTURING_PHASE; for (const obj of event.eventPath) { if (!event.propagationStopped) { invokeEventListeners(event, obj); } } event.eventPhase = event.AT_TARGET; if (!event.propagationStopped) { invokeEventListeners(event, event.target); } if (event.bubbles) { event.eventPath.reverse(); event.eventPhase = event.BUBBLING_PHASE; for (const obj of event.eventPath) { if (!event.propagationStopped) { invokeEventListeners(event, obj); } } } event.dispatched = false; event.eventPhase = event.NONE; event.currentTarget = null; if (event.canceled) { return false; } return true; } }; var FakeEventTarget_default = FakeEventTarget; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/FDBRequest.js var FDBRequest = class extends FakeEventTarget_default { constructor() { super(...arguments); __publicField(this, "_result", null); __publicField(this, "_error", null); __publicField(this, "source", null); __publicField(this, "transaction", null); __publicField(this, "readyState", "pending"); __publicField(this, "onsuccess", null); __publicField(this, "onerror", null); } get error() { if (this.readyState === "pending") { throw new InvalidStateError(); } return this._error; } set error(value) { this._error = value; } get result() { if (this.readyState === "pending") { throw new InvalidStateError(); } return this._result; } set result(value) { this._result = value; } toString() { return "[object IDBRequest]"; } }; var FDBRequest_default = FDBRequest; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/enforceRange.js var enforceRange = (num, type) => { const min = 0; const max = type === "unsigned long" ? 4294967295 : 9007199254740991; if (isNaN(num) || num < min || num > max) { throw new TypeError(); } if (num >= 0) { return Math.floor(num); } }; var enforceRange_default = enforceRange; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/FakeDOMStringList.js var FakeDOMStringList = class extends Array { contains(value) { for (const value2 of this) { if (value === value2) { return true; } } return false; } item(i) { if (i < 0 || i >= this.length) { return null; } return this[i]; } // Used internally, should not be used by others. I could maybe get rid of these and replace rather than mutate, but too lazy to check the spec. _push(...values) { return Array.prototype.push.call(this, ...values); } _sort(...values) { return Array.prototype.sort.call(this, ...values); } }; var FakeDOMStringList_default = FakeDOMStringList; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/valueToKeyRange.js var valueToKeyRange = (value, nullDisallowedFlag = false) => { if (value instanceof FDBKeyRange_default) { return value; } if (value === null || value === void 0) { if (nullDisallowedFlag) { throw new DataError(); } return new FDBKeyRange_default(void 0, void 0, false, false); } const key = valueToKey_default(value); return FDBKeyRange_default.only(key); }; var valueToKeyRange_default = valueToKeyRange; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/FDBIndex.js var confirmActiveTransaction = (index) => { if (index._rawIndex.deleted || index.objectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } if (index.objectStore.transaction._state !== "active") { throw new TransactionInactiveError(); } }; var FDBIndex = class { constructor(objectStore, rawIndex) { this._rawIndex = rawIndex; this._name = rawIndex.name; this.objectStore = objectStore; this.keyPath = rawIndex.keyPath; this.multiEntry = rawIndex.multiEntry; this.unique = rawIndex.unique; } get name() { return this._name; } // https://w3c.github.io/IndexedDB/#dom-idbindex-name set name(name) { const transaction = this.objectStore.transaction; if (!transaction.db._runningVersionchangeTransaction) { throw new InvalidStateError(); } if (transaction._state !== "active") { throw new TransactionInactiveError(); } if (this._rawIndex.deleted || this.objectStore._rawObjectStore.deleted) { throw new InvalidStateError(); } name = String(name); if (name === this._name) { return; } if (this.objectStore.indexNames.contains(name)) { throw new ConstraintError(); } const oldName = this._name; const oldIndexNames = [...this.objectStore.indexNames]; this._name = name; this._rawIndex.name = name; this.objectStore._indexesCache.delete(oldName); this.objectStore._indexesCache.set(name, this); this.objectStore._rawObjectStore.rawIndexes.delete(oldName); this.objectStore._rawObjectStore.rawIndexes.set(name, this._rawIndex); this.objectStore.indexNames = new FakeDOMStringList_default( ...Array.from(this.objectStore._rawObjectStore.rawIndexes.keys()) .filter((indexName) => { const index = this.objectStore._rawObjectStore.rawIndexes.get(indexName); return index && !index.deleted; }) .sort(), ); transaction._rollbackLog.push(() => { this._name = oldName; this._rawIndex.name = oldName; this.objectStore._indexesCache.delete(name); this.objectStore._indexesCache.set(oldName, this); this.objectStore._rawObjectStore.rawIndexes.delete(name); this.objectStore._rawObjectStore.rawIndexes.set(oldName, this._rawIndex); this.objectStore.indexNames = new FakeDOMStringList_default( ...oldIndexNames, ); }); } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction openCursor(range, direction) { confirmActiveTransaction(this); if (range === null) { range = void 0; } if (range !== void 0 && !(range instanceof FDBKeyRange_default)) { range = FDBKeyRange_default.only(valueToKey_default(range)); } const request = new FDBRequest_default(); request.source = this; request.transaction = this.objectStore.transaction; const cursor = new FDBCursorWithValue_default( this, range, direction, request, ); return this.objectStore.transaction._execRequestAsync({ operation: cursor._iterate.bind(cursor), request, source: this, }); } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openKeyCursor-IDBRequest-any-range-IDBCursorDirection-direction openKeyCursor(range, direction) { confirmActiveTransaction(this); if (range === null) { range = void 0; } if (range !== void 0 && !(range instanceof FDBKeyRange_default)) { range = FDBKeyRange_default.only(valueToKey_default(range)); } const request = new FDBRequest_default(); request.source = this; request.transaction = this.objectStore.transaction; const cursor = new FDBCursor_default(this, range, direction, request, true); return this.objectStore.transaction._execRequestAsync({ operation: cursor._iterate.bind(cursor), request, source: this, }); } get(key) { confirmActiveTransaction(this); if (!(key instanceof FDBKeyRange_default)) { key = valueToKey_default(key); } return this.objectStore.transaction._execRequestAsync({ operation: this._rawIndex.getValue.bind(this._rawIndex, key), source: this, }); } // http://w3c.github.io/IndexedDB/#dom-idbindex-getall getAll(query, count) { if (arguments.length > 1 && count !== void 0) { count = enforceRange_default(count, "unsigned long"); } confirmActiveTransaction(this); const range = valueToKeyRange_default(query); return this.objectStore.transaction._execRequestAsync({ operation: this._rawIndex.getAllValues.bind(this._rawIndex, range, count), source: this, }); } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-getKey-IDBRequest-any-key getKey(key) { confirmActiveTransaction(this); if (!(key instanceof FDBKeyRange_default)) { key = valueToKey_default(key); } return this.objectStore.transaction._execRequestAsync({ operation: this._rawIndex.getKey.bind(this._rawIndex, key), source: this, }); } // http://w3c.github.io/IndexedDB/#dom-idbindex-getallkeys getAllKeys(query, count) { if (arguments.length > 1 && count !== void 0) { count = enforceRange_default(count, "unsigned long"); } confirmActiveTransaction(this); const range = valueToKeyRange_default(query); return this.objectStore.transaction._execRequestAsync({ operation: this._rawIndex.getAllKeys.bind(this._rawIndex, range, count), source: this, }); } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-count-IDBRequest-any-key count(key) { confirmActiveTransaction(this); if (key === null) { key = void 0; } if (key !== void 0 && !(key instanceof FDBKeyRange_default)) { key = FDBKeyRange_default.only(valueToKey_default(key)); } return this.objectStore.transaction._execRequestAsync({ operation: () => { return this._rawIndex.count(key); }, source: this, }); } toString() { return "[object IDBIndex]"; } }; var FDBIndex_default = FDBIndex; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/canInjectKey.js var canInjectKey = (keyPath, value) => { if (Array.isArray(keyPath)) { throw new Error( "The key paths used in this section are always strings and never sequences, since it is not possible to create a object store which has a key generator and also has a key path that is a sequence.", ); } const identifiers = keyPath.split("."); if (identifiers.length === 0) { throw new Error("Assert: identifiers is not empty"); } identifiers.pop(); for (const identifier of identifiers) { if (typeof value !== "object" && !Array.isArray(value)) { return false; } const hop = Object.hasOwn(value, identifier); if (!hop) { return true; } value = value[identifier]; } return typeof value === "object" || Array.isArray(value); }; var canInjectKey_default = canInjectKey; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/binarySearch.js function binarySearch(records, key) { let low = 0; let high = records.length; let mid; while (low < high) { mid = (low + high) >>> 1; if (cmp_default(records[mid].key, key) < 0) { low = mid + 1; } else { high = mid; } } return low; } function getIndexByKey(records, key) { const idx = binarySearch(records, key); const record = records[idx]; if (record && cmp_default(record.key, key) === 0) { return idx; } return -1; } function getByKey(records, key) { const idx = getIndexByKey(records, key); return records[idx]; } function getIndexByKeyRange(records, keyRange) { const lowerIdx = typeof keyRange.lower === "undefined" ? 0 : binarySearch(records, keyRange.lower); const upperIdx = typeof keyRange.upper === "undefined" ? records.length - 1 : binarySearch(records, keyRange.upper); for (let i = lowerIdx; i <= upperIdx; i++) { const record = records[i]; if (record && keyRange.includes(record.key)) { return i; } } return -1; } function getByKeyRange(records, keyRange) { const idx = getIndexByKeyRange(records, keyRange); return records[idx]; } function getIndexByKeyGTE(records, key) { const idx = binarySearch(records, key); const record = records[idx]; if (record && cmp_default(record.key, key) >= 0) { return idx; } return -1; } // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/RecordStore.js var RecordStore = class { constructor() { __publicField(this, "records", []); } get(key) { if (key instanceof FDBKeyRange_default) { return getByKeyRange(this.records, key); } return getByKey(this.records, key); } add(newRecord) { let i; if (this.records.length === 0) { i = 0; } else { i = getIndexByKeyGTE(this.records, newRecord.key); if (i === -1) { i = this.records.length; } else { while ( i < this.records.length && cmp_default(this.records[i].key, newRecord.key) === 0 ) { if (cmp_default(this.records[i].value, newRecord.value) !== -1) { break; } i += 1; } } } this.records.splice(i, 0, newRecord); } delete(key) { const deletedRecords = []; const isRange = key instanceof FDBKeyRange_default; while (true) { const idx = isRange ? getIndexByKeyRange(this.records, key) : getIndexByKey(this.records, key); if (idx === -1) { break; } deletedRecords.push(this.records[idx]); this.records.splice(idx, 1); } return deletedRecords; } deleteByValue(key) { const range = key instanceof FDBKeyRange_default ? key : FDBKeyRange_default.only(key); const deletedRecords = []; this.records = this.records.filter((record) => { const shouldDelete = range.includes(record.value); if (shouldDelete) { deletedRecords.push(record); } return !shouldDelete; }); return deletedRecords; } clear() { const deletedRecords = this.records.slice(); this.records = []; return deletedRecords; } values(range, direction = "next") { return { [Symbol.iterator]: () => { let i; if (direction === "next") { i = 0; if (range !== void 0 && range.lower !== void 0) { while (this.records[i] !== void 0) { const cmpResult = cmp_default(this.records[i].key, range.lower); if (cmpResult === 1 || (cmpResult === 0 && !range.lowerOpen)) { break; } i += 1; } } } else { i = this.records.length - 1; if (range !== void 0 && range.upper !== void 0) { while (this.records[i] !== void 0) { const cmpResult = cmp_default(this.records[i].key, range.upper); if (cmpResult === -1 || (cmpResult === 0 && !range.upperOpen)) { break; } i -= 1; } } } return { next: () => { let done; let value; if (direction === "next") { value = this.records[i]; done = i >= this.records.length; i += 1; if (!done && range !== void 0 && range.upper !== void 0) { const cmpResult = cmp_default(value.key, range.upper); done = cmpResult === 1 || (cmpResult === 0 && range.upperOpen); if (done) { value = void 0; } } } else { value = this.records[i]; done = i < 0; i -= 1; if (!done && range !== void 0 && range.lower !== void 0) { const cmpResult = cmp_default(value.key, range.lower); done = cmpResult === -1 || (cmpResult === 0 && range.lowerOpen); if (done) { value = void 0; } } } return { done, value, }; }, }; }, }; } }; var RecordStore_default = RecordStore; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/Index.js var Index = class { constructor(rawObjectStore, name, keyPath, multiEntry, unique) { __publicField(this, "deleted", false); // Initialized should be used to decide whether to throw an error or abort the versionchange transaction when there is a // constraint __publicField(this, "initialized", false); __publicField(this, "records", new RecordStore_default()); this.rawObjectStore = rawObjectStore; this.name = name; this.keyPath = keyPath; this.multiEntry = multiEntry; this.unique = unique; } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-retrieving-a-value-from-an-index getKey(key) { const record = this.records.get(key); return record !== void 0 ? record.value : void 0; } // http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index getAllKeys(range, count) { if (count === void 0 || count === 0) { count = Infinity; } const records = []; for (const record of this.records.values(range)) { records.push(structuredClone(record.value)); if (records.length >= count) { break; } } return records; } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#index-referenced-value-retrieval-operation getValue(key) { const record = this.records.get(key); return record !== void 0 ? this.rawObjectStore.getValue(record.value) : void 0; } // http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index getAllValues(range, count) { if (count === void 0 || count === 0) { count = Infinity; } const records = []; for (const record of this.records.values(range)) { records.push(this.rawObjectStore.getValue(record.value)); if (records.length >= count) { break; } } return records; } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store (step 7) storeRecord(newRecord) { let indexKey; try { indexKey = extractKey_default(this.keyPath, newRecord.value).key; } catch (err) { if (err.name === "DataError") { return; } throw err; } if (!this.multiEntry || !Array.isArray(indexKey)) { try { valueToKey_default(indexKey); } catch (e) { return; } } else { const keep = []; for (const part of indexKey) { if (keep.indexOf(part) < 0) { try { keep.push(valueToKey_default(part)); } catch (err) {} } } indexKey = keep; } if (!this.multiEntry || !Array.isArray(indexKey)) { if (this.unique) { const existingRecord = this.records.get(indexKey); if (existingRecord) { throw new ConstraintError(); } } } else { if (this.unique) { for (const individualIndexKey of indexKey) { const existingRecord = this.records.get(individualIndexKey); if (existingRecord) { throw new ConstraintError(); } } } } if (!this.multiEntry || !Array.isArray(indexKey)) { this.records.add({ key: indexKey, value: newRecord.key, }); } else { for (const individualIndexKey of indexKey) { this.records.add({ key: individualIndexKey, value: newRecord.key, }); } } } initialize(transaction) { if (this.initialized) { throw new Error("Index already initialized"); } transaction._execRequestAsync({ operation: () => { try { for (const record of this.rawObjectStore.records.values()) { this.storeRecord(record); } this.initialized = true; } catch (err) { transaction._abort(err.name); } }, source: null, }); } count(range) { let count = 0; for (const record of this.records.values(range)) { count += 1; } return count; } }; var Index_default = Index; // ../../node_modules/.pnpm/fake-indexeddb@6.0.1/node_modules/fake-indexeddb/build/esm/lib/validateKeyPath.js var validateKeyPath = (keyPath, parent) => { if ( keyPath !== void 0 && keyPath !== null && typeof keyPath !== "string" && keyPath.toString && (parent === "array" || !Array.isArray(keyPath)) ) { keyPath = keyPath.toString(); } if (typeof keyPath === "string") { if (keyPath === "" && parent !== "string") { return; } try { const validIdentifierRegex = // eslint-disable-next-line no-misleading-character-class /^(?:[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u