@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.
package/dist/bundle.cjs CHANGED
@@ -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
  }
@@ -10448,7 +10457,7 @@ function requireDist () {
10448
10457
 
10449
10458
  var distExports = requireDist();
10450
10459
 
10451
- var version = "1.47.0";
10460
+ var version = "1.48.0";
10452
10461
  var PACKAGE = {
10453
10462
  version: version};
10454
10463
 
@@ -14129,39 +14138,6 @@ class ConnectionClosedError extends Error {
14129
14138
  }
14130
14139
  }
14131
14140
 
14132
- /**
14133
- * Instructs PowerSync to sync data into a "raw" table.
14134
- *
14135
- * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
14136
- * using client-side table and column constraints.
14137
- *
14138
- * To collect local writes to raw tables with PowerSync, custom triggers are required. See
14139
- * {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
14140
- * using raw tables.
14141
- *
14142
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
14143
- *
14144
- * @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or
14145
- * stability guarantees.
14146
- */
14147
- class RawTable {
14148
- /**
14149
- * The name of the table.
14150
- *
14151
- * This does not have to match the actual table name in the schema - {@link put} and {@link delete} are free to use
14152
- * another table. Instead, this name is used by the sync client to recognize that operations on this table (as it
14153
- * appears in the source / backend database) are to be handled specially.
14154
- */
14155
- name;
14156
- put;
14157
- delete;
14158
- constructor(name, type) {
14159
- this.name = name;
14160
- this.put = type.put;
14161
- this.delete = type.delete;
14162
- }
14163
- }
14164
-
14165
14141
  /**
14166
14142
  * A schema is a collection of tables. It is used to define the structure of a database.
14167
14143
  */
@@ -14206,7 +14182,7 @@ class Schema {
14206
14182
  */
14207
14183
  withRawTables(tables) {
14208
14184
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
14209
- this.rawTables.push(new RawTable(name, rawTableDefinition));
14185
+ this.rawTables.push({ name, ...rawTableDefinition });
14210
14186
  }
14211
14187
  }
14212
14188
  validate() {
@@ -14217,8 +14193,30 @@ class Schema {
14217
14193
  toJSON() {
14218
14194
  return {
14219
14195
  tables: this.tables.map((t) => t.toJSON()),
14220
- raw_tables: this.rawTables
14196
+ raw_tables: this.rawTables.map(Schema.rawTableToJson)
14197
+ };
14198
+ }
14199
+ /**
14200
+ * Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
14201
+ *
14202
+ * The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
14203
+ * to define triggers for this table.
14204
+ */
14205
+ static rawTableToJson(table) {
14206
+ const serialized = {
14207
+ name: table.name,
14208
+ put: table.put,
14209
+ delete: table.delete,
14210
+ clear: table.clear
14221
14211
  };
14212
+ if ('schema' in table) {
14213
+ // We have schema options, those are flattened into the outer JSON object for the core extension.
14214
+ const schema = table.schema;
14215
+ serialized.table_name = schema.tableName ?? table.name;
14216
+ serialized.synced_columns = schema.syncedColumns;
14217
+ Object.assign(serialized, encodeTableOptions(table.schema));
14218
+ }
14219
+ return serialized;
14222
14220
  }
14223
14221
  }
14224
14222
 
@@ -14431,7 +14429,6 @@ exports.MEMORY_TRIGGER_CLAIM_MANAGER = MEMORY_TRIGGER_CLAIM_MANAGER;
14431
14429
  exports.OnChangeQueryProcessor = OnChangeQueryProcessor;
14432
14430
  exports.OpType = OpType;
14433
14431
  exports.OplogEntry = OplogEntry;
14434
- exports.RawTable = RawTable;
14435
14432
  exports.Schema = Schema;
14436
14433
  exports.SqliteBucketStorage = SqliteBucketStorage;
14437
14434
  exports.SyncDataBatch = SyncDataBatch;