2020-08-05 22:08:55 +05:30
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-02-07 05:50:27 +05:30
|
|
|
import {txnAsPromise} from "./utils.js";
|
2019-06-27 01:30:50 +05:30
|
|
|
import {StorageError} from "../common.js";
|
2020-04-21 01:11:10 +05:30
|
|
|
import {Store} from "./Store.js";
|
2020-04-21 00:56:39 +05:30
|
|
|
import {SessionStore} from "./stores/SessionStore.js";
|
|
|
|
import {RoomSummaryStore} from "./stores/RoomSummaryStore.js";
|
|
|
|
import {TimelineEventStore} from "./stores/TimelineEventStore.js";
|
|
|
|
import {RoomStateStore} from "./stores/RoomStateStore.js";
|
2020-06-27 02:56:24 +05:30
|
|
|
import {RoomMemberStore} from "./stores/RoomMemberStore.js";
|
2020-04-21 00:56:39 +05:30
|
|
|
import {TimelineFragmentStore} from "./stores/TimelineFragmentStore.js";
|
|
|
|
import {PendingEventStore} from "./stores/PendingEventStore.js";
|
2020-08-31 18:08:03 +05:30
|
|
|
import {UserIdentityStore} from "./stores/UserIdentityStore.js";
|
|
|
|
import {DeviceIdentityStore} from "./stores/DeviceIdentityStore.js";
|
2020-09-01 21:29:59 +05:30
|
|
|
import {OlmSessionStore} from "./stores/OlmSessionStore.js";
|
2020-09-02 17:54:38 +05:30
|
|
|
import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js";
|
2020-09-03 21:19:20 +05:30
|
|
|
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js";
|
2020-09-04 19:01:00 +05:30
|
|
|
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js";
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
export class Transaction {
|
2019-06-27 02:01:36 +05:30
|
|
|
constructor(txn, allowedStoreNames) {
|
|
|
|
this._txn = txn;
|
|
|
|
this._allowedStoreNames = allowedStoreNames;
|
|
|
|
this._stores = {
|
|
|
|
session: null,
|
|
|
|
roomSummary: null,
|
|
|
|
roomTimeline: null,
|
|
|
|
roomState: null,
|
|
|
|
};
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
_idbStore(name) {
|
|
|
|
if (!this._allowedStoreNames.includes(name)) {
|
|
|
|
// more specific error? this is a bug, so maybe not ...
|
|
|
|
throw new StorageError(`Invalid store for transaction: ${name}, only ${this._allowedStoreNames.join(", ")} are allowed.`);
|
|
|
|
}
|
|
|
|
return new Store(this._txn.objectStore(name));
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
_store(name, mapStore) {
|
|
|
|
if (!this._stores[name]) {
|
|
|
|
const idbStore = this._idbStore(name);
|
|
|
|
this._stores[name] = mapStore(idbStore);
|
|
|
|
}
|
|
|
|
return this._stores[name];
|
|
|
|
}
|
2019-02-07 05:50:27 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
get session() {
|
|
|
|
return this._store("session", idbStore => new SessionStore(idbStore));
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
get roomSummary() {
|
|
|
|
return this._store("roomSummary", idbStore => new RoomSummaryStore(idbStore));
|
|
|
|
}
|
2019-02-11 01:55:29 +05:30
|
|
|
|
2019-05-12 23:54:06 +05:30
|
|
|
get timelineFragments() {
|
|
|
|
return this._store("timelineFragments", idbStore => new TimelineFragmentStore(idbStore));
|
|
|
|
}
|
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
get timelineEvents() {
|
|
|
|
return this._store("timelineEvents", idbStore => new TimelineEventStore(idbStore));
|
|
|
|
}
|
2019-02-11 01:55:29 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
get roomState() {
|
|
|
|
return this._store("roomState", idbStore => new RoomStateStore(idbStore));
|
|
|
|
}
|
2019-02-11 01:55:29 +05:30
|
|
|
|
2020-06-27 02:56:24 +05:30
|
|
|
get roomMembers() {
|
|
|
|
return this._store("roomMembers", idbStore => new RoomMemberStore(idbStore));
|
|
|
|
}
|
|
|
|
|
2019-07-27 14:10:56 +05:30
|
|
|
get pendingEvents() {
|
|
|
|
return this._store("pendingEvents", idbStore => new PendingEventStore(idbStore));
|
|
|
|
}
|
|
|
|
|
2020-08-31 18:08:03 +05:30
|
|
|
get userIdentities() {
|
|
|
|
return this._store("userIdentities", idbStore => new UserIdentityStore(idbStore));
|
|
|
|
}
|
|
|
|
|
|
|
|
get deviceIdentities() {
|
|
|
|
return this._store("deviceIdentities", idbStore => new DeviceIdentityStore(idbStore));
|
|
|
|
}
|
|
|
|
|
2020-09-01 21:29:59 +05:30
|
|
|
get olmSessions() {
|
|
|
|
return this._store("olmSessions", idbStore => new OlmSessionStore(idbStore));
|
|
|
|
}
|
2020-09-02 17:54:38 +05:30
|
|
|
|
|
|
|
get inboundGroupSessions() {
|
|
|
|
return this._store("inboundGroupSessions", idbStore => new InboundGroupSessionStore(idbStore));
|
|
|
|
}
|
2020-09-03 21:19:20 +05:30
|
|
|
|
|
|
|
get outboundGroupSessions() {
|
|
|
|
return this._store("outboundGroupSessions", idbStore => new OutboundGroupSessionStore(idbStore));
|
|
|
|
}
|
2020-09-04 19:01:00 +05:30
|
|
|
|
|
|
|
get groupSessionDecryptions() {
|
|
|
|
return this._store("groupSessionDecryptions", idbStore => new OutboundGroupSessionStore(idbStore));
|
|
|
|
}
|
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
complete() {
|
|
|
|
return txnAsPromise(this._txn);
|
|
|
|
}
|
2019-02-05 04:51:50 +05:30
|
|
|
|
2019-06-27 02:01:36 +05:30
|
|
|
abort() {
|
|
|
|
this._txn.abort();
|
|
|
|
}
|
2019-05-12 23:54:06 +05:30
|
|
|
}
|