@motiadev/adapter-redis-state 0.11.1-beta.156-879726 → 0.11.1-beta.156-491458

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 { RedisStateAdapterOptions } from './types';
2
+ export type { RedisStateAdapterConfig } 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,wBAAwB,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,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
@@ -1,13 +1,11 @@
1
1
  import type { StateAdapter, StateItem, StateItemsInput } from '@motiadev/core';
2
- import { type RedisClientOptions, type RedisClientType } from 'redis';
3
- import type { RedisStateAdapterOptions } from './types';
2
+ import type { RedisStateAdapterConfig } from './types';
4
3
  export declare class RedisStateAdapter implements StateAdapter {
5
4
  private client;
6
5
  private keyPrefix;
7
6
  private ttl?;
8
7
  private connected;
9
- private isExternalClient;
10
- constructor(redisConnection: RedisClientType | RedisClientOptions, options?: RedisStateAdapterOptions);
8
+ constructor(config: RedisStateAdapterConfig);
11
9
  private connect;
12
10
  private ensureConnected;
13
11
  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;AAC3F,OA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,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,38 +2,42 @@
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
- }
8
5
  class RedisStateAdapter {
9
- constructor(redisConnection, options) {
6
+ constructor(config) {
10
7
  this.connected = false;
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
- }
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();
37
41
  }
38
42
  async connect() {
39
43
  if (!this.connected && !this.client.isOpen) {
@@ -111,7 +115,7 @@ class RedisStateAdapter {
111
115
  }
112
116
  }
113
117
  async cleanup() {
114
- if (!this.isExternalClient && this.client.isOpen) {
118
+ if (this.client.isOpen) {
115
119
  await this.client.quit();
116
120
  }
117
121
  }
@@ -182,15 +186,15 @@ class RedisStateAdapter {
182
186
  }
183
187
  async scanKeys(pattern) {
184
188
  const keys = [];
185
- let cursor = '0';
189
+ let cursor = 0;
186
190
  do {
187
- const result = await this.client.scan(cursor.toString(), {
191
+ const result = await this.client.scan(cursor, {
188
192
  MATCH: pattern,
189
193
  COUNT: 100,
190
194
  });
191
195
  cursor = result.cursor;
192
196
  keys.push(...result.keys);
193
- } while (String(cursor) !== '0');
197
+ } while (cursor !== 0);
194
198
  return keys;
195
199
  }
196
200
  applyFilters(items, filters) {
package/dist/types.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- export interface RedisStateAdapterOptions {
1
+ export interface RedisStateAdapterConfig {
2
+ host?: string;
3
+ port?: number;
4
+ password?: string;
5
+ username?: string;
6
+ database?: number;
2
7
  keyPrefix?: string;
3
8
  ttl?: number;
9
+ socket?: {
10
+ reconnectStrategy?: (retries: number) => number | Error;
11
+ connectTimeout?: number;
12
+ };
4
13
  }
5
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
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"}
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"}
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-879726",
6
+ "version": "0.11.1-beta.156-491458",
7
7
  "dependencies": {
8
- "redis": "^5.9.0",
9
- "@motiadev/core": "0.11.1-beta.156-879726"
8
+ "redis": "^4.7.0",
9
+ "@motiadev/core": "0.11.1-beta.156-491458"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/node": "^22.10.2",