Skip to content

Commit 58af07b

Browse files
committed
review fix
1 parent 4ef4d2d commit 58af07b

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

.changeset/neat-hornets-call.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@opennextjs/cloudflare": patch
33
---
44

5-
Add a new `withFilter` tag cache to allow to filter the tag cache used
5+
Add a new `withFilter` tag cache to allow to filter the tags used

packages/cloudflare/src/api/overrides/tag-cache/tag-cache-filter.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("withFilter", () => {
2020

2121
it("should filter out tags based on writeTags", async () => {
2222
const tagCache = withFilter({
23-
originalTagCache: mockedTagCache,
23+
tagCache: mockedTagCache,
2424
filterFn,
2525
});
2626

@@ -32,7 +32,7 @@ describe("withFilter", () => {
3232

3333
it("should not call writeTags if no tags are valid", async () => {
3434
const tagCache = withFilter({
35-
originalTagCache: mockedTagCache,
35+
tagCache: mockedTagCache,
3636
filterFn,
3737
});
3838
const tags = ["invalid_tag"];
@@ -42,7 +42,7 @@ describe("withFilter", () => {
4242

4343
it("should filter out tags based on hasBeenRevalidated", async () => {
4444
const tagCache = withFilter({
45-
originalTagCache: mockedTagCache,
45+
tagCache: mockedTagCache,
4646
filterFn,
4747
});
4848

@@ -55,7 +55,7 @@ describe("withFilter", () => {
5555

5656
it("should not call hasBeenRevalidated if no tags are valid", async () => {
5757
const tagCache = withFilter({
58-
originalTagCache: mockedTagCache,
58+
tagCache: mockedTagCache,
5959
filterFn,
6060
});
6161
const tags = ["invalid_tag"];
@@ -66,7 +66,7 @@ describe("withFilter", () => {
6666

6767
it("should filter out tags based on getPathsByTags", async () => {
6868
const tagCache = withFilter({
69-
originalTagCache: mockedTagCache,
69+
tagCache: mockedTagCache,
7070
filterFn,
7171
});
7272

@@ -78,7 +78,7 @@ describe("withFilter", () => {
7878

7979
it("should not call getPathsByTags if no tags are valid", async () => {
8080
const tagCache = withFilter({
81-
originalTagCache: mockedTagCache,
81+
tagCache: mockedTagCache,
8282
filterFn,
8383
});
8484
const tags = ["invalid_tag"];
@@ -88,7 +88,7 @@ describe("withFilter", () => {
8888

8989
it("should return the correct name", () => {
9090
const tagCache = withFilter({
91-
originalTagCache: mockedTagCache,
91+
tagCache: mockedTagCache,
9292
filterFn,
9393
});
9494

@@ -97,7 +97,7 @@ describe("withFilter", () => {
9797

9898
it("should not create a function if getPathsByTags is not defined", async () => {
9999
const tagCache = withFilter({
100-
originalTagCache: {
100+
tagCache: {
101101
...mockedTagCache,
102102
getPathsByTags: undefined,
103103
},
@@ -107,9 +107,9 @@ describe("withFilter", () => {
107107
expect(tagCache.getPathsByTags).toBeUndefined();
108108
});
109109

110-
it("should properly filter soft tags", () => {
110+
it("should filter soft tags", () => {
111111
const tagCache = withFilter({
112-
originalTagCache: mockedTagCache,
112+
tagCache: mockedTagCache,
113113
filterFn: softTagFilter,
114114
});
115115

packages/cloudflare/src/api/overrides/tag-cache/tag-cache-filter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,45 @@ interface WithFilterOptions {
55
* The original tag cache.
66
* Call to this will receive only the filtered tags.
77
*/
8-
originalTagCache: NextModeTagCache;
8+
tagCache: NextModeTagCache;
99
/**
1010
* The function to filter tags.
1111
* @param tag The tag to filter.
12-
* @returns true if the tag should be forwarde, false otherwise.
12+
* @returns true if the tag should be forwarded, false otherwise.
1313
*/
1414
filterFn: (tag: string) => boolean;
1515
}
1616

1717
/**
1818
* Creates a new tag cache that filters tags based on the provided filter function.
19-
* This is usefult to remove tags that are not used by the app, this could reduce the number of request to the underlying tag cache.
19+
* This is useful to remove tags that are not used by the app, this could reduce the number of requests to the underlying tag cache.
2020
*/
21-
export function withFilter({ originalTagCache, filterFn }: WithFilterOptions): NextModeTagCache {
21+
export function withFilter({ tagCache, filterFn }: WithFilterOptions): NextModeTagCache {
2222
return {
23-
name: `filtered-${originalTagCache.name}`,
23+
name: `filtered-${tagCache.name}`,
2424
mode: "nextMode",
25-
getPathsByTags: originalTagCache.getPathsByTags
25+
getPathsByTags: tagCache.getPathsByTags
2626
? async (tags) => {
2727
const filteredTags = tags.filter(filterFn);
2828
if (filteredTags.length === 0) {
2929
return [];
3030
}
31-
return originalTagCache.getPathsByTags!(filteredTags);
31+
return tagCache.getPathsByTags!(filteredTags);
3232
}
3333
: undefined,
3434
hasBeenRevalidated: async (tags, lastModified) => {
3535
const filteredTags = tags.filter(filterFn);
3636
if (filteredTags.length === 0) {
3737
return false;
3838
}
39-
return originalTagCache.hasBeenRevalidated(filteredTags, lastModified);
39+
return tagCache.hasBeenRevalidated(filteredTags, lastModified);
4040
},
4141
writeTags: async (tags) => {
4242
const filteredTags = tags.filter(filterFn);
4343
if (filteredTags.length === 0) {
4444
return;
4545
}
46-
return originalTagCache.writeTags(filteredTags);
46+
return tagCache.writeTags(filteredTags);
4747
},
4848
};
4949
}

0 commit comments

Comments
 (0)