Skip to content

Commit 32b2413

Browse files
committed
Apply new naming scheme
1 parent 85b39bd commit 32b2413

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

.changeset/giant-ladybugs-dress.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'@powersync/common': minor
33
---
44

5-
- Add `includeOld` option on `Table` which sets `CrudEntry.oldData` to previous values on updates.
6-
- Add `includeMetadata` option on `Table` which adds a `_metadata` column that can be used for updates.
5+
- Add `trackOld` option on `Table` which sets `CrudEntry.oldData` to previous values on updates.
6+
- Add `trackMetadata` option on `Table` which adds a `_metadata` column that can be used for updates.
77
The configured metadata is available through `CrudEntry.metadata`.
8-
- Add `ignoreEmptyUpdate` option which skips creating CRUD entries for updates that don't change any values.
8+
- Add `ignoreEmptyUpdates` option which skips creating CRUD entries for updates that don't change any values.

packages/common/src/client/sync/bucket/CrudEntry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class CrudEntry {
6666
opData?: Record<string, any>;
6767

6868
/**
69-
* For tables where the `includeOld` option has been enabled, this tracks previous values for
69+
* For tables where the `trackOld` option has been enabled, this tracks previous values for
7070
* `UPDATE` and `DELETE` statements.
7171
*/
7272
oldData?: Record<string, any>;
@@ -83,7 +83,7 @@ export class CrudEntry {
8383
/**
8484
* Client-side metadata attached with this write.
8585
*
86-
* This field is only available when the `includeMetadata` option was set to `true` when creating a table
86+
* This field is only available when the `trackMetadata` option was set to `true` when creating a table
8787
* and the insert or update statement set the `_metadata` column.
8888
*/
8989
metadata?: string;

packages/common/src/db/schema/Table.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ interface SharedTableOptions {
1414
localOnly?: boolean;
1515
insertOnly?: boolean;
1616
viewName?: string;
17-
includeOld?: boolean | IncludeOldOptions;
18-
includeMetadata?: boolean;
19-
ignoreEmptyUpdate?: boolean;
17+
trackOld?: boolean | TrackOldOptions;
18+
trackMetadata?: boolean;
19+
ignoreEmptyUpdates?: boolean;
2020
}
2121

2222
/** Whether to include old columns when PowerSync tracks local changes.
2323
*
2424
* Including old columns may be helpful for some backend connector implementations, which is
2525
* why it can be enabled on per-table or per-columm basis.
2626
*/
27-
export interface IncludeOldOptions {
27+
export interface TrackOldOptions {
2828
/** When defined, a list of column names for which old values should be tracked. */
2929
columns?: string[];
3030
/** When enabled, only include values that have actually been changed by an update. */
@@ -56,9 +56,9 @@ export const DEFAULT_TABLE_OPTIONS = {
5656
indexes: [],
5757
insertOnly: false,
5858
localOnly: false,
59-
includeOld: false,
60-
includeMetadata: false,
61-
ignoreEmptyUpdate: false
59+
trackOld: false,
60+
trackMetadata: false,
61+
ignoreEmptyUpdates: false
6262
};
6363

6464
export const InvalidSQLCharacters = /["'%,.#\s[\]]/;
@@ -200,9 +200,9 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
200200
viewName: options?.viewName,
201201
insertOnly: options?.insertOnly,
202202
localOnly: options?.localOnly,
203-
includeOld: options?.includeOld,
204-
includeMetadata: options?.includeMetadata,
205-
ignoreEmptyUpdate: options?.ignoreEmptyUpdate
203+
trackOld: options?.trackOld,
204+
trackMetadata: options?.trackMetadata,
205+
ignoreEmptyUpdates: options?.ignoreEmptyUpdates
206206
};
207207
this.applyDefaultOptions();
208208

@@ -212,9 +212,9 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
212212
private applyDefaultOptions() {
213213
this.options.insertOnly ??= DEFAULT_TABLE_OPTIONS.insertOnly;
214214
this.options.localOnly ??= DEFAULT_TABLE_OPTIONS.localOnly;
215-
this.options.includeOld ??= DEFAULT_TABLE_OPTIONS.includeOld;
216-
this.options.includeMetadata ??= DEFAULT_TABLE_OPTIONS.includeMetadata;
217-
this.options.ignoreEmptyUpdate ??= DEFAULT_TABLE_OPTIONS.ignoreEmptyUpdate;
215+
this.options.trackOld ??= DEFAULT_TABLE_OPTIONS.trackOld;
216+
this.options.trackMetadata ??= DEFAULT_TABLE_OPTIONS.trackMetadata;
217+
this.options.ignoreEmptyUpdates ??= DEFAULT_TABLE_OPTIONS.ignoreEmptyUpdates;
218218
}
219219

220220
get name() {
@@ -255,16 +255,16 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
255255
return this.options.insertOnly!;
256256
}
257257

258-
get includeOld() {
259-
return this.options.includeOld!;
258+
get trackOld() {
259+
return this.options.trackOld!;
260260
}
261261

262-
get includeMetadata() {
263-
return this.options.includeMetadata!;
262+
get trackMetadata() {
263+
return this.options.trackMetadata!;
264264
}
265265

266-
get ignoreEmptyUpdate() {
267-
return this.options.ignoreEmptyUpdate!;
266+
get ignoreEmptyUpdates() {
267+
return this.options.ignoreEmptyUpdates!;
268268
}
269269

270270
get internalName() {
@@ -298,10 +298,10 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
298298
throw new Error(`Table has too many columns. The maximum number of columns is ${MAX_AMOUNT_OF_COLUMNS}.`);
299299
}
300300

301-
if (this.includeMetadata && this.localOnly) {
301+
if (this.trackMetadata && this.localOnly) {
302302
throw new Error(`Can't include metadata for local-only tables.`);
303303
}
304-
if (this.includeOld != false && this.localOnly) {
304+
if (this.trackOld != false && this.localOnly) {
305305
throw new Error(`Can't include old values for local-only tables.`);
306306
}
307307

@@ -341,17 +341,17 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
341341
}
342342

343343
toJSON() {
344-
const includeOld = this.includeOld;
344+
const trackOld = this.trackOld;
345345

346346
return {
347347
name: this.name,
348348
view_name: this.viewName,
349349
local_only: this.localOnly,
350350
insert_only: this.insertOnly,
351-
include_old: includeOld && ((includeOld as any).columns ?? true),
352-
include_old_only_when_changed: typeof includeOld == 'object' && includeOld.onlyWhenChanged == true,
353-
include_metadata: this.includeMetadata,
354-
ignore_empty_update: this.ignoreEmptyUpdate,
351+
include_old: trackOld && ((trackOld as any).columns ?? true),
352+
include_old_only_when_changed: typeof trackOld == 'object' && trackOld.onlyWhenChanged == true,
353+
include_metadata: this.trackMetadata,
354+
ignore_empty_update: this.ignoreEmptyUpdates,
355355
columns: this.columns.map((c) => c.toJSON()),
356356
indexes: this.indexes.map((e) => e.toJSON(this))
357357
};

packages/common/tests/db/schema/Table.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ describe('Table', () => {
136136
}
137137

138138
expect(createTable({}).toJSON().include_metadata).toBe(false);
139-
expect(createTable({ includeMetadata: true }).toJSON().include_metadata).toBe(true);
139+
expect(createTable({ trackMetadata: true }).toJSON().include_metadata).toBe(true);
140140

141-
expect(createTable({ includeOld: true }).toJSON().include_old).toBe(true);
142-
expect(createTable({ includeOld: true }).toJSON().include_old_only_when_changed).toBe(false);
141+
expect(createTable({ trackOld: true }).toJSON().include_old).toBe(true);
142+
expect(createTable({ trackOld: true }).toJSON().include_old_only_when_changed).toBe(false);
143143

144-
const complexIncldueOld = createTable({ includeOld: {
144+
const complexIncldueOld = createTable({ trackOld: {
145145
columns: ['foo', 'bar'],
146146
onlyWhenChanged: true,
147147
} });
148148
expect(complexIncldueOld.toJSON().include_old).toStrictEqual(['foo', 'bar']);
149149
expect(complexIncldueOld.toJSON().include_old_only_when_changed).toBe(true);
150150

151-
expect(createTable({ ignoreEmptyUpdate: true }).toJSON().ignore_empty_update).toBe(true);
151+
expect(createTable({ ignoreEmptyUpdates: true }).toJSON().ignore_empty_update).toBe(true);
152152
});
153153

154154
describe('validate', () => {
@@ -205,7 +205,7 @@ describe('Table', () => {
205205
{
206206
name: column.text
207207
},
208-
{ localOnly: true, includeMetadata: true }
208+
{ localOnly: true, trackMetadata: true }
209209
).validate()
210210
).toThrowError("Can't include metadata for local-only tables.");
211211
});
@@ -216,7 +216,7 @@ describe('Table', () => {
216216
{
217217
name: column.text
218218
},
219-
{ localOnly: true, includeOld: true }
219+
{ localOnly: true, trackOld: true }
220220
).validate()
221221
).toThrowError("Can't include old values for local-only tables.");
222222

@@ -225,7 +225,7 @@ describe('Table', () => {
225225
{
226226
name: column.text
227227
},
228-
{ localOnly: true, includeOld: { onlyWhenChanged: false } }
228+
{ localOnly: true, trackOld: { onlyWhenChanged: false } }
229229
).validate()
230230
).toThrowError("Can't include old values for local-only tables.");
231231
});

packages/node/tests/crud.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ databaseTest('include metadata', async ({ database }) => {
99
{
1010
name: column.text
1111
},
12-
{ includeMetadata: true }
12+
{ trackMetadata: true }
1313
)
1414
});
1515
await database.updateSchema(schema);
@@ -26,7 +26,7 @@ databaseTest('include old values', async ({ database }) => {
2626
{
2727
name: column.text
2828
},
29-
{ includeOld: true }
29+
{ trackOld: true }
3030
)
3131
});
3232
await database.updateSchema(schema);
@@ -46,7 +46,7 @@ databaseTest('include old values with column filter', async ({ database }) => {
4646
name: column.text,
4747
content: column.text
4848
},
49-
{ includeOld: { columns: ['name'] } }
49+
{ trackOld: { columns: ['name'] } }
5050
)
5151
});
5252
await database.updateSchema(schema);
@@ -66,7 +66,7 @@ databaseTest('include old values when changed', async ({ database }) => {
6666
name: column.text,
6767
content: column.text
6868
},
69-
{ includeOld: { onlyWhenChanged: true } }
69+
{ trackOld: { onlyWhenChanged: true } }
7070
)
7171
});
7272
await database.updateSchema(schema);
@@ -85,7 +85,7 @@ databaseTest('ignore empty update', async ({ database }) => {
8585
{
8686
name: column.text
8787
},
88-
{ ignoreEmptyUpdate: true }
88+
{ ignoreEmptyUpdates: true }
8989
)
9090
});
9191
await database.updateSchema(schema);

0 commit comments

Comments
 (0)