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.
Files changed (69) hide show
  1. package/dist/actions/manager.js +6 -2
  2. package/dist/actions/store.js +33 -19
  3. package/dist/adapters/local/expo-sqlite.js +4 -2
  4. package/dist/adapters/local/libsql.js +3 -1
  5. package/dist/adapters/local/op-sqlite.js +2 -1
  6. package/dist/adapters/network/index.js +10 -5
  7. package/dist/adapters/remote/convex.js +37 -10
  8. package/dist/adapters/remote/firestore.js +11 -4
  9. package/dist/adapters/remote/self-hosted.js +9 -5
  10. package/dist/adapters/remote/supabase.js +95 -29
  11. package/dist/auth/apple.js +8 -4
  12. package/dist/auth/github.js +15 -7
  13. package/dist/auth/google.js +7 -4
  14. package/dist/auth/identity.js +5 -1
  15. package/dist/auth/local.js +74 -21
  16. package/dist/auth/microsoft.js +22 -8
  17. package/dist/auth/session.js +45 -34
  18. package/dist/auth/unified.js +3 -2
  19. package/dist/backups/cloud-storage.js +10 -7
  20. package/dist/backups/encryption.js +4 -2
  21. package/dist/backups/onedrive.js +3 -3
  22. package/dist/backups/operations.js +4 -2
  23. package/dist/config/index.d.ts +1 -1
  24. package/dist/config/resolve-local.js +18 -6
  25. package/dist/config/resolve-remote.js +2 -1
  26. package/dist/core/client.d.ts +2 -2
  27. package/dist/core/client.js +64 -26
  28. package/dist/core/index.d.ts +1 -1
  29. package/dist/core/maintenance.js +5 -4
  30. package/dist/core/meta-store.js +3 -3
  31. package/dist/core/outbox-store.js +32 -25
  32. package/dist/core/query-builder.js +23 -10
  33. package/dist/core/query.js +19 -7
  34. package/dist/core/schema-manager.js +6 -2
  35. package/dist/core/sync-worker.js +38 -12
  36. package/dist/core/table-manager.js +8 -2
  37. package/dist/core/types.d.ts +1 -1
  38. package/dist/devtools/BenchmarkModal.d.ts +1 -1
  39. package/dist/devtools/BenchmarkModal.js +234 -54
  40. package/dist/devtools/SyncInspector.js +260 -37
  41. package/dist/email/index.js +46 -18
  42. package/dist/keys/generator.js +4 -1
  43. package/dist/keys/manager.js +22 -4
  44. package/dist/keys/signed-token.js +12 -4
  45. package/dist/keys/store.js +23 -16
  46. package/dist/kv/manager.js +5 -2
  47. package/dist/kv/store.js +13 -13
  48. package/dist/react/auth.js +12 -12
  49. package/dist/react/backups.js +1 -1
  50. package/dist/react/index.js +14 -9
  51. package/dist/react/runner.js +1 -1
  52. package/dist/react/status.js +6 -2
  53. package/dist/reactive/event-emitter.js +2 -2
  54. package/dist/scheduler/cron.js +3 -1
  55. package/dist/scheduler/store.js +37 -31
  56. package/dist/schema/generator.js +37 -34
  57. package/dist/search/manager.js +3 -1
  58. package/dist/search/store.js +17 -16
  59. package/dist/server/email.js +3 -2
  60. package/dist/server/index.js +4 -4
  61. package/dist/server/sync.js +11 -4
  62. package/dist/storage/driver.js +2 -1
  63. package/dist/storage/expo.js +5 -2
  64. package/dist/storage/manager.js +3 -1
  65. package/dist/storage/store.js +26 -25
  66. package/dist/utils/dynamic.js +4 -2
  67. package/dist/utils/logger.js +13 -6
  68. package/dist/utils/portability.js +21 -9
  69. package/package.json +1 -1
@@ -232,7 +232,10 @@ class ActionManager {
232
232
  }
233
233
  // 3. Mark EXECUTING
234
234
  await store_js_1.ActionStore.updateStatus(this.db, this.tableName, action.id, 'EXECUTING');
235
- this.events.emit('action:executing', { ...action, status: 'EXECUTING' });
235
+ this.events.emit('action:executing', {
236
+ ...action,
237
+ status: 'EXECUTING',
238
+ });
236
239
  // 4. Rate-limiting throttle
237
240
  await this.waitForRateLimit();
238
241
  // 5. Execute handler
@@ -322,7 +325,8 @@ class ActionManager {
322
325
  }
323
326
  } while (this.flushRerunRequested);
324
327
  }
325
- finally { }
328
+ finally {
329
+ }
326
330
  return result;
327
331
  }
328
332
  /**
@@ -10,7 +10,11 @@ function mapActionRow(r) {
10
10
  return {
11
11
  id: r.id,
12
12
  action: r.action,
13
- payload: r.payload ? (typeof r.payload === 'string' ? JSON.parse(r.payload) : r.payload) : {},
13
+ payload: r.payload
14
+ ? typeof r.payload === 'string'
15
+ ? JSON.parse(r.payload)
16
+ : r.payload
17
+ : {},
14
18
  idempotencyKey: r.idempotency_key ?? null,
15
19
  status: r.status,
16
20
  createdAt: Number(r.created_at || 0),
@@ -19,7 +23,11 @@ function mapActionRow(r) {
19
23
  retryCount: Number(r.retry_count || 0),
20
24
  maxRetries: Number(r.max_retries || 3),
21
25
  lastError: r.last_error ?? null,
22
- result: r.result ? (typeof r.result === 'string' ? JSON.parse(r.result) : r.result) : null,
26
+ result: r.result
27
+ ? typeof r.result === 'string'
28
+ ? JSON.parse(r.result)
29
+ : r.result
30
+ : null,
23
31
  };
24
32
  }
25
33
  class ActionStore {
@@ -27,19 +35,19 @@ class ActionStore {
27
35
  * Initializes the action outbox schema and indexes if they do not exist.
28
36
  */
29
37
  static async ensureSchema(db, tableName = exports.DEFAULT_ACTIONS_TABLE) {
30
- await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
31
- id TEXT PRIMARY KEY,
32
- action TEXT NOT NULL,
33
- payload TEXT NOT NULL,
34
- idempotency_key TEXT UNIQUE,
35
- status TEXT NOT NULL DEFAULT 'PENDING',
36
- created_at INTEGER NOT NULL,
37
- expires_at INTEGER,
38
- executed_at INTEGER,
39
- retry_count INTEGER NOT NULL DEFAULT 0,
40
- max_retries INTEGER NOT NULL DEFAULT 3,
41
- last_error TEXT,
42
- result TEXT
38
+ await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
39
+ id TEXT PRIMARY KEY,
40
+ action TEXT NOT NULL,
41
+ payload TEXT NOT NULL,
42
+ idempotency_key TEXT UNIQUE,
43
+ status TEXT NOT NULL DEFAULT 'PENDING',
44
+ created_at INTEGER NOT NULL,
45
+ expires_at INTEGER,
46
+ executed_at INTEGER,
47
+ retry_count INTEGER NOT NULL DEFAULT 0,
48
+ max_retries INTEGER NOT NULL DEFAULT 3,
49
+ last_error TEXT,
50
+ result TEXT
43
51
  );`);
44
52
  await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_status ON ${tableName} (status, created_at);`);
45
53
  await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_idempotency ON ${tableName} (idempotency_key);`);
@@ -55,12 +63,14 @@ class ActionStore {
55
63
  * Inserts an action record into storage.
56
64
  */
57
65
  static async insertRecord(db, tableName = exports.DEFAULT_ACTIONS_TABLE, record) {
58
- await db.execute(`INSERT INTO ${tableName} (
59
- id, action, payload, idempotency_key, status, created_at, expires_at, executed_at, retry_count, max_retries, last_error, result
66
+ await db.execute(`INSERT INTO ${tableName} (
67
+ id, action, payload, idempotency_key, status, created_at, expires_at, executed_at, retry_count, max_retries, last_error, result
60
68
  ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
61
69
  record.id,
62
70
  record.action,
63
- typeof record.payload === 'string' ? record.payload : JSON.stringify(record.payload ?? {}),
71
+ typeof record.payload === 'string'
72
+ ? record.payload
73
+ : JSON.stringify(record.payload ?? {}),
64
74
  record.idempotencyKey ?? null,
65
75
  record.status,
66
76
  record.createdAt,
@@ -69,7 +79,11 @@ class ActionStore {
69
79
  record.retryCount,
70
80
  record.maxRetries,
71
81
  record.lastError ?? null,
72
- record.result ? (typeof record.result === 'string' ? record.result : JSON.stringify(record.result)) : null,
82
+ record.result
83
+ ? typeof record.result === 'string'
84
+ ? record.result
85
+ : JSON.stringify(record.result)
86
+ : null,
73
87
  ]);
74
88
  }
75
89
  /**
@@ -19,7 +19,8 @@ class ExpoSQLiteAdapter {
19
19
  }
20
20
  const run = async () => {
21
21
  // Parameterless DDL statements bypass statement preparation
22
- if ((!params || params.length === 0) && typeof this.db.execAsync === 'function') {
22
+ if ((!params || params.length === 0) &&
23
+ typeof this.db.execAsync === 'function') {
23
24
  await this.db.execAsync(trimmed);
24
25
  return [];
25
26
  }
@@ -44,7 +45,8 @@ class ExpoSQLiteAdapter {
44
45
  if (READ_QUERY_REGEX.test(trimmed)) {
45
46
  return this.db.getAllAsync(trimmed, p);
46
47
  }
47
- if ((!p || p.length === 0) && typeof this.db.execAsync === 'function') {
48
+ if ((!p || p.length === 0) &&
49
+ typeof this.db.execAsync === 'function') {
48
50
  await this.db.execAsync(trimmed);
49
51
  return [];
50
52
  }
@@ -8,7 +8,9 @@ function normalizeRows(res) {
8
8
  if (rows.length === 0)
9
9
  return [];
10
10
  // If rows are already standard objects
11
- if (typeof rows[0] === 'object' && !Array.isArray(rows[0]) && rows[0] !== null) {
11
+ if (typeof rows[0] === 'object' &&
12
+ !Array.isArray(rows[0]) &&
13
+ rows[0] !== null) {
12
14
  return rows;
13
15
  }
14
16
  // If rows are tuples/arrays, map them to column names
@@ -11,7 +11,8 @@ function extractRows(res) {
11
11
  return res.rows;
12
12
  if (res.rows._array && Array.isArray(res.rows._array))
13
13
  return res.rows._array;
14
- if (typeof res.rows.length === 'number' && typeof res.rows.item === 'function') {
14
+ if (typeof res.rows.length === 'number' &&
15
+ typeof res.rows.item === 'function') {
15
16
  const arr = [];
16
17
  for (let i = 0; i < res.rows.length; i++) {
17
18
  arr.push(res.rows.item(i));
@@ -13,18 +13,21 @@ class DefaultNetworkStatusProvider {
13
13
  try {
14
14
  const NetInfo = (0, dynamic_js_1.safeDynamicRequire)(NETINFO_PKG);
15
15
  const netInfoInstance = NetInfo?.default || NetInfo;
16
- if (netInfoInstance && typeof netInfoInstance.addEventListener === 'function') {
16
+ if (netInfoInstance &&
17
+ typeof netInfoInstance.addEventListener === 'function') {
17
18
  netInfoInstance
18
19
  .fetch()
19
20
  .then((state) => {
20
21
  const online = state.isConnected === true &&
21
- (state.isInternetReachable === true || state.isInternetReachable === null);
22
+ (state.isInternetReachable === true ||
23
+ state.isInternetReachable === null);
22
24
  this.setOnline(online);
23
25
  })
24
26
  .catch(() => { });
25
27
  const unsub = netInfoInstance.addEventListener((state) => {
26
28
  const online = state.isConnected === true &&
27
- (state.isInternetReachable === true || state.isInternetReachable === null);
29
+ (state.isInternetReachable === true ||
30
+ state.isInternetReachable === null);
28
31
  this.setOnline(online);
29
32
  });
30
33
  this.cleanupBrowserListeners = () => {
@@ -42,8 +45,10 @@ class DefaultNetworkStatusProvider {
42
45
  // NetInfo not installed or running in node/web
43
46
  }
44
47
  // 2. Web DOM environment fallback
45
- if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
46
- if (typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean') {
48
+ if (typeof window !== 'undefined' &&
49
+ typeof window.addEventListener === 'function') {
50
+ if (typeof navigator !== 'undefined' &&
51
+ typeof navigator.onLine === 'boolean') {
47
52
  this._isOnline = navigator.onLine;
48
53
  }
49
54
  const onOnline = () => this.setOnline(true);
@@ -125,7 +125,9 @@ class ConvexRemoteAdapter {
125
125
  maxServerTimestamp = rowTime;
126
126
  }
127
127
  const rowId = getRowId(row, this.primaryKey);
128
- const tableName = row.tableName || row._table || (this.tables.length === 1 ? this.tables[0] : 'default');
128
+ const tableName = row.tableName ||
129
+ row._table ||
130
+ (this.tables.length === 1 ? this.tables[0] : 'default');
129
131
  changes.push({
130
132
  tableName,
131
133
  operation,
@@ -176,11 +178,18 @@ class ConvexRemoteAdapter {
176
178
  if (generation !== this.liveGeneration || this.liveCallback !== callback)
177
179
  return;
178
180
  try {
179
- const unsubscribe = this.client.onUpdate(this.pullQuery, { sinceTimestamp: Date.now() - 2000, tables: this.tables, ...(scope ? { scope } : {}) }, (data) => {
181
+ const unsubscribe = this.client.onUpdate(this.pullQuery, {
182
+ sinceTimestamp: Date.now() - 2000,
183
+ tables: this.tables,
184
+ ...(scope ? { scope } : {}),
185
+ }, (data) => {
180
186
  if (generation !== this.liveGeneration || !data)
181
187
  return;
182
188
  if (data.changes && Array.isArray(data.changes)) {
183
- callback({ timestamp: Number(data.timestamp || Date.now()), changes: data.changes });
189
+ callback({
190
+ timestamp: Number(data.timestamp || Date.now()),
191
+ changes: data.changes,
192
+ });
184
193
  return;
185
194
  }
186
195
  if (Array.isArray(data) && data.length > 0) {
@@ -190,10 +199,19 @@ class ConvexRemoteAdapter {
190
199
  const rowTime = getRowTimestamp(row[this.updatedAtColumn], row._creationTime);
191
200
  const rowId = getRowId(row, this.primaryKey);
192
201
  const tableName = row.tableName || row._table || (this.tables[0] ?? 'default');
193
- return { tableName, operation: op, rowId, payload: isSoftDeleted ? null : row, timestamp: rowTime };
202
+ return {
203
+ tableName,
204
+ operation: op,
205
+ rowId,
206
+ payload: isSoftDeleted ? null : row,
207
+ timestamp: rowTime,
208
+ };
194
209
  });
195
210
  const maxTime = Math.max(...changes.map((change) => change.timestamp || 0));
196
- callback({ timestamp: maxTime > 0 ? maxTime : Date.now(), changes });
211
+ callback({
212
+ timestamp: maxTime > 0 ? maxTime : Date.now(),
213
+ changes,
214
+ });
197
215
  }
198
216
  });
199
217
  if (generation !== this.liveGeneration) {
@@ -201,16 +219,21 @@ class ConvexRemoteAdapter {
201
219
  unsubscribe();
202
220
  return;
203
221
  }
204
- this.unsubscribeLive = typeof unsubscribe === 'function' ? unsubscribe : undefined;
222
+ this.unsubscribeLive =
223
+ typeof unsubscribe === 'function' ? unsubscribe : undefined;
205
224
  }
206
225
  catch (err) {
207
226
  console.warn('ConvexRemoteAdapter live subscription failed to initialize:', err);
208
227
  }
209
228
  };
210
229
  try {
211
- const scopeResult = typeof this.liveScope === 'function' ? this.liveScope() : this.liveScope;
230
+ const scopeResult = typeof this.liveScope === 'function'
231
+ ? this.liveScope()
232
+ : this.liveScope;
212
233
  if (scopeResult && typeof scopeResult.then === 'function') {
213
- void Promise.resolve(scopeResult).then(subscribe).catch((err) => {
234
+ void Promise.resolve(scopeResult)
235
+ .then(subscribe)
236
+ .catch((err) => {
214
237
  console.warn('ConvexRemoteAdapter live scope failed to resolve:', err);
215
238
  });
216
239
  }
@@ -249,7 +272,8 @@ class ConvexRemoteAdapter {
249
272
  return await this.client.action(functionName, args);
250
273
  }
251
274
  catch (err) {
252
- if (typeof this.client?.mutation === 'function' && err?.message?.includes?.('not an action')) {
275
+ if (typeof this.client?.mutation === 'function' &&
276
+ err?.message?.includes?.('not an action')) {
253
277
  return await this.client.mutation(functionName, args);
254
278
  }
255
279
  throw err;
@@ -279,7 +303,10 @@ class ConvexRemoteAdapter {
279
303
  * Enables or disables an automated cron job on Convex.
280
304
  */
281
305
  async setAutomationEnabled(jobId, enabled) {
282
- return this.call('functions/automations:setEnabled', { jobId, enabled });
306
+ return this.call('functions/automations:setEnabled', {
307
+ jobId,
308
+ enabled,
309
+ });
283
310
  }
284
311
  /**
285
312
  * Lists cloud backup archives stored on Convex.
@@ -71,7 +71,8 @@ class FirestoreRemoteAdapter {
71
71
  try {
72
72
  const FIRESTORE_PKG = ['firebase', 'firestore'].join('/');
73
73
  this.firestoreModule =
74
- (0, dynamic_js_1.safeDynamicRequire)(FIRESTORE_PKG) ?? (await (0, dynamic_js_1.safeDynamicImport)(FIRESTORE_PKG));
74
+ (0, dynamic_js_1.safeDynamicRequire)(FIRESTORE_PKG) ??
75
+ (await (0, dynamic_js_1.safeDynamicImport)(FIRESTORE_PKG));
75
76
  return this.firestoreModule;
76
77
  }
77
78
  catch {
@@ -90,7 +91,8 @@ class FirestoreRemoteAdapter {
90
91
  const failedIds = [];
91
92
  const errors = {};
92
93
  try {
93
- const isCompat = typeof this.db.batch === 'function' && typeof this.db.collection === 'function';
94
+ const isCompat = typeof this.db.batch === 'function' &&
95
+ typeof this.db.collection === 'function';
94
96
  const mod = isCompat ? null : await this.getModule();
95
97
  const CHUNK_SIZE = 450;
96
98
  for (let i = 0; i < operations.length; i += CHUNK_SIZE) {
@@ -284,7 +286,10 @@ class FirestoreRemoteAdapter {
284
286
  }
285
287
  }
286
288
  else if (snapshot.docs) {
287
- docList = snapshot.docs.map((doc) => ({ doc, isRemoved: false }));
289
+ docList = snapshot.docs.map((doc) => ({
290
+ doc,
291
+ isRemoved: false,
292
+ }));
288
293
  }
289
294
  if (docList.length === 0)
290
295
  return;
@@ -374,7 +379,9 @@ class FirestoreRemoteAdapter {
374
379
  !storageOrApp.storage &&
375
380
  !storageOrApp.app &&
376
381
  typeof storageOrApp === 'object' &&
377
- ('bucket' in storageOrApp || 'storageModule' in storageOrApp || 'basePath' in storageOrApp)) {
382
+ ('bucket' in storageOrApp ||
383
+ 'storageModule' in storageOrApp ||
384
+ 'basePath' in storageOrApp)) {
378
385
  opts = storageOrApp;
379
386
  client = this.db.app || this.db;
380
387
  }
@@ -130,7 +130,7 @@ class SelfHostedRemoteAdapter {
130
130
  'contracts/renewal': '/contracts/renewal',
131
131
  'contracts/termination': '/contracts/termination',
132
132
  'tenant-self-service': '/tenant-self-service',
133
- 'email': '/email',
133
+ email: '/email',
134
134
  'backups/create': '/backups/create',
135
135
  'backups/list': '/backups',
136
136
  'crons/toggle': '/crons/toggle',
@@ -166,7 +166,9 @@ class SelfHostedRemoteAdapter {
166
166
  throw new Error(`Self-hosted function call "${functionName}" failed (${response.status}): ${errText}`);
167
167
  }
168
168
  const data = await response.json();
169
- return (isBackups ? data.archives || [] : data.automations || []);
169
+ return (isBackups
170
+ ? data.archives || data.backups || []
171
+ : data.automations || []);
170
172
  }
171
173
  const endpoint = actionEndpoints[normalized] || `/${normalized}`;
172
174
  const fullUrl = `${this.url}${endpoint.startsWith('/') ? endpoint : '/' + endpoint}`;
@@ -189,10 +191,12 @@ class SelfHostedRemoteAdapter {
189
191
  * Queries a remote function or view across self-hosted endpoints.
190
192
  */
191
193
  async queryRemote(queryName, args = {}) {
192
- if (queryName.includes('listMyBackups') || queryName.includes('listBackups')) {
194
+ if (queryName.includes('listMyBackups') ||
195
+ queryName.includes('listBackups')) {
193
196
  return (await this.listBackups());
194
197
  }
195
- if (queryName.includes('listMine') || queryName.includes('listAutomations')) {
198
+ if (queryName.includes('listMine') ||
199
+ queryName.includes('listAutomations')) {
196
200
  return (await this.listAutomations());
197
201
  }
198
202
  return this.call(queryName, args);
@@ -211,7 +215,7 @@ class SelfHostedRemoteAdapter {
211
215
  throw new Error(`Self-hosted listBackups failed (${response.status}): ${errText}`);
212
216
  }
213
217
  const data = await response.json();
214
- return (data.archives || []);
218
+ return (data.archives || data.backups || []);
215
219
  }
216
220
  /**
217
221
  * Gets a direct download URL for a file stored on self-hosted backend.