redux-cluster 2.0.0 β†’ 2.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.
package/README.md CHANGED
@@ -1,15 +1,20 @@
1
1
  # Redux Cluster 2.0
2
2
 
3
- [![npm version](https://badge.fury.io/js/redux-cluster.svg)](https://badge.fury.io/js/redux-cluster)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
3
+ [![npm](https://img.shields.io/npm/v/redux-cluster.svg)](https://www.npmjs.com/package/redux-cluster)
4
+ [![npm](https://img.shields.io/npm/dy/redux-cluster.svg)](https://www.npmjs.com/package/redux-cluster)
5
+ [![NpmLicense](https://img.shields.io/npm/l/redux-cluster.svg)](https://www.npmjs.com/package/redux-cluster)
6
+ ![GitHub last commit](https://img.shields.io/github/last-commit/siarheidudko/redux-cluster.svg)
7
+ ![GitHub release](https://img.shields.io/github/release/siarheidudko/redux-cluster.svg)
6
8
 
7
9
  A modern TypeScript library for synchronizing Redux stores across multiple processes and machines using TCP, Unix Domain Sockets, and IPC.
8
10
 
11
+ > 🌐 **Need WebSocket support for browsers?** Check out [redux-cluster-ws](https://www.npmjs.com/package/redux-cluster-ws) - our companion package that extends Redux Cluster with WebSocket transport for browser clients.
12
+
9
13
  ## 🌟 Key Features
10
14
 
11
15
  - πŸ”„ **Real-time State Synchronization** across multiple processes/machines
12
16
  - 🌐 **Multiple Transport Options**: TCP, Unix Domain Sockets, IPC
17
+ - 🌍 **WebSocket Support**: Available via [redux-cluster-ws](https://www.npmjs.com/package/redux-cluster-ws)
13
18
  - πŸ“‘ **Bidirectional Communication** - any node can dispatch actions
14
19
  - πŸ”’ **Built-in Security** with authentication and IP banning
15
20
  - ⚑ **High Performance** with optimized networking and compression
@@ -261,8 +266,34 @@ See the [examples/](./examples/) directory for complete working examples:
261
266
  - **[File Socket](./examples/file-socket/)** - Local IPC via Unix sockets
262
267
  - **[Basic Store](./examples/basic/)** - Local Redux store without networking
263
268
 
269
+ > 🌐 **WebSocket Examples**: For browser integration examples with WebSocket transport, visit the [redux-cluster-ws examples](https://github.com/siarheidudko/redux-cluster-ws/tree/main/examples).
270
+
264
271
  Each example includes a README with step-by-step instructions.
265
272
 
273
+ ## πŸ“¦ Related Packages
274
+
275
+ ### redux-cluster-ws
276
+
277
+ WebSocket transport layer for Redux Cluster, enabling browser client support:
278
+
279
+ ```bash
280
+ npm install redux-cluster-ws
281
+ ```
282
+
283
+ **Features:**
284
+
285
+ - 🌐 WebSocket server and client
286
+ - πŸ”— Seamless integration with Redux Cluster
287
+ - πŸ–₯️ Browser support for web applications
288
+ - πŸ“± Real-time state synchronization to browsers
289
+ - πŸ”’ Same security features as core package
290
+
291
+ **Links:**
292
+
293
+ - πŸ“‹ [NPM Package](https://www.npmjs.com/package/redux-cluster-ws)
294
+ - πŸ“– [Documentation](https://github.com/siarheidudko/redux-cluster-ws)
295
+ - 🎯 [Examples](https://github.com/siarheidudko/redux-cluster-ws/tree/main/examples)
296
+
266
297
  ## πŸ§ͺ Testing
267
298
 
268
299
  ```bash
@@ -299,7 +330,7 @@ Benchmark results:
299
330
  ## πŸ—ΊοΈ Roadmap
300
331
 
301
332
  - [ ] **Redis Transport** - Redis pub/sub for clustering
302
- - [ ] **WebSocket Transport** - Browser client support
333
+ - [x] **WebSocket Transport** - Available in [redux-cluster-ws](https://www.npmjs.com/package/redux-cluster-ws)
303
334
  - [ ] **Conflict Resolution** - CRDT-based conflict resolution
304
335
  - [ ] **Persistence Layer** - Automatic state persistence
305
336
  - [ ] **Monitoring Dashboard** - Real-time cluster monitoring
@@ -307,7 +338,11 @@ Benchmark results:
307
338
 
308
339
  ## 🀝 Contributing
309
340
 
310
- Contributions are welcome! Please read our [Contributing Guidelines](./CONTRIBUTING.md) and [Code of Conduct](./CODE_OF_CONDUCT.md).
341
+ 1. Fork the repository
342
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
343
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
344
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
345
+ 5. Open a Pull Request
311
346
 
312
347
  ### Development Setup
313
348
 
@@ -1 +1 @@
1
- {"version":3,"file":"redux-cluster.d.ts","sourceRoot":"","sources":["../../../src/core/redux-cluster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAW5D,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,cAAc,EAEd,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,kBAAkB,EAEnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMlD,qBAAa,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAC1D,YAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;IAGlC,SAAgB,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAClD,SAAgB,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAClD,SAAgB,SAAS,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACpD,SAAgB,cAAc,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAC9D,SAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;IAG3E,SAAgB,MAAM,EAAE,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aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,IAAI;IASxD,oBAAoB,IAAI,MAAM,EAAE;CAMxC"}
@@ -222,7 +222,8 @@ class ReduxCluster {
222
222
  if (message._hash === this.RCHash) {
223
223
  switch (message._msg) {
224
224
  case types_1.MessageType.MSG_TO_MASTER:
225
- if (message._action.type === types_1.MessageType.SYNC) {
225
+ if (message._action.type === types_1.MessageType.SYNC &&
226
+ !message._action._internal) {
226
227
  throw new Error("Please don't use REDUX_CLUSTER_SYNC action type!");
227
228
  }
228
229
  // Deserialize action if it contains ProtoObject
@@ -245,6 +246,7 @@ class ReduxCluster {
245
246
  _action: {
246
247
  type: types_1.MessageType.SYNC,
247
248
  payload: this.getState(),
249
+ _internal: true,
248
250
  },
249
251
  };
250
252
  const serializedResponse = {
@@ -301,6 +303,7 @@ class ReduxCluster {
301
303
  _action: {
302
304
  type: types_1.MessageType.SYNC,
303
305
  payload: this.getState(),
306
+ _internal: true,
304
307
  },
305
308
  };
306
309
  // Serialize ProtoObject instances for IPC
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/network/server.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EAEd,aAAa,EACd,MAAM,UAAU,CAAC;AAGlB,qBAAa,aAAa;IAatB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IAblB,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;IAC5D,SAAgB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACtD,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAM;IAE7E,OAAO,CAAC,QAAQ,CAA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CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAM;IAE7E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,iBAAiB,CAAiB;gBAGhC,KAAK,EAAE,iBAAiB,EACxB,QAAQ,GAAE,cAAmB;IAavC,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,WAAW;IA8CnB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,mBAAmB;IA2D3B,OAAO,CAAC,mBAAmB;IA8C3B,OAAO,CAAC,oBAAoB;IAyD5B,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,qBAAqB;IActB,SAAS,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IAgBzC,YAAY,IAAI,IAAI;IAI3B,OAAO,CAAC,OAAO;IAQR,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAiD9B"}
@@ -155,9 +155,7 @@ class ClusterServer {
155
155
  }
156
156
  handleNewConnection(socket) {
157
157
  // Hash IP address for security using hasher function
158
- const clientIP = socket.remoteAddress
159
- ? (0, crypto_1.hasher)(socket.remoteAddress)
160
- : "";
158
+ const clientIP = socket.remoteAddress ? (0, crypto_1.hasher)(socket.remoteAddress) : "";
161
159
  const uid = crypto.randomUUID();
162
160
  const clusterSocket = socket;
163
161
  clusterSocket.uid = uid;
@@ -260,7 +258,8 @@ class ClusterServer {
260
258
  switch (data._msg) {
261
259
  case types_1.MessageType.MSG_TO_MASTER:
262
260
  if (this.sockets[socket.uid]) {
263
- if (data._action.type === types_1.MessageType.SYNC) {
261
+ if (data._action.type === types_1.MessageType.SYNC &&
262
+ !data._action._internal) {
264
263
  throw new Error("Please don't use REDUX_CLUSTER_SYNC action type!");
265
264
  }
266
265
  // Apply action to server state
@@ -276,6 +275,7 @@ class ClusterServer {
276
275
  _action: {
277
276
  type: types_1.MessageType.SYNC,
278
277
  payload: this.store.getState(),
278
+ _internal: true,
279
279
  },
280
280
  });
281
281
  }
@@ -371,6 +371,7 @@ class ClusterServer {
371
371
  _action: {
372
372
  type: types_1.MessageType.SYNC,
373
373
  payload: this.store.getState(),
374
+ _internal: true,
374
375
  },
375
376
  };
376
377
  for (const uid in this.sockets) {
@@ -2,9 +2,6 @@ import * as fs from "fs";
2
2
  import { MessageType } from "../types";
3
3
  import { encrypter, decrypter } from "../utils/crypto";
4
4
  export class BackupManager {
5
- store;
6
- settings;
7
- createBackupInstance;
8
5
  constructor(store, settings) {
9
6
  this.store = store;
10
7
  this.settings = settings;
@@ -63,14 +60,12 @@ export class BackupManager {
63
60
  }
64
61
  }
65
62
  class BackupInstance {
66
- store;
67
- settings;
68
- count = 0;
69
- allowed = true;
70
- unsubscribe = null;
71
63
  constructor(store, settings) {
72
64
  this.store = store;
73
65
  this.settings = settings;
66
+ this.count = 0;
67
+ this.allowed = true;
68
+ this.unsubscribe = null;
74
69
  this.unsubscribe = this.store.subscribe(() => {
75
70
  this.handleStateChange();
76
71
  });
@@ -1 +1 @@
1
- {"version":3,"file":"redux-cluster.d.ts","sourceRoot":"","sources":["../../../src/core/redux-cluster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAW5D,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,cAAc,EAEd,cAAc,EACd,cAAc,EACd,cAA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AS;IACzB,OAAO,CAAC,WAAW,CAAC,CAA0B;IAC9C,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,aAAa,CAAyB;gBAElC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,GAAE,kBAAuB;IA4EnE,OAAO,CAAC,YAAY;IASb,aAAa,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAItC,OAAO,CAAC,gBAAgB;IA2BxB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,gBAAgB;IA0BxB,OAAO,CAAC,gBAAgB;IAiCxB,OAAO,CAAC,mBAAmB;IA4D3B,OAAO,CAAC,mBAAmB;IAoCpB,SAAS,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IA8BzC,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IAW7C,YAAY,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa;IAetD,YAAY,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa;IAetD,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAKlD,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,IAAI;IASxD,oBAAoB,IAAI,MAAM,EAAE;CAMxC"}
@@ -10,31 +10,14 @@ import { BackupManager } from "./backup";
10
10
  // Global reducers registry to prevent name conflicts
11
11
  const reducers = {};
12
12
  export class ReduxCluster {
13
- // Redux Store properties
14
- dispatch;
15
- getState;
16
- subscribe;
17
- replaceReducer;
18
- [Symbol.observable];
19
- // ReduxCluster specific properties
20
- RCHash;
21
- version;
22
- homepage;
23
- role = [];
24
- connected = false;
25
- mode = "action";
26
- resync = 1000;
27
- stderr = console.error;
28
- config;
29
- altReducer;
30
- defaultState;
31
- store;
32
- allsock = {};
33
- counter;
34
- dispatchNEW;
35
- unsubscribe;
36
- classRegistry = createClassRegistry();
37
13
  constructor(reducer, config = {}) {
14
+ this.role = [];
15
+ this.connected = false;
16
+ this.mode = "action";
17
+ this.resync = 1000;
18
+ this.stderr = console.error;
19
+ this.allsock = {};
20
+ this.classRegistry = createClassRegistry();
38
21
  this.altReducer = reducer;
39
22
  this.RCHash = hasher(reducer.name) || "";
40
23
  // Set configuration with defaults
@@ -233,7 +216,8 @@ export class ReduxCluster {
233
216
  if (message._hash === this.RCHash) {
234
217
  switch (message._msg) {
235
218
  case MessageType.MSG_TO_MASTER:
236
- if (message._action.type === MessageType.SYNC) {
219
+ if (message._action.type === MessageType.SYNC &&
220
+ !message._action._internal) {
237
221
  throw new Error("Please don't use REDUX_CLUSTER_SYNC action type!");
238
222
  }
239
223
  // Deserialize action if it contains ProtoObject
@@ -256,6 +240,7 @@ export class ReduxCluster {
256
240
  _action: {
257
241
  type: MessageType.SYNC,
258
242
  payload: this.getState(),
243
+ _internal: true,
259
244
  },
260
245
  };
261
246
  const serializedResponse = {
@@ -312,6 +297,7 @@ export class ReduxCluster {
312
297
  _action: {
313
298
  type: MessageType.SYNC,
314
299
  payload: this.getState(),
300
+ _internal: true,
315
301
  },
316
302
  };
317
303
  // Serialize ProtoObject instances for IPC
@@ -374,3 +360,4 @@ export class ReduxCluster {
374
360
  return [];
375
361
  }
376
362
  }
363
+ Symbol.observable;
@@ -6,17 +6,10 @@ import * as stream from "stream";
6
6
  import { MessageType } from "../types";
7
7
  import { hasher } from "../utils/crypto";
8
8
  export class ClusterClient {
9
- store;
10
- settings;
11
- login;
12
- password;
13
- client;
14
- listenOptions;
15
- shouldReconnect = true;
16
- reconnectTimeout;
17
9
  constructor(store, settings = {}) {
18
10
  this.store = store;
19
11
  this.settings = settings;
12
+ this.shouldReconnect = true;
20
13
  this.setupCredentials();
21
14
  this.setupConnection();
22
15
  this.connectToServer();
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"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AC,iBAAiB;IAazB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,qBAAqB;IActB,SAAS,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IAgBzC,YAAY,IAAI,IAAI;IAI3B,OAAO,CAAC,OAAO;IAQR,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAiD9B"}
@@ -8,20 +8,14 @@ import * as crypto from "crypto";
8
8
  import { MessageType, } from "../types";
9
9
  import { hasher } from "../utils/crypto";
10
10
  export class ClusterServer {
11
- store;
12
- settings;
13
- uid;
14
- sockets = {};
15
- database = {};
16
- ip2ban = {};
17
- ip2banTimeout = 10800000; // 3 hours
18
- ip2banGC;
19
- server;
20
- unsubscribe;
21
- shouldAutoRestart = true;
22
11
  constructor(store, settings = {}) {
23
12
  this.store = store;
24
13
  this.settings = settings;
14
+ this.sockets = {};
15
+ this.database = {};
16
+ this.ip2ban = {};
17
+ this.ip2banTimeout = 10800000; // 3 hours
18
+ this.shouldAutoRestart = true;
25
19
  this.uid = crypto.randomUUID();
26
20
  this.setupDatabase();
27
21
  this.setupBanSystem();
@@ -125,9 +119,7 @@ export class ClusterServer {
125
119
  }
126
120
  handleNewConnection(socket) {
127
121
  // Hash IP address for security using hasher function
128
- const clientIP = socket.remoteAddress
129
- ? hasher(socket.remoteAddress)
130
- : "";
122
+ const clientIP = socket.remoteAddress ? hasher(socket.remoteAddress) : "";
131
123
  const uid = crypto.randomUUID();
132
124
  const clusterSocket = socket;
133
125
  clusterSocket.uid = uid;
@@ -230,7 +222,8 @@ export class ClusterServer {
230
222
  switch (data._msg) {
231
223
  case MessageType.MSG_TO_MASTER:
232
224
  if (this.sockets[socket.uid]) {
233
- if (data._action.type === MessageType.SYNC) {
225
+ if (data._action.type === MessageType.SYNC &&
226
+ !data._action._internal) {
234
227
  throw new Error("Please don't use REDUX_CLUSTER_SYNC action type!");
235
228
  }
236
229
  // Apply action to server state
@@ -246,6 +239,7 @@ export class ClusterServer {
246
239
  _action: {
247
240
  type: MessageType.SYNC,
248
241
  payload: this.store.getState(),
242
+ _internal: true,
249
243
  },
250
244
  });
251
245
  }
@@ -341,6 +335,7 @@ export class ClusterServer {
341
335
  _action: {
342
336
  type: MessageType.SYNC,
343
337
  payload: this.store.getState(),
338
+ _internal: true,
344
339
  },
345
340
  };
346
341
  for (const uid in this.sockets) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redux-cluster",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "description": "TypeScript cluster module for Redux that synchronizes Redux stores across cluster processes via IPC and TCP sockets",
6
6
  "main": "dist/cjs/index.js",
@@ -49,6 +49,7 @@
49
49
  "build:pkg": "./scripts/create-package-files.sh",
50
50
  "build:watch": "tsc --watch",
51
51
  "clean": "rm -rf dist",
52
+ "update": "eval \"$(node -e 'const t = require(`./package.json`);const ignore = require(`./ignoreUpdatesModules.json`);console.log(`npm i ${(Object.keys(t.dependencies || {}).filter((e)=>ignore.base.indexOf(e) === -1).map((e)=>(`${e}@latest`)).join(` `))} --save&&npm i ${(Object.keys(t.devDependencies || {}).filter((e)=>ignore.dev.indexOf(e) === -1).map((e)=>(`${e}@latest`)).join(` `))} --save-dev`);')\"",
52
53
  "prepublishOnly": "npm run clean && npm run build",
53
54
  "test": "npm run test:all",
54
55
  "test:all": "node --test --import tsx tests/unit.test.ts tests/error.test.ts tests/transport.test.ts",
@@ -96,8 +97,8 @@
96
97
  },
97
98
  "devDependencies": {
98
99
  "@types/node": "^20.11.17",
99
- "@typescript-eslint/eslint-plugin": "^8.42.0",
100
- "@typescript-eslint/parser": "^8.42.0",
100
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
101
+ "@typescript-eslint/parser": "^8.43.0",
101
102
  "eslint": "^9.35.0",
102
103
  "ts-node": "^10.9.2",
103
104
  "tsx": "^4.20.5",