@@ -3,9 +3,10 @@ import {
33 getUuidReplicaIdentityBson ,
44 InternalOpId ,
55 OplogEntry ,
6+ SaveOptions ,
67 storage
78} from '@powersync/service-core' ;
8- import { ParameterLookup , RequestParameters } from '@powersync/service-sync-rules' ;
9+ import { DateTimeValue , ParameterLookup , RequestParameters } from '@powersync/service-sync-rules' ;
910import { expect , test , describe , beforeEach } from 'vitest' ;
1011import * as test_utils from '../test-utils/test-utils-index.js' ;
1112import { SqlBucketDescriptor } from '@powersync/service-sync-rules/src/SqlBucketDescriptor.js' ;
@@ -1995,4 +1996,70 @@ bucket_definitions:
19951996 // we expect 0n and 1n, or 1n and 2n.
19961997 expect ( checkpoint2 ) . toBeGreaterThan ( checkpoint1 ) ;
19971998 } ) ;
1999+
2000+ test ( 'data with custom types' , async ( ) => {
2001+ await using factory = await generateStorageFactory ( ) ;
2002+ const testValue = {
2003+ sourceTable : TEST_TABLE ,
2004+ tag : storage . SaveOperationTag . INSERT ,
2005+ after : {
2006+ id : 't1' ,
2007+ description : new DateTimeValue ( '2025-08-28T11:30:00' )
2008+ } ,
2009+ afterReplicaId : test_utils . rid ( 't1' )
2010+ } satisfies SaveOptions ;
2011+
2012+ {
2013+ // First, deploy old sync rules and row with date time value
2014+ const syncRules = await factory . updateSyncRules ( {
2015+ content : `
2016+ bucket_definitions:
2017+ global:
2018+ data:
2019+ - SELECT id, description FROM test
2020+ `
2021+ } ) ;
2022+ const bucketStorage = factory . getInstance ( syncRules ) ;
2023+ await bucketStorage . startBatch ( test_utils . BATCH_OPTIONS , async ( batch ) => {
2024+ await batch . save ( testValue ) ;
2025+ await batch . commit ( '1/1' ) ;
2026+ } ) ;
2027+
2028+ const { checkpoint } = await bucketStorage . getCheckpoint ( ) ;
2029+ const batch = await test_utils . fromAsync (
2030+ bucketStorage . getBucketDataBatch ( checkpoint , new Map ( [ [ 'global[]' , 0n ] ] ) )
2031+ ) ;
2032+ expect ( batch [ 0 ] . chunkData . data ) . toMatchObject ( [
2033+ {
2034+ data : '{"id":"t1","description":"2025-08-28 11:30:00"}'
2035+ }
2036+ ] ) ;
2037+ }
2038+
2039+ const syncRules = await factory . updateSyncRules ( {
2040+ content : `
2041+ bucket_definitions:
2042+ global:
2043+ data:
2044+ - SELECT id, description FROM test
2045+
2046+ config:
2047+ edition: 2
2048+ `
2049+ } ) ;
2050+ const bucketStorage = factory . getInstance ( syncRules ) ;
2051+ await bucketStorage . startBatch ( test_utils . BATCH_OPTIONS , async ( batch ) => {
2052+ await batch . save ( testValue ) ;
2053+ await batch . commit ( '1/2' ) ;
2054+ } ) ;
2055+ const { checkpoint } = await bucketStorage . getCheckpoint ( ) ;
2056+ const batch = await test_utils . fromAsync (
2057+ bucketStorage . getBucketDataBatch ( checkpoint , new Map ( [ [ '2#global[]' , 0n ] ] ) )
2058+ ) ;
2059+ expect ( batch [ 0 ] . chunkData . data ) . toMatchObject ( [
2060+ {
2061+ data : '{"id":"t1","description":"2025-08-28T11:30:00"}'
2062+ }
2063+ ] ) ;
2064+ } ) ;
19982065}
0 commit comments