11import { mongo } from '@powersync/lib-service-mongodb' ;
22import { storage } from '@powersync/service-core' ;
33import { JSONBig , JsonContainer } from '@powersync/service-jsonbig' ;
4- import { SqliteRow , SqliteValue } from '@powersync/service-sync-rules' ;
4+ import {
5+ CustomSqliteType ,
6+ SqliteInputRow ,
7+ SqliteInputValue ,
8+ SqliteRow ,
9+ SqliteValue ,
10+ TimeValue
11+ } from '@powersync/service-sync-rules' ;
512
613import { ErrorCode , ServiceError } from '@powersync/lib-services-framework' ;
714import { MongoLSN } from '../common/MongoLSN.js' ;
@@ -27,15 +34,15 @@ export function getCacheIdentifier(source: storage.SourceEntityDescriptor | stor
2734 return `${ source . schema } .${ source . name } ` ;
2835}
2936
30- export function constructAfterRecord ( document : mongo . Document ) : SqliteRow {
31- let record : SqliteRow = { } ;
37+ export function constructAfterRecord ( document : mongo . Document ) : SqliteInputRow {
38+ let record : SqliteInputRow = { } ;
3239 for ( let key of Object . keys ( document ) ) {
3340 record [ key ] = toMongoSyncRulesValue ( document [ key ] ) ;
3441 }
3542 return record ;
3643}
3744
38- export function toMongoSyncRulesValue ( data : any ) : SqliteValue {
45+ export function toMongoSyncRulesValue ( data : any ) : SqliteInputValue {
3946 const autoBigNum = true ;
4047 if ( data === null ) {
4148 return null ;
@@ -60,7 +67,8 @@ export function toMongoSyncRulesValue(data: any): SqliteValue {
6067 } else if ( data instanceof mongo . UUID ) {
6168 return data . toHexString ( ) ;
6269 } else if ( data instanceof Date ) {
63- return data . toISOString ( ) . replace ( 'T' , ' ' ) ;
70+ const isoString = data . toISOString ( ) ;
71+ return new TimeValue ( isoString . replace ( 'T' , ' ' ) , isoString ) ;
6472 } else if ( data instanceof mongo . Binary ) {
6573 return new Uint8Array ( data . buffer ) ;
6674 } else if ( data instanceof mongo . Long ) {
@@ -72,8 +80,7 @@ export function toMongoSyncRulesValue(data: any): SqliteValue {
7280 } else if ( data instanceof RegExp ) {
7381 return JSON . stringify ( { pattern : data . source , options : data . flags } ) ;
7482 } else if ( Array . isArray ( data ) ) {
75- // We may be able to avoid some parse + stringify cycles here for JsonSqliteContainer.
76- return JSONBig . stringify ( data . map ( ( element ) => filterJsonData ( element ) ) ) ;
83+ return CustomSqliteType . wrapArray ( data . map ( ( element ) => filterJsonData ( element ) ) ) ;
7784 } else if ( data instanceof Uint8Array ) {
7885 return data ;
7986 } else if ( data instanceof JsonContainer ) {
@@ -117,7 +124,8 @@ function filterJsonData(data: any, depth = 0): any {
117124 } else if ( typeof data == 'bigint' ) {
118125 return data ;
119126 } else if ( data instanceof Date ) {
120- return data . toISOString ( ) . replace ( 'T' , ' ' ) ;
127+ const isoString = data . toISOString ( ) ;
128+ return new TimeValue ( isoString . replace ( 'T' , ' ' ) , isoString ) ;
121129 } else if ( data instanceof mongo . ObjectId ) {
122130 return data . toHexString ( ) ;
123131 } else if ( data instanceof mongo . UUID ) {
@@ -133,7 +141,7 @@ function filterJsonData(data: any, depth = 0): any {
133141 } else if ( data instanceof RegExp ) {
134142 return { pattern : data . source , options : data . flags } ;
135143 } else if ( Array . isArray ( data ) ) {
136- return data . map ( ( element ) => filterJsonData ( element , depth + 1 ) ) ;
144+ return CustomSqliteType . wrapArray ( data . map ( ( element ) => filterJsonData ( element , depth + 1 ) ) ) ;
137145 } else if ( ArrayBuffer . isView ( data ) ) {
138146 return undefined ;
139147 } else if ( data instanceof JsonContainer ) {
0 commit comments