@powersync/common 0.0.0-dev-20260226160529 → 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 -53
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +49 -53
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +48 -53
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +49 -53
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +130 -80
- package/lib/client/AbstractPowerSyncDatabase.js +1 -5
- package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
- 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/AbstractPowerSyncDatabase.ts +1 -6
- 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/src/db/schema/Schema.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { encodeTableOptions } from './internal.js';
|
|
1
2
|
import { RawTable, RawTableType } from './RawTable.js';
|
|
2
3
|
import { RowType, Table } from './Table.js';
|
|
3
4
|
|
|
@@ -57,7 +58,7 @@ export class Schema<S extends SchemaType = SchemaType> {
|
|
|
57
58
|
*/
|
|
58
59
|
withRawTables(tables: Record<string, RawTableType>) {
|
|
59
60
|
for (const [name, rawTableDefinition] of Object.entries(tables)) {
|
|
60
|
-
this.rawTables.push(
|
|
61
|
+
this.rawTables.push({ name, ...rawTableDefinition });
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -70,7 +71,31 @@ export class Schema<S extends SchemaType = SchemaType> {
|
|
|
70
71
|
toJSON() {
|
|
71
72
|
return {
|
|
72
73
|
tables: this.tables.map((t) => t.toJSON()),
|
|
73
|
-
raw_tables: this.rawTables
|
|
74
|
+
raw_tables: this.rawTables.map(Schema.rawTableToJson)
|
|
74
75
|
};
|
|
75
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.
|
|
80
|
+
*
|
|
81
|
+
* The output of this can be passed through `JSON.serialize` and then used in `powersync_create_raw_table_crud_trigger`
|
|
82
|
+
* to define triggers for this table.
|
|
83
|
+
*/
|
|
84
|
+
static rawTableToJson(table: RawTable): unknown {
|
|
85
|
+
const serialized: any = {
|
|
86
|
+
name: table.name,
|
|
87
|
+
put: table.put,
|
|
88
|
+
delete: table.delete,
|
|
89
|
+
clear: table.clear
|
|
90
|
+
};
|
|
91
|
+
if ('schema' in table) {
|
|
92
|
+
// We have schema options, those are flattened into the outer JSON object for the core extension.
|
|
93
|
+
const schema = table.schema;
|
|
94
|
+
serialized.table_name = schema.tableName ?? table.name;
|
|
95
|
+
serialized.synced_columns = schema.syncedColumns;
|
|
96
|
+
Object.assign(serialized, encodeTableOptions(table.schema));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return serialized;
|
|
100
|
+
}
|
|
76
101
|
}
|
package/src/db/schema/Table.ts
CHANGED
|
@@ -8,17 +8,24 @@ import {
|
|
|
8
8
|
} from './Column.js';
|
|
9
9
|
import { Index } from './Index.js';
|
|
10
10
|
import { IndexedColumn } from './IndexedColumn.js';
|
|
11
|
+
import { encodeTableOptions } from './internal.js';
|
|
11
12
|
import { TableV2 } from './TableV2.js';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Options that apply both to JSON-based tables and raw tables.
|
|
16
|
+
*/
|
|
17
|
+
export interface TableOrRawTableOptions {
|
|
14
18
|
localOnly?: boolean;
|
|
15
19
|
insertOnly?: boolean;
|
|
16
|
-
viewName?: string;
|
|
17
20
|
trackPrevious?: boolean | TrackPreviousOptions;
|
|
18
21
|
trackMetadata?: boolean;
|
|
19
22
|
ignoreEmptyUpdates?: boolean;
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
interface SharedTableOptions extends TableOrRawTableOptions {
|
|
26
|
+
viewName?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
/** Whether to include previous column values when PowerSync tracks local changes.
|
|
23
30
|
*
|
|
24
31
|
* Including old values may be helpful for some backend connector implementations, which is
|
|
@@ -341,19 +348,12 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
|
|
|
341
348
|
}
|
|
342
349
|
|
|
343
350
|
toJSON() {
|
|
344
|
-
const trackPrevious = this.trackPrevious;
|
|
345
|
-
|
|
346
351
|
return {
|
|
347
352
|
name: this.name,
|
|
348
353
|
view_name: this.viewName,
|
|
349
|
-
local_only: this.localOnly,
|
|
350
|
-
insert_only: this.insertOnly,
|
|
351
|
-
include_old: trackPrevious && ((trackPrevious as any).columns ?? true),
|
|
352
|
-
include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
|
|
353
|
-
include_metadata: this.trackMetadata,
|
|
354
|
-
ignore_empty_update: this.ignoreEmptyUpdates,
|
|
355
354
|
columns: this.columns.map((c) => c.toJSON()),
|
|
356
|
-
indexes: this.indexes.map((e) => e.toJSON(this))
|
|
355
|
+
indexes: this.indexes.map((e) => e.toJSON(this)),
|
|
356
|
+
...encodeTableOptions(this)
|
|
357
357
|
};
|
|
358
358
|
}
|
|
359
359
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TableOrRawTableOptions } from './Table.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal Not exported from `index.ts`.
|
|
5
|
+
*/
|
|
6
|
+
export function encodeTableOptions(options: TableOrRawTableOptions) {
|
|
7
|
+
const trackPrevious = options.trackPrevious;
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
local_only: options.localOnly,
|
|
11
|
+
insert_only: options.insertOnly,
|
|
12
|
+
include_old: trackPrevious && ((trackPrevious as any).columns ?? true),
|
|
13
|
+
include_old_only_when_changed: typeof trackPrevious == 'object' && trackPrevious.onlyWhenChanged == true,
|
|
14
|
+
include_metadata: options.trackMetadata,
|
|
15
|
+
ignore_empty_update: options.ignoreEmptyUpdates
|
|
16
|
+
};
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export * from './db/DBAdapter.js';
|
|
|
39
39
|
export * from './db/schema/Column.js';
|
|
40
40
|
export * from './db/schema/Index.js';
|
|
41
41
|
export * from './db/schema/IndexedColumn.js';
|
|
42
|
-
export
|
|
42
|
+
export { RawTableType, PendingStatementParameter, PendingStatement } from './db/schema/RawTable.js';
|
|
43
43
|
export * from './db/schema/Schema.js';
|
|
44
44
|
export * from './db/schema/Table.js';
|
|
45
45
|
export * from './db/schema/TableV2.js';
|