@powersync/service-module-mongodb-storage 0.0.0-dev-20250721150646 → 0.0.0-dev-20250722083948

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @powersync/service-module-mongodb-storage
2
2
 
3
- ## 0.0.0-dev-20250721150646
3
+ ## 0.0.0-dev-20250722083948
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -8,10 +8,10 @@
8
8
  - a700ec9: Reporting mongo storage added to storage engine.
9
9
  - Updated dependencies [f1d187b]
10
10
  - Updated dependencies [a700ec9]
11
- - @powersync/service-core@0.0.0-dev-20250721150646
12
- - @powersync/service-types@0.0.0-dev-20250721150646
13
- - @powersync/lib-services-framework@0.0.0-dev-20250721150646
14
- - @powersync/lib-service-mongodb@0.0.0-dev-20250721150646
11
+ - @powersync/service-core@0.0.0-dev-20250722083948
12
+ - @powersync/service-types@0.0.0-dev-20250722083948
13
+ - @powersync/lib-services-framework@0.0.0-dev-20250722083948
14
+ - @powersync/lib-service-mongodb@0.0.0-dev-20250722083948
15
15
 
16
16
  ## 0.10.4
17
17
 
@@ -1,14 +1,14 @@
1
1
  import { storage } from '@powersync/service-core';
2
2
  import { event_types } from '@powersync/service-types';
3
3
  import { PowerSyncMongo } from './implementation/db.js';
4
- import { ListCurrentConnectionsResponse, SdkConnectEventData, SdkDisconnectEventData } from '@powersync/service-types/dist/events.js';
4
+ import { ListCurrentConnectionsResponse, SdkConnectBucketData, SdkDisconnectEventData } from '@powersync/service-types/dist/events.js';
5
5
  export declare class MongoReportStorage implements storage.ReportStorageFactory {
6
6
  private readonly client;
7
7
  readonly db: PowerSyncMongo;
8
8
  constructor(db: PowerSyncMongo);
9
9
  deleteOldSdkData(data: event_types.DeleteOldSdkData): Promise<void>;
10
10
  scrapeSdkData(data: event_types.InstanceRequest): Promise<ListCurrentConnectionsResponse>;
11
- reportSdkConnect(data: SdkConnectEventData): Promise<void>;
11
+ reportSdkConnect(data: SdkConnectBucketData): Promise<void>;
12
12
  reportSdkDisconnect(data: SdkDisconnectEventData): Promise<void>;
13
13
  listCurrentConnections(data: event_types.InstanceRequest): Promise<ListCurrentConnectionsResponse>;
14
14
  [Symbol.asyncDispose](): Promise<void>;
@@ -1,3 +1,15 @@
1
+ function dateFilter(userId, clientId) {
2
+ const date = new Date();
3
+ const year = date.getFullYear();
4
+ const month = date.getMonth() + 1;
5
+ const day = date.getDate();
6
+ return {
7
+ user_id: userId,
8
+ client_id: clientId,
9
+ $gte: new Date(year, month, day, 0, 0, 0),
10
+ $lt: new Date(year, month, day + 1, 0, 0, 0)
11
+ };
12
+ }
1
13
  export class MongoReportStorage {
2
14
  client;
3
15
  db;
@@ -36,16 +48,19 @@ export class MongoReportStorage {
36
48
  };
37
49
  }
38
50
  async reportSdkConnect(data) {
39
- await this.db.sdk_report_events.findOneAndUpdate({ _id: data.id }, {
40
- $set: data.data
51
+ await this.db.sdk_report_events.findOneAndUpdate(dateFilter(data.user_id, data.client_id), {
52
+ $set: data,
53
+ $unset: {
54
+ disconnect_at: ''
55
+ }
41
56
  }, {
42
57
  upsert: true
43
58
  });
44
59
  }
45
60
  async reportSdkDisconnect(data) {
46
- await this.db.sdk_report_events.findOneAndUpdate({ _id: data.id }, {
61
+ await this.db.sdk_report_events.findOneAndUpdate(dateFilter(data.user_id, data.client_id), {
47
62
  $set: {
48
- disconnect_at: data.data.disconnect_at
63
+ disconnect_at: data.disconnect_at
49
64
  },
50
65
  $unset: {
51
66
  jwt_exp: ''
@@ -1 +1 @@
1
- {"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,kBAAkB;IACZ,MAAM,CAAoB;IAC3B,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE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a;aACvC;YACD,MAAM,EAAE;gBACN,OAAO,EAAE,EAAE;aACZ;SACF,CACF,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,sBAAsB,CAAC,IAAiC;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,iBAAiB;aAC3C,SAAS,CAAyB;YACjC;gBACE,MAAM,EAAE;oBACN,GAAG,EAAE,IAAI;oBACT,QAAQ,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE;oBACnC,UAAU,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE;oBACvC,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;iBAC5B;aACF;YACD;gBACE,QAAQ,EAAE;oBACR,GAAG,EAAE,CAAC;oBACN,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,aAAa;oBACtB,IAAI,EAAE,OAAO;iBACd;aACF;SACF,CAAC;aACD,OAAO,EAAE,CAAC;QACb,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,MAAM,CAAC,CAAC,CAAC;SACb,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,QAAQ;IACV,CAAC;CACF"}
1
+ {"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAWA,SAAS,UAAU,CAAC,MAAc,EAAE,QAAgB;IAClD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC3B,OAAO;QACL,OAAO,EAAE,MAAM;QACf,SAAS,EAAE,QAAQ;QACnB,IAAI,EAAE,IA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QAAQ;IACV,CAAC;CACF"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@powersync/service-module-mongodb-storage",
3
3
  "repository": "https://github.com/powersync-ja/powersync-service",
4
4
  "types": "dist/index.d.ts",
5
- "version": "0.0.0-dev-20250721150646",
5
+ "version": "0.0.0-dev-20250722083948",
6
6
  "main": "dist/index.js",
7
7
  "license": "FSL-1.1-Apache-2.0",
8
8
  "type": "module",
@@ -27,15 +27,15 @@
27
27
  "lru-cache": "^10.2.2",
28
28
  "ts-codec": "^1.3.0",
29
29
  "uuid": "^11.1.0",
30
- "@powersync/lib-service-mongodb": "0.0.0-dev-20250721150646",
31
- "@powersync/lib-services-framework": "0.0.0-dev-20250721150646",
32
- "@powersync/service-core": "0.0.0-dev-20250721150646",
33
- "@powersync/service-types": "0.0.0-dev-20250721150646",
30
+ "@powersync/lib-service-mongodb": "0.0.0-dev-20250722083948",
31
+ "@powersync/lib-services-framework": "0.0.0-dev-20250722083948",
32
+ "@powersync/service-core": "0.0.0-dev-20250722083948",
33
+ "@powersync/service-types": "0.0.0-dev-20250722083948",
34
34
  "@powersync/service-jsonbig": "0.17.10",
35
35
  "@powersync/service-sync-rules": "0.27.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@powersync/service-core-tests": "0.0.0-dev-20250721150646"
38
+ "@powersync/service-core-tests": "0.0.0-dev-20250722083948"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc -b",
@@ -5,10 +5,23 @@ import { PowerSyncMongo } from './implementation/db.js';
5
5
  import {
6
6
  ListCurrentConnections,
7
7
  ListCurrentConnectionsResponse,
8
- SdkConnectEventData,
8
+ SdkConnectBucketData,
9
9
  SdkDisconnectEventData
10
10
  } from '@powersync/service-types/dist/events.js';
11
11
 
12
+ function dateFilter(userId: string, clientId: string): mongo.Filter<mongo.Document> {
13
+ const date = new Date();
14
+ const year = date.getFullYear();
15
+ const month = date.getMonth() + 1;
16
+ const day = date.getDate();
17
+ return {
18
+ user_id: userId,
19
+ client_id: clientId,
20
+ $gte: new Date(year, month, day, 0, 0, 0),
21
+ $lt: new Date(year, month, day + 1, 0, 0, 0)
22
+ };
23
+ }
24
+
12
25
  export class MongoReportStorage implements storage.ReportStorageFactory {
13
26
  private readonly client: mongo.MongoClient;
14
27
  public readonly db: PowerSyncMongo;
@@ -50,11 +63,14 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
50
63
  };
51
64
  }
52
65
 
53
- async reportSdkConnect(data: SdkConnectEventData): Promise<void> {
66
+ async reportSdkConnect(data: SdkConnectBucketData): Promise<void> {
54
67
  await this.db.sdk_report_events.findOneAndUpdate(
55
- { _id: data.id },
68
+ dateFilter(data.user_id, data.client_id!),
56
69
  {
57
- $set: data.data
70
+ $set: data,
71
+ $unset: {
72
+ disconnect_at: ''
73
+ }
58
74
  },
59
75
  {
60
76
  upsert: true
@@ -62,17 +78,14 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
62
78
  );
63
79
  }
64
80
  async reportSdkDisconnect(data: SdkDisconnectEventData): Promise<void> {
65
- await this.db.sdk_report_events.findOneAndUpdate(
66
- { _id: data.id },
67
- {
68
- $set: {
69
- disconnect_at: data.data.disconnect_at
70
- },
71
- $unset: {
72
- jwt_exp: ''
73
- }
81
+ await this.db.sdk_report_events.findOneAndUpdate(dateFilter(data.user_id, data.client_id!), {
82
+ $set: {
83
+ disconnect_at: data.disconnect_at
84
+ },
85
+ $unset: {
86
+ jwt_exp: ''
74
87
  }
75
- );
88
+ });
76
89
  }
77
90
  async listCurrentConnections(data: event_types.InstanceRequest): Promise<ListCurrentConnectionsResponse> {
78
91
  const result = await this.db.sdk_report_events