@motiadev/adapter-redis-state 0.11.2-beta.156 → 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
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
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;
|
|
1
|
+
{"version":3,"file":"redis-state-adapter.d.ts","sourceRoot":"","sources":["../src/redis-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AAG,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(
|
|
9
|
+
constructor(redisConnection, options) {
|
|
7
10
|
this.connected = false;
|
|
8
|
-
this.keyPrefix =
|
|
9
|
-
this.ttl =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,
|
|
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.2-beta.
|
|
6
|
+
"version": "0.11.2-beta.157-492501",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"redis": "^
|
|
9
|
-
"@motiadev/core": "0.11.2-beta.
|
|
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",
|