Skip to content

Commit ac56405

Browse files
committed
Exported proxy and abort signal helper
1 parent b53cdd2 commit ac56405

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
lines changed

packages/nextjs-cache-handler/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nextjs-cache-handler/package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"next",
1919
"redis"
2020
],
21-
"version": "2.1.0-canary",
21+
"version": "2.1.0-canary2",
2222
"type": "module",
2323
"license": "MIT",
2424
"description": "Next.js cache handlers",
@@ -34,6 +34,14 @@
3434
"./instrumentation": {
3535
"require": "./dist/instrumentation/instrumentation.cjs",
3636
"import": "./dist/instrumentation/instrumentation.js"
37+
},
38+
"./cluster/withProxy": {
39+
"require": "./dist/helpers/withProxy.cjs",
40+
"import": "./dist/helpers/withProxy.js"
41+
},
42+
"./helpers/withAbortSignal": {
43+
"require": "./dist/helpers/withAbortSignal.cjs",
44+
"import": "./dist/helpers/withAbortSignal.js"
3745
}
3846
},
3947
"typesVersions": {
@@ -55,6 +63,12 @@
5563
],
5664
"redis-cluster-strings": [
5765
"dist/handlers/redis-cluster-strings.d.ts"
66+
],
67+
"cluster/withProxy": [
68+
"dist/helpers/withProxy.d.ts"
69+
],
70+
"helpers/withAbortSignal": [
71+
"dist/helpers/withAbortSignal.d.ts"
5872
]
5973
}
6074
},

packages/nextjs-cache-handler/src/handlers/redis-cluster-strings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Handler } from "./cache-handler.types";
22
import { CreateRedisClusterStringsHandlerOptions } from "./redis-cluster-strings.types";
33
import createRedisStringsHandler from "./redis-strings";
4-
import { withAbortSignalWrapper } from "../helpers/redisClusterProxy";
4+
import { withProxy } from "../helpers/redisClusterProxy";
55

66
/**
77
* Creates a Handler for handling cache operations using Redis Cluster strings.
@@ -23,7 +23,7 @@ export default function createHandler({
2323
...options
2424
}: CreateRedisClusterStringsHandlerOptions): Handler {
2525
return createRedisStringsHandler({
26-
client: withAbortSignalWrapper(client),
26+
client: withProxy(client),
2727
...options,
2828
});
2929
}

packages/nextjs-cache-handler/src/handlers/redis-strings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
parseBuffersToStrings,
88
} from "../helpers/buffer";
99
import { RedisClientType, RedisClusterType } from "@redis/client";
10-
import { WithAbortSignalCluster } from "../helpers/redisClusterProxy";
10+
import { RedisClusterWithAbortSignal } from "../helpers/redisClusterProxy";
1111

1212
/**
1313
* Creates a Handler for handling cache operations using Redis strings.
@@ -33,7 +33,7 @@ export default function createHandler({
3333
keyExpirationStrategy = "EXPIREAT",
3434
revalidateTagQuerySize = 10_000,
3535
}: CreateRedisStringsHandlerOptions<
36-
RedisClientType | WithAbortSignalCluster<RedisClusterType>
36+
RedisClientType | RedisClusterWithAbortSignal<RedisClusterType>
3737
>): Handler {
3838
function assertClientIsReady(): void {
3939
if (!client.isReady) {
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import type { RedisClusterType } from "@redis/client";
22
import { withAbortSignal } from "./withAbortSignal";
33

4-
export type WithAbortSignalCluster<T extends RedisClusterType> = T & {
4+
export type RedisClusterWithAbortSignal<T extends RedisClusterType> = T & {
55
withAbortSignal(signal: AbortSignal): T;
66
isReady: boolean;
77
};
88

9-
export function withAbortSignalWrapper<T extends RedisClusterType>(
10-
client: T,
9+
export function withProxy<T extends RedisClusterType>(
10+
cluster: T,
1111
defaultSignal?: AbortSignal,
12-
): WithAbortSignalCluster<T> {
12+
): RedisClusterWithAbortSignal<T> {
1313
let signal: AbortSignal | undefined = defaultSignal;
1414

1515
const handler: ProxyHandler<T> = {
1616
get(target, prop, receiver) {
1717
if (prop === "withAbortSignal") {
1818
return (s: AbortSignal) => {
1919
signal = s;
20-
return new Proxy(client, handler);
20+
return new Proxy(cluster, handler);
2121
};
2222
}
2323

2424
if (prop === "isReady") {
25-
return client.isOpen;
25+
return cluster.replicas.every((s) => s.client?.isReady);
2626
}
2727

2828
const orig = Reflect.get(target, prop, receiver);
@@ -34,5 +34,5 @@ export function withAbortSignalWrapper<T extends RedisClusterType>(
3434
},
3535
};
3636

37-
return new Proxy(client, handler) as WithAbortSignalCluster<T>;
37+
return new Proxy(cluster, handler) as RedisClusterWithAbortSignal<T>;
3838
}

packages/nextjs-cache-handler/tsup.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { defineConfig } from "tsup";
22

33
export const tsup = defineConfig({
44
name: "Build cache-handler",
5-
entry: ["src/handlers/*.ts", "src/instrumentation/*.ts"],
5+
entry: [
6+
"src/handlers/*.ts",
7+
"src/instrumentation/*.ts",
8+
"src/helpers/redisClusterProxy.ts",
9+
"src/helpers/withAbortSignal.ts",
10+
],
611
splitting: false,
712
outDir: "dist",
813
clean: false,

0 commit comments

Comments
 (0)