@powersync/common 1.46.0 → 1.48.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 (71) hide show
  1. package/README.md +5 -1
  2. package/dist/bundle.cjs +1298 -395
  3. package/dist/bundle.cjs.map +1 -1
  4. package/dist/bundle.mjs +1291 -395
  5. package/dist/bundle.mjs.map +1 -1
  6. package/dist/bundle.node.cjs +1298 -395
  7. package/dist/bundle.node.cjs.map +1 -1
  8. package/dist/bundle.node.mjs +1291 -395
  9. package/dist/bundle.node.mjs.map +1 -1
  10. package/dist/index.d.cts +652 -106
  11. package/lib/attachments/AttachmentContext.d.ts +86 -0
  12. package/lib/attachments/AttachmentContext.js +229 -0
  13. package/lib/attachments/AttachmentContext.js.map +1 -0
  14. package/lib/attachments/AttachmentErrorHandler.d.ts +31 -0
  15. package/lib/attachments/AttachmentErrorHandler.js +2 -0
  16. package/lib/attachments/AttachmentErrorHandler.js.map +1 -0
  17. package/lib/attachments/AttachmentQueue.d.ts +149 -0
  18. package/lib/attachments/AttachmentQueue.js +362 -0
  19. package/lib/attachments/AttachmentQueue.js.map +1 -0
  20. package/lib/attachments/AttachmentService.d.ts +29 -0
  21. package/lib/attachments/AttachmentService.js +56 -0
  22. package/lib/attachments/AttachmentService.js.map +1 -0
  23. package/lib/attachments/LocalStorageAdapter.d.ts +62 -0
  24. package/lib/attachments/LocalStorageAdapter.js +6 -0
  25. package/lib/attachments/LocalStorageAdapter.js.map +1 -0
  26. package/lib/attachments/RemoteStorageAdapter.d.ts +27 -0
  27. package/lib/attachments/RemoteStorageAdapter.js +2 -0
  28. package/lib/attachments/RemoteStorageAdapter.js.map +1 -0
  29. package/lib/attachments/Schema.d.ts +50 -0
  30. package/lib/attachments/Schema.js +62 -0
  31. package/lib/attachments/Schema.js.map +1 -0
  32. package/lib/attachments/SyncingService.d.ts +62 -0
  33. package/lib/attachments/SyncingService.js +168 -0
  34. package/lib/attachments/SyncingService.js.map +1 -0
  35. package/lib/attachments/WatchedAttachmentItem.d.ts +17 -0
  36. package/lib/attachments/WatchedAttachmentItem.js +2 -0
  37. package/lib/attachments/WatchedAttachmentItem.js.map +1 -0
  38. package/lib/db/schema/RawTable.d.ts +61 -26
  39. package/lib/db/schema/RawTable.js +1 -32
  40. package/lib/db/schema/RawTable.js.map +1 -1
  41. package/lib/db/schema/Schema.d.ts +14 -7
  42. package/lib/db/schema/Schema.js +25 -3
  43. package/lib/db/schema/Schema.js.map +1 -1
  44. package/lib/db/schema/Table.d.ts +13 -8
  45. package/lib/db/schema/Table.js +3 -8
  46. package/lib/db/schema/Table.js.map +1 -1
  47. package/lib/db/schema/internal.d.ts +12 -0
  48. package/lib/db/schema/internal.js +15 -0
  49. package/lib/db/schema/internal.js.map +1 -0
  50. package/lib/index.d.ts +11 -1
  51. package/lib/index.js +10 -1
  52. package/lib/index.js.map +1 -1
  53. package/lib/utils/mutex.d.ts +1 -1
  54. package/lib/utils/mutex.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/attachments/AttachmentContext.ts +279 -0
  57. package/src/attachments/AttachmentErrorHandler.ts +34 -0
  58. package/src/attachments/AttachmentQueue.ts +472 -0
  59. package/src/attachments/AttachmentService.ts +62 -0
  60. package/src/attachments/LocalStorageAdapter.ts +72 -0
  61. package/src/attachments/README.md +718 -0
  62. package/src/attachments/RemoteStorageAdapter.ts +30 -0
  63. package/src/attachments/Schema.ts +87 -0
  64. package/src/attachments/SyncingService.ts +193 -0
  65. package/src/attachments/WatchedAttachmentItem.ts +19 -0
  66. package/src/db/schema/RawTable.ts +66 -31
  67. package/src/db/schema/Schema.ts +27 -2
  68. package/src/db/schema/Table.ts +11 -11
  69. package/src/db/schema/internal.ts +17 -0
  70. package/src/index.ts +12 -1
  71. package/src/utils/mutex.ts +1 -1
@@ -0,0 +1,62 @@
1
+ import { column } from '../db/schema/Column.js';
2
+ import { Table } from '../db/schema/Table.js';
3
+ export const ATTACHMENT_TABLE = 'attachments';
4
+ /**
5
+ * Maps a database row to an AttachmentRecord.
6
+ *
7
+ * @param row - The database row object
8
+ * @returns The corresponding AttachmentRecord
9
+ *
10
+ * @experimental
11
+ */
12
+ export function attachmentFromSql(row) {
13
+ return {
14
+ id: row.id,
15
+ filename: row.filename,
16
+ localUri: row.local_uri,
17
+ size: row.size,
18
+ mediaType: row.media_type,
19
+ timestamp: row.timestamp,
20
+ metaData: row.meta_data,
21
+ hasSynced: row.has_synced === 1,
22
+ state: row.state
23
+ };
24
+ }
25
+ /**
26
+ * AttachmentState represents the current synchronization state of an attachment.
27
+ *
28
+ * @experimental
29
+ */
30
+ export var AttachmentState;
31
+ (function (AttachmentState) {
32
+ AttachmentState[AttachmentState["QUEUED_UPLOAD"] = 0] = "QUEUED_UPLOAD";
33
+ AttachmentState[AttachmentState["QUEUED_DOWNLOAD"] = 1] = "QUEUED_DOWNLOAD";
34
+ AttachmentState[AttachmentState["QUEUED_DELETE"] = 2] = "QUEUED_DELETE";
35
+ AttachmentState[AttachmentState["SYNCED"] = 3] = "SYNCED";
36
+ AttachmentState[AttachmentState["ARCHIVED"] = 4] = "ARCHIVED"; // Attachment has been orphaned, i.e. the associated record has been deleted
37
+ })(AttachmentState || (AttachmentState = {}));
38
+ /**
39
+ * AttachmentTable defines the schema for the attachment queue table.
40
+ *
41
+ * @internal
42
+ */
43
+ export class AttachmentTable extends Table {
44
+ constructor(options) {
45
+ super({
46
+ filename: column.text,
47
+ local_uri: column.text,
48
+ timestamp: column.integer,
49
+ size: column.integer,
50
+ media_type: column.text,
51
+ state: column.integer, // Corresponds to AttachmentState
52
+ has_synced: column.integer,
53
+ meta_data: column.text
54
+ }, {
55
+ ...options,
56
+ viewName: options?.viewName ?? ATTACHMENT_TABLE,
57
+ localOnly: true,
58
+ insertOnly: false
59
+ });
60
+ }
61
+ }
62
+ //# sourceMappingURL=Schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/attachments/Schema.ts"],"names":[],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;YACV,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,gBAAgB;YAC/C,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,KAAK;SAClB,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import { ILogger } from '../utils/Logger.js';
2
+ import { AttachmentService } from './AttachmentService.js';
3
+ import { LocalStorageAdapter } from './LocalStorageAdapter.js';
4
+ import { RemoteStorageAdapter } from './RemoteStorageAdapter.js';
5
+ import { AttachmentRecord } from './Schema.js';
6
+ import { AttachmentErrorHandler } from './AttachmentErrorHandler.js';
7
+ import { AttachmentContext } from './AttachmentContext.js';
8
+ /**
9
+ * Orchestrates attachment synchronization between local and remote storage.
10
+ * Handles uploads, downloads, deletions, and state transitions.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare class SyncingService {
15
+ private attachmentService;
16
+ private localStorage;
17
+ private remoteStorage;
18
+ private logger;
19
+ private errorHandler?;
20
+ constructor(attachmentService: AttachmentService, localStorage: LocalStorageAdapter, remoteStorage: RemoteStorageAdapter, logger: ILogger, errorHandler?: AttachmentErrorHandler);
21
+ /**
22
+ * Processes attachments based on their state (upload, download, or delete).
23
+ * All updates are saved in a single batch after processing.
24
+ *
25
+ * @param attachments - Array of attachment records to process
26
+ * @param context - Attachment context for database operations
27
+ * @returns Promise that resolves when all attachments have been processed and saved
28
+ */
29
+ processAttachments(attachments: AttachmentRecord[], context: AttachmentContext): Promise<void>;
30
+ /**
31
+ * Uploads an attachment from local storage to remote storage.
32
+ * On success, marks as SYNCED. On failure, defers to error handler or archives.
33
+ *
34
+ * @param attachment - The attachment record to upload
35
+ * @returns Updated attachment record with new state
36
+ * @throws Error if the attachment has no localUri
37
+ */
38
+ uploadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
39
+ /**
40
+ * Downloads an attachment from remote storage to local storage.
41
+ * Retrieves the file, converts to base64, and saves locally.
42
+ * On success, marks as SYNCED. On failure, defers to error handler or archives.
43
+ *
44
+ * @param attachment - The attachment record to download
45
+ * @returns Updated attachment record with local URI and new state
46
+ */
47
+ downloadAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
48
+ /**
49
+ * Deletes an attachment from both remote and local storage.
50
+ * Removes the remote file, local file (if exists), and the attachment record.
51
+ * On failure, defers to error handler or archives.
52
+ *
53
+ * @param attachment - The attachment record to delete
54
+ * @returns Updated attachment record
55
+ */
56
+ deleteAttachment(attachment: AttachmentRecord): Promise<AttachmentRecord>;
57
+ /**
58
+ * Performs cleanup of archived attachments by removing their local files and records.
59
+ * Errors during local file deletion are logged but do not prevent record deletion.
60
+ */
61
+ deleteArchivedAttachments(context: AttachmentContext): Promise<boolean>;
62
+ }
@@ -0,0 +1,168 @@
1
+ import { AttachmentState } from './Schema.js';
2
+ /**
3
+ * Orchestrates attachment synchronization between local and remote storage.
4
+ * Handles uploads, downloads, deletions, and state transitions.
5
+ *
6
+ * @internal
7
+ */
8
+ export class SyncingService {
9
+ attachmentService;
10
+ localStorage;
11
+ remoteStorage;
12
+ logger;
13
+ errorHandler;
14
+ constructor(attachmentService, localStorage, remoteStorage, logger, errorHandler) {
15
+ this.attachmentService = attachmentService;
16
+ this.localStorage = localStorage;
17
+ this.remoteStorage = remoteStorage;
18
+ this.logger = logger;
19
+ this.errorHandler = errorHandler;
20
+ }
21
+ /**
22
+ * Processes attachments based on their state (upload, download, or delete).
23
+ * All updates are saved in a single batch after processing.
24
+ *
25
+ * @param attachments - Array of attachment records to process
26
+ * @param context - Attachment context for database operations
27
+ * @returns Promise that resolves when all attachments have been processed and saved
28
+ */
29
+ async processAttachments(attachments, context) {
30
+ const updatedAttachments = [];
31
+ for (const attachment of attachments) {
32
+ switch (attachment.state) {
33
+ case AttachmentState.QUEUED_UPLOAD:
34
+ const uploaded = await this.uploadAttachment(attachment);
35
+ updatedAttachments.push(uploaded);
36
+ break;
37
+ case AttachmentState.QUEUED_DOWNLOAD:
38
+ const downloaded = await this.downloadAttachment(attachment);
39
+ updatedAttachments.push(downloaded);
40
+ break;
41
+ case AttachmentState.QUEUED_DELETE:
42
+ const deleted = await this.deleteAttachment(attachment);
43
+ updatedAttachments.push(deleted);
44
+ break;
45
+ default:
46
+ break;
47
+ }
48
+ }
49
+ await context.saveAttachments(updatedAttachments);
50
+ }
51
+ /**
52
+ * Uploads an attachment from local storage to remote storage.
53
+ * On success, marks as SYNCED. On failure, defers to error handler or archives.
54
+ *
55
+ * @param attachment - The attachment record to upload
56
+ * @returns Updated attachment record with new state
57
+ * @throws Error if the attachment has no localUri
58
+ */
59
+ async uploadAttachment(attachment) {
60
+ this.logger.info(`Uploading attachment ${attachment.filename}`);
61
+ try {
62
+ if (attachment.localUri == null) {
63
+ throw new Error(`No localUri for attachment ${attachment.id}`);
64
+ }
65
+ const fileBlob = await this.localStorage.readFile(attachment.localUri);
66
+ await this.remoteStorage.uploadFile(fileBlob, attachment);
67
+ return {
68
+ ...attachment,
69
+ state: AttachmentState.SYNCED,
70
+ hasSynced: true
71
+ };
72
+ }
73
+ catch (error) {
74
+ const shouldRetry = (await this.errorHandler?.onUploadError(attachment, error)) ?? true;
75
+ if (!shouldRetry) {
76
+ return {
77
+ ...attachment,
78
+ state: AttachmentState.ARCHIVED
79
+ };
80
+ }
81
+ return attachment;
82
+ }
83
+ }
84
+ /**
85
+ * Downloads an attachment from remote storage to local storage.
86
+ * Retrieves the file, converts to base64, and saves locally.
87
+ * On success, marks as SYNCED. On failure, defers to error handler or archives.
88
+ *
89
+ * @param attachment - The attachment record to download
90
+ * @returns Updated attachment record with local URI and new state
91
+ */
92
+ async downloadAttachment(attachment) {
93
+ this.logger.info(`Downloading attachment ${attachment.filename}`);
94
+ try {
95
+ const fileData = await this.remoteStorage.downloadFile(attachment);
96
+ const localUri = this.localStorage.getLocalUri(attachment.filename);
97
+ await this.localStorage.saveFile(localUri, fileData);
98
+ return {
99
+ ...attachment,
100
+ state: AttachmentState.SYNCED,
101
+ localUri: localUri,
102
+ hasSynced: true
103
+ };
104
+ }
105
+ catch (error) {
106
+ const shouldRetry = (await this.errorHandler?.onDownloadError(attachment, error)) ?? true;
107
+ if (!shouldRetry) {
108
+ return {
109
+ ...attachment,
110
+ state: AttachmentState.ARCHIVED
111
+ };
112
+ }
113
+ return attachment;
114
+ }
115
+ }
116
+ /**
117
+ * Deletes an attachment from both remote and local storage.
118
+ * Removes the remote file, local file (if exists), and the attachment record.
119
+ * On failure, defers to error handler or archives.
120
+ *
121
+ * @param attachment - The attachment record to delete
122
+ * @returns Updated attachment record
123
+ */
124
+ async deleteAttachment(attachment) {
125
+ try {
126
+ await this.remoteStorage.deleteFile(attachment);
127
+ if (attachment.localUri) {
128
+ await this.localStorage.deleteFile(attachment.localUri);
129
+ }
130
+ await this.attachmentService.withContext(async (ctx) => {
131
+ await ctx.deleteAttachment(attachment.id);
132
+ });
133
+ return {
134
+ ...attachment,
135
+ state: AttachmentState.ARCHIVED
136
+ };
137
+ }
138
+ catch (error) {
139
+ const shouldRetry = (await this.errorHandler?.onDeleteError(attachment, error)) ?? true;
140
+ if (!shouldRetry) {
141
+ return {
142
+ ...attachment,
143
+ state: AttachmentState.ARCHIVED
144
+ };
145
+ }
146
+ return attachment;
147
+ }
148
+ }
149
+ /**
150
+ * Performs cleanup of archived attachments by removing their local files and records.
151
+ * Errors during local file deletion are logged but do not prevent record deletion.
152
+ */
153
+ async deleteArchivedAttachments(context) {
154
+ return await context.deleteArchivedAttachments(async (archivedAttachments) => {
155
+ for (const attachment of archivedAttachments) {
156
+ if (attachment.localUri) {
157
+ try {
158
+ await this.localStorage.deleteFile(attachment.localUri);
159
+ }
160
+ catch (error) {
161
+ this.logger.error('Error deleting local file for archived attachment', error);
162
+ }
163
+ }
164
+ }
165
+ });
166
+ }
167
+ }
168
+ //# sourceMappingURL=SyncingService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncingService.js","sourceRoot":"","sources":["../../src/attachments/SyncingService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,eAAe,EAAE,MAAM,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AAM,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC;YACxF,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO;oBACL,GAAG,UAAU;oBACb,KAAK,EAAE,eAAe,CAAC,QAAQ;iBAChC,CAAC;YACJ,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,yBAAyB,CAAC,OAA0B;QACxD,OAAO,MAAM,OAAO,CAAC,yBAAyB,CAAC,KAAK,EAAE,mBAAmB,EAAE,EAAE;YAC3E,KAAK,MAAM,UAAU,IAAI,mBAAmB,EAAE,CAAC;gBAC7C,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;oBACxB,IAAI,CAAC;wBACH,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;oBAC1D,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mDAAmD,EAAE,KAAK,CAAC,CAAC;oBAChF,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WatchedAttachmentItem represents an attachment reference in your application's data model.
3
+ * Use either filename OR fileExtension (not both).
4
+ *
5
+ * @experimental
6
+ */
7
+ export type WatchedAttachmentItem = {
8
+ id: string;
9
+ filename: string;
10
+ fileExtension?: never;
11
+ metaData?: string;
12
+ } | {
13
+ id: string;
14
+ fileExtension: string;
15
+ filename?: never;
16
+ metaData?: string;
17
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=WatchedAttachmentItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatchedAttachmentItem.js","sourceRoot":"","sources":["../../src/attachments/WatchedAttachmentItem.ts"],"names":[],"mappings":""}
@@ -1,8 +1,21 @@
1
+ import { TableOrRawTableOptions } from './Table.js';
1
2
  /**
2
- * A pending variant of a {@link RawTable} that doesn't have a name (because it would be inferred when creating the
3
- * schema).
3
+ * Instructs PowerSync to sync data into a "raw" table.
4
+ *
5
+ * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
6
+ * using client-side table and column constraints.
7
+ *
8
+ * To collect local writes to raw tables with PowerSync, custom triggers are required. See
9
+ * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
10
+ * using raw tables.
11
+ *
12
+ * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
13
+ *
14
+ * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
15
+ * stability guarantees.
4
16
  */
5
- export type RawTableType = {
17
+ export type RawTableType = RawTableTypeWithStatements | InferredRawTableType;
18
+ interface RawTableTypeWithStatements {
6
19
  /**
7
20
  * The statement to run when PowerSync detects that a row needs to be inserted or updated.
8
21
  */
@@ -11,7 +24,40 @@ export type RawTableType = {
11
24
  * The statement to run when PowerSync detects that a row needs to be deleted.
12
25
  */
13
26
  delete: PendingStatement;
14
- };
27
+ /**
28
+ * An optional statement to run when `disconnectAndClear()` is called on a PowerSync database.
29
+ */
30
+ clear?: string;
31
+ }
32
+ /**
33
+ * The schema of a {@link RawTableType} in the local database.
34
+ *
35
+ * This information is optional when declaring raw tables. However, providing it allows the sync client to infer `put`
36
+ * and `delete` statements automatically.
37
+ */
38
+ interface RawTableSchema extends TableOrRawTableOptions {
39
+ /**
40
+ * The actual name of the raw table in the local schema.
41
+ *
42
+ * Unlike {@link RawTable.name}, which describes the name of synced tables to match, this reflects the SQLite table
43
+ * name. This is used to infer {@link RawTableType.put} and {@link RawTableType.delete} statements for the sync
44
+ * client. It can also be used to auto-generate triggers forwarding writes on raw tables into the CRUD upload queue
45
+ * (using the `powersync_create_raw_table_crud_trigger` SQL function).
46
+ *
47
+ * When absent, defaults to {@link RawTable.name}.
48
+ */
49
+ tableName?: string;
50
+ /**
51
+ * An optional filter of columns that should be synced.
52
+ *
53
+ * By default, all columns in a raw table are considered for sync. If a filter is specified, PowerSync treats
54
+ * unmatched columns as local-only and will not attempt to sync them.
55
+ */
56
+ syncedColumns?: string[];
57
+ }
58
+ interface InferredRawTableType extends Partial<RawTableTypeWithStatements> {
59
+ schema: RawTableSchema;
60
+ }
15
61
  /**
16
62
  * A parameter to use as part of {@link PendingStatement}.
17
63
  *
@@ -20,10 +66,12 @@ export type RawTableType = {
20
66
  *
21
67
  * For insert and replace operations, the values of columns in the table are available as parameters through
22
68
  * `{Column: 'name'}`.
69
+ * The `"Rest"` parameter gets resolved to a JSON object covering all values from the synced row that haven't been
70
+ * covered by a `Column` parameter.
23
71
  */
24
72
  export type PendingStatementParameter = 'Id' | {
25
73
  Column: string;
26
- };
74
+ } | 'Rest';
27
75
  /**
28
76
  * A statement that the PowerSync client should use to insert or delete data into a table managed by the user.
29
77
  */
@@ -32,30 +80,17 @@ export type PendingStatement = {
32
80
  params: PendingStatementParameter[];
33
81
  };
34
82
  /**
35
- * Instructs PowerSync to sync data into a "raw" table.
36
- *
37
- * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
38
- * using client-side table and column constraints.
39
- *
40
- * To collect local writes to raw tables with PowerSync, custom triggers are required. See
41
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
42
- * using raw tables.
43
- *
44
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
45
- *
46
- * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
47
- * stability guarantees.
83
+ * @internal
48
84
  */
49
- export declare class RawTable implements RawTableType {
85
+ export type RawTable<T extends RawTableType = RawTableType> = T & {
50
86
  /**
51
87
  * The name of the table.
52
88
  *
53
- * This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
54
- * another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
55
- * appears in the source / backend database) are to be handled specially.
89
+ * This does not have to match the actual table name in the schema - {@link RawTableType.put} and
90
+ * {@link RawTableType.delete} are free to use another table. Instead, this name is used by the sync client to
91
+ * recognize that operations on this table (as it appears in the source / backend database) are to be handled
92
+ * specially.
56
93
  */
57
94
  name: string;
58
- put: PendingStatement;
59
- delete: PendingStatement;
60
- constructor(name: string, type: RawTableType);
61
- }
95
+ };
96
+ export {};
@@ -1,33 +1,2 @@
1
- /**
2
- * Instructs PowerSync to sync data into a "raw" table.
3
- *
4
- * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
5
- * using client-side table and column constraints.
6
- *
7
- * To collect local writes to raw tables with PowerSync, custom triggers are required. See
8
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
9
- * using raw tables.
10
- *
11
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
12
- *
13
- * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
14
- * stability guarantees.
15
- */
16
- export class RawTable {
17
- /**
18
- * The name of the table.
19
- *
20
- * This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
21
- * another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
22
- * appears in the source / backend database) are to be handled specially.
23
- */
24
- name;
25
- put;
26
- delete;
27
- constructor(name, type) {
28
- this.name = name;
29
- this.put = type.put;
30
- this.delete = type.delete;
31
- }
32
- }
1
+ export {};
33
2
  //# sourceMappingURL=RawTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RawTable.js","sourceRoot":"","sources":["../../../src/db/schema/RawTable.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,QAAQ;IACnB;;;;;;OAMG;IACH,IAAI,CAAS;IACb,GAAG,CAAmB;IACtB,MAAM,CAAmB;IAEzB,YAAY,IAAY,EAAE,IAAkB;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CACF"}
1
+ {"version":3,"file":"RawTable.js","sourceRoot":"","sources":["../../../src/db/schema/RawTable.ts"],"names":[],"mappings":""}
@@ -27,14 +27,14 @@ export declare class Schema<S extends SchemaType = SchemaType> {
27
27
  validate(): void;
28
28
  toJSON(): {
29
29
  tables: {
30
- name: string;
31
- view_name: string;
32
- local_only: boolean;
33
- insert_only: boolean;
30
+ local_only: boolean | undefined;
31
+ insert_only: boolean | undefined;
34
32
  include_old: any;
35
33
  include_old_only_when_changed: boolean;
36
- include_metadata: boolean;
37
- ignore_empty_update: boolean;
34
+ include_metadata: boolean | undefined;
35
+ ignore_empty_update: boolean | undefined;
36
+ name: string;
37
+ view_name: string;
38
38
  columns: {
39
39
  name: string;
40
40
  type: import("./Column.js").ColumnType | undefined;
@@ -48,7 +48,14 @@ export declare class Schema<S extends SchemaType = SchemaType> {
48
48
  }[];
49
49
  }[];
50
50
  }[];
51
- raw_tables: RawTable[];
51
+ raw_tables: unknown[];
52
52
  };
53
+ /**
54
+ * Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
55
+ *
56
+ * The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
57
+ * to define triggers for this table.
58
+ */
59
+ static rawTableToJson(table: RawTable): unknown;
53
60
  }
54
61
  export {};
@@ -1,4 +1,4 @@
1
- import { RawTable } from './RawTable.js';
1
+ import { encodeTableOptions } from './internal.js';
2
2
  /**
3
3
  * A schema is a collection of tables. It is used to define the structure of a database.
4
4
  */
@@ -43,7 +43,7 @@ export class Schema {
43
43
  */
44
44
  withRawTables(tables) {
45
45
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
46
- this.rawTables.push(new RawTable(name, rawTableDefinition));
46
+ this.rawTables.push({ name, ...rawTableDefinition });
47
47
  }
48
48
  }
49
49
  validate() {
@@ -54,8 +54,30 @@ export class Schema {
54
54
  toJSON() {
55
55
  return {
56
56
  tables: this.tables.map((t) => t.toJSON()),
57
- raw_tables: this.rawTables
57
+ raw_tables: this.rawTables.map(Schema.rawTableToJson)
58
58
  };
59
59
  }
60
+ /**
61
+ * Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
62
+ *
63
+ * The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
64
+ * to define triggers for this table.
65
+ */
66
+ static rawTableToJson(table) {
67
+ const serialized = {
68
+ name: table.name,
69
+ put: table.put,
70
+ delete: table.delete,
71
+ clear: table.clear
72
+ };
73
+ if ('schema' in table) {
74
+ // We have schema options, those are flattened into the outer JSON object for the core extension.
75
+ const schema = table.schema;
76
+ serialized.table_name = schema.tableName ?? table.name;
77
+ serialized.synced_columns = schema.syncedColumns;
78
+ Object.assign(serialized, encodeTableOptions(table.schema));
79
+ }
80
+ return serialized;
81
+ }
60
82
  }
61
83
  //# sourceMappingURL=Schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../../src/db/schema/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAC;AASvD;;GAEG;AACH,MAAM,OAAO,MAAM;IACjB;;MAEE;IACO,KAAK,CAAqB;IAC1B,KAAK,CAAI;IACT,MAAM,CAAU;IAChB,SAAS,CAAa;IAE/B,YAAY,MAAmB;QAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B;;;;cAIE;YACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC;oBACtB,MAAM,IAAI,KAAK,CACb,2KAA2K,CAC5K,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,4DAA4D;YAC5D,IAAI,CAAC,KAAK,GA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E,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC1C,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC;SACtD,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAe;QACnC,MAAM,UAAU,GAAQ;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACF,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;YACtB,iGAAiG;YACjG,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC5B,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC;YACvD,UAAU,CAAC,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC;YACjD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
@@ -1,14 +1,19 @@
1
1
  import { Column, ColumnsType, ColumnType, ExtractColumnValueType } from './Column.js';
2
2
  import { Index } from './Index.js';
3
3
  import { TableV2 } from './TableV2.js';
4
- interface SharedTableOptions {
4
+ /**
5
+ * Options that apply both to JSON-based tables and raw tables.
6
+ */
7
+ export interface TableOrRawTableOptions {
5
8
  localOnly?: boolean;
6
9
  insertOnly?: boolean;
7
- viewName?: string;
8
10
  trackPrevious?: boolean | TrackPreviousOptions;
9
11
  trackMetadata?: boolean;
10
12
  ignoreEmptyUpdates?: boolean;
11
13
  }
14
+ interface SharedTableOptions extends TableOrRawTableOptions {
15
+ viewName?: string;
16
+ }
12
17
  /** Whether to include previous column values when PowerSync tracks local changes.
13
18
  *
14
19
  * Including old values may be helpful for some backend connector implementations, which is
@@ -132,14 +137,14 @@ export declare class Table<Columns extends ColumnsType = ColumnsType> {
132
137
  get validName(): boolean;
133
138
  validate(): void;
134
139
  toJSON(): {
135
- name: string;
136
- view_name: string;
137
- local_only: boolean;
138
- insert_only: boolean;
140
+ local_only: boolean | undefined;
141
+ insert_only: boolean | undefined;
139
142
  include_old: any;
140
143
  include_old_only_when_changed: boolean;
141
- include_metadata: boolean;
142
- ignore_empty_update: boolean;
144
+ include_metadata: boolean | undefined;
145
+ ignore_empty_update: boolean | undefined;
146
+ name: string;
147
+ view_name: string;
143
148
  columns: {
144
149
  name: string;
145
150
  type: ColumnType | undefined;
@@ -1,6 +1,7 @@
1
1
  import { Column, ColumnType, MAX_AMOUNT_OF_COLUMNS } from './Column.js';
2
2
  import { Index } from './Index.js';
3
3
  import { IndexedColumn } from './IndexedColumn.js';
4
+ import { encodeTableOptions } from './internal.js';
4
5
  export const DEFAULT_TABLE_OPTIONS = {
5
6
  indexes: [],
6
7
  insertOnly: false,
@@ -190,18 +191,12 @@ export class Table {
190
191
  }
191
192
  }
192
193
  toJSON() {
193
- const trackPrevious = this.trackPrevious;
194
194
  return {
195
195
  name: this.name,
196
196
  view_name: this.viewName,
197
- local_only: this.localOnly,
198
- insert_only: this.insertOnly,
199
- include_old: trackPrevious && (trackPrevious.columns ?? true),
200
- include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
201
- include_metadata: this.trackMetadata,
202
- ignore_empty_update: this.ignoreEmptyUpdates,
203
197
  columns: this.columns.map((c) => c.toJSON()),
204
- indexes: this.indexes.map((e) => e.toJSON(this))
198
+ indexes: this.indexes.map((e) => e.toJSON(this)),
199
+ ...encodeTableOptions(this)
205
200
  };
206
201
  }
207
202
  }