|
|
|
@ -1,22 +1,6 @@
|
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
// Sanity-check the conversion and remove this comment.
|
|
|
|
|
/*
|
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
* DS205: Consider reworking code to avoid use of IIFEs
|
|
|
|
|
* DS206: Consider reworking classes to avoid initClass
|
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
|
|
|
*/
|
|
|
|
|
(function () {
|
|
|
|
|
let NAME = undefined;
|
|
|
|
|
let VERSION = undefined;
|
|
|
|
|
app.DB = class DB {
|
|
|
|
|
static initClass() {
|
|
|
|
|
NAME = "docs";
|
|
|
|
|
VERSION = 15;
|
|
|
|
|
}
|
|
|
|
|
app.DB = class DB {
|
|
|
|
|
static NAME = "docs";
|
|
|
|
|
static VERSION = 15;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.versionMultipler = $.isIE() ? 1e5 : 1e9;
|
|
|
|
@ -38,8 +22,8 @@
|
|
|
|
|
try {
|
|
|
|
|
this.open = true;
|
|
|
|
|
const req = indexedDB.open(
|
|
|
|
|
NAME,
|
|
|
|
|
VERSION * this.versionMultipler + this.userVersion(),
|
|
|
|
|
DB.NAME,
|
|
|
|
|
DB.VERSION * this.versionMultipler + this.userVersion(),
|
|
|
|
|
);
|
|
|
|
|
req.onsuccess = (event) => this.onOpenSuccess(event);
|
|
|
|
|
req.onerror = (event) => this.onOpenError(event);
|
|
|
|
@ -123,7 +107,7 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVersionError() {
|
|
|
|
|
const req = indexedDB.open(NAME);
|
|
|
|
|
const req = indexedDB.open(DB.NAME);
|
|
|
|
|
req.onsuccess = (event) => {
|
|
|
|
|
return this.handleVersionMismatch(event.target.result.version);
|
|
|
|
|
};
|
|
|
|
@ -134,10 +118,10 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleVersionMismatch(actualVersion) {
|
|
|
|
|
if (Math.floor(actualVersion / this.versionMultipler) !== VERSION) {
|
|
|
|
|
if (Math.floor(actualVersion / this.versionMultipler) !== DB.VERSION) {
|
|
|
|
|
this.fail("version");
|
|
|
|
|
} else {
|
|
|
|
|
this.setUserVersion(actualVersion - VERSION * this.versionMultipler);
|
|
|
|
|
this.setUserVersion(actualVersion - DB.VERSION * this.versionMultipler);
|
|
|
|
|
this.db();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -179,7 +163,7 @@
|
|
|
|
|
} catch (error) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var doc of Array.from(app.docs.all())) {
|
|
|
|
|
for (var doc of app.docs.all()) {
|
|
|
|
|
if (!$.arrayDelete(objectStoreNames, doc.slug)) {
|
|
|
|
|
try {
|
|
|
|
|
db.createObjectStore(doc.slug);
|
|
|
|
@ -187,7 +171,7 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var name of Array.from(objectStoreNames)) {
|
|
|
|
|
for (var name of objectStoreNames) {
|
|
|
|
|
try {
|
|
|
|
|
db.deleteObjectStore(name);
|
|
|
|
|
} catch (error2) {}
|
|
|
|
@ -217,11 +201,7 @@
|
|
|
|
|
};
|
|
|
|
|
txn.onerror = (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (
|
|
|
|
|
(txn.error != null ? txn.error.name : undefined) ===
|
|
|
|
|
"NotFoundError" &&
|
|
|
|
|
_retry
|
|
|
|
|
) {
|
|
|
|
|
if (txn.error?.name === "NotFoundError" && _retry) {
|
|
|
|
|
this.migrate();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
return this.store(doc, data, onSuccess, onError, false);
|
|
|
|
@ -266,11 +246,7 @@
|
|
|
|
|
};
|
|
|
|
|
txn.onerror = function (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (
|
|
|
|
|
(txn.error != null ? txn.error.name : undefined) ===
|
|
|
|
|
"NotFoundError" &&
|
|
|
|
|
_retry
|
|
|
|
|
) {
|
|
|
|
|
if (txn.error?.name === "NotFoundError" && _retry) {
|
|
|
|
|
this.migrate();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
return this.unstore(doc, onSuccess, onError, false);
|
|
|
|
@ -289,8 +265,8 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
version(doc, fn) {
|
|
|
|
|
let version;
|
|
|
|
|
if ((version = this.cachedVersion(doc)) != null) {
|
|
|
|
|
let version = this.cachedVersion(doc);
|
|
|
|
|
if (version != null) {
|
|
|
|
|
fn(version);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -326,8 +302,8 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
versions(docs, fn) {
|
|
|
|
|
let versions;
|
|
|
|
|
if ((versions = this.cachedVersions(docs))) {
|
|
|
|
|
let versions = this.cachedVersions(docs);
|
|
|
|
|
if (versions) {
|
|
|
|
|
fn(versions);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -366,7 +342,7 @@
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const result = {};
|
|
|
|
|
for (var doc of Array.from(docs)) {
|
|
|
|
|
for (var doc of docs) {
|
|
|
|
|
result[doc.slug] = this.cachedVersion(doc);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
@ -374,7 +350,9 @@
|
|
|
|
|
|
|
|
|
|
load(entry, onSuccess, onError) {
|
|
|
|
|
if (this.shouldLoadWithIDB(entry)) {
|
|
|
|
|
return this.loadWithIDB(entry, onSuccess, () => this.loadWithXHR(entry, onSuccess, onError));
|
|
|
|
|
return this.loadWithIDB(entry, onSuccess, () =>
|
|
|
|
|
this.loadWithXHR(entry, onSuccess, onError),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return this.loadWithXHR(entry, onSuccess, onError);
|
|
|
|
|
}
|
|
|
|
@ -470,13 +448,13 @@
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (slug of Array.from(docs)) {
|
|
|
|
|
for (slug of docs) {
|
|
|
|
|
if (!app.docs.findBy("slug", slug)) {
|
|
|
|
|
this.corruptedDocs.push(slug);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (slug of Array.from(this.corruptedDocs)) {
|
|
|
|
|
for (slug of this.corruptedDocs) {
|
|
|
|
|
$.arrayDelete(docs, slug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -496,7 +474,7 @@
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (var doc of Array.from(docs)) {
|
|
|
|
|
for (var doc of docs) {
|
|
|
|
|
txn.objectStore(doc).get("index").onsuccess = (event) => {
|
|
|
|
|
if (!event.target.result) {
|
|
|
|
|
this.corruptedDocs.push(event.target.source.name);
|
|
|
|
@ -528,8 +506,7 @@
|
|
|
|
|
|
|
|
|
|
shouldLoadWithIDB(entry) {
|
|
|
|
|
return (
|
|
|
|
|
this.useIndexedDB &&
|
|
|
|
|
(!this.cachedDocs || this.cachedDocs[entry.doc.slug])
|
|
|
|
|
this.useIndexedDB && (!this.cachedDocs || this.cachedDocs[entry.doc.slug])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -551,9 +528,7 @@
|
|
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
|
try {
|
|
|
|
|
if (typeof indexedDB !== "undefined" && indexedDB !== null) {
|
|
|
|
|
indexedDB.deleteDatabase(NAME);
|
|
|
|
|
}
|
|
|
|
|
indexedDB?.deleteDatabase(DB.NAME);
|
|
|
|
|
} catch (error) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -581,7 +556,4 @@
|
|
|
|
|
userVersion() {
|
|
|
|
|
return app.settings.get("schema");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
app.DB.initClass();
|
|
|
|
|
return app.DB;
|
|
|
|
|
})();
|
|
|
|
|
};
|
|
|
|
|