@pluv/persistence-redis 5.0.1 → 5.0.2

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.
@@ -0,0 +1,30 @@
1
+ import { AbstractPersistence } from "@pluv/io";
2
+ import { JsonObject } from "@pluv/types";
3
+ import { Cluster, Redis } from "ioredis";
4
+ //#region src/PersistenceRedis.d.ts
5
+ type RedisClient = Cluster | Redis;
6
+ interface PersistenceRedisOptions {
7
+ client: RedisClient;
8
+ }
9
+ declare class PersistenceRedis extends AbstractPersistence {
10
+ private _client;
11
+ private _initialized;
12
+ constructor(options: PersistenceRedisOptions);
13
+ addUser(room: string, connectionId: string, user: JsonObject | null): Promise<void>;
14
+ deleteStorageState(room: string): Promise<void>;
15
+ deleteUser(room: string, connectionId: string): Promise<void>;
16
+ deleteUsers(room: string): Promise<void>;
17
+ getStorageState(room: string): Promise<string | null>;
18
+ setStorageState(room: string, state: string): Promise<void>;
19
+ getUser(room: string, connectionId: string): Promise<JsonObject | null>;
20
+ getUsers(room: string): Promise<Map<[connectionId: string][0], JsonObject | null>>;
21
+ getUsersSize(room: string): Promise<number>;
22
+ initialize(roomContext: {}): typeof this;
23
+ private _getClusterKey;
24
+ private _getRoomStorageKey;
25
+ private _getRoomUsersKey;
26
+ private _getRoomUsersUserKey;
27
+ }
28
+ //#endregion
29
+ export { PersistenceRedis, type RedisClient };
30
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/PersistenceRedis.ts"],"mappings":";;;;KAUY,cAAc,UAAU;UAEnB;EACb,QAAQ;;cAGC,yBAAyB;UAC1B;UACA;EAEI,YAAA,SAAS;EASR,QACT,cACA,sBACA,MAAM,oBACP;EAYU,mBAAmB,eAAe;EAQlC,WAAW,cAAc,uBAAuB;EAmBhD,YAAY,eAAe;EAiB3B,gBAAgB,eAAe;EAQ/B,gBAAgB,cAAc,gBAAgB;EAQ9C,QAAQ,cAAc,uBAAuB,QAAQ;EAUrD,SACT,eACD,QAAQ,KAAK,0BAA0B;EAqB7B,aAAa,eAAe;EAQlC,WAAW;UAOV;UAIA;UAIA;UAIA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,104 @@
1
+ import { AbstractPersistence } from "@pluv/io";
2
+ //#region src/utils/partitionByLength.ts
3
+ const partitionByLength = (arr, length) => {
4
+ if (!arr.length) return [];
5
+ const head = arr.slice(0, length);
6
+ const tail = arr.slice(length);
7
+ return [head, ...partitionByLength(tail, length)];
8
+ };
9
+ //#endregion
10
+ //#region src/PersistenceRedis.ts
11
+ const DELIMITER = ":::";
12
+ const HASH_TAG = "{PluvPersistenceRedis}";
13
+ const GET_USERS_CONCURRENCY = 4;
14
+ var PersistenceRedis = class PersistenceRedis extends AbstractPersistence {
15
+ _client;
16
+ _initialized = null;
17
+ constructor(options) {
18
+ super();
19
+ const { client } = options;
20
+ this._client = client;
21
+ this._initialized = options._initialized;
22
+ }
23
+ async addUser(room, connectionId, user) {
24
+ if (!this._initialized) return;
25
+ await this._initialized;
26
+ await this._client.multi().sadd(this._getRoomUsersKey(room), connectionId).set(this._getRoomUsersUserKey(room, connectionId), JSON.stringify(user)).exec();
27
+ }
28
+ async deleteStorageState(room) {
29
+ if (!this._initialized) return;
30
+ await this._initialized;
31
+ await this._client.del(this._getRoomStorageKey(room));
32
+ }
33
+ async deleteUser(room, connectionId) {
34
+ if (!this._initialized) return;
35
+ await this._initialized;
36
+ const size = await this.getUsersSize(room);
37
+ let multi = this._client.multi().srem(this._getRoomUsersKey(room), connectionId).del(this._getRoomUsersUserKey(room, connectionId));
38
+ if (size === 1) multi = multi.del(this._getRoomStorageKey(room)).del(this._getRoomUsersKey(room));
39
+ await multi.exec();
40
+ }
41
+ async deleteUsers(room) {
42
+ if (!this._initialized) return;
43
+ await this._initialized;
44
+ await (await this._client.smembers(this._getRoomUsersKey(room))).reduce((commands, connectionId) => {
45
+ return commands.del(this._getRoomUsersUserKey(room, connectionId));
46
+ }, this._client.multi().del(this._getRoomUsersKey(room))).exec();
47
+ }
48
+ async getStorageState(room) {
49
+ if (!this._initialized) return null;
50
+ await this._initialized;
51
+ return await this._client.get(this._getRoomStorageKey(room));
52
+ }
53
+ async setStorageState(room, state) {
54
+ if (!this._initialized) return;
55
+ await this._initialized;
56
+ await this._client.set(this._getRoomStorageKey(room), state);
57
+ }
58
+ async getUser(room, connectionId) {
59
+ if (!this._initialized) return null;
60
+ await this._initialized;
61
+ const data = await this._client.get(this._getRoomUsersUserKey(room, connectionId));
62
+ return !data ? null : JSON.parse(data);
63
+ }
64
+ async getUsers(room) {
65
+ if (!this._initialized) return /* @__PURE__ */ new Map();
66
+ await this._initialized;
67
+ const members = await this._client.smembers(this._getRoomUsersKey(room));
68
+ return await partitionByLength(members, GET_USERS_CONCURRENCY).reduce(async (promise, partition) => {
69
+ const map = await promise;
70
+ const promises = partition.map(async (connectionId) => {
71
+ map.set(connectionId, await this.getUser(room, connectionId));
72
+ });
73
+ await Promise.all(promises);
74
+ return map;
75
+ }, Promise.resolve(/* @__PURE__ */ new Map()));
76
+ }
77
+ async getUsersSize(room) {
78
+ if (!this._initialized) return 0;
79
+ await this._initialized;
80
+ return await this._client.scard(this._getRoomUsersKey(room));
81
+ }
82
+ initialize(roomContext) {
83
+ return new PersistenceRedis({
84
+ client: this._client,
85
+ _initialized: Promise.resolve(true)
86
+ });
87
+ }
88
+ _getClusterKey(key) {
89
+ return `${HASH_TAG}${key}`;
90
+ }
91
+ _getRoomStorageKey(room) {
92
+ return this._getClusterKey(`room_storage${DELIMITER}${room}`);
93
+ }
94
+ _getRoomUsersKey(room) {
95
+ return this._getClusterKey(`room_users${DELIMITER}${room}`);
96
+ }
97
+ _getRoomUsersUserKey(room, connectionId) {
98
+ return this._getClusterKey(`${this._getRoomUsersKey(room)}${DELIMITER}${connectionId}`);
99
+ }
100
+ };
101
+ //#endregion
102
+ export { PersistenceRedis };
103
+
104
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/partitionByLength.ts","../src/PersistenceRedis.ts"],"sourcesContent":["export const partitionByLength = <T>(\n arr: readonly T[] | T[],\n length: number,\n): readonly (readonly T[])[] => {\n if (!arr.length) return [];\n\n const head = arr.slice(0, length);\n const tail = arr.slice(length);\n\n return [head, ...partitionByLength(tail, length)];\n};\n","import { AbstractPersistence } from \"@pluv/io\";\nimport type { JsonObject } from \"@pluv/types\";\nimport type { Cluster, Redis } from \"ioredis\";\nimport { partitionByLength } from \"./utils\";\n\nconst DELIMITER = \":::\";\nconst HASH_TAG = \"{PluvPersistenceRedis}\";\n\nconst GET_USERS_CONCURRENCY = 4;\n\nexport type RedisClient = Cluster | Redis;\n\nexport interface PersistenceRedisOptions {\n client: RedisClient;\n}\n\nexport class PersistenceRedis extends AbstractPersistence {\n private _client: RedisClient;\n private _initialized: Promise<true> | null = null;\n\n constructor(options: PersistenceRedisOptions) {\n super();\n\n const { client } = options;\n\n this._client = client;\n this._initialized = (options as any)._initialized;\n }\n\n public async addUser(\n room: string,\n connectionId: string,\n user: JsonObject | null,\n ): Promise<void> {\n if (!this._initialized) return;\n\n await this._initialized;\n\n await this._client\n .multi()\n .sadd(this._getRoomUsersKey(room), connectionId)\n .set(this._getRoomUsersUserKey(room, connectionId), JSON.stringify(user))\n .exec();\n }\n\n public async deleteStorageState(room: string): Promise<void> {\n if (!this._initialized) return;\n\n await this._initialized;\n\n await this._client.del(this._getRoomStorageKey(room));\n }\n\n public async deleteUser(room: string, connectionId: string): Promise<void> {\n if (!this._initialized) return;\n\n await this._initialized;\n\n const size = await this.getUsersSize(room);\n\n let multi = this._client\n .multi()\n .srem(this._getRoomUsersKey(room), connectionId)\n .del(this._getRoomUsersUserKey(room, connectionId));\n\n if (size === 1) {\n multi = multi.del(this._getRoomStorageKey(room)).del(this._getRoomUsersKey(room));\n }\n\n await multi.exec();\n }\n\n public async deleteUsers(room: string): Promise<void> {\n if (!this._initialized) return;\n\n await this._initialized;\n\n const members = await this._client.smembers(this._getRoomUsersKey(room));\n\n await members\n .reduce(\n (commands, connectionId) => {\n return commands.del(this._getRoomUsersUserKey(room, connectionId));\n },\n this._client.multi().del(this._getRoomUsersKey(room)),\n )\n .exec();\n }\n\n public async getStorageState(room: string): Promise<string | null> {\n if (!this._initialized) return null;\n\n await this._initialized;\n\n return await this._client.get(this._getRoomStorageKey(room));\n }\n\n public async setStorageState(room: string, state: string): Promise<void> {\n if (!this._initialized) return;\n\n await this._initialized;\n\n await this._client.set(this._getRoomStorageKey(room), state);\n }\n\n public async getUser(room: string, connectionId: string): Promise<JsonObject | null> {\n if (!this._initialized) return null;\n\n await this._initialized;\n\n const data = await this._client.get(this._getRoomUsersUserKey(room, connectionId));\n\n return !data ? null : JSON.parse(data);\n }\n\n public async getUsers(\n room: string,\n ): Promise<Map<[connectionId: string][0], JsonObject | null>> {\n if (!this._initialized) return new Map();\n\n await this._initialized;\n\n const members = await this._client.smembers(this._getRoomUsersKey(room));\n const partitions = partitionByLength(members, GET_USERS_CONCURRENCY);\n\n return await partitions.reduce(async (promise, partition) => {\n const map = await promise;\n\n const promises = partition.map(async (connectionId) => {\n map.set(connectionId, await this.getUser(room, connectionId));\n });\n\n await Promise.all(promises);\n\n return map;\n }, Promise.resolve(new Map<string, JsonObject | null>()));\n }\n\n public async getUsersSize(room: string): Promise<number> {\n if (!this._initialized) return 0;\n\n await this._initialized;\n\n return await this._client.scard(this._getRoomUsersKey(room));\n }\n\n public initialize(roomContext: {}): typeof this {\n return new PersistenceRedis({\n client: this._client,\n ...{ _initialized: Promise.resolve(true as const) },\n }) as typeof this;\n }\n\n private _getClusterKey(key: string): string {\n return `${HASH_TAG}${key}`;\n }\n\n private _getRoomStorageKey(room: string): string {\n return this._getClusterKey(`room_storage${DELIMITER}${room}`);\n }\n\n private _getRoomUsersKey(room: string): string {\n return this._getClusterKey(`room_users${DELIMITER}${room}`);\n }\n\n private _getRoomUsersUserKey(room: string, connectionId: string): string {\n return this._getClusterKey(`${this._getRoomUsersKey(room)}${DELIMITER}${connectionId}`);\n }\n}\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/persistence-redis",
3
- "version": "5.0.1",
3
+ "version": "5.0.2",
4
4
  "description": "@pluv/io crdt storage persistence for node.js",
5
5
  "author": {
6
6
  "email": "david@pluv.io",
@@ -16,21 +16,24 @@
16
16
  },
17
17
  "type": "module",
18
18
  "types": "./dist/index.d.mts",
19
+ "files": [
20
+ "dist"
21
+ ],
19
22
  "publishConfig": {
20
23
  "access": "public"
21
24
  },
22
25
  "dependencies": {
23
- "@pluv/io": "^5.0.1",
24
- "@pluv/types": "^5.0.1",
26
+ "@pluv/io": "^5.0.2",
27
+ "@pluv/types": "^5.0.2",
25
28
  "@types/node": "^26.2.0"
26
29
  },
27
30
  "peerDependencies": {
28
31
  "ioredis": "^5.0.0"
29
32
  },
30
33
  "devDependencies": {
31
- "@pluv/tsconfig": "^5.0.1",
34
+ "@pluv/tsconfig": "^5.0.2",
32
35
  "eslint": "^10.9.0",
33
- "eslint-config-pluv": "^5.0.1",
36
+ "eslint-config-pluv": "^5.0.2",
34
37
  "ioredis": "^6.0.0",
35
38
  "tsdown": "0.22.14",
36
39
  "typescript": "^5.9.3"
package/CHANGELOG.md DELETED
@@ -1,882 +0,0 @@
1
- # @pluv/persistence-redis
2
-
3
- ## 5.0.1
4
-
5
- ### Patch Changes
6
-
7
- - @pluv/io@5.0.1
8
- - @pluv/types@5.0.1
9
-
10
- ## 5.0.0
11
-
12
- ### Patch Changes
13
-
14
- - @pluv/io@5.0.0
15
- - @pluv/types@5.0.0
16
-
17
- ## 4.1.0
18
-
19
- ### Patch Changes
20
-
21
- - @pluv/io@4.1.0
22
- - @pluv/types@4.1.0
23
-
24
- ## 4.0.2
25
-
26
- ### Patch Changes
27
-
28
- - e1913b3: Upgraded internal dependencies
29
- - Updated dependencies [e1913b3]
30
- - @pluv/types@4.0.2
31
- - @pluv/io@4.0.2
32
-
33
- ## 4.0.1
34
-
35
- ### Patch Changes
36
-
37
- - @pluv/io@4.0.1
38
- - @pluv/types@4.0.1
39
-
40
- ## 4.0.0
41
-
42
- ### Major Changes
43
-
44
- - df5c39c: Update all packages to be ESM only.
45
-
46
- ### Minor Changes
47
-
48
- - 037074e: Migrated build process from tsup to tsdown.
49
-
50
- ### Patch Changes
51
-
52
- - 2eb5def: Bumped dependencies.
53
- - Updated dependencies [2eb5def]
54
- - Updated dependencies [df5c39c]
55
- - Updated dependencies [c142910]
56
- - Updated dependencies [037074e]
57
- - Updated dependencies [07e2a1e]
58
- - @pluv/types@4.0.0
59
- - @pluv/io@4.0.0
60
-
61
- ## 3.2.2
62
-
63
- ### Patch Changes
64
-
65
- - Updated dependencies [8665dbe]
66
- - @pluv/types@3.2.2
67
- - @pluv/io@3.2.2
68
-
69
- ## 3.2.1
70
-
71
- ### Patch Changes
72
-
73
- - @pluv/io@3.2.1
74
- - @pluv/types@3.2.1
75
-
76
- ## 3.2.0
77
-
78
- ### Patch Changes
79
-
80
- - Updated dependencies [6d2b257]
81
- - @pluv/io@3.2.0
82
- - @pluv/types@3.2.0
83
-
84
- ## 3.1.7
85
-
86
- ### Patch Changes
87
-
88
- - Updated dependencies [f1d56d9]
89
- - @pluv/io@3.1.7
90
- - @pluv/types@3.1.7
91
-
92
- ## 3.1.6
93
-
94
- ### Patch Changes
95
-
96
- - @pluv/io@3.1.6
97
- - @pluv/types@3.1.6
98
-
99
- ## 3.1.5
100
-
101
- ### Patch Changes
102
-
103
- - @pluv/io@3.1.5
104
- - @pluv/types@3.1.5
105
-
106
- ## 3.1.4
107
-
108
- ### Patch Changes
109
-
110
- - @pluv/io@3.1.4
111
- - @pluv/types@3.1.4
112
-
113
- ## 3.1.3
114
-
115
- ### Patch Changes
116
-
117
- - Updated dependencies [651a9f8]
118
- - @pluv/io@3.1.3
119
- - @pluv/types@3.1.3
120
-
121
- ## 3.1.2
122
-
123
- ### Patch Changes
124
-
125
- - Updated dependencies [8f138aa]
126
- - @pluv/io@3.1.2
127
- - @pluv/types@3.1.2
128
-
129
- ## 3.1.1
130
-
131
- ### Patch Changes
132
-
133
- - Updated dependencies [7b719bf]
134
- - @pluv/io@3.1.1
135
- - @pluv/types@3.1.1
136
-
137
- ## 3.1.0
138
-
139
- ### Patch Changes
140
-
141
- - Updated dependencies [a40f4dc]
142
- - @pluv/io@3.1.0
143
- - @pluv/types@3.1.0
144
-
145
- ## 3.0.0
146
-
147
- ### Patch Changes
148
-
149
- - @pluv/io@3.0.0
150
- - @pluv/types@3.0.0
151
-
152
- ## 2.3.1
153
-
154
- ### Patch Changes
155
-
156
- - @pluv/io@2.3.1
157
- - @pluv/types@2.3.1
158
-
159
- ## 2.3.0
160
-
161
- ### Patch Changes
162
-
163
- - @pluv/io@2.3.0
164
- - @pluv/types@2.3.0
165
-
166
- ## 2.2.8
167
-
168
- ### Patch Changes
169
-
170
- - Updated dependencies [b60ccd8]
171
- - @pluv/io@2.2.8
172
- - @pluv/types@2.2.8
173
-
174
- ## 2.2.7
175
-
176
- ### Patch Changes
177
-
178
- - Updated dependencies [ec2717b]
179
- - @pluv/io@2.2.7
180
- - @pluv/types@2.2.7
181
-
182
- ## 2.2.6
183
-
184
- ### Patch Changes
185
-
186
- - @pluv/io@2.2.6
187
- - @pluv/types@2.2.6
188
-
189
- ## 2.2.5
190
-
191
- ### Patch Changes
192
-
193
- - @pluv/io@2.2.5
194
- - @pluv/types@2.2.5
195
-
196
- ## 2.2.4
197
-
198
- ### Patch Changes
199
-
200
- - @pluv/io@2.2.4
201
- - @pluv/types@2.2.4
202
-
203
- ## 2.2.3
204
-
205
- ### Patch Changes
206
-
207
- - @pluv/io@2.2.3
208
- - @pluv/types@2.2.3
209
-
210
- ## 2.2.2
211
-
212
- ### Patch Changes
213
-
214
- - @pluv/io@2.2.2
215
- - @pluv/types@2.2.2
216
-
217
- ## 2.2.1
218
-
219
- ### Patch Changes
220
-
221
- - @pluv/io@2.2.1
222
- - @pluv/types@2.2.1
223
-
224
- ## 2.2.0
225
-
226
- ### Patch Changes
227
-
228
- - Updated dependencies [cb660cd]
229
- - @pluv/io@2.2.0
230
- - @pluv/types@2.2.0
231
-
232
- ## 2.1.0
233
-
234
- ### Patch Changes
235
-
236
- - @pluv/io@2.1.0
237
- - @pluv/types@2.1.0
238
-
239
- ## 2.0.2
240
-
241
- ### Patch Changes
242
-
243
- - @pluv/io@2.0.2
244
- - @pluv/types@2.0.2
245
-
246
- ## 2.0.1
247
-
248
- ### Patch Changes
249
-
250
- - @pluv/io@2.0.1
251
- - @pluv/types@2.0.1
252
-
253
- ## 2.0.0
254
-
255
- ### Patch Changes
256
-
257
- - Updated dependencies [047a1d8]
258
- - @pluv/types@2.0.0
259
- - @pluv/io@2.0.0
260
-
261
- ## 1.0.2
262
-
263
- ### Patch Changes
264
-
265
- - @pluv/io@1.0.2
266
- - @pluv/types@1.0.2
267
-
268
- ## 1.0.1
269
-
270
- ### Patch Changes
271
-
272
- - Updated dependencies [c583be9]
273
- - @pluv/io@1.0.1
274
- - @pluv/types@1.0.1
275
-
276
- ## 1.0.0
277
-
278
- ### Major Changes
279
-
280
- - af94706: pluv.io is now stable and production ready!
281
-
282
- With this v1 release, pluv.io will now follow [semantic versioning](https://semver.org/) with more comprehensive release notes for future changes to the library.
283
-
284
- Checkout the [full documentation here](https://pluv.io/docs/introduction) to get started today!
285
-
286
- ### Patch Changes
287
-
288
- - Updated dependencies [af94706]
289
- - @pluv/io@1.0.0
290
- - @pluv/types@1.0.0
291
-
292
- ## 0.44.2
293
-
294
- ### Patch Changes
295
-
296
- - @pluv/io@0.44.2
297
- - @pluv/types@0.44.2
298
-
299
- ## 0.44.1
300
-
301
- ### Patch Changes
302
-
303
- - @pluv/io@0.44.1
304
- - @pluv/types@0.44.1
305
-
306
- ## 0.44.0
307
-
308
- ### Patch Changes
309
-
310
- - @pluv/io@0.44.0
311
- - @pluv/types@0.44.0
312
-
313
- ## 0.43.0
314
-
315
- ### Patch Changes
316
-
317
- - Updated dependencies [e60a677]
318
- - Updated dependencies [0063e80]
319
- - Updated dependencies [244a973]
320
- - Updated dependencies [4b0fbb3]
321
- - @pluv/io@0.43.0
322
- - @pluv/types@0.43.0
323
-
324
- ## 0.42.0
325
-
326
- ### Minor Changes
327
-
328
- - 4ce32ee: **BREAKING** `Persistence.getUsers` now returns a map of connection id strings to user JSON objects instead of an array of user JSON objects. This change is intended to be internal only and generally non-breaking.
329
-
330
- ### Patch Changes
331
-
332
- - Updated dependencies [cf1529a]
333
- - @pluv/io@0.42.0
334
- - @pluv/types@0.42.0
335
-
336
- ## 0.41.7
337
-
338
- ### Patch Changes
339
-
340
- - @pluv/io@0.41.7
341
- - @pluv/types@0.41.7
342
-
343
- ## 0.41.6
344
-
345
- ### Patch Changes
346
-
347
- - @pluv/io@0.41.6
348
- - @pluv/types@0.41.6
349
-
350
- ## 0.41.5
351
-
352
- ### Patch Changes
353
-
354
- - @pluv/io@0.41.5
355
- - @pluv/types@0.41.5
356
-
357
- ## 0.41.4
358
-
359
- ### Patch Changes
360
-
361
- - @pluv/io@0.41.4
362
- - @pluv/types@0.41.4
363
-
364
- ## 0.41.3
365
-
366
- ### Patch Changes
367
-
368
- - Updated dependencies [49051c0]
369
- - @pluv/io@0.41.3
370
- - @pluv/types@0.41.3
371
-
372
- ## 0.41.2
373
-
374
- ### Patch Changes
375
-
376
- - @pluv/io@0.41.2
377
- - @pluv/types@0.41.2
378
-
379
- ## 0.41.1
380
-
381
- ### Patch Changes
382
-
383
- - @pluv/io@0.41.1
384
- - @pluv/types@0.41.1
385
-
386
- ## 0.41.0
387
-
388
- ### Patch Changes
389
-
390
- - Updated dependencies [73adf21]
391
- - Updated dependencies [f02a430]
392
- - Updated dependencies [0b908b3]
393
- - Updated dependencies [6422f3b]
394
- - Updated dependencies [555b88d]
395
- - Updated dependencies [a663c65]
396
- - Updated dependencies [555b88d]
397
- - @pluv/io@0.41.0
398
- - @pluv/types@0.41.0
399
-
400
- ## 0.40.2
401
-
402
- ### Patch Changes
403
-
404
- - @pluv/io@0.40.2
405
- - @pluv/types@0.40.2
406
-
407
- ## 0.40.1
408
-
409
- ### Patch Changes
410
-
411
- - @pluv/io@0.40.1
412
- - @pluv/types@0.40.1
413
-
414
- ## 0.40.0
415
-
416
- ### Patch Changes
417
-
418
- - @pluv/io@0.40.0
419
- - @pluv/types@0.40.0
420
-
421
- ## 0.39.1
422
-
423
- ### Patch Changes
424
-
425
- - @pluv/io@0.39.1
426
- - @pluv/types@0.39.1
427
-
428
- ## 0.39.0
429
-
430
- ### Patch Changes
431
-
432
- - Updated dependencies [fe6e239]
433
- - Updated dependencies [737d508]
434
- - @pluv/io@0.39.0
435
- - @pluv/types@0.39.0
436
-
437
- ## 0.38.14
438
-
439
- ### Patch Changes
440
-
441
- - @pluv/io@0.38.14
442
- - @pluv/types@0.38.14
443
-
444
- ## 0.38.13
445
-
446
- ### Patch Changes
447
-
448
- - Updated dependencies [809afd3]
449
- - @pluv/io@0.38.13
450
- - @pluv/types@0.38.13
451
-
452
- ## 0.38.12
453
-
454
- ### Patch Changes
455
-
456
- - @pluv/io@0.38.12
457
- - @pluv/types@0.38.12
458
-
459
- ## 0.38.11
460
-
461
- ### Patch Changes
462
-
463
- - @pluv/io@0.38.11
464
- - @pluv/types@0.38.11
465
-
466
- ## 0.38.10
467
-
468
- ### Patch Changes
469
-
470
- - @pluv/io@0.38.10
471
- - @pluv/types@0.38.10
472
-
473
- ## 0.38.9
474
-
475
- ### Patch Changes
476
-
477
- - @pluv/io@0.38.9
478
- - @pluv/types@0.38.9
479
-
480
- ## 0.38.8
481
-
482
- ### Patch Changes
483
-
484
- - @pluv/io@0.38.8
485
- - @pluv/types@0.38.8
486
-
487
- ## 0.38.7
488
-
489
- ### Patch Changes
490
-
491
- - @pluv/io@0.38.7
492
- - @pluv/types@0.38.7
493
-
494
- ## 0.38.6
495
-
496
- ### Patch Changes
497
-
498
- - @pluv/io@0.38.6
499
- - @pluv/types@0.38.6
500
-
501
- ## 0.38.5
502
-
503
- ### Patch Changes
504
-
505
- - @pluv/io@0.38.5
506
- - @pluv/types@0.38.5
507
-
508
- ## 0.38.4
509
-
510
- ### Patch Changes
511
-
512
- - @pluv/io@0.38.4
513
- - @pluv/types@0.38.4
514
-
515
- ## 0.38.3
516
-
517
- ### Patch Changes
518
-
519
- - Updated dependencies [8346273]
520
- - @pluv/io@0.38.3
521
- - @pluv/types@0.38.3
522
-
523
- ## 0.38.2
524
-
525
- ### Patch Changes
526
-
527
- - Updated dependencies [039cd64]
528
- - @pluv/io@0.38.2
529
- - @pluv/types@0.38.2
530
-
531
- ## 0.38.1
532
-
533
- ### Patch Changes
534
-
535
- - @pluv/io@0.38.1
536
- - @pluv/types@0.38.1
537
-
538
- ## 0.38.0
539
-
540
- ### Patch Changes
541
-
542
- - Updated dependencies [f4ceca3]
543
- - @pluv/types@0.38.0
544
- - @pluv/io@0.38.0
545
-
546
- ## 0.37.7
547
-
548
- ### Patch Changes
549
-
550
- - @pluv/io@0.37.7
551
- - @pluv/types@0.37.7
552
-
553
- ## 0.37.6
554
-
555
- ### Patch Changes
556
-
557
- - Updated dependencies [3a874f1]
558
- - @pluv/io@0.37.6
559
- - @pluv/types@0.37.6
560
-
561
- ## 0.37.5
562
-
563
- ### Patch Changes
564
-
565
- - Updated dependencies [9a9ecee]
566
- - @pluv/io@0.37.5
567
- - @pluv/types@0.37.5
568
-
569
- ## 0.37.4
570
-
571
- ### Patch Changes
572
-
573
- - @pluv/io@0.37.4
574
- - @pluv/types@0.37.4
575
-
576
- ## 0.37.3
577
-
578
- ### Patch Changes
579
-
580
- - @pluv/io@0.37.3
581
- - @pluv/types@0.37.3
582
-
583
- ## 0.37.2
584
-
585
- ### Patch Changes
586
-
587
- - @pluv/io@0.37.2
588
- - @pluv/types@0.37.2
589
-
590
- ## 0.37.1
591
-
592
- ### Patch Changes
593
-
594
- - @pluv/io@0.37.1
595
- - @pluv/types@0.37.1
596
-
597
- ## 0.37.0
598
-
599
- ### Patch Changes
600
-
601
- - Updated dependencies [9b74abb]
602
- - @pluv/io@0.37.0
603
- - @pluv/types@0.37.0
604
-
605
- ## 0.36.0
606
-
607
- ### Patch Changes
608
-
609
- - @pluv/io@0.36.0
610
- - @pluv/types@0.36.0
611
-
612
- ## 0.35.4
613
-
614
- ### Patch Changes
615
-
616
- - Updated dependencies [5d3a56f]
617
- - @pluv/io@0.35.4
618
- - @pluv/types@0.35.4
619
-
620
- ## 0.35.3
621
-
622
- ### Patch Changes
623
-
624
- - @pluv/io@0.35.3
625
- - @pluv/types@0.35.3
626
-
627
- ## 0.35.2
628
-
629
- ### Patch Changes
630
-
631
- - Updated dependencies [81cb692]
632
- - @pluv/types@0.35.2
633
- - @pluv/io@0.35.2
634
-
635
- ## 0.35.1
636
-
637
- ### Patch Changes
638
-
639
- - @pluv/io@0.35.1
640
- - @pluv/types@0.35.1
641
-
642
- ## 0.35.0
643
-
644
- ### Patch Changes
645
-
646
- - Updated dependencies [c9073ad]
647
- - @pluv/io@0.35.0
648
- - @pluv/types@0.35.0
649
-
650
- ## 0.34.1
651
-
652
- ### Patch Changes
653
-
654
- - Updated dependencies [d639427]
655
- - @pluv/io@0.34.1
656
- - @pluv/types@0.34.1
657
-
658
- ## 0.34.0
659
-
660
- ### Patch Changes
661
-
662
- - Updated dependencies [0c920ea]
663
- - Updated dependencies [70af3b2]
664
- - @pluv/io@0.34.0
665
- - @pluv/types@0.34.0
666
-
667
- ## 0.33.0
668
-
669
- ### Patch Changes
670
-
671
- - @pluv/io@0.33.0
672
- - @pluv/types@0.33.0
673
-
674
- ## 0.32.9
675
-
676
- ### Patch Changes
677
-
678
- - @pluv/io@0.32.9
679
- - @pluv/types@0.32.9
680
-
681
- ## 0.32.8
682
-
683
- ### Patch Changes
684
-
685
- - Updated dependencies [e659f8a]
686
- - @pluv/io@0.32.8
687
- - @pluv/types@0.32.8
688
-
689
- ## 0.32.7
690
-
691
- ### Patch Changes
692
-
693
- - @pluv/io@0.32.7
694
- - @pluv/types@0.32.7
695
-
696
- ## 0.32.6
697
-
698
- ### Patch Changes
699
-
700
- - Updated dependencies [c0956e7]
701
- - @pluv/io@0.32.6
702
- - @pluv/types@0.32.6
703
-
704
- ## 0.32.5
705
-
706
- ### Patch Changes
707
-
708
- - @pluv/io@0.32.5
709
- - @pluv/types@0.32.5
710
-
711
- ## 0.32.4
712
-
713
- ### Patch Changes
714
-
715
- - @pluv/io@0.32.4
716
- - @pluv/types@0.32.4
717
-
718
- ## 0.32.3
719
-
720
- ### Patch Changes
721
-
722
- - Updated dependencies [bb21274]
723
- - @pluv/io@0.32.3
724
- - @pluv/types@0.32.3
725
-
726
- ## 0.32.2
727
-
728
- ### Patch Changes
729
-
730
- - Updated dependencies [890d45b]
731
- - @pluv/io@0.32.2
732
- - @pluv/types@0.32.2
733
-
734
- ## 0.32.1
735
-
736
- ### Patch Changes
737
-
738
- - @pluv/io@0.32.1
739
- - @pluv/types@0.32.1
740
-
741
- ## 0.32.0
742
-
743
- ### Patch Changes
744
-
745
- - Updated dependencies [cde5305]
746
- - @pluv/io@0.32.0
747
- - @pluv/types@0.32.0
748
-
749
- ## 0.31.0
750
-
751
- ### Patch Changes
752
-
753
- - Updated dependencies [b3c31d7]
754
- - @pluv/io@0.31.0
755
- - @pluv/types@0.31.0
756
-
757
- ## 0.30.2
758
-
759
- ### Patch Changes
760
-
761
- - @pluv/io@0.30.2
762
- - @pluv/types@0.30.2
763
-
764
- ## 0.30.1
765
-
766
- ### Patch Changes
767
-
768
- - Updated dependencies [b9c3633]
769
- - @pluv/io@0.30.1
770
- - @pluv/types@0.30.1
771
-
772
- ## 0.30.0
773
-
774
- ### Patch Changes
775
-
776
- - Updated dependencies [7246a9e]
777
- - @pluv/io@0.30.0
778
- - @pluv/types@0.30.0
779
-
780
- ## 0.29.0
781
-
782
- ### Patch Changes
783
-
784
- - @pluv/io@0.29.0
785
- - @pluv/types@0.29.0
786
-
787
- ## 0.28.0
788
-
789
- ### Patch Changes
790
-
791
- - @pluv/io@0.28.0
792
- - @pluv/types@0.28.0
793
-
794
- ## 0.27.0
795
-
796
- ### Patch Changes
797
-
798
- - Updated dependencies [19ed36c]
799
- - Updated dependencies [e309b0b]
800
- - @pluv/io@0.27.0
801
- - @pluv/types@0.27.0
802
-
803
- ## 0.26.0
804
-
805
- ### Patch Changes
806
-
807
- - @pluv/io@0.26.0
808
- - @pluv/types@0.26.0
809
-
810
- ## 0.25.4
811
-
812
- ### Patch Changes
813
-
814
- - Updated dependencies [7a9080c]
815
- - @pluv/io@0.25.4
816
- - @pluv/types@0.25.4
817
-
818
- ## 0.25.3
819
-
820
- ### Patch Changes
821
-
822
- - Updated dependencies [50d9b96]
823
- - @pluv/io@0.25.3
824
- - @pluv/types@0.25.3
825
-
826
- ## 0.25.2
827
-
828
- ### Patch Changes
829
-
830
- - Updated dependencies [60a0bf1]
831
- - @pluv/io@0.25.2
832
- - @pluv/types@0.25.2
833
-
834
- ## 0.25.1
835
-
836
- ### Patch Changes
837
-
838
- - Updated dependencies [3925f7c]
839
- - @pluv/io@0.25.1
840
- - @pluv/types@0.25.1
841
-
842
- ## 0.25.0
843
-
844
- ### Minor Changes
845
-
846
- - 9db06ba: **BREAKING **
847
-
848
- Fixed typos `persistance` to `persistence`.
849
-
850
- This does mean that all properties referencing `persistance` will need to be fixed. Examples below:
851
-
852
- ```bash
853
- # Re-install @pluv/persistence-redis
854
- pnpm uninstall @pluv/persistance-redis
855
- pnpm install @pluv/persistence-redis
856
- ```
857
-
858
- ```ts
859
- // Before
860
- createIO({
861
- platform: platformNode({
862
- persistance: new PersistanceRedis(/* ... */),
863
- }),
864
- });
865
-
866
- // After
867
- createIO({
868
- platform: platformNode({
869
- persistence: new PersistenceRedis(/* ... */),
870
- }),
871
- });
872
- ```
873
-
874
- `@pluv/persistance-redis` has been deprecated for `@pluv/persistence-redis`.
875
-
876
- ### Patch Changes
877
-
878
- - Updated dependencies [4e078ca]
879
- - Updated dependencies [f556d30]
880
- - Updated dependencies [9db06ba]
881
- - @pluv/io@0.25.0
882
- - @pluv/types@0.25.0
package/eslint.config.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { config } from "eslint-config-pluv/base";
2
-
3
- /** @type {import("eslint").Linter.Config} */
4
- export default config;
@@ -1,169 +0,0 @@
1
- import { AbstractPersistence } from "@pluv/io";
2
- import type { JsonObject } from "@pluv/types";
3
- import type { Cluster, Redis } from "ioredis";
4
- import { partitionByLength } from "./utils";
5
-
6
- const DELIMITER = ":::";
7
- const HASH_TAG = "{PluvPersistenceRedis}";
8
-
9
- const GET_USERS_CONCURRENCY = 4;
10
-
11
- export type RedisClient = Cluster | Redis;
12
-
13
- export interface PersistenceRedisOptions {
14
- client: RedisClient;
15
- }
16
-
17
- export class PersistenceRedis extends AbstractPersistence {
18
- private _client: RedisClient;
19
- private _initialized: Promise<true> | null = null;
20
-
21
- constructor(options: PersistenceRedisOptions) {
22
- super();
23
-
24
- const { client } = options;
25
-
26
- this._client = client;
27
- this._initialized = (options as any)._initialized;
28
- }
29
-
30
- public async addUser(
31
- room: string,
32
- connectionId: string,
33
- user: JsonObject | null,
34
- ): Promise<void> {
35
- if (!this._initialized) return;
36
-
37
- await this._initialized;
38
-
39
- await this._client
40
- .multi()
41
- .sadd(this._getRoomUsersKey(room), connectionId)
42
- .set(this._getRoomUsersUserKey(room, connectionId), JSON.stringify(user))
43
- .exec();
44
- }
45
-
46
- public async deleteStorageState(room: string): Promise<void> {
47
- if (!this._initialized) return;
48
-
49
- await this._initialized;
50
-
51
- await this._client.del(this._getRoomStorageKey(room));
52
- }
53
-
54
- public async deleteUser(room: string, connectionId: string): Promise<void> {
55
- if (!this._initialized) return;
56
-
57
- await this._initialized;
58
-
59
- const size = await this.getUsersSize(room);
60
-
61
- let multi = this._client
62
- .multi()
63
- .srem(this._getRoomUsersKey(room), connectionId)
64
- .del(this._getRoomUsersUserKey(room, connectionId));
65
-
66
- if (size === 1) {
67
- multi = multi.del(this._getRoomStorageKey(room)).del(this._getRoomUsersKey(room));
68
- }
69
-
70
- await multi.exec();
71
- }
72
-
73
- public async deleteUsers(room: string): Promise<void> {
74
- if (!this._initialized) return;
75
-
76
- await this._initialized;
77
-
78
- const members = await this._client.smembers(this._getRoomUsersKey(room));
79
-
80
- await members
81
- .reduce(
82
- (commands, connectionId) => {
83
- return commands.del(this._getRoomUsersUserKey(room, connectionId));
84
- },
85
- this._client.multi().del(this._getRoomUsersKey(room)),
86
- )
87
- .exec();
88
- }
89
-
90
- public async getStorageState(room: string): Promise<string | null> {
91
- if (!this._initialized) return null;
92
-
93
- await this._initialized;
94
-
95
- return await this._client.get(this._getRoomStorageKey(room));
96
- }
97
-
98
- public async setStorageState(room: string, state: string): Promise<void> {
99
- if (!this._initialized) return;
100
-
101
- await this._initialized;
102
-
103
- await this._client.set(this._getRoomStorageKey(room), state);
104
- }
105
-
106
- public async getUser(room: string, connectionId: string): Promise<JsonObject | null> {
107
- if (!this._initialized) return null;
108
-
109
- await this._initialized;
110
-
111
- const data = await this._client.get(this._getRoomUsersUserKey(room, connectionId));
112
-
113
- return !data ? null : JSON.parse(data);
114
- }
115
-
116
- public async getUsers(
117
- room: string,
118
- ): Promise<Map<[connectionId: string][0], JsonObject | null>> {
119
- if (!this._initialized) return new Map();
120
-
121
- await this._initialized;
122
-
123
- const members = await this._client.smembers(this._getRoomUsersKey(room));
124
- const partitions = partitionByLength(members, GET_USERS_CONCURRENCY);
125
-
126
- return await partitions.reduce(async (promise, partition) => {
127
- const map = await promise;
128
-
129
- const promises = partition.map(async (connectionId) => {
130
- map.set(connectionId, await this.getUser(room, connectionId));
131
- });
132
-
133
- await Promise.all(promises);
134
-
135
- return map;
136
- }, Promise.resolve(new Map<string, JsonObject | null>()));
137
- }
138
-
139
- public async getUsersSize(room: string): Promise<number> {
140
- if (!this._initialized) return 0;
141
-
142
- await this._initialized;
143
-
144
- return await this._client.scard(this._getRoomUsersKey(room));
145
- }
146
-
147
- public initialize(roomContext: {}): typeof this {
148
- return new PersistenceRedis({
149
- client: this._client,
150
- ...{ _initialized: Promise.resolve(true as const) },
151
- }) as typeof this;
152
- }
153
-
154
- private _getClusterKey(key: string): string {
155
- return `${HASH_TAG}${key}`;
156
- }
157
-
158
- private _getRoomStorageKey(room: string): string {
159
- return this._getClusterKey(`room_storage${DELIMITER}${room}`);
160
- }
161
-
162
- private _getRoomUsersKey(room: string): string {
163
- return this._getClusterKey(`room_users${DELIMITER}${room}`);
164
- }
165
-
166
- private _getRoomUsersUserKey(room: string, connectionId: string): string {
167
- return this._getClusterKey(`${this._getRoomUsersKey(room)}${DELIMITER}${connectionId}`);
168
- }
169
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export type { RedisClient } from "./PersistenceRedis";
2
- export { PersistenceRedis } from "./PersistenceRedis";
@@ -1 +0,0 @@
1
- export { partitionByLength } from "./partitionByLength";
@@ -1,11 +0,0 @@
1
- export const partitionByLength = <T>(
2
- arr: readonly T[] | T[],
3
- length: number,
4
- ): readonly (readonly T[])[] => {
5
- if (!arr.length) return [];
6
-
7
- const head = arr.slice(0, length);
8
- const tail = arr.slice(length);
9
-
10
- return [head, ...partitionByLength(tail, length)];
11
- };
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@pluv/tsconfig/library.json",
3
- "include": ["**/*.ts"],
4
- "exclude": ["node_modules"],
5
- "compilerOptions": {
6
- "types": ["@types/node"]
7
- }
8
- }
package/tsdown.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- format: ["esm"],
5
- dts: true,
6
- outDir: "dist",
7
- entry: "src/index.ts",
8
- target: "esnext",
9
- sourcemap: true,
10
- clean: true,
11
- exports: {
12
- all: true,
13
- },
14
- });