UNPKG

fake-indexeddb

Version:

Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API

83 lines (82 loc) 3.59 kB
const 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.", SyntaxError: "The keypath argument contains an invalid key path", VersionError: "An attempt was made to open a database using a lower version than the existing version." }; // Cannot set an error code on an error using the normal setter; // this leads to "Cannot set property code of which has only a getter" const setErrorCode = (error, value) => { Object.defineProperty(error, 'code', { value, writable: false, enumerable: true, configurable: false }); }; export class AbortError extends DOMException { constructor(message = messages.AbortError) { super(message, "AbortError"); } } export class ConstraintError extends DOMException { constructor(message = messages.ConstraintError) { super(message, "ConstraintError"); } } export class DataCloneError extends DOMException { constructor(message = messages.DataCloneError) { super(message, "DataCloneError"); } } export class DataError extends DOMException { constructor(message = messages.DataError) { super(message, "DataError"); setErrorCode(this, 0); } } export class InvalidAccessError extends DOMException { constructor(message = messages.InvalidAccessError) { super(message, "InvalidAccessError"); } } export class InvalidStateError extends DOMException { constructor(message = messages.InvalidStateError) { super(message, "InvalidStateError"); setErrorCode(this, 11); } } export class NotFoundError extends DOMException { constructor(message = messages.NotFoundError) { super(message, "NotFoundError"); } } export class ReadOnlyError extends DOMException { constructor(message = messages.ReadOnlyError) { super(message, "ReadOnlyError"); } } export class SyntaxError extends DOMException { constructor(message = messages.VersionError) { super(message, "SyntaxError"); setErrorCode(this, 12); } } export class TransactionInactiveError extends DOMException { constructor(message = messages.TransactionInactiveError) { super(message, "TransactionInactiveError"); setErrorCode(this, 0); } } export class VersionError extends DOMException { constructor(message = messages.VersionError) { super(message, "VersionError"); } }