File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed
modules/module-postgres-storage/src Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import {
1515 SdkConnectBucketData ,
1616 SdkDisconnectEventData
1717} from '@powersync/service-types/src/events.js' ;
18- import { SdkReporting } from '../types/models/SdkReporting.js' ;
18+ import { SdkReporting , SdkReportingDecoded } from '../types/models/SdkReporting.js' ;
1919
2020export type PostgresReportStorageOptions = {
2121 config : NormalizedPostgresStorageConfig ;
@@ -109,7 +109,13 @@ export class PostgresReportStorageFactory implements storage.ReportStorageFactor
109109 }
110110 }
111111
112- private async listConnectionsDateRangeQuery ( data : event_types . ListCurrentConnectionsRequest ) {
112+ private mapListCurrentConnectionsResponse ( result : SdkReportingDecoded ) : ListCurrentConnections {
113+ return {
114+ users : Number ( result . users ) ,
115+ sdks : result . sdks . data
116+ } ;
117+ }
118+ private async listConnectionsQuery ( data : event_types . ListCurrentConnectionsRequest ) {
113119 const { range } = data ;
114120 if ( ! range ) {
115121 return this . db . sql `
@@ -300,15 +306,14 @@ export class PostgresReportStorageFactory implements storage.ReportStorageFactor
300306 } ) ;
301307 }
302308 async listCurrentConnections ( data : ListCurrentConnectionsRequest ) : Promise < ListCurrentConnections > {
303- const rows = await this . listConnectionsDateRangeQuery ( data ) ;
304- console . log ( { rows } ) ;
305- // @ts -ignore
306- console . log ( rows . sdks ) ;
307- return {
308- // @ts -ignore
309- users : Number ( rows . users ) ,
310- sdks : [ ]
311- } ;
309+ const result = await this . listConnectionsQuery ( data ) ;
310+ if ( ! result ) {
311+ return {
312+ users : 0 ,
313+ sdks : [ ]
314+ } ;
315+ }
316+ return this . mapListCurrentConnectionsResponse ( result ) ;
312317 }
313318
314319 async scrapeSdkData ( data : ScrapeSdkDataRequest ) : Promise < ListCurrentConnections > {
Original file line number Diff line number Diff line change @@ -7,11 +7,14 @@ export const Sdks = t.object({
77 users : t . number
88} ) ;
99
10+ export type Sdks = t . Encoded < typeof Sdks > ;
11+
1012export const SdkReporting = t . object ( {
1113 users : bigint ,
1214 sdks : t . object ( {
13- data : jsonb ( t . array ( Sdks ) )
15+ data : jsonb < Sdks [ ] > ( t . array ( Sdks ) )
1416 } )
1517} ) ;
1618
1719export type SdkReporting = t . Encoded < typeof SdkReporting > ;
20+ export type SdkReportingDecoded = t . Decoded < typeof SdkReporting > ;
You can’t perform that action at this time.
0 commit comments