@powersync/common 1.25.0 → 1.27.0

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.
@@ -265,6 +265,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
265
265
  * and optionally return results.
266
266
  */
267
267
  execute(sql: string, parameters?: any[]): Promise<QueryResult>;
268
+ executeRaw(sql: string, parameters?: any[]): Promise<any[][]>;
268
269
  /**
269
270
  * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
270
271
  * and optionally return results.
@@ -459,6 +459,10 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
459
459
  await this.waitForReady();
460
460
  return this.database.execute(sql, parameters);
461
461
  }
462
+ async executeRaw(sql, parameters) {
463
+ await this.waitForReady();
464
+ return this.database.executeRaw(sql, parameters);
465
+ }
462
466
  /**
463
467
  * Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
464
468
  * and optionally return results.
@@ -6,6 +6,9 @@ export interface SQLOpenOptions {
6
6
  dbFilename: string;
7
7
  /**
8
8
  * Directory where the database file is located.
9
+ *
10
+ * When set, the directory must exist when the database is opened, it will
11
+ * not be created automatically.
9
12
  */
10
13
  dbLocation?: string;
11
14
  /**
@@ -148,6 +148,11 @@ The next upload iteration will be delayed.`);
148
148
  }
149
149
  checkedCrudItem = nextCrudItem;
150
150
  await this.options.uploadCrud();
151
+ this.updateSyncStatus({
152
+ dataFlow: {
153
+ uploadError: undefined
154
+ }
155
+ });
151
156
  }
152
157
  else {
153
158
  // Uploading is completed
@@ -159,7 +164,8 @@ The next upload iteration will be delayed.`);
159
164
  checkedCrudItem = undefined;
160
165
  this.updateSyncStatus({
161
166
  dataFlow: {
162
- uploading: false
167
+ uploading: false,
168
+ uploadError: ex
163
169
  }
164
170
  });
165
171
  await this.delayRetry();
@@ -300,6 +306,11 @@ The next upload iteration will be delayed.`);
300
306
  else {
301
307
  this.logger.error(ex);
302
308
  }
309
+ this.updateSyncStatus({
310
+ dataFlow: {
311
+ downloadError: ex
312
+ }
313
+ });
303
314
  // On error, wait a little before retrying
304
315
  await this.delayRetry();
305
316
  }
@@ -422,7 +433,8 @@ The next upload iteration will be delayed.`);
422
433
  connected: true,
423
434
  lastSyncedAt: new Date(),
424
435
  dataFlow: {
425
- downloading: false
436
+ downloading: false,
437
+ downloadError: undefined
426
438
  }
427
439
  });
428
440
  }
@@ -520,7 +532,10 @@ The next upload iteration will be delayed.`);
520
532
  this.updateSyncStatus({
521
533
  connected: true,
522
534
  lastSyncedAt: new Date(),
523
- priorityStatusEntries: []
535
+ priorityStatusEntries: [],
536
+ dataFlow: {
537
+ downloadError: undefined
538
+ }
524
539
  });
525
540
  }
526
541
  else if (validatedCheckpoint === targetCheckpoint) {
@@ -542,7 +557,8 @@ The next upload iteration will be delayed.`);
542
557
  lastSyncedAt: new Date(),
543
558
  priorityStatusEntries: [],
544
559
  dataFlow: {
545
- downloading: false
560
+ downloading: false,
561
+ downloadError: undefined
546
562
  }
547
563
  });
548
564
  }
@@ -39,6 +39,21 @@ export interface DBGetUtils {
39
39
  export interface LockContext extends DBGetUtils {
40
40
  /** Execute a single write statement. */
41
41
  execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
42
+ /**
43
+ * Execute a single write statement and return raw results.
44
+ * Unlike `execute`, which returns an object with structured key-value pairs,
45
+ * `executeRaw` returns a nested array of raw values, where each row is
46
+ * represented as an array of column values without field names.
47
+ *
48
+ * Example result:
49
+ *
50
+ * ```[ [ '1', 'list 1', '33', 'Post content', '1' ] ]```
51
+ *
52
+ * Where as `execute`'s `rows._array` would have been:
53
+ *
54
+ * ```[ { id: '33', name: 'list 1', content: 'Post content', list_id: '1' } ]```
55
+ */
56
+ executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
42
57
  }
43
58
  export interface Transaction extends LockContext {
44
59
  /** Commit multiple changes to the local DB using the Transaction context. */
@@ -84,6 +99,7 @@ export interface DBLockOptions {
84
99
  export interface DBAdapter extends BaseObserverInterface<DBAdapterListener>, DBGetUtils {
85
100
  close: () => void | Promise<void>;
86
101
  execute: (query: string, params?: any[]) => Promise<QueryResult>;
102
+ executeRaw: (query: string, params?: any[]) => Promise<any[][]>;
87
103
  executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
88
104
  name: string;
89
105
  readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
@@ -1,6 +1,17 @@
1
1
  export type SyncDataFlowStatus = Partial<{
2
2
  downloading: boolean;
3
3
  uploading: boolean;
4
+ /**
5
+ * Error during downloading (including connecting).
6
+ *
7
+ * Cleared on the next successful data download.
8
+ */
9
+ downloadError?: Error;
10
+ /**
11
+ * Error during uploading.
12
+ * Cleared on the next successful upload.
13
+ */
14
+ uploadError?: Error;
4
15
  }>;
5
16
  export interface SyncPriorityStatus {
6
17
  priority: number;
@@ -39,6 +50,17 @@ export declare class SyncStatus {
39
50
  get dataFlowStatus(): Partial<{
40
51
  downloading: boolean;
41
52
  uploading: boolean;
53
+ /**
54
+ * Error during downloading (including connecting).
55
+ *
56
+ * Cleared on the next successful data download.
57
+ */
58
+ downloadError?: Error;
59
+ /**
60
+ * Error during uploading.
61
+ * Cleared on the next successful upload.
62
+ */
63
+ uploadError?: Error;
42
64
  }>;
43
65
  /**
44
66
  * Partial sync status for involved bucket priorities.
@@ -83,7 +83,7 @@ export class SyncStatus {
83
83
  }
84
84
  getMessage() {
85
85
  const dataFlow = this.dataFlowStatus;
86
- return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}`;
86
+ return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}. UploadError: ${dataFlow.uploadError}, DownloadError?: ${dataFlow.downloadError}>`;
87
87
  }
88
88
  toJSON() {
89
89
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "1.25.0",
3
+ "version": "1.27.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"