diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/hub-client.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/hub-client.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js b/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js index 7ba6f92..dbd5037 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/hub-client.js @@ -12,8 +12,14 @@ const AUTH_KEY = 'mb_auth'; // should not cost a round trip before the first click works. const TOKEN_RENEW_MARGIN_S = 600; const IDB_NAME = 'meshbay'; -const IDB_VERSION = 1; +// **2**, for the `playlists` store (docs/playlists.md §14.2). The version and +// every store this database has live here, in one place, and `openDB` is +// exported so nothing else opens it at a version of its own — two modules +// disagreeing about the version is a `VersionError` thrown at whichever of +// them happens to run second. +const IDB_VERSION = 2; const IDB_STORE = 'group_indexes'; +const IDB_PLAYLISTS = 'playlists'; function navigate(path) { window.location.hash = path; @@ -29,6 +35,13 @@ function openDB() { if (!db.objectStoreNames.contains(IDB_STORE)) { db.createObjectStore(IDB_STORE, { keyPath: 'groupId' }); } + // Added at version 2. Out-of-line keys: the records are the playlist + // objects themselves, and the key is `userId|kind` — two accounts on one + // browser is ordinary, and so is a sign-out that never runs, so the + // separation belongs in the key rather than in a cleanup path. + if (!db.objectStoreNames.contains(IDB_PLAYLISTS)) { + db.createObjectStore(IDB_PLAYLISTS); + } }; req.onsuccess = () => resolve(req.result); req.onerror = () => reject(req.error); @@ -301,8 +314,11 @@ async function hubFetch(path, { method = 'GET', body, token, _retried } = {}) { return r.json(); } +// `openDB` and `IDB_PLAYLISTS` are exported so playlists.js reads and writes +// its own store without owning the database's version. export { HUB, navigate, session, + openDB, IDB_PLAYLISTS, cacheGroupIndex, getCachedGroupIndex, getAllCachedIndexes, clearAllCachedIndexes, _storeBundleKey, _loadBundleKey, _storeRecoveryKey, _loadRecoveryKey, _clearKeyDB, loadAuth, saveAuth, setAuth, setAuthChangeListener, |