218 lines
4.9 KiB
JavaScript
218 lines
4.9 KiB
JavaScript
// Metro module 1915 (f1916).
|
|
import { Host } from "./Module1916";
|
|
import { DatabaseState } from "./Module1914";
|
|
import { Runtime } from "./Module1917";
|
|
import Module10 from "./Module10";
|
|
function $mk70600($env) {
|
|
return (a0, a1) => {
|
|
const r2 = $env[0];
|
|
if (r2.handle === a0) {
|
|
r2.lastState = a1;
|
|
}
|
|
};
|
|
}
|
|
function $mk102701($env) {
|
|
return (a0) => {
|
|
const r2 = $env;
|
|
r2[2].raw.execute(a0, {
|
|
...r2[1],
|
|
handle: 0
|
|
});
|
|
};
|
|
}
|
|
let c1602_5;
|
|
let env1602 = {};
|
|
c1602_5 = void 0;
|
|
export class Database {
|
|
constructor(a0) {
|
|
let env13313;
|
|
const r2 = env13313 = {};
|
|
env13313[0] = this;
|
|
this.raw = a0;
|
|
this.name = a0.name;
|
|
this.lastState = DatabaseState.Open;
|
|
this.handle = a0.handle;
|
|
this.databaseStateCallback = Runtime.addDatabaseStateCallback($mk70600(r2));
|
|
}
|
|
static async open(c13314_0, c13314_1) {
|
|
let c24698_0 = c1602_5;
|
|
return new c24698_0(await Host.open(c13314_0, c13314_1));
|
|
}
|
|
static openSyncUnsafe(a0, a1) {
|
|
const raw = Host.openSyncUnsafe(a0, a1);
|
|
let env13315;
|
|
const r16 = env13315 = {};
|
|
const r18 = {
|
|
__proto__: c1602_5.prototype
|
|
};
|
|
env13315[0] = r18;
|
|
r18.raw = raw;
|
|
r18.name = raw.name;
|
|
r18.lastState = DatabaseState.Open;
|
|
r18.handle = raw.handle;
|
|
r18.databaseStateCallback = Runtime.addDatabaseStateCallback($mk70600(r16));
|
|
return r18;
|
|
}
|
|
static delete(a0) {
|
|
return Host.delete(a0);
|
|
}
|
|
close() {
|
|
this.lastState = DatabaseState.Closed;
|
|
const raw = this.raw;
|
|
if (raw != null) {
|
|
raw.close();
|
|
}
|
|
this.raw = null;
|
|
Runtime.removeCompletionCallback(this.databaseStateCallback);
|
|
}
|
|
disable(a0) {
|
|
let r14;
|
|
if (this.raw == null) {
|
|
r14 = Promise.resolve();
|
|
} else {
|
|
this.lastState = DatabaseState.Disabled;
|
|
r14 = this.execute({
|
|
type: "db.disable",
|
|
handle: 0,
|
|
reason: a0
|
|
});
|
|
}
|
|
return r14;
|
|
}
|
|
execute(a0, a1) {
|
|
let r30;
|
|
let env13316;
|
|
const r3 = env13316 = {
|
|
$parent: env1602
|
|
};
|
|
env13316[2] = this;
|
|
env13316[1] = a0;
|
|
let r7 = a1;
|
|
env13316[0] = a1;
|
|
if (this.raw == null) {
|
|
throw new Error(`database is no longer open (database: ${this}`);
|
|
}
|
|
let r14 = "key" in a0 ? a0.key[0] : a0.table;
|
|
if (a1 === null) {
|
|
if (a1 == null) {
|
|
r7 = a0.type;
|
|
}
|
|
r30 = Runtime.executeAsync(r7, $mk102701(r3));
|
|
} else {
|
|
const r13 = a1 == null ? a0.type : a1;
|
|
if (r14 == null) {
|
|
r14 = "";
|
|
}
|
|
r30 = Module10.timeAsync("💾", `${r13} ${r14}`, () => {
|
|
const r1 = env13316;
|
|
let r10 = env13316[0];
|
|
if (r10 == null) {
|
|
r10 = env13316[1].type;
|
|
}
|
|
return Runtime.executeAsync(r10, $mk102701(r1));
|
|
});
|
|
}
|
|
return r30;
|
|
}
|
|
executeSync(a0) {
|
|
if (this.raw == null) {
|
|
throw new Error(`database is no longer open (database: ${this}`);
|
|
}
|
|
let r10 = "key" in a0 ? a0.key[0] : a0.table;
|
|
const type = a0.type;
|
|
if (r10 == null) {
|
|
r10 = "";
|
|
}
|
|
return Module10.time("💾", `SYNC: ${type} ${r10}`, () => this.raw.execute(null, {
|
|
...a0,
|
|
handle: 0
|
|
}, {
|
|
synchronous: true
|
|
}));
|
|
}
|
|
fullVacuum() {
|
|
return this.execute({
|
|
type: "db.vacuum",
|
|
handle: 0,
|
|
complete: true
|
|
});
|
|
}
|
|
fsInfo() {
|
|
return this.execute({
|
|
type: "db.fs_info",
|
|
handle: 0
|
|
});
|
|
}
|
|
incrementalVacuum() {
|
|
return this.execute({
|
|
type: "db.vacuum",
|
|
handle: 0,
|
|
complete: false
|
|
});
|
|
}
|
|
instantaneousState() {
|
|
let Closed;
|
|
if (this.raw == null) {
|
|
Closed = DatabaseState.Closed;
|
|
} else {
|
|
Closed = this.executeSync({
|
|
type: "db.state"
|
|
});
|
|
this.lastState = Closed;
|
|
}
|
|
return Closed;
|
|
}
|
|
async instantaneousStateAsync() {
|
|
let Closed;
|
|
const _this = this;
|
|
let _this2;
|
|
L14: {
|
|
if (_this.raw == null) {
|
|
Closed = DatabaseState.Closed;
|
|
break L14;
|
|
}
|
|
_this2 = _this;
|
|
const lastState = await _this.execute({
|
|
type: "db.state"
|
|
});
|
|
_this2.lastState = lastState;
|
|
return lastState;
|
|
}
|
|
return Closed;
|
|
}
|
|
state() {
|
|
return this.lastState;
|
|
}
|
|
transaction(a0, c13319_1) {
|
|
const r11 = {
|
|
__proto__: DatabaseTransaction.prototype
|
|
};
|
|
r11.database = this;
|
|
r11.operations = [];
|
|
let c13319_0 = r11;
|
|
return Promise.resolve(a0(r11)).then(() => c13319_0.operations.length > 0 ? this.execute({
|
|
type: "db.transaction",
|
|
operations: c13319_0.complete()
|
|
}, c13319_1) : Promise.resolve());
|
|
}
|
|
}
|
|
c1602_5 = Database;
|
|
export class DatabaseTransaction {
|
|
constructor(a0) {
|
|
this.database = a0;
|
|
this.operations = [];
|
|
}
|
|
add(a0) {
|
|
this.operations.push(a0);
|
|
}
|
|
complete() {
|
|
for (const operation of this.operations) {
|
|
operation.handle = 0;
|
|
}
|
|
return this.operations;
|
|
}
|
|
toString() {
|
|
return `[DatabaseTransaction ${this.database.handle}: ${this.operations.length} ops]`;
|
|
}
|
|
}
|