diff --git a/GOAL.md b/doc/GOAL.md similarity index 100% rename from GOAL.md rename to doc/GOAL.md diff --git a/TODO.md b/doc/TODO.md similarity index 100% rename from TODO.md rename to doc/TODO.md diff --git a/api.md b/doc/api.md similarity index 100% rename from api.md rename to doc/api.md diff --git a/index.html b/index.html new file mode 100644 index 00000000..d0cabfa3 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/matrix.mjs b/prototypes/matrix.mjs similarity index 100% rename from matrix.mjs rename to prototypes/matrix.mjs diff --git a/partialkey.html b/prototypes/partialkey.html similarity index 100% rename from partialkey.html rename to prototypes/partialkey.html diff --git a/typedarray.html b/prototypes/typedarray.html similarity index 100% rename from typedarray.html rename to prototypes/typedarray.html diff --git a/src/index.html b/src/index.html deleted file mode 100644 index fe5dda16..00000000 --- a/src/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/main.js b/src/main.js index 1f8286fd..f98eeb5c 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import Network from "./network.js"; import Session from "./session.js"; -import createIdbStorage from "./storage/idb/factory.js"; +import createIdbStorage from "./storage/idb/create.js"; const HOMESERVER = "http://localhost:8008"; async function getLoginData(username, password) { diff --git a/src/storage/idb/factory.js b/src/storage/idb/create.js similarity index 71% rename from src/storage/idb/factory.js rename to src/storage/idb/create.js index 54cf82fe..3899bef2 100644 --- a/src/storage/idb/factory.js +++ b/src/storage/idb/create.js @@ -1,3 +1,6 @@ +import Storage from "./storage.js"; +import { openDatabase } from "./utils.js"; + export default async function createIdbStorage(databaseName) { const db = await openDatabase(databaseName, createStores); return new Storage(db); @@ -5,8 +8,9 @@ export default async function createIdbStorage(databaseName) { function createStores(db) { db.createObjectStore("sync"); //sync token - db.createObjectStore("roomSummary", "room_id", {unique: true}); - const timeline = db.createObjectStore("roomTimeline", ["room_id", "sort_key"]); + // any way to make keys unique here? + db.createObjectStore("roomSummary", {keyPath: "room_id"}); + const timeline = db.createObjectStore("roomTimeline", {keyPath: ["room_id", "sort_key"]}); timeline.createIndex("by_event_id", ["room_id", "event.event_id"], {unique: true}); // how to get the first/last x events for a room? // we don't want to specify the sort key, but would need an index for the room_id? @@ -14,5 +18,5 @@ function createStores(db) { // still, you also can't have a PK of [room_id, sort_key] and get the last or first events with just the room_id? the only thing that changes it that the PK will provide an inherent sorting that you inherit in an index that only has room_id as keyPath??? There must be a better way, need to write a prototype test for this. // SOLUTION: with numeric keys, you can just us a min/max value to get first/last // db.createObjectStore("members", ["room_id", "state_key"]); - const state = db.createObjectStore("roomState", ["event.room_id", "event.type", "event.state_key"]); + const state = db.createObjectStore("roomState", {keyPath: ["event.room_id", "event.type", "event.state_key"]}); } \ No newline at end of file diff --git a/src/storage/idb/index.js b/src/storage/idb/store-index.js similarity index 71% rename from src/storage/idb/index.js rename to src/storage/idb/store-index.js index 5e5dd7a9..0062364f 100644 --- a/src/storage/idb/index.js +++ b/src/storage/idb/store-index.js @@ -1,6 +1,6 @@ import QueryTarget from "./query-target.js"; -export default class Index extends QueryTarget { +export default class StoreIndex extends QueryTarget { constructor(index) { this._index = index; } diff --git a/src/storage/idb/store.js b/src/storage/idb/store.js index 800bca17..d3ecb1b2 100644 --- a/src/storage/idb/store.js +++ b/src/storage/idb/store.js @@ -1,5 +1,5 @@ import QueryTarget from "./query-target.js"; -import Index from "./index.js"; +import StoreIndex from "./store-index.js"; export default class Store extends QueryTarget { constructor(store) { @@ -11,6 +11,6 @@ export default class Store extends QueryTarget { } index(indexName) { - return new Index(this._store.index(indexName)); + return new StoreIndex(this._store.index(indexName)); } } \ No newline at end of file