@powersync/common 1.53.1 → 1.54.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 (217) hide show
  1. package/dist/bundle.cjs +560 -353
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +560 -353
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +560 -353
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +560 -353
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +733 -198
  10. package/lib/attachments/AttachmentContext.d.ts +7 -6
  11. package/lib/attachments/AttachmentContext.js +2 -1
  12. package/lib/attachments/AttachmentContext.js.map +1 -1
  13. package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
  14. package/lib/attachments/AttachmentQueue.d.ts +61 -20
  15. package/lib/attachments/AttachmentQueue.js +16 -18
  16. package/lib/attachments/AttachmentQueue.js.map +1 -1
  17. package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
  18. package/lib/attachments/LocalStorageAdapter.js +3 -0
  19. package/lib/attachments/LocalStorageAdapter.js.map +1 -1
  20. package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
  21. package/lib/attachments/Schema.d.ts +12 -4
  22. package/lib/attachments/Schema.js +8 -3
  23. package/lib/attachments/Schema.js.map +1 -1
  24. package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
  25. package/lib/client/AbstractPowerSyncDatabase.d.ts +110 -58
  26. package/lib/client/AbstractPowerSyncDatabase.js +59 -48
  27. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  28. package/lib/client/AbstractPowerSyncOpenFactory.d.ts +6 -0
  29. package/lib/client/AbstractPowerSyncOpenFactory.js +3 -0
  30. package/lib/client/AbstractPowerSyncOpenFactory.js.map +1 -1
  31. package/lib/client/ConnectionManager.d.ts +4 -1
  32. package/lib/client/ConnectionManager.js +1 -1
  33. package/lib/client/ConnectionManager.js.map +1 -1
  34. package/lib/client/Query.d.ts +9 -0
  35. package/lib/client/SQLOpenFactory.d.ts +12 -0
  36. package/lib/client/SQLOpenFactory.js +6 -0
  37. package/lib/client/SQLOpenFactory.js.map +1 -1
  38. package/lib/client/compilableQueryWatch.d.ts +6 -0
  39. package/lib/client/compilableQueryWatch.js +3 -0
  40. package/lib/client/compilableQueryWatch.js.map +1 -1
  41. package/lib/client/connection/PowerSyncBackendConnector.d.ts +3 -0
  42. package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
  43. package/lib/client/constants.d.ts +3 -0
  44. package/lib/client/constants.js +3 -0
  45. package/lib/client/constants.js.map +1 -1
  46. package/lib/client/runOnSchemaChange.d.ts +3 -0
  47. package/lib/client/runOnSchemaChange.js +3 -0
  48. package/lib/client/runOnSchemaChange.js.map +1 -1
  49. package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +12 -0
  50. package/lib/client/sync/bucket/BucketStorageAdapter.js +6 -0
  51. package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
  52. package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
  53. package/lib/client/sync/bucket/CrudBatch.js +2 -0
  54. package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
  55. package/lib/client/sync/bucket/CrudEntry.d.ts +9 -0
  56. package/lib/client/sync/bucket/CrudEntry.js +4 -0
  57. package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
  58. package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
  59. package/lib/client/sync/bucket/CrudTransaction.js +3 -0
  60. package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
  61. package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +3 -0
  62. package/lib/client/sync/bucket/SqliteBucketStorage.js +3 -0
  63. package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
  64. package/lib/client/sync/stream/AbstractRemote.d.ts +30 -1
  65. package/lib/client/sync/stream/AbstractRemote.js +15 -1
  66. package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
  67. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +61 -14
  68. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +60 -47
  69. package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
  70. package/lib/client/sync/stream/JsonValue.d.ts +3 -0
  71. package/lib/client/sync/stream/WebsocketClientTransport.js +2 -1
  72. package/lib/client/sync/stream/WebsocketClientTransport.js.map +1 -1
  73. package/lib/client/sync/sync-streams.d.ts +22 -7
  74. package/lib/client/triggers/TriggerManager.d.ts +19 -18
  75. package/lib/client/triggers/TriggerManager.js +2 -1
  76. package/lib/client/triggers/TriggerManager.js.map +1 -1
  77. package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
  78. package/lib/client/triggers/TriggerManagerImpl.js +3 -3
  79. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
  80. package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
  81. package/lib/client/triggers/sanitizeSQL.js +4 -0
  82. package/lib/client/triggers/sanitizeSQL.js.map +1 -1
  83. package/lib/client/watched/GetAllQuery.d.ts +4 -0
  84. package/lib/client/watched/GetAllQuery.js +2 -0
  85. package/lib/client/watched/GetAllQuery.js.map +1 -1
  86. package/lib/client/watched/WatchedQuery.d.ts +24 -2
  87. package/lib/client/watched/WatchedQuery.js +9 -0
  88. package/lib/client/watched/WatchedQuery.js.map +1 -1
  89. package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +1 -1
  90. package/lib/client/watched/processors/AbstractQueryProcessor.js.map +1 -1
  91. package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +20 -0
  92. package/lib/client/watched/processors/DifferentialQueryProcessor.js +4 -0
  93. package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
  94. package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -0
  95. package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
  96. package/lib/client/watched/processors/comparators.d.ts +8 -0
  97. package/lib/client/watched/processors/comparators.js +4 -0
  98. package/lib/client/watched/processors/comparators.js.map +1 -1
  99. package/lib/db/ConnectionClosedError.d.ts +2 -0
  100. package/lib/db/ConnectionClosedError.js +2 -0
  101. package/lib/db/ConnectionClosedError.js.map +1 -1
  102. package/lib/db/DBAdapter.d.ts +56 -6
  103. package/lib/db/DBAdapter.js +15 -3
  104. package/lib/db/DBAdapter.js.map +1 -1
  105. package/lib/db/crud/SyncProgress.d.ts +6 -1
  106. package/lib/db/crud/SyncProgress.js +2 -0
  107. package/lib/db/crud/SyncProgress.js.map +1 -1
  108. package/lib/db/crud/SyncStatus.d.ts +36 -38
  109. package/lib/db/crud/SyncStatus.js +19 -14
  110. package/lib/db/crud/SyncStatus.js.map +1 -1
  111. package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
  112. package/lib/db/crud/UploadQueueStatus.js +3 -0
  113. package/lib/db/crud/UploadQueueStatus.js.map +1 -1
  114. package/lib/db/schema/Column.d.ts +28 -0
  115. package/lib/db/schema/Column.js +16 -3
  116. package/lib/db/schema/Column.js.map +1 -1
  117. package/lib/db/schema/Index.d.ts +9 -0
  118. package/lib/db/schema/Index.js +6 -0
  119. package/lib/db/schema/Index.js.map +1 -1
  120. package/lib/db/schema/IndexedColumn.d.ts +9 -0
  121. package/lib/db/schema/IndexedColumn.js +6 -0
  122. package/lib/db/schema/IndexedColumn.js.map +1 -1
  123. package/lib/db/schema/RawTable.d.ts +7 -1
  124. package/lib/db/schema/Schema.d.ts +6 -1
  125. package/lib/db/schema/Schema.js +3 -1
  126. package/lib/db/schema/Schema.js.map +1 -1
  127. package/lib/db/schema/Table.d.ts +27 -3
  128. package/lib/db/schema/Table.js +9 -0
  129. package/lib/db/schema/Table.js.map +1 -1
  130. package/lib/db/schema/TableV2.d.ts +2 -0
  131. package/lib/db/schema/TableV2.js +2 -0
  132. package/lib/db/schema/TableV2.js.map +1 -1
  133. package/lib/index.d.ts +1 -1
  134. package/lib/types/types.d.ts +6 -0
  135. package/lib/utils/AbortOperation.d.ts +2 -0
  136. package/lib/utils/AbortOperation.js +2 -0
  137. package/lib/utils/AbortOperation.js.map +1 -1
  138. package/lib/utils/BaseObserver.d.ts +12 -0
  139. package/lib/utils/BaseObserver.js +3 -0
  140. package/lib/utils/BaseObserver.js.map +1 -1
  141. package/lib/utils/ControlledExecutor.d.ts +6 -0
  142. package/lib/utils/ControlledExecutor.js +3 -0
  143. package/lib/utils/ControlledExecutor.js.map +1 -1
  144. package/lib/utils/Logger.d.ts +9 -0
  145. package/lib/utils/Logger.js +6 -0
  146. package/lib/utils/Logger.js.map +1 -1
  147. package/lib/utils/async.d.ts +13 -7
  148. package/lib/utils/async.js +38 -24
  149. package/lib/utils/async.js.map +1 -1
  150. package/lib/utils/mutex.d.ts +8 -0
  151. package/lib/utils/mutex.js +3 -0
  152. package/lib/utils/mutex.js.map +1 -1
  153. package/lib/utils/parseQuery.d.ts +6 -0
  154. package/lib/utils/parseQuery.js +3 -0
  155. package/lib/utils/parseQuery.js.map +1 -1
  156. package/lib/utils/stream_transform.d.ts +3 -1
  157. package/lib/utils/stream_transform.js.map +1 -1
  158. package/package.json +3 -2
  159. package/src/attachments/AttachmentContext.ts +7 -6
  160. package/src/attachments/AttachmentErrorHandler.ts +6 -6
  161. package/src/attachments/AttachmentQueue.ts +71 -23
  162. package/src/attachments/LocalStorageAdapter.ts +14 -8
  163. package/src/attachments/README.md +2 -0
  164. package/src/attachments/RemoteStorageAdapter.ts +4 -4
  165. package/src/attachments/Schema.ts +12 -4
  166. package/src/attachments/WatchedAttachmentItem.ts +3 -1
  167. package/src/client/AbstractPowerSyncDatabase.ts +117 -62
  168. package/src/client/AbstractPowerSyncOpenFactory.ts +6 -0
  169. package/src/client/ConnectionManager.ts +4 -1
  170. package/src/client/Query.ts +9 -0
  171. package/src/client/SQLOpenFactory.ts +12 -0
  172. package/src/client/compilableQueryWatch.ts +6 -0
  173. package/src/client/connection/PowerSyncBackendConnector.ts +3 -0
  174. package/src/client/connection/PowerSyncCredentials.ts +3 -0
  175. package/src/client/constants.ts +3 -0
  176. package/src/client/runOnSchemaChange.ts +3 -0
  177. package/src/client/sync/bucket/BucketStorageAdapter.ts +12 -0
  178. package/src/client/sync/bucket/CrudBatch.ts +2 -0
  179. package/src/client/sync/bucket/CrudEntry.ts +9 -0
  180. package/src/client/sync/bucket/CrudTransaction.ts +3 -0
  181. package/src/client/sync/bucket/SqliteBucketStorage.ts +3 -0
  182. package/src/client/sync/stream/AbstractRemote.ts +30 -1
  183. package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +86 -59
  184. package/src/client/sync/stream/JsonValue.ts +3 -0
  185. package/src/client/sync/stream/WebsocketClientTransport.ts +3 -1
  186. package/src/client/sync/sync-streams.ts +22 -9
  187. package/src/client/triggers/TriggerManager.ts +19 -18
  188. package/src/client/triggers/TriggerManagerImpl.ts +5 -5
  189. package/src/client/triggers/sanitizeSQL.ts +5 -0
  190. package/src/client/watched/GetAllQuery.ts +5 -1
  191. package/src/client/watched/WatchedQuery.ts +24 -2
  192. package/src/client/watched/processors/AbstractQueryProcessor.ts +6 -6
  193. package/src/client/watched/processors/DifferentialQueryProcessor.ts +28 -5
  194. package/src/client/watched/processors/OnChangeQueryProcessor.ts +9 -3
  195. package/src/client/watched/processors/comparators.ts +8 -0
  196. package/src/db/ConnectionClosedError.ts +2 -0
  197. package/src/db/DBAdapter.ts +58 -6
  198. package/src/db/crud/SyncProgress.ts +6 -1
  199. package/src/db/crud/SyncStatus.ts +40 -21
  200. package/src/db/crud/UploadQueueStatus.ts +3 -0
  201. package/src/db/schema/Column.ts +28 -3
  202. package/src/db/schema/Index.ts +9 -0
  203. package/src/db/schema/IndexedColumn.ts +9 -0
  204. package/src/db/schema/RawTable.ts +7 -1
  205. package/src/db/schema/Schema.ts +8 -3
  206. package/src/db/schema/Table.ts +30 -5
  207. package/src/db/schema/TableV2.ts +2 -0
  208. package/src/index.ts +1 -1
  209. package/src/types/types.ts +6 -0
  210. package/src/utils/AbortOperation.ts +2 -0
  211. package/src/utils/BaseObserver.ts +12 -0
  212. package/src/utils/ControlledExecutor.ts +6 -0
  213. package/src/utils/Logger.ts +9 -0
  214. package/src/utils/async.ts +51 -24
  215. package/src/utils/mutex.ts +12 -0
  216. package/src/utils/parseQuery.ts +6 -0
  217. package/src/utils/stream_transform.ts +3 -1
@@ -1,5 +1,11 @@
1
+ /**
2
+ * @alpha
3
+ */
1
4
  export type AttachmentData = ArrayBuffer | string;
2
5
 
6
+ /**
7
+ * @alpha
8
+ */
3
9
  export enum EncodingType {
4
10
  UTF8 = 'utf8',
5
11
  Base64 = 'base64'
@@ -15,41 +21,41 @@ export enum EncodingType {
15
21
  export interface LocalStorageAdapter {
16
22
  /**
17
23
  * Saves data to a local file.
18
- * @param filePath Path where the file will be stored
19
- * @param data Data to store (ArrayBuffer, Blob, or string)
24
+ * @param filePath - Path where the file will be stored
25
+ * @param data - Data to store (ArrayBuffer, Blob, or string)
20
26
  * @returns Number of bytes written
21
27
  */
22
28
  saveFile(filePath: string, data: AttachmentData): Promise<number>;
23
29
 
24
30
  /**
25
31
  * Retrieves file data as an ArrayBuffer.
26
- * @param filePath Path where the file is stored
32
+ * @param filePath - Path where the file is stored
27
33
  * @returns ArrayBuffer containing the file data
28
34
  */
29
35
  readFile(filePath: string): Promise<ArrayBuffer>;
30
36
 
31
37
  /**
32
38
  * Deletes the file at the given path.
33
- * @param filePath Path where the file is stored
39
+ * @param filePath - Path where the file is stored
34
40
  */
35
41
  deleteFile(filePath: string): Promise<void>;
36
42
 
37
43
  /**
38
44
  * Checks if a file exists at the given path.
39
- * @param filePath Path where the file is stored
45
+ * @param filePath - Path where the file is stored
40
46
  * @returns True if the file exists, false otherwise
41
47
  */
42
48
  fileExists(filePath: string): Promise<boolean>;
43
49
 
44
50
  /**
45
51
  * Creates a directory at the specified path.
46
- * @param path The full path to the directory
52
+ * @param path - The full path to the directory
47
53
  */
48
54
  makeDir(path: string): Promise<void>;
49
55
 
50
56
  /**
51
57
  * Removes a directory at the specified path.
52
- * @param path The full path to the directory
58
+ * @param path - The full path to the directory
53
59
  */
54
60
  rmDir(path: string): Promise<void>;
55
61
 
@@ -65,7 +71,7 @@ export interface LocalStorageAdapter {
65
71
 
66
72
  /**
67
73
  * Returns the file path for the provided filename in the storage directory.
68
- * @param filename The filename to get the path for
74
+ * @param filename - The filename to get the path for
69
75
  * @returns The full file path
70
76
  */
71
77
  getLocalUri(filename: string): string;
@@ -427,10 +427,12 @@ type WatchedAttachmentItem = {
427
427
  id: string;
428
428
  fileExtension: string; // e.g., 'jpg', 'pdf'
429
429
  metaData?: string;
430
+ mediaType?: string; // e.g., 'image/jpeg'
430
431
  } | {
431
432
  id: string;
432
433
  filename: string; // e.g., 'document.pdf'
433
434
  metaData?: string;
435
+ mediaType?: string; // e.g., 'application/pdf'
434
436
  };
435
437
  ```
436
438
 
@@ -10,21 +10,21 @@ import { AttachmentRecord } from './Schema.js';
10
10
  export interface RemoteStorageAdapter {
11
11
  /**
12
12
  * Uploads a file to remote storage.
13
- * @param fileData The binary content of the file to upload
14
- * @param attachment The associated attachment metadata
13
+ * @param fileData - The binary content of the file to upload
14
+ * @param attachment - The associated attachment metadata
15
15
  */
16
16
  uploadFile(fileData: ArrayBuffer, attachment: AttachmentRecord): Promise<void>;
17
17
 
18
18
  /**
19
19
  * Downloads a file from remote storage.
20
- * @param attachment The attachment describing the file to download
20
+ * @param attachment - The attachment describing the file to download
21
21
  * @returns The binary data of the downloaded file
22
22
  */
23
23
  downloadFile(attachment: AttachmentRecord): Promise<ArrayBuffer>;
24
24
 
25
25
  /**
26
26
  * Deletes a file from remote storage.
27
- * @param attachment The attachment describing the file to delete
27
+ * @param attachment - The attachment describing the file to delete
28
28
  */
29
29
  deleteFile(attachment: AttachmentRecord): Promise<void>;
30
30
  }
@@ -2,12 +2,17 @@ import { column } from '../db/schema/Column.js';
2
2
  import { Table } from '../db/schema/Table.js';
3
3
  import { TableV2Options } from '../db/schema/Table.js';
4
4
 
5
+ /**
6
+ * The default name of the local table storing attachment data.
7
+ *
8
+ * @alpha
9
+ */
5
10
  export const ATTACHMENT_TABLE = 'attachments';
6
11
 
7
12
  /**
8
13
  * AttachmentRecord represents an attachment in the local database.
9
14
  *
10
- * @experimental
15
+ * @alpha
11
16
  */
12
17
  export interface AttachmentRecord {
13
18
  id: string;
@@ -27,7 +32,7 @@ export interface AttachmentRecord {
27
32
  * @param row - The database row object
28
33
  * @returns The corresponding AttachmentRecord
29
34
  *
30
- * @experimental
35
+ * @alpha
31
36
  */
32
37
  export function attachmentFromSql(row: any): AttachmentRecord {
33
38
  return {
@@ -46,7 +51,7 @@ export function attachmentFromSql(row: any): AttachmentRecord {
46
51
  /**
47
52
  * AttachmentState represents the current synchronization state of an attachment.
48
53
  *
49
- * @experimental
54
+ * @alpha
50
55
  */
51
56
  export enum AttachmentState {
52
57
  QUEUED_UPLOAD = 0, // Attachment to be uploaded
@@ -56,12 +61,15 @@ export enum AttachmentState {
56
61
  ARCHIVED = 4 // Attachment has been orphaned, i.e. the associated record has been deleted
57
62
  }
58
63
 
64
+ /**
65
+ * @alpha
66
+ */
59
67
  export interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {}
60
68
 
61
69
  /**
62
70
  * AttachmentTable defines the schema for the attachment queue table.
63
71
  *
64
- * @internal
72
+ * @alpha
65
73
  */
66
74
  export class AttachmentTable extends Table {
67
75
  constructor(options?: AttachmentTableOptions) {
@@ -2,7 +2,7 @@
2
2
  * WatchedAttachmentItem represents an attachment reference in your application's data model.
3
3
  * Use either filename OR fileExtension (not both).
4
4
  *
5
- * @experimental
5
+ * @alpha
6
6
  */
7
7
  export type WatchedAttachmentItem =
8
8
  | {
@@ -10,10 +10,12 @@ export type WatchedAttachmentItem =
10
10
  filename: string;
11
11
  fileExtension?: never;
12
12
  metaData?: string;
13
+ mediaType?: string;
13
14
  }
14
15
  | {
15
16
  id: string;
16
17
  fileExtension: string;
17
18
  filename?: never;
18
19
  metaData?: string;
20
+ mediaType?: string;
19
21
  };