@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.
Files changed (39) hide show
  1. package/dist/bundle.cjs +48 -53
  2. package/dist/bundle.cjs.map +1 -1
  3. package/dist/bundle.mjs +49 -53
  4. package/dist/bundle.mjs.map +1 -1
  5. package/dist/bundle.node.cjs +48 -53
  6. package/dist/bundle.node.cjs.map +1 -1
  7. package/dist/bundle.node.mjs +49 -53
  8. package/dist/bundle.node.mjs.map +1 -1
  9. package/dist/index.d.cts +130 -80
  10. package/lib/client/AbstractPowerSyncDatabase.js +1 -5
  11. package/lib/client/AbstractPowerSyncDatabase.js.map +1 -1
  12. package/lib/client/triggers/TriggerManager.d.ts +5 -0
  13. package/lib/client/triggers/TriggerManagerImpl.d.ts +1 -1
  14. package/lib/client/triggers/TriggerManagerImpl.js +6 -4
  15. package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
  16. package/lib/db/schema/RawTable.d.ts +61 -26
  17. package/lib/db/schema/RawTable.js +1 -32
  18. package/lib/db/schema/RawTable.js.map +1 -1
  19. package/lib/db/schema/Schema.d.ts +14 -7
  20. package/lib/db/schema/Schema.js +25 -3
  21. package/lib/db/schema/Schema.js.map +1 -1
  22. package/lib/db/schema/Table.d.ts +13 -8
  23. package/lib/db/schema/Table.js +3 -8
  24. package/lib/db/schema/Table.js.map +1 -1
  25. package/lib/db/schema/internal.d.ts +12 -0
  26. package/lib/db/schema/internal.js +15 -0
  27. package/lib/db/schema/internal.js.map +1 -0
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +0 -1
  30. package/lib/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/client/AbstractPowerSyncDatabase.ts +1 -6
  33. package/src/client/triggers/TriggerManager.ts +6 -0
  34. package/src/client/triggers/TriggerManagerImpl.ts +6 -3
  35. package/src/db/schema/RawTable.ts +66 -31
  36. package/src/db/schema/Schema.ts +27 -2
  37. package/src/db/schema/Table.ts +11 -11
  38. package/src/db/schema/internal.ts +17 -0
  39. package/src/index.ts +1 -1
@@ -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(new RawTable(name, rawTableDefinition));
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
  }
@@ -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
- interface SharedTableOptions {
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 * from './db/schema/RawTable.js';
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';