implement session deletion on data layer
This commit is contained in:
parent
1ef08a29a4
commit
fbe785c1c4
@ -65,6 +65,8 @@ export default class SessionRepo {
|
||||
static async #handleChange() {
|
||||
if (!(this instanceof Session))
|
||||
throw new TypeError("session to put in must be an actual Session");
|
||||
if (!(SessionRepo.#marker in this))
|
||||
return;
|
||||
SessionRepo.put(this, this[SessionRepo.#marker]);
|
||||
}
|
||||
|
||||
@ -173,6 +175,29 @@ export default class SessionRepo {
|
||||
(session) => SessionRepo.#setupChangeHandling(session, transaction.db));
|
||||
}
|
||||
|
||||
/** Delete a specific session.
|
||||
*
|
||||
* This also tears down the auto updating if the passed session is an
|
||||
* instance of `Session`.
|
||||
*
|
||||
* @param {number | Session} session The session or session ID to delete.
|
||||
* @param {Transactable=} transaction A transaction to use.
|
||||
*/
|
||||
static async delete(session, transaction) {
|
||||
transaction = toTransaction(transaction, [WbDb.OS_SESSIONS], "readwrite");
|
||||
let sessions = transaction.objectStore(WbDb.OS_SESSIONS);
|
||||
|
||||
if (session instanceof Session) {
|
||||
session.removeEventListener(Session.EVENT_CHANGE, SessionRepo.#handleChange);
|
||||
delete this[SessionRepo.#marker];
|
||||
session = session.id;
|
||||
}
|
||||
if (typeof session !== "number")
|
||||
throw new TypeError("session to delete must be session or session ID");
|
||||
|
||||
return requestToPromise(sessions.delete(session));
|
||||
}
|
||||
|
||||
/** Load all sessions, parse them, then reinsert them.
|
||||
*
|
||||
* Does not set the intermediate objects up for change handling.
|
||||
|
||||
@ -207,6 +207,21 @@ export default function() {
|
||||
assert.strictEqual(sessions[1].id, second.id, "second is older");
|
||||
});
|
||||
|
||||
QUnit.test("delete session", async function(assert) {
|
||||
inst = WbDb.get(true);
|
||||
await waitForOpen(inst);
|
||||
|
||||
let session = new Session();
|
||||
await SessionRepo.put(session, inst);
|
||||
let stored = await SessionRepo.get(session.id, inst);
|
||||
assert.notStrictEqual(stored, undefined, "session stored");
|
||||
assert.strictEqual(stored.id, session.id, "IDs match");
|
||||
|
||||
await SessionRepo.delete(session.id, inst);
|
||||
stored = await SessionRepo.get(session.id, inst);
|
||||
assert.strictEqual(stored, undefined, "no longer stored");
|
||||
});
|
||||
|
||||
QUnit.test("reinserting all sessions", async function(assert) {
|
||||
// old structurized session (see v1 tests of session model)
|
||||
const old = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user