Skip to content

Commit 61d49ef

Browse files
committed
Rename to CustomSqliteValue
1 parent fe4cdb3 commit 61d49ef

File tree

10 files changed

+29
-29
lines changed

10 files changed

+29
-29
lines changed

modules/module-mongodb/src/replication/MongoRelation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mongo } from '@powersync/lib-service-mongodb';
22
import { storage } from '@powersync/service-core';
33
import { JSONBig, JsonContainer } from '@powersync/service-jsonbig';
44
import {
5-
CustomSqliteType,
5+
CustomSqliteValue,
66
SqliteInputRow,
77
SqliteInputValue,
88
SqliteRow,
@@ -80,7 +80,7 @@ export function toMongoSyncRulesValue(data: any): SqliteInputValue {
8080
} else if (data instanceof RegExp) {
8181
return JSON.stringify({ pattern: data.source, options: data.flags });
8282
} else if (Array.isArray(data)) {
83-
return CustomSqliteType.wrapArray(data.map((element) => filterJsonData(element)));
83+
return CustomSqliteValue.wrapArray(data.map((element) => filterJsonData(element)));
8484
} else if (data instanceof Uint8Array) {
8585
return data;
8686
} else if (data instanceof JsonContainer) {
@@ -141,7 +141,7 @@ function filterJsonData(data: any, depth = 0): any {
141141
} else if (data instanceof RegExp) {
142142
return { pattern: data.source, options: data.flags };
143143
} else if (Array.isArray(data)) {
144-
return CustomSqliteType.wrapArray(data.map((element) => filterJsonData(element, depth + 1)));
144+
return CustomSqliteValue.wrapArray(data.map((element) => filterJsonData(element, depth + 1)));
145145
} else if (ArrayBuffer.isView(data)) {
146146
return undefined;
147147
} else if (data instanceof JsonContainer) {

modules/module-mongodb/test/src/mongo_test.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mongo } from '@powersync/lib-service-mongodb';
2-
import { CustomSqliteType, SqliteInputRow, SqliteRow, SqlSyncRules, TimeValue } from '@powersync/service-sync-rules';
2+
import { CustomSqliteValue, SqliteInputRow, SqliteRow, SqlSyncRules, TimeValue } from '@powersync/service-sync-rules';
33
import { describe, expect, test } from 'vitest';
44

55
import { MongoRouteAPIAdapter } from '@module/api/MongoRouteAPIAdapter.js';
@@ -211,7 +211,7 @@ describe('mongo data types', () => {
211211

212212
expect(transformed[2]).toMatchObject({
213213
_id: 3n,
214-
date: CustomSqliteType.wrapArray([new TimeValue('2023-03-06 13:47:00.000Z', '2023-03-06T13:47:00.000Z')])
214+
date: CustomSqliteValue.wrapArray([new TimeValue('2023-03-06 13:47:00.000Z', '2023-03-06T13:47:00.000Z')])
215215
});
216216

217217
expect(transformed[3]).toMatchObject({

modules/module-postgres/test/src/pg_test.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { constructAfterRecord } from '@module/utils/pgwire_utils.js';
22
import * as pgwire from '@powersync/service-jpgwire';
3-
import { CustomSqliteType, SqliteInputRow, SqliteRow, TimeValue } from '@powersync/service-sync-rules';
3+
import { CustomSqliteValue, SqliteInputRow, SqliteRow, TimeValue } from '@powersync/service-sync-rules';
44
import { describe, expect, test } from 'vitest';
55
import { clearTestDb, connectPgPool, connectPgWire, TEST_URI } from './util.js';
66
import { WalStream } from '@module/replication/WalStream.js';
@@ -235,8 +235,8 @@ VALUES(10, ARRAY['null']::TEXT[]);
235235
id: 3n,
236236
date: `["2023-03-06"]`,
237237
time: `["15:47:00"]`,
238-
timestamp: CustomSqliteType.wrapArray([new TimeValue('2023-03-06 15:47:00', '2023-03-06T15:47:00')]),
239-
timestamptz: CustomSqliteType.wrapArray([
238+
timestamp: CustomSqliteValue.wrapArray([new TimeValue('2023-03-06 15:47:00', '2023-03-06T15:47:00')]),
239+
timestamptz: CustomSqliteValue.wrapArray([
240240
new TimeValue('2023-03-06 13:47:00Z', '2023-03-06T13:47:00Z'),
241241
new TimeValue('2023-03-06 13:47:00.12345Z', '2023-03-06T13:47:00.12345Z')
242242
])

packages/sync-rules/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export { SyncStream } from './streams/stream.js';
2222
export { syncStreamFromSql } from './streams/from_sql.js';
2323
export * from './TablePattern.js';
2424
export * from './types.js';
25-
export * from './types/custom_sqlite_type.js';
25+
export * from './types/custom_sqlite_value.js';
2626
export * from './types/time.js';
2727
export * from './utils.js';

packages/sync-rules/src/sql_functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { jsonValueToSqlite } from './utils.js';
88
import wkx from '@syncpoint/wkx';
99
import { ExpressionType, SqliteType, SqliteValueType, TYPE_INTEGER } from './ExpressionType.js';
1010
import * as uuid from 'uuid';
11-
import { CustomSqliteType } from './types/custom_sqlite_type.js';
11+
import { CustomSqliteValue } from './types/custom_sqlite_value.js';
1212

1313
export const BASIC_OPERATORS = new Set<string>([
1414
'=',
@@ -647,7 +647,7 @@ export function sqliteTypeOf(arg: SqliteInputValue): SqliteValueType {
647647
return 'real';
648648
} else if (arg instanceof Uint8Array) {
649649
return 'blob';
650-
} else if (arg instanceof CustomSqliteType) {
650+
} else if (arg instanceof CustomSqliteValue) {
651651
return arg.sqliteType;
652652
} else {
653653
// Should not happen

packages/sync-rules/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { toSyncRulesParameters } from './utils.js';
77
import { BucketPriority } from './BucketDescription.js';
88
import { ParameterLookup } from './BucketParameterQuerier.js';
99
import { TimeValue } from './types/time.js';
10-
import { CustomSqliteType } from './types/custom_sqlite_type.js';
10+
import { CustomSqliteValue } from './types/custom_sqlite_value.js';
1111

1212
export interface SyncRules {
1313
evaluateRow(options: EvaluateRowOptions): EvaluationResult[];
@@ -192,7 +192,7 @@ export type SqliteValue = number | string | null | bigint | Uint8Array;
192192
* A value that is either supported by SQLite natively, or one that can be lowered into a SQLite-value given additional
193193
* context.
194194
*/
195-
export type SqliteInputValue = SqliteValue | CustomSqliteType;
195+
export type SqliteInputValue = SqliteValue | CustomSqliteValue;
196196

197197
/**
198198
* A set of values that are both SQLite and JSON-compatible.
@@ -225,7 +225,7 @@ export type DatabaseInputValue =
225225
| boolean
226226
| DatabaseInputValue[]
227227
| JsonContainer
228-
| CustomSqliteType
228+
| CustomSqliteValue
229229
| { [key: string]: DatabaseInputValue };
230230

231231
/**

packages/sync-rules/src/types/custom_sqlite_type.ts renamed to packages/sync-rules/src/types/custom_sqlite_value.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { SqliteValueType } from '../ExpressionType.js';
88
*
99
* This is used to conditionally render some values in different formats depending on compatibility options. For
1010
* instance, old versions of the sync service used to [encode timestamp values incorrectly](https://github.com/powersync-ja/powersync-service/issues/286).
11-
* To fix this without breaking backwards-compatibility, we now represent timestamp values as a {@link CustomSqliteType}
11+
* To fix this without breaking backwards-compatibility, we now represent timestamp values as a {@link CustomSqliteValue}
1212
* subtype where `toSqliteValue` returns the old or the new format depending on options.
1313
*
14-
* Instances of {@link CustomSqliteType} are always temporary structures that aren't persisted. They are created by the
14+
* Instances of {@link CustomSqliteValue} are always temporary structures that aren't persisted. They are created by the
1515
* replicator implementations, the sync rule implementation will invoke {@link toSqliteValue} to ensure that an
1616
* {@link EvaluatedRow} only consists of proper SQLite values.
1717
*/
18-
export abstract class CustomSqliteType {
18+
export abstract class CustomSqliteValue {
1919
/**
2020
* Renders this custom value into a {@link SqliteValue}.
2121
*
@@ -26,7 +26,7 @@ export abstract class CustomSqliteType {
2626
abstract get sqliteType(): SqliteValueType;
2727

2828
static wrapArray(elements: DatabaseInputValue[]): SqliteInputValue {
29-
const hasCustomValue = elements.some((v) => v instanceof CustomSqliteType);
29+
const hasCustomValue = elements.some((v) => v instanceof CustomSqliteValue);
3030
if (hasCustomValue) {
3131
// We need access to the compatibility context before encoding contents as JSON.
3232
return new CustomArray(elements);
@@ -37,7 +37,7 @@ export abstract class CustomSqliteType {
3737
}
3838
}
3939

40-
class CustomArray extends CustomSqliteType {
40+
class CustomArray extends CustomSqliteValue {
4141
constructor(private readonly elements: DatabaseInputValue[]) {
4242
super();
4343
}
@@ -49,7 +49,7 @@ class CustomArray extends CustomSqliteType {
4949
toSqliteValue(context: CompatibilityContext): SqliteValue {
5050
return JSONBig.stringify(
5151
this.elements.map((element) => {
52-
return element instanceof CustomSqliteType ? element.toSqliteValue(context) : element;
52+
return element instanceof CustomSqliteValue ? element.toSqliteValue(context) : element;
5353
})
5454
);
5555
}

packages/sync-rules/src/types/time.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SqliteValueType } from '../ExpressionType.js';
22
import { CompatibilityContext, Quirk } from '../quirks.js';
3-
import { CustomSqliteType } from './custom_sqlite_type.js';
3+
import { CustomSqliteValue } from './custom_sqlite_value.js';
44

55
/**
66
* In old versions of the sync service, timestamp values were formatted with a space between the date and time
@@ -9,7 +9,7 @@ import { CustomSqliteType } from './custom_sqlite_type.js';
99
* This is not ISO 6801 compatible, but changing it would be breaking existing users. So, this option is opt-in and
1010
* disabled by default until a major upgrade.
1111
*/
12-
export class TimeValue extends CustomSqliteType {
12+
export class TimeValue extends CustomSqliteValue {
1313
// YYYY-MM-DD hh:mm:ss.sss / YYYY-MM-DD hh:mm:ss.sssZ
1414
readonly legacyRepresentation: string;
1515
// YYYY-MM-DDThh:mm:ss.sss / YYYY-MM-DDThh:mm:ss.sssZ

packages/sync-rules/src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SqliteValue
1313
} from './types.js';
1414
import { SyncRuleProcessingError as SyncRulesProcessingError } from './errors.js';
15-
import { CustomSqliteType } from './types/custom_sqlite_type.js';
15+
import { CustomSqliteValue } from './types/custom_sqlite_value.js';
1616
import { CompatibilityContext } from './quirks.js';
1717

1818
export function isSelectStatement(q: Statement): q is SelectFromStatement {
@@ -88,7 +88,7 @@ function filterJsonData(data: any, depth = 0): any {
8888
} else if (typeof data == 'bigint') {
8989
return data;
9090
} else if (Array.isArray(data)) {
91-
return CustomSqliteType.wrapArray(data.map((element) => filterJsonData(element, depth + 1)));
91+
return CustomSqliteValue.wrapArray(data.map((element) => filterJsonData(element, depth + 1)));
9292
} else if (ArrayBuffer.isView(data)) {
9393
return undefined;
9494
} else if (data instanceof JsonContainer) {
@@ -158,8 +158,8 @@ export function toSyncRulesValue(
158158
} else if (typeof data == 'boolean') {
159159
return data ? SQLITE_TRUE : SQLITE_FALSE;
160160
} else if (Array.isArray(data)) {
161-
return CustomSqliteType.wrapArray(data.map(filterJsonData));
162-
} else if (data instanceof Uint8Array || data instanceof CustomSqliteType) {
161+
return CustomSqliteValue.wrapArray(data.map(filterJsonData));
162+
} else if (data instanceof Uint8Array || data instanceof CustomSqliteValue) {
163163
return data;
164164
} else if (data instanceof JsonContainer) {
165165
return data.toString();
@@ -175,7 +175,7 @@ export function toSyncRulesValue(
175175
}
176176

177177
export function applyValueContext(value: SqliteInputValue, context: CompatibilityContext): SqliteValue {
178-
if (value instanceof CustomSqliteType) {
178+
if (value instanceof CustomSqliteValue) {
179179
return value.toSqliteValue(context);
180180
} else {
181181
return value;

packages/sync-rules/test/src/quirks.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from 'vitest';
2-
import { CustomSqliteType, SqlSyncRules, TimeValue } from '../../src/index.js';
2+
import { CustomSqliteValue, SqlSyncRules, TimeValue } from '../../src/index.js';
33

44
import { ASSETS, PARSE_OPTIONS } from './util.js';
55

@@ -77,7 +77,7 @@ fixed_quirks:
7777
});
7878

7979
test('arrays', () => {
80-
const data = CustomSqliteType.wrapArray(['static value', new TimeValue('old', 'fixed')]);
80+
const data = CustomSqliteValue.wrapArray(['static value', new TimeValue('old', 'fixed')]);
8181

8282
for (const withFixedQuirk of [false, true]) {
8383
let syncRules = `

0 commit comments

Comments
 (0)