@powersync/common 1.57.1 → 2.0.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.
Files changed (219) hide show
  1. package/lib/attachments/AttachmentContext.d.ts +5 -5
  2. package/lib/attachments/AttachmentContext.js +6 -2
  3. package/lib/attachments/AttachmentContext.js.map +1 -1
  4. package/lib/attachments/AttachmentQueue.d.ts +6 -6
  5. package/lib/attachments/AttachmentQueue.js +9 -8
  6. package/lib/attachments/AttachmentQueue.js.map +1 -1
  7. package/lib/attachments/AttachmentService.d.ts +3 -3
  8. package/lib/attachments/AttachmentService.js +4 -3
  9. package/lib/attachments/AttachmentService.js.map +1 -1
  10. package/lib/attachments/Schema.d.ts +2 -2
  11. package/lib/attachments/SyncingService.d.ts +2 -2
  12. package/lib/attachments/SyncingService.js +21 -6
  13. package/lib/attachments/SyncingService.js.map +1 -1
  14. package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +56 -232
  15. package/lib/client/CommonPowerSyncDatabase.js +2 -0
  16. package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
  17. package/lib/client/SQLOpenFactory.d.ts +35 -13
  18. package/lib/client/SQLOpenFactory.js +1 -25
  19. package/lib/client/SQLOpenFactory.js.map +1 -1
  20. package/lib/client/compilableQueryWatch.d.ts +2 -2
  21. package/lib/client/compilableQueryWatch.js +1 -2
  22. package/lib/client/compilableQueryWatch.js.map +1 -1
  23. package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -3
  24. package/lib/client/runOnSchemaChange.d.ts +2 -2
  25. package/lib/client/runOnSchemaChange.js.map +1 -1
  26. package/lib/client/sync/bucket/CrudEntry.d.ts +3 -34
  27. package/lib/client/sync/bucket/CrudEntry.js +0 -99
  28. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  29. package/lib/client/sync/options.d.ts +65 -0
  30. package/lib/client/sync/options.js +25 -0
  31. package/lib/client/sync/options.js.map +1 -0
  32. package/lib/client/sync/sync-streams.d.ts +1 -1
  33. package/lib/client/triggers/TriggerManager.d.ts +9 -38
  34. package/lib/client/watched/GetAllQuery.d.ts +3 -3
  35. package/lib/client/watched/GetAllQuery.js +1 -1
  36. package/lib/client/watched/GetAllQuery.js.map +1 -1
  37. package/lib/client/watched/WatchedQuery.d.ts +2 -10
  38. package/lib/client/watched/WatchedQuery.js +0 -11
  39. package/lib/client/watched/WatchedQuery.js.map +1 -1
  40. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +0 -50
  41. package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -176
  42. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  43. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +0 -22
  44. package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
  45. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  46. package/lib/db/DBAdapter.d.ts +72 -154
  47. package/lib/db/DBAdapter.js +70 -108
  48. package/lib/db/DBAdapter.js.map +1 -1
  49. package/lib/db/QueryResult.d.ts +104 -0
  50. package/lib/db/QueryResult.js +96 -0
  51. package/lib/db/QueryResult.js.map +1 -0
  52. package/lib/db/crud/SyncProgress.d.ts +1 -13
  53. package/lib/db/crud/SyncProgress.js +1 -62
  54. package/lib/db/crud/SyncProgress.js.map +1 -1
  55. package/lib/db/crud/SyncStatus.d.ts +32 -66
  56. package/lib/db/crud/SyncStatus.js +1 -253
  57. package/lib/db/crud/SyncStatus.js.map +1 -1
  58. package/lib/db/schema/Column.d.ts +0 -7
  59. package/lib/db/schema/Column.js +0 -7
  60. package/lib/db/schema/Column.js.map +1 -1
  61. package/lib/db/schema/Index.d.ts +2 -6
  62. package/lib/db/schema/Index.js +1 -4
  63. package/lib/db/schema/Index.js.map +1 -1
  64. package/lib/db/schema/IndexedColumn.d.ts +2 -6
  65. package/lib/db/schema/IndexedColumn.js +1 -4
  66. package/lib/db/schema/IndexedColumn.js.map +1 -1
  67. package/lib/db/schema/Schema.d.ts +4 -28
  68. package/lib/db/schema/Schema.js.map +1 -1
  69. package/lib/db/schema/Table.d.ts +50 -96
  70. package/lib/db/schema/Table.js +83 -91
  71. package/lib/db/schema/Table.js.map +1 -1
  72. package/lib/index.d.ts +5 -21
  73. package/lib/index.js +5 -22
  74. package/lib/index.js.map +1 -1
  75. package/lib/utils/BaseObserver.d.ts +1 -1
  76. package/lib/utils/BaseObserver.js +1 -1
  77. package/lib/utils/Logger.d.ts +52 -23
  78. package/lib/utils/Logger.js +35 -33
  79. package/lib/utils/Logger.js.map +1 -1
  80. package/lib/utils/MetaBaseObserver.d.ts +11 -11
  81. package/lib/utils/MetaBaseObserver.js +1 -50
  82. package/lib/utils/MetaBaseObserver.js.map +1 -1
  83. package/lib/utils/mutex.d.ts +3 -53
  84. package/lib/utils/mutex.js +1 -156
  85. package/lib/utils/mutex.js.map +1 -1
  86. package/package.json +8 -45
  87. package/src/attachments/AttachmentContext.ts +11 -10
  88. package/src/attachments/AttachmentQueue.ts +15 -14
  89. package/src/attachments/AttachmentService.ts +7 -6
  90. package/src/attachments/Schema.ts +2 -2
  91. package/src/attachments/SyncingService.ts +23 -9
  92. package/src/client/CommonPowerSyncDatabase.ts +540 -0
  93. package/src/client/SQLOpenFactory.ts +38 -22
  94. package/src/client/compilableQueryWatch.ts +3 -4
  95. package/src/client/connection/PowerSyncBackendConnector.ts +3 -3
  96. package/src/client/runOnSchemaChange.ts +2 -2
  97. package/src/client/sync/bucket/CrudEntry.ts +4 -104
  98. package/src/client/sync/options.ts +77 -0
  99. package/src/client/sync/sync-streams.ts +1 -1
  100. package/src/client/triggers/TriggerManager.ts +10 -41
  101. package/src/client/watched/GetAllQuery.ts +3 -3
  102. package/src/client/watched/WatchedQuery.ts +2 -15
  103. package/src/client/watched/processors/DifferentialQueryProcessor.ts +0 -223
  104. package/src/client/watched/processors/OnChangeQueryProcessor.ts +0 -111
  105. package/src/db/DBAdapter.ts +141 -226
  106. package/src/db/QueryResult.ts +195 -0
  107. package/src/db/crud/SyncProgress.ts +2 -42
  108. package/src/db/crud/SyncStatus.ts +45 -220
  109. package/src/db/schema/Column.ts +0 -8
  110. package/src/db/schema/Index.ts +3 -6
  111. package/src/db/schema/IndexedColumn.ts +3 -6
  112. package/src/db/schema/Schema.ts +4 -4
  113. package/src/db/schema/Table.ts +111 -186
  114. package/src/index.ts +5 -21
  115. package/src/utils/BaseObserver.ts +1 -1
  116. package/src/utils/Logger.ts +80 -34
  117. package/src/utils/MetaBaseObserver.ts +14 -60
  118. package/src/utils/mutex.ts +4 -201
  119. package/dist/bundle.cjs +0 -14390
  120. package/dist/bundle.cjs.map +0 -1
  121. package/dist/bundle.mjs +0 -14309
  122. package/dist/bundle.mjs.map +0 -1
  123. package/dist/bundle.node.cjs +0 -12021
  124. package/dist/bundle.node.cjs.map +0 -1
  125. package/dist/bundle.node.mjs +0 -11940
  126. package/dist/bundle.node.mjs.map +0 -1
  127. package/dist/index.d.cts +0 -4651
  128. package/legacy/sync_protocol.d.ts +0 -103
  129. package/lib/client/AbstractPowerSyncDatabase.js +0 -990
  130. package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
  131. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -28
  132. package/lib/client/AbstractPowerSyncOpenFactory.js +0 -28
  133. package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
  134. package/lib/client/ConnectionManager.d.ts +0 -115
  135. package/lib/client/ConnectionManager.js +0 -294
  136. package/lib/client/ConnectionManager.js.map +0 -1
  137. package/lib/client/CustomQuery.d.ts +0 -22
  138. package/lib/client/CustomQuery.js +0 -43
  139. package/lib/client/CustomQuery.js.map +0 -1
  140. package/lib/client/constants.d.ts +0 -4
  141. package/lib/client/constants.js +0 -5
  142. package/lib/client/constants.js.map +0 -1
  143. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -56
  144. package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -29
  145. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
  146. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -37
  147. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -165
  148. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
  149. package/lib/client/sync/stream/AbstractRemote.d.ts +0 -180
  150. package/lib/client/sync/stream/AbstractRemote.js +0 -505
  151. package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
  152. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -265
  153. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -705
  154. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
  155. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
  156. package/lib/client/sync/stream/WebsocketClientTransport.js +0 -62
  157. package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
  158. package/lib/client/sync/stream/core-instruction.d.ts +0 -77
  159. package/lib/client/sync/stream/core-instruction.js +0 -30
  160. package/lib/client/sync/stream/core-instruction.js.map +0 -1
  161. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
  162. package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
  163. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
  164. package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
  165. package/lib/client/triggers/TriggerManagerImpl.js +0 -410
  166. package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
  167. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
  168. package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
  169. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
  170. package/lib/db/ConnectionClosedError.d.ts +0 -12
  171. package/lib/db/ConnectionClosedError.js +0 -23
  172. package/lib/db/ConnectionClosedError.js.map +0 -1
  173. package/lib/db/schema/TableV2.d.ts +0 -11
  174. package/lib/db/schema/TableV2.js +0 -11
  175. package/lib/db/schema/TableV2.js.map +0 -1
  176. package/lib/utils/AbortOperation.d.ts +0 -11
  177. package/lib/utils/AbortOperation.js +0 -21
  178. package/lib/utils/AbortOperation.js.map +0 -1
  179. package/lib/utils/ControlledExecutor.d.ts +0 -31
  180. package/lib/utils/ControlledExecutor.js +0 -54
  181. package/lib/utils/ControlledExecutor.js.map +0 -1
  182. package/lib/utils/async.d.ts +0 -46
  183. package/lib/utils/async.js +0 -147
  184. package/lib/utils/async.js.map +0 -1
  185. package/lib/utils/compatibility.d.ts +0 -8
  186. package/lib/utils/compatibility.js +0 -9
  187. package/lib/utils/compatibility.js.map +0 -1
  188. package/lib/utils/parseQuery.d.ts +0 -12
  189. package/lib/utils/parseQuery.js +0 -20
  190. package/lib/utils/parseQuery.js.map +0 -1
  191. package/lib/utils/queue.d.ts +0 -16
  192. package/lib/utils/queue.js +0 -42
  193. package/lib/utils/queue.js.map +0 -1
  194. package/lib/utils/stream_transform.d.ts +0 -41
  195. package/lib/utils/stream_transform.js +0 -211
  196. package/lib/utils/stream_transform.js.map +0 -1
  197. package/src/client/AbstractPowerSyncDatabase.ts +0 -1408
  198. package/src/client/AbstractPowerSyncOpenFactory.ts +0 -45
  199. package/src/client/ConnectionManager.ts +0 -405
  200. package/src/client/CustomQuery.ts +0 -56
  201. package/src/client/constants.ts +0 -4
  202. package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -65
  203. package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -202
  204. package/src/client/sync/stream/AbstractRemote.ts +0 -644
  205. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -970
  206. package/src/client/sync/stream/WebsocketClientTransport.ts +0 -82
  207. package/src/client/sync/stream/core-instruction.ts +0 -109
  208. package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
  209. package/src/client/triggers/TriggerManagerImpl.ts +0 -501
  210. package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
  211. package/src/db/ConnectionClosedError.ts +0 -25
  212. package/src/db/schema/TableV2.ts +0 -11
  213. package/src/utils/AbortOperation.ts +0 -19
  214. package/src/utils/ControlledExecutor.ts +0 -78
  215. package/src/utils/async.ts +0 -185
  216. package/src/utils/compatibility.ts +0 -9
  217. package/src/utils/parseQuery.ts +0 -31
  218. package/src/utils/queue.ts +0 -48
  219. package/src/utils/stream_transform.ts +0 -260
@@ -0,0 +1,195 @@
1
+ /**
2
+ * A SQLite value, either text, a number, a blob value or null.
3
+ *
4
+ * @public
5
+ */
6
+ export type SqliteValue = string | number | bigint | number[] | Uint8Array | null;
7
+
8
+ /**
9
+ * A record of SQLite values representing a row.
10
+ *
11
+ * @public
12
+ */
13
+ export type SqliteRecord = Record<string, SqliteValue>;
14
+
15
+ /**
16
+ * A representation of query results as JavaScript object.
17
+ *
18
+ * @public
19
+ */
20
+ export interface ResultSet {
21
+ /**
22
+ * The amount of rows in the result set.
23
+ */
24
+ get length(): number;
25
+
26
+ /**
27
+ * @deprecated Use {@link QueryResult.array} instead.
28
+ */
29
+ get _array(): any[];
30
+
31
+ /**
32
+ * @deprecated Use {@link QueryResult.array} instead.
33
+ */
34
+ item<T>(idx: number): T;
35
+ }
36
+
37
+ /**
38
+ * Shared superinterface for {@link QueryResult} and {@link RawQueryResult}.
39
+ *
40
+ * @public
41
+ */
42
+ export interface BaseQueryResult {
43
+ /** Represents the auto-generated row id if applicable. */
44
+ insertId?: number;
45
+ /**
46
+ * Number of affected rows reported by SQLite for a write query.
47
+ *
48
+ * When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
49
+ * `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
50
+ * Use a `RETURNING` clause and inspect `rows` when you need to confirm which rows changed.
51
+ */
52
+ rowsAffected?: number;
53
+ }
54
+
55
+ /**
56
+ * Object returned by SQL Query executions.
57
+ *
58
+ * @public
59
+ */
60
+ export interface QueryResult<T = SqliteRecord> extends BaseQueryResult, Iterable<T, undefined> {
61
+ /**
62
+ * If the query returned rows, the result set containing returned values.
63
+ */
64
+ rows?: ResultSet;
65
+ /**
66
+ * Rows in this result set.
67
+ */
68
+ array: T[];
69
+ }
70
+
71
+ /**
72
+ * A raw array-based result set representing rows returned by SQLite.
73
+ *
74
+ * @public
75
+ */
76
+ export interface RawQueryResult extends BaseQueryResult {
77
+ /**
78
+ * Names of columns in this result set. Every column has a name, so the length of this array is always equal to the
79
+ * amount of columns in the result set.
80
+ *
81
+ * Note that column names are not necessarily unique, e.g. a `SELECT foo.user, bar.user FROM ...` will have
82
+ * `['user', 'user']` in this array.
83
+ */
84
+ columnNames: string[];
85
+
86
+ /**
87
+ * Rows in the result set.
88
+ *
89
+ * Each row has a length equal to {@link RawQueryResult.columnNames}.
90
+ */
91
+ rawRows: SqliteValue[][];
92
+ }
93
+
94
+ function rowToRecord<T>(columnNames: string[], row: SqliteValue[]) {
95
+ const record: SqliteRecord = {};
96
+ columnNames.forEach((name, idx) => (record[name] = row[idx]));
97
+ return record as T;
98
+ }
99
+
100
+ /**
101
+ * Creates a query result by mapping raw rows to JavaScript.
102
+ *
103
+ * This should not be used with libraries doing this mapping natively, as that is typically more performant.
104
+ *
105
+ * @public
106
+ */
107
+ export function queryResultFromRaw<T>(raw: RawQueryResult): QueryResult<T> {
108
+ const { insertId, rowsAffected, columnNames, rawRows } = raw;
109
+ let array: any[] | undefined;
110
+
111
+ function loadAsArray() {
112
+ if (array) return array;
113
+
114
+ return (array = rawRows.map((row) => rowToRecord(columnNames, row)));
115
+ }
116
+
117
+ function getRow<T>(idx: number) {
118
+ if (array) return array[idx];
119
+ return rowToRecord(columnNames, rawRows[idx]);
120
+ }
121
+
122
+ return {
123
+ insertId,
124
+ rowsAffected,
125
+ get array() {
126
+ return loadAsArray();
127
+ },
128
+ rows: {
129
+ length: rawRows.length,
130
+ get _array() {
131
+ return loadAsArray();
132
+ },
133
+ item: getRow
134
+ } satisfies ResultSet,
135
+ [Symbol.iterator](): Iterator<T> {
136
+ let nextIndex = 0;
137
+
138
+ return {
139
+ next: function (): IteratorResult<T, any> {
140
+ if (nextIndex >= rawRows.length) {
141
+ return { done: true, value: undefined };
142
+ }
143
+
144
+ const row = getRow(nextIndex);
145
+ nextIndex++;
146
+ return { done: false, value: row };
147
+ }
148
+ };
149
+ }
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Creates a query result from rows that have already been mapped to JavaScript.
155
+ *
156
+ * @public
157
+ */
158
+ export function queryResultFromMapped<T>(base: BaseQueryResult, rows?: T[]): QueryResult<T> {
159
+ if (rows == null) return queryResultWithoutRows(base);
160
+
161
+ return {
162
+ insertId: base.insertId,
163
+ rowsAffected: base.rowsAffected,
164
+ array: rows ?? [],
165
+ rows: {
166
+ length: rows.length,
167
+ _array: rows,
168
+ item(i: number) {
169
+ return rows[i] as any;
170
+ }
171
+ } satisfies ResultSet,
172
+ [Symbol.iterator](): Iterator<T> {
173
+ return rows[Symbol.iterator]();
174
+ }
175
+ };
176
+ }
177
+
178
+ /**
179
+ * Creates a {@link QueryResult} not containing any rows.
180
+ *
181
+ * @public
182
+ */
183
+ export function queryResultWithoutRows(result: BaseQueryResult): QueryResult<never> {
184
+ return {
185
+ ...result,
186
+ array: [],
187
+ [Symbol.iterator](): Iterator<never> {
188
+ return {
189
+ next() {
190
+ return { done: true, value: undefined };
191
+ }
192
+ };
193
+ }
194
+ };
195
+ }
@@ -1,15 +1,5 @@
1
- import type { BucketProgress } from '../../client/sync/stream/core-instruction.js';
2
1
  import type { SyncStatus } from './SyncStatus.js';
3
2
 
4
- // (bucket, progress) pairs
5
- /** @internal */
6
- export type InternalProgressInformation = Record<string, BucketProgress>;
7
-
8
- /**
9
- * @internal The priority used by the core extension to indicate that a full sync was completed.
10
- */
11
- export const FULL_SYNC_PRIORITY = 2147483647;
12
-
13
3
  /**
14
4
  * Information about a progressing download made by the PowerSync SDK.
15
5
  *
@@ -64,42 +54,12 @@ export interface ProgressWithOperations {
64
54
  *
65
55
  * @public
66
56
  */
67
- export class SyncProgress implements ProgressWithOperations {
68
- totalOperations: number;
69
- downloadedOperations: number;
70
- downloadedFraction: number;
71
-
72
- constructor(protected internal: InternalProgressInformation) {
73
- const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
74
-
75
- this.totalOperations = untilCompletion.totalOperations;
76
- this.downloadedOperations = untilCompletion.downloadedOperations;
77
- this.downloadedFraction = untilCompletion.downloadedFraction;
78
- }
79
-
57
+ export interface SyncProgress extends ProgressWithOperations {
80
58
  /**
81
59
  * Returns download progress towards all data up until the specified priority being received.
82
60
  *
83
61
  * The returned {@link ProgressWithOperations} tracks the target amount of operations that need
84
62
  * to be downloaded in total and how many of them have already been received.
85
63
  */
86
- untilPriority(priority: number): ProgressWithOperations {
87
- let total = 0;
88
- let downloaded = 0;
89
-
90
- for (const progress of Object.values(this.internal)) {
91
- // Include higher-priority buckets, which are represented by lower numbers.
92
- if (progress.priority <= priority) {
93
- downloaded += progress.since_last;
94
- total += progress.target_count - progress.at_last;
95
- }
96
- }
97
-
98
- let progress = total == 0 ? 0.0 : downloaded / total;
99
- return {
100
- totalOperations: total,
101
- downloadedOperations: downloaded,
102
- downloadedFraction: progress
103
- };
104
- }
64
+ untilPriority(priority: number): ProgressWithOperations;
105
65
  }
@@ -1,12 +1,11 @@
1
- import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js';
2
- import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js';
3
1
  import { SyncStreamDescription, SyncSubscriptionDescription } from '../../client/sync/sync-streams.js';
4
- import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js';
2
+ import { ProgressWithOperations, SyncProgress } from './SyncProgress.js';
5
3
 
6
4
  /**
7
5
  * @public
6
+ * @deprecated All fields are available on {@link SyncStatus} directly.
8
7
  */
9
- export type SyncDataFlowStatus = Partial<{
8
+ export interface SyncDataFlowStatus {
10
9
  downloading: boolean;
11
10
  uploading: boolean;
12
11
  /**
@@ -20,17 +19,7 @@ export type SyncDataFlowStatus = Partial<{
20
19
  * Cleared on the next successful upload.
21
20
  */
22
21
  uploadError?: Error;
23
- /**
24
- * Internal information about how far we are downloading operations in buckets.
25
- *
26
- * @internal Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
27
- */
28
- downloadProgress: InternalProgressInformation | null;
29
- /**
30
- * @internal
31
- */
32
- internalStreamSubscriptions: CoreStreamSubscription[] | null;
33
- }>;
22
+ }
34
23
 
35
24
  /**
36
25
  * @public
@@ -42,56 +31,51 @@ export interface SyncPriorityStatus {
42
31
  }
43
32
 
44
33
  /**
45
- * @internal
34
+ * @public
46
35
  */
47
- export type SyncStatusOptions = {
48
- connected?: boolean;
49
- connecting?: boolean;
50
- dataFlow?: SyncDataFlowStatus;
51
- lastSyncedAt?: Date;
52
- hasSynced?: boolean;
53
- priorityStatusEntries?: SyncPriorityStatus[];
36
+ export interface SyncStatus {
54
37
  /**
55
- * @deprecated This field is no longer set, since {@link SyncClientImplementation.RUST} is the only option.
38
+ * Indicates if the client is currently connected to the PowerSync service.
39
+ *
40
+ * @returns True if connected, false otherwise. Defaults to false if not specified.
56
41
  */
57
- clientImplementation?: SyncClientImplementation;
58
- };
59
-
60
- /**
61
- * @public
62
- */
63
- export class SyncStatus {
64
- constructor(protected options: SyncStatusOptions) {}
42
+ get connected(): boolean;
65
43
 
66
44
  /**
67
- * Returns the used sync client implementation (either the one implemented in JavaScript or the newer Rust-based
68
- * implementation).
69
- *
70
- * This information is only available after a connection has been requested.
45
+ * Indicates if the client is in the process of establishing a connection to the PowerSync service.
71
46
  *
72
- * @deprecated This always returns the Rust client (the only option).
47
+ * @returns True if connecting, false otherwise. Defaults to false if not specified.
73
48
  */
74
- get clientImplementation() {
75
- return this.options.clientImplementation;
76
- }
49
+ get connecting(): boolean;
77
50
 
78
51
  /**
79
- * Indicates if the client is currently connected to the PowerSync service.
80
- *
81
- * @returns True if connected, false otherwise. Defaults to false if not specified.
52
+ * Whether the PowerSync SDK is currently downloading data from the connected PowerSync service.
82
53
  */
83
- get connected(): boolean {
84
- return this.options.connected ?? false;
85
- }
54
+ get downloading(): boolean;
86
55
 
87
56
  /**
88
- * Indicates if the client is in the process of establishing a connection to the PowerSync service.
57
+ * Whether the PowerSync SDK is currently uploading local mutations through the configured
58
+ * {@link PowerSyncBackendConnector}.
59
+ */
60
+ get uploading(): boolean;
61
+
62
+ /**
63
+ * An error that occurred during downloads (including connection establishment errors).
89
64
  *
90
- * @returns True if connecting, false otherwise. Defaults to false if not specified.
65
+ * A download error will be reported on all sync status entries until the next successful sync.
91
66
  */
92
- get connecting(): boolean {
93
- return this.options.connecting ?? false;
94
- }
67
+ get downloadError(): Error | undefined;
68
+
69
+ /**
70
+ * Error during uploading.
71
+ * Cleared on the next successful upload.
72
+ */
73
+ get uploadError(): Error | undefined;
74
+
75
+ /**
76
+ * @deprecated All fields on {@link SyncDataFlowStatus} are available on {@link SyncStatus} directly.
77
+ */
78
+ get dataFlowStatus(): SyncDataFlowStatus;
95
79
 
96
80
  /**
97
81
  * Time that a last sync has fully completed, if any.
@@ -99,9 +83,7 @@ export class SyncStatus {
99
83
  *
100
84
  * @returns The timestamp of the last successful sync, or undefined if no sync has completed.
101
85
  */
102
- get lastSyncedAt(): Date | undefined {
103
- return this.options.lastSyncedAt;
104
- }
86
+ get lastSyncedAt(): Date | undefined;
105
87
 
106
88
  /**
107
89
  * Indicates whether there has been at least one full sync completed since initialization.
@@ -109,33 +91,7 @@ export class SyncStatus {
109
91
  * @returns True if at least one sync has completed, false if no sync has completed,
110
92
  * or undefined when the state is still being loaded from the database.
111
93
  */
112
- get hasSynced(): boolean | undefined {
113
- return this.options.hasSynced;
114
- }
115
-
116
- /**
117
- * Provides the current data flow status regarding uploads and downloads.
118
- *
119
- * @returns An object containing:
120
- * - downloading: True if actively downloading changes (only when connected is also true)
121
- * - uploading: True if actively uploading changes
122
- * Defaults to `{downloading: false, uploading: false}` if not specified.
123
- */
124
- get dataFlowStatus(): SyncDataFlowStatus {
125
- return (
126
- this.options.dataFlow ?? {
127
- /**
128
- * true if actively downloading changes.
129
- * This is only true when {@link connected} is also true.
130
- */
131
- downloading: false,
132
- /**
133
- * true if uploading changes.
134
- */
135
- uploading: false
136
- }
137
- );
138
- }
94
+ get hasSynced(): boolean | undefined;
139
95
 
140
96
  /**
141
97
  * All sync streams currently being tracked in the database.
@@ -143,21 +99,12 @@ export class SyncStatus {
143
99
  * This returns null when the database is currently being opened and we don't have reliable information about all
144
100
  * included streams yet.
145
101
  */
146
- get syncStreams(): SyncStreamStatus[] | undefined {
147
- return this.options.dataFlow?.internalStreamSubscriptions?.map((core) => new SyncStreamStatusView(this, core));
148
- }
102
+ get syncStreams(): SyncStreamStatus[] | undefined;
149
103
 
150
104
  /**
151
105
  * If the `stream` appears in {@link SyncStatus.syncStreams}, returns the current status for that stream.
152
106
  */
153
- forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined {
154
- const asJson = JSON.stringify(stream.parameters);
155
- const raw = this.options.dataFlow?.internalStreamSubscriptions?.find(
156
- (r) => r.name == stream.name && asJson == JSON.stringify(r.parameters)
157
- );
158
-
159
- return raw && new SyncStreamStatusView(this, raw);
160
- }
107
+ forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
161
108
 
162
109
  /**
163
110
  * Provides sync status information for all bucket priorities, sorted by priority (highest first).
@@ -165,24 +112,15 @@ export class SyncStatus {
165
112
  * @returns An array of status entries for different sync priority levels,
166
113
  * sorted with highest priorities (lower numbers) first.
167
114
  */
168
- get priorityStatusEntries(): SyncPriorityStatus[] {
169
- return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
170
- }
115
+ get priorityStatusEntries(): SyncPriorityStatus[] | undefined;
171
116
 
172
117
  /**
173
118
  * A realtime progress report on how many operations have been downloaded and
174
119
  * how many are necessary in total to complete the next sync iteration.
175
120
  *
176
- * This field is only set when {@link SyncDataFlowStatus#downloading} is also true.
121
+ * This field is only set when {@link SyncStatus#downloading} is also true.
177
122
  */
178
- get downloadProgress(): SyncProgress | null {
179
- const internalProgress = this.options.dataFlow?.downloadProgress;
180
- if (internalProgress == null) {
181
- return null;
182
- }
183
-
184
- return new SyncProgress(internalProgress);
185
- }
123
+ get downloadProgress(): SyncProgress | null;
186
124
 
187
125
  /**
188
126
  * Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
@@ -203,22 +141,7 @@ export class SyncStatus {
203
141
  * @param priority - The bucket priority for which the status should be reported
204
142
  * @returns Status information for the requested priority level or the next higher level with available status
205
143
  */
206
- statusForPriority(priority: number): SyncPriorityStatus {
207
- // priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
208
- for (const known of this.priorityStatusEntries) {
209
- // We look for the first entry that doesn't have a higher priority.
210
- if (known.priority >= priority) {
211
- return known;
212
- }
213
- }
214
-
215
- // If we have a complete sync, that necessarily includes all priorities.
216
- return {
217
- priority,
218
- lastSyncedAt: this.lastSyncedAt,
219
- hasSynced: this.hasSynced
220
- };
221
- }
144
+ statusForPriority(priority: number): SyncPriorityStatus | undefined;
222
145
 
223
146
  /**
224
147
  * Compares this SyncStatus instance with another to determine if they are equal.
@@ -227,20 +150,7 @@ export class SyncStatus {
227
150
  * @param status - The SyncStatus instance to compare against
228
151
  * @returns True if the instances are considered equal, false otherwise
229
152
  */
230
- isEqual(status: SyncStatus) {
231
- /**
232
- * By default Error object are serialized to an empty object.
233
- * This replaces Errors with more useful information before serialization.
234
- */
235
- const replacer = (_: string, value: any) => {
236
- if (value instanceof Error) {
237
- return this.serializeError(value);
238
- }
239
- return value;
240
- };
241
-
242
- return JSON.stringify(this.options, replacer) == JSON.stringify(status.options, replacer);
243
- }
153
+ isEqual(status: SyncStatus): boolean;
244
154
 
245
155
  /**
246
156
  * Creates a human-readable string representation of the current sync status.
@@ -248,56 +158,7 @@ export class SyncStatus {
248
158
  *
249
159
  * @returns A string representation of the sync status
250
160
  */
251
- getMessage() {
252
- const dataFlow = this.dataFlowStatus;
253
- 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}>`;
254
- }
255
-
256
- /**
257
- * Serializes the SyncStatus instance to a plain object.
258
- *
259
- * @returns A plain object representation of the sync status
260
- */
261
- toJSON(): SyncStatusOptions {
262
- return {
263
- connected: this.connected,
264
- connecting: this.connecting,
265
- dataFlow: {
266
- ...this.dataFlowStatus,
267
- uploadError: this.serializeError(this.dataFlowStatus.uploadError),
268
- downloadError: this.serializeError(this.dataFlowStatus.downloadError)
269
- },
270
- lastSyncedAt: this.lastSyncedAt,
271
- hasSynced: this.hasSynced,
272
- priorityStatusEntries: this.priorityStatusEntries
273
- };
274
- }
275
-
276
- /**
277
- * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
278
- * This explicitly serializes errors in the SyncStatus.
279
- */
280
- protected serializeError(error?: Error): Error | undefined {
281
- if (typeof error == 'undefined') {
282
- return undefined;
283
- }
284
- const serialized: Error = {
285
- name: error.name,
286
- message: error.message,
287
- stack: error.stack
288
- };
289
- // `Error.cause` can be any value (the spec types it as unknown). Preserve it
290
- // so consumers reading uploadError/downloadError keep the failure context.
291
- // Recurse for Error causes so the whole chain is flattened the same way.
292
- if (typeof error.cause != 'undefined') {
293
- serialized.cause = error.cause instanceof Error ? this.serializeError(error.cause) : error.cause;
294
- }
295
- return serialized;
296
- }
297
-
298
- private static comparePriorities(a: SyncPriorityStatus, b: SyncPriorityStatus) {
299
- return b.priority - a.priority; // Reverse because higher priorities have lower numbers
300
- }
161
+ getMessage(): string;
301
162
  }
302
163
 
303
164
  /**
@@ -310,39 +171,3 @@ export interface SyncStreamStatus {
310
171
  subscription: SyncSubscriptionDescription;
311
172
  priority: number | null;
312
173
  }
313
-
314
- class SyncStreamStatusView implements SyncStreamStatus {
315
- subscription: SyncSubscriptionDescription;
316
-
317
- constructor(
318
- private status: SyncStatus,
319
- private core: CoreStreamSubscription
320
- ) {
321
- this.subscription = {
322
- name: core.name,
323
- parameters: core.parameters,
324
- active: core.active,
325
- isDefault: core.is_default,
326
- hasExplicitSubscription: core.has_explicit_subscription,
327
- expiresAt: core.expires_at != null ? new Date(core.expires_at * 1000) : null,
328
- hasSynced: core.last_synced_at != null,
329
- lastSyncedAt: core.last_synced_at != null ? new Date(core.last_synced_at * 1000) : null
330
- };
331
- }
332
-
333
- get progress() {
334
- if (this.status.dataFlowStatus.downloadProgress == null) {
335
- // Don't make download progress public if we're not currently downloading.
336
- return null;
337
- }
338
-
339
- const { total, downloaded } = this.core.progress;
340
- const progress = total == 0 ? 0.0 : downloaded / total;
341
-
342
- return { totalOperations: total, downloadedOperations: downloaded, downloadedFraction: progress };
343
- }
344
-
345
- get priority() {
346
- return this.core.priority;
347
- }
348
- }
@@ -45,14 +45,6 @@ const real: BaseColumnType<number | null> = {
45
45
  type: ColumnType.REAL
46
46
  };
47
47
 
48
- /**
49
- * powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
50
- * In earlier versions this was limited to 63.
51
- *
52
- * @internal
53
- */
54
- export const MAX_AMOUNT_OF_COLUMNS = 1999;
55
-
56
48
  /**
57
49
  * @public
58
50
  */
@@ -1,5 +1,5 @@
1
1
  import { IndexedColumn } from './IndexedColumn.js';
2
- import { Table } from './Table.js';
2
+ import { ResolvedTable } from './Table.js';
3
3
 
4
4
  /**
5
5
  * @public
@@ -9,10 +9,7 @@ export interface IndexOptions {
9
9
  columns?: IndexedColumn[];
10
10
  }
11
11
 
12
- /**
13
- * @internal
14
- */
15
- export const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
12
+ const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
16
13
  columns: []
17
14
  };
18
15
 
@@ -39,7 +36,7 @@ export class Index {
39
36
  return this.options.columns ?? [];
40
37
  }
41
38
 
42
- toJSON(table: Table) {
39
+ toJSON(table: ResolvedTable) {
43
40
  return {
44
41
  name: this.name,
45
42
  columns: this.columns.map((c) => c.toJSON(table))
@@ -1,5 +1,5 @@
1
1
  import { ColumnType } from './Column.js';
2
- import { Table } from './Table.js';
2
+ import { ResolvedTable } from './Table.js';
3
3
 
4
4
  /**
5
5
  * @public
@@ -9,10 +9,7 @@ export interface IndexColumnOptions {
9
9
  ascending?: boolean;
10
10
  }
11
11
 
12
- /**
13
- * @internal
14
- */
15
- export const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
12
+ const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
16
13
  ascending: true
17
14
  };
18
15
 
@@ -41,7 +38,7 @@ export class IndexedColumn {
41
38
  return this.options.ascending;
42
39
  }
43
40
 
44
- toJSON(table: Table) {
41
+ toJSON(table: ResolvedTable) {
45
42
  return {
46
43
  name: this.name,
47
44
  ascending: this.ascending,