@motiadev/adapter-redis-state 0.11.1-beta.156-491458 → 0.11.2-beta.157-492501

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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { RedisStateAdapter } from './redis-state-adapter';
2
- export type { RedisStateAdapterConfig } from './types';
2
+ export type { RedisStateAdapterOptions } from './types';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA"}
@@ -1,11 +1,13 @@
1
1
  import type { StateAdapter, StateItem, StateItemsInput } from '@motiadev/core';
2
- import type { RedisStateAdapterConfig } from './types';
2
+ import { type RedisClientOptions, type RedisClientType } from 'redis';
3
+ import type { RedisStateAdapterOptions } from './types';
3
4
  export declare class RedisStateAdapter implements StateAdapter {
4
5
  private client;
5
6
  private keyPrefix;
6
7
  private ttl?;
7
8
  private connected;
8
- constructor(config: RedisStateAdapterConfig);
9
+ private isExternalClient;
10
+ constructor(redisConnection: RedisClientType | RedisClientOptions, options?: RedisStateAdapterOptions);
9
11
  private connect;
10
12
  private ensureConnected;
11
13
  private makeKey;
@@ -1 +1 @@
1
- {"version":3,"file":"redis-state-adapter.d.ts","sourceRoot":"","sources":["../src/redis-state-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAe,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE3F,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AI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOxC,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAiB7B,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAkD3C,QAAQ;IAgBtB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,aAAa;CAmCtB"}
@@ -2,42 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RedisStateAdapter = void 0;
4
4
  const redis_1 = require("redis");
5
+ function isRedisClient(input) {
6
+ return typeof input === 'object' && 'isOpen' in input && 'connect' in input;
7
+ }
5
8
  class RedisStateAdapter {
6
- constructor(config) {
9
+ constructor(redisConnection, options) {
7
10
  this.connected = false;
8
- this.keyPrefix = config.keyPrefix || 'motia:state:';
9
- this.ttl = config.ttl;
10
- this.client = (0, redis_1.createClient)({
11
- socket: {
12
- host: config.host || 'localhost',
13
- port: config.port || 6379,
14
- reconnectStrategy: config.socket?.reconnectStrategy ||
15
- ((retries) => {
16
- if (retries > 10) {
17
- return new Error('Redis connection retry limit exceeded');
18
- }
19
- return Math.min(retries * 100, 3000);
20
- }),
21
- connectTimeout: config.socket?.connectTimeout || 10000,
22
- },
23
- password: config.password,
24
- username: config.username,
25
- database: config.database || 0,
26
- });
27
- this.client.on('error', (err) => {
28
- console.error('[Redis State] Client error:', err);
29
- });
30
- this.client.on('connect', () => {
31
- this.connected = true;
32
- });
33
- this.client.on('disconnect', () => {
34
- console.warn('[Redis State] Disconnected');
35
- this.connected = false;
36
- });
37
- this.client.on('reconnecting', () => {
38
- console.log('[Redis State] Reconnecting...');
39
- });
40
- this.connect();
11
+ this.keyPrefix = options?.keyPrefix || 'motia:state:';
12
+ this.ttl = options?.ttl;
13
+ if (isRedisClient(redisConnection)) {
14
+ this.client = redisConnection;
15
+ this.isExternalClient = true;
16
+ this.connected = this.client.isOpen;
17
+ }
18
+ else {
19
+ const config = redisConnection;
20
+ this.isExternalClient = false;
21
+ this.client = (0, redis_1.createClient)(config);
22
+ this.client.on('error', (err) => {
23
+ console.error('[Redis State] Client error:', err);
24
+ });
25
+ this.client.on('connect', () => {
26
+ this.connected = true;
27
+ });
28
+ this.client.on('disconnect', () => {
29
+ console.warn('[Redis State] Disconnected');
30
+ this.connected = false;
31
+ });
32
+ this.client.on('reconnecting', () => {
33
+ console.log('[Redis State] Reconnecting...');
34
+ });
35
+ this.connect();
36
+ }
41
37
  }
42
38
  async connect() {
43
39
  if (!this.connected && !this.client.isOpen) {
@@ -115,7 +111,7 @@ class RedisStateAdapter {
115
111
  }
116
112
  }
117
113
  async cleanup() {
118
- if (this.client.isOpen) {
114
+ if (!this.isExternalClient && this.client.isOpen) {
119
115
  await this.client.quit();
120
116
  }
121
117
  }
@@ -186,15 +182,15 @@ class RedisStateAdapter {
186
182
  }
187
183
  async scanKeys(pattern) {
188
184
  const keys = [];
189
- let cursor = 0;
185
+ let cursor = '0';
190
186
  do {
191
- const result = await this.client.scan(cursor, {
187
+ const result = await this.client.scan(cursor.toString(), {
192
188
  MATCH: pattern,
193
189
  COUNT: 100,
194
190
  });
195
191
  cursor = result.cursor;
196
192
  keys.push(...result.keys);
197
- } while (cursor !== 0);
193
+ } while (String(cursor) !== '0');
198
194
  return keys;
199
195
  }
200
196
  applyFilters(items, filters) {
package/dist/types.d.ts CHANGED
@@ -1,14 +1,5 @@
1
- export interface RedisStateAdapterConfig {
2
- host?: string;
3
- port?: number;
4
- password?: string;
5
- username?: string;
6
- database?: number;
1
+ export interface RedisStateAdapterOptions {
7
2
  keyPrefix?: string;
8
3
  ttl?: number;
9
- socket?: {
10
- reconnectStrategy?: (retries: number) => number | Error;
11
- connectTimeout?: number;
12
- };
13
4
  }
14
5
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE;QACP,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,KAAK,CAAA;QACvD,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,CAAA;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb"}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Redis state adapter for Motia framework, enabling distributed state management across multiple instances.",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
- "version": "0.11.1-beta.156-491458",
6
+ "version": "0.11.2-beta.157-492501",
7
7
  "dependencies": {
8
- "redis": "^4.7.0",
9
- "@motiadev/core": "0.11.1-beta.156-491458"
8
+ "redis": "^5.9.0",
9
+ "@motiadev/core": "0.11.2-beta.157-492501"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/node": "^22.10.2",