@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.
@@ -105,6 +105,21 @@ class Index {
105
105
  }
106
106
  }
107
107
 
108
+ /**
109
+ * @internal Not exported from `index.ts`.
110
+ */
111
+ function encodeTableOptions(options) {
112
+ const trackPrevious = options.trackPrevious;
113
+ return {
114
+ local_only: options.localOnly,
115
+ insert_only: options.insertOnly,
116
+ include_old: trackPrevious && (trackPrevious.columns ?? true),
117
+ include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
118
+ include_metadata: options.trackMetadata,
119
+ ignore_empty_update: options.ignoreEmptyUpdates
120
+ };
121
+ }
122
+
108
123
  const DEFAULT_TABLE_OPTIONS = {
109
124
  indexes: [],
110
125
  insertOnly: false,
@@ -294,18 +309,12 @@ class Table {
294
309
  }
295
310
  }
296
311
  toJSON() {
297
- const trackPrevious = this.trackPrevious;
298
312
  return {
299
313
  name: this.name,
300
314
  view_name: this.viewName,
301
- local_only: this.localOnly,
302
- insert_only: this.insertOnly,
303
- include_old: trackPrevious && (trackPrevious.columns ?? true),
304
- include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
305
- include_metadata: this.trackMetadata,
306
- ignore_empty_update: this.ignoreEmptyUpdates,
307
315
  columns: this.columns.map((c) => c.toJSON()),
308
- indexes: this.indexes.map((e) => e.toJSON(this))
316
+ indexes: this.indexes.map((e) => e.toJSON(this)),
317
+ ...encodeTableOptions(this)
309
318
  };
310
319
  }
311
320
  }
@@ -7926,7 +7935,7 @@ function requireDist () {
7926
7935
 
7927
7936
  var distExports = requireDist();
7928
7937
 
7929
- var version = "1.47.0";
7938
+ var version = "1.48.0";
7930
7939
  var PACKAGE = {
7931
7940
  version: version};
7932
7941
 
@@ -11607,39 +11616,6 @@ class ConnectionClosedError extends Error {
11607
11616
  }
11608
11617
  }
11609
11618
 
11610
- /**
11611
- * Instructs PowerSync to sync data into a "raw" table.
11612
- *
11613
- * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
11614
- * using client-side table and column constraints.
11615
- *
11616
- * To collect local writes to raw tables with PowerSync, custom triggers are required. See
11617
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
11618
- * using raw tables.
11619
- *
11620
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
11621
- *
11622
- * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
11623
- * stability guarantees.
11624
- */
11625
- class RawTable {
11626
- /**
11627
- * The name of the table.
11628
- *
11629
- * This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
11630
- * another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
11631
- * appears in the source / backend database) are to be handled specially.
11632
- */
11633
- name;
11634
- put;
11635
- delete;
11636
- constructor(name, type) {
11637
- this.name = name;
11638
- this.put = type.put;
11639
- this.delete = type.delete;
11640
- }
11641
- }
11642
-
11643
11619
  /**
11644
11620
  * A schema is a collection of tables. It is used to define the structure of a database.
11645
11621
  */
@@ -11684,7 +11660,7 @@ class Schema {
11684
11660
  */
11685
11661
  withRawTables(tables) {
11686
11662
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
11687
- this.rawTables.push(new RawTable(name, rawTableDefinition));
11663
+ this.rawTables.push({ name, ...rawTableDefinition });
11688
11664
  }
11689
11665
  }
11690
11666
  validate() {
@@ -11695,8 +11671,30 @@ class Schema {
11695
11671
  toJSON() {
11696
11672
  return {
11697
11673
  tables: this.tables.map((t) => t.toJSON()),
11698
- raw_tables: this.rawTables
11674
+ raw_tables: this.rawTables.map(Schema.rawTableToJson)
11675
+ };
11676
+ }
11677
+ /**
11678
+ * Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
11679
+ *
11680
+ * The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
11681
+ * to define triggers for this table.
11682
+ */
11683
+ static rawTableToJson(table) {
11684
+ const serialized = {
11685
+ name: table.name,
11686
+ put: table.put,
11687
+ delete: table.delete,
11688
+ clear: table.clear
11699
11689
  };
11690
+ if ('schema' in table) {
11691
+ // We have schema options, those are flattened into the outer JSON object for the core extension.
11692
+ const schema = table.schema;
11693
+ serialized.table_name = schema.tableName ?? table.name;
11694
+ serialized.synced_columns = schema.syncedColumns;
11695
+ Object.assign(serialized, encodeTableOptions(table.schema));
11696
+ }
11697
+ return serialized;
11700
11698
  }
11701
11699
  }
11702
11700
 
@@ -11909,7 +11907,6 @@ exports.MEMORY_TRIGGER_CLAIM_MANAGER = MEMORY_TRIGGER_CLAIM_MANAGER;
11909
11907
  exports.OnChangeQueryProcessor = OnChangeQueryProcessor;
11910
11908
  exports.OpType = OpType;
11911
11909
  exports.OplogEntry = OplogEntry;
11912
- exports.RawTable = RawTable;
11913
11910
  exports.Schema = Schema;
11914
11911
  exports.SqliteBucketStorage = SqliteBucketStorage;
11915
11912
  exports.SyncDataBatch = SyncDataBatch;