Skip to content

Commit 8654b08

Browse files
committed
Rename options
1 parent 783dc56 commit 8654b08

File tree

4 files changed

+44
-37
lines changed

4 files changed

+44
-37
lines changed

packages/powersync_core/lib/src/crud.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CrudEntry {
7373
/// An optional metadata string attached to this entry at the time the write
7474
/// has been issued.
7575
///
76-
/// For tables where [Table.includeMetadata] is enabled, a hidden `_metadata`
76+
/// For tables where [Table.trackMetadata] is enabled, a hidden `_metadata`
7777
/// column is added to this table that can be used during updates to attach
7878
/// a hint to the update thas is preserved here.
7979
final String? metadata;
@@ -90,7 +90,7 @@ class CrudEntry {
9090
/// Old values before an update.
9191
///
9292
/// This is only tracked for tables for which this has been enabled by setting
93-
/// the [Table.includeOld].
93+
/// the [Table.trackPreviousValues].
9494
final Map<String, dynamic>? oldData;
9595

9696
CrudEntry(

packages/powersync_core/lib/src/schema.dart

+23-22
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Schema {
3131
///
3232
/// These options are enabled by passing them to a non-local [Table]
3333
/// constructor.
34-
final class IncludeOldOptions {
34+
final class TrackPreviousValuesOptions {
3535
/// A filter of column names for which updates should be tracked.
3636
///
3737
/// When set to a non-null value, columns not included in this list will not
@@ -42,7 +42,8 @@ final class IncludeOldOptions {
4242
/// instead of always including all old values.
4343
final bool onlyWhenChanged;
4444

45-
const IncludeOldOptions({this.columnFilter, this.onlyWhenChanged = false});
45+
const TrackPreviousValuesOptions(
46+
{this.columnFilter, this.onlyWhenChanged = false});
4647
}
4748

4849
/// A single table in the schema.
@@ -61,12 +62,12 @@ class Table {
6162
/// Whether to add a hidden `_metadata` column that will be enabled for
6263
/// updates to attach custom information about writes that will be reported
6364
/// through [CrudEntry.metadata].
64-
final bool includeMetadata;
65+
final bool trackMetadata;
6566

6667
/// Whether to track old values of columns for [CrudEntry.oldData].
6768
///
68-
/// See [IncludeOldOptions] for details.
69-
final IncludeOldOptions? includeOld;
69+
/// See [TrackPreviousValuesOptions] for details.
70+
final TrackPreviousValuesOptions? trackPreviousValues;
7071

7172
/// Whether the table only exists locally.
7273
final bool localOnly;
@@ -76,7 +77,7 @@ class Table {
7677

7778
/// Whether an `UPDATE` statement that doesn't change any values should be
7879
/// ignored when creating CRUD entries.
79-
final bool ignoreEmptyUpdate;
80+
final bool ignoreEmptyUpdates;
8081

8182
/// Override the name for the view
8283
final String? _viewNameOverride;
@@ -107,9 +108,9 @@ class Table {
107108
this.indexes = const [],
108109
String? viewName,
109110
this.localOnly = false,
110-
this.ignoreEmptyUpdate = false,
111-
this.includeMetadata = false,
112-
this.includeOld,
111+
this.ignoreEmptyUpdates = false,
112+
this.trackMetadata = false,
113+
this.trackPreviousValues,
113114
}) : insertOnly = false,
114115
_viewNameOverride = viewName;
115116

@@ -120,9 +121,9 @@ class Table {
120121
{this.indexes = const [], String? viewName})
121122
: localOnly = true,
122123
insertOnly = false,
123-
includeMetadata = false,
124-
includeOld = null,
125-
ignoreEmptyUpdate = false,
124+
trackMetadata = false,
125+
trackPreviousValues = null,
126+
ignoreEmptyUpdates = false,
126127
_viewNameOverride = viewName;
127128

128129
/// Create a table that only supports inserts.
@@ -137,9 +138,9 @@ class Table {
137138
this.name,
138139
this.columns, {
139140
String? viewName,
140-
this.ignoreEmptyUpdate = false,
141-
this.includeMetadata = false,
142-
this.includeOld,
141+
this.ignoreEmptyUpdates = false,
142+
this.trackMetadata = false,
143+
this.trackPreviousValues,
143144
}) : localOnly = false,
144145
insertOnly = true,
145146
indexes = const [],
@@ -172,11 +173,11 @@ class Table {
172173
"Invalid characters in view name: $_viewNameOverride");
173174
}
174175

175-
if (includeMetadata && localOnly) {
176+
if (trackMetadata && localOnly) {
176177
throw AssertionError("Local-only tables can't track metadata");
177178
}
178179

179-
if (includeOld != null && localOnly) {
180+
if (trackPreviousValues != null && localOnly) {
180181
throw AssertionError("Local-only tables can't track old values");
181182
}
182183

@@ -228,11 +229,11 @@ class Table {
228229
'insert_only': insertOnly,
229230
'columns': columns,
230231
'indexes': indexes.map((e) => e.toJson(this)).toList(growable: false),
231-
'ignore_empty_update': ignoreEmptyUpdate,
232-
'include_metadata': includeMetadata,
233-
if (includeOld case final includeOld?) ...{
234-
'include_old': includeOld.columnFilter ?? true,
235-
'include_old_only_when_changed': includeOld.onlyWhenChanged,
232+
'ignore_empty_update': ignoreEmptyUpdates,
233+
'include_metadata': trackMetadata,
234+
if (trackPreviousValues case final trackPreviousValues?) ...{
235+
'include_old': trackPreviousValues.columnFilter ?? true,
236+
'include_old_only_when_changed': trackPreviousValues.onlyWhenChanged,
236237
},
237238
};
238239
}

packages/powersync_core/test/crud_test.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void main() {
276276
Table(
277277
'lists',
278278
[Column.text('name')],
279-
includeMetadata: true,
279+
trackMetadata: true,
280280
)
281281
]));
282282

@@ -293,7 +293,7 @@ void main() {
293293
Table(
294294
'lists',
295295
[Column.text('name'), Column.text('content')],
296-
includeOld: IncludeOldOptions(),
296+
trackPreviousValues: TrackPreviousValuesOptions(),
297297
)
298298
]));
299299

@@ -312,7 +312,8 @@ void main() {
312312
Table(
313313
'lists',
314314
[Column.text('name'), Column.text('content')],
315-
includeOld: IncludeOldOptions(columnFilter: ['name']),
315+
trackPreviousValues:
316+
TrackPreviousValuesOptions(columnFilter: ['name']),
316317
)
317318
]));
318319

@@ -332,7 +333,8 @@ void main() {
332333
Table(
333334
'lists',
334335
[Column.text('name'), Column.text('content')],
335-
includeOld: IncludeOldOptions(onlyWhenChanged: true),
336+
trackPreviousValues:
337+
TrackPreviousValuesOptions(onlyWhenChanged: true),
336338
)
337339
]));
338340

@@ -351,7 +353,7 @@ void main() {
351353
Table(
352354
'lists',
353355
[Column.text('name')],
354-
ignoreEmptyUpdate: true,
356+
ignoreEmptyUpdates: true,
355357
)
356358
]));
357359

packages/powersync_core/test/schema_test.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,17 @@ void main() {
320320

321321
test('local-only with metadata', () {
322322
final table = Table('foo', [Column.text('bar')],
323-
localOnly: true, includeMetadata: true);
323+
localOnly: true, trackMetadata: true);
324324

325325
expect(
326326
table.validate,
327327
throwsA(isA<AssertionError>().having((e) => e.message, 'emssage',
328328
"Local-only tables can't track metadata")));
329329
});
330330

331-
test('local-only with includeOld', () {
331+
test('local-only with trackPreviousValues', () {
332332
final table = Table('foo', [Column.text('bar')],
333-
localOnly: true, includeOld: IncludeOldOptions());
333+
localOnly: true, trackPreviousValues: TrackPreviousValuesOptions());
334334

335335
expect(
336336
table.validate,
@@ -395,14 +395,15 @@ void main() {
395395
});
396396

397397
test('handles options', () {
398-
expect(Table('foo', [], includeMetadata: true).toJson(),
398+
expect(Table('foo', [], trackMetadata: true).toJson(),
399399
containsPair('include_metadata', isTrue));
400400

401-
expect(Table('foo', [], ignoreEmptyUpdate: true).toJson(),
401+
expect(Table('foo', [], ignoreEmptyUpdates: true).toJson(),
402402
containsPair('ignore_empty_update', isTrue));
403403

404404
expect(
405-
Table('foo', [], includeOld: IncludeOldOptions()).toJson(),
405+
Table('foo', [], trackPreviousValues: TrackPreviousValuesOptions())
406+
.toJson(),
406407
allOf(
407408
containsPair('include_old', isTrue),
408409
containsPair('include_old_only_when_changed', isFalse),
@@ -411,7 +412,8 @@ void main() {
411412

412413
expect(
413414
Table('foo', [],
414-
includeOld: IncludeOldOptions(columnFilter: ['foo', 'bar']))
415+
trackPreviousValues:
416+
TrackPreviousValuesOptions(columnFilter: ['foo', 'bar']))
415417
.toJson(),
416418
allOf(
417419
containsPair('include_old', ['foo', 'bar']),
@@ -420,7 +422,9 @@ void main() {
420422
);
421423

422424
expect(
423-
Table('foo', [], includeOld: IncludeOldOptions(onlyWhenChanged: true))
425+
Table('foo', [],
426+
trackPreviousValues:
427+
TrackPreviousValuesOptions(onlyWhenChanged: true))
424428
.toJson(),
425429
allOf(
426430
containsPair('include_old', isTrue),

0 commit comments

Comments
 (0)