11import { mongo } from '@powersync/lib-service-mongodb' ;
2- import { CustomSqliteValue , SqliteInputRow , SqliteRow , SqlSyncRules , TimeValue } from '@powersync/service-sync-rules' ;
2+ import { applyRowContext , CompatibilityContext , SqliteInputRow , SqlSyncRules } from '@powersync/service-sync-rules' ;
33import { describe , expect , test } from 'vitest' ;
44
55import { MongoRouteAPIAdapter } from '@module/api/MongoRouteAPIAdapter.js' ;
@@ -138,8 +138,10 @@ describe('mongo data types', () => {
138138 ] ) ;
139139 }
140140
141- function checkResults ( transformed : Record < string , any > [ ] ) {
142- expect ( transformed [ 0 ] ) . toMatchObject ( {
141+ function checkResults ( transformed : SqliteInputRow [ ] ) {
142+ const sqliteValue = transformed . map ( ( e ) => applyRowContext ( e , CompatibilityContext . FULL_BACKWARDS_COMPATIBILITY ) ) ;
143+
144+ expect ( sqliteValue [ 0 ] ) . toMatchObject ( {
143145 _id : 1n ,
144146 text : 'text' ,
145147 uuid : 'baeb2514-4c57-436d-b3cc-c1256211656d' ,
@@ -152,17 +154,17 @@ describe('mongo data types', () => {
152154 null : null ,
153155 decimal : '3.14'
154156 } ) ;
155- expect ( transformed [ 1 ] ) . toMatchObject ( {
157+ expect ( sqliteValue [ 1 ] ) . toMatchObject ( {
156158 _id : 2n ,
157159 nested : '{"test":"thing"}'
158160 } ) ;
159161
160- expect ( transformed [ 2 ] ) . toMatchObject ( {
162+ expect ( sqliteValue [ 2 ] ) . toMatchObject ( {
161163 _id : 3n ,
162- date : new TimeValue ( '2023-03-06 13:47:00.000Z' , '2023-03-06T13:47:00.000Z' )
164+ date : '2023-03-06 13:47:00.000Z'
163165 } ) ;
164166
165- expect ( transformed [ 3 ] ) . toMatchObject ( {
167+ expect ( sqliteValue [ 3 ] ) . toMatchObject ( {
166168 _id : 4n ,
167169 objectId : '66e834cc91d805df11fa0ecb' ,
168170 timestamp : 1958505087099n ,
@@ -177,9 +179,9 @@ describe('mongo data types', () => {
177179 } ) ;
178180
179181 // This must specifically be null, and not undefined.
180- expect ( transformed [ 4 ] . undefined ) . toBeNull ( ) ;
182+ expect ( sqliteValue [ 4 ] . undefined ) . toBeNull ( ) ;
181183
182- expect ( transformed [ 5 ] ) . toMatchObject ( {
184+ expect ( sqliteValue [ 5 ] ) . toMatchObject ( {
183185 _id : 6n ,
184186 int4 : - 1n ,
185187 int8 : - 9007199254740993n ,
@@ -188,8 +190,10 @@ describe('mongo data types', () => {
188190 } ) ;
189191 }
190192
191- function checkResultsNested ( transformed : Record < string , any > [ ] ) {
192- expect ( transformed [ 0 ] ) . toMatchObject ( {
193+ function checkResultsNested ( transformed : SqliteInputRow [ ] ) {
194+ const sqliteValue = transformed . map ( ( e ) => applyRowContext ( e , CompatibilityContext . FULL_BACKWARDS_COMPATIBILITY ) ) ;
195+
196+ expect ( sqliteValue [ 0 ] ) . toMatchObject ( {
193197 _id : 1n ,
194198 text : `["text"]` ,
195199 uuid : '["baeb2514-4c57-436d-b3cc-c1256211656d"]' ,
@@ -204,30 +208,30 @@ describe('mongo data types', () => {
204208
205209 // Note: Depending on to what extent we use the original postgres value, the whitespace may change, and order may change.
206210 // We do expect that decimals and big numbers are preserved.
207- expect ( transformed [ 1 ] ) . toMatchObject ( {
211+ expect ( sqliteValue [ 1 ] ) . toMatchObject ( {
208212 _id : 2n ,
209213 nested : '[{"test":"thing"}]'
210214 } ) ;
211215
212- expect ( transformed [ 2 ] ) . toMatchObject ( {
216+ expect ( sqliteValue [ 2 ] ) . toMatchObject ( {
213217 _id : 3n ,
214- date : CustomSqliteValue . wrapArray ( [ new TimeValue ( ' 2023-03-06 13:47:00.000Z' , '2023-03-06T13:47:00.000Z' ) ] )
218+ date : '[" 2023-03-06 13:47:00.000Z"]'
215219 } ) ;
216220
217- expect ( transformed [ 3 ] ) . toMatchObject ( {
221+ expect ( sqliteValue [ 3 ] ) . toMatchObject ( {
218222 _id : 5n ,
219223 undefined : '[null]'
220224 } ) ;
221225
222- expect ( transformed [ 4 ] ) . toMatchObject ( {
226+ expect ( sqliteValue [ 4 ] ) . toMatchObject ( {
223227 _id : 6n ,
224228 int4 : '[-1]' ,
225229 int8 : '[-9007199254740993]' ,
226230 float : '[-3.14]' ,
227231 decimal : '["-3.14"]'
228232 } ) ;
229233
230- expect ( transformed [ 5 ] ) . toMatchObject ( {
234+ expect ( sqliteValue [ 5 ] ) . toMatchObject ( {
231235 _id : 10n ,
232236 objectId : '["66e834cc91d805df11fa0ecb"]' ,
233237 timestamp : '[1958505087099]' ,
0 commit comments