next-cache-toolbar 0.2.1 → 0.3.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.
Files changed (29) hide show
  1. package/dist/cjs/{cache-entry-client-C0CjMKC5.js → cache-entry-client-BlFbLrtq.js} +34 -22
  2. package/dist/cjs/{cache-panel-context-client-FIUru-uB.js → cache-panel-context-client-CkDMJX2-.js} +7 -1
  3. package/dist/cjs/{cache-panel-head-client-Cs4uyFh7.js → cache-panel-head-client-BqfBWPpR.js} +30 -21
  4. package/dist/cjs/{cache-panel-table-client-9aBv-MjJ.js → cache-panel-table-client-DBvA6vo5.js} +2 -2
  5. package/dist/cjs/{cache-panel-trigger-client-CGeo22Q8.js → cache-panel-trigger-client-0RzTHzAT.js} +2 -3
  6. package/dist/cjs/{cache-panel-wrapper-client-puZq7rcV.js → cache-panel-wrapper-client-DTI35uJg.js} +2 -3
  7. package/dist/cjs/cache-purge-button-client-CXGIDomZ.js +25 -0
  8. package/dist/cjs/{cache-refresh-data-client-CrvqEMoX.js → cache-refresh-data-client-DJC8x360.js} +3 -4
  9. package/dist/cjs/{dialog-client-ChHtZVMD.js → dialog-client-eJy2OUEG.js} +18 -16
  10. package/dist/cjs/{getCacheEntries-server-DMz68ZTt.js → getCacheEntries-server-B4Sz1uw3.js} +41 -9
  11. package/dist/cjs/index.d.ts +6 -1
  12. package/dist/cjs/index.js +12 -10
  13. package/dist/cjs/purge-cache-server-GmkiFGoN.js +12 -0
  14. package/dist/es/{cache-entry-client-Ceh-eYDl.js → cache-entry-client-Bk7a0rFQ.mjs} +34 -22
  15. package/dist/es/{cache-panel-context-client-DCXKayLF.js → cache-panel-context-client-DlqXZGzO.mjs} +7 -1
  16. package/dist/es/{cache-panel-head-client-BBfig3xH.js → cache-panel-head-client-DTReOdNO.mjs} +15 -6
  17. package/dist/es/{cache-panel-table-client-C9YfopmF.js → cache-panel-table-client-B844eHwF.mjs} +2 -2
  18. package/dist/es/{cache-panel-trigger-client-CGReagL-.js → cache-panel-trigger-client-CbXiKLEx.mjs} +2 -3
  19. package/dist/es/{cache-panel-wrapper-client-CjKNX-hk.js → cache-panel-wrapper-client-Dcmlm3kc.mjs} +2 -3
  20. package/dist/es/cache-purge-button-client-CN9H6t8R.mjs +25 -0
  21. package/dist/es/{cache-refresh-data-client-Cb9wMeZh.js → cache-refresh-data-client-Cixnlkkn.mjs} +3 -4
  22. package/dist/es/{dialog-client-C319YNfG.js → dialog-client-D8kKKnZH.mjs} +2 -2
  23. package/dist/es/{getCacheEntries-server-BkR7kA29.js → getCacheEntries-server-CPw1bnT3.mjs} +41 -9
  24. package/dist/es/index.d.mts +6 -1
  25. package/dist/es/index.mjs +13 -11
  26. package/dist/es/purge-cache-server-Dd41_99d.mjs +12 -0
  27. package/dist/style.css +1 -1
  28. package/package.json +84 -84
  29. package/readme.md +32 -5
@@ -1,12 +1,11 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var classVarianceAuthority = require('class-variance-authority');
4
- var React = require('react');
5
3
  var clsx = require('clsx');
6
4
  var tailwindMerge = require('tailwind-merge');
5
+ var classVarianceAuthority = require('class-variance-authority');
7
6
  var reactSlot = require('@radix-ui/react-slot');
8
- var dialogClient = require('./dialog-client-ChHtZVMD.js');
9
- var lucideReact = require('lucide-react');
7
+ var React = require('react');
8
+ var dialogClient = require('./dialog-client-eJy2OUEG.js');
10
9
  var JsonView = require('react18-json-view');
11
10
 
12
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -115,13 +114,15 @@ const buttonVariants = classVarianceAuthority.cva("nct-inline-flex nct-items-cen
115
114
  outline: "nct-border nct-border-input nct-bg-background hover:nct-bg-accent hover:nct-text-accent-foreground",
116
115
  secondary: "nct-bg-secondary nct-text-secondary-foreground hover:nct-bg-secondary/80",
117
116
  ghost: "hover:nct-bg-accent hover:nct-text-accent-foreground",
118
- link: "nct-text-primary nct-underline-offset-4 hover:nct-underline"
117
+ link: "nct-text-primary nct-underline-offset-4 hover:nct-underline",
118
+ linkTable: "nct-text-muted-foreground"
119
119
  },
120
120
  size: {
121
121
  default: "nct-h-10 nct-px-4 nct-py-2",
122
122
  sm: "nct-h-9 nct-rounded-md nct-px-3",
123
123
  lg: "nct-h-11 nct-rounded-md nct-px-8",
124
- icon: "nct-h-10 nct-w-10"
124
+ icon: "nct-h-10 nct-w-10",
125
+ text: "h-auto"
125
126
  }
126
127
  },
127
128
  defaultVariants: {
@@ -144,7 +145,7 @@ const Button = /*#__PURE__*/ React__namespace.forwardRef(({ className, variant,
144
145
  Button.displayName = "Button";
145
146
 
146
147
  const getEntryRevalidateLeft = (cacheEntry)=>{
147
- if (!cacheEntry.data?.headers.date || !cacheEntry.revalidate) {
148
+ if (!cacheEntry.data?.headers?.date || !cacheEntry.revalidate) {
148
149
  return;
149
150
  }
150
151
  const cacheEntryDate = new Date(cacheEntry.data?.headers.date);
@@ -158,7 +159,7 @@ const CacheEntry = (props)=>{
158
159
  children: [
159
160
  /*#__PURE__*/ jsxRuntime.jsx(TableCell, {
160
161
  className: "nct-truncate nct-max-w-[25vw]",
161
- children: props.cacheEntry.data?.url
162
+ children: props.cacheEntry.data.url
162
163
  }),
163
164
  /*#__PURE__*/ jsxRuntime.jsx(TableCell, {
164
165
  title: cacheEntryRevalidateLeft?.toString() ?? "-",
@@ -166,12 +167,16 @@ const CacheEntry = (props)=>{
166
167
  children: "STALE"
167
168
  }) : props.cacheEntry.revalidate ?? "-"
168
169
  }),
169
- /*#__PURE__*/ jsxRuntime.jsx(TableCell, {
170
+ /*#__PURE__*/ jsxRuntime.jsxs(TableCell, {
170
171
  className: "nct-break-before-all",
171
- children: props.cacheEntry.tags.join("\n")
172
+ children: [
173
+ "[",
174
+ props.cacheEntry.tags.join(","),
175
+ "]"
176
+ ]
172
177
  }),
173
178
  /*#__PURE__*/ jsxRuntime.jsx(TableCell, {
174
- children: props.cacheEntry.data?.headers.date
179
+ children: props.cacheEntry.timestamp.toLocaleString()
175
180
  }),
176
181
  /*#__PURE__*/ jsxRuntime.jsxs(dialogClient.Dialog, {
177
182
  children: [
@@ -180,22 +185,29 @@ const CacheEntry = (props)=>{
180
185
  children: /*#__PURE__*/ jsxRuntime.jsx(TableCell, {
181
186
  className: "nct-flex nct-justify-center",
182
187
  children: /*#__PURE__*/ jsxRuntime.jsx(Button, {
183
- variant: "ghost",
184
- size: "icon",
185
- children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.Braces, {
186
- size: 16
187
- })
188
+ children: "show content"
188
189
  })
189
190
  })
190
191
  }),
191
- /*#__PURE__*/ jsxRuntime.jsx(dialogClient.DialogContent, {
192
+ /*#__PURE__*/ jsxRuntime.jsxs(dialogClient.DialogContent, {
192
193
  className: "sm:nct-max-w-3xl nct-max-h-[65vh] nct-overflow-y-auto nct-overflow-x-hidden",
193
- children: /*#__PURE__*/ jsxRuntime.jsx("div", {
194
- className: "nct-flex nct-items-center nct-space-x-2",
195
- children: /*#__PURE__*/ jsxRuntime.jsx(JsonView__default.default, {
196
- src: props.cacheEntry.data.body
194
+ children: [
195
+ /*#__PURE__*/ jsxRuntime.jsx(dialogClient.DialogTitle, {
196
+ className: "nct-hidden",
197
+ children: props.cacheEntry.data.url
198
+ }),
199
+ /*#__PURE__*/ jsxRuntime.jsx(dialogClient.DialogDescription, {
200
+ className: "nct-hidden",
201
+ children: props.cacheEntry.data.url
202
+ }),
203
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
204
+ className: "nct-flex nct-items-center nct-space-x-2",
205
+ children: /*#__PURE__*/ jsxRuntime.jsx(JsonView__default.default, {
206
+ src: props.cacheEntry.data.body,
207
+ collapsed: 1
208
+ })
197
209
  })
198
- })
210
+ ]
199
211
  })
200
212
  ]
201
213
  })
@@ -31,7 +31,7 @@ const sortCacheEntryByKey = (key, a, b)=>{
31
31
  return a.tags[0]?.localeCompare(b.tags[0] ?? "") ?? 0;
32
32
  case "timestamp":
33
33
  {
34
- if (!a.data?.headers.date || !b.data?.headers.date) {
34
+ if (!a.data?.headers?.date || !b.data?.headers?.date) {
35
35
  return 0;
36
36
  }
37
37
  return new Date(b.data.headers.date).getTime() - new Date(a.data.headers.date).getTime();
@@ -46,7 +46,13 @@ const CachePanelContextProvider = (props)=>{
46
46
  const [sorting, setSorting] = React.useState(undefined);
47
47
  const toggleOpen = ()=>{
48
48
  setIsOpen(!isOpen);
49
+ localStorage.setItem("cache-panel-open", (!isOpen).toString());
49
50
  };
51
+ React__default.default.useEffect(()=>{
52
+ if (typeof window !== "undefined") {
53
+ setIsOpen(localStorage.getItem("cache-panel-open") === "true");
54
+ }
55
+ }, []);
50
56
  const addFilter = (key, value)=>{
51
57
  setFilters((prev)=>{
52
58
  if (!prev) {
@@ -1,26 +1,26 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
3
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
4
4
  var React = require('react');
5
5
  var lucideReact = require('lucide-react');
6
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
6
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
7
7
 
8
8
  function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n.default = e;
23
- return n;
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return n;
24
24
  }
25
25
 
26
26
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
@@ -99,19 +99,28 @@ const CachePanelHead = ({ sortingProperty, children, className, withFilter = fal
99
99
  setFilterInputVisible(false);
100
100
  }
101
101
  };
102
+ const isActiveSortProperty = sorting?.key === sortingProperty;
103
+ const ariaSortAttribute = isActiveSortProperty ? sortingDirection === "asc" ? "ascending" : "descending" : undefined;
102
104
  return /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.TableHead, {
103
105
  className: cacheEntryClient.cn("group", className),
104
106
  ...props,
107
+ "aria-sort": ariaSortAttribute,
105
108
  children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
106
- className: cacheEntryClient.cn("nct-flex nct-items-center nct-gap-2 nct-py-2", sorting?.key === sortingProperty && "nct-underline"),
109
+ className: cacheEntryClient.cn("nct-flex nct-items-center nct-gap-2 nct-py-2", isActiveSortProperty && "nct-underline"),
107
110
  children: [
108
- /*#__PURE__*/ jsxRuntime.jsx("div", {
111
+ /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.Button, {
112
+ variant: "linkTable",
113
+ size: "text",
109
114
  onClick: onHeadClick,
110
115
  onKeyDown: onHeadClick,
111
116
  children: children
112
117
  }),
113
- sortingDirection === "asc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowDownAZIcon, {}),
114
- sortingDirection === "desc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowUpAZIcon, {}),
118
+ sortingDirection === "asc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowDownAZIcon, {
119
+ "aria-hidden": true
120
+ }),
121
+ sortingDirection === "desc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowUpAZIcon, {
122
+ "aria-hidden": true
123
+ }),
115
124
  withFilter && /*#__PURE__*/ jsxRuntime.jsxs("div", {
116
125
  className: "ml-auto",
117
126
  children: [
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
4
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
3
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
4
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
5
5
 
6
6
  const CachePanelTable = ()=>{
7
7
  const { entries } = cachePanelContextClient.useCachePanelContext();
@@ -1,8 +1,7 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
4
- require('react');
5
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
3
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
4
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
6
5
 
7
6
  function CachePanelTrigger(props) {
8
7
  const { toggleOpen } = cachePanelContextClient.useCachePanelContext();
@@ -1,8 +1,7 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
4
- require('react');
5
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
3
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
4
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
6
5
 
7
6
  const CacheTable = (props)=>{
8
7
  const { isOpen } = cachePanelContextClient.useCachePanelContext();
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ var jsxRuntime = require('react/jsx-runtime');
3
+ var purgeCacheServer = require('./purge-cache-server-GmkiFGoN.js');
4
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
5
+ var lucideReact = require('lucide-react');
6
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
7
+
8
+ function CachePurgeButton() {
9
+ const { setEntries } = cachePanelContextClient.useCachePanelContext();
10
+ const purgeCache = ()=>{
11
+ purgeCacheServer.purgeCache().then(()=>{
12
+ setEntries([]);
13
+ });
14
+ };
15
+ return /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.Button, {
16
+ variant: "outline",
17
+ size: "icon",
18
+ onClick: purgeCache,
19
+ children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.BombIcon, {
20
+ className: "nct-h-4 nct-w-4"
21
+ })
22
+ });
23
+ }
24
+
25
+ exports.CachePurgeButton = CachePurgeButton;
@@ -1,11 +1,11 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
- var getCacheEntriesServer = require('./getCacheEntries-server-DMz68ZTt.js');
4
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
3
+ var getCacheEntriesServer = require('./getCacheEntries-server-B4Sz1uw3.js');
4
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
5
5
  var lucideReact = require('lucide-react');
6
6
  var navigation = require('next/navigation');
7
7
  var React = require('react');
8
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
8
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
9
9
 
10
10
  function RefreshDataButton({ enabled, interval }) {
11
11
  const { setEntries } = cachePanelContextClient.useCachePanelContext();
@@ -18,7 +18,6 @@ function RefreshDataButton({ enabled, interval }) {
18
18
  });
19
19
  };
20
20
  React.useEffect(()=>{
21
- console.log("pathname changed", pathname);
22
21
  refreshData();
23
22
  }, [
24
23
  pathname
@@ -1,26 +1,26 @@
1
1
  'use client';
2
2
  var jsxRuntime = require('react/jsx-runtime');
3
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
3
4
  var DialogPrimitive = require('@radix-ui/react-dialog');
4
5
  var lucideReact = require('lucide-react');
5
6
  var React = require('react');
6
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
7
7
 
8
8
  function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n.default = e;
23
- return n;
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return n;
24
24
  }
25
25
 
26
26
  var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
@@ -77,4 +77,6 @@ DialogDescription.displayName = DialogPrimitive__namespace.Description.displayNa
77
77
 
78
78
  exports.Dialog = Dialog;
79
79
  exports.DialogContent = DialogContent;
80
+ exports.DialogDescription = DialogDescription;
81
+ exports.DialogTitle = DialogTitle;
80
82
  exports.DialogTrigger = DialogTrigger;
@@ -1,6 +1,6 @@
1
1
  'use server';
2
- var zod = require('zod');
3
2
  var node_fs = require('node:fs');
3
+ var zod = require('zod');
4
4
 
5
5
  const stringToJSONSchema = zod.z.string().transform((str, ctx)=>{
6
6
  try {
@@ -17,12 +17,26 @@ const stringToJSONSchema = zod.z.string().transform((str, ctx)=>{
17
17
  return zod.z.NEVER;
18
18
  }
19
19
  });
20
- const nextCacheFileSchema = zod.z.object({
20
+ const unstableCacheFileSchema = zod.z.object({
21
+ data: zod.z.object({
22
+ body: zod.z.string(),
23
+ headers: zod.z.object({}).transform(()=>null),
24
+ status: zod.z.number(),
25
+ url: zod.z.literal("")
26
+ }),
27
+ kind: zod.z.union([
28
+ zod.z.literal("FETCH"),
29
+ zod.z.unknown()
30
+ ]),
31
+ revalidate: zod.z.number().optional(),
32
+ tags: zod.z.array(zod.z.string()).optional().default([])
33
+ });
34
+ const fetchCacheFileSchema = zod.z.object({
21
35
  data: zod.z.object({
22
36
  body: zod.z.string(),
23
37
  headers: zod.z.record(zod.z.string(), zod.z.string()),
24
38
  status: zod.z.number(),
25
- url: zod.z.string()
39
+ url: zod.z.string().url()
26
40
  }),
27
41
  kind: zod.z.union([
28
42
  zod.z.literal("FETCH"),
@@ -30,12 +44,18 @@ const nextCacheFileSchema = zod.z.object({
30
44
  ]),
31
45
  revalidate: zod.z.number().optional(),
32
46
  tags: zod.z.array(zod.z.string()).optional().default([])
33
- }).transform((cacheEntry)=>{
34
- const body = stringToJSONSchema.parse(atob(cacheEntry.data.body));
47
+ });
48
+ const nextCacheFileSchema = zod.z.union([
49
+ unstableCacheFileSchema,
50
+ fetchCacheFileSchema
51
+ ]).transform((cacheEntry)=>{
52
+ const body = cacheEntry.data.url !== "" ? stringToJSONSchema.parse(atob(cacheEntry.data.body)) : stringToJSONSchema.parse(cacheEntry.data.body);
35
53
  return {
36
54
  ...cacheEntry,
55
+ timestamp: cacheEntry.data.headers?.date ? new Date(cacheEntry.data.headers?.date) : new Date(),
37
56
  data: {
38
57
  ...cacheEntry.data,
58
+ url: cacheEntry.data.url === "" ? "unstable_cache" : cacheEntry.data.url,
39
59
  body
40
60
  }
41
61
  };
@@ -54,14 +74,26 @@ const getCacheFiles = async ()=>{
54
74
  continue;
55
75
  }
56
76
  try {
57
- const fileContent = await node_fs.promises.readFile(`${cachePath}/${file}`);
58
- const cacheEntry = nextCacheFileSchema.parse(JSON.parse(fileContent.toString()));
59
- cacheFiles.set(file, cacheEntry);
77
+ const fileContent = await node_fs.promises.readFile(`${cachePath}/${file}`).catch((err)=>{
78
+ throw Error(`Error reading file ${file}`, {
79
+ cause: err
80
+ });
81
+ });
82
+ const fileStats = await node_fs.promises.stat(`${cachePath}/${file}`).catch((err)=>{
83
+ throw Error(`Error reading file ${file}`, {
84
+ cause: err
85
+ });
86
+ });
87
+ const jsonData = JSON.parse(fileContent.toString());
88
+ const cacheEntry = nextCacheFileSchema.parse(jsonData);
89
+ cacheFiles.set(file, {
90
+ ...cacheEntry,
91
+ timestamp: fileStats.birthtime
92
+ });
60
93
  } catch (error) {
61
94
  if (error instanceof zod.ZodError) {
62
95
  const issues = error.issues;
63
96
  console.error(`File ${file} do not match the schema`, issues);
64
- continue;
65
97
  }
66
98
  console.error(`Error parsing ${file}`);
67
99
  }
@@ -11,7 +11,12 @@ type Props = {
11
11
  * @default 10000
12
12
  */
13
13
  interval?: number;
14
+ /**
15
+ * If true, the purge button will be shown.
16
+ * @default false
17
+ */
18
+ purgeButton?: boolean;
14
19
  };
15
- declare function NextCacheToolbar({ autoRefresh, interval, }: Props): Promise<react_jsx_runtime.JSX.Element>;
20
+ declare function NextCacheToolbar({ autoRefresh, interval, purgeButton, }: Props): Promise<react_jsx_runtime.JSX.Element>;
16
21
 
17
22
  export { NextCacheToolbar };
package/dist/cjs/index.js CHANGED
@@ -2,16 +2,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var lucideReact = require('lucide-react');
5
- var getCacheEntriesServer = require('./getCacheEntries-server-DMz68ZTt.js');
6
- var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
7
- var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
8
- var cachePanelTableClient = require('./cache-panel-table-client-9aBv-MjJ.js');
9
- var cachePanelTriggerClient = require('./cache-panel-trigger-client-CGeo22Q8.js');
10
- var cachePanelWrapperClient = require('./cache-panel-wrapper-client-puZq7rcV.js');
11
- var cacheRefreshDataClient = require('./cache-refresh-data-client-CrvqEMoX.js');
12
- var cachePanelHeadClient = require('./cache-panel-head-client-Cs4uyFh7.js');
5
+ var getCacheEntriesServer = require('./getCacheEntries-server-B4Sz1uw3.js');
6
+ var cacheEntryClient = require('./cache-entry-client-BlFbLrtq.js');
7
+ var cachePanelContextClient = require('./cache-panel-context-client-CkDMJX2-.js');
8
+ var cachePanelTableClient = require('./cache-panel-table-client-DBvA6vo5.js');
9
+ var cachePanelTriggerClient = require('./cache-panel-trigger-client-0RzTHzAT.js');
10
+ var cachePanelWrapperClient = require('./cache-panel-wrapper-client-DTI35uJg.js');
11
+ var cachePurgeButtonClient = require('./cache-purge-button-client-CXGIDomZ.js');
12
+ var cacheRefreshDataClient = require('./cache-refresh-data-client-DJC8x360.js');
13
+ var cachePanelHeadClient = require('./cache-panel-head-client-BqfBWPpR.js');
13
14
 
14
- async function NextCacheToolbar({ autoRefresh = false, interval = 10000 }) {
15
+ async function NextCacheToolbar({ autoRefresh = false, interval = 10000, purgeButton = false }) {
15
16
  const files = await getCacheEntriesServer.getCacheFiles();
16
17
  return /*#__PURE__*/ jsxRuntime.jsx("div", {
17
18
  id: "next-cache-toolbar",
@@ -21,7 +22,7 @@ async function NextCacheToolbar({ autoRefresh = false, interval = 10000 }) {
21
22
  children: [
22
23
  /*#__PURE__*/ jsxRuntime.jsx(cachePanelTriggerClient.CachePanelTrigger, {
23
24
  className: "nct-fixed nct-rounded-full nct-bottom-4 nct-right-4 nct-bg-gradient-to-r nct-from-fuchsia-500 nct-to-cyan-500",
24
- children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.Braces, {})
25
+ children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.Layers3Icon, {})
25
26
  }),
26
27
  /*#__PURE__*/ jsxRuntime.jsxs(cachePanelWrapperClient.CacheTable, {
27
28
  children: [
@@ -57,6 +58,7 @@ async function NextCacheToolbar({ autoRefresh = false, interval = 10000 }) {
57
58
  enabled: autoRefresh,
58
59
  interval: interval
59
60
  }),
61
+ purgeButton && /*#__PURE__*/ jsxRuntime.jsx(cachePurgeButtonClient.CachePurgeButton, {}),
60
62
  /*#__PURE__*/ jsxRuntime.jsx(cachePanelTriggerClient.CachePanelTrigger, {
61
63
  children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.PanelBottomCloseIcon, {})
62
64
  })
@@ -0,0 +1,12 @@
1
+ 'use server';
2
+ var node_fs = require('node:fs');
3
+
4
+ const cachePath = ".next/cache/fetch-cache";
5
+ const purgeCache = async ()=>{
6
+ await node_fs.promises.rm(cachePath, {
7
+ recursive: true,
8
+ force: true
9
+ });
10
+ };
11
+
12
+ exports.purgeCache = purgeCache;
@@ -1,12 +1,11 @@
1
1
  'use client';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { cva } from 'class-variance-authority';
4
- import * as React from 'react';
5
3
  import { clsx } from 'clsx';
6
4
  import { twMerge } from 'tailwind-merge';
5
+ import { cva } from 'class-variance-authority';
7
6
  import { Slot } from '@radix-ui/react-slot';
8
- import { D as Dialog, a as DialogTrigger, b as DialogContent } from './dialog-client-C319YNfG.js';
9
- import { Braces } from 'lucide-react';
7
+ import * as React from 'react';
8
+ import { D as Dialog, a as DialogTrigger, b as DialogContent, c as DialogTitle, d as DialogDescription } from './dialog-client-D8kKKnZH.mjs';
10
9
  import JsonView from 'react18-json-view';
11
10
 
12
11
  function cn(...inputs) {
@@ -92,13 +91,15 @@ const buttonVariants = cva("nct-inline-flex nct-items-center nct-justify-center
92
91
  outline: "nct-border nct-border-input nct-bg-background hover:nct-bg-accent hover:nct-text-accent-foreground",
93
92
  secondary: "nct-bg-secondary nct-text-secondary-foreground hover:nct-bg-secondary/80",
94
93
  ghost: "hover:nct-bg-accent hover:nct-text-accent-foreground",
95
- link: "nct-text-primary nct-underline-offset-4 hover:nct-underline"
94
+ link: "nct-text-primary nct-underline-offset-4 hover:nct-underline",
95
+ linkTable: "nct-text-muted-foreground"
96
96
  },
97
97
  size: {
98
98
  default: "nct-h-10 nct-px-4 nct-py-2",
99
99
  sm: "nct-h-9 nct-rounded-md nct-px-3",
100
100
  lg: "nct-h-11 nct-rounded-md nct-px-8",
101
- icon: "nct-h-10 nct-w-10"
101
+ icon: "nct-h-10 nct-w-10",
102
+ text: "h-auto"
102
103
  }
103
104
  },
104
105
  defaultVariants: {
@@ -121,7 +122,7 @@ const Button = /*#__PURE__*/ React.forwardRef(({ className, variant, size, asChi
121
122
  Button.displayName = "Button";
122
123
 
123
124
  const getEntryRevalidateLeft = (cacheEntry)=>{
124
- if (!cacheEntry.data?.headers.date || !cacheEntry.revalidate) {
125
+ if (!cacheEntry.data?.headers?.date || !cacheEntry.revalidate) {
125
126
  return;
126
127
  }
127
128
  const cacheEntryDate = new Date(cacheEntry.data?.headers.date);
@@ -135,7 +136,7 @@ const CacheEntry = (props)=>{
135
136
  children: [
136
137
  /*#__PURE__*/ jsx(TableCell, {
137
138
  className: "nct-truncate nct-max-w-[25vw]",
138
- children: props.cacheEntry.data?.url
139
+ children: props.cacheEntry.data.url
139
140
  }),
140
141
  /*#__PURE__*/ jsx(TableCell, {
141
142
  title: cacheEntryRevalidateLeft?.toString() ?? "-",
@@ -143,12 +144,16 @@ const CacheEntry = (props)=>{
143
144
  children: "STALE"
144
145
  }) : props.cacheEntry.revalidate ?? "-"
145
146
  }),
146
- /*#__PURE__*/ jsx(TableCell, {
147
+ /*#__PURE__*/ jsxs(TableCell, {
147
148
  className: "nct-break-before-all",
148
- children: props.cacheEntry.tags.join("\n")
149
+ children: [
150
+ "[",
151
+ props.cacheEntry.tags.join(","),
152
+ "]"
153
+ ]
149
154
  }),
150
155
  /*#__PURE__*/ jsx(TableCell, {
151
- children: props.cacheEntry.data?.headers.date
156
+ children: props.cacheEntry.timestamp.toLocaleString()
152
157
  }),
153
158
  /*#__PURE__*/ jsxs(Dialog, {
154
159
  children: [
@@ -157,22 +162,29 @@ const CacheEntry = (props)=>{
157
162
  children: /*#__PURE__*/ jsx(TableCell, {
158
163
  className: "nct-flex nct-justify-center",
159
164
  children: /*#__PURE__*/ jsx(Button, {
160
- variant: "ghost",
161
- size: "icon",
162
- children: /*#__PURE__*/ jsx(Braces, {
163
- size: 16
164
- })
165
+ children: "show content"
165
166
  })
166
167
  })
167
168
  }),
168
- /*#__PURE__*/ jsx(DialogContent, {
169
+ /*#__PURE__*/ jsxs(DialogContent, {
169
170
  className: "sm:nct-max-w-3xl nct-max-h-[65vh] nct-overflow-y-auto nct-overflow-x-hidden",
170
- children: /*#__PURE__*/ jsx("div", {
171
- className: "nct-flex nct-items-center nct-space-x-2",
172
- children: /*#__PURE__*/ jsx(JsonView, {
173
- src: props.cacheEntry.data.body
171
+ children: [
172
+ /*#__PURE__*/ jsx(DialogTitle, {
173
+ className: "nct-hidden",
174
+ children: props.cacheEntry.data.url
175
+ }),
176
+ /*#__PURE__*/ jsx(DialogDescription, {
177
+ className: "nct-hidden",
178
+ children: props.cacheEntry.data.url
179
+ }),
180
+ /*#__PURE__*/ jsx("div", {
181
+ className: "nct-flex nct-items-center nct-space-x-2",
182
+ children: /*#__PURE__*/ jsx(JsonView, {
183
+ src: props.cacheEntry.data.body,
184
+ collapsed: 1
185
+ })
174
186
  })
175
- })
187
+ ]
176
188
  })
177
189
  ]
178
190
  })
@@ -27,7 +27,7 @@ const sortCacheEntryByKey = (key, a, b)=>{
27
27
  return a.tags[0]?.localeCompare(b.tags[0] ?? "") ?? 0;
28
28
  case "timestamp":
29
29
  {
30
- if (!a.data?.headers.date || !b.data?.headers.date) {
30
+ if (!a.data?.headers?.date || !b.data?.headers?.date) {
31
31
  return 0;
32
32
  }
33
33
  return new Date(b.data.headers.date).getTime() - new Date(a.data.headers.date).getTime();
@@ -42,7 +42,13 @@ const CachePanelContextProvider = (props)=>{
42
42
  const [sorting, setSorting] = useState(undefined);
43
43
  const toggleOpen = ()=>{
44
44
  setIsOpen(!isOpen);
45
+ localStorage.setItem("cache-panel-open", (!isOpen).toString());
45
46
  };
47
+ React__default.useEffect(()=>{
48
+ if (typeof window !== "undefined") {
49
+ setIsOpen(localStorage.getItem("cache-panel-open") === "true");
50
+ }
51
+ }, []);
46
52
  const addFilter = (key, value)=>{
47
53
  setFilters((prev)=>{
48
54
  if (!prev) {