Skip to content

Commit 6e00969

Browse files
committed
Fix mongodb as well
1 parent 2991a0e commit 6e00969

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { mongo } from '@powersync/lib-service-mongodb';
22
import { storage } from '@powersync/service-core';
3-
import { JSONBig, JsonContainer } from '@powersync/service-jsonbig';
3+
import { JsonContainer } from '@powersync/service-jsonbig';
44
import {
55
CompatibilityContext,
66
CustomArray,
77
CustomObject,
88
CustomSqliteValue,
9-
DatabaseInputValue,
109
SqliteInputRow,
1110
SqliteInputValue,
12-
SqliteRow,
13-
SqliteValue,
1411
DateTimeValue
1512
} from '@powersync/service-sync-rules';
1613

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
CompatibilityContext,
55
CompatibilityEdition,
66
SqliteInputRow,
7-
SqlSyncRules
7+
SqlSyncRules,
8+
TimeValue,
9+
CustomArray
810
} from '@powersync/service-sync-rules';
911
import { describe, expect, test } from 'vitest';
1012

@@ -167,7 +169,7 @@ describe('mongo data types', () => {
167169

168170
expect(sqliteValue[2]).toMatchObject({
169171
_id: 3n,
170-
date: '2023-03-06 13:47:00.000Z'
172+
date: new TimeValue('2023-03-06 13:47:00.000Z', '2023-03-06T13:47:00.000Z')
171173
});
172174

173175
expect(sqliteValue[3]).toMatchObject({
@@ -221,7 +223,7 @@ describe('mongo data types', () => {
221223

222224
expect(sqliteValue[2]).toMatchObject({
223225
_id: 3n,
224-
date: '["2023-03-06 13:47:00.000Z"]'
226+
date: ['2023-03-06 13:47:00.000Z']
225227
});
226228

227229
expect(sqliteValue[3]).toMatchObject({

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JSONBig } from '@powersync/service-jsonbig';
22
import { CompatibilityContext } from '../quirks.js';
33
import { SqliteValue, EvaluatedRow, SqliteInputValue, DatabaseInputValue } from '../types.js';
4-
import { filterJsonData } from '../utils.js';
4+
import { SqliteValueType } from '../ExpressionType.js';
55

66
/**
77
* A value that decays into a {@link SqliteValue} in a context-specific way.
@@ -23,14 +23,16 @@ export abstract class CustomSqliteType {
2323
*/
2424
abstract toSqliteValue(context: CompatibilityContext): SqliteValue;
2525

26+
abstract get sqliteType(): SqliteValueType;
27+
2628
static wrapArray(elements: DatabaseInputValue[]): SqliteInputValue {
2729
const hasCustomValue = elements.some((v) => v instanceof CustomSqliteType);
2830
if (hasCustomValue) {
2931
// We need access to the compatibility context before encoding contents as JSON.
3032
return new CustomArray(elements);
3133
} else {
3234
// We can encode the array statically.
33-
return JSONBig.stringify(elements.map((element) => filterJsonData(element)));
35+
return JSONBig.stringify(elements);
3436
}
3537
}
3638
}
@@ -40,11 +42,14 @@ class CustomArray extends CustomSqliteType {
4042
super();
4143
}
4244

45+
get sqliteType(): SqliteValueType {
46+
return 'text';
47+
}
48+
4349
toSqliteValue(context: CompatibilityContext): SqliteValue {
4450
return JSONBig.stringify(
4551
this.elements.map((element) => {
46-
const mapped = element instanceof CustomSqliteType ? element.toSqliteValue(context) : element;
47-
return filterJsonData(mapped);
52+
return element instanceof CustomSqliteType ? element.toSqliteValue(context) : element;
4853
})
4954
);
5055
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class DateTimeValue extends CustomSqliteValue {
2929
return 'text';
3030
}
3131

32+
get sqliteType(): SqliteValueType {
33+
return 'text';
34+
}
35+
3236
toSqliteValue(context: CompatibilityContext) {
3337
return context.isEnabled(CompatibilityOption.timestampsIso8601)
3438
? this.iso8601Representation

0 commit comments

Comments
 (0)