stellar-drive 1.2.27 → 1.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -19
- package/dist/auth/loginGuard.d.ts.map +1 -1
- package/dist/auth/loginGuard.js +18 -24
- package/dist/auth/loginGuard.js.map +1 -1
- package/dist/auth/offlineCredentials.d.ts +3 -5
- package/dist/auth/offlineCredentials.d.ts.map +1 -1
- package/dist/auth/offlineCredentials.js +14 -15
- package/dist/auth/offlineCredentials.js.map +1 -1
- package/dist/auth/offlineSession.d.ts +7 -9
- package/dist/auth/offlineSession.d.ts.map +1 -1
- package/dist/auth/offlineSession.js +18 -31
- package/dist/auth/offlineSession.js.map +1 -1
- package/dist/auth/resolveAuthState.d.ts.map +1 -1
- package/dist/auth/resolveAuthState.js +12 -12
- package/dist/auth/resolveAuthState.js.map +1 -1
- package/dist/auth/singleUser.d.ts.map +1 -1
- package/dist/auth/singleUser.js +28 -49
- package/dist/auth/singleUser.js.map +1 -1
- package/dist/bin/install-pwa.d.ts.map +1 -1
- package/dist/bin/install-pwa.js +3315 -958
- package/dist/bin/install-pwa.js.map +1 -1
- package/dist/config.d.ts +23 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -8
- package/dist/config.js.map +1 -1
- package/dist/conflicts.d.ts.map +1 -1
- package/dist/conflicts.js +9 -13
- package/dist/conflicts.js.map +1 -1
- package/dist/database.d.ts +13 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +16 -0
- package/dist/database.js.map +1 -1
- package/dist/demo.d.ts +7 -0
- package/dist/demo.d.ts.map +1 -1
- package/dist/demo.js +51 -3
- package/dist/demo.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +21 -46
- package/dist/engine.js.map +1 -1
- package/dist/entries/toast.d.ts +12 -0
- package/dist/entries/toast.d.ts.map +1 -0
- package/dist/entries/toast.js +11 -0
- package/dist/entries/toast.js.map +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +1 -16
- package/dist/queue.js.map +1 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +9 -21
- package/dist/realtime.js.map +1 -1
- package/dist/stores/toast.d.ts +40 -0
- package/dist/stores/toast.d.ts.map +1 -0
- package/dist/stores/toast.js +39 -0
- package/dist/stores/toast.js.map +1 -0
- package/package.json +13 -1
- package/src/components/GlobalToast.svelte +251 -0
- package/src/components/OfflineToast.svelte +168 -0
package/dist/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiD7D,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO;QACL;YACE,EAAE,EAAE,WAAW;YACf,MAAM,EAAE,WAAW;YACnB,QAAQ,EAAE,aAAa;YACvB,WAAW,EAAE,iBAAiB;YAC9B,SAAS;YACT,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,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AgB,CAAC,EAAE,CAAC;QAChE,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,4CAA4C;QAC9C,CAAC;IACH,CAAC;IAED,mCAAmC;IACnC,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAE/B,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAc;IACtD,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;IACtD,CAAC;AACH,CAAC"}
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAkOH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CAW7D;AAuCD,uDAAuD;AACvD,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AA8HD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AA+DD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB;;;;;;uBA5NF,MAAM;yBAAW,MAAM;;;oBAF5C,MAAM;sBACJ,MAAM;sBAEN,MAAM;;;;;;;;;;;;EA2OrB;AAgMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAO/D;AAuCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAcvC;AAq7CD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAC/B,KAAK,GAAE,OAAe,EACtB,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAqPf;AAgpBD,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAoerD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAqEpD;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CA2BrD;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAuEvD"}
|
package/dist/engine.js
CHANGED
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
* @see {@link ./realtime.ts} - Supabase Realtime WebSocket subscriptions
|
|
60
60
|
* @see {@link ./config.ts} - Engine configuration and table definitions
|
|
61
61
|
*/
|
|
62
|
-
import { getEngineConfig, getDexieTableFor, waitForDb } from './config';
|
|
63
|
-
import { clearDbResetFlag } from './database';
|
|
62
|
+
import { getEngineConfig, getDexieTableFor, waitForDb, findTableConfig, RECENTLY_MODIFIED_TTL_MS } from './config';
|
|
63
|
+
import { clearDbResetFlag, getDb, TABLE } from './database';
|
|
64
64
|
import { debugLog, debugWarn, debugError, isDebugMode } from './debug';
|
|
65
65
|
import { getPendingSync, removeSyncItem, bulkRemoveSyncItems, incrementRetry, getPendingEntityIds, cleanupFailedItems, coalescePendingOps, queueSyncOperation } from './queue';
|
|
66
66
|
import { getDeviceId } from './deviceId';
|
|
@@ -71,7 +71,7 @@ import { isOnline } from './stores/network';
|
|
|
71
71
|
import { getSession } from './supabase/auth';
|
|
72
72
|
import { supabase as supabaseProxy } from './supabase/client';
|
|
73
73
|
import { getOfflineCredentials } from './auth/offlineCredentials';
|
|
74
|
-
import {
|
|
74
|
+
import { getOfflineSession, createOfflineSession } from './auth/offlineSession';
|
|
75
75
|
import { validateSchema } from './supabase/validate';
|
|
76
76
|
import { formatBytes } from './utils';
|
|
77
77
|
import { getDiagnostics } from './diagnostics';
|
|
@@ -85,18 +85,6 @@ import { isDemoMode } from './demo';
|
|
|
85
85
|
// so we can't read config values at module load time (they'd be undefined).
|
|
86
86
|
// Each function reads from the live config on every call to support hot-reloading.
|
|
87
87
|
// =============================================================================
|
|
88
|
-
/**
|
|
89
|
-
* Get the Dexie database instance from the engine config.
|
|
90
|
-
*
|
|
91
|
-
* @returns The initialized Dexie database
|
|
92
|
-
* @throws {Error} If the database hasn't been initialized via `initEngine()`
|
|
93
|
-
*/
|
|
94
|
-
function getDb() {
|
|
95
|
-
const db = getEngineConfig().db;
|
|
96
|
-
if (!db)
|
|
97
|
-
throw new Error('Database not initialized. Provide db or database config to initEngine().');
|
|
98
|
-
return db;
|
|
99
|
-
}
|
|
100
88
|
/**
|
|
101
89
|
* Get the Supabase client instance.
|
|
102
90
|
*
|
|
@@ -121,7 +109,7 @@ function getSupabase() {
|
|
|
121
109
|
* @returns The local Dexie table name (may include a prefix)
|
|
122
110
|
*/
|
|
123
111
|
function getDexieTableName(name) {
|
|
124
|
-
const table =
|
|
112
|
+
const table = findTableConfig(name);
|
|
125
113
|
return table ? getDexieTableFor(table) : name;
|
|
126
114
|
}
|
|
127
115
|
/**
|
|
@@ -135,8 +123,7 @@ function getDexieTableName(name) {
|
|
|
135
123
|
* @returns PostgREST column selector (e.g., `"id,name,updated_at"` or `"*"`)
|
|
136
124
|
*/
|
|
137
125
|
function getColumns(name) {
|
|
138
|
-
|
|
139
|
-
return table?.columns || '*';
|
|
126
|
+
return findTableConfig(name)?.columns || '*';
|
|
140
127
|
}
|
|
141
128
|
/**
|
|
142
129
|
* Guarantee mandatory system-field defaults on an outbound sync payload.
|
|
@@ -198,8 +185,7 @@ function filterPayloadToSchema(tableName, payload) {
|
|
|
198
185
|
* @returns `true` if the table is a singleton
|
|
199
186
|
*/
|
|
200
187
|
function isSingletonTable(name) {
|
|
201
|
-
|
|
202
|
-
return table?.isSingleton || false;
|
|
188
|
+
return findTableConfig(name)?.isSingleton || false;
|
|
203
189
|
}
|
|
204
190
|
// --- Timing & Threshold Config Accessors ---
|
|
205
191
|
// Each has a sensible default if not configured by the consumer.
|
|
@@ -451,18 +437,7 @@ let realtimeWasTornDown = false;
|
|
|
451
437
|
let lastRealtimeStartAt = 0;
|
|
452
438
|
/** Debounce delay for visibility-change syncs (prevents rapid tab-switching spam) */
|
|
453
439
|
const VISIBILITY_SYNC_DEBOUNCE_MS = 1000;
|
|
454
|
-
|
|
455
|
-
* How long a locally-modified entity is "protected" from being overwritten by pull.
|
|
456
|
-
*
|
|
457
|
-
* When the user writes locally, the entity is marked as recently modified.
|
|
458
|
-
* During pull, if a remote version arrives within this TTL, it's skipped to
|
|
459
|
-
* prevent the pull from reverting the user's fresh local change before the
|
|
460
|
-
* push has a chance to send it to the server.
|
|
461
|
-
*
|
|
462
|
-
* Industry standard range: 500ms–2000ms. We use 2s to cover the sync debounce
|
|
463
|
-
* window (1s default) plus network latency with margin.
|
|
464
|
-
*/
|
|
465
|
-
const RECENTLY_MODIFIED_TTL_MS = 2000;
|
|
440
|
+
/* RECENTLY_MODIFIED_TTL_MS is imported from './config' — see that module for docs. */
|
|
466
441
|
/**
|
|
467
442
|
* Map of entity ID → timestamp for recently modified entities.
|
|
468
443
|
*
|
|
@@ -906,7 +881,7 @@ async function forceFullSync() {
|
|
|
906
881
|
}
|
|
907
882
|
try {
|
|
908
883
|
const config = getEngineConfig();
|
|
909
|
-
const db =
|
|
884
|
+
const db = getDb();
|
|
910
885
|
await resetSyncCursor();
|
|
911
886
|
// Clear local data (except sync queue - keep pending changes)
|
|
912
887
|
const entityTables = config.tables.map((t) => db.table(getDexieTableFor(t)));
|
|
@@ -972,7 +947,7 @@ async function pullRemoteChanges(minCursor) {
|
|
|
972
947
|
throw new Error('Not authenticated. Please sign in to sync.');
|
|
973
948
|
}
|
|
974
949
|
const config = getEngineConfig();
|
|
975
|
-
const db =
|
|
950
|
+
const db = getDb();
|
|
976
951
|
const supabase = config.supabase;
|
|
977
952
|
// Use the later of stored cursor or provided minCursor
|
|
978
953
|
// This prevents re-fetching records we just pushed in this sync cycle
|
|
@@ -1097,7 +1072,7 @@ async function pullRemoteChanges(minCursor) {
|
|
|
1097
1072
|
// Check if any table has data to process (avoid opening transaction on empty pull)
|
|
1098
1073
|
const hasData = results.some((r) => r.data && r.data.length > 0);
|
|
1099
1074
|
if (hasData) {
|
|
1100
|
-
await db.transaction('rw', [...entityTables, db.table('syncQueue'), db.table(
|
|
1075
|
+
await db.transaction('rw', [...entityTables, db.table('syncQueue'), db.table(TABLE.CONFLICT_HISTORY)], async () => {
|
|
1101
1076
|
for (let i = 0; i < config.tables.length; i++) {
|
|
1102
1077
|
const data = results[i].data;
|
|
1103
1078
|
await applyRemoteWithConflictResolution(tableNames[i], data, db.table(getDexieTableFor(config.tables[i])));
|
|
@@ -1269,8 +1244,8 @@ async function pushPendingOps() {
|
|
|
1269
1244
|
if (!schema)
|
|
1270
1245
|
return 0;
|
|
1271
1246
|
// Resolve schema keys from supabase names (strip prefix)
|
|
1272
|
-
const configA =
|
|
1273
|
-
const configB =
|
|
1247
|
+
const configA = findTableConfig(tableA);
|
|
1248
|
+
const configB = findTableConfig(tableB);
|
|
1274
1249
|
const keyA = configA?.schemaKey || tableA;
|
|
1275
1250
|
const keyB = configB?.schemaKey || tableB;
|
|
1276
1251
|
const aIsChild = isChildTable(schema, keyA);
|
|
@@ -2347,7 +2322,7 @@ async function fullReconciliation() {
|
|
|
2347
2322
|
if (!userId)
|
|
2348
2323
|
return 0;
|
|
2349
2324
|
const config = getEngineConfig();
|
|
2350
|
-
const db =
|
|
2325
|
+
const db = getDb();
|
|
2351
2326
|
const supabase = config.supabase;
|
|
2352
2327
|
// Check if cursor is stale enough to warrant full reconciliation
|
|
2353
2328
|
const cursor = getLastSyncCursor(userId);
|
|
@@ -2438,7 +2413,7 @@ async function hydrateFromRemote() {
|
|
|
2438
2413
|
return;
|
|
2439
2414
|
}
|
|
2440
2415
|
const config = getEngineConfig();
|
|
2441
|
-
const db =
|
|
2416
|
+
const db = getDb();
|
|
2442
2417
|
const supabase = config.supabase;
|
|
2443
2418
|
// Get user ID for sync cursor isolation
|
|
2444
2419
|
const userId = await getCurrentUserId();
|
|
@@ -2599,7 +2574,7 @@ async function cleanupLocalTombstones() {
|
|
|
2599
2574
|
cutoffDate.setDate(cutoffDate.getDate() - tombstoneMaxAgeDays);
|
|
2600
2575
|
const cutoffStr = cutoffDate.toISOString();
|
|
2601
2576
|
const config = getEngineConfig();
|
|
2602
|
-
const db =
|
|
2577
|
+
const db = getDb();
|
|
2603
2578
|
let totalDeleted = 0;
|
|
2604
2579
|
try {
|
|
2605
2580
|
const entityTables = config.tables.map((t) => db.table(getDexieTableFor(t)));
|
|
@@ -2710,7 +2685,7 @@ async function debugTombstones(options) {
|
|
|
2710
2685
|
cutoffDate.setDate(cutoffDate.getDate() - tombstoneMaxAgeDays);
|
|
2711
2686
|
const cutoffStr = cutoffDate.toISOString();
|
|
2712
2687
|
const config = getEngineConfig();
|
|
2713
|
-
const db =
|
|
2688
|
+
const db = getDb();
|
|
2714
2689
|
const supabase = config.supabase;
|
|
2715
2690
|
debugLog('=== TOMBSTONE DEBUG ===');
|
|
2716
2691
|
debugLog(`Cutoff date (${tombstoneMaxAgeDays} days ago): ${cutoffStr}`);
|
|
@@ -2950,7 +2925,7 @@ export async function startSyncEngine() {
|
|
|
2950
2925
|
debugWarn('[Engine] Cached credentials do not match current user - skipping offline session creation');
|
|
2951
2926
|
return;
|
|
2952
2927
|
}
|
|
2953
|
-
const existingSession = await
|
|
2928
|
+
const existingSession = await getOfflineSession();
|
|
2954
2929
|
if (!existingSession) {
|
|
2955
2930
|
await createOfflineSession(credentials.userId);
|
|
2956
2931
|
debugLog('[Engine] Offline session created from cached credentials');
|
|
@@ -3029,7 +3004,7 @@ export async function startSyncEngine() {
|
|
|
3029
3004
|
credentials.email !== currentSession.user.email) {
|
|
3030
3005
|
return;
|
|
3031
3006
|
}
|
|
3032
|
-
const existingSession = await
|
|
3007
|
+
const existingSession = await getOfflineSession();
|
|
3033
3008
|
if (!existingSession) {
|
|
3034
3009
|
await createOfflineSession(credentials.userId);
|
|
3035
3010
|
debugLog('[Engine] Offline session created on cold start');
|
|
@@ -3342,17 +3317,17 @@ export async function stopSyncEngine() {
|
|
|
3342
3317
|
*/
|
|
3343
3318
|
export async function clearLocalCache() {
|
|
3344
3319
|
const config = getEngineConfig();
|
|
3345
|
-
const db =
|
|
3320
|
+
const db = getDb();
|
|
3346
3321
|
// Get user ID before clearing to remove their sync cursor
|
|
3347
3322
|
const userId = await getCurrentUserId();
|
|
3348
3323
|
const entityTables = config.tables.map((t) => db.table(getDexieTableFor(t)));
|
|
3349
|
-
const metaTables = [db.table('syncQueue'), db.table(
|
|
3324
|
+
const metaTables = [db.table('syncQueue'), db.table(TABLE.CONFLICT_HISTORY)];
|
|
3350
3325
|
await db.transaction('rw', [...entityTables, ...metaTables], async () => {
|
|
3351
3326
|
for (const t of entityTables) {
|
|
3352
3327
|
await t.clear();
|
|
3353
3328
|
}
|
|
3354
3329
|
await db.table('syncQueue').clear();
|
|
3355
|
-
await db.table(
|
|
3330
|
+
await db.table(TABLE.CONFLICT_HISTORY).clear();
|
|
3356
3331
|
});
|
|
3357
3332
|
// Reset sync cursor (user-specific) and hydration flag
|
|
3358
3333
|
if (typeof localStorage !== 'undefined') {
|