local-lite 0.2.2 → 0.2.5

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.
@@ -1,4 +1,4 @@
1
- import { RemoteDBAdapter } from './index.js';
1
+ import { RemoteAutomationJob, RemoteBackupArchive, RemoteDBAdapter } from './index.js';
2
2
  import { DeltaChanges, SyncOperation, PushResult } from '../../core/types.js';
3
3
  import { SyncLogger, CustomLogger, LogLevel } from '../../utils/logger.js';
4
4
  import { createConvexStorageUploader, ConvexStorageUploaderOptions, ConvexStorageUploaderInstance } from '../../storage/convex.js';
@@ -79,5 +79,29 @@ export declare class ConvexRemoteAdapter implements RemoteDBAdapter {
79
79
  * Connects local-lite offline blob/file storage directly to Convex File Storage.
80
80
  */
81
81
  createStorageUploader(options?: ConvexStorageUploaderOptions): ConvexStorageUploaderInstance;
82
+ /**
83
+ * Invokes a remote Convex action or mutation.
84
+ */
85
+ call<T = any>(functionName: string, args?: any): Promise<T>;
86
+ /**
87
+ * Queries a remote Convex query function.
88
+ */
89
+ queryRemote<T = any>(queryName: string, args?: any): Promise<T>;
90
+ /**
91
+ * Lists automated cron jobs configured on Convex.
92
+ */
93
+ listAutomations(): Promise<RemoteAutomationJob[]>;
94
+ /**
95
+ * Enables or disables an automated cron job on Convex.
96
+ */
97
+ setAutomationEnabled(jobId: string, enabled: boolean): Promise<void>;
98
+ /**
99
+ * Lists cloud backup archives stored on Convex.
100
+ */
101
+ listBackups(): Promise<RemoteBackupArchive[]>;
102
+ /**
103
+ * Gets a direct download URL for a file stored on Convex.
104
+ */
105
+ getDownloadUrl(fileIdOrKey: string): Promise<string | null>;
82
106
  }
83
107
  export { createConvexStorageUploader, type ConvexStorageUploaderOptions, type ConvexStorageUploaderInstance, };
@@ -240,5 +240,64 @@ class ConvexRemoteAdapter {
240
240
  createStorageUploader(options = {}) {
241
241
  return (0, convex_js_1.createConvexStorageUploader)(this.client, options);
242
242
  }
243
+ /**
244
+ * Invokes a remote Convex action or mutation.
245
+ */
246
+ async call(functionName, args = {}) {
247
+ if (typeof this.client?.action === 'function') {
248
+ try {
249
+ return await this.client.action(functionName, args);
250
+ }
251
+ catch (err) {
252
+ if (typeof this.client?.mutation === 'function' && err?.message?.includes?.('not an action')) {
253
+ return await this.client.mutation(functionName, args);
254
+ }
255
+ throw err;
256
+ }
257
+ }
258
+ if (typeof this.client?.mutation === 'function') {
259
+ return await this.client.mutation(functionName, args);
260
+ }
261
+ throw new Error('Convex client does not support action or mutation execution.');
262
+ }
263
+ /**
264
+ * Queries a remote Convex query function.
265
+ */
266
+ async queryRemote(queryName, args = {}) {
267
+ if (typeof this.client?.query === 'function') {
268
+ return await this.client.query(queryName, args);
269
+ }
270
+ throw new Error('Convex client does not support query execution.');
271
+ }
272
+ /**
273
+ * Lists automated cron jobs configured on Convex.
274
+ */
275
+ async listAutomations() {
276
+ return this.queryRemote('functions/automations:listMine', {});
277
+ }
278
+ /**
279
+ * Enables or disables an automated cron job on Convex.
280
+ */
281
+ async setAutomationEnabled(jobId, enabled) {
282
+ return this.call('functions/automations:setEnabled', { jobId, enabled });
283
+ }
284
+ /**
285
+ * Lists cloud backup archives stored on Convex.
286
+ */
287
+ async listBackups() {
288
+ return this.queryRemote('functions/convexBackups:listMyBackups', {});
289
+ }
290
+ /**
291
+ * Gets a direct download URL for a file stored on Convex.
292
+ */
293
+ async getDownloadUrl(fileIdOrKey) {
294
+ if (typeof this.client?.query === 'function') {
295
+ try {
296
+ return await this.client.query('functions/convexBackups:getDownloadUrl', { storageId: fileIdOrKey });
297
+ }
298
+ catch { }
299
+ }
300
+ return null;
301
+ }
243
302
  }
244
303
  exports.ConvexRemoteAdapter = ConvexRemoteAdapter;
@@ -1,4 +1,20 @@
1
1
  import { SyncOperation, DeltaChanges, PushResult } from '../../core/types.js';
2
+ export interface RemoteAutomationJob {
3
+ id: string;
4
+ name: string;
5
+ description?: string;
6
+ enabled: boolean;
7
+ locked?: boolean;
8
+ }
9
+ export interface RemoteBackupArchive {
10
+ createdAt: number;
11
+ status: string;
12
+ fileName?: string;
13
+ sizeBytes?: number;
14
+ recordCount?: number;
15
+ error?: string;
16
+ downloadUrl: string | null;
17
+ }
2
18
  export interface RemoteDBAdapter {
3
19
  pushChanges(operations: SyncOperation[]): Promise<boolean | PushResult>;
4
20
  /** Return a complete batch through timestamp; reject on partial failure. Supports optional scope for data filtering. */
@@ -6,6 +22,18 @@ export interface RemoteDBAdapter {
6
22
  /** Live events do not advance the durable pull checkpoint; return a cleanup function. */
7
23
  subscribeToLiveChanges(callback: (changes: DeltaChanges) => void, scope?: Record<string, any> | (() => Record<string, any> | Promise<Record<string, any>>)): () => void;
8
24
  setSyncScope?(scope?: Record<string, any> | (() => Record<string, any> | Promise<Record<string, any>>)): void;
25
+ /** Call a remote cloud action/function/RPC */
26
+ call?<T = any>(functionName: string, args?: any): Promise<T>;
27
+ /** Query a remote function or view */
28
+ queryRemote?<T = any>(queryName: string, args?: any): Promise<T>;
29
+ /** List cloud automated cron jobs */
30
+ listAutomations?(): Promise<RemoteAutomationJob[]>;
31
+ /** Enable or disable a cloud automated cron job */
32
+ setAutomationEnabled?(jobId: string, enabled: boolean): Promise<void>;
33
+ /** List remote cloud backup archive files */
34
+ listBackups?(): Promise<RemoteBackupArchive[]>;
35
+ /** Get a public or signed download URL for a cloud file/backup */
36
+ getDownloadUrl?(fileIdOrKey: string): Promise<string | null>;
9
37
  }
10
38
  export * from './supabase.js';
11
39
  export * from './demo.js';
@@ -1,5 +1,5 @@
1
1
  import type { SupabaseClient } from '@supabase/supabase-js';
2
- import { RemoteDBAdapter } from './index.js';
2
+ import { RemoteAutomationJob, RemoteBackupArchive, RemoteDBAdapter } from './index.js';
3
3
  import { DeltaChanges, PushResult, SyncOperation } from '../../core/types.js';
4
4
  import { SyncLogger, CustomLogger, LogLevel } from '../../utils/logger.js';
5
5
  import { createSupabaseStorageUploader, type SupabaseStorageUploaderOptions, type SupabaseStorageUploaderInstance } from '../../storage/supabase.js';
@@ -129,5 +129,29 @@ export declare class SupabaseRemoteAdapter implements RemoteDBAdapter {
129
129
  * Connects local-lite offline blob/file storage directly to Supabase Storage.
130
130
  */
131
131
  createStorageUploader(options: SupabaseStorageUploaderOptions): SupabaseStorageUploaderInstance;
132
+ /**
133
+ * Invokes a Supabase Edge Function or Postgres RPC function.
134
+ */
135
+ call<T = any>(functionName: string, args?: any): Promise<T>;
136
+ /**
137
+ * Queries a remote Postgres RPC or view.
138
+ */
139
+ queryRemote<T = any>(queryName: string, args?: any): Promise<T>;
140
+ /**
141
+ * Lists automated cron jobs configured on Supabase.
142
+ */
143
+ listAutomations(): Promise<RemoteAutomationJob[]>;
144
+ /**
145
+ * Enables or disables an automated cron job on Supabase.
146
+ */
147
+ setAutomationEnabled(jobId: string, enabled: boolean): Promise<void>;
148
+ /**
149
+ * Lists cloud backup archives stored on Supabase Storage.
150
+ */
151
+ listBackups(): Promise<RemoteBackupArchive[]>;
152
+ /**
153
+ * Gets a signed download URL for a file stored on Supabase Storage.
154
+ */
155
+ getDownloadUrl(fileIdOrKey: string): Promise<string | null>;
132
156
  }
133
157
  export { SupabaseRemoteAdapter as SupabaseAdapter, createSupabaseStorageUploader, type SupabaseStorageUploaderOptions, type SupabaseStorageUploaderInstance, };
@@ -558,6 +558,17 @@ class SupabaseRemoteAdapter {
558
558
  catch { }
559
559
  this.activeChannel = undefined;
560
560
  }
561
+ if (client?.getChannels && client?.removeChannel) {
562
+ try {
563
+ const existingChannels = client.getChannels();
564
+ for (const ch of existingChannels) {
565
+ if (ch.topic?.includes(this.channelName)) {
566
+ client.removeChannel(ch);
567
+ }
568
+ }
569
+ }
570
+ catch { }
571
+ }
561
572
  if (!client || typeof client.channel !== 'function') {
562
573
  this.logger.debug('Supabase client is not available; skipping live changes subscription.');
563
574
  return () => {
@@ -650,6 +661,96 @@ class SupabaseRemoteAdapter {
650
661
  createStorageUploader(options) {
651
662
  return (0, supabase_js_1.createSupabaseStorageUploader)(this.getClient(), options);
652
663
  }
664
+ /**
665
+ * Invokes a Supabase Edge Function or Postgres RPC function.
666
+ */
667
+ async call(functionName, args = {}) {
668
+ const client = this.getClient();
669
+ if (!client)
670
+ throw new Error('Supabase client is not available.');
671
+ if (typeof client.functions?.invoke === 'function') {
672
+ try {
673
+ const { data, error } = await client.functions.invoke(functionName, { body: args });
674
+ if (!error)
675
+ return data;
676
+ if (error?.status !== 404 && !error?.message?.includes?.('not found')) {
677
+ throw error;
678
+ }
679
+ }
680
+ catch (err) {
681
+ if (!err?.message?.includes?.('not found')) {
682
+ // If RPC is available, fall through and try RPC
683
+ if (typeof client.rpc !== 'function')
684
+ throw err;
685
+ }
686
+ }
687
+ }
688
+ if (typeof client.rpc === 'function') {
689
+ const { data, error } = await client.rpc(functionName, args);
690
+ if (error)
691
+ throw error;
692
+ return data;
693
+ }
694
+ throw new Error('Supabase client does not support functions or rpc invocation.');
695
+ }
696
+ /**
697
+ * Queries a remote Postgres RPC or view.
698
+ */
699
+ async queryRemote(queryName, args = {}) {
700
+ const client = this.getClient();
701
+ if (typeof client?.rpc === 'function') {
702
+ const { data, error } = await client.rpc(queryName, args);
703
+ if (error)
704
+ throw error;
705
+ return data;
706
+ }
707
+ throw new Error('Supabase client does not support rpc queries.');
708
+ }
709
+ /**
710
+ * Lists automated cron jobs configured on Supabase.
711
+ */
712
+ async listAutomations() {
713
+ return this.call('list_automations', {});
714
+ }
715
+ /**
716
+ * Enables or disables an automated cron job on Supabase.
717
+ */
718
+ async setAutomationEnabled(jobId, enabled) {
719
+ return this.call('set_automation_enabled', { job_id: jobId, enabled });
720
+ }
721
+ /**
722
+ * Lists cloud backup archives stored on Supabase Storage.
723
+ */
724
+ async listBackups() {
725
+ try {
726
+ const client = this.getClient();
727
+ if (typeof client?.storage?.from === 'function') {
728
+ const { data, error } = await client.storage.from('backups').list();
729
+ if (!error && Array.isArray(data)) {
730
+ return data.map((file) => ({
731
+ createdAt: new Date(file.created_at || file.updated_at || Date.now()).getTime(),
732
+ status: 'succeeded',
733
+ fileName: file.name,
734
+ sizeBytes: file.metadata?.size,
735
+ downloadUrl: null,
736
+ }));
737
+ }
738
+ }
739
+ }
740
+ catch { }
741
+ return [];
742
+ }
743
+ /**
744
+ * Gets a signed download URL for a file stored on Supabase Storage.
745
+ */
746
+ async getDownloadUrl(fileIdOrKey) {
747
+ const client = this.getClient();
748
+ if (typeof client?.storage?.from === 'function') {
749
+ const { data } = await client.storage.from('backups').createSignedUrl(fileIdOrKey, 3600);
750
+ return data?.signedUrl ?? null;
751
+ }
752
+ return null;
753
+ }
653
754
  }
654
755
  exports.SupabaseRemoteAdapter = SupabaseRemoteAdapter;
655
756
  exports.SupabaseAdapter = SupabaseRemoteAdapter;
@@ -1,5 +1,5 @@
1
1
  import { LocalDBAdapter, LocalTransaction } from '../adapters/local/index.js';
2
- import { RemoteDBAdapter } from '../adapters/remote/index.js';
2
+ import { RemoteAutomationJob, RemoteBackupArchive, RemoteDBAdapter } from '../adapters/remote/index.js';
3
3
  import { EventEmitter } from '../reactive/event-emitter.js';
4
4
  import { SyncWorker } from './sync-worker.js';
5
5
  import { type OutboxDeleteClause } from './outbox-store.js';
@@ -132,6 +132,30 @@ export declare class LocalFirstClient {
132
132
  private initialization?;
133
133
  constructor(config: LocalFirstClientConfig);
134
134
  getPrimaryKey(): string;
135
+ /**
136
+ * Invokes a remote function, action, or RPC through the configured remote backend adapter.
137
+ * Works seamlessly across Convex actions/mutations, Supabase Edge Functions/RPC, etc.
138
+ */
139
+ call<T = any>(functionName: string, args?: any): Promise<T>;
140
+ /**
141
+ * Executes a remote query through the configured remote backend adapter.
142
+ */
143
+ queryRemote<T = any>(queryName: string, args?: any): Promise<T>;
144
+ /**
145
+ * Cloud automation / scheduled cron job controls.
146
+ */
147
+ get automations(): {
148
+ list: () => Promise<RemoteAutomationJob[]>;
149
+ setEnabled: (jobId: string, enabled: boolean) => Promise<void>;
150
+ };
151
+ /**
152
+ * Lists remote database backup archives from cloud storage.
153
+ */
154
+ listBackups(): Promise<RemoteBackupArchive[]>;
155
+ /**
156
+ * Retrieves a download URL for a file stored in the remote backend.
157
+ */
158
+ getDownloadUrl(fileIdOrKey: string): Promise<string | null>;
135
159
  /**
136
160
  * Options for TableManager.applyMutation on locally-originated writes.
137
161
  * The touch value uses the mutation timestamp so it matches what remote
@@ -363,6 +363,62 @@ class LocalFirstClient {
363
363
  getPrimaryKey() {
364
364
  return this.primaryKey;
365
365
  }
366
+ /**
367
+ * Invokes a remote function, action, or RPC through the configured remote backend adapter.
368
+ * Works seamlessly across Convex actions/mutations, Supabase Edge Functions/RPC, etc.
369
+ */
370
+ async call(functionName, args = {}) {
371
+ if (!this.remote || typeof this.remote.call !== 'function') {
372
+ throw new Error(`The current remote adapter does not support remote function calls (call).`);
373
+ }
374
+ return this.remote.call(functionName, args);
375
+ }
376
+ /**
377
+ * Executes a remote query through the configured remote backend adapter.
378
+ */
379
+ async queryRemote(queryName, args = {}) {
380
+ if (!this.remote || typeof this.remote.queryRemote !== 'function') {
381
+ throw new Error(`The current remote adapter does not support remote queries (queryRemote).`);
382
+ }
383
+ return this.remote.queryRemote(queryName, args);
384
+ }
385
+ /**
386
+ * Cloud automation / scheduled cron job controls.
387
+ */
388
+ get automations() {
389
+ return {
390
+ list: async () => {
391
+ if (this.remote && typeof this.remote.listAutomations === 'function') {
392
+ return this.remote.listAutomations();
393
+ }
394
+ return [];
395
+ },
396
+ setEnabled: async (jobId, enabled) => {
397
+ if (this.remote && typeof this.remote.setAutomationEnabled === 'function') {
398
+ return this.remote.setAutomationEnabled(jobId, enabled);
399
+ }
400
+ throw new Error('Remote adapter does not support remote automations.');
401
+ },
402
+ };
403
+ }
404
+ /**
405
+ * Lists remote database backup archives from cloud storage.
406
+ */
407
+ async listBackups() {
408
+ if (this.remote && typeof this.remote.listBackups === 'function') {
409
+ return this.remote.listBackups();
410
+ }
411
+ return [];
412
+ }
413
+ /**
414
+ * Retrieves a download URL for a file stored in the remote backend.
415
+ */
416
+ async getDownloadUrl(fileIdOrKey) {
417
+ if (this.remote && typeof this.remote.getDownloadUrl === 'function') {
418
+ return this.remote.getDownloadUrl(fileIdOrKey);
419
+ }
420
+ return null;
421
+ }
366
422
  /**
367
423
  * Options for TableManager.applyMutation on locally-originated writes.
368
424
  * The touch value uses the mutation timestamp so it matches what remote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
4
4
  "description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",