@beignet/provider-cache-redis 0.0.32

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.js ADDED
@@ -0,0 +1,414 @@
1
+ /**
2
+ * @beignet/provider-cache-redis
3
+ *
4
+ * Redis provider that extends ports with cache capabilities using ioredis.
5
+ *
6
+ * Configuration:
7
+ * - REDIS_URL: Redis connection URL (required)
8
+ * - REDIS_DB: Redis database number (optional, default: 0)
9
+ * - REDIS_CONNECT_TIMEOUT_MS: Initial connection timeout in milliseconds (optional, default: 5000)
10
+ * - REDIS_MAX_RETRIES_PER_REQUEST: Per-command retry limit (optional, default: 2)
11
+ * - REDIS_CONNECT_MAX_ATTEMPTS: Connection attempts before startup fails (optional, default: 3)
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { createNextServer } from "@beignet/next";
16
+ * import { redisCacheProvider } from "@beignet/provider-cache-redis";
17
+ *
18
+ * const server = await createNextServer({
19
+ * ports: basePorts,
20
+ * providers: [redisCacheProvider],
21
+ * // ...
22
+ * });
23
+ *
24
+ * // In your use cases:
25
+ * async function myUseCase(ctx: AppCtx) {
26
+ * const cached = await ctx.ports.cache.get("key");
27
+ * if (!cached) {
28
+ * const value = await fetchData();
29
+ * await ctx.ports.cache.set("key", value, { ttlSeconds: 3600 });
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ import { createProvider, createProviderInstrumentation, } from "@beignet/core/providers";
35
+ import { Redis } from "ioredis";
36
+ import { z } from "zod";
37
+ const DEFAULT_CONNECT_TIMEOUT_MS = 5000;
38
+ const DEFAULT_MAX_RETRIES_PER_REQUEST = 2;
39
+ const DEFAULT_CONNECT_MAX_ATTEMPTS = 3;
40
+ const RECONNECT_BACKOFF_CAP_MS = 2000;
41
+ const NumberString = z
42
+ .string()
43
+ .regex(/^\d+$/, "Expected a non-negative integer string")
44
+ .transform((value) => Number.parseInt(value, 10));
45
+ /**
46
+ * Configuration schema for the Redis provider.
47
+ * Validates environment variables with REDIS_ prefix.
48
+ */
49
+ const RedisConfigSchema = z.object({
50
+ /**
51
+ * Redis connection URL.
52
+ * Example: "redis://localhost:6379"
53
+ */
54
+ URL: z.string().url(),
55
+ /**
56
+ * Redis database number (optional).
57
+ * Defaults to 0 if not specified.
58
+ */
59
+ DB: NumberString.optional(),
60
+ /**
61
+ * Timeout for the initial connection attempt, in milliseconds.
62
+ * Defaults to 5000.
63
+ */
64
+ CONNECT_TIMEOUT_MS: NumberString.default(DEFAULT_CONNECT_TIMEOUT_MS),
65
+ /**
66
+ * How many times a single command is retried before its promise rejects.
67
+ * Defaults to 2.
68
+ */
69
+ MAX_RETRIES_PER_REQUEST: NumberString.default(DEFAULT_MAX_RETRIES_PER_REQUEST),
70
+ /**
71
+ * Connection attempts allowed before startup `connect()` rejects.
72
+ * Defaults to 3.
73
+ */
74
+ CONNECT_MAX_ATTEMPTS: NumberString.default(DEFAULT_CONNECT_MAX_ATTEMPTS),
75
+ });
76
+ function errorMessage(error) {
77
+ return error instanceof Error ? error.message : String(error);
78
+ }
79
+ function redactConnectionUrl(url) {
80
+ try {
81
+ const parsed = new URL(url);
82
+ if (parsed.username)
83
+ parsed.username = "redacted";
84
+ if (parsed.password)
85
+ parsed.password = "redacted";
86
+ if (parsed.search)
87
+ parsed.search = "?redacted";
88
+ parsed.hash = "";
89
+ return parsed.toString();
90
+ }
91
+ catch {
92
+ return "[invalid URL]";
93
+ }
94
+ }
95
+ function reconnectBackoff(attempt) {
96
+ return Math.min(2 ** attempt * 100, RECONNECT_BACKOFF_CAP_MS);
97
+ }
98
+ async function checkRedisHealth(client) {
99
+ try {
100
+ const response = await client.ping();
101
+ return {
102
+ ok: true,
103
+ metadata: { adapter: "redis", response },
104
+ };
105
+ }
106
+ catch (error) {
107
+ return {
108
+ ok: false,
109
+ message: errorMessage(error),
110
+ metadata: { adapter: "redis" },
111
+ };
112
+ }
113
+ }
114
+ /**
115
+ * Create an env-backed Redis cache provider.
116
+ *
117
+ * Reads `REDIS_*` env vars, contributes `ports.cache`, and exposes
118
+ * `ports.redis` for raw ioredis client access.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const provider = createRedisCacheProvider({ connectTimeoutMs: 2000 });
123
+ * ```
124
+ */
125
+ export function createRedisCacheProvider(options = {}) {
126
+ const ConfigSchema = RedisConfigSchema.extend({
127
+ DB: options.db !== undefined
128
+ ? NumberString.default(options.db)
129
+ : RedisConfigSchema.shape.DB,
130
+ CONNECT_TIMEOUT_MS: options.connectTimeoutMs !== undefined
131
+ ? NumberString.default(options.connectTimeoutMs)
132
+ : RedisConfigSchema.shape.CONNECT_TIMEOUT_MS,
133
+ MAX_RETRIES_PER_REQUEST: options.maxRetriesPerRequest !== undefined
134
+ ? NumberString.default(options.maxRetriesPerRequest)
135
+ : RedisConfigSchema.shape.MAX_RETRIES_PER_REQUEST,
136
+ });
137
+ return createProvider({
138
+ name: "cache-redis",
139
+ config: {
140
+ schema: ConfigSchema,
141
+ envPrefix: "REDIS_",
142
+ },
143
+ async setup({ ports, config }) {
144
+ if (!config) {
145
+ throw new Error("[redisCacheProvider] Missing Redis config. " +
146
+ "Please set REDIS_URL environment variable.");
147
+ }
148
+ const connectMaxAttempts = config.CONNECT_MAX_ATTEMPTS ?? DEFAULT_CONNECT_MAX_ATTEMPTS;
149
+ // ioredis uses a single retryStrategy for both the initial connect and
150
+ // later reconnects, so track whether the first connect ever succeeded.
151
+ let connectedOnce = false;
152
+ const defaultRetryStrategy = (attempt) => {
153
+ if (!connectedOnce) {
154
+ // Stop retrying during the initial connect so `connect()` below
155
+ // rejects promptly instead of hanging against an unreachable host.
156
+ if (attempt >= connectMaxAttempts) {
157
+ return null;
158
+ }
159
+ return reconnectBackoff(attempt);
160
+ }
161
+ // After a successful connection, keep reconnecting with capped
162
+ // exponential backoff.
163
+ return reconnectBackoff(attempt);
164
+ };
165
+ const client = new Redis(config.URL, {
166
+ db: config.DB ?? options.db ?? 0,
167
+ // Defer connecting until the explicit connect() below so startup can
168
+ // surface a clear error instead of connecting in the background.
169
+ lazyConnect: true,
170
+ connectTimeout: config.CONNECT_TIMEOUT_MS ??
171
+ options.connectTimeoutMs ??
172
+ DEFAULT_CONNECT_TIMEOUT_MS,
173
+ maxRetriesPerRequest: config.MAX_RETRIES_PER_REQUEST ??
174
+ options.maxRetriesPerRequest ??
175
+ DEFAULT_MAX_RETRIES_PER_REQUEST,
176
+ retryStrategy: options.retryStrategy ?? defaultRetryStrategy,
177
+ });
178
+ // Test connection
179
+ try {
180
+ await client.connect();
181
+ connectedOnce = true;
182
+ }
183
+ catch (error) {
184
+ client.disconnect();
185
+ throw new Error(`[redisCacheProvider] Failed to connect to Redis at ${redactConnectionUrl(config.URL)}: ${errorMessage(error)}`);
186
+ }
187
+ const instrumentation = createProviderInstrumentation(ports, {
188
+ providerName: "cache-redis",
189
+ watcher: "cache",
190
+ });
191
+ const recordCacheEvent = (event) => {
192
+ instrumentation.custom({
193
+ name: `cache.${event.operation}`,
194
+ label: `Cache ${event.operation}`,
195
+ summary: event.summary,
196
+ details: {
197
+ operation: event.operation,
198
+ key: event.key,
199
+ ...event.details,
200
+ },
201
+ });
202
+ };
203
+ // Extend ports with cache API
204
+ const cache = {
205
+ get: async (key) => {
206
+ const startedAt = Date.now();
207
+ try {
208
+ const value = await client.get(key);
209
+ recordCacheEvent({
210
+ operation: "get",
211
+ key,
212
+ summary: value == null ? "Cache miss" : "Cache hit",
213
+ details: {
214
+ hit: value != null,
215
+ durationMs: Date.now() - startedAt,
216
+ },
217
+ });
218
+ return value;
219
+ }
220
+ catch (error) {
221
+ recordCacheEvent({
222
+ operation: "get.failed",
223
+ key,
224
+ summary: "Cache get failed",
225
+ details: {
226
+ durationMs: Date.now() - startedAt,
227
+ error: errorMessage(error),
228
+ },
229
+ });
230
+ throw error;
231
+ }
232
+ },
233
+ set: async (key, value, options) => {
234
+ const startedAt = Date.now();
235
+ try {
236
+ if (options?.ttlSeconds != null && options.ttlSeconds > 0) {
237
+ await client.set(key, value, "EX", options.ttlSeconds);
238
+ }
239
+ else {
240
+ await client.set(key, value);
241
+ }
242
+ recordCacheEvent({
243
+ operation: "set",
244
+ key,
245
+ summary: "Cache set",
246
+ details: {
247
+ ttlSeconds: options?.ttlSeconds ?? null,
248
+ durationMs: Date.now() - startedAt,
249
+ },
250
+ });
251
+ }
252
+ catch (error) {
253
+ recordCacheEvent({
254
+ operation: "set.failed",
255
+ key,
256
+ summary: "Cache set failed",
257
+ details: {
258
+ ttlSeconds: options?.ttlSeconds ?? null,
259
+ durationMs: Date.now() - startedAt,
260
+ error: errorMessage(error),
261
+ },
262
+ });
263
+ throw error;
264
+ }
265
+ },
266
+ delete: async (key) => {
267
+ const startedAt = Date.now();
268
+ try {
269
+ const deleted = (await client.del(key)) > 0;
270
+ recordCacheEvent({
271
+ operation: "delete",
272
+ key,
273
+ summary: deleted ? "Cache key deleted" : "Cache key missing",
274
+ details: {
275
+ deleted,
276
+ durationMs: Date.now() - startedAt,
277
+ },
278
+ });
279
+ return deleted;
280
+ }
281
+ catch (error) {
282
+ recordCacheEvent({
283
+ operation: "delete.failed",
284
+ key,
285
+ summary: "Cache delete failed",
286
+ details: {
287
+ durationMs: Date.now() - startedAt,
288
+ error: errorMessage(error),
289
+ },
290
+ });
291
+ throw error;
292
+ }
293
+ },
294
+ has: async (key) => {
295
+ const startedAt = Date.now();
296
+ try {
297
+ const result = await client.exists(key);
298
+ const exists = result === 1;
299
+ recordCacheEvent({
300
+ operation: "has",
301
+ key,
302
+ summary: exists ? "Cache key exists" : "Cache key missing",
303
+ details: {
304
+ exists,
305
+ durationMs: Date.now() - startedAt,
306
+ },
307
+ });
308
+ return exists;
309
+ }
310
+ catch (error) {
311
+ recordCacheEvent({
312
+ operation: "has.failed",
313
+ key,
314
+ summary: "Cache has failed",
315
+ details: {
316
+ durationMs: Date.now() - startedAt,
317
+ error: errorMessage(error),
318
+ },
319
+ });
320
+ throw error;
321
+ }
322
+ },
323
+ remember: async (key, factory, options) => {
324
+ const startedAt = Date.now();
325
+ try {
326
+ const cached = await client.get(key);
327
+ if (cached != null) {
328
+ recordCacheEvent({
329
+ operation: "remember",
330
+ key,
331
+ summary: "Cache remember hit",
332
+ details: {
333
+ hit: true,
334
+ ttlSeconds: options?.ttlSeconds ?? null,
335
+ durationMs: Date.now() - startedAt,
336
+ },
337
+ });
338
+ return cached;
339
+ }
340
+ const value = await factory();
341
+ if (options?.ttlSeconds != null && options.ttlSeconds > 0) {
342
+ await client.set(key, value, "EX", options.ttlSeconds);
343
+ }
344
+ else {
345
+ await client.set(key, value);
346
+ }
347
+ recordCacheEvent({
348
+ operation: "remember",
349
+ key,
350
+ summary: "Cache remember miss",
351
+ details: {
352
+ hit: false,
353
+ ttlSeconds: options?.ttlSeconds ?? null,
354
+ durationMs: Date.now() - startedAt,
355
+ },
356
+ });
357
+ return value;
358
+ }
359
+ catch (error) {
360
+ recordCacheEvent({
361
+ operation: "remember.failed",
362
+ key,
363
+ summary: "Cache remember failed",
364
+ details: {
365
+ ttlSeconds: options?.ttlSeconds ?? null,
366
+ durationMs: Date.now() - startedAt,
367
+ error: errorMessage(error),
368
+ },
369
+ });
370
+ throw error;
371
+ }
372
+ },
373
+ };
374
+ return {
375
+ ports: {
376
+ cache,
377
+ redis: {
378
+ client,
379
+ checkHealth: () => checkRedisHealth(client),
380
+ },
381
+ },
382
+ async stop() {
383
+ try {
384
+ await client.quit();
385
+ }
386
+ catch {
387
+ // Silently ignore errors during shutdown
388
+ }
389
+ },
390
+ };
391
+ },
392
+ });
393
+ }
394
+ /**
395
+ * Default env-backed Redis provider.
396
+ *
397
+ * Configuration via environment variables:
398
+ * - REDIS_URL: Redis connection URL (required)
399
+ * - REDIS_DB: Redis database number (optional)
400
+ * - REDIS_CONNECT_TIMEOUT_MS: Initial connection timeout in ms (optional)
401
+ * - REDIS_MAX_RETRIES_PER_REQUEST: Per-command retry limit (optional)
402
+ * - REDIS_CONNECT_MAX_ATTEMPTS: Connection attempts before startup fails (optional)
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * const server = await createNextServer({
407
+ * ports: basePorts,
408
+ * providers: [redisCacheProvider],
409
+ * // ...
410
+ * });
411
+ * ```
412
+ */
413
+ export const redisCacheProvider = createRedisCacheProvider();
414
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EACL,cAAc,EACd,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AAC1C,MAAM,4BAA4B,GAAG,CAAC,CAAC;AACvC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC,MAAM,YAAY,GAAG,CAAC;KACnB,MAAM,EAAE;KACR,KAAK,CAAC,OAAO,EAAE,wCAAwC,CAAC;KACxD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC;;;OAGG;IACH,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAErB;;;OAGG;IACH,EAAE,EAAE,YAAY,CAAC,QAAQ,EAAE;IAE3B;;;OAGG;IACH,kBAAkB,EAAE,YAAY,CAAC,OAAO,CAAC,0BAA0B,CAAC;IAEpE;;;OAGG;IACH,uBAAuB,EAAE,YAAY,CAAC,OAAO,CAC3C,+BAA+B,CAChC;IAED;;;OAGG;IACH,oBAAoB,EAAE,YAAY,CAAC,OAAO,CAAC,4BAA4B,CAAC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C,GAAG,EAAE,GAAG,SAAS;6BACnC;yBACF,CAAC,CAAC;wBAEH,OAAO,KAAK,CAAC;oBACf,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,gBAAgB,CAAC;4BACf,SAAS,EAAE,iBAAiB;4BAC5B,GAAG;4BACH,OAAO,EAAE,uBAAuB;4BAChC,OAAO,EAAE;gCACP,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,IAAI;gCACvC,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;gCAClC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;6BAC3B;yBACF,CAAC,CAAC;wBACH,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;aACF,CAAC;YAEF,OAAO;gBACL,KAAK,EAAE;oBACL,KAAK;oBACL,KAAK,EAAE;wBACL,MAAM;wBACN,WAAW,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC;qBAC5C;iBACgC;gBACnC,KAAK,CAAC,IAAI;oBACR,IAAI,CAAC;wBACH,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBACtB,CAAC;oBAAC,MAAM,CAAC;wBACP,yCAAyC;oBAC3C,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@beignet/provider-cache-redis",
3
+ "version": "0.0.32",
4
+ "type": "module",
5
+ "description": "Redis provider for Beignet - adds cache port using ioredis",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "!src/**/*.test.ts",
18
+ "!src/**/*.test.tsx",
19
+ "!src/**/*.test-d.ts",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "prepack": "bun run build",
26
+ "dev": "tsc --watch",
27
+ "clean": "rm -rf dist coverage .turbo",
28
+ "test": "bun test",
29
+ "test:coverage": "bun test --coverage",
30
+ "lint": "biome check ."
31
+ },
32
+ "keywords": [
33
+ "beignet",
34
+ "redis",
35
+ "provider",
36
+ "cache",
37
+ "ports"
38
+ ],
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/taylorbryant/beignet.git",
43
+ "directory": "packages/provider-cache-redis"
44
+ },
45
+ "author": "Taylor Bryant",
46
+ "homepage": "https://github.com/taylorbryant/beignet#readme",
47
+ "bugs": "https://github.com/taylorbryant/beignet/issues",
48
+ "sideEffects": false,
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "engines": {
53
+ "node": ">=18.0.0"
54
+ },
55
+ "peerDependencies": {
56
+ "@beignet/core": ">=0.0.3 <1.0.0",
57
+ "ioredis": "^5.0.0"
58
+ },
59
+ "dependencies": {
60
+ "zod": "^4.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "@beignet/devtools": "*",
64
+ "@types/bun": "^1.3.13",
65
+ "@types/node": "^20.10.0",
66
+ "ioredis": "^5.0.0",
67
+ "typescript": "^5.3.0"
68
+ },
69
+ "beignet": {
70
+ "provider": {
71
+ "displayName": "Redis cache provider",
72
+ "ports": [
73
+ "cache",
74
+ "redis"
75
+ ],
76
+ "appPorts": [
77
+ {
78
+ "name": "cache",
79
+ "type": "CachePort"
80
+ }
81
+ ],
82
+ "env": [
83
+ "REDIS_URL",
84
+ "REDIS_DB",
85
+ "REDIS_CONNECT_TIMEOUT_MS",
86
+ "REDIS_MAX_RETRIES_PER_REQUEST",
87
+ "REDIS_CONNECT_MAX_ATTEMPTS"
88
+ ],
89
+ "requiredEnv": [
90
+ "REDIS_URL"
91
+ ],
92
+ "watchers": [
93
+ "cache"
94
+ ],
95
+ "registration": {
96
+ "required": true,
97
+ "tokens": [
98
+ "redisCacheProvider",
99
+ "createRedisCacheProvider"
100
+ ]
101
+ }
102
+ }
103
+ }
104
+ }