@powersync/common 1.47.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.
@@ -103,6 +103,21 @@ class Index {
103
103
  }
104
104
  }
105
105
 
106
+ /**
107
+ * @internal Not exported from `index.ts`.
108
+ */
109
+ function encodeTableOptions(options) {
110
+ const trackPrevious = options.trackPrevious;
111
+ return {
112
+ local_only: options.localOnly,
113
+ insert_only: options.insertOnly,
114
+ include_old: trackPrevious && (trackPrevious.columns ?? true),
115
+ include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
116
+ include_metadata: options.trackMetadata,
117
+ ignore_empty_update: options.ignoreEmptyUpdates
118
+ };
119
+ }
120
+
106
121
  const DEFAULT_TABLE_OPTIONS = {
107
122
  indexes: [],
108
123
  insertOnly: false,
@@ -292,18 +307,12 @@ class Table {
292
307
  }
293
308
  }
294
309
  toJSON() {
295
- const trackPrevious = this.trackPrevious;
296
310
  return {
297
311
  name: this.name,
298
312
  view_name: this.viewName,
299
- local_only: this.localOnly,
300
- insert_only: this.insertOnly,
301
- include_old: trackPrevious && (trackPrevious.columns ?? true),
302
- include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
303
- include_metadata: this.trackMetadata,
304
- ignore_empty_update: this.ignoreEmptyUpdates,
305
313
  columns: this.columns.map((c) => c.toJSON()),
306
- indexes: this.indexes.map((e) => e.toJSON(this))
314
+ indexes: this.indexes.map((e) => e.toJSON(this)),
315
+ ...encodeTableOptions(this)
307
316
  };
308
317
  }
309
318
  }
@@ -7924,7 +7933,7 @@ function requireDist () {
7924
7933
 
7925
7934
  var distExports = requireDist();
7926
7935
 
7927
- var version = "1.47.0";
7936
+ var version = "1.48.0";
7928
7937
  var PACKAGE = {
7929
7938
  version: version};
7930
7939
 
@@ -11605,39 +11614,6 @@ class ConnectionClosedError extends Error {
11605
11614
  }
11606
11615
  }
11607
11616
 
11608
- /**
11609
- * Instructs PowerSync to sync data into a "raw" table.
11610
- *
11611
- * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
11612
- * using client-side table and column constraints.
11613
- *
11614
- * To collect local writes to raw tables with PowerSync, custom triggers are required. See
11615
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
11616
- * using raw tables.
11617
- *
11618
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
11619
- *
11620
- * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
11621
- * stability guarantees.
11622
- */
11623
- class RawTable {
11624
- /**
11625
- * The name of the table.
11626
- *
11627
- * This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
11628
- * another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
11629
- * appears in the source / backend database) are to be handled specially.
11630
- */
11631
- name;
11632
- put;
11633
- delete;
11634
- constructor(name, type) {
11635
- this.name = name;
11636
- this.put = type.put;
11637
- this.delete = type.delete;
11638
- }
11639
- }
11640
-
11641
11617
  /**
11642
11618
  * A schema is a collection of tables. It is used to define the structure of a database.
11643
11619
  */
@@ -11682,7 +11658,7 @@ class Schema {
11682
11658
  */
11683
11659
  withRawTables(tables) {
11684
11660
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
11685
- this.rawTables.push(new RawTable(name, rawTableDefinition));
11661
+ this.rawTables.push({ name, ...rawTableDefinition });
11686
11662
  }
11687
11663
  }
11688
11664
  validate() {
@@ -11693,8 +11669,30 @@ class Schema {
11693
11669
  toJSON() {
11694
11670
  return {
11695
11671
  tables: this.tables.map((t) => t.toJSON()),
11696
- raw_tables: this.rawTables
11672
+ raw_tables: this.rawTables.map(Schema.rawTableToJson)
11673
+ };
11674
+ }
11675
+ /**
11676
+ * Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
11677
+ *
11678
+ * The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
11679
+ * to define triggers for this table.
11680
+ */
11681
+ static rawTableToJson(table) {
11682
+ const serialized = {
11683
+ name: table.name,
11684
+ put: table.put,
11685
+ delete: table.delete,
11686
+ clear: table.clear
11697
11687
  };
11688
+ if ('schema' in table) {
11689
+ // We have schema options, those are flattened into the outer JSON object for the core extension.
11690
+ const schema = table.schema;
11691
+ serialized.table_name = schema.tableName ?? table.name;
11692
+ serialized.synced_columns = schema.syncedColumns;
11693
+ Object.assign(serialized, encodeTableOptions(table.schema));
11694
+ }
11695
+ return serialized;
11698
11696
  }
11699
11697
  }
11700
11698
 
@@ -11853,5 +11851,5 @@ const parseQuery = (query, parameters) => {
11853
11851
  return { sqlStatement, parameters: parameters };
11854
11852
  };
11855
11853
 
11856
- export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RawTable, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, mutexRunExclusive, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
11854
+ export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, mutexRunExclusive, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
11857
11855
  //# sourceMappingURL=bundle.node.mjs.map