refactor: clean up opal-web duplication, dead code, and comment noise

- Deduplicate API_BASE (was defined in both client.js and endpoints.js)
- Extract EMPTY_STATE and persist() helper in auth store (DRY)
- Extract updateByUuid() in tasks store, normalize to .map() pattern
- Remove unused getQueueSize(), Select.svelte, and lib/index.js
- Modernize uuid.js to prefer crypto.randomUUID()
- Strip ~60 redundant comments that restated self-evident code

No behavior changes. Build passes, pre-existing type errors unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 01:03:08 +01:00
parent 41a12fe7a9
commit 8693681660
22 changed files with 110 additions and 470 deletions
+13 -31
View File
@@ -20,10 +20,7 @@ import { generateUUID } from '$lib/utils/uuid.js';
const SYNC_STATE_KEY = 'opal_sync_state';
const CLIENT_ID_KEY = 'opal_client_id';
/**
* Get or create client ID
* @returns {string}
*/
/** @returns {string} */
function getClientId() {
let clientId = getItem(CLIENT_ID_KEY);
if (!clientId) {
@@ -33,10 +30,7 @@ function getClientId() {
return clientId;
}
/**
* Load sync state
* @returns {SyncState}
*/
/** @returns {SyncState} */
function loadSyncState() {
const stored = getItem(SYNC_STATE_KEY);
return {
@@ -48,26 +42,20 @@ function loadSyncState() {
};
}
/**
* Create sync store
*/
function createSyncStore() {
const { subscribe, set, update } = writable(loadSyncState());
return {
subscribe,
/**
* Perform sync
* @returns {Promise<SyncResult>}
*/
/** @returns {Promise<SyncResult>} */
async sync() {
update(state => ({ ...state, status: 'syncing', error: null }));
try {
const state = loadSyncState();
const queue = getQueue();
let result = {
pulled: 0,
pushed: 0,
@@ -75,8 +63,7 @@ function createSyncStore() {
queued_offline: 0,
errors: []
};
// Push queued changes
if (queue.length > 0) {
const tasks = queue.map(q => q.data);
try {
@@ -87,8 +74,7 @@ function createSyncStore() {
result.errors.push(`Failed to push queue: ${error.message}`);
}
}
// Pull changes from server
try {
const changes = await syncAPI.getChanges(state.lastSync, state.clientId);
result.pulled = changes.length;
@@ -96,11 +82,10 @@ function createSyncStore() {
} catch (error) {
result.errors.push(`Failed to pull changes: ${error.message}`);
}
// Update sync state
const now = Math.floor(Date.now() / 1000);
setItem(SYNC_STATE_KEY, { lastSync: now });
update(state => ({
...state,
status: 'idle',
@@ -108,7 +93,7 @@ function createSyncStore() {
queueSize: 0,
error: null
}));
return result;
} catch (error) {
update(state => ({
@@ -119,10 +104,7 @@ function createSyncStore() {
throw error;
}
},
/**
* Update queue size
*/
updateQueueSize() {
update(state => ({
...state,