@pluv/io 0.41.7 → 0.42.0

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.
@@ -1,9 +1,9 @@
1
1
 
2
- > @pluv/io@0.41.7 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.42.0 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@0.41.7 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@0.42.0 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- ESM dist/index.mjs 49.44 KB
16
- ESM ⚡️ Build success in 113ms
17
- CJS dist/index.js 51.61 KB
18
- CJS ⚡️ Build success in 116ms
15
+ ESM dist/index.mjs 49.97 KB
16
+ ESM ⚡️ Build success in 129ms
17
+ CJS dist/index.js 52.15 KB
18
+ CJS ⚡️ Build success in 157ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 2933ms
21
- DTS dist/index.d.mts 31.42 KB
22
- DTS dist/index.d.ts 31.42 KB
20
+ DTS ⚡️ Build success in 3067ms
21
+ DTS dist/index.d.mts 31.53 KB
22
+ DTS dist/index.d.ts 31.53 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.42.0
4
+
5
+ ### Patch Changes
6
+
7
+ - cf1529a: Each time garbage collection is run, a sync-state event will be emitted to connected sessions with info of currently connected users.
8
+ - @pluv/crdt@0.42.0
9
+ - @pluv/types@0.42.0
10
+
3
11
  ## 0.41.7
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -9,8 +9,9 @@ declare abstract class AbstractPersistence {
9
9
  abstract deleteUsers(room: string): Promise<void>;
10
10
  abstract getStorageState(room: string): Promise<string | null>;
11
11
  abstract getUser(room: string, connectionId: string): Promise<JsonObject | null>;
12
- abstract getUsers(room: string): Promise<readonly (JsonObject | null)[]>;
12
+ abstract getUsers(room: string): Promise<Map<[connectionId: string][0], JsonObject | null>>;
13
13
  abstract getUsersSize(room: string): Promise<number>;
14
+ abstract initialize(roomContext: any): AbstractPersistence;
14
15
  abstract setStorageState(room: string, state: string): Promise<void>;
15
16
  }
16
17
 
@@ -385,6 +386,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
385
386
  private _closeWebSockets;
386
387
  private _emitQuitters;
387
388
  private _emitRegistered;
389
+ private _emitSyncState;
388
390
  private _ensureDetached;
389
391
  private _getAbstractWs;
390
392
  private _getAuthorizedUser;
package/dist/index.d.ts CHANGED
@@ -9,8 +9,9 @@ declare abstract class AbstractPersistence {
9
9
  abstract deleteUsers(room: string): Promise<void>;
10
10
  abstract getStorageState(room: string): Promise<string | null>;
11
11
  abstract getUser(room: string, connectionId: string): Promise<JsonObject | null>;
12
- abstract getUsers(room: string): Promise<readonly (JsonObject | null)[]>;
12
+ abstract getUsers(room: string): Promise<Map<[connectionId: string][0], JsonObject | null>>;
13
13
  abstract getUsersSize(room: string): Promise<number>;
14
+ abstract initialize(roomContext: any): AbstractPersistence;
14
15
  abstract setStorageState(room: string, state: string): Promise<void>;
15
16
  }
16
17
 
@@ -385,6 +386,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
385
386
  private _closeWebSockets;
386
387
  private _emitQuitters;
387
388
  private _emitRegistered;
389
+ private _emitSyncState;
388
390
  private _ensureDetached;
389
391
  private _getAbstractWs;
390
392
  private _getAuthorizedUser;
package/dist/index.js CHANGED
@@ -145,9 +145,19 @@ var Persistence = class extends AbstractPersistence {
145
145
  return Promise.resolve(user != null ? user : null);
146
146
  }
147
147
  getUsers(room) {
148
- const users = this._users.get(room);
149
- if (!users) return Promise.resolve([]);
150
- return Promise.resolve(Array.from(users.values()));
148
+ return __async(this, null, function* () {
149
+ const users = this._users.get(room);
150
+ if (!users) return /* @__PURE__ */ new Map();
151
+ return users;
152
+ });
153
+ }
154
+ getUsersSize(room) {
155
+ return __async(this, null, function* () {
156
+ return this._users.size;
157
+ });
158
+ }
159
+ initialize(roomContext) {
160
+ return this;
151
161
  }
152
162
  setStorageState(room, state) {
153
163
  this._storages.set(room, state);
@@ -503,6 +513,7 @@ var IORoom = class {
503
513
  return __async(this, null, function* () {
504
514
  this._lastGarbageCollectMs = Date.now();
505
515
  this._emitQuitters();
516
+ this._emitSyncState();
506
517
  });
507
518
  }
508
519
  getSize() {
@@ -695,6 +706,17 @@ var IORoom = class {
695
706
  }
696
707
  });
697
708
  }
709
+ _emitSyncState() {
710
+ return __async(this, null, function* () {
711
+ const connectionIds = yield this._platform.persistence.getUsers(this.id).then((map) => Object.keys(map));
712
+ yield this._broadcast({
713
+ message: {
714
+ type: "$syncStateReceived",
715
+ data: { connectionIds }
716
+ }
717
+ });
718
+ });
719
+ }
698
720
  _ensureDetached() {
699
721
  if (this._platform._config.registrationMode === "detached") return;
700
722
  throw new Error("Platform must use detached mode");
@@ -1117,7 +1139,7 @@ var pickBy = (obj, by) => {
1117
1139
  };
1118
1140
 
1119
1141
  // src/version.generated.ts
1120
- var version = "0.41.7";
1142
+ var version = "0.42.0";
1121
1143
 
1122
1144
  // src/PluvServer.ts
1123
1145
  var PluvServer = class {
package/dist/index.mjs CHANGED
@@ -103,9 +103,19 @@ var Persistence = class extends AbstractPersistence {
103
103
  return Promise.resolve(user != null ? user : null);
104
104
  }
105
105
  getUsers(room) {
106
- const users = this._users.get(room);
107
- if (!users) return Promise.resolve([]);
108
- return Promise.resolve(Array.from(users.values()));
106
+ return __async(this, null, function* () {
107
+ const users = this._users.get(room);
108
+ if (!users) return /* @__PURE__ */ new Map();
109
+ return users;
110
+ });
111
+ }
112
+ getUsersSize(room) {
113
+ return __async(this, null, function* () {
114
+ return this._users.size;
115
+ });
116
+ }
117
+ initialize(roomContext) {
118
+ return this;
109
119
  }
110
120
  setStorageState(room, state) {
111
121
  this._storages.set(room, state);
@@ -461,6 +471,7 @@ var IORoom = class {
461
471
  return __async(this, null, function* () {
462
472
  this._lastGarbageCollectMs = Date.now();
463
473
  this._emitQuitters();
474
+ this._emitSyncState();
464
475
  });
465
476
  }
466
477
  getSize() {
@@ -653,6 +664,17 @@ var IORoom = class {
653
664
  }
654
665
  });
655
666
  }
667
+ _emitSyncState() {
668
+ return __async(this, null, function* () {
669
+ const connectionIds = yield this._platform.persistence.getUsers(this.id).then((map) => Object.keys(map));
670
+ yield this._broadcast({
671
+ message: {
672
+ type: "$syncStateReceived",
673
+ data: { connectionIds }
674
+ }
675
+ });
676
+ });
677
+ }
656
678
  _ensureDetached() {
657
679
  if (this._platform._config.registrationMode === "detached") return;
658
680
  throw new Error("Platform must use detached mode");
@@ -1075,7 +1097,7 @@ var pickBy = (obj, by) => {
1075
1097
  };
1076
1098
 
1077
1099
  // src/version.generated.ts
1078
- var version = "0.41.7";
1100
+ var version = "0.42.0";
1079
1101
 
1080
1102
  // src/PluvServer.ts
1081
1103
  var PluvServer = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.41.7",
3
+ "version": "0.42.0",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "jose": "^5.10.0",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.5",
24
- "@pluv/crdt": "^0.41.7",
25
- "@pluv/types": "^0.41.7"
24
+ "@pluv/crdt": "^0.42.0",
25
+ "@pluv/types": "^0.42.0"
26
26
  },
27
27
  "devDependencies": {
28
- "eslint": "^9.25.0",
28
+ "eslint": "^9.25.1",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.3",
32
- "@pluv/tsconfig": "^0.41.7",
33
- "eslint-config-pluv": "^0.41.7"
32
+ "@pluv/tsconfig": "^0.42.0",
33
+ "eslint-config-pluv": "^0.42.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
@@ -13,9 +13,11 @@ export abstract class AbstractPersistence {
13
13
 
14
14
  public abstract getUser(room: string, connectionId: string): Promise<JsonObject | null>;
15
15
 
16
- public abstract getUsers(room: string): Promise<readonly (JsonObject | null)[]>;
16
+ public abstract getUsers(room: string): Promise<Map<[connectionId: string][0], JsonObject | null>>;
17
17
 
18
18
  public abstract getUsersSize(room: string): Promise<number>;
19
19
 
20
+ public abstract initialize(roomContext: any): AbstractPersistence;
21
+
20
22
  public abstract setStorageState(room: string, state: string): Promise<void>;
21
23
  }
package/src/IORoom.ts CHANGED
@@ -256,6 +256,7 @@ export class IORoom<
256
256
  public async garbageCollect(): Promise<void> {
257
257
  this._lastGarbageCollectMs = Date.now();
258
258
  this._emitQuitters();
259
+ this._emitSyncState();
259
260
  }
260
261
 
261
262
  public getSize(): number {
@@ -507,6 +508,17 @@ export class IORoom<
507
508
  }
508
509
  }
509
510
 
511
+ private async _emitSyncState(): Promise<void> {
512
+ const connectionIds = await this._platform.persistence.getUsers(this.id).then((map) => Object.keys(map));
513
+
514
+ await this._broadcast({
515
+ message: {
516
+ type: "$syncStateReceived",
517
+ data: { connectionIds },
518
+ },
519
+ });
520
+ }
521
+
510
522
  private _ensureDetached(): void {
511
523
  if (this._platform._config.registrationMode === "detached") return;
512
524
 
@@ -57,12 +57,20 @@ export class Persistence extends AbstractPersistence {
57
57
  return Promise.resolve(user ?? null);
58
58
  }
59
59
 
60
- public getUsers(room: string): Promise<readonly (JsonObject | null)[]> {
60
+ public async getUsers(room: string): Promise<Map<string, JsonObject | null>> {
61
61
  const users = this._users.get(room);
62
62
 
63
- if (!users) return Promise.resolve([]);
63
+ if (!users) return new Map();
64
64
 
65
- return Promise.resolve(Array.from(users.values()));
65
+ return users;
66
+ }
67
+
68
+ public async getUsersSize(room: string): Promise<number> {
69
+ return this._users.size;
70
+ }
71
+
72
+ public initialize(roomContext: any): this {
73
+ return this;
66
74
  }
67
75
 
68
76
  public setStorageState(room: string, state: string): Promise<void> {
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.41.7'
2
+ export const version = '0.42.0'