-
Notifications
You must be signed in to change notification settings - Fork 25
Feature/sdk reporting #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EspressoTrip-v2
wants to merge
211
commits into
main
Choose a base branch
from
feature/sdk-reporting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 173 commits
Commits
Show all changes
211 commits
Select commit
Hold shift + click to select a range
7546215
emiiter engine
EspressoTrip-v2 7eb90c4
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 edee67a
emitter changes
EspressoTrip-v2 fea7be8
chnages based on feedback
EspressoTrip-v2 0f603cb
refactoring and some renaming
EspressoTrip-v2 ef6cfd1
controller addition handler
EspressoTrip-v2 65c2f5b
type fix
EspressoTrip-v2 777d426
dev packages
EspressoTrip-v2 f6370a6
forgot lockfile
EspressoTrip-v2 79c9a5d
reverted dev packages
EspressoTrip-v2 4685dd3
lockfile dammit
EspressoTrip-v2 dd29d5f
testing
EspressoTrip-v2 cbdcaaf
test emitter
EspressoTrip-v2 fd6b080
test
EspressoTrip-v2 2846a61
added emiiter to socket route
EspressoTrip-v2 93bf85a
fixed binding
EspressoTrip-v2 1e12209
removed log
EspressoTrip-v2 499d98b
report storage initial
EspressoTrip-v2 44209ff
sdk scape
EspressoTrip-v2 063e446
reworked the emitter engine
EspressoTrip-v2 e3e7aab
alterations to types eventemitter
EspressoTrip-v2 5359d09
list events chnage
EspressoTrip-v2 ce5092b
changed document type mongo
EspressoTrip-v2 5ff2da5
changed document type mongo
EspressoTrip-v2 0657ffe
changed document type mongo
EspressoTrip-v2 388ab2f
changed document type mongo
EspressoTrip-v2 af06f64
chnaged date imps events
EspressoTrip-v2 50eb198
chnaged jwt exp
EspressoTrip-v2 119f5c4
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 ec9ce6f
ffs
EspressoTrip-v2 8a017f8
dev packages are desynced
EspressoTrip-v2 63b6f67
test disconnect event
EspressoTrip-v2 d5429c7
disconnect event
EspressoTrip-v2 83d4280
removed accidental key in event
EspressoTrip-v2 8f74f27
changes to update logic sdk
EspressoTrip-v2 db58d24
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 f1d187b
chnageste bump
EspressoTrip-v2 5280565
dev packages issue
EspressoTrip-v2 8cbbd35
dev packages
EspressoTrip-v2 a700ec9
chnages to mongo storage and package bumps
EspressoTrip-v2 72398c2
unset disconnect on connect
EspressoTrip-v2 842e621
change document sdk
EspressoTrip-v2 12ac832
deisconnect chnages
EspressoTrip-v2 6dfe510
connection query
EspressoTrip-v2 f3c356a
chnaged query for sdk data
EspressoTrip-v2 617fc06
removed the disconnect time
EspressoTrip-v2 bb9dfd7
chnaged disconnect report to use userdata
EspressoTrip-v2 9a4094e
fix
EspressoTrip-v2 644de71
chnaged sdk scrape and added sdk delete event
EspressoTrip-v2 7d93f69
change disconnect mongo update
EspressoTrip-v2 efd5600
wip
EspressoTrip-v2 64e397f
wip
EspressoTrip-v2 87e98c9
create new doc only if older than a day
EspressoTrip-v2 2fd9181
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 1ee1d39
wip
EspressoTrip-v2 fda348c
wip
EspressoTrip-v2 cb46003
duh
EspressoTrip-v2 b21770f
scrape data
EspressoTrip-v2 06a1859
wip
EspressoTrip-v2 d20451d
timespan logging
EspressoTrip-v2 453ec72
fix day query bug
EspressoTrip-v2 ae49da8
remove facet
EspressoTrip-v2 b123e43
dates
EspressoTrip-v2 eb7c4c2
wip
EspressoTrip-v2 46dd4af
wip
EspressoTrip-v2 d56753e
unique sdks
EspressoTrip-v2 5f59578
wip
EspressoTrip-v2 bb742da
sdk
EspressoTrip-v2 28efea4
sdk
EspressoTrip-v2 a4645b9
wip
EspressoTrip-v2 bc18198
wip
EspressoTrip-v2 6e1c1ef
list connections and some helpers
EspressoTrip-v2 83972c6
corrections timeframes
EspressoTrip-v2 fcc0468
testing
EspressoTrip-v2 486a094
scrapeSdk interval
EspressoTrip-v2 58fdb79
change to response
EspressoTrip-v2 70f1408
change to response
EspressoTrip-v2 5ded122
testing date ranges
EspressoTrip-v2 668b0d8
custom start range list connections
EspressoTrip-v2 a2cf616
start date
EspressoTrip-v2 2e6cb41
custom date validation
EspressoTrip-v2 c808e97
date start validation
EspressoTrip-v2 e7e1457
testing
EspressoTrip-v2 9ccf251
test
EspressoTrip-v2 0b1fadd
refactoring
EspressoTrip-v2 4ea15e6
date bug
EspressoTrip-v2 3735ab4
fixes krep in bugs
EspressoTrip-v2 c9088a4
added seperate filter for delete
EspressoTrip-v2 e2f7a7e
indexes
EspressoTrip-v2 28914bf
check document scan result
EspressoTrip-v2 51bbcc4
remove explain
EspressoTrip-v2 4c4144e
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 db23db6
end date to list connections
EspressoTrip-v2 f67746d
removed a log
EspressoTrip-v2 9797bad
postgres imp WIP
EspressoTrip-v2 73d8829
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 4682a74
tests
EspressoTrip-v2 f46bede
timestamp casting
EspressoTrip-v2 8d194f1
casting issues
EspressoTrip-v2 29b4b59
fix incorrect type
EspressoTrip-v2 a741f41
iso issues
EspressoTrip-v2 75c6692
testing
EspressoTrip-v2 70eac9c
testing
EspressoTrip-v2 732e1d2
transaction
EspressoTrip-v2 8899f9e
added logs
EspressoTrip-v2 42ddacf
pg-wire frustrations
EspressoTrip-v2 85d6e6b
pg-wire frustrations
EspressoTrip-v2 052ca63
pg-wire frustrations
EspressoTrip-v2 d4118ac
pg-wire frustrations
EspressoTrip-v2 2c1eb1b
pg-wire frustrations
EspressoTrip-v2 3f8cec5
pg-wire frustrations
EspressoTrip-v2 f824035
pg-wire frustrations
EspressoTrip-v2 27eb8f4
pg-wire frustrations
EspressoTrip-v2 02a5036
change the sql query to test
EspressoTrip-v2 c8c38df
testing
EspressoTrip-v2 d039559
testing
EspressoTrip-v2 aefa0f9
testing
EspressoTrip-v2 e096409
testing
EspressoTrip-v2 7526ab2
ts-codecs
EspressoTrip-v2 f1244fd
ts-codecs
EspressoTrip-v2 f88544f
ts-codecs
EspressoTrip-v2 6b5b58b
ts-codecs
EspressoTrip-v2 792b299
ts-codecs
EspressoTrip-v2 caf0c26
ts-codecs
EspressoTrip-v2 b2d5e9e
fixed sdk scrape query
EspressoTrip-v2 e538cdf
checking delete old data
EspressoTrip-v2 f385a50
checking delete old data
EspressoTrip-v2 8bed767
deleted row logging
EspressoTrip-v2 551edf2
seperated migration for sdk
EspressoTrip-v2 cabd182
seperated migration for sdk
EspressoTrip-v2 79043fa
added redundancy for events
EspressoTrip-v2 45d17df
better log
EspressoTrip-v2 c7cd9b1
oops
EspressoTrip-v2 2b9695c
clean up
EspressoTrip-v2 2d34818
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 2ff73da
fixing a bug
EspressoTrip-v2 0c3a853
fixing a bug
EspressoTrip-v2 8277c8e
removed query
EspressoTrip-v2 4a930e9
removed query
EspressoTrip-v2 ac40bca
removed query
EspressoTrip-v2 5020173
trying to simplify the update
EspressoTrip-v2 c2b84d2
trying to simplify the update
EspressoTrip-v2 fc82f14
tests tests
EspressoTrip-v2 a9d453f
postgres tests WIP
EspressoTrip-v2 7baf97b
removed command
EspressoTrip-v2 65120ce
application name conflict report storage
EspressoTrip-v2 da94778
checking concurrency issues in tests
EspressoTrip-v2 de57ca0
test chnages to tests
EspressoTrip-v2 05006be
completed postgres tests
EspressoTrip-v2 794a099
mongo tests report
EspressoTrip-v2 9b7fde8
seperated the migrations for sdk, problems testing
EspressoTrip-v2 1af5e3a
okay then
EspressoTrip-v2 30d0efd
mongo db tests report storage
EspressoTrip-v2 10a0164
changed the disconnect report to use connect_at time for long running…
EspressoTrip-v2 51661d8
fixed connected at filter
EspressoTrip-v2 824ed2f
main merge
EspressoTrip-v2 92ddb08
SMerge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 1a6ad40
cclean up some code for pr
EspressoTrip-v2 0fad466
version bump
EspressoTrip-v2 4ac4ed3
chnages to date ranges on scrapes, simplified
EspressoTrip-v2 877ce66
fixed list current connections payload
EspressoTrip-v2 37825aa
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 29a0845
fix migration indexes on down
EspressoTrip-v2 ea0c212
model document naming
EspressoTrip-v2 c1b6a0c
moved abstarct methods to the top
EspressoTrip-v2 5a9c5ce
PR review chnages
EspressoTrip-v2 4f0c77d
PR review changes
EspressoTrip-v2 8167d34
emitter PR chnages
EspressoTrip-v2 cbfa0cb
PR chnages
EspressoTrip-v2 fa5b872
PR changes as requested
EspressoTrip-v2 a2ad23e
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 a15ee2d
changed names to the agreed naming convention
EspressoTrip-v2 ed65508
chnages table names to match naming conventions
EspressoTrip-v2 9e9e91b
fixed tests
EspressoTrip-v2 f986049
removed index drop migrations
EspressoTrip-v2 fe2ef90
removed unused type
EspressoTrip-v2 7a6673e
changed date query
EspressoTrip-v2 4a0c4ca
added comments
EspressoTrip-v2 d5f2ae6
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 acd4bea
refactored test utils to its own file in postgres and mongo
EspressoTrip-v2 084287c
oops
EspressoTrip-v2 e4fca96
some fixes
EspressoTrip-v2 465807e
better documentation
EspressoTrip-v2 3403189
removed date range from get connected clients
EspressoTrip-v2 961067d
refactored tests
EspressoTrip-v2 fb8294b
date formats
EspressoTrip-v2 4b5dc44
removed as utc
EspressoTrip-v2 8728315
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 dceadf2
DateTime chnages to postgres driver
EspressoTrip-v2 565ff4a
added forced UTC for connection update
EspressoTrip-v2 1a04822
removed as utc
EspressoTrip-v2 961183c
moved migration
EspressoTrip-v2 7d5ce86
renamed migration
EspressoTrip-v2 daeaabe
if not exists to connecction migration
EspressoTrip-v2 799b984
merge conflicts fixed
EspressoTrip-v2 50c4a32
mock event engine to tests
EspressoTrip-v2 5bb5818
mock token payload
EspressoTrip-v2 5dd58a1
Merge main
EspressoTrip-v2 0180a8e
Merge main
EspressoTrip-v2 73cd8de
Merge main
EspressoTrip-v2 4ea7b73
removed errand import merged from main
EspressoTrip-v2 38fe19c
PR changes
EspressoTrip-v2 8bffdf1
Merge main
EspressoTrip-v2 70ff679
removed duplicated type
EspressoTrip-v2 48acf22
jpgwire
EspressoTrip-v2 4cc5031
jpgwire
EspressoTrip-v2 438b060
removed jpgwire comment
EspressoTrip-v2 068ac81
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 a230ee5
Merge main
EspressoTrip-v2 77476ff
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 19fcf3d
Merge branch 'main' into feature/sdk-reporting
EspressoTrip-v2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@powersync/service-module-mongodb-storage': patch | ||
'@powersync/service-core': patch | ||
'@powersync/service-types': patch | ||
--- | ||
|
||
sdk reporting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@powersync/service-module-postgres-storage': patch | ||
'@powersync/service-module-mongodb-storage': patch | ||
'@powersync/service-core': patch | ||
'@powersync/service-types': patch | ||
--- | ||
|
||
Added sdk reporting to storage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@powersync/service-module-postgres-storage': patch | ||
'@powersync/service-module-mongodb-storage': patch | ||
'@powersync/service-module-postgres': patch | ||
'@powersync/service-module-mongodb': patch | ||
'@powersync/service-core': patch | ||
'@powersync/service-module-mysql': patch | ||
'@powersync/service-module-core': patch | ||
'@powersync/lib-services-framework': patch | ||
'@powersync/service-types': patch | ||
--- | ||
|
||
Reporting mongo storage added to storage engine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...module-mongodb-storage/src/migrations/db/migrations/1752661449910-connection-reporting.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { migrations } from '@powersync/service-core'; | ||
import * as storage from '../../../storage/storage-index.js'; | ||
import { MongoStorageConfig } from '../../../types/types.js'; | ||
|
||
export const up: migrations.PowerSyncMigrationFunction = async (context) => { | ||
const { | ||
service_context: { configuration } | ||
} = context; | ||
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); | ||
|
||
try { | ||
await db.createConnectionReportingCollection(); | ||
|
||
await db.connection_report_events.createIndex( | ||
{ | ||
connected_at: 1, | ||
jwt_exp: 1, | ||
disconnected_at: 1 | ||
}, | ||
{ name: 'connection_list_index' } | ||
); | ||
|
||
await db.connection_report_events.createIndex( | ||
{ | ||
user_id: 1 | ||
}, | ||
{ name: 'connection_user_id_index' } | ||
); | ||
await db.connection_report_events.createIndex( | ||
{ | ||
client_id: 1 | ||
}, | ||
{ name: 'connection_client_id_index' } | ||
); | ||
await db.connection_report_events.createIndex( | ||
{ | ||
sdk: 1 | ||
}, | ||
{ name: 'connection_index' } | ||
); | ||
} finally { | ||
await db.client.close(); | ||
} | ||
}; | ||
|
||
export const down: migrations.PowerSyncMigrationFunction = async (context) => { | ||
const { | ||
service_context: { configuration } | ||
} = context; | ||
|
||
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig); | ||
|
||
try { | ||
if (await db.connection_report_events.indexExists('connection_list_index')) { | ||
await db.connection_report_events.dropIndex('connection_list_index'); | ||
} | ||
if (await db.connection_report_events.indexExists('connection_user_id_index')) { | ||
await db.connection_report_events.dropIndex('connection_user_id_index'); | ||
} | ||
if (await db.connection_report_events.indexExists('connection_client_id_index')) { | ||
await db.connection_report_events.dropIndex('connection_client_id_index'); | ||
} | ||
if (await db.connection_report_events.indexExists('connection_index')) { | ||
await db.connection_report_events.dropIndex('connection_index'); | ||
} | ||
await db.db.dropCollection('connection_report_events'); | ||
} finally { | ||
await db.client.close(); | ||
} | ||
}; |
195 changes: 195 additions & 0 deletions
195
modules/module-mongodb-storage/src/storage/MongoReportStorage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import { mongo } from '@powersync/lib-service-mongodb'; | ||
import { storage } from '@powersync/service-core'; | ||
import { event_types } from '@powersync/service-types'; | ||
import { PowerSyncMongo } from './implementation/db.js'; | ||
import { logger } from '@powersync/lib-services-framework'; | ||
|
||
export class MongoReportStorage implements storage.ReportStorage { | ||
private readonly client: mongo.MongoClient; | ||
EspressoTrip-v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
public readonly db: PowerSyncMongo; | ||
|
||
constructor(db: PowerSyncMongo) { | ||
this.client = db.client; | ||
this.db = db; | ||
} | ||
async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> { | ||
const { date } = data; | ||
const result = await this.db.connection_report_events.deleteMany({ | ||
connected_at: { $lt: date }, | ||
$or: [ | ||
{ disconnected_at: { $exists: true } }, | ||
{ jwt_exp: { $lt: new Date() }, disconnected_at: { $exists: false } } | ||
] | ||
}); | ||
if (result.deletedCount > 0) { | ||
logger.info( | ||
`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.` | ||
); | ||
} | ||
} | ||
|
||
async getClientConnectionReports( | ||
data: event_types.ClientConnectionReportRequest | ||
): Promise<event_types.ClientConnectionReport> { | ||
const { start, end } = data; | ||
const result = await this.db.connection_report_events | ||
.aggregate<event_types.ClientConnectionReport>([ | ||
{ | ||
$match: { | ||
connected_at: { $lte: end, $gte: start } | ||
} | ||
}, | ||
this.connectionsFacetPipeline(), | ||
this.connectionsProjectPipeline() | ||
]) | ||
.toArray(); | ||
return result[0]; | ||
} | ||
|
||
async reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void> { | ||
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!); | ||
await this.db.connection_report_events.findOneAndUpdate( | ||
updateFilter, | ||
{ | ||
$set: data, | ||
$unset: { | ||
disconnected_at: '' | ||
} | ||
}, | ||
{ | ||
upsert: true | ||
} | ||
); | ||
} | ||
async reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void> { | ||
const { connected_at, user_id, client_id } = data; | ||
await this.db.connection_report_events.findOneAndUpdate( | ||
{ | ||
client_id, | ||
user_id, | ||
connected_at | ||
rkistner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
$set: { | ||
disconnected_at: data.disconnected_at | ||
}, | ||
$unset: { | ||
jwt_exp: '' | ||
} | ||
} | ||
); | ||
} | ||
async getConnectedClients(data: event_types.ClientConnectionsRequest): Promise<event_types.ClientConnectionReport> { | ||
const timeframeFilter = this.listConnectionsDateRange(data); | ||
const result = await this.db.connection_report_events | ||
.aggregate<event_types.ClientConnectionReport>([ | ||
{ | ||
$match: { | ||
disconnected_at: { $exists: false }, | ||
jwt_exp: { $gt: new Date() }, | ||
...timeframeFilter | ||
EspressoTrip-v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
}, | ||
this.connectionsFacetPipeline(), | ||
this.connectionsProjectPipeline() | ||
]) | ||
.toArray(); | ||
return result[0]; | ||
} | ||
|
||
async [Symbol.asyncDispose]() { | ||
// No-op | ||
} | ||
|
||
EspressoTrip-v2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private parseJsDate(date: Date) { | ||
const year = date.getFullYear(); | ||
const month = date.getMonth(); | ||
const today = date.getDate(); | ||
const day = date.getDay(); | ||
return { | ||
year, | ||
month, | ||
today, | ||
day, | ||
parsedDate: date | ||
}; | ||
} | ||
|
||
private connectionsFacetPipeline() { | ||
return { | ||
$facet: { | ||
unique_users: [ | ||
{ | ||
$group: { | ||
_id: '$user_id' | ||
} | ||
}, | ||
{ | ||
$count: 'count' | ||
} | ||
], | ||
sdk_versions_array: [ | ||
{ | ||
$group: { | ||
_id: '$sdk', | ||
total: { $sum: 1 }, | ||
client_ids: { $addToSet: '$client_id' }, | ||
user_ids: { $addToSet: '$user_id' } | ||
} | ||
}, | ||
{ | ||
$project: { | ||
_id: 0, | ||
sdk: '$_id', | ||
users: { $size: '$user_ids' }, | ||
clients: { $size: '$client_ids' } | ||
} | ||
}, | ||
{ | ||
$sort: { | ||
sdk: 1 | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
} | ||
|
||
private connectionsProjectPipeline() { | ||
return { | ||
$project: { | ||
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] }, | ||
sdks: '$sdk_versions_array' | ||
} | ||
}; | ||
} | ||
|
||
private updateDocFilter(userId: string, clientId: string) { | ||
const { year, month, today } = this.parseJsDate(new Date()); | ||
const nextDay = today + 1; | ||
return { | ||
user_id: userId, | ||
client_id: clientId, | ||
connected_at: { | ||
// Need to create a new date here to sett the time to 00:00:00 | ||
$gte: new Date(year, month, today), | ||
$lt: new Date(year, month, nextDay) | ||
} | ||
EspressoTrip-v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}; | ||
} | ||
|
||
private listConnectionsDateRange(data: event_types.ClientConnectionsRequest) { | ||
const { range } = data; | ||
if (!range) { | ||
return undefined; | ||
} | ||
const endDate = data.range?.end ? new Date(data.range.end) : new Date(); | ||
const startDate = new Date(range.start); | ||
return { | ||
connected_at: { | ||
$lte: endDate, | ||
$gte: startDate | ||
} | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...dule-mongodb-storage/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TestStorageOptions } from '@powersync/service-core'; | ||
import { connectMongoForTests } from './util.js'; | ||
import { MongoReportStorage } from '../MongoReportStorage.js'; | ||
|
||
export type MongoTestStorageOptions = { | ||
url: string; | ||
isCI: boolean; | ||
}; | ||
|
||
export const MongoTestReportStorageFactoryGenerator = (factoryOptions: MongoTestStorageOptions) => { | ||
EspressoTrip-v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return async (options?: TestStorageOptions) => { | ||
const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI); | ||
|
||
await db.createConnectionReportingCollection(); | ||
|
||
if (!options?.doNotClear) { | ||
await db.clear(); | ||
} | ||
|
||
return new MongoReportStorage(db); | ||
}; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.