eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

47 lines
1.6 KiB
JavaScript

class DraftStore {
constructor(indexedDB) {
this.indexedDB = indexedDB;
}
async database() {
if (!this.pending)
this.pending = new Promise((resolve, reject) => {
const request = this.indexedDB.open('wishforge-unconfirmed-drafts', 1);
request.onupgradeneeded = () => request.result.createObjectStore('drafts', { keyPath: 'id' });
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
});
return this.pending;
}
async operation(mode, action) {
const db = await this.database();
return new Promise((resolve, reject) => {
const tx = db.transaction('drafts', mode);
const request = action(tx.objectStore('drafts'));
let value;
request.onsuccess = () => {
value = request.result;
};
tx.oncomplete = () => resolve(value);
tx.onerror = () => reject(tx.error);
tx.onabort = () => reject(tx.error);
});
}
put(record) {
if (
record.text.length + record.baseText.length > 2 * 1024 * 1024 ||
new TextEncoder().encode(record.text + record.baseText).byteLength > 2 * 1024 * 1024
)
throw new Error('Draft exceeds the 2 MiB local recovery limit');
return this.operation('readwrite', store => store.put(record));
}
remove(id) {
return this.operation('readwrite', store => store.delete(id));
}
async list(scope) {
return (await this.operation('readonly', store => store.getAll()))
.filter(record => record.scope === scope)
.sort((a, b) => b.updatedAt - a.updatedAt);
}
}
module.exports = { DraftStore };