@mastra/redis 1.0.1 → 1.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/CHANGELOG.md +15 -0
- package/dist/docs/SKILL.md +22 -0
- package/dist/docs/assets/SOURCE_MAP.json +6 -0
- package/dist/docs/references/reference-storage-redis.md +266 -0
- package/dist/index.cjs +1804 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1795 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/db/index.d.ts +26 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +65 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +51 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +25 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +47 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/store.d.ts +66 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/types.d.ts +88 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/utils.d.ts +8 -0
- package/dist/storage/utils.d.ts.map +1 -0
- package/package.json +8 -9
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
2
|
+
import type { StorageDomains } from '@mastra/core/storage';
|
|
3
|
+
import type { RedisClient, RedisConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Redis storage adapter for Mastra.
|
|
6
|
+
*
|
|
7
|
+
* Provides storage functionality for direct Redis connections using the official redis package.
|
|
8
|
+
*
|
|
9
|
+
* Access domain-specific storage via `getStore()`:
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Using connection string
|
|
14
|
+
* const storage = new RedisStore({
|
|
15
|
+
* id: 'my-store',
|
|
16
|
+
* connectionString: 'redis://localhost:6379',
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Using host/port
|
|
20
|
+
* const storage = new RedisStore({
|
|
21
|
+
* id: 'my-store',
|
|
22
|
+
* host: 'localhost',
|
|
23
|
+
* port: 6379,
|
|
24
|
+
* password: 'secret',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Access memory domain
|
|
28
|
+
* const memory = await storage.getStore('memory');
|
|
29
|
+
* await memory?.saveThread({ thread });
|
|
30
|
+
*
|
|
31
|
+
* // Access workflows domain
|
|
32
|
+
* const workflows = await storage.getStore('workflows');
|
|
33
|
+
* await workflows?.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Using a pre-configured client for advanced features
|
|
39
|
+
* import { createClient } from 'redis';
|
|
40
|
+
*
|
|
41
|
+
* const client = createClient({
|
|
42
|
+
* url: 'redis://localhost:6379',
|
|
43
|
+
* socket: {
|
|
44
|
+
* reconnectStrategy: (retries) => Math.min(retries * 50, 2000),
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
* await client.connect();
|
|
48
|
+
*
|
|
49
|
+
* const storage = new RedisStore({
|
|
50
|
+
* id: 'my-store',
|
|
51
|
+
* client,
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare class RedisStore extends MastraStorage {
|
|
56
|
+
private client;
|
|
57
|
+
private shouldManageConnection;
|
|
58
|
+
stores: StorageDomains;
|
|
59
|
+
constructor(config: RedisConfig);
|
|
60
|
+
init(): Promise<void>;
|
|
61
|
+
getClient(): RedisClient;
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
private createClient;
|
|
64
|
+
private createClientUrl;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/storage/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,qBAAa,UAAW,SAAQ,aAAa;IAC3C,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,sBAAsB,CAAU;IACjC,MAAM,EAAE,cAAc,CAAC;gBAElB,MAAM,EAAE,WAAW;IAcT,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAOpC,SAAS,IAAI,WAAW;IAIlB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnC,OAAO,CAAC,YAAY;IA+BpB,OAAO,CAAC,eAAe;CASxB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { RedisClientType } from 'redis';
|
|
2
|
+
export type RedisClient = RedisClientType<Record<string, never>, Record<string, never>, Record<string, never>>;
|
|
3
|
+
/**
|
|
4
|
+
* Redis configuration type.
|
|
5
|
+
*
|
|
6
|
+
* Accepts either:
|
|
7
|
+
* - A pre-configured redis client: `{ id, client }`
|
|
8
|
+
* - Connection string: `{ id, connectionString }`
|
|
9
|
+
* - Host/port config: `{ id, host, port?, password?, db? }`
|
|
10
|
+
*/
|
|
11
|
+
export type RedisConfig = {
|
|
12
|
+
id: string;
|
|
13
|
+
/**
|
|
14
|
+
* When true, automatic initialization (table creation/migrations) is disabled.
|
|
15
|
+
* This is useful for CI/CD pipelines where you want to:
|
|
16
|
+
* 1. Run migrations explicitly during deployment (not at runtime)
|
|
17
|
+
* 2. Use different credentials for schema changes vs runtime operations
|
|
18
|
+
*
|
|
19
|
+
* When disableInit is true:
|
|
20
|
+
* - The storage will not automatically create/alter tables on first use
|
|
21
|
+
* - You must call `storage.init()` explicitly in your CI/CD scripts
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // In CI/CD script:
|
|
25
|
+
* const storage = new RedisStore({ ...config, disableInit: false });
|
|
26
|
+
* await storage.init(); // Explicitly run migrations
|
|
27
|
+
*
|
|
28
|
+
* // In runtime application:
|
|
29
|
+
* const storage = new RedisStore({ ...config, disableInit: true });
|
|
30
|
+
* // No auto-init, tables must already exist
|
|
31
|
+
*/
|
|
32
|
+
disableInit?: boolean;
|
|
33
|
+
} & ({
|
|
34
|
+
/**
|
|
35
|
+
* Pre-configured redis client (from the official `redis` package).
|
|
36
|
+
* Use this when you need to configure the client before initialization,
|
|
37
|
+
* e.g., to set custom socket options or interceptors.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { createClient } from 'redis';
|
|
42
|
+
*
|
|
43
|
+
* const client = createClient({
|
|
44
|
+
* url: 'redis://localhost:6379',
|
|
45
|
+
* socket: {
|
|
46
|
+
* reconnectStrategy: (retries) => Math.min(retries * 50, 2000),
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
* await client.connect();
|
|
50
|
+
*
|
|
51
|
+
* const store = new RedisStore({ id: 'my-store', client });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
client: RedisClient;
|
|
55
|
+
} | {
|
|
56
|
+
/**
|
|
57
|
+
* Redis connection string URL.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const store = new RedisStore({
|
|
62
|
+
* id: 'my-store',
|
|
63
|
+
* connectionString: 'redis://user:password@localhost:6379/0',
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
connectionString: string;
|
|
68
|
+
} | {
|
|
69
|
+
/**
|
|
70
|
+
* Redis host address.
|
|
71
|
+
*/
|
|
72
|
+
host: string;
|
|
73
|
+
/**
|
|
74
|
+
* Redis port number.
|
|
75
|
+
* @default 6379
|
|
76
|
+
*/
|
|
77
|
+
port?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Redis password for authentication.
|
|
80
|
+
*/
|
|
81
|
+
password?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Redis database number.
|
|
84
|
+
* @default 0
|
|
85
|
+
*/
|
|
86
|
+
db?: number;
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/storage/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE/G;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,CACA;IACE;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,EAAE,WAAW,CAAC;CACrB,GACD;IACE;;;;;;;;;;OAUG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACD;IACE;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RedisClient, RedisConfig } from './types.js';
|
|
2
|
+
export declare function isClientConfig(config: RedisConfig): config is RedisConfig & {
|
|
3
|
+
client: RedisClient;
|
|
4
|
+
};
|
|
5
|
+
export declare function isConnectionStringConfig(config: RedisConfig): config is RedisConfig & {
|
|
6
|
+
connectionString: string;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/storage/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExD,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAEnG;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,WAAW,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAElH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/redis",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Redis storage provider for Mastra - provides storage capabilities for direct Redis connections",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "22.13.17",
|
|
28
|
-
"@vitest/coverage-v8": "4.1.
|
|
29
|
-
"@vitest/ui": "4.1.
|
|
28
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
29
|
+
"@vitest/ui": "4.1.5",
|
|
30
30
|
"dotenv": "^17.0.0",
|
|
31
31
|
"eslint": "^9.37.0",
|
|
32
32
|
"tsup": "^8.5.0",
|
|
33
33
|
"typescript": "^5.9.3",
|
|
34
|
-
"vitest": "4.1.
|
|
35
|
-
"@internal/
|
|
36
|
-
"@internal/
|
|
37
|
-
"@internal/
|
|
38
|
-
"@mastra/core": "1.
|
|
34
|
+
"vitest": "4.1.5",
|
|
35
|
+
"@internal/lint": "0.0.87",
|
|
36
|
+
"@internal/types-builder": "0.0.62",
|
|
37
|
+
"@internal/storage-test-utils": "0.0.83",
|
|
38
|
+
"@mastra/core": "1.29.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
@@ -62,7 +62,6 @@
|
|
|
62
62
|
"posttest": "docker compose down",
|
|
63
63
|
"lint": "eslint .",
|
|
64
64
|
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
65
|
-
"build:docs": "pnpx tsx ../../scripts/generate-package-docs.ts stores/redis",
|
|
66
65
|
"build:watch": "tsup --watch --silent --config tsup.config.ts"
|
|
67
66
|
}
|
|
68
67
|
}
|