next-cache-toolbar 0.1.2 → 0.2.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/cjs/{cache-entry-client-Cg2-NRrZ.js → cache-entry-client-C0CjMKC5.js} +11 -12
- package/dist/cjs/cache-panel-context-client-FIUru-uB.js +115 -0
- package/dist/cjs/cache-panel-head-client-Cs4uyFh7.js +139 -0
- package/dist/cjs/cache-panel-table-client-9aBv-MjJ.js +22 -0
- package/dist/cjs/{cache-panel-trigger-client-ChZncD_2.js → cache-panel-trigger-client-CGeo22Q8.js} +2 -2
- package/dist/cjs/{cache-panel-wrapper-client-DE5QrmN0.js → cache-panel-wrapper-client-2eJisZgJ.js} +2 -2
- package/dist/cjs/cache-refresh-data-client-VWar7JpG.js +48 -0
- package/dist/cjs/{dialog-client-AZHsTC7l.js → dialog-client-ChHtZVMD.js} +16 -16
- package/dist/cjs/getCacheEntries-server-BheTh0n9.js +72 -0
- package/dist/cjs/index.d.ts +13 -1
- package/dist/cjs/index.js +19 -86
- package/dist/es/{cache-entry-client-CtWrVYTN.js → cache-entry-client-Ceh-eYDl.js} +11 -14
- package/dist/es/cache-panel-context-client-DCXKayLF.js +110 -0
- package/dist/es/cache-panel-head-client-BBfig3xH.js +120 -0
- package/dist/es/cache-panel-table-client-C9YfopmF.js +22 -0
- package/dist/es/{cache-panel-trigger-client-GrlxjSO5.js → cache-panel-trigger-client-CGReagL-.js} +2 -2
- package/dist/es/{cache-panel-wrapper-client-BosTuysv.js → cache-panel-wrapper-client-Cv0HcuJC.js} +2 -2
- package/dist/es/cache-refresh-data-client-BjsJkQ5H.js +48 -0
- package/dist/es/{dialog-client-D5Q_DDEF.js → dialog-client-C319YNfG.js} +1 -1
- package/dist/es/getCacheEntries-server-CgNUCSp3.js +72 -0
- package/dist/es/index.d.mts +13 -1
- package/dist/es/index.mjs +18 -85
- package/dist/style.css +1 -2
- package/package.json +15 -9
- package/readme.md +4 -0
- package/dist/cjs/cache-panel-context-client-B1EgwMzI.js +0 -33
- package/dist/cjs/cache-panel-head-client-CbhKAPhZ.js +0 -46
- package/dist/cjs/cache-panel-table-client-CuP76AwU.js +0 -56
- package/dist/cjs/refresh-data-button-client-D4e_gWso.js +0 -28
- package/dist/es/cache-panel-context-client-D5NKXXpF.js +0 -28
- package/dist/es/cache-panel-head-client-CZC6pddt.js +0 -46
- package/dist/es/cache-panel-table-client-Qc84cSj6.js +0 -56
- package/dist/es/refresh-data-button-client-DaxVafNg.js +0 -28
|
@@ -5,7 +5,7 @@ var React = require('react');
|
|
|
5
5
|
var clsx = require('clsx');
|
|
6
6
|
var tailwindMerge = require('tailwind-merge');
|
|
7
7
|
var reactSlot = require('@radix-ui/react-slot');
|
|
8
|
-
var dialogClient = require('./dialog-client-
|
|
8
|
+
var dialogClient = require('./dialog-client-ChHtZVMD.js');
|
|
9
9
|
var lucideReact = require('lucide-react');
|
|
10
10
|
var JsonView = require('react18-json-view');
|
|
11
11
|
|
|
@@ -143,18 +143,16 @@ const Button = /*#__PURE__*/ React__namespace.forwardRef(({ className, variant,
|
|
|
143
143
|
});
|
|
144
144
|
Button.displayName = "Button";
|
|
145
145
|
|
|
146
|
+
const getEntryRevalidateLeft = (cacheEntry)=>{
|
|
147
|
+
if (!cacheEntry.data?.headers.date || !cacheEntry.revalidate) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const cacheEntryDate = new Date(cacheEntry.data?.headers.date);
|
|
151
|
+
const msDiff = new Date().getTime() - cacheEntryDate.getTime();
|
|
152
|
+
return Math.floor(cacheEntry.revalidate - msDiff / 1000);
|
|
153
|
+
};
|
|
146
154
|
const CacheEntry = (props)=>{
|
|
147
|
-
const cacheEntryRevalidateLeft =
|
|
148
|
-
if (!props.cacheEntry.data?.headers.date || !props.cacheEntry.revalidate) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const cacheEntryDate = new Date(props.cacheEntry.data?.headers.date);
|
|
152
|
-
const msDiff = new Date().getTime() - cacheEntryDate.getTime();
|
|
153
|
-
return Math.floor(props.cacheEntry.revalidate - msDiff / 1000);
|
|
154
|
-
}, [
|
|
155
|
-
props.cacheEntry.data?.headers.date,
|
|
156
|
-
props.cacheEntry.revalidate
|
|
157
|
-
]);
|
|
155
|
+
const cacheEntryRevalidateLeft = getEntryRevalidateLeft(props.cacheEntry);
|
|
158
156
|
const isStale = cacheEntryRevalidateLeft ? cacheEntryRevalidateLeft < 0 : false;
|
|
159
157
|
return /*#__PURE__*/ jsxRuntime.jsxs(TableRow, {
|
|
160
158
|
children: [
|
|
@@ -209,6 +207,7 @@ exports.Button = Button;
|
|
|
209
207
|
exports.CacheEntry = CacheEntry;
|
|
210
208
|
exports.Table = Table;
|
|
211
209
|
exports.TableBody = TableBody;
|
|
210
|
+
exports.TableCell = TableCell;
|
|
212
211
|
exports.TableHead = TableHead;
|
|
213
212
|
exports.TableHeader = TableHeader;
|
|
214
213
|
exports.TableRow = TableRow;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
8
|
+
|
|
9
|
+
const CachePanelContext = /*#__PURE__*/ React.createContext({
|
|
10
|
+
entries: [],
|
|
11
|
+
isOpen: false,
|
|
12
|
+
setEntries: ()=>{},
|
|
13
|
+
toggleOpen: ()=>{},
|
|
14
|
+
setSorting: ()=>{},
|
|
15
|
+
addFilter: ()=>{},
|
|
16
|
+
clearFilter: ()=>{}
|
|
17
|
+
});
|
|
18
|
+
const sortCacheEntryByKey = (key, a, b)=>{
|
|
19
|
+
switch(key){
|
|
20
|
+
case "url":
|
|
21
|
+
if (!a.data || !b.data) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
return a.data.url.localeCompare(b.data.url);
|
|
25
|
+
case "revalidate":
|
|
26
|
+
return (a.revalidate ?? 0) - (b.revalidate ?? 0);
|
|
27
|
+
case "tags":
|
|
28
|
+
if (a.tags.length === 0 || b.tags.length === 0) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
return a.tags[0]?.localeCompare(b.tags[0] ?? "") ?? 0;
|
|
32
|
+
case "timestamp":
|
|
33
|
+
{
|
|
34
|
+
if (!a.data?.headers.date || !b.data?.headers.date) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
return new Date(b.data.headers.date).getTime() - new Date(a.data.headers.date).getTime();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const useCachePanelContext = ()=>React__default.default.useContext(CachePanelContext);
|
|
42
|
+
const CachePanelContextProvider = (props)=>{
|
|
43
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
44
|
+
const [entries, setEntries] = React.useState(props.entries);
|
|
45
|
+
const [filters, setFilters] = React.useState();
|
|
46
|
+
const [sorting, setSorting] = React.useState(undefined);
|
|
47
|
+
const toggleOpen = ()=>{
|
|
48
|
+
setIsOpen(!isOpen);
|
|
49
|
+
};
|
|
50
|
+
const addFilter = (key, value)=>{
|
|
51
|
+
setFilters((prev)=>{
|
|
52
|
+
if (!prev) {
|
|
53
|
+
return {
|
|
54
|
+
[key]: value
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
...prev,
|
|
59
|
+
[key]: value
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const clearFilter = (key)=>{
|
|
64
|
+
setFilters((prev)=>{
|
|
65
|
+
if (!prev) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
delete prev[key];
|
|
69
|
+
return prev;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const derivedEntries = React.useMemo(()=>{
|
|
73
|
+
let copiedEntries = entries.slice();
|
|
74
|
+
if (filters) {
|
|
75
|
+
copiedEntries = copiedEntries.filter((entry)=>{
|
|
76
|
+
const { tags: tagsFilter, url: urlFilter } = filters;
|
|
77
|
+
if (tagsFilter && !entry[1].tags.some((tag)=>tag.match(tagsFilter))) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (urlFilter && !entry[1].data.url.match(urlFilter)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!sorting) {
|
|
87
|
+
return copiedEntries;
|
|
88
|
+
}
|
|
89
|
+
const { key, direction } = sorting;
|
|
90
|
+
return copiedEntries.toSorted((a, b)=>{
|
|
91
|
+
return sortCacheEntryByKey(key, a[1], b[1]) * (direction === "asc" ? 1 : -1);
|
|
92
|
+
});
|
|
93
|
+
}, [
|
|
94
|
+
entries,
|
|
95
|
+
sorting,
|
|
96
|
+
filters
|
|
97
|
+
]);
|
|
98
|
+
return /*#__PURE__*/ jsxRuntime.jsx(CachePanelContext.Provider, {
|
|
99
|
+
value: {
|
|
100
|
+
isOpen,
|
|
101
|
+
toggleOpen,
|
|
102
|
+
setSorting,
|
|
103
|
+
sorting,
|
|
104
|
+
entries: derivedEntries,
|
|
105
|
+
setEntries,
|
|
106
|
+
filters,
|
|
107
|
+
addFilter,
|
|
108
|
+
clearFilter
|
|
109
|
+
},
|
|
110
|
+
children: props.children
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
exports.CachePanelContextProvider = CachePanelContextProvider;
|
|
115
|
+
exports.useCachePanelContext = useCachePanelContext;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
+
var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
|
|
7
|
+
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
|
+
|
|
28
|
+
const Input = /*#__PURE__*/ React__namespace.forwardRef(({ className, type, ...props }, ref)=>{
|
|
29
|
+
return /*#__PURE__*/ jsxRuntime.jsx("input", {
|
|
30
|
+
type: type,
|
|
31
|
+
className: cacheEntryClient.cn("nct-flex nct-h-10 nct-w-full nct-rounded-md nct-border nct-border-input nct-bg-background nct-px-3 nct-py-2 nct-text-sm nct-ring-offset-background file:nct-border-0 file:nct-bg-transparent file:nct-text-sm file:nct-font-medium placeholder:nct-text-muted-foreground focus-visible:nct-outline-none focus-visible:nct-ring-2 focus-visible:nct-ring-ring focus-visible:nct-ring-offset-2 disabled:nct-cursor-not-allowed disabled:nct-opacity-50", className),
|
|
32
|
+
ref: ref,
|
|
33
|
+
...props
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
Input.displayName = "Input";
|
|
37
|
+
|
|
38
|
+
const CachePanelHead = ({ sortingProperty, children, className, withFilter = false, ...props })=>{
|
|
39
|
+
const { setSorting, sorting, filters, addFilter, clearFilter } = cachePanelContextClient.useCachePanelContext();
|
|
40
|
+
const [filterInputVisible, setFilterInputVisible] = React.useState(false);
|
|
41
|
+
const inputRef = React.useCallback((node)=>{
|
|
42
|
+
if (!node) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
node.focus();
|
|
46
|
+
}, []);
|
|
47
|
+
const sortingDirection = React.useMemo(()=>{
|
|
48
|
+
if (!sorting || sorting.key !== sortingProperty) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return sorting.direction;
|
|
52
|
+
}, [
|
|
53
|
+
sorting,
|
|
54
|
+
sortingProperty
|
|
55
|
+
]);
|
|
56
|
+
const filterValue = React.useMemo(()=>{
|
|
57
|
+
if (sortingProperty !== "url" && sortingProperty !== "tags") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return filters?.[sortingProperty] ?? "";
|
|
61
|
+
}, [
|
|
62
|
+
sortingProperty,
|
|
63
|
+
filters
|
|
64
|
+
]);
|
|
65
|
+
const onHeadClick = ()=>{
|
|
66
|
+
if (sorting && sorting.key === sortingProperty) {
|
|
67
|
+
setSorting({
|
|
68
|
+
key: sortingProperty,
|
|
69
|
+
direction: sorting.direction === "asc" ? "desc" : "asc"
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
setSorting({
|
|
73
|
+
key: sortingProperty,
|
|
74
|
+
direction: "asc"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const onFilterInputKeyDown = (event)=>{
|
|
79
|
+
if (sortingProperty !== "url" && sortingProperty !== "tags") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// clear value on esc
|
|
83
|
+
if (event.key === "Escape") {
|
|
84
|
+
clearFilter(sortingProperty);
|
|
85
|
+
setFilterInputVisible(false);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const onFilterInputChange = (event)=>{
|
|
89
|
+
if (sortingProperty !== "url" && sortingProperty !== "tags") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
addFilter(sortingProperty, event.target.value);
|
|
93
|
+
};
|
|
94
|
+
const onFilterInputBlur = (event)=>{
|
|
95
|
+
if (sortingProperty !== "url" && sortingProperty !== "tags") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (event.target.value === "") {
|
|
99
|
+
setFilterInputVisible(false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.TableHead, {
|
|
103
|
+
className: cacheEntryClient.cn("group", className),
|
|
104
|
+
...props,
|
|
105
|
+
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"),
|
|
107
|
+
children: [
|
|
108
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
109
|
+
onClick: onHeadClick,
|
|
110
|
+
onKeyDown: onHeadClick,
|
|
111
|
+
children: children
|
|
112
|
+
}),
|
|
113
|
+
sortingDirection === "asc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowDownAZIcon, {}),
|
|
114
|
+
sortingDirection === "desc" && /*#__PURE__*/ jsxRuntime.jsx(lucideReact.ArrowUpAZIcon, {}),
|
|
115
|
+
withFilter && /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
116
|
+
className: "ml-auto",
|
|
117
|
+
children: [
|
|
118
|
+
!filterInputVisible && /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.Button, {
|
|
119
|
+
variant: "ghost",
|
|
120
|
+
size: "icon",
|
|
121
|
+
className: cacheEntryClient.cn(),
|
|
122
|
+
onClick: ()=>setFilterInputVisible(true),
|
|
123
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.FilterIcon, {})
|
|
124
|
+
}),
|
|
125
|
+
filterInputVisible && /*#__PURE__*/ jsxRuntime.jsx(Input, {
|
|
126
|
+
onKeyDown: onFilterInputKeyDown,
|
|
127
|
+
value: filterValue,
|
|
128
|
+
onChange: onFilterInputChange,
|
|
129
|
+
onBlur: onFilterInputBlur,
|
|
130
|
+
ref: inputRef
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
exports.CachePanelHead = CachePanelHead;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
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');
|
|
5
|
+
|
|
6
|
+
const CachePanelTable = ()=>{
|
|
7
|
+
const { entries } = cachePanelContextClient.useCachePanelContext();
|
|
8
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(cacheEntryClient.TableBody, {
|
|
9
|
+
children: [
|
|
10
|
+
entries.length === 0 && /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.TableRow, {
|
|
11
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.TableCell, {
|
|
12
|
+
children: "No cache entries"
|
|
13
|
+
})
|
|
14
|
+
}),
|
|
15
|
+
entries.map(([file, cacheEntry])=>/*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.CacheEntry, {
|
|
16
|
+
cacheEntry: cacheEntry
|
|
17
|
+
}, file))
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.CachePanelTable = CachePanelTable;
|
package/dist/cjs/{cache-panel-trigger-client-ChZncD_2.js → cache-panel-trigger-client-CGeo22Q8.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
-
var cacheEntryClient = require('./cache-entry-client-
|
|
3
|
+
var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
|
|
4
4
|
require('react');
|
|
5
|
-
var cachePanelContextClient = require('./cache-panel-context-client-
|
|
5
|
+
var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
|
|
6
6
|
|
|
7
7
|
function CachePanelTrigger(props) {
|
|
8
8
|
const { toggleOpen } = cachePanelContextClient.useCachePanelContext();
|
package/dist/cjs/{cache-panel-wrapper-client-DE5QrmN0.js → cache-panel-wrapper-client-2eJisZgJ.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
-
var cacheEntryClient = require('./cache-entry-client-
|
|
3
|
+
var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
|
|
4
4
|
require('react');
|
|
5
|
-
var cachePanelContextClient = require('./cache-panel-context-client-
|
|
5
|
+
var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
|
|
6
6
|
|
|
7
7
|
const CacheTable = (props)=>{
|
|
8
8
|
const { isOpen } = cachePanelContextClient.useCachePanelContext();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
|
+
var getCacheEntriesServer = require('./getCacheEntries-server-BheTh0n9.js');
|
|
4
|
+
var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var navigation = require('next/navigation');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var cachePanelContextClient = require('./cache-panel-context-client-FIUru-uB.js');
|
|
9
|
+
|
|
10
|
+
function RefreshDataButton({ enabled, interval }) {
|
|
11
|
+
const { setEntries } = cachePanelContextClient.useCachePanelContext();
|
|
12
|
+
const [isPending, startTransition] = React.useTransition();
|
|
13
|
+
const pathname = navigation.usePathname();
|
|
14
|
+
const refreshData = ()=>{
|
|
15
|
+
startTransition(async ()=>{
|
|
16
|
+
const files = await getCacheEntriesServer.getCacheFiles();
|
|
17
|
+
setEntries(files ?? []);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
React.useEffect(()=>{
|
|
21
|
+
console.log("pathname changed", pathname);
|
|
22
|
+
refreshData();
|
|
23
|
+
}, [
|
|
24
|
+
pathname
|
|
25
|
+
]);
|
|
26
|
+
React.useEffect(()=>{
|
|
27
|
+
if (!enabled) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const intervalId = setInterval(refreshData, interval);
|
|
31
|
+
return ()=>clearInterval(intervalId);
|
|
32
|
+
}, [
|
|
33
|
+
enabled,
|
|
34
|
+
interval
|
|
35
|
+
]);
|
|
36
|
+
return /*#__PURE__*/ jsxRuntime.jsx(cacheEntryClient.Button, {
|
|
37
|
+
variant: "outline",
|
|
38
|
+
size: "icon",
|
|
39
|
+
onClick: refreshData,
|
|
40
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.Loader2, {
|
|
41
|
+
className: cacheEntryClient.cn("nct-h-4 nct-w-4", {
|
|
42
|
+
"nct-animate-spin": isPending
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.RefreshDataButton = RefreshDataButton;
|
|
@@ -3,24 +3,24 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
3
3
|
var DialogPrimitive = require('@radix-ui/react-dialog');
|
|
4
4
|
var lucideReact = require('lucide-react');
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var cacheEntryClient = require('./cache-entry-client-
|
|
6
|
+
var cacheEntryClient = require('./cache-entry-client-C0CjMKC5.js');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
const stringToJSONSchema = zod.z.string().transform((str, ctx)=>{
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(str);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
ctx.addIssue({
|
|
10
|
+
code: "custom",
|
|
11
|
+
message: "Encoded body is not in JSON format",
|
|
12
|
+
path: [
|
|
13
|
+
"data",
|
|
14
|
+
"body"
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
return zod.z.NEVER;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const nextCacheFileSchema = zod.z.object({
|
|
21
|
+
data: zod.z.object({
|
|
22
|
+
body: zod.z.string(),
|
|
23
|
+
headers: zod.z.record(zod.z.string(), zod.z.string()),
|
|
24
|
+
status: zod.z.number(),
|
|
25
|
+
url: zod.z.string()
|
|
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
|
+
}).transform((cacheEntry)=>{
|
|
34
|
+
const body = stringToJSONSchema.parse(atob(cacheEntry.data.body));
|
|
35
|
+
return {
|
|
36
|
+
...cacheEntry,
|
|
37
|
+
data: {
|
|
38
|
+
...cacheEntry.data,
|
|
39
|
+
body
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const cachePath = ".next/cache/fetch-cache";
|
|
45
|
+
const getCacheFiles = async ()=>{
|
|
46
|
+
if (!fs.existsSync(cachePath)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const files = await fs.promises.readdir(cachePath);
|
|
50
|
+
const cacheFiles = new Map();
|
|
51
|
+
for (const file of files){
|
|
52
|
+
// ignore tags-manifest file
|
|
53
|
+
if (file.match(/manifest/)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const fileContent = await fs.promises.readFile(`${cachePath}/${file}`);
|
|
58
|
+
const cacheEntry = nextCacheFileSchema.parse(JSON.parse(fileContent.toString()));
|
|
59
|
+
cacheFiles.set(file, cacheEntry);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof zod.ZodError) {
|
|
62
|
+
const issues = error.issues;
|
|
63
|
+
console.error(`File ${file} do not match the schema`, issues);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
console.error(`Error parsing ${file}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Array.from(cacheFiles.entries());
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.getCacheFiles = getCacheFiles;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* If true, the cache table will automatically refresh when the pathname changes.
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
8
|
+
autoRefresh?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The interval in milliseconds to refresh the cache table.
|
|
11
|
+
* @default 10000
|
|
12
|
+
*/
|
|
13
|
+
interval?: number;
|
|
14
|
+
};
|
|
15
|
+
declare function NextCacheToolbar({ autoRefresh, interval, }: Props): Promise<react_jsx_runtime.JSX.Element>;
|
|
4
16
|
|
|
5
17
|
export { NextCacheToolbar };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,93 +1,23 @@
|
|
|
1
|
-
'use server';
|
|
2
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
2
|
|
|
4
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var cacheEntryClient = require('./cache-entry-client-Cg2-NRrZ.js');
|
|
6
4
|
var lucideReact = require('lucide-react');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var refreshDataButtonClient = require('./refresh-data-button-client-D4e_gWso.js');
|
|
5
|
+
var getCacheEntriesServer = require('./getCacheEntries-server-BheTh0n9.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-2eJisZgJ.js');
|
|
11
|
+
var cacheRefreshDataClient = require('./cache-refresh-data-client-VWar7JpG.js');
|
|
12
|
+
var cachePanelHeadClient = require('./cache-panel-head-client-Cs4uyFh7.js');
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return JSON.parse(str);
|
|
20
|
-
} catch (e) {
|
|
21
|
-
ctx.addIssue({
|
|
22
|
-
code: "custom",
|
|
23
|
-
message: "Encoded body is not in JSON format",
|
|
24
|
-
path: [
|
|
25
|
-
"data",
|
|
26
|
-
"body"
|
|
27
|
-
]
|
|
28
|
-
});
|
|
29
|
-
return zod.z.NEVER;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const nextCacheFileSchema = zod.z.object({
|
|
33
|
-
data: zod.z.object({
|
|
34
|
-
body: zod.z.string(),
|
|
35
|
-
headers: zod.z.record(zod.z.string(), zod.z.string()),
|
|
36
|
-
status: zod.z.number(),
|
|
37
|
-
url: zod.z.string()
|
|
38
|
-
}),
|
|
39
|
-
kind: zod.z.union([
|
|
40
|
-
zod.z.literal("FETCH"),
|
|
41
|
-
zod.z.unknown()
|
|
42
|
-
]),
|
|
43
|
-
revalidate: zod.z.number().optional(),
|
|
44
|
-
tags: zod.z.array(zod.z.string()).optional().default([])
|
|
45
|
-
}).transform((cacheEntry)=>{
|
|
46
|
-
const body = stringToJSONSchema.parse(atob(cacheEntry.data.body));
|
|
47
|
-
return {
|
|
48
|
-
...cacheEntry,
|
|
49
|
-
data: {
|
|
50
|
-
...cacheEntry.data,
|
|
51
|
-
body
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const cachePath = ".next/cache/fetch-cache";
|
|
57
|
-
const getCacheFiles = async ()=>{
|
|
58
|
-
if (!fs.existsSync(cachePath)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const files = await promises.readdir(cachePath);
|
|
62
|
-
const cacheFiles = new Map();
|
|
63
|
-
for (const file of files){
|
|
64
|
-
// ignore tags-manifest file
|
|
65
|
-
if (file.match(/manifest/)) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const fileContent = await promises.readFile(`${cachePath}/${file}`);
|
|
70
|
-
const cacheEntry = nextCacheFileSchema.parse(JSON.parse(fileContent.toString()));
|
|
71
|
-
cacheFiles.set(file, cacheEntry);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (error instanceof zod.ZodError) {
|
|
74
|
-
const issues = error.issues;
|
|
75
|
-
console.error(`File ${file} do not match the schema`, issues);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
console.error(`Error parsing ${file}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return cacheFiles;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
async function NextCacheToolbar() {
|
|
85
|
-
const files = await getCacheFiles();
|
|
86
|
-
const cacheEntries = Array.from(files?.entries() ?? []);
|
|
14
|
+
async function NextCacheToolbar({ autoRefresh = false, interval = 10000 }) {
|
|
15
|
+
const files = await getCacheEntriesServer.getCacheFiles();
|
|
87
16
|
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
88
17
|
id: "next-cache-toolbar",
|
|
89
18
|
className: "nct-text-primary nct-font-mono",
|
|
90
19
|
children: /*#__PURE__*/ jsxRuntime.jsxs(cachePanelContextClient.CachePanelContextProvider, {
|
|
20
|
+
entries: files ?? [],
|
|
91
21
|
children: [
|
|
92
22
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelTriggerClient.CachePanelTrigger, {
|
|
93
23
|
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",
|
|
@@ -102,14 +32,16 @@ async function NextCacheToolbar() {
|
|
|
102
32
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelHeadClient.CachePanelHead, {
|
|
103
33
|
sortingProperty: "url",
|
|
104
34
|
className: "nct-w-[300px]",
|
|
35
|
+
withFilter: true,
|
|
105
36
|
children: "URL"
|
|
106
37
|
}),
|
|
107
38
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelHeadClient.CachePanelHead, {
|
|
108
39
|
sortingProperty: "revalidate",
|
|
109
|
-
children: "Revalidate"
|
|
40
|
+
children: "Revalidate (ms)"
|
|
110
41
|
}),
|
|
111
42
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelHeadClient.CachePanelHead, {
|
|
112
43
|
sortingProperty: "tags",
|
|
44
|
+
withFilter: true,
|
|
113
45
|
children: "Tags"
|
|
114
46
|
}),
|
|
115
47
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelHeadClient.CachePanelHead, {
|
|
@@ -121,7 +53,10 @@ async function NextCacheToolbar() {
|
|
|
121
53
|
children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
122
54
|
className: "nct-flex nct-items-center nct-justify-end nct-gap-2",
|
|
123
55
|
children: [
|
|
124
|
-
/*#__PURE__*/ jsxRuntime.jsx(
|
|
56
|
+
/*#__PURE__*/ jsxRuntime.jsx(cacheRefreshDataClient.RefreshDataButton, {
|
|
57
|
+
enabled: autoRefresh,
|
|
58
|
+
interval: interval
|
|
59
|
+
}),
|
|
125
60
|
/*#__PURE__*/ jsxRuntime.jsx(cachePanelTriggerClient.CachePanelTrigger, {
|
|
126
61
|
children: /*#__PURE__*/ jsxRuntime.jsx(lucideReact.PanelBottomCloseIcon, {})
|
|
127
62
|
})
|
|
@@ -131,9 +66,7 @@ async function NextCacheToolbar() {
|
|
|
131
66
|
]
|
|
132
67
|
})
|
|
133
68
|
}),
|
|
134
|
-
/*#__PURE__*/ jsxRuntime.jsx(cachePanelTableClient.CachePanelTable, {
|
|
135
|
-
entries: cacheEntries
|
|
136
|
-
})
|
|
69
|
+
/*#__PURE__*/ jsxRuntime.jsx(cachePanelTableClient.CachePanelTable, {})
|
|
137
70
|
]
|
|
138
71
|
})
|
|
139
72
|
]
|