@chat-adapter/state-ioredis 4.0.0
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 +75 -0
- package/dist/index.js +192 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { StateAdapter, Lock } from 'chat';
|
|
2
|
+
import Redis from 'ioredis';
|
|
3
|
+
|
|
4
|
+
interface IoRedisStateAdapterOptions {
|
|
5
|
+
/** Redis connection URL (e.g., redis://localhost:6379) */
|
|
6
|
+
url: string;
|
|
7
|
+
/** Key prefix for all Redis keys (default: "chat-sdk") */
|
|
8
|
+
keyPrefix?: string;
|
|
9
|
+
}
|
|
10
|
+
interface IoRedisStateClientOptions {
|
|
11
|
+
/** Existing ioredis client instance */
|
|
12
|
+
client: Redis;
|
|
13
|
+
/** Key prefix for all Redis keys (default: "chat-sdk") */
|
|
14
|
+
keyPrefix?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Redis state adapter using ioredis for production use.
|
|
18
|
+
*
|
|
19
|
+
* Provides persistent subscriptions and distributed locking
|
|
20
|
+
* across multiple server instances.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // With URL
|
|
25
|
+
* const state = createIoRedisState({ url: process.env.REDIS_URL });
|
|
26
|
+
*
|
|
27
|
+
* // With existing client
|
|
28
|
+
* const client = new Redis(process.env.REDIS_URL);
|
|
29
|
+
* const state = createIoRedisState({ client });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare class IoRedisStateAdapter implements StateAdapter {
|
|
33
|
+
private client;
|
|
34
|
+
private keyPrefix;
|
|
35
|
+
private connected;
|
|
36
|
+
private connectPromise;
|
|
37
|
+
private ownsClient;
|
|
38
|
+
constructor(options: IoRedisStateAdapterOptions | IoRedisStateClientOptions);
|
|
39
|
+
private key;
|
|
40
|
+
private subscriptionsSetKey;
|
|
41
|
+
connect(): Promise<void>;
|
|
42
|
+
disconnect(): Promise<void>;
|
|
43
|
+
subscribe(threadId: string): Promise<void>;
|
|
44
|
+
unsubscribe(threadId: string): Promise<void>;
|
|
45
|
+
isSubscribed(threadId: string): Promise<boolean>;
|
|
46
|
+
listSubscriptions(adapterName?: string): AsyncIterable<string>;
|
|
47
|
+
acquireLock(threadId: string, ttlMs: number): Promise<Lock | null>;
|
|
48
|
+
releaseLock(lock: Lock): Promise<void>;
|
|
49
|
+
extendLock(lock: Lock, ttlMs: number): Promise<boolean>;
|
|
50
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
51
|
+
set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
52
|
+
delete(key: string): Promise<void>;
|
|
53
|
+
private ensureConnected;
|
|
54
|
+
/**
|
|
55
|
+
* Get the underlying ioredis client for advanced usage.
|
|
56
|
+
*/
|
|
57
|
+
getClient(): Redis;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create an ioredis state adapter.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // With URL
|
|
65
|
+
* const state = createIoRedisState({ url: process.env.REDIS_URL });
|
|
66
|
+
*
|
|
67
|
+
* // With existing client
|
|
68
|
+
* import Redis from "ioredis";
|
|
69
|
+
* const client = new Redis(process.env.REDIS_URL);
|
|
70
|
+
* const state = createIoRedisState({ client });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function createIoRedisState(options: IoRedisStateAdapterOptions | IoRedisStateClientOptions): IoRedisStateAdapter;
|
|
74
|
+
|
|
75
|
+
export { IoRedisStateAdapter, type IoRedisStateAdapterOptions, type IoRedisStateClientOptions, createIoRedisState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import Redis from "ioredis";
|
|
3
|
+
var IoRedisStateAdapter = class {
|
|
4
|
+
client;
|
|
5
|
+
keyPrefix;
|
|
6
|
+
connected = false;
|
|
7
|
+
connectPromise = null;
|
|
8
|
+
ownsClient;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
if ("client" in options) {
|
|
11
|
+
this.client = options.client;
|
|
12
|
+
this.ownsClient = false;
|
|
13
|
+
} else {
|
|
14
|
+
this.client = new Redis(options.url);
|
|
15
|
+
this.ownsClient = true;
|
|
16
|
+
}
|
|
17
|
+
this.keyPrefix = options.keyPrefix || "chat-sdk";
|
|
18
|
+
this.client.on("error", (err) => {
|
|
19
|
+
console.error("[chat-sdk] ioredis client error:", err);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
key(type, id) {
|
|
23
|
+
return `${this.keyPrefix}:${type}:${id}`;
|
|
24
|
+
}
|
|
25
|
+
subscriptionsSetKey() {
|
|
26
|
+
return `${this.keyPrefix}:subscriptions`;
|
|
27
|
+
}
|
|
28
|
+
async connect() {
|
|
29
|
+
if (this.connected) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!this.connectPromise) {
|
|
33
|
+
this.connectPromise = new Promise((resolve, reject) => {
|
|
34
|
+
if (this.client.status === "ready") {
|
|
35
|
+
this.connected = true;
|
|
36
|
+
resolve();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.client.once("ready", () => {
|
|
40
|
+
this.connected = true;
|
|
41
|
+
resolve();
|
|
42
|
+
});
|
|
43
|
+
this.client.once("error", (err) => {
|
|
44
|
+
reject(err);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
await this.connectPromise;
|
|
49
|
+
}
|
|
50
|
+
async disconnect() {
|
|
51
|
+
if (this.connected && this.ownsClient) {
|
|
52
|
+
await this.client.quit();
|
|
53
|
+
this.connected = false;
|
|
54
|
+
this.connectPromise = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async subscribe(threadId) {
|
|
58
|
+
this.ensureConnected();
|
|
59
|
+
await this.client.sadd(this.subscriptionsSetKey(), threadId);
|
|
60
|
+
}
|
|
61
|
+
async unsubscribe(threadId) {
|
|
62
|
+
this.ensureConnected();
|
|
63
|
+
await this.client.srem(this.subscriptionsSetKey(), threadId);
|
|
64
|
+
}
|
|
65
|
+
async isSubscribed(threadId) {
|
|
66
|
+
this.ensureConnected();
|
|
67
|
+
const result = await this.client.sismember(
|
|
68
|
+
this.subscriptionsSetKey(),
|
|
69
|
+
threadId
|
|
70
|
+
);
|
|
71
|
+
return result === 1;
|
|
72
|
+
}
|
|
73
|
+
async *listSubscriptions(adapterName) {
|
|
74
|
+
this.ensureConnected();
|
|
75
|
+
let cursor = "0";
|
|
76
|
+
do {
|
|
77
|
+
const [nextCursor, members] = await this.client.sscan(
|
|
78
|
+
this.subscriptionsSetKey(),
|
|
79
|
+
cursor,
|
|
80
|
+
"COUNT",
|
|
81
|
+
100
|
|
82
|
+
);
|
|
83
|
+
cursor = nextCursor;
|
|
84
|
+
for (const threadId of members) {
|
|
85
|
+
if (adapterName) {
|
|
86
|
+
if (threadId.startsWith(`${adapterName}:`)) {
|
|
87
|
+
yield threadId;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
yield threadId;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} while (cursor !== "0");
|
|
94
|
+
}
|
|
95
|
+
async acquireLock(threadId, ttlMs) {
|
|
96
|
+
this.ensureConnected();
|
|
97
|
+
const token = generateToken();
|
|
98
|
+
const lockKey = this.key("lock", threadId);
|
|
99
|
+
const acquired = await this.client.set(lockKey, token, "PX", ttlMs, "NX");
|
|
100
|
+
if (acquired === "OK") {
|
|
101
|
+
return {
|
|
102
|
+
threadId,
|
|
103
|
+
token,
|
|
104
|
+
expiresAt: Date.now() + ttlMs
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
async releaseLock(lock) {
|
|
110
|
+
this.ensureConnected();
|
|
111
|
+
const lockKey = this.key("lock", lock.threadId);
|
|
112
|
+
const script = `
|
|
113
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
114
|
+
return redis.call("del", KEYS[1])
|
|
115
|
+
else
|
|
116
|
+
return 0
|
|
117
|
+
end
|
|
118
|
+
`;
|
|
119
|
+
await this.client.eval(script, 1, lockKey, lock.token);
|
|
120
|
+
}
|
|
121
|
+
async extendLock(lock, ttlMs) {
|
|
122
|
+
this.ensureConnected();
|
|
123
|
+
const lockKey = this.key("lock", lock.threadId);
|
|
124
|
+
const script = `
|
|
125
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
126
|
+
return redis.call("pexpire", KEYS[1], ARGV[2])
|
|
127
|
+
else
|
|
128
|
+
return 0
|
|
129
|
+
end
|
|
130
|
+
`;
|
|
131
|
+
const result = await this.client.eval(
|
|
132
|
+
script,
|
|
133
|
+
1,
|
|
134
|
+
lockKey,
|
|
135
|
+
lock.token,
|
|
136
|
+
ttlMs.toString()
|
|
137
|
+
);
|
|
138
|
+
return result === 1;
|
|
139
|
+
}
|
|
140
|
+
async get(key) {
|
|
141
|
+
this.ensureConnected();
|
|
142
|
+
const cacheKey = this.key("cache", key);
|
|
143
|
+
const value = await this.client.get(cacheKey);
|
|
144
|
+
if (value === null) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
return JSON.parse(value);
|
|
149
|
+
} catch {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async set(key, value, ttlMs) {
|
|
154
|
+
this.ensureConnected();
|
|
155
|
+
const cacheKey = this.key("cache", key);
|
|
156
|
+
const serialized = JSON.stringify(value);
|
|
157
|
+
if (ttlMs) {
|
|
158
|
+
await this.client.set(cacheKey, serialized, "PX", ttlMs);
|
|
159
|
+
} else {
|
|
160
|
+
await this.client.set(cacheKey, serialized);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async delete(key) {
|
|
164
|
+
this.ensureConnected();
|
|
165
|
+
const cacheKey = this.key("cache", key);
|
|
166
|
+
await this.client.del(cacheKey);
|
|
167
|
+
}
|
|
168
|
+
ensureConnected() {
|
|
169
|
+
if (!this.connected) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
"IoRedisStateAdapter is not connected. Call connect() first."
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get the underlying ioredis client for advanced usage.
|
|
177
|
+
*/
|
|
178
|
+
getClient() {
|
|
179
|
+
return this.client;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function generateToken() {
|
|
183
|
+
return `ioredis_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
184
|
+
}
|
|
185
|
+
function createIoRedisState(options) {
|
|
186
|
+
return new IoRedisStateAdapter(options);
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
IoRedisStateAdapter,
|
|
190
|
+
createIoRedisState
|
|
191
|
+
};
|
|
192
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Lock, StateAdapter } from \"chat\";\nimport Redis from \"ioredis\";\n\nexport interface IoRedisStateAdapterOptions {\n /** Redis connection URL (e.g., redis://localhost:6379) */\n url: string;\n /** Key prefix for all Redis keys (default: \"chat-sdk\") */\n keyPrefix?: string;\n}\n\nexport interface IoRedisStateClientOptions {\n /** Existing ioredis client instance */\n client: Redis;\n /** Key prefix for all Redis keys (default: \"chat-sdk\") */\n keyPrefix?: string;\n}\n\n/**\n * Redis state adapter using ioredis for production use.\n *\n * Provides persistent subscriptions and distributed locking\n * across multiple server instances.\n *\n * @example\n * ```typescript\n * // With URL\n * const state = createIoRedisState({ url: process.env.REDIS_URL });\n *\n * // With existing client\n * const client = new Redis(process.env.REDIS_URL);\n * const state = createIoRedisState({ client });\n * ```\n */\nexport class IoRedisStateAdapter implements StateAdapter {\n private client: Redis;\n private keyPrefix: string;\n private connected = false;\n private connectPromise: Promise<void> | null = null;\n private ownsClient: boolean;\n\n constructor(options: IoRedisStateAdapterOptions | IoRedisStateClientOptions) {\n if (\"client\" in options) {\n this.client = options.client;\n this.ownsClient = false;\n } else {\n this.client = new Redis(options.url);\n this.ownsClient = true;\n }\n this.keyPrefix = options.keyPrefix || \"chat-sdk\";\n\n // Handle connection errors\n this.client.on(\"error\", (err) => {\n console.error(\"[chat-sdk] ioredis client error:\", err);\n });\n }\n\n private key(type: \"sub\" | \"lock\" | \"cache\", id: string): string {\n return `${this.keyPrefix}:${type}:${id}`;\n }\n\n private subscriptionsSetKey(): string {\n return `${this.keyPrefix}:subscriptions`;\n }\n\n async connect(): Promise<void> {\n // ioredis auto-connects, but we track state for consistency\n if (this.connected) {\n return;\n }\n\n // Reuse existing connection attempt to avoid race conditions\n if (!this.connectPromise) {\n this.connectPromise = new Promise<void>((resolve, reject) => {\n if (this.client.status === \"ready\") {\n this.connected = true;\n resolve();\n return;\n }\n\n this.client.once(\"ready\", () => {\n this.connected = true;\n resolve();\n });\n\n this.client.once(\"error\", (err) => {\n reject(err);\n });\n });\n }\n\n await this.connectPromise;\n }\n\n async disconnect(): Promise<void> {\n if (this.connected && this.ownsClient) {\n await this.client.quit();\n this.connected = false;\n this.connectPromise = null;\n }\n }\n\n async subscribe(threadId: string): Promise<void> {\n this.ensureConnected();\n await this.client.sadd(this.subscriptionsSetKey(), threadId);\n }\n\n async unsubscribe(threadId: string): Promise<void> {\n this.ensureConnected();\n await this.client.srem(this.subscriptionsSetKey(), threadId);\n }\n\n async isSubscribed(threadId: string): Promise<boolean> {\n this.ensureConnected();\n const result = await this.client.sismember(\n this.subscriptionsSetKey(),\n threadId,\n );\n return result === 1;\n }\n\n async *listSubscriptions(adapterName?: string): AsyncIterable<string> {\n this.ensureConnected();\n\n // Use SSCAN for large sets to avoid blocking\n let cursor = \"0\";\n do {\n const [nextCursor, members] = await this.client.sscan(\n this.subscriptionsSetKey(),\n cursor,\n \"COUNT\",\n 100,\n );\n cursor = nextCursor;\n\n for (const threadId of members) {\n if (adapterName) {\n if (threadId.startsWith(`${adapterName}:`)) {\n yield threadId;\n }\n } else {\n yield threadId;\n }\n }\n } while (cursor !== \"0\");\n }\n\n async acquireLock(threadId: string, ttlMs: number): Promise<Lock | null> {\n this.ensureConnected();\n\n const token = generateToken();\n const lockKey = this.key(\"lock\", threadId);\n\n // Use SET NX PX for atomic lock acquisition\n const acquired = await this.client.set(lockKey, token, \"PX\", ttlMs, \"NX\");\n\n if (acquired === \"OK\") {\n return {\n threadId,\n token,\n expiresAt: Date.now() + ttlMs,\n };\n }\n\n return null;\n }\n\n async releaseLock(lock: Lock): Promise<void> {\n this.ensureConnected();\n\n const lockKey = this.key(\"lock\", lock.threadId);\n\n // Use Lua script for atomic check-and-delete\n const script = `\n if redis.call(\"get\", KEYS[1]) == ARGV[1] then\n return redis.call(\"del\", KEYS[1])\n else\n return 0\n end\n `;\n\n await this.client.eval(script, 1, lockKey, lock.token);\n }\n\n async extendLock(lock: Lock, ttlMs: number): Promise<boolean> {\n this.ensureConnected();\n\n const lockKey = this.key(\"lock\", lock.threadId);\n\n // Use Lua script for atomic check-and-extend\n const script = `\n if redis.call(\"get\", KEYS[1]) == ARGV[1] then\n return redis.call(\"pexpire\", KEYS[1], ARGV[2])\n else\n return 0\n end\n `;\n\n const result = await this.client.eval(\n script,\n 1,\n lockKey,\n lock.token,\n ttlMs.toString(),\n );\n\n return result === 1;\n }\n\n async get<T = unknown>(key: string): Promise<T | null> {\n this.ensureConnected();\n\n const cacheKey = this.key(\"cache\", key);\n const value = await this.client.get(cacheKey);\n\n if (value === null) {\n return null;\n }\n\n try {\n return JSON.parse(value) as T;\n } catch {\n // If parsing fails, return as string\n return value as unknown as T;\n }\n }\n\n async set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void> {\n this.ensureConnected();\n\n const cacheKey = this.key(\"cache\", key);\n const serialized = JSON.stringify(value);\n\n if (ttlMs) {\n await this.client.set(cacheKey, serialized, \"PX\", ttlMs);\n } else {\n await this.client.set(cacheKey, serialized);\n }\n }\n\n async delete(key: string): Promise<void> {\n this.ensureConnected();\n\n const cacheKey = this.key(\"cache\", key);\n await this.client.del(cacheKey);\n }\n\n private ensureConnected(): void {\n if (!this.connected) {\n throw new Error(\n \"IoRedisStateAdapter is not connected. Call connect() first.\",\n );\n }\n }\n\n /**\n * Get the underlying ioredis client for advanced usage.\n */\n getClient(): Redis {\n return this.client;\n }\n}\n\nfunction generateToken(): string {\n return `ioredis_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;\n}\n\n/**\n * Create an ioredis state adapter.\n *\n * @example\n * ```typescript\n * // With URL\n * const state = createIoRedisState({ url: process.env.REDIS_URL });\n *\n * // With existing client\n * import Redis from \"ioredis\";\n * const client = new Redis(process.env.REDIS_URL);\n * const state = createIoRedisState({ client });\n * ```\n */\nexport function createIoRedisState(\n options: IoRedisStateAdapterOptions | IoRedisStateClientOptions,\n): IoRedisStateAdapter {\n return new IoRedisStateAdapter(options);\n}\n"],"mappings":";AACA,OAAO,WAAW;AAgCX,IAAM,sBAAN,MAAkD;AAAA,EAC/C;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,iBAAuC;AAAA,EACvC;AAAA,EAER,YAAY,SAAiE;AAC3E,QAAI,YAAY,SAAS;AACvB,WAAK,SAAS,QAAQ;AACtB,WAAK,aAAa;AAAA,IACpB,OAAO;AACL,WAAK,SAAS,IAAI,MAAM,QAAQ,GAAG;AACnC,WAAK,aAAa;AAAA,IACpB;AACA,SAAK,YAAY,QAAQ,aAAa;AAGtC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ;AAC/B,cAAQ,MAAM,oCAAoC,GAAG;AAAA,IACvD,CAAC;AAAA,EACH;AAAA,EAEQ,IAAI,MAAgC,IAAoB;AAC9D,WAAO,GAAG,KAAK,SAAS,IAAI,IAAI,IAAI,EAAE;AAAA,EAC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B,UAAM,WAAW,KAAK,IAAI,SAAS,GAAG;AACtC,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,QAAQ;AAE5C,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AAEA,QAAI;AACF,aAAO,KAAK,MAAM,KAAK;AAAA,IACzB,QAAQ;AAEN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,IAAiB,KAAa,OAAU,OAA+B;AAC3E,SAAK,gBAAgB;AAErB,UAAM,WAAW,KAAK,IAAI,SAAS,GAAG;AACtC,UAAM,aAAa,KAAK,UAAU,KAAK;AAEvC,QAAI,OAAO;AACT,YAAM,KAAK,OAAO,IAAI,UAAU,YAAY,MAAM,KAAK;AAAA,IACzD,OAAO;AACL,YAAM,KAAK,OAAO,IAAI,UAAU,UAAU;AAAA,IAC5C;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,SAAK,gBAAgB;AAErB,UAAM,WAAW,KAAK,IAAI,SAAS,GAAG;AACtC,UAAM,KAAK,OAAO,IAAI,QAAQ;AAAA,EAChC;AAAA,EAEQ,kBAAwB;AAC9B,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,YAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,SAAS,gBAAwB;AAC/B,SAAO,WAAW,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,EAAE,CAAC;AAC7E;AAgBO,SAAS,mBACd,SACqB;AACrB,SAAO,IAAI,oBAAoB,OAAO;AACxC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chat-adapter/state-ioredis",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "ioredis state adapter for chat (production)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ioredis": "^5.4.1",
|
|
20
|
+
"chat": "4.0.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.10.2",
|
|
27
|
+
"tsup": "^8.3.5",
|
|
28
|
+
"typescript": "^5.7.2",
|
|
29
|
+
"vitest": "^2.1.8"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"chat",
|
|
33
|
+
"state",
|
|
34
|
+
"ioredis",
|
|
35
|
+
"redis",
|
|
36
|
+
"production"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"dev": "tsup --watch",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"lint": "biome check src",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
}
|
|
48
|
+
}
|