@@ -3,6 +3,8 @@ import * as bson from 'bson';
33import { SqliteJsonValue } from '@powersync/service-sync-rules' ;
44import { ReplicaId } from './BucketStorage.js' ;
55
6+ type NodeBuffer = Buffer < ArrayBuffer > ;
7+
68export const BSON_DESERIALIZE_OPTIONS : bson . DeserializeOptions = {
79 // use bigint instead of Long
810 useBigInt64 : true
@@ -12,15 +14,15 @@ export const BSON_DESERIALIZE_OPTIONS: bson.DeserializeOptions = {
1214 * Lookup serialization must be number-agnostic. I.e. normalize numbers, instead of preserving numbers.
1315 * @param lookup
1416 */
15- export const serializeLookupBuffer = ( lookup : SqliteJsonValue [ ] ) : Buffer => {
17+ export const serializeLookupBuffer = ( lookup : SqliteJsonValue [ ] ) : NodeBuffer => {
1618 const normalized = lookup . map ( ( value ) => {
1719 if ( typeof value == 'number' && Number . isInteger ( value ) ) {
1820 return BigInt ( value ) ;
1921 } else {
2022 return value ;
2123 }
2224 } ) ;
23- return bson . serialize ( { l : normalized } ) as Buffer ;
25+ return bson . serialize ( { l : normalized } ) as NodeBuffer ;
2426} ;
2527
2628export const serializeLookup = ( lookup : SqliteJsonValue [ ] ) => {
@@ -40,8 +42,8 @@ export const isUUID = (value: any): value is bson.UUID => {
4042 return uuid . _bsontype == 'Binary' && uuid . sub_type == bson . Binary . SUBTYPE_UUID ;
4143} ;
4244
43- export const serializeReplicaId = ( id : ReplicaId ) : Buffer => {
44- return bson . serialize ( { id } ) as Buffer ;
45+ export const serializeReplicaId = ( id : ReplicaId ) : NodeBuffer => {
46+ return bson . serialize ( { id } ) as NodeBuffer ;
4547} ;
4648
4749export const deserializeReplicaId = ( id : Buffer ) : ReplicaId => {
@@ -53,8 +55,8 @@ export const deserializeBson = (buffer: Buffer) => {
5355 return bson . deserialize ( buffer , BSON_DESERIALIZE_OPTIONS ) ;
5456} ;
5557
56- export const serializeBson = ( document : any ) : Buffer => {
57- return bson . serialize ( document ) as Buffer ;
58+ export const serializeBson = ( document : any ) : NodeBuffer => {
59+ return bson . serialize ( document ) as NodeBuffer ;
5860} ;
5961
6062/**
@@ -73,6 +75,6 @@ export const replicaIdEquals = (a: ReplicaId, b: ReplicaId) => {
7375 return false ;
7476 } else {
7577 // There are many possible primitive values, this covers them all
76- return serializeReplicaId ( a ) . equals ( serializeReplicaId ( b ) as ArrayBuffer as Uint8Array ) ;
78+ return serializeReplicaId ( a ) . equals ( serializeReplicaId ( b ) ) ;
7779 }
7880} ;
0 commit comments