local-lite 1.0.1 → 1.0.3
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/dist/actions/manager.js +6 -2
- package/dist/actions/store.js +33 -19
- package/dist/adapters/local/expo-sqlite.js +4 -2
- package/dist/adapters/local/libsql.js +3 -1
- package/dist/adapters/local/op-sqlite.js +2 -1
- package/dist/adapters/network/index.js +10 -5
- package/dist/adapters/remote/convex.js +37 -10
- package/dist/adapters/remote/firestore.js +11 -4
- package/dist/adapters/remote/self-hosted.js +9 -5
- package/dist/adapters/remote/supabase.js +95 -29
- package/dist/auth/apple.js +8 -4
- package/dist/auth/github.js +15 -7
- package/dist/auth/google.js +7 -4
- package/dist/auth/identity.js +5 -1
- package/dist/auth/local.js +74 -21
- package/dist/auth/microsoft.js +22 -8
- package/dist/auth/session.js +45 -34
- package/dist/auth/unified.js +3 -2
- package/dist/backups/cloud-storage.js +10 -7
- package/dist/backups/encryption.js +4 -2
- package/dist/backups/onedrive.js +3 -3
- package/dist/backups/operations.js +4 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/resolve-local.js +18 -6
- package/dist/config/resolve-remote.js +2 -1
- package/dist/core/client.d.ts +2 -2
- package/dist/core/client.js +64 -26
- package/dist/core/index.d.ts +1 -1
- package/dist/core/maintenance.js +5 -4
- package/dist/core/meta-store.js +3 -3
- package/dist/core/outbox-store.js +32 -25
- package/dist/core/query-builder.js +23 -10
- package/dist/core/query.js +19 -7
- package/dist/core/schema-manager.js +6 -2
- package/dist/core/sync-worker.js +38 -12
- package/dist/core/table-manager.js +8 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.js +234 -54
- package/dist/devtools/SyncInspector.js +260 -37
- package/dist/email/index.js +46 -18
- package/dist/keys/generator.js +4 -1
- package/dist/keys/manager.js +22 -4
- package/dist/keys/signed-token.js +12 -4
- package/dist/keys/store.js +23 -16
- package/dist/kv/manager.js +5 -2
- package/dist/kv/store.js +13 -13
- package/dist/react/auth.js +12 -12
- package/dist/react/backups.js +1 -1
- package/dist/react/index.js +14 -9
- package/dist/react/runner.js +1 -1
- package/dist/react/status.js +6 -2
- package/dist/reactive/event-emitter.js +2 -2
- package/dist/scheduler/cron.js +3 -1
- package/dist/scheduler/store.js +37 -31
- package/dist/schema/generator.js +37 -34
- package/dist/search/manager.js +3 -1
- package/dist/search/store.js +17 -16
- package/dist/server/email.js +3 -2
- package/dist/server/index.js +4 -4
- package/dist/server/sync.js +11 -4
- package/dist/storage/driver.js +2 -1
- package/dist/storage/expo.js +5 -2
- package/dist/storage/manager.js +3 -1
- package/dist/storage/store.js +26 -25
- package/dist/utils/dynamic.js +4 -2
- package/dist/utils/logger.js +13 -6
- package/dist/utils/portability.js +21 -9
- package/package.json +1 -1
package/dist/keys/manager.js
CHANGED
|
@@ -55,11 +55,19 @@ class ApiKeyManager {
|
|
|
55
55
|
*/
|
|
56
56
|
async verify(rawKey, options = {}) {
|
|
57
57
|
if (!rawKey || typeof rawKey !== 'string') {
|
|
58
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
valid: false,
|
|
60
|
+
status: 'MALFORMED',
|
|
61
|
+
error: 'API key is missing or not a string',
|
|
62
|
+
};
|
|
59
63
|
}
|
|
60
64
|
// 1. Instant syntactic & checksum format verification
|
|
61
65
|
if (!(0, generator_js_1.verifyApiKeyFormat)(rawKey, options.expectedPrefix)) {
|
|
62
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
status: 'MALFORMED',
|
|
69
|
+
error: 'Invalid API key format or checksum',
|
|
70
|
+
};
|
|
63
71
|
}
|
|
64
72
|
// 2. Hash and lookup in database
|
|
65
73
|
const computedHash = (0, generator_js_1.hashApiKey)(rawKey);
|
|
@@ -69,11 +77,21 @@ class ApiKeyManager {
|
|
|
69
77
|
}
|
|
70
78
|
// 3. Check revocation
|
|
71
79
|
if (record.revoked) {
|
|
72
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
valid: false,
|
|
82
|
+
status: 'REVOKED',
|
|
83
|
+
record,
|
|
84
|
+
error: 'API key has been revoked',
|
|
85
|
+
};
|
|
73
86
|
}
|
|
74
87
|
// 4. Check expiration
|
|
75
88
|
if (record.expiresAt && record.expiresAt <= Date.now()) {
|
|
76
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
valid: false,
|
|
91
|
+
status: 'EXPIRED',
|
|
92
|
+
record,
|
|
93
|
+
error: 'API key has expired',
|
|
94
|
+
};
|
|
77
95
|
}
|
|
78
96
|
// 5. Update last_used_at timestamp
|
|
79
97
|
if (options.updateLastUsed !== false) {
|
|
@@ -22,9 +22,11 @@ function base64UrlEncode(bytes) {
|
|
|
22
22
|
const second = bytes[i + 1];
|
|
23
23
|
const third = bytes[i + 2];
|
|
24
24
|
result += B64URL_ALPHABET[first >> 2];
|
|
25
|
-
result +=
|
|
25
|
+
result +=
|
|
26
|
+
B64URL_ALPHABET[((first & 3) << 4) | (second === undefined ? 0 : second >> 4)];
|
|
26
27
|
if (second !== undefined) {
|
|
27
|
-
result +=
|
|
28
|
+
result +=
|
|
29
|
+
B64URL_ALPHABET[((second & 15) << 2) | (third === undefined ? 0 : third >> 6)];
|
|
28
30
|
}
|
|
29
31
|
if (third !== undefined) {
|
|
30
32
|
result += B64URL_ALPHABET[third & 63];
|
|
@@ -109,7 +111,10 @@ function verifySignedToken(token, secret, options = {}) {
|
|
|
109
111
|
}
|
|
110
112
|
const parts = token.trim().split('.');
|
|
111
113
|
if (parts.length !== 3) {
|
|
112
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
valid: false,
|
|
116
|
+
error: 'Malformed token structure: expected 3 parts',
|
|
117
|
+
};
|
|
113
118
|
}
|
|
114
119
|
const [headerB64, payloadB64, signature] = parts;
|
|
115
120
|
const content = `${headerB64}.${payloadB64}`;
|
|
@@ -125,7 +130,10 @@ function verifySignedToken(token, secret, options = {}) {
|
|
|
125
130
|
parsedPayload = JSON.parse(jsonStr);
|
|
126
131
|
}
|
|
127
132
|
catch (err) {
|
|
128
|
-
return {
|
|
133
|
+
return {
|
|
134
|
+
valid: false,
|
|
135
|
+
error: `Failed to decode token payload: ${err?.message || err}`,
|
|
136
|
+
};
|
|
129
137
|
}
|
|
130
138
|
// 3. Verify Expiration
|
|
131
139
|
const clockSkewMs = (options.clockSkewSeconds ?? 60) * 1000;
|
package/dist/keys/store.js
CHANGED
|
@@ -10,7 +10,11 @@ function mapKeyRow(r) {
|
|
|
10
10
|
prefix: r.prefix,
|
|
11
11
|
display: r.display,
|
|
12
12
|
keyHash: r.key_hash,
|
|
13
|
-
metadata: r.metadata
|
|
13
|
+
metadata: r.metadata
|
|
14
|
+
? typeof r.metadata === 'string'
|
|
15
|
+
? JSON.parse(r.metadata)
|
|
16
|
+
: r.metadata
|
|
17
|
+
: undefined,
|
|
14
18
|
createdAt: Number(r.created_at || 0),
|
|
15
19
|
expiresAt: r.expires_at != null ? Number(r.expires_at) : null,
|
|
16
20
|
lastUsedAt: r.last_used_at != null ? Number(r.last_used_at) : null,
|
|
@@ -23,25 +27,25 @@ class KeyStore {
|
|
|
23
27
|
* Initializes the API keys schema and indexes if they do not exist.
|
|
24
28
|
*/
|
|
25
29
|
static async ensureSchema(db, tableName = exports.DEFAULT_KEYS_TABLE) {
|
|
26
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
27
|
-
id TEXT PRIMARY KEY,
|
|
28
|
-
name TEXT NOT NULL,
|
|
29
|
-
prefix TEXT NOT NULL,
|
|
30
|
-
display TEXT NOT NULL,
|
|
31
|
-
key_hash TEXT NOT NULL UNIQUE,
|
|
32
|
-
metadata TEXT,
|
|
33
|
-
created_at INTEGER NOT NULL,
|
|
34
|
-
expires_at INTEGER,
|
|
35
|
-
last_used_at INTEGER,
|
|
36
|
-
revoked INTEGER NOT NULL DEFAULT 0,
|
|
37
|
-
revoked_at INTEGER
|
|
30
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
31
|
+
id TEXT PRIMARY KEY,
|
|
32
|
+
name TEXT NOT NULL,
|
|
33
|
+
prefix TEXT NOT NULL,
|
|
34
|
+
display TEXT NOT NULL,
|
|
35
|
+
key_hash TEXT NOT NULL UNIQUE,
|
|
36
|
+
metadata TEXT,
|
|
37
|
+
created_at INTEGER NOT NULL,
|
|
38
|
+
expires_at INTEGER,
|
|
39
|
+
last_used_at INTEGER,
|
|
40
|
+
revoked INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
revoked_at INTEGER
|
|
38
42
|
);`);
|
|
39
43
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_hash ON ${tableName} (key_hash);`);
|
|
40
44
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_revoked ON ${tableName} (revoked, expires_at);`);
|
|
41
45
|
}
|
|
42
46
|
static async insertRecord(db, tableName = exports.DEFAULT_KEYS_TABLE, record) {
|
|
43
|
-
await db.execute(`INSERT INTO ${tableName} (
|
|
44
|
-
id, name, prefix, display, key_hash, metadata, created_at, expires_at, last_used_at, revoked, revoked_at
|
|
47
|
+
await db.execute(`INSERT INTO ${tableName} (
|
|
48
|
+
id, name, prefix, display, key_hash, metadata, created_at, expires_at, last_used_at, revoked, revoked_at
|
|
45
49
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
46
50
|
record.id,
|
|
47
51
|
record.name,
|
|
@@ -69,7 +73,10 @@ class KeyStore {
|
|
|
69
73
|
return mapKeyRow(rows[0]);
|
|
70
74
|
}
|
|
71
75
|
static async updateLastUsed(db, tableName = exports.DEFAULT_KEYS_TABLE, id, timestamp) {
|
|
72
|
-
await db.execute(`UPDATE ${tableName} SET last_used_at = ? WHERE id = ?;`, [
|
|
76
|
+
await db.execute(`UPDATE ${tableName} SET last_used_at = ? WHERE id = ?;`, [
|
|
77
|
+
timestamp,
|
|
78
|
+
id,
|
|
79
|
+
]);
|
|
73
80
|
}
|
|
74
81
|
static async revoke(db, tableName = exports.DEFAULT_KEYS_TABLE, id) {
|
|
75
82
|
const now = Date.now();
|
package/dist/kv/manager.js
CHANGED
|
@@ -11,7 +11,8 @@ class KVManager {
|
|
|
11
11
|
constructor(db, eventsOrOptions, options) {
|
|
12
12
|
this.db = db;
|
|
13
13
|
let opts = {};
|
|
14
|
-
if (eventsOrOptions &&
|
|
14
|
+
if (eventsOrOptions &&
|
|
15
|
+
typeof eventsOrOptions.emit === 'function') {
|
|
15
16
|
this.events = eventsOrOptions;
|
|
16
17
|
opts = options || {};
|
|
17
18
|
}
|
|
@@ -117,7 +118,9 @@ class KVManager {
|
|
|
117
118
|
if (!options.passphrase) {
|
|
118
119
|
throw new Error('Passphrase is required to store encrypted secret.');
|
|
119
120
|
}
|
|
120
|
-
const strValue = typeof secretValue === 'string'
|
|
121
|
+
const strValue = typeof secretValue === 'string'
|
|
122
|
+
? secretValue
|
|
123
|
+
: JSON.stringify(secretValue);
|
|
121
124
|
const plainBytes = new TextEncoder().encode(strValue);
|
|
122
125
|
const encryptedBytes = await (0, encryption_js_1.encryptBackupData)(plainBytes, options.passphrase);
|
|
123
126
|
const encryptedBase64 = (0, signed_token_js_1.base64UrlEncode)(encryptedBytes);
|
package/dist/kv/store.js
CHANGED
|
@@ -31,23 +31,23 @@ function mapKVRow(r) {
|
|
|
31
31
|
}
|
|
32
32
|
class KVStore {
|
|
33
33
|
static async ensureSchema(db, tableName = exports.DEFAULT_KV_TABLE) {
|
|
34
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
35
|
-
key TEXT PRIMARY KEY,
|
|
36
|
-
value TEXT NOT NULL,
|
|
37
|
-
type TEXT NOT NULL,
|
|
38
|
-
created_at INTEGER NOT NULL,
|
|
39
|
-
updated_at INTEGER NOT NULL,
|
|
40
|
-
expires_at INTEGER
|
|
34
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
35
|
+
key TEXT PRIMARY KEY,
|
|
36
|
+
value TEXT NOT NULL,
|
|
37
|
+
type TEXT NOT NULL,
|
|
38
|
+
created_at INTEGER NOT NULL,
|
|
39
|
+
updated_at INTEGER NOT NULL,
|
|
40
|
+
expires_at INTEGER
|
|
41
41
|
);`);
|
|
42
42
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_expires ON ${tableName} (expires_at);`);
|
|
43
43
|
}
|
|
44
44
|
static async set(db, tableName = exports.DEFAULT_KV_TABLE, key, valueStr, type, now, expiresAt) {
|
|
45
|
-
await db.execute(`INSERT INTO ${tableName} (key, value, type, created_at, updated_at, expires_at)
|
|
46
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
47
|
-
ON CONFLICT(key) DO UPDATE SET
|
|
48
|
-
value = excluded.value,
|
|
49
|
-
type = excluded.type,
|
|
50
|
-
updated_at = excluded.updated_at,
|
|
45
|
+
await db.execute(`INSERT INTO ${tableName} (key, value, type, created_at, updated_at, expires_at)
|
|
46
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
47
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
48
|
+
value = excluded.value,
|
|
49
|
+
type = excluded.type,
|
|
50
|
+
updated_at = excluded.updated_at,
|
|
51
51
|
expires_at = excluded.expires_at;`, [key, valueStr, type, now, now, expiresAt]);
|
|
52
52
|
}
|
|
53
53
|
static async get(db, tableName = exports.DEFAULT_KV_TABLE, key) {
|
package/dist/react/auth.js
CHANGED
|
@@ -19,19 +19,19 @@ function useGoogleAuth(client) {
|
|
|
19
19
|
let isMounted = true;
|
|
20
20
|
client
|
|
21
21
|
.getUser()
|
|
22
|
-
.then(currentUser => {
|
|
22
|
+
.then((currentUser) => {
|
|
23
23
|
if (isMounted) {
|
|
24
24
|
setUser(currentUser);
|
|
25
25
|
setLoading(false);
|
|
26
26
|
}
|
|
27
27
|
})
|
|
28
|
-
.catch(err => {
|
|
28
|
+
.catch((err) => {
|
|
29
29
|
if (isMounted) {
|
|
30
30
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
31
31
|
setLoading(false);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
34
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
35
35
|
if (isMounted) {
|
|
36
36
|
setUser(updatedUser);
|
|
37
37
|
}
|
|
@@ -108,19 +108,19 @@ function useMicrosoftAuth(client) {
|
|
|
108
108
|
let isMounted = true;
|
|
109
109
|
client
|
|
110
110
|
.getUser()
|
|
111
|
-
.then(currentUser => {
|
|
111
|
+
.then((currentUser) => {
|
|
112
112
|
if (isMounted) {
|
|
113
113
|
setUser(currentUser);
|
|
114
114
|
setLoading(false);
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
|
-
.catch(err => {
|
|
117
|
+
.catch((err) => {
|
|
118
118
|
if (isMounted) {
|
|
119
119
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
120
120
|
setLoading(false);
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
123
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
124
124
|
if (isMounted) {
|
|
125
125
|
setUser(updatedUser);
|
|
126
126
|
}
|
|
@@ -197,19 +197,19 @@ function useGitHubAuth(client) {
|
|
|
197
197
|
let isMounted = true;
|
|
198
198
|
client
|
|
199
199
|
.getUser()
|
|
200
|
-
.then(currentUser => {
|
|
200
|
+
.then((currentUser) => {
|
|
201
201
|
if (isMounted) {
|
|
202
202
|
setUser(currentUser);
|
|
203
203
|
setLoading(false);
|
|
204
204
|
}
|
|
205
205
|
})
|
|
206
|
-
.catch(err => {
|
|
206
|
+
.catch((err) => {
|
|
207
207
|
if (isMounted) {
|
|
208
208
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
209
209
|
setLoading(false);
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
212
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
213
213
|
if (isMounted) {
|
|
214
214
|
setUser(updatedUser);
|
|
215
215
|
}
|
|
@@ -286,19 +286,19 @@ function useAppleAuth(client) {
|
|
|
286
286
|
let isMounted = true;
|
|
287
287
|
client
|
|
288
288
|
.getUser()
|
|
289
|
-
.then(currentUser => {
|
|
289
|
+
.then((currentUser) => {
|
|
290
290
|
if (isMounted) {
|
|
291
291
|
setUser(currentUser);
|
|
292
292
|
setLoading(false);
|
|
293
293
|
}
|
|
294
294
|
})
|
|
295
|
-
.catch(err => {
|
|
295
|
+
.catch((err) => {
|
|
296
296
|
if (isMounted) {
|
|
297
297
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
298
298
|
setLoading(false);
|
|
299
299
|
}
|
|
300
300
|
});
|
|
301
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
301
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
302
302
|
if (isMounted) {
|
|
303
303
|
setUser(updatedUser);
|
|
304
304
|
}
|
package/dist/react/backups.js
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -52,10 +52,7 @@ function areRowsEqual(a, b) {
|
|
|
52
52
|
const bVal = bObj[k];
|
|
53
53
|
if (aVal === bVal)
|
|
54
54
|
continue;
|
|
55
|
-
if (aVal &&
|
|
56
|
-
bVal &&
|
|
57
|
-
typeof aVal === 'object' &&
|
|
58
|
-
typeof bVal === 'object') {
|
|
55
|
+
if (aVal && bVal && typeof aVal === 'object' && typeof bVal === 'object') {
|
|
59
56
|
if (Array.isArray(aVal) !== Array.isArray(bVal))
|
|
60
57
|
return false;
|
|
61
58
|
if (JSON.stringify(aVal) !== JSON.stringify(bVal))
|
|
@@ -331,7 +328,7 @@ function normalizeMultiQueries(input) {
|
|
|
331
328
|
*/
|
|
332
329
|
function useLiveQueries(client, queries) {
|
|
333
330
|
const signature = (0, react_1.useMemo)(() => {
|
|
334
|
-
return JSON.stringify(queries, (_, val) =>
|
|
331
|
+
return JSON.stringify(queries, (_, val) => typeof val === 'function' ? 'fn' : val);
|
|
335
332
|
}, [queries]);
|
|
336
333
|
const items = (0, react_1.useMemo)(() => normalizeMultiQueries(queries), [signature]);
|
|
337
334
|
const clientScope = getClientScope(client);
|
|
@@ -374,7 +371,8 @@ function useLiveQueries(client, queries) {
|
|
|
374
371
|
}
|
|
375
372
|
catch (err) {
|
|
376
373
|
const msg = String(err?.message || err || '');
|
|
377
|
-
if (msg.includes('no such column') ||
|
|
374
|
+
if (msg.includes('no such column') ||
|
|
375
|
+
msg.includes('no such table')) {
|
|
378
376
|
return { key: item.key, rows: [] };
|
|
379
377
|
}
|
|
380
378
|
console.error(`Error in useLiveQueries("${item.table}"):`, err);
|
|
@@ -474,7 +472,10 @@ function useLiveRow(client, tableName, rowId, options) {
|
|
|
474
472
|
const unsubscribe = client.events.on(tableName, (event) => {
|
|
475
473
|
advanceTableVersion(client, tableName);
|
|
476
474
|
// Precise row-level invalidation: only refetch if event affects this rowId or is a bulk event
|
|
477
|
-
if (!event ||
|
|
475
|
+
if (!event ||
|
|
476
|
+
!event.rowId ||
|
|
477
|
+
event.rowId === rowId ||
|
|
478
|
+
event.rowId === 'batch') {
|
|
478
479
|
scheduleRefetch();
|
|
479
480
|
}
|
|
480
481
|
});
|
|
@@ -578,8 +579,12 @@ function useLiveInfiniteQuery(client, tableName, options = {}) {
|
|
|
578
579
|
function useMutations(client) {
|
|
579
580
|
return (0, react_1.useMemo)(() => ({
|
|
580
581
|
client,
|
|
581
|
-
insert: (table, payload, opts) => client
|
|
582
|
-
|
|
582
|
+
insert: (table, payload, opts) => client
|
|
583
|
+
? client.insert(table, payload, opts)
|
|
584
|
+
: Promise.resolve(undefined),
|
|
585
|
+
insertMany: (table, records, opts) => client
|
|
586
|
+
? client.insertMany(table, records, opts)
|
|
587
|
+
: Promise.resolve(undefined),
|
|
583
588
|
update: (table, id, payload, opts) => client ? client.update(table, id, payload, opts) : Promise.resolve(),
|
|
584
589
|
updateMany: (table, updates, opts) => client ? client.updateMany(table, updates, opts) : Promise.resolve(),
|
|
585
590
|
delete: (table, id, opts) => client ? client.delete(table, id, opts) : Promise.resolve(),
|
package/dist/react/runner.js
CHANGED
package/dist/react/status.js
CHANGED
|
@@ -37,7 +37,9 @@ function useSyncStatus(client) {
|
|
|
37
37
|
if (records) {
|
|
38
38
|
setPendingRecords(records);
|
|
39
39
|
const activeCount = metrics
|
|
40
|
-
? metrics.outboxPendingCount +
|
|
40
|
+
? metrics.outboxPendingCount +
|
|
41
|
+
metrics.outboxProcessingCount +
|
|
42
|
+
metrics.outboxFailedCount
|
|
41
43
|
: records.length;
|
|
42
44
|
setPendingCount(activeCount);
|
|
43
45
|
}
|
|
@@ -71,7 +73,9 @@ function useSyncStatus(client) {
|
|
|
71
73
|
setLastSyncedAt(ts > 0 ? ts : null);
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
catch {
|
|
76
|
+
catch {
|
|
77
|
+
/* ignored */
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
});
|
|
77
81
|
return () => {
|
|
@@ -23,12 +23,12 @@ class EventEmitter {
|
|
|
23
23
|
emit(event, data) {
|
|
24
24
|
const eventSet = this.listeners.get(event);
|
|
25
25
|
if (eventSet) {
|
|
26
|
-
eventSet.forEach(callback => {
|
|
26
|
+
eventSet.forEach((callback) => {
|
|
27
27
|
try {
|
|
28
28
|
callback(data);
|
|
29
29
|
}
|
|
30
30
|
catch (err) {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error('Emitter error:', err);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}
|
package/dist/scheduler/cron.js
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseScheduleToIntervalMs = parseScheduleToIntervalMs;
|
|
4
4
|
exports.calculateNextRun = calculateNextRun;
|
|
5
5
|
function parseScheduleToIntervalMs(schedule) {
|
|
6
|
-
if (typeof schedule === 'object' &&
|
|
6
|
+
if (typeof schedule === 'object' &&
|
|
7
|
+
schedule !== null &&
|
|
8
|
+
'intervalMs' in schedule) {
|
|
7
9
|
return Math.max(1000, Number(schedule.intervalMs) || 60000);
|
|
8
10
|
}
|
|
9
11
|
if (typeof schedule === 'number') {
|
package/dist/scheduler/store.js
CHANGED
|
@@ -9,7 +9,8 @@ function mapJobRow(r) {
|
|
|
9
9
|
let payload = undefined;
|
|
10
10
|
if (r.payload) {
|
|
11
11
|
try {
|
|
12
|
-
payload =
|
|
12
|
+
payload =
|
|
13
|
+
typeof r.payload === 'string' ? JSON.parse(r.payload) : r.payload;
|
|
13
14
|
}
|
|
14
15
|
catch {
|
|
15
16
|
payload = r.payload;
|
|
@@ -40,40 +41,40 @@ function mapJobRunRow(r) {
|
|
|
40
41
|
}
|
|
41
42
|
class JobStore {
|
|
42
43
|
static async ensureSchema(db, jobsTable = exports.DEFAULT_JOBS_TABLE, runsTable = exports.DEFAULT_JOB_RUNS_TABLE) {
|
|
43
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${jobsTable} (
|
|
44
|
-
id TEXT PRIMARY KEY,
|
|
45
|
-
name TEXT NOT NULL,
|
|
46
|
-
schedule TEXT NOT NULL,
|
|
47
|
-
interval_ms INTEGER NOT NULL,
|
|
48
|
-
last_run_at INTEGER,
|
|
49
|
-
next_run_at INTEGER NOT NULL,
|
|
50
|
-
enabled INTEGER NOT NULL DEFAULT 1,
|
|
51
|
-
payload TEXT,
|
|
52
|
-
created_at INTEGER NOT NULL
|
|
44
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${jobsTable} (
|
|
45
|
+
id TEXT PRIMARY KEY,
|
|
46
|
+
name TEXT NOT NULL,
|
|
47
|
+
schedule TEXT NOT NULL,
|
|
48
|
+
interval_ms INTEGER NOT NULL,
|
|
49
|
+
last_run_at INTEGER,
|
|
50
|
+
next_run_at INTEGER NOT NULL,
|
|
51
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
52
|
+
payload TEXT,
|
|
53
|
+
created_at INTEGER NOT NULL
|
|
53
54
|
);`);
|
|
54
55
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${jobsTable}_next ON ${jobsTable} (next_run_at);`);
|
|
55
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${runsTable} (
|
|
56
|
-
id TEXT PRIMARY KEY,
|
|
57
|
-
job_id TEXT NOT NULL,
|
|
58
|
-
status TEXT NOT NULL,
|
|
59
|
-
started_at INTEGER NOT NULL,
|
|
60
|
-
finished_at INTEGER,
|
|
61
|
-
duration_ms INTEGER,
|
|
62
|
-
error TEXT
|
|
56
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${runsTable} (
|
|
57
|
+
id TEXT PRIMARY KEY,
|
|
58
|
+
job_id TEXT NOT NULL,
|
|
59
|
+
status TEXT NOT NULL,
|
|
60
|
+
started_at INTEGER NOT NULL,
|
|
61
|
+
finished_at INTEGER,
|
|
62
|
+
duration_ms INTEGER,
|
|
63
|
+
error TEXT
|
|
63
64
|
);`);
|
|
64
65
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${runsTable}_job ON ${runsTable} (job_id, started_at);`);
|
|
65
66
|
}
|
|
66
67
|
static async upsertJob(db, jobsTable = exports.DEFAULT_JOBS_TABLE, job) {
|
|
67
68
|
const payloadStr = job.payload !== undefined ? JSON.stringify(job.payload) : null;
|
|
68
|
-
await db.execute(`INSERT INTO ${jobsTable} (id, name, schedule, interval_ms, last_run_at, next_run_at, enabled, payload, created_at)
|
|
69
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
70
|
-
ON CONFLICT(id) DO UPDATE SET
|
|
71
|
-
name = excluded.name,
|
|
72
|
-
schedule = excluded.schedule,
|
|
73
|
-
interval_ms = excluded.interval_ms,
|
|
74
|
-
last_run_at = excluded.last_run_at,
|
|
75
|
-
next_run_at = excluded.next_run_at,
|
|
76
|
-
enabled = excluded.enabled,
|
|
69
|
+
await db.execute(`INSERT INTO ${jobsTable} (id, name, schedule, interval_ms, last_run_at, next_run_at, enabled, payload, created_at)
|
|
70
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
71
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
72
|
+
name = excluded.name,
|
|
73
|
+
schedule = excluded.schedule,
|
|
74
|
+
interval_ms = excluded.interval_ms,
|
|
75
|
+
last_run_at = excluded.last_run_at,
|
|
76
|
+
next_run_at = excluded.next_run_at,
|
|
77
|
+
enabled = excluded.enabled,
|
|
77
78
|
payload = excluded.payload;`, [
|
|
78
79
|
job.id,
|
|
79
80
|
job.name,
|
|
@@ -104,14 +105,17 @@ class JobStore {
|
|
|
104
105
|
await db.execute(`UPDATE ${jobsTable} SET last_run_at = ?, next_run_at = ? WHERE id = ?;`, [lastRunAt, nextRunAt, id]);
|
|
105
106
|
}
|
|
106
107
|
static async setJobEnabled(db, jobsTable = exports.DEFAULT_JOBS_TABLE, id, enabled) {
|
|
107
|
-
await db.execute(`UPDATE ${jobsTable} SET enabled = ? WHERE id = ?;`, [
|
|
108
|
+
await db.execute(`UPDATE ${jobsTable} SET enabled = ? WHERE id = ?;`, [
|
|
109
|
+
enabled ? 1 : 0,
|
|
110
|
+
id,
|
|
111
|
+
]);
|
|
108
112
|
}
|
|
109
113
|
static async deleteJob(db, jobsTable = exports.DEFAULT_JOBS_TABLE, id) {
|
|
110
114
|
await db.execute(`DELETE FROM ${jobsTable} WHERE id = ?;`, [id]);
|
|
111
115
|
}
|
|
112
116
|
// --- Run History ---
|
|
113
117
|
static async recordRunStart(db, runsTable = exports.DEFAULT_JOB_RUNS_TABLE, run) {
|
|
114
|
-
await db.execute(`INSERT INTO ${runsTable} (id, job_id, status, started_at, finished_at, duration_ms, error)
|
|
118
|
+
await db.execute(`INSERT INTO ${runsTable} (id, job_id, status, started_at, finished_at, duration_ms, error)
|
|
115
119
|
VALUES (?, ?, ?, ?, ?, ?, ?);`, [run.id, run.jobId, run.status, run.startedAt, null, null, null]);
|
|
116
120
|
}
|
|
117
121
|
static async recordRunFinish(db, runsTable = exports.DEFAULT_JOB_RUNS_TABLE, id, status, finishedAt, durationMs, error) {
|
|
@@ -128,7 +132,9 @@ class JobStore {
|
|
|
128
132
|
return (rows || []).map(mapJobRunRow);
|
|
129
133
|
}
|
|
130
134
|
static async pruneRuns(db, runsTable = exports.DEFAULT_JOB_RUNS_TABLE, cutoffTimestamp) {
|
|
131
|
-
await db.execute(`DELETE FROM ${runsTable} WHERE started_at < ?;`, [
|
|
135
|
+
await db.execute(`DELETE FROM ${runsTable} WHERE started_at < ?;`, [
|
|
136
|
+
cutoffTimestamp,
|
|
137
|
+
]);
|
|
132
138
|
}
|
|
133
139
|
}
|
|
134
140
|
exports.JobStore = JobStore;
|
package/dist/schema/generator.js
CHANGED
|
@@ -63,7 +63,8 @@ function parseSchemaIndexes(content, options = {}) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
// Skip empty relationships
|
|
66
|
-
if (line.includes('Relationships: [];') ||
|
|
66
|
+
if (line.includes('Relationships: [];') ||
|
|
67
|
+
line.includes('Relationships: []')) {
|
|
67
68
|
continue;
|
|
68
69
|
}
|
|
69
70
|
if (line.includes('Relationships: [')) {
|
|
@@ -79,14 +80,16 @@ function parseSchemaIndexes(content, options = {}) {
|
|
|
79
80
|
const itemRegex = /foreignKeyName:\s*['"]([^'"]+)['"][\s\S]*?columns:\s*\[([^\]]+)\][\s\S]*?isOneToOne:\s*(true|false)[\s\S]*?referencedRelation:\s*['"]([^'"]+)['"](?:[\s\S]*?referencedColumns:\s*\[([^\]]+)\])?/g;
|
|
80
81
|
const matches = [...block.matchAll(itemRegex)];
|
|
81
82
|
for (const m of matches) {
|
|
82
|
-
const columns = m[2]
|
|
83
|
+
const columns = m[2]
|
|
84
|
+
.split(',')
|
|
85
|
+
.map((c) => c.trim().replace(/['"]/g, ''));
|
|
83
86
|
const isOneToOne = m[3] === 'true';
|
|
84
87
|
const referencedRelation = m[4];
|
|
85
88
|
const referencedColumns = m[5]
|
|
86
|
-
? m[5].split(',').map(c => c.trim().replace(/['"]/g, ''))
|
|
89
|
+
? m[5].split(',').map((c) => c.trim().replace(/['"]/g, ''))
|
|
87
90
|
: undefined;
|
|
88
91
|
const isUnique = isOneToOne ? 'UNIQUE ' : '';
|
|
89
|
-
const colSql = columns.map(c => `"${c}"`).join(', ');
|
|
92
|
+
const colSql = columns.map((c) => `"${c}"`).join(', ');
|
|
90
93
|
const colSlug = columns.join('_');
|
|
91
94
|
const indexName = `idx_${currentTable}_${colSlug}`;
|
|
92
95
|
relationships.push({
|
|
@@ -112,7 +115,7 @@ function parseSchemaIndexes(content, options = {}) {
|
|
|
112
115
|
for (const [table, cols] of tableColumns.entries()) {
|
|
113
116
|
if (cols.has('business_id') && cols.has('deleted')) {
|
|
114
117
|
const idxName = `idx_${table}_biz_del`;
|
|
115
|
-
if (!relationships.some(r => r.table === table &&
|
|
118
|
+
if (!relationships.some((r) => r.table === table &&
|
|
116
119
|
r.columns.length === 2 &&
|
|
117
120
|
r.columns.includes('business_id') &&
|
|
118
121
|
r.columns.includes('deleted'))) {
|
|
@@ -133,35 +136,35 @@ function parseSchemaIndexes(content, options = {}) {
|
|
|
133
136
|
* Generates TypeScript source code containing index definitions and an applicator helper.
|
|
134
137
|
*/
|
|
135
138
|
function formatSchemaIndexesCode(indexes) {
|
|
136
|
-
const sqlStatements = indexes.map(i => i.sql).join('\n');
|
|
137
|
-
return `/**
|
|
138
|
-
* AUTO-GENERATED FILE - DO NOT EDIT MANUALLY.
|
|
139
|
-
* Generated by local-lite schema index generator.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* SQLite index statements extracted from Supabase database schema.
|
|
144
|
-
* Total indexes: ${indexes.length}
|
|
145
|
-
*/
|
|
146
|
-
export const SCHEMA_INDEXES: readonly string[] = \`
|
|
147
|
-
${sqlStatements}
|
|
148
|
-
\`.trim().split('\\n');
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Applies all schema indexes into SQLite to ensure zero-latency local reads.
|
|
152
|
-
* Executes each statement safely, ignoring errors if tables are not yet created.
|
|
153
|
-
*/
|
|
154
|
-
export async function ensureSchemaIndexes(db: {
|
|
155
|
-
execute: (query: string, params?: any[]) => Promise<any>;
|
|
156
|
-
}): Promise<void> {
|
|
157
|
-
for (const sql of SCHEMA_INDEXES) {
|
|
158
|
-
try {
|
|
159
|
-
await db.execute(sql);
|
|
160
|
-
} catch {
|
|
161
|
-
// Safe fallback if table has not been created yet
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
139
|
+
const sqlStatements = indexes.map((i) => i.sql).join('\n');
|
|
140
|
+
return `/**
|
|
141
|
+
* AUTO-GENERATED FILE - DO NOT EDIT MANUALLY.
|
|
142
|
+
* Generated by local-lite schema index generator.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* SQLite index statements extracted from Supabase database schema.
|
|
147
|
+
* Total indexes: ${indexes.length}
|
|
148
|
+
*/
|
|
149
|
+
export const SCHEMA_INDEXES: readonly string[] = \`
|
|
150
|
+
${sqlStatements}
|
|
151
|
+
\`.trim().split('\\n');
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Applies all schema indexes into SQLite to ensure zero-latency local reads.
|
|
155
|
+
* Executes each statement safely, ignoring errors if tables are not yet created.
|
|
156
|
+
*/
|
|
157
|
+
export async function ensureSchemaIndexes(db: {
|
|
158
|
+
execute: (query: string, params?: any[]) => Promise<any>;
|
|
159
|
+
}): Promise<void> {
|
|
160
|
+
for (const sql of SCHEMA_INDEXES) {
|
|
161
|
+
try {
|
|
162
|
+
await db.execute(sql);
|
|
163
|
+
} catch {
|
|
164
|
+
// Safe fallback if table has not been created yet
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
165
168
|
`;
|
|
166
169
|
}
|
|
167
170
|
/**
|
package/dist/search/manager.js
CHANGED
|
@@ -45,7 +45,9 @@ class SearchManager {
|
|
|
45
45
|
*/
|
|
46
46
|
async indexRecord(table, rowId, values) {
|
|
47
47
|
const config = this.indices.get(table);
|
|
48
|
-
const columns = config
|
|
48
|
+
const columns = config
|
|
49
|
+
? config.columns
|
|
50
|
+
: Object.keys(values).filter((k) => k !== 'id');
|
|
49
51
|
await store_js_1.SearchStore.indexRow(this.db, table, rowId, columns, values);
|
|
50
52
|
}
|
|
51
53
|
/**
|