@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630141119

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 (263) hide show
  1. package/lib/attachments/AttachmentContext.d.ts +9 -8
  2. package/lib/attachments/AttachmentContext.js +8 -3
  3. package/lib/attachments/AttachmentContext.js.map +1 -1
  4. package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
  5. package/lib/attachments/AttachmentQueue.d.ts +85 -36
  6. package/lib/attachments/AttachmentQueue.js +19 -21
  7. package/lib/attachments/AttachmentQueue.js.map +1 -1
  8. package/lib/attachments/AttachmentService.d.ts +3 -3
  9. package/lib/attachments/AttachmentService.js +4 -3
  10. package/lib/attachments/AttachmentService.js.map +1 -1
  11. package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
  12. package/lib/attachments/LocalStorageAdapter.js +3 -0
  13. package/lib/attachments/LocalStorageAdapter.js.map +1 -1
  14. package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
  15. package/lib/attachments/Schema.d.ts +14 -6
  16. package/lib/attachments/Schema.js +8 -3
  17. package/lib/attachments/Schema.js.map +1 -1
  18. package/lib/attachments/SyncingService.d.ts +2 -2
  19. package/lib/attachments/SyncingService.js +8 -3
  20. package/lib/attachments/SyncingService.js.map +1 -1
  21. package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
  22. package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
  23. package/lib/client/CommonPowerSyncDatabase.js +2 -0
  24. package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
  25. package/lib/client/Query.d.ts +9 -0
  26. package/lib/client/SQLOpenFactory.d.ts +44 -10
  27. package/lib/client/SQLOpenFactory.js +1 -19
  28. package/lib/client/SQLOpenFactory.js.map +1 -1
  29. package/lib/client/compilableQueryWatch.d.ts +8 -2
  30. package/lib/client/compilableQueryWatch.js +4 -2
  31. package/lib/client/compilableQueryWatch.js.map +1 -1
  32. package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
  33. package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
  34. package/lib/client/runOnSchemaChange.d.ts +5 -2
  35. package/lib/client/runOnSchemaChange.js +3 -0
  36. package/lib/client/runOnSchemaChange.js.map +1 -1
  37. package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
  38. package/lib/client/sync/bucket/CrudBatch.js +2 -0
  39. package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
  40. package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
  41. package/lib/client/sync/bucket/CrudEntry.js +2 -97
  42. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  43. package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
  44. package/lib/client/sync/bucket/CrudTransaction.js +3 -0
  45. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
  46. package/lib/client/sync/options.d.ts +65 -0
  47. package/lib/client/sync/options.js +25 -0
  48. package/lib/client/sync/options.js.map +1 -0
  49. package/lib/client/sync/stream/JsonValue.d.ts +3 -0
  50. package/lib/client/sync/sync-streams.d.ts +23 -8
  51. package/lib/client/triggers/TriggerManager.d.ts +28 -56
  52. package/lib/client/triggers/TriggerManager.js +2 -1
  53. package/lib/client/triggers/TriggerManager.js.map +1 -1
  54. package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
  55. package/lib/client/triggers/sanitizeSQL.js +4 -0
  56. package/lib/client/triggers/sanitizeSQL.js.map +1 -1
  57. package/lib/client/watched/GetAllQuery.d.ts +7 -3
  58. package/lib/client/watched/GetAllQuery.js +3 -1
  59. package/lib/client/watched/GetAllQuery.js.map +1 -1
  60. package/lib/client/watched/WatchedQuery.d.ts +20 -6
  61. package/lib/client/watched/WatchedQuery.js +3 -5
  62. package/lib/client/watched/WatchedQuery.js.map +1 -1
  63. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
  64. package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
  65. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  66. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
  67. package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
  68. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  69. package/lib/client/watched/processors/comparators.d.ts +8 -0
  70. package/lib/client/watched/processors/comparators.js +4 -0
  71. package/lib/client/watched/processors/comparators.js.map +1 -1
  72. package/lib/db/DBAdapter.d.ts +90 -113
  73. package/lib/db/DBAdapter.js +70 -89
  74. package/lib/db/DBAdapter.js.map +1 -1
  75. package/lib/db/QueryResult.d.ts +104 -0
  76. package/lib/db/QueryResult.js +96 -0
  77. package/lib/db/QueryResult.js.map +1 -0
  78. package/lib/db/crud/SyncProgress.d.ts +7 -14
  79. package/lib/db/crud/SyncProgress.js +1 -60
  80. package/lib/db/crud/SyncProgress.js.map +1 -1
  81. package/lib/db/crud/SyncStatus.d.ts +54 -91
  82. package/lib/db/crud/SyncStatus.js +1 -245
  83. package/lib/db/crud/SyncStatus.js.map +1 -1
  84. package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
  85. package/lib/db/crud/UploadQueueStatus.js +3 -0
  86. package/lib/db/crud/UploadQueueStatus.js.map +1 -1
  87. package/lib/db/schema/Column.d.ts +22 -1
  88. package/lib/db/schema/Column.js +10 -4
  89. package/lib/db/schema/Column.js.map +1 -1
  90. package/lib/db/schema/Index.d.ts +8 -3
  91. package/lib/db/schema/Index.js +4 -1
  92. package/lib/db/schema/Index.js.map +1 -1
  93. package/lib/db/schema/IndexedColumn.d.ts +8 -3
  94. package/lib/db/schema/IndexedColumn.js +4 -1
  95. package/lib/db/schema/IndexedColumn.js.map +1 -1
  96. package/lib/db/schema/RawTable.d.ts +7 -1
  97. package/lib/db/schema/Schema.d.ts +10 -29
  98. package/lib/db/schema/Schema.js +3 -1
  99. package/lib/db/schema/Schema.js.map +1 -1
  100. package/lib/db/schema/Table.d.ts +69 -91
  101. package/lib/db/schema/Table.js +88 -87
  102. package/lib/db/schema/Table.js.map +1 -1
  103. package/lib/index.d.ts +6 -22
  104. package/lib/index.js +5 -22
  105. package/lib/index.js.map +1 -1
  106. package/lib/types/types.d.ts +6 -0
  107. package/lib/utils/BaseObserver.d.ts +12 -0
  108. package/lib/utils/BaseObserver.js +3 -0
  109. package/lib/utils/BaseObserver.js.map +1 -1
  110. package/lib/utils/Logger.d.ts +60 -22
  111. package/lib/utils/Logger.js +38 -30
  112. package/lib/utils/Logger.js.map +1 -1
  113. package/lib/utils/MetaBaseObserver.d.ts +11 -11
  114. package/lib/utils/MetaBaseObserver.js +1 -50
  115. package/lib/utils/MetaBaseObserver.js.map +1 -1
  116. package/lib/utils/mutex.d.ts +3 -45
  117. package/lib/utils/mutex.js +1 -153
  118. package/lib/utils/mutex.js.map +1 -1
  119. package/package.json +9 -46
  120. package/src/attachments/AttachmentContext.ts +15 -13
  121. package/src/attachments/AttachmentErrorHandler.ts +6 -6
  122. package/src/attachments/AttachmentQueue.ts +99 -42
  123. package/src/attachments/AttachmentService.ts +7 -6
  124. package/src/attachments/LocalStorageAdapter.ts +14 -8
  125. package/src/attachments/README.md +2 -0
  126. package/src/attachments/RemoteStorageAdapter.ts +4 -4
  127. package/src/attachments/Schema.ts +14 -6
  128. package/src/attachments/SyncingService.ts +10 -6
  129. package/src/attachments/WatchedAttachmentItem.ts +3 -1
  130. package/src/client/CommonPowerSyncDatabase.ts +540 -0
  131. package/src/client/Query.ts +9 -0
  132. package/src/client/SQLOpenFactory.ts +47 -19
  133. package/src/client/compilableQueryWatch.ts +9 -4
  134. package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
  135. package/src/client/connection/PowerSyncCredentials.ts +3 -0
  136. package/src/client/runOnSchemaChange.ts +5 -2
  137. package/src/client/sync/bucket/CrudBatch.ts +2 -0
  138. package/src/client/sync/bucket/CrudEntry.ts +10 -101
  139. package/src/client/sync/bucket/CrudTransaction.ts +3 -0
  140. package/src/client/sync/options.ts +77 -0
  141. package/src/client/sync/stream/JsonValue.ts +3 -0
  142. package/src/client/sync/sync-streams.ts +23 -10
  143. package/src/client/triggers/TriggerManager.ts +29 -59
  144. package/src/client/triggers/sanitizeSQL.ts +5 -0
  145. package/src/client/watched/GetAllQuery.ts +8 -4
  146. package/src/client/watched/WatchedQuery.ts +20 -11
  147. package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
  148. package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
  149. package/src/client/watched/processors/comparators.ts +8 -0
  150. package/src/db/DBAdapter.ts +160 -175
  151. package/src/db/QueryResult.ts +195 -0
  152. package/src/db/crud/SyncProgress.ts +8 -43
  153. package/src/db/crud/SyncStatus.ts +66 -216
  154. package/src/db/crud/UploadQueueStatus.ts +3 -0
  155. package/src/db/schema/Column.ts +22 -5
  156. package/src/db/schema/Index.ts +9 -3
  157. package/src/db/schema/IndexedColumn.ts +9 -3
  158. package/src/db/schema/RawTable.ts +7 -1
  159. package/src/db/schema/Schema.ts +12 -7
  160. package/src/db/schema/Table.ts +130 -180
  161. package/src/index.ts +6 -22
  162. package/src/types/types.ts +6 -0
  163. package/src/utils/BaseObserver.ts +12 -0
  164. package/src/utils/Logger.ts +86 -31
  165. package/src/utils/MetaBaseObserver.ts +14 -60
  166. package/src/utils/mutex.ts +4 -189
  167. package/dist/bundle.cjs +0 -14136
  168. package/dist/bundle.cjs.map +0 -1
  169. package/dist/bundle.mjs +0 -14056
  170. package/dist/bundle.mjs.map +0 -1
  171. package/dist/bundle.node.cjs +0 -11613
  172. package/dist/bundle.node.cjs.map +0 -1
  173. package/dist/bundle.node.mjs +0 -11533
  174. package/dist/bundle.node.mjs.map +0 -1
  175. package/dist/index.d.cts +0 -4052
  176. package/legacy/sync_protocol.d.ts +0 -103
  177. package/lib/client/AbstractPowerSyncDatabase.js +0 -987
  178. package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
  179. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
  180. package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
  181. package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
  182. package/lib/client/ConnectionManager.d.ts +0 -112
  183. package/lib/client/ConnectionManager.js +0 -294
  184. package/lib/client/ConnectionManager.js.map +0 -1
  185. package/lib/client/CustomQuery.d.ts +0 -22
  186. package/lib/client/CustomQuery.js +0 -43
  187. package/lib/client/CustomQuery.js.map +0 -1
  188. package/lib/client/constants.d.ts +0 -1
  189. package/lib/client/constants.js +0 -2
  190. package/lib/client/constants.js.map +0 -1
  191. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
  192. package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
  193. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
  194. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
  195. package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
  196. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
  197. package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
  198. package/lib/client/sync/stream/AbstractRemote.js +0 -473
  199. package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
  200. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
  201. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
  202. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
  203. package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
  204. package/lib/client/sync/stream/WebsocketClientTransport.js +0 -61
  205. package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
  206. package/lib/client/sync/stream/core-instruction.d.ts +0 -71
  207. package/lib/client/sync/stream/core-instruction.js +0 -27
  208. package/lib/client/sync/stream/core-instruction.js.map +0 -1
  209. package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
  210. package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
  211. package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
  212. package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
  213. package/lib/client/triggers/TriggerManagerImpl.js +0 -405
  214. package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
  215. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
  216. package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
  217. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
  218. package/lib/db/ConnectionClosedError.d.ts +0 -10
  219. package/lib/db/ConnectionClosedError.js +0 -21
  220. package/lib/db/ConnectionClosedError.js.map +0 -1
  221. package/lib/db/schema/TableV2.d.ts +0 -9
  222. package/lib/db/schema/TableV2.js +0 -9
  223. package/lib/db/schema/TableV2.js.map +0 -1
  224. package/lib/utils/AbortOperation.d.ts +0 -9
  225. package/lib/utils/AbortOperation.js +0 -19
  226. package/lib/utils/AbortOperation.js.map +0 -1
  227. package/lib/utils/ControlledExecutor.d.ts +0 -25
  228. package/lib/utils/ControlledExecutor.js +0 -51
  229. package/lib/utils/ControlledExecutor.js.map +0 -1
  230. package/lib/utils/async.d.ts +0 -14
  231. package/lib/utils/async.js +0 -46
  232. package/lib/utils/async.js.map +0 -1
  233. package/lib/utils/parseQuery.d.ts +0 -6
  234. package/lib/utils/parseQuery.js +0 -17
  235. package/lib/utils/parseQuery.js.map +0 -1
  236. package/lib/utils/queue.d.ts +0 -16
  237. package/lib/utils/queue.js +0 -42
  238. package/lib/utils/queue.js.map +0 -1
  239. package/lib/utils/stream_transform.d.ts +0 -39
  240. package/lib/utils/stream_transform.js +0 -206
  241. package/lib/utils/stream_transform.js.map +0 -1
  242. package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
  243. package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
  244. package/src/client/ConnectionManager.ts +0 -402
  245. package/src/client/CustomQuery.ts +0 -56
  246. package/src/client/constants.ts +0 -1
  247. package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
  248. package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
  249. package/src/client/sync/stream/AbstractRemote.ts +0 -602
  250. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
  251. package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
  252. package/src/client/sync/stream/core-instruction.ts +0 -98
  253. package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
  254. package/src/client/triggers/TriggerManagerImpl.ts +0 -496
  255. package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
  256. package/src/db/ConnectionClosedError.ts +0 -23
  257. package/src/db/schema/TableV2.ts +0 -9
  258. package/src/utils/AbortOperation.ts +0 -17
  259. package/src/utils/ControlledExecutor.ts +0 -72
  260. package/src/utils/async.ts +0 -50
  261. package/src/utils/parseQuery.ts +0 -25
  262. package/src/utils/queue.ts +0 -48
  263. package/src/utils/stream_transform.ts +0 -252
@@ -1,20 +1,12 @@
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
  *
16
6
  * To obtain these values, use {@link SyncProgress}, available through
17
7
  * {@link SyncStatus#downloadProgress}.
8
+ *
9
+ * @public
18
10
  */
19
11
  export interface ProgressWithOperations {
20
12
  /**
@@ -28,7 +20,8 @@ export interface ProgressWithOperations {
28
20
  downloadedOperations: number;
29
21
 
30
22
  /**
31
- * Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
23
+ * Relative progress, as {@link ProgressWithOperations.downloadedOperations} of
24
+ * {@link ProgressWithOperations.totalOperations}.
32
25
  *
33
26
  * This will be a number between `0.0` and `1.0` (inclusive).
34
27
  *
@@ -58,43 +51,15 @@ export interface ProgressWithOperations {
58
51
  *
59
52
  * Also note that data is downloaded in bulk, which means that individual counters are unlikely
60
53
  * to be updated one-by-one.
54
+ *
55
+ * @public
61
56
  */
62
- export class SyncProgress implements ProgressWithOperations {
63
- totalOperations: number;
64
- downloadedOperations: number;
65
- downloadedFraction: number;
66
-
67
- constructor(protected internal: InternalProgressInformation) {
68
- const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
69
-
70
- this.totalOperations = untilCompletion.totalOperations;
71
- this.downloadedOperations = untilCompletion.downloadedOperations;
72
- this.downloadedFraction = untilCompletion.downloadedFraction;
73
- }
74
-
57
+ export interface SyncProgress extends ProgressWithOperations {
75
58
  /**
76
59
  * Returns download progress towards all data up until the specified priority being received.
77
60
  *
78
61
  * The returned {@link ProgressWithOperations} tracks the target amount of operations that need
79
62
  * to be downloaded in total and how many of them have already been received.
80
63
  */
81
- untilPriority(priority: number): ProgressWithOperations {
82
- let total = 0;
83
- let downloaded = 0;
84
-
85
- for (const progress of Object.values(this.internal)) {
86
- // Include higher-priority buckets, which are represented by lower numbers.
87
- if (progress.priority <= priority) {
88
- downloaded += progress.since_last;
89
- total += progress.target_count - progress.at_last;
90
- }
91
- }
92
-
93
- let progress = total == 0 ? 0.0 : downloaded / total;
94
- return {
95
- totalOperations: total,
96
- downloadedOperations: downloaded,
97
- downloadedFraction: progress
98
- };
99
- }
64
+ untilPriority(priority: number): ProgressWithOperations;
100
65
  }
@@ -1,9 +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
- export type SyncDataFlowStatus = Partial<{
4
+ /**
5
+ * @public
6
+ * @deprecated All fields are available on {@link SyncStatus} directly.
7
+ */
8
+ export interface SyncDataFlowStatus {
7
9
  downloading: boolean;
8
10
  uploading: boolean;
9
11
  /**
@@ -17,105 +19,79 @@ export type SyncDataFlowStatus = Partial<{
17
19
  * Cleared on the next successful upload.
18
20
  */
19
21
  uploadError?: Error;
20
- /**
21
- * Internal information about how far we are downloading operations in buckets.
22
- *
23
- * Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
24
- */
25
- downloadProgress: InternalProgressInformation | null;
26
- internalStreamSubscriptions: CoreStreamSubscription[] | null;
27
- }>;
22
+ }
28
23
 
24
+ /**
25
+ * @public
26
+ */
29
27
  export interface SyncPriorityStatus {
30
28
  priority: number;
31
29
  lastSyncedAt?: Date;
32
30
  hasSynced?: boolean;
33
31
  }
34
32
 
35
- export type SyncStatusOptions = {
36
- connected?: boolean;
37
- connecting?: boolean;
38
- dataFlow?: SyncDataFlowStatus;
39
- lastSyncedAt?: Date;
40
- hasSynced?: boolean;
41
- priorityStatusEntries?: SyncPriorityStatus[];
42
- clientImplementation?: SyncClientImplementation;
43
- };
44
-
45
- export class SyncStatus {
46
- constructor(protected options: SyncStatusOptions) {}
47
-
33
+ /**
34
+ * @public
35
+ */
36
+ export interface SyncStatus {
48
37
  /**
49
- * Returns the used sync client implementation (either the one implemented in JavaScript or the newer Rust-based
50
- * implementation).
38
+ * Indicates if the client is currently connected to the PowerSync service.
51
39
  *
52
- * This information is only available after a connection has been requested.
40
+ * @returns True if connected, false otherwise. Defaults to false if not specified.
53
41
  */
54
- get clientImplementation() {
55
- return this.options.clientImplementation;
56
- }
42
+ get connected(): boolean;
57
43
 
58
44
  /**
59
- * Indicates if the client is currently connected to the PowerSync service.
45
+ * Indicates if the client is in the process of establishing a connection to the PowerSync service.
60
46
  *
61
- * @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
47
+ * @returns True if connecting, false otherwise. Defaults to false if not specified.
62
48
  */
63
- get connected() {
64
- return this.options.connected ?? false;
65
- }
49
+ get connecting(): boolean;
66
50
 
67
51
  /**
68
- * Indicates if the client is in the process of establishing a connection to the PowerSync service.
52
+ * Whether the PowerSync SDK is currently downloading data from the connected PowerSync service.
53
+ */
54
+ get downloading(): boolean;
55
+
56
+ /**
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).
69
64
  *
70
- * @returns {boolean} 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.
66
+ */
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.
71
77
  */
72
- get connecting() {
73
- return this.options.connecting ?? false;
74
- }
78
+ get dataFlowStatus(): SyncDataFlowStatus;
75
79
 
76
80
  /**
77
81
  * Time that a last sync has fully completed, if any.
78
82
  * This timestamp is reset to null after a restart of the PowerSync service.
79
83
  *
80
- * @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
84
+ * @returns The timestamp of the last successful sync, or undefined if no sync has completed.
81
85
  */
82
- get lastSyncedAt() {
83
- return this.options.lastSyncedAt;
84
- }
86
+ get lastSyncedAt(): Date | undefined;
85
87
 
86
88
  /**
87
89
  * Indicates whether there has been at least one full sync completed since initialization.
88
90
  *
89
- * @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
91
+ * @returns True if at least one sync has completed, false if no sync has completed,
90
92
  * or undefined when the state is still being loaded from the database.
91
93
  */
92
- get hasSynced() {
93
- return this.options.hasSynced;
94
- }
95
-
96
- /**
97
- * Provides the current data flow status regarding uploads and downloads.
98
- *
99
- * @returns {SyncDataFlowStatus} An object containing:
100
- * - downloading: True if actively downloading changes (only when connected is also true)
101
- * - uploading: True if actively uploading changes
102
- * Defaults to {downloading: false, uploading: false} if not specified.
103
- */
104
- get dataFlowStatus() {
105
- return (
106
- this.options.dataFlow ?? {
107
- /**
108
- * true if actively downloading changes.
109
- * This is only true when {@link connected} is also true.
110
- */
111
- downloading: false,
112
- /**
113
- * true if uploading changes.
114
- */
115
- uploading: false
116
- }
117
- );
118
- }
94
+ get hasSynced(): boolean | undefined;
119
95
 
120
96
  /**
121
97
  * All sync streams currently being tracked in teh database.
@@ -123,46 +99,28 @@ export class SyncStatus {
123
99
  * This returns null when the database is currently being opened and we don't have reliable information about all
124
100
  * included streams yet.
125
101
  */
126
- get syncStreams(): SyncStreamStatus[] | undefined {
127
- return this.options.dataFlow?.internalStreamSubscriptions?.map((core) => new SyncStreamStatusView(this, core));
128
- }
102
+ get syncStreams(): SyncStreamStatus[] | undefined;
129
103
 
130
104
  /**
131
- * If the `stream` appears in {@link syncStreams}, returns the current status for that stream.
105
+ * If the `stream` appears in {@link SyncStatus.syncStreams}, returns the current status for that stream.
132
106
  */
133
- forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined {
134
- const asJson = JSON.stringify(stream.parameters);
135
- const raw = this.options.dataFlow?.internalStreamSubscriptions?.find(
136
- (r) => r.name == stream.name && asJson == JSON.stringify(r.parameters)
137
- );
138
-
139
- return raw && new SyncStreamStatusView(this, raw);
140
- }
107
+ forStream(stream: SyncStreamDescription): SyncStreamStatus | undefined;
141
108
 
142
109
  /**
143
110
  * Provides sync status information for all bucket priorities, sorted by priority (highest first).
144
111
  *
145
- * @returns {SyncPriorityStatus[]} An array of status entries for different sync priority levels,
112
+ * @returns An array of status entries for different sync priority levels,
146
113
  * sorted with highest priorities (lower numbers) first.
147
114
  */
148
- get priorityStatusEntries() {
149
- return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
150
- }
115
+ get priorityStatusEntries(): SyncPriorityStatus[] | undefined;
151
116
 
152
117
  /**
153
118
  * A realtime progress report on how many operations have been downloaded and
154
119
  * how many are necessary in total to complete the next sync iteration.
155
120
  *
156
- * 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.
157
122
  */
158
- get downloadProgress(): SyncProgress | null {
159
- const internalProgress = this.options.dataFlow?.downloadProgress;
160
- if (internalProgress == null) {
161
- return null;
162
- }
163
-
164
- return new SyncProgress(internalProgress);
165
- }
123
+ get downloadProgress(): SyncProgress | null;
166
124
 
167
125
  /**
168
126
  * Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
@@ -180,144 +138,36 @@ export class SyncStatus {
180
138
  * For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
181
139
  * with a priority of 1 may return information for priority level 3.
182
140
  *
183
- * @param {number} priority The bucket priority for which the status should be reported
184
- * @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
141
+ * @param priority - The bucket priority for which the status should be reported
142
+ * @returns Status information for the requested priority level or the next higher level with available status
185
143
  */
186
- statusForPriority(priority: number): SyncPriorityStatus {
187
- // priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
188
- for (const known of this.priorityStatusEntries) {
189
- // We look for the first entry that doesn't have a higher priority.
190
- if (known.priority >= priority) {
191
- return known;
192
- }
193
- }
194
-
195
- // If we have a complete sync, that necessarily includes all priorities.
196
- return {
197
- priority,
198
- lastSyncedAt: this.lastSyncedAt,
199
- hasSynced: this.hasSynced
200
- };
201
- }
144
+ statusForPriority(priority: number): SyncPriorityStatus | undefined;
202
145
 
203
146
  /**
204
147
  * Compares this SyncStatus instance with another to determine if they are equal.
205
148
  * Equality is determined by comparing the serialized JSON representation of both instances.
206
149
  *
207
- * @param {SyncStatus} status The SyncStatus instance to compare against
208
- * @returns {boolean} True if the instances are considered equal, false otherwise
150
+ * @param status - The SyncStatus instance to compare against
151
+ * @returns True if the instances are considered equal, false otherwise
209
152
  */
210
- isEqual(status: SyncStatus) {
211
- /**
212
- * By default Error object are serialized to an empty object.
213
- * This replaces Errors with more useful information before serialization.
214
- */
215
- const replacer = (_: string, value: any) => {
216
- if (value instanceof Error) {
217
- return {
218
- name: value.name,
219
- message: value.message,
220
- stack: value.stack
221
- };
222
- }
223
- return value;
224
- };
225
-
226
- return JSON.stringify(this.options, replacer) == JSON.stringify(status.options, replacer);
227
- }
153
+ isEqual(status: SyncStatus): boolean;
228
154
 
229
155
  /**
230
156
  * Creates a human-readable string representation of the current sync status.
231
157
  * Includes information about connection state, sync completion, and data flow.
232
158
  *
233
- * @returns {string} A string representation of the sync status
234
- */
235
- getMessage() {
236
- const dataFlow = this.dataFlowStatus;
237
- 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}>`;
238
- }
239
-
240
- /**
241
- * Serializes the SyncStatus instance to a plain object.
242
- *
243
- * @returns {SyncStatusOptions} A plain object representation of the sync status
159
+ * @returns A string representation of the sync status
244
160
  */
245
- toJSON(): SyncStatusOptions {
246
- return {
247
- connected: this.connected,
248
- connecting: this.connecting,
249
- dataFlow: {
250
- ...this.dataFlowStatus,
251
- uploadError: this.serializeError(this.dataFlowStatus.uploadError),
252
- downloadError: this.serializeError(this.dataFlowStatus.downloadError)
253
- },
254
- lastSyncedAt: this.lastSyncedAt,
255
- hasSynced: this.hasSynced,
256
- priorityStatusEntries: this.priorityStatusEntries
257
- };
258
- }
259
-
260
- /**
261
- * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
262
- * This explicitly serializes errors in the SyncStatus.
263
- */
264
- protected serializeError(error?: Error) {
265
- if (typeof error == 'undefined') {
266
- return undefined;
267
- }
268
- return {
269
- name: error.name,
270
- message: error.message,
271
- stack: error.stack
272
- };
273
- }
274
-
275
- private static comparePriorities(a: SyncPriorityStatus, b: SyncPriorityStatus) {
276
- return b.priority - a.priority; // Reverse because higher priorities have lower numbers
277
- }
161
+ getMessage(): string;
278
162
  }
279
163
 
280
164
  /**
281
165
  * Information about a sync stream subscription.
166
+ *
167
+ * @public
282
168
  */
283
169
  export interface SyncStreamStatus {
284
170
  progress: ProgressWithOperations | null;
285
171
  subscription: SyncSubscriptionDescription;
286
172
  priority: number | null;
287
173
  }
288
-
289
- class SyncStreamStatusView implements SyncStreamStatus {
290
- subscription: SyncSubscriptionDescription;
291
-
292
- constructor(
293
- private status: SyncStatus,
294
- private core: CoreStreamSubscription
295
- ) {
296
- this.subscription = {
297
- name: core.name,
298
- parameters: core.parameters,
299
- active: core.active,
300
- isDefault: core.is_default,
301
- hasExplicitSubscription: core.has_explicit_subscription,
302
- expiresAt: core.expires_at != null ? new Date(core.expires_at * 1000) : null,
303
- hasSynced: core.last_synced_at != null,
304
- lastSyncedAt: core.last_synced_at != null ? new Date(core.last_synced_at * 1000) : null
305
- };
306
- }
307
-
308
- get progress() {
309
- if (this.status.dataFlowStatus.downloadProgress == null) {
310
- // Don't make download progress public if we're not currently downloading.
311
- return null;
312
- }
313
-
314
- const { total, downloaded } = this.core.progress;
315
- const progress = total == 0 ? 0.0 : downloaded / total;
316
-
317
- return { totalOperations: total, downloadedOperations: downloaded, downloadedFraction: progress };
318
- }
319
-
320
- get priority() {
321
- return this.core.priority;
322
- }
323
- }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @public
3
+ */
1
4
  export class UploadQueueStats {
2
5
  constructor(
3
6
  /**
@@ -1,21 +1,36 @@
1
- // https://www.sqlite.org/lang_expr.html#castexpr
1
+ /**
2
+ * @see https://www.sqlite.org/lang_expr.html#castexpr
3
+ * @public
4
+ */
2
5
  export enum ColumnType {
3
6
  TEXT = 'TEXT',
4
7
  INTEGER = 'INTEGER',
5
8
  REAL = 'REAL'
6
9
  }
7
10
 
11
+ /**
12
+ * @public
13
+ */
8
14
  export interface ColumnOptions {
9
15
  name: string;
10
16
  type?: ColumnType;
11
17
  }
12
18
 
19
+ /**
20
+ * @public
21
+ */
13
22
  export type BaseColumnType<T extends number | string | null> = {
14
23
  type: ColumnType;
15
24
  };
16
25
 
26
+ /**
27
+ * @public
28
+ */
17
29
  export type ColumnsType = Record<string, BaseColumnType<any>>;
18
30
 
31
+ /**
32
+ * @public
33
+ */
19
34
  export type ExtractColumnValueType<T extends BaseColumnType<any>> = T extends BaseColumnType<infer R> ? R : unknown;
20
35
 
21
36
  const text: BaseColumnType<string | null> = {
@@ -30,16 +45,18 @@ const real: BaseColumnType<number | null> = {
30
45
  type: ColumnType.REAL
31
46
  };
32
47
 
33
- // powersync-sqlite-core limits the number of column per table to 1999, due to internal SQLite limits.
34
- // In earlier versions this was limited to 63.
35
- export const MAX_AMOUNT_OF_COLUMNS = 1999;
36
-
48
+ /**
49
+ * @public
50
+ */
37
51
  export const column = {
38
52
  text,
39
53
  integer,
40
54
  real
41
55
  };
42
56
 
57
+ /**
58
+ * @public
59
+ */
43
60
  export class Column {
44
61
  constructor(protected options: ColumnOptions) {}
45
62
 
@@ -1,15 +1,21 @@
1
1
  import { IndexedColumn } from './IndexedColumn.js';
2
- import { Table } from './Table.js';
2
+ import { ResolvedTable } from './Table.js';
3
3
 
4
+ /**
5
+ * @public
6
+ */
4
7
  export interface IndexOptions {
5
8
  name: string;
6
9
  columns?: IndexedColumn[];
7
10
  }
8
11
 
9
- export const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
12
+ const DEFAULT_INDEX_OPTIONS: Partial<IndexOptions> = {
10
13
  columns: []
11
14
  };
12
15
 
16
+ /**
17
+ * @public
18
+ */
13
19
  export class Index {
14
20
  static createAscending(options: IndexOptions, columnNames: string[]) {
15
21
  return new Index({
@@ -30,7 +36,7 @@ export class Index {
30
36
  return this.options.columns ?? [];
31
37
  }
32
38
 
33
- toJSON(table: Table) {
39
+ toJSON(table: ResolvedTable) {
34
40
  return {
35
41
  name: this.name,
36
42
  columns: this.columns.map((c) => c.toJSON(table))
@@ -1,15 +1,21 @@
1
1
  import { ColumnType } from './Column.js';
2
- import { Table } from './Table.js';
2
+ import { ResolvedTable } from './Table.js';
3
3
 
4
+ /**
5
+ * @public
6
+ */
4
7
  export interface IndexColumnOptions {
5
8
  name: string;
6
9
  ascending?: boolean;
7
10
  }
8
11
 
9
- export const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
12
+ const DEFAULT_INDEX_COLUMN_OPTIONS: Partial<IndexColumnOptions> = {
10
13
  ascending: true
11
14
  };
12
15
 
16
+ /**
17
+ * @public
18
+ */
13
19
  export class IndexedColumn {
14
20
  protected options: IndexColumnOptions;
15
21
 
@@ -32,7 +38,7 @@ export class IndexedColumn {
32
38
  return this.options.ascending;
33
39
  }
34
40
 
35
- toJSON(table: Table) {
41
+ toJSON(table: ResolvedTable) {
36
42
  return {
37
43
  name: this.name,
38
44
  ascending: this.ascending,
@@ -7,8 +7,10 @@ import { TableOrRawTableOptions } from './Table.js';
7
7
  * using client-side table and column constraints.
8
8
  *
9
9
  * To collect local writes to raw tables with PowerSync, custom triggers are required. See
10
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
10
+ * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables} for details and an example on
11
11
  * using raw tables.
12
+ *
13
+ * @public
12
14
  */
13
15
  export type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
14
16
 
@@ -70,11 +72,15 @@ interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
70
72
  * `{Column: 'name'}`.
71
73
  * The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
72
74
  * covered by a `Column` parameter.
75
+ *
76
+ * @public
73
77
  */
74
78
  export type PendingStatementParameter = 'Id' | { Column: string } | 'Rest';
75
79
 
76
80
  /**
77
81
  * A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
82
+ *
83
+ * @public
78
84
  */
79
85
  export type PendingStatement = {
80
86
  sql: string;
@@ -1,26 +1,31 @@
1
1
  import { encodeTableOptions } from './internal.js';
2
2
  import { RawTable, RawTableType } from './RawTable.js';
3
- import { RowType, Table } from './Table.js';
3
+ import { ResolvedTable, RowType, Table } from './Table.js';
4
4
 
5
5
  type SchemaType = Record<string, Table<any>>;
6
6
 
7
+ /**
8
+ * @public
9
+ */
7
10
  export type SchemaTableType<S extends SchemaType> = {
8
11
  [K in keyof S]: RowType<S[K]>;
9
12
  };
10
13
 
11
14
  /**
12
15
  * A schema is a collection of tables. It is used to define the structure of a database.
16
+ *
17
+ * @public
13
18
  */
14
19
  export class Schema<S extends SchemaType = SchemaType> {
15
20
  /*
16
21
  Only available when constructing with mapped typed definition columns
17
22
  */
18
- readonly types: SchemaTableType<S>;
19
- readonly props: S;
20
- readonly tables: Table[];
23
+ readonly types!: SchemaTableType<S>;
24
+ readonly props!: S;
25
+ readonly tables: ResolvedTable[];
21
26
  readonly rawTables: RawTable[];
22
27
 
23
- constructor(tables: Table[] | S) {
28
+ constructor(tables: ResolvedTable[] | S) {
24
29
  if (Array.isArray(tables)) {
25
30
  /*
26
31
  We need to validate that the tables have a name here because a user could pass in an array
@@ -52,7 +57,7 @@ export class Schema<S extends SchemaType = SchemaType> {
52
57
  * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
53
58
  * using client-side table and column constraints.
54
59
  *
55
- * @param tables An object of (table name, raw table definition) entries.
60
+ * @param tables - An object of (table name, raw table definition) entries.
56
61
  */
57
62
  withRawTables(tables: Record<string, RawTableType>) {
58
63
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
@@ -66,7 +71,7 @@ export class Schema<S extends SchemaType = SchemaType> {
66
71
  }
67
72
  }
68
73
 
69
- toJSON() {
74
+ toJSON(): unknown {
70
75
  return {
71
76
  tables: this.tables.map((t) => t.toJSON()),
72
77
  raw_tables: this.rawTables.map(Schema.rawTableToJson)