Replace Vault wrapper class with precise TS types

This commit is contained in:
2025-09-07 14:06:10 -07:00
parent f832191c0b
commit d730428eb8
4 changed files with 31 additions and 30 deletions
+5 -4
View File
@@ -2,7 +2,7 @@ import _ from 'lodash';
import * as Y from 'yjs';
import { openDB } from 'idb';
import { generateId } from './util';
import { Vault } from './vault';
import { getDocsMap, type DocMap } from './vault';
const DB_NAME = 'synced-docs';
const LOCAL_UPDATE_STORE = 'local-updates';
@@ -98,17 +98,18 @@ async function getOrCreateVaultDoc() {
if (!vaultMap.has('docs')) {
vaultMap.set('docs', new Y.Map());
}
return new Vault(vault);
return vault;
}
export const defaultVault = await getOrCreateVaultDoc();
// console.log(defaultVault.doc.getMap().toJSON())
const docsMap = defaultVault.getDocsMap();
const docsMap = getDocsMap(defaultVault.doc);
if (docsMap.size === 0) {
console.log('Running vault migration...');
for (const oldKey of ['foo', 'bar', 'baz']) {
const newId = generateId();
const docInfo = new Y.Map([['title', oldKey]]);
const docInfo = new Y.Map([['title', oldKey]]) as DocMap;
docsMap.set(newId, docInfo);
const tx = db.transaction(LOCAL_UPDATE_STORE, 'readwrite');