@colyseus/core 0.16.0-preview.21 → 0.16.0-preview.27

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.
Files changed (87) hide show
  1. package/build/MatchMaker.d.ts +15 -14
  2. package/build/MatchMaker.js +81 -65
  3. package/build/MatchMaker.js.map +2 -2
  4. package/build/MatchMaker.mjs +80 -64
  5. package/build/MatchMaker.mjs.map +2 -2
  6. package/build/Protocol.d.ts +3 -4
  7. package/build/Protocol.js +22 -20
  8. package/build/Protocol.js.map +2 -2
  9. package/build/Protocol.mjs +22 -20
  10. package/build/Protocol.mjs.map +2 -2
  11. package/build/Room.d.ts +30 -29
  12. package/build/Room.js +123 -84
  13. package/build/Room.js.map +2 -2
  14. package/build/Room.mjs +123 -84
  15. package/build/Room.mjs.map +2 -2
  16. package/build/Server.d.ts +0 -1
  17. package/build/Server.js +2 -2
  18. package/build/Server.js.map +2 -2
  19. package/build/Server.mjs +1 -1
  20. package/build/Server.mjs.map +2 -2
  21. package/build/Transport.d.ts +0 -5
  22. package/build/index.d.ts +1 -1
  23. package/build/index.js +1 -1
  24. package/build/index.js.map +2 -2
  25. package/build/index.mjs +1 -1
  26. package/build/index.mjs.map +1 -1
  27. package/build/matchmaker/Lobby.d.ts +2 -2
  28. package/build/matchmaker/Lobby.js.map +2 -2
  29. package/build/matchmaker/Lobby.mjs.map +2 -2
  30. package/build/matchmaker/RegisteredHandler.d.ts +4 -5
  31. package/build/matchmaker/RegisteredHandler.js +4 -3
  32. package/build/matchmaker/RegisteredHandler.js.map +2 -2
  33. package/build/matchmaker/RegisteredHandler.mjs +4 -3
  34. package/build/matchmaker/RegisteredHandler.mjs.map +2 -2
  35. package/build/matchmaker/controller.d.ts +1 -2
  36. package/build/matchmaker/driver/RoomData.d.ts +3 -3
  37. package/build/matchmaker/driver/RoomData.js +3 -3
  38. package/build/matchmaker/driver/RoomData.js.map +2 -2
  39. package/build/matchmaker/driver/RoomData.mjs +2 -2
  40. package/build/matchmaker/driver/RoomData.mjs.map +2 -2
  41. package/build/matchmaker/driver/api.d.ts +104 -0
  42. package/build/matchmaker/driver/api.js +29 -0
  43. package/build/matchmaker/driver/api.js.map +7 -0
  44. package/build/matchmaker/driver/api.mjs +6 -0
  45. package/build/matchmaker/driver/api.mjs.map +7 -0
  46. package/build/matchmaker/driver/index.d.ts +7 -7
  47. package/build/matchmaker/driver/index.js +1 -1
  48. package/build/matchmaker/driver/index.js.map +2 -2
  49. package/build/matchmaker/driver/index.mjs +2 -2
  50. package/build/matchmaker/driver/index.mjs.map +2 -2
  51. package/build/matchmaker/driver/interfaces.d.ts +7 -11
  52. package/build/matchmaker/driver/interfaces.js.map +1 -1
  53. package/build/matchmaker/driver/local/LocalDriver.d.ts +13 -0
  54. package/build/matchmaker/driver/local/LocalDriver.js +65 -0
  55. package/build/matchmaker/driver/local/LocalDriver.js.map +7 -0
  56. package/build/matchmaker/driver/local/LocalDriver.mjs +42 -0
  57. package/build/matchmaker/driver/local/LocalDriver.mjs.map +7 -0
  58. package/build/matchmaker/driver/local/Query.d.ts +9 -0
  59. package/build/matchmaker/driver/local/Query.js +78 -0
  60. package/build/matchmaker/driver/local/Query.js.map +7 -0
  61. package/build/matchmaker/driver/local/Query.mjs +55 -0
  62. package/build/matchmaker/driver/local/Query.mjs.map +7 -0
  63. package/build/matchmaker/driver/local/RoomData.d.ts +19 -0
  64. package/build/matchmaker/driver/local/RoomData.js +79 -0
  65. package/build/matchmaker/driver/local/RoomData.js.map +7 -0
  66. package/build/matchmaker/driver/local/RoomData.mjs +56 -0
  67. package/build/matchmaker/driver/local/RoomData.mjs.map +7 -0
  68. package/build/presence/LocalPresence.d.ts +9 -2
  69. package/build/presence/LocalPresence.js +77 -3
  70. package/build/presence/LocalPresence.js.map +3 -3
  71. package/build/presence/LocalPresence.mjs +77 -3
  72. package/build/presence/LocalPresence.mjs.map +3 -3
  73. package/build/presence/Presence.d.ts +38 -2
  74. package/build/presence/Presence.js.map +1 -1
  75. package/build/rooms/LobbyRoom.d.ts +4 -4
  76. package/build/rooms/LobbyRoom.js.map +2 -2
  77. package/build/rooms/LobbyRoom.mjs.map +2 -2
  78. package/build/serializer/SchemaSerializer.d.ts +11 -10
  79. package/build/serializer/SchemaSerializer.js.map +2 -2
  80. package/build/serializer/SchemaSerializer.mjs.map +2 -2
  81. package/build/serializer/Serializer.d.ts +0 -1
  82. package/build/utils/Utils.d.ts +4 -2
  83. package/build/utils/Utils.js +11 -2
  84. package/build/utils/Utils.js.map +2 -2
  85. package/build/utils/Utils.mjs +10 -2
  86. package/build/utils/Utils.mjs.map +2 -2
  87. package/package.json +2 -2
@@ -0,0 +1,65 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var LocalDriver_exports = {};
19
+ __export(LocalDriver_exports, {
20
+ LocalDriver: () => LocalDriver
21
+ });
22
+ module.exports = __toCommonJS(LocalDriver_exports);
23
+ var import_Logger = require("../../../Logger");
24
+ var import_Query = require("./Query");
25
+ var import_RoomData = require("./RoomData");
26
+ class LocalDriver {
27
+ constructor() {
28
+ this.rooms = [];
29
+ }
30
+ createInstance(initialValues = {}) {
31
+ return new import_RoomData.RoomData(initialValues, this.rooms);
32
+ }
33
+ has(roomId) {
34
+ return this.rooms.some((room) => room.roomId === roomId);
35
+ }
36
+ query(conditions, sortOptions) {
37
+ const query = new import_Query.Query(this.rooms, conditions);
38
+ if (sortOptions) {
39
+ query.sort(sortOptions);
40
+ }
41
+ return query.filter(conditions);
42
+ }
43
+ cleanup(processId) {
44
+ const cachedRooms = this.query({ processId });
45
+ import_Logger.logger.debug("> Removing stale rooms by processId:", processId, `(${cachedRooms.length} rooms found)`);
46
+ cachedRooms.forEach((room) => room.remove());
47
+ return Promise.resolve();
48
+ }
49
+ findOne(conditions, sortOptions) {
50
+ const query = new import_Query.Query(this.rooms, conditions);
51
+ if (sortOptions) {
52
+ query.sort(sortOptions);
53
+ }
54
+ return query;
55
+ }
56
+ clear() {
57
+ this.rooms = [];
58
+ }
59
+ shutdown() {
60
+ }
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ LocalDriver
65
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/LocalDriver.ts"],
4
+ "sourcesContent": ["import { logger } from \"../../../Logger\";\nimport { IRoomCache, SortOptions, RoomCache, MatchMakerDriver } from \"../api\";\n\n// re-export\nexport type { IRoomCache, SortOptions, RoomCache, MatchMakerDriver };\n\nimport { Query } from './Query';\nimport { RoomData } from './RoomData';\n\nexport class LocalDriver implements MatchMakerDriver {\n public rooms: IRoomCache[] = [];\n\n public createInstance(initialValues: any = {}) {\n return new RoomData(initialValues, this.rooms);\n }\n\n public has(roomId: string) {\n return this.rooms.some((room) => room.roomId === roomId);\n }\n\n public query(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query.filter(conditions);\n }\n\n public cleanup(processId: string) {\n const cachedRooms = this.query({ processId });\n logger.debug(\"> Removing stale rooms by processId:\", processId, `(${cachedRooms.length} rooms found)`);\n\n cachedRooms.forEach((room) => room.remove());\n return Promise.resolve();\n }\n\n public findOne(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query as unknown as Promise<RoomCache>;\n }\n\n public clear() {\n this.rooms = [];\n }\n\n public shutdown() {\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAMvB,mBAAsB;AACtB,sBAAyB;AAElB,MAAM,YAAwC;AAAA,EAA9C;AACL,SAAO,QAAsB,CAAC;AAAA;AAAA,EAEvB,eAAe,gBAAqB,CAAC,GAAG;AAC7C,WAAO,IAAI,yBAAS,eAAe,KAAK,KAAK;AAAA,EAC/C;AAAA,EAEO,IAAI,QAAgB;AACzB,WAAO,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACzD;AAAA,EAEO,MAAM,YAAiC,aAA2B;AACvE,UAAM,QAAQ,IAAI,mBAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO,MAAM,OAAO,UAAU;AAAA,EAChC;AAAA,EAEO,QAAQ,WAAmB;AAChC,UAAM,cAAc,KAAK,MAAM,EAAE,UAAU,CAAC;AAC5C,yBAAO,MAAM,wCAAwC,WAAW,IAAI,YAAY,qBAAqB;AAErG,gBAAY,QAAQ,CAAC,SAAS,KAAK,OAAO,CAAC;AAC3C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,QAAQ,YAAiC,aAA2B;AACzE,UAAM,QAAQ,IAAI,mBAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,QAAQ;AACb,SAAK,QAAQ,CAAC;AAAA,EAChB;AAAA,EAEO,WAAW;AAAA,EAClB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,42 @@
1
+ import { logger } from "../../../Logger";
2
+ import { Query } from "./Query";
3
+ import { RoomData } from "./RoomData";
4
+ class LocalDriver {
5
+ constructor() {
6
+ this.rooms = [];
7
+ }
8
+ createInstance(initialValues = {}) {
9
+ return new RoomData(initialValues, this.rooms);
10
+ }
11
+ has(roomId) {
12
+ return this.rooms.some((room) => room.roomId === roomId);
13
+ }
14
+ query(conditions, sortOptions) {
15
+ const query = new Query(this.rooms, conditions);
16
+ if (sortOptions) {
17
+ query.sort(sortOptions);
18
+ }
19
+ return query.filter(conditions);
20
+ }
21
+ cleanup(processId) {
22
+ const cachedRooms = this.query({ processId });
23
+ logger.debug("> Removing stale rooms by processId:", processId, `(${cachedRooms.length} rooms found)`);
24
+ cachedRooms.forEach((room) => room.remove());
25
+ return Promise.resolve();
26
+ }
27
+ findOne(conditions, sortOptions) {
28
+ const query = new Query(this.rooms, conditions);
29
+ if (sortOptions) {
30
+ query.sort(sortOptions);
31
+ }
32
+ return query;
33
+ }
34
+ clear() {
35
+ this.rooms = [];
36
+ }
37
+ shutdown() {
38
+ }
39
+ }
40
+ export {
41
+ LocalDriver
42
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/LocalDriver.ts"],
4
+ "sourcesContent": ["import { logger } from \"../../../Logger\";\nimport { IRoomCache, SortOptions, RoomCache, MatchMakerDriver } from \"../api\";\n\n// re-export\nexport type { IRoomCache, SortOptions, RoomCache, MatchMakerDriver };\n\nimport { Query } from './Query';\nimport { RoomData } from './RoomData';\n\nexport class LocalDriver implements MatchMakerDriver {\n public rooms: IRoomCache[] = [];\n\n public createInstance(initialValues: any = {}) {\n return new RoomData(initialValues, this.rooms);\n }\n\n public has(roomId: string) {\n return this.rooms.some((room) => room.roomId === roomId);\n }\n\n public query(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query.filter(conditions);\n }\n\n public cleanup(processId: string) {\n const cachedRooms = this.query({ processId });\n logger.debug(\"> Removing stale rooms by processId:\", processId, `(${cachedRooms.length} rooms found)`);\n\n cachedRooms.forEach((room) => room.remove());\n return Promise.resolve();\n }\n\n public findOne(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query as unknown as Promise<RoomCache>;\n }\n\n public clear() {\n this.rooms = [];\n }\n\n public shutdown() {\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,cAAc;AAMvB,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAElB,MAAM,YAAwC;AAAA,EAA9C;AACL,SAAO,QAAsB,CAAC;AAAA;AAAA,EAEvB,eAAe,gBAAqB,CAAC,GAAG;AAC7C,WAAO,IAAI,SAAS,eAAe,KAAK,KAAK;AAAA,EAC/C;AAAA,EAEO,IAAI,QAAgB;AACzB,WAAO,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACzD;AAAA,EAEO,MAAM,YAAiC,aAA2B;AACvE,UAAM,QAAQ,IAAI,MAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO,MAAM,OAAO,UAAU;AAAA,EAChC;AAAA,EAEO,QAAQ,WAAmB;AAChC,UAAM,cAAc,KAAK,MAAM,EAAE,UAAU,CAAC;AAC5C,WAAO,MAAM,wCAAwC,WAAW,IAAI,YAAY,qBAAqB;AAErG,gBAAY,QAAQ,CAAC,SAAS,KAAK,OAAO,CAAC;AAC3C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,QAAQ,YAAiC,aAA2B;AACzE,UAAM,QAAQ,IAAI,MAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,QAAQ;AACb,SAAK,QAAQ,CAAC;AAAA,EAChB;AAAA,EAEO,WAAW;AAAA,EAClB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ import { SortOptions } from '../api';
2
+ export declare class Query<T> {
3
+ private $rooms;
4
+ private conditions;
5
+ constructor(rooms: any[], conditions: any);
6
+ sort(options: SortOptions): void;
7
+ filter(conditions: any): T[];
8
+ then(resolve: any, reject: any): any;
9
+ }
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var Query_exports = {};
19
+ __export(Query_exports, {
20
+ Query: () => Query
21
+ });
22
+ module.exports = __toCommonJS(Query_exports);
23
+ class Query {
24
+ constructor(rooms, conditions) {
25
+ this.$rooms = rooms.slice(0);
26
+ this.conditions = conditions;
27
+ }
28
+ sort(options) {
29
+ this.$rooms = this.$rooms.sort((room1, room2) => {
30
+ for (const field in options) {
31
+ if (options.hasOwnProperty(field)) {
32
+ const direction = options[field];
33
+ const isAscending = direction === 1 || direction === "asc" || direction === "ascending";
34
+ if (isAscending) {
35
+ if (room1[field] > room2[field]) {
36
+ return 1;
37
+ }
38
+ if (room1[field] < room2[field]) {
39
+ return -1;
40
+ }
41
+ } else {
42
+ if (room1[field] > room2[field]) {
43
+ return -1;
44
+ }
45
+ if (room1[field] < room2[field]) {
46
+ return 1;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ });
52
+ }
53
+ filter(conditions) {
54
+ return this.$rooms.filter((room) => {
55
+ for (const field in conditions) {
56
+ if (conditions.hasOwnProperty(field) && room[field] !== conditions[field]) {
57
+ return false;
58
+ }
59
+ }
60
+ return true;
61
+ });
62
+ }
63
+ then(resolve, reject) {
64
+ const result = this.$rooms.find((room) => {
65
+ for (const field in this.conditions) {
66
+ if (this.conditions.hasOwnProperty(field) && room[field] !== this.conditions[field]) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ });
72
+ return resolve(result);
73
+ }
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ Query
78
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/Query.ts"],
4
+ "sourcesContent": ["import { SortOptions } from '../api';\n\nexport class Query<T> {\n private $rooms: T[];\n private conditions: any;\n\n constructor(rooms: any[], conditions) {\n this.$rooms = rooms.slice(0);\n this.conditions = conditions;\n }\n\n public sort(options: SortOptions) {\n this.$rooms = this.$rooms.sort((room1, room2) => {\n for (const field in options) {\n if (options.hasOwnProperty(field)) {\n const direction = options[field];\n const isAscending = (direction === 1 || direction === 'asc' || direction === 'ascending');\n\n if (isAscending) {\n if (room1[field] > room2[field]) { return 1; }\n if (room1[field] < room2[field]) { return -1; }\n\n } else {\n if (room1[field] > room2[field]) { return -1; }\n if (room1[field] < room2[field]) { return 1; }\n }\n }\n }\n });\n }\n\n public filter(conditions: any) {\n return this.$rooms.filter(((room) => {\n for (const field in conditions) {\n if (\n conditions.hasOwnProperty(field) &&\n room[field] !== conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n\n }\n\n public then(resolve, reject) {\n const result: any = this.$rooms.find(((room) => {\n for (const field in this.conditions) {\n if (\n this.conditions.hasOwnProperty(field) &&\n room[field] !== this.conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n return resolve(result);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,MAAS;AAAA,EAIpB,YAAY,OAAc,YAAY;AACpC,SAAK,SAAS,MAAM,MAAM,CAAC;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,KAAK,SAAsB;AAChC,SAAK,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU;AAC/C,iBAAW,SAAS,SAAS;AAC3B,YAAI,QAAQ,eAAe,KAAK,GAAG;AACjC,gBAAM,YAAY,QAAQ;AAC1B,gBAAM,cAAe,cAAc,KAAK,cAAc,SAAS,cAAc;AAE7E,cAAI,aAAa;AACf,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAC7C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAAA,UAEhD,OAAO;AACL,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAC9C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,YAAiB;AAC7B,WAAO,KAAK,OAAO,OAAQ,CAAC,SAAS;AACnC,iBAAW,SAAS,YAAY;AAC9B,YACE,WAAW,eAAe,KAAK,KAC/B,KAAK,WAAW,WAAW,QAC3B;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AAAA,EAEJ;AAAA,EAEO,KAAK,SAAS,QAAQ;AAC3B,UAAM,SAAc,KAAK,OAAO,KAAM,CAAC,SAAS;AAC9C,iBAAW,SAAS,KAAK,YAAY;AACnC,YACE,KAAK,WAAW,eAAe,KAAK,KACpC,KAAK,WAAW,KAAK,WAAW,QAChC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AACF,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,55 @@
1
+ class Query {
2
+ constructor(rooms, conditions) {
3
+ this.$rooms = rooms.slice(0);
4
+ this.conditions = conditions;
5
+ }
6
+ sort(options) {
7
+ this.$rooms = this.$rooms.sort((room1, room2) => {
8
+ for (const field in options) {
9
+ if (options.hasOwnProperty(field)) {
10
+ const direction = options[field];
11
+ const isAscending = direction === 1 || direction === "asc" || direction === "ascending";
12
+ if (isAscending) {
13
+ if (room1[field] > room2[field]) {
14
+ return 1;
15
+ }
16
+ if (room1[field] < room2[field]) {
17
+ return -1;
18
+ }
19
+ } else {
20
+ if (room1[field] > room2[field]) {
21
+ return -1;
22
+ }
23
+ if (room1[field] < room2[field]) {
24
+ return 1;
25
+ }
26
+ }
27
+ }
28
+ }
29
+ });
30
+ }
31
+ filter(conditions) {
32
+ return this.$rooms.filter((room) => {
33
+ for (const field in conditions) {
34
+ if (conditions.hasOwnProperty(field) && room[field] !== conditions[field]) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ });
40
+ }
41
+ then(resolve, reject) {
42
+ const result = this.$rooms.find((room) => {
43
+ for (const field in this.conditions) {
44
+ if (this.conditions.hasOwnProperty(field) && room[field] !== this.conditions[field]) {
45
+ return false;
46
+ }
47
+ }
48
+ return true;
49
+ });
50
+ return resolve(result);
51
+ }
52
+ }
53
+ export {
54
+ Query
55
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/Query.ts"],
4
+ "sourcesContent": ["import { SortOptions } from '../api';\n\nexport class Query<T> {\n private $rooms: T[];\n private conditions: any;\n\n constructor(rooms: any[], conditions) {\n this.$rooms = rooms.slice(0);\n this.conditions = conditions;\n }\n\n public sort(options: SortOptions) {\n this.$rooms = this.$rooms.sort((room1, room2) => {\n for (const field in options) {\n if (options.hasOwnProperty(field)) {\n const direction = options[field];\n const isAscending = (direction === 1 || direction === 'asc' || direction === 'ascending');\n\n if (isAscending) {\n if (room1[field] > room2[field]) { return 1; }\n if (room1[field] < room2[field]) { return -1; }\n\n } else {\n if (room1[field] > room2[field]) { return -1; }\n if (room1[field] < room2[field]) { return 1; }\n }\n }\n }\n });\n }\n\n public filter(conditions: any) {\n return this.$rooms.filter(((room) => {\n for (const field in conditions) {\n if (\n conditions.hasOwnProperty(field) &&\n room[field] !== conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n\n }\n\n public then(resolve, reject) {\n const result: any = this.$rooms.find(((room) => {\n for (const field in this.conditions) {\n if (\n this.conditions.hasOwnProperty(field) &&\n room[field] !== this.conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n return resolve(result);\n }\n}\n"],
5
+ "mappings": "AAEO,MAAM,MAAS;AAAA,EAIpB,YAAY,OAAc,YAAY;AACpC,SAAK,SAAS,MAAM,MAAM,CAAC;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,KAAK,SAAsB;AAChC,SAAK,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU;AAC/C,iBAAW,SAAS,SAAS;AAC3B,YAAI,QAAQ,eAAe,KAAK,GAAG;AACjC,gBAAM,YAAY,QAAQ;AAC1B,gBAAM,cAAe,cAAc,KAAK,cAAc,SAAS,cAAc;AAE7E,cAAI,aAAa;AACf,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAC7C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAAA,UAEhD,OAAO;AACL,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAC9C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,YAAiB;AAC7B,WAAO,KAAK,OAAO,OAAQ,CAAC,SAAS;AACnC,iBAAW,SAAS,YAAY;AAC9B,YACE,WAAW,eAAe,KAAK,KAC/B,KAAK,WAAW,WAAW,QAC3B;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AAAA,EAEJ;AAAA,EAEO,KAAK,SAAS,QAAQ;AAC3B,UAAM,SAAc,KAAK,OAAO,KAAM,CAAC,SAAS;AAC9C,iBAAW,SAAS,KAAK,YAAY;AACnC,YACE,KAAK,WAAW,eAAe,KAAK,KACpC,KAAK,WAAW,KAAK,WAAW,QAChC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AACF,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ import { RoomCache, IRoomCache } from '../api';
2
+ export declare class RoomData implements RoomCache {
3
+ clients: number;
4
+ locked: boolean;
5
+ private: boolean;
6
+ maxClients: number;
7
+ metadata: any;
8
+ name: string;
9
+ publicAddress: string;
10
+ processId: string;
11
+ roomId: string;
12
+ createdAt: Date;
13
+ unlisted: boolean;
14
+ private $rooms;
15
+ constructor(initialValues: any, rooms: IRoomCache[]);
16
+ save(): void;
17
+ updateOne(operations: any): void;
18
+ remove(): void;
19
+ }
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var RoomData_exports = {};
19
+ __export(RoomData_exports, {
20
+ RoomData: () => RoomData
21
+ });
22
+ module.exports = __toCommonJS(RoomData_exports);
23
+ var import_Utils = require("../../../utils/Utils");
24
+ class RoomData {
25
+ constructor(initialValues, rooms) {
26
+ this.clients = 0;
27
+ this.locked = false;
28
+ this.private = false;
29
+ this.maxClients = Infinity;
30
+ this.unlisted = false;
31
+ this.createdAt = new Date();
32
+ for (const field in initialValues) {
33
+ if (initialValues.hasOwnProperty(field)) {
34
+ this[field] = initialValues[field];
35
+ }
36
+ }
37
+ Object.defineProperty(this, "$rooms", {
38
+ value: rooms,
39
+ enumerable: false,
40
+ writable: true
41
+ });
42
+ }
43
+ save() {
44
+ if (this.$rooms.indexOf(this) === -1) {
45
+ this.$rooms.push(this);
46
+ }
47
+ }
48
+ updateOne(operations) {
49
+ if (operations.$set) {
50
+ for (const field in operations.$set) {
51
+ if (operations.$set.hasOwnProperty(field)) {
52
+ this[field] = operations.$set[field];
53
+ }
54
+ }
55
+ }
56
+ if (operations.$inc) {
57
+ for (const field in operations.$inc) {
58
+ if (operations.$inc.hasOwnProperty(field)) {
59
+ this[field] += operations.$inc[field];
60
+ }
61
+ }
62
+ }
63
+ }
64
+ remove() {
65
+ if (!this.$rooms) {
66
+ return;
67
+ }
68
+ const roomIndex = this.$rooms.indexOf(this);
69
+ if (roomIndex === -1) {
70
+ return;
71
+ }
72
+ (0, import_Utils.spliceOne)(this.$rooms, roomIndex);
73
+ this.$rooms = null;
74
+ }
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ RoomData
79
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/RoomData.ts"],
4
+ "sourcesContent": ["import { spliceOne } from '../../../utils/Utils';\nimport { RoomCache, IRoomCache } from '../api';\n\nexport class RoomData implements RoomCache {\n public clients: number = 0;\n public locked: boolean = false;\n public private: boolean = false;\n public maxClients: number = Infinity;\n public metadata: any;\n public name: string;\n public publicAddress: string;\n public processId: string;\n public roomId: string;\n public createdAt: Date;\n public unlisted: boolean = false;\n\n private $rooms: RoomCache[];\n\n constructor(initialValues: any, rooms: IRoomCache[]) {\n this.createdAt = new Date();\n\n for (const field in initialValues) {\n if (initialValues.hasOwnProperty(field)) {\n this[field] = initialValues[field];\n }\n }\n\n // make $rooms non-enumerable, so it can be serialized (circular references)\n Object.defineProperty(this, \"$rooms\", {\n value: rooms,\n enumerable: false,\n writable: true,\n });\n }\n\n public save() {\n if (this.$rooms.indexOf(this) === -1) {\n this.$rooms.push(this);\n }\n }\n\n public updateOne(operations: any) {\n if (operations.$set) {\n for (const field in operations.$set) {\n if (operations.$set.hasOwnProperty(field)) {\n this[field] = operations.$set[field];\n }\n }\n }\n\n if (operations.$inc) {\n for (const field in operations.$inc) {\n if (operations.$inc.hasOwnProperty(field)) {\n this[field] += operations.$inc[field];\n }\n }\n }\n }\n\n public remove() {\n //\n // WORKAROUND: prevent calling `.remove()` multiple times\n // Seems to happen during disconnect + dispose: https://github.com/colyseus/colyseus/issues/390\n //\n if (!this.$rooms) { return; }\n\n const roomIndex = this.$rooms.indexOf(this);\n if (roomIndex === -1) { return; }\n\n spliceOne(this.$rooms, roomIndex);\n this.$rooms = null;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAGnB,MAAM,SAA8B;AAAA,EAezC,YAAY,eAAoB,OAAqB;AAdrD,SAAO,UAAkB;AACzB,SAAO,SAAkB;AACzB,SAAO,UAAmB;AAC1B,SAAO,aAAqB;AAO5B,SAAO,WAAoB;AAKzB,SAAK,YAAY,IAAI,KAAK;AAE1B,eAAW,SAAS,eAAe;AACjC,UAAI,cAAc,eAAe,KAAK,GAAG;AACvC,aAAK,SAAS,cAAc;AAAA,MAC9B;AAAA,IACF;AAGA,WAAO,eAAe,MAAM,UAAU;AAAA,MACpC,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEO,OAAO;AACZ,QAAI,KAAK,OAAO,QAAQ,IAAI,MAAM,IAAI;AACpC,WAAK,OAAO,KAAK,IAAI;AAAA,IACvB;AAAA,EACF;AAAA,EAEO,UAAU,YAAiB;AAChC,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,SAAS,WAAW,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,UAAU,WAAW,KAAK;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,SAAS;AAKd,QAAI,CAAC,KAAK,QAAQ;AAAE;AAAA,IAAQ;AAE5B,UAAM,YAAY,KAAK,OAAO,QAAQ,IAAI;AAC1C,QAAI,cAAc,IAAI;AAAE;AAAA,IAAQ;AAEhC,gCAAU,KAAK,QAAQ,SAAS;AAChC,SAAK,SAAS;AAAA,EAChB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
1
+ import { spliceOne } from "../../../utils/Utils";
2
+ class RoomData {
3
+ constructor(initialValues, rooms) {
4
+ this.clients = 0;
5
+ this.locked = false;
6
+ this.private = false;
7
+ this.maxClients = Infinity;
8
+ this.unlisted = false;
9
+ this.createdAt = new Date();
10
+ for (const field in initialValues) {
11
+ if (initialValues.hasOwnProperty(field)) {
12
+ this[field] = initialValues[field];
13
+ }
14
+ }
15
+ Object.defineProperty(this, "$rooms", {
16
+ value: rooms,
17
+ enumerable: false,
18
+ writable: true
19
+ });
20
+ }
21
+ save() {
22
+ if (this.$rooms.indexOf(this) === -1) {
23
+ this.$rooms.push(this);
24
+ }
25
+ }
26
+ updateOne(operations) {
27
+ if (operations.$set) {
28
+ for (const field in operations.$set) {
29
+ if (operations.$set.hasOwnProperty(field)) {
30
+ this[field] = operations.$set[field];
31
+ }
32
+ }
33
+ }
34
+ if (operations.$inc) {
35
+ for (const field in operations.$inc) {
36
+ if (operations.$inc.hasOwnProperty(field)) {
37
+ this[field] += operations.$inc[field];
38
+ }
39
+ }
40
+ }
41
+ }
42
+ remove() {
43
+ if (!this.$rooms) {
44
+ return;
45
+ }
46
+ const roomIndex = this.$rooms.indexOf(this);
47
+ if (roomIndex === -1) {
48
+ return;
49
+ }
50
+ spliceOne(this.$rooms, roomIndex);
51
+ this.$rooms = null;
52
+ }
53
+ }
54
+ export {
55
+ RoomData
56
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/RoomData.ts"],
4
+ "sourcesContent": ["import { spliceOne } from '../../../utils/Utils';\nimport { RoomCache, IRoomCache } from '../api';\n\nexport class RoomData implements RoomCache {\n public clients: number = 0;\n public locked: boolean = false;\n public private: boolean = false;\n public maxClients: number = Infinity;\n public metadata: any;\n public name: string;\n public publicAddress: string;\n public processId: string;\n public roomId: string;\n public createdAt: Date;\n public unlisted: boolean = false;\n\n private $rooms: RoomCache[];\n\n constructor(initialValues: any, rooms: IRoomCache[]) {\n this.createdAt = new Date();\n\n for (const field in initialValues) {\n if (initialValues.hasOwnProperty(field)) {\n this[field] = initialValues[field];\n }\n }\n\n // make $rooms non-enumerable, so it can be serialized (circular references)\n Object.defineProperty(this, \"$rooms\", {\n value: rooms,\n enumerable: false,\n writable: true,\n });\n }\n\n public save() {\n if (this.$rooms.indexOf(this) === -1) {\n this.$rooms.push(this);\n }\n }\n\n public updateOne(operations: any) {\n if (operations.$set) {\n for (const field in operations.$set) {\n if (operations.$set.hasOwnProperty(field)) {\n this[field] = operations.$set[field];\n }\n }\n }\n\n if (operations.$inc) {\n for (const field in operations.$inc) {\n if (operations.$inc.hasOwnProperty(field)) {\n this[field] += operations.$inc[field];\n }\n }\n }\n }\n\n public remove() {\n //\n // WORKAROUND: prevent calling `.remove()` multiple times\n // Seems to happen during disconnect + dispose: https://github.com/colyseus/colyseus/issues/390\n //\n if (!this.$rooms) { return; }\n\n const roomIndex = this.$rooms.indexOf(this);\n if (roomIndex === -1) { return; }\n\n spliceOne(this.$rooms, roomIndex);\n this.$rooms = null;\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB;AAGnB,MAAM,SAA8B;AAAA,EAezC,YAAY,eAAoB,OAAqB;AAdrD,SAAO,UAAkB;AACzB,SAAO,SAAkB;AACzB,SAAO,UAAmB;AAC1B,SAAO,aAAqB;AAO5B,SAAO,WAAoB;AAKzB,SAAK,YAAY,IAAI,KAAK;AAE1B,eAAW,SAAS,eAAe;AACjC,UAAI,cAAc,eAAe,KAAK,GAAG;AACvC,aAAK,SAAS,cAAc;AAAA,MAC9B;AAAA,IACF;AAGA,WAAO,eAAe,MAAM,UAAU;AAAA,MACpC,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEO,OAAO;AACZ,QAAI,KAAK,OAAO,QAAQ,IAAI,MAAM,IAAI;AACpC,WAAK,OAAO,KAAK,IAAI;AAAA,IACvB;AAAA,EACF;AAAA,EAEO,UAAU,YAAiB;AAChC,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,SAAS,WAAW,KAAK;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,UAAU,WAAW,KAAK;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,SAAS;AAKd,QAAI,CAAC,KAAK,QAAQ;AAAE;AAAA,IAAQ;AAE5B,UAAM,YAAY,KAAK,OAAO,QAAQ,IAAI;AAC1C,QAAI,cAAc,IAAI;AAAE;AAAA,IAAQ;AAEhC,cAAU,KAAK,QAAQ,SAAS;AAChC,SAAK,SAAS;AAAA,EAChB;AACF;",
6
+ "names": []
7
+ }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { Presence } from './Presence';
4
3
  type Callback = (...args: any[]) => void;
@@ -23,9 +22,10 @@ export declare class LocalPresence implements Presence {
23
22
  subscribe(topic: string, callback: (...args: any[]) => void): this;
24
23
  unsubscribe(topic: string, callback?: Callback): this;
25
24
  publish(topic: string, data: any): this;
26
- exists(roomId: string): Promise<boolean>;
25
+ exists(key: string): Promise<boolean>;
27
26
  set(key: string, value: string): void;
28
27
  setex(key: string, value: string, seconds: number): void;
28
+ expire(key: string, seconds: number): void;
29
29
  get(key: string): string | number;
30
30
  del(key: string): void;
31
31
  sadd(key: string, value: any): void;
@@ -36,6 +36,7 @@ export declare class LocalPresence implements Presence {
36
36
  sinter(...keys: string[]): Promise<any[]>;
37
37
  hset(key: string, field: string, value: string): void;
38
38
  hincrby(key: string, field: string, incrBy: number): number;
39
+ hincrbyex(key: string, field: string, incrBy: number, expireInSeconds: number): number;
39
40
  hget(key: string, field: string): Promise<string>;
40
41
  hgetall(key: string): Promise<{
41
42
  [key: string]: string;
@@ -44,6 +45,12 @@ export declare class LocalPresence implements Presence {
44
45
  hlen(key: string): Promise<number>;
45
46
  incr(key: string): Promise<number>;
46
47
  decr(key: string): Promise<number>;
48
+ llen(key: string): number;
49
+ rpush(key: string, ...values: string[]): number;
50
+ lpush(key: string, ...values: string[]): number;
51
+ lpop(key: string): string;
52
+ rpop(key: string): string;
53
+ brpop(...args: [...keys: string[], timeoutInSeconds: number]): Promise<[string, string] | null>;
47
54
  shutdown(): void;
48
55
  }
49
56
  export {};
@@ -86,17 +86,20 @@ class LocalPresence {
86
86
  this.channels.emit(topic, data);
87
87
  return this;
88
88
  }
89
- async exists(roomId) {
90
- return this.channels.listenerCount(roomId) > 0;
89
+ async exists(key) {
90
+ return this.channels.listenerCount(key) > 0;
91
91
  }
92
92
  set(key, value) {
93
93
  this.keys[key] = value;
94
94
  }
95
95
  setex(key, value, seconds) {
96
+ this.keys[key] = value;
97
+ this.expire(key, seconds);
98
+ }
99
+ expire(key, seconds) {
96
100
  if (this.timeouts[key]) {
97
101
  clearTimeout(this.timeouts[key]);
98
102
  }
99
- this.keys[key] = value;
100
103
  this.timeouts[key] = setTimeout(() => {
101
104
  delete this.keys[key];
102
105
  delete this.timeouts[key];
@@ -164,6 +167,16 @@ class LocalPresence {
164
167
  this.hash[key][field] = value.toString();
165
168
  return value;
166
169
  }
170
+ hincrbyex(key, field, incrBy, expireInSeconds) {
171
+ if (!this.hash[key]) {
172
+ this.hash[key] = {};
173
+ }
174
+ let value = Number(this.hash[key][field] || "0");
175
+ value += incrBy;
176
+ this.hash[key][field] = value.toString();
177
+ this.setex(key, field, expireInSeconds);
178
+ return value;
179
+ }
167
180
  async hget(key, field) {
168
181
  return this.hash[key] && this.hash[key][field];
169
182
  }
@@ -194,6 +207,67 @@ class LocalPresence {
194
207
  this.keys[key]--;
195
208
  return Promise.resolve(this.keys[key]);
196
209
  }
210
+ llen(key) {
211
+ return this.data[key] && this.data[key].length || 0;
212
+ }
213
+ rpush(key, ...values) {
214
+ if (!this.data[key]) {
215
+ this.data[key] = [];
216
+ }
217
+ let lastLength = 0;
218
+ values.forEach((value) => {
219
+ lastLength = this.data[key].push(value);
220
+ });
221
+ return lastLength;
222
+ }
223
+ lpush(key, ...values) {
224
+ if (!this.data[key]) {
225
+ this.data[key] = [];
226
+ }
227
+ let lastLength = 0;
228
+ values.forEach((value) => {
229
+ lastLength = this.data[key].unshift(value);
230
+ });
231
+ return lastLength;
232
+ }
233
+ lpop(key) {
234
+ return Array.isArray(this.data[key]) && this.data[key].shift();
235
+ }
236
+ rpop(key) {
237
+ return this.data[key].pop();
238
+ }
239
+ brpop(...args) {
240
+ const keys = args.slice(0, -2);
241
+ const timeoutInSeconds = args[args.length - 1];
242
+ const getFirstPopulated = () => {
243
+ const keyWithValue = keys.find((key) => this.data[key] && this.data[key].length > 0);
244
+ if (keyWithValue) {
245
+ return [keyWithValue, this.data[keyWithValue].pop()];
246
+ } else {
247
+ return null;
248
+ }
249
+ };
250
+ const firstPopulated = getFirstPopulated();
251
+ if (firstPopulated) {
252
+ return Promise.resolve(firstPopulated);
253
+ } else {
254
+ const maxRetries = timeoutInSeconds * 8;
255
+ let tries = 0;
256
+ return new Promise((resolve) => {
257
+ const interval = setInterval(() => {
258
+ tries++;
259
+ const firstPopulated2 = getFirstPopulated();
260
+ if (firstPopulated2) {
261
+ clearInterval(interval);
262
+ return resolve(firstPopulated2);
263
+ } else if (tries >= maxRetries) {
264
+ clearInterval(interval);
265
+ return resolve(void 0);
266
+ }
267
+ }, timeoutInSeconds * 1e3 / maxRetries);
268
+ });
269
+ }
270
+ }
197
271
  shutdown() {
198
272
  if (import_DevMode.isDevMode) {
199
273
  const cache = JSON.stringify({