@powersync/common 0.0.0-dev-20260216124709 → 0.0.0-dev-20260305092446
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 +48 -49
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +49 -49
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +48 -49
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +49 -49
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +130 -80
- package/lib/client/triggers/TriggerManager.d.ts +5 -0
- package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
- package/lib/client/triggers/TriggerManagerImpl.js +6 -4
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +61 -26
- package/lib/db/schema/RawTable.js +1 -32
- package/lib/db/schema/RawTable.js.map +1 -1
- package/lib/db/schema/Schema.d.ts +14 -7
- package/lib/db/schema/Schema.js +25 -3
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +13 -8
- package/lib/db/schema/Table.js +3 -8
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/db/schema/internal.d.ts +12 -0
- package/lib/db/schema/internal.js +15 -0
- package/lib/db/schema/internal.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +6 -0
- package/src/client/triggers/TriggerManagerImpl.ts +6 -3
- package/src/db/schema/RawTable.ts +66 -31
- package/src/db/schema/Schema.ts +27 -2
- package/src/db/schema/Table.ts +11 -11
- package/src/db/schema/internal.ts +17 -0
- package/src/index.ts +1 -1
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.
|
|
10460
|
+
var version = "1.47.0";
|
|
10452
10461
|
var PACKAGE = {
|
|
10453
10462
|
version: version};
|
|
10454
10463
|
|
|
@@ -12481,7 +12490,7 @@ class TriggerManagerImpl {
|
|
|
12481
12490
|
}
|
|
12482
12491
|
async createDiffTrigger(options) {
|
|
12483
12492
|
await this.db.waitForReady();
|
|
12484
|
-
const { source, destination, columns, when, hooks,
|
|
12493
|
+
const { source, destination, columns, when, hooks, persistDestination = false,
|
|
12485
12494
|
// Fall back to the provided default if not given on this level
|
|
12486
12495
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
12487
12496
|
const operations = Object.keys(when);
|
|
@@ -12536,11 +12545,13 @@ class TriggerManagerImpl {
|
|
|
12536
12545
|
* we need to ensure we can cleanup the created resources.
|
|
12537
12546
|
* We unfortunately cannot rely on transaction rollback.
|
|
12538
12547
|
*/
|
|
12539
|
-
const cleanup = async () => {
|
|
12548
|
+
const cleanup = async (force) => {
|
|
12540
12549
|
disposeWarningListener();
|
|
12541
12550
|
return this.db.writeLock(async (tx) => {
|
|
12542
12551
|
await this.removeTriggers(tx, triggerIds);
|
|
12543
|
-
|
|
12552
|
+
if (!persistDestination || force) {
|
|
12553
|
+
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
12554
|
+
}
|
|
12544
12555
|
await releaseStorageClaim?.();
|
|
12545
12556
|
});
|
|
12546
12557
|
};
|
|
@@ -12548,7 +12559,7 @@ class TriggerManagerImpl {
|
|
|
12548
12559
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
12549
12560
|
await hooks?.beforeCreate?.(tx);
|
|
12550
12561
|
await tx.execute(/* sql */ `
|
|
12551
|
-
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
12562
|
+
CREATE ${tableTriggerTypeClause} TABLE ${persistDestination ? 'IF NOT EXISTS ' : ''}${destination} (
|
|
12552
12563
|
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12553
12564
|
id TEXT,
|
|
12554
12565
|
operation TEXT,
|
|
@@ -14129,39 +14140,6 @@ class ConnectionClosedError extends Error {
|
|
|
14129
14140
|
}
|
|
14130
14141
|
}
|
|
14131
14142
|
|
|
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
14143
|
/**
|
|
14166
14144
|
* A schema is a collection of tables. It is used to define the structure of a database.
|
|
14167
14145
|
*/
|
|
@@ -14206,7 +14184,7 @@ class Schema {
|
|
|
14206
14184
|
*/
|
|
14207
14185
|
withRawTables(tables) {
|
|
14208
14186
|
for (const [name, rawTableDefinition] of Object.entries(tables)) {
|
|
14209
|
-
this.rawTables.push(
|
|
14187
|
+
this.rawTables.push({ name, ...rawTableDefinition });
|
|
14210
14188
|
}
|
|
14211
14189
|
}
|
|
14212
14190
|
validate() {
|
|
@@ -14217,8 +14195,30 @@ class Schema {
|
|
|
14217
14195
|
toJSON() {
|
|
14218
14196
|
return {
|
|
14219
14197
|
tables: this.tables.map((t) => t.toJSON()),
|
|
14220
|
-
raw_tables: this.rawTables
|
|
14198
|
+
raw_tables: this.rawTables.map(Schema.rawTableToJson)
|
|
14199
|
+
};
|
|
14200
|
+
}
|
|
14201
|
+
/**
|
|
14202
|
+
* Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
|
|
14203
|
+
*
|
|
14204
|
+
* The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
|
|
14205
|
+
* to define triggers for this table.
|
|
14206
|
+
*/
|
|
14207
|
+
static rawTableToJson(table) {
|
|
14208
|
+
const serialized = {
|
|
14209
|
+
name: table.name,
|
|
14210
|
+
put: table.put,
|
|
14211
|
+
delete: table.delete,
|
|
14212
|
+
clear: table.clear
|
|
14221
14213
|
};
|
|
14214
|
+
if ('schema' in table) {
|
|
14215
|
+
// We have schema options, those are flattened into the outer JSON object for the core extension.
|
|
14216
|
+
const schema = table.schema;
|
|
14217
|
+
serialized.table_name = schema.tableName ?? table.name;
|
|
14218
|
+
serialized.synced_columns = schema.syncedColumns;
|
|
14219
|
+
Object.assign(serialized, encodeTableOptions(table.schema));
|
|
14220
|
+
}
|
|
14221
|
+
return serialized;
|
|
14222
14222
|
}
|
|
14223
14223
|
}
|
|
14224
14224
|
|
|
@@ -14431,7 +14431,6 @@ exports.MEMORY_TRIGGER_CLAIM_MANAGER = MEMORY_TRIGGER_CLAIM_MANAGER;
|
|
|
14431
14431
|
exports.OnChangeQueryProcessor = OnChangeQueryProcessor;
|
|
14432
14432
|
exports.OpType = OpType;
|
|
14433
14433
|
exports.OplogEntry = OplogEntry;
|
|
14434
|
-
exports.RawTable = RawTable;
|
|
14435
14434
|
exports.Schema = Schema;
|
|
14436
14435
|
exports.SqliteBucketStorage = SqliteBucketStorage;
|
|
14437
14436
|
exports.SyncDataBatch = SyncDataBatch;
|