@spoosh/plugin-nextjs 0.1.0-beta.0 → 0.1.2
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/README.md +27 -18
- package/dist/index.d.mts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -26,13 +26,15 @@ export async function revalidateAction(tags: string[], paths: string[]) {
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
+
import { Spoosh } from "@spoosh/core";
|
|
29
30
|
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
30
31
|
import { invalidationPlugin } from "@spoosh/plugin-invalidation";
|
|
31
32
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const client = new Spoosh<ApiSchema, Error>("/api")
|
|
34
|
+
.use([
|
|
35
|
+
invalidationPlugin(),
|
|
36
|
+
nextjsPlugin({ serverRevalidator: revalidateAction }),
|
|
37
|
+
]);
|
|
36
38
|
|
|
37
39
|
// After a successful mutation, cache tags are automatically revalidated
|
|
38
40
|
const { trigger } = useWrite((api) => api.posts.$post);
|
|
@@ -69,12 +71,16 @@ await trigger({
|
|
|
69
71
|
For apps that primarily fetch data on the client side, set `skipServerRevalidation: true` by default and opt-in for specific mutations that affect server-rendered content:
|
|
70
72
|
|
|
71
73
|
```typescript
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
import { Spoosh } from "@spoosh/core";
|
|
75
|
+
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
76
|
+
|
|
77
|
+
const client = new Spoosh<ApiSchema, Error>("/api")
|
|
78
|
+
.use([
|
|
79
|
+
nextjsPlugin({
|
|
80
|
+
serverRevalidator: revalidate,
|
|
81
|
+
skipServerRevalidation: true,
|
|
82
|
+
}),
|
|
83
|
+
]);
|
|
78
84
|
|
|
79
85
|
// Most mutations don't need server revalidation
|
|
80
86
|
await trigger({ body: data });
|
|
@@ -82,7 +88,7 @@ await trigger({ body: data });
|
|
|
82
88
|
// Opt-in when mutation affects server-rendered pages
|
|
83
89
|
await trigger({
|
|
84
90
|
body: data,
|
|
85
|
-
serverRevalidate: true,
|
|
91
|
+
serverRevalidate: true,
|
|
86
92
|
});
|
|
87
93
|
```
|
|
88
94
|
|
|
@@ -91,12 +97,15 @@ await trigger({
|
|
|
91
97
|
For apps that rely heavily on server-side rendering or React Server Components, keep the default behavior (revalidate on every mutation) and opt-out when needed:
|
|
92
98
|
|
|
93
99
|
```typescript
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
import { Spoosh } from "@spoosh/core";
|
|
101
|
+
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
102
|
+
|
|
103
|
+
const client = new Spoosh<ApiSchema, Error>("/api")
|
|
104
|
+
.use([
|
|
105
|
+
nextjsPlugin({
|
|
106
|
+
serverRevalidator: revalidate,
|
|
107
|
+
}),
|
|
108
|
+
]);
|
|
100
109
|
|
|
101
110
|
// Server cache is revalidated by default
|
|
102
111
|
await trigger({ body: data });
|
|
@@ -104,7 +113,7 @@ await trigger({ body: data });
|
|
|
104
113
|
// Skip for mutations that don't affect server content
|
|
105
114
|
await trigger({
|
|
106
115
|
body: { theme: "dark" },
|
|
107
|
-
serverRevalidate: false,
|
|
116
|
+
serverRevalidate: false,
|
|
108
117
|
});
|
|
109
118
|
```
|
|
110
119
|
|
package/dist/index.d.mts
CHANGED
|
@@ -31,18 +31,20 @@ type NextjsWriteResult = object;
|
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
34
|
+
* import { Spoosh } from "@spoosh/core";
|
|
34
35
|
* import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
35
36
|
*
|
|
36
|
-
* const
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
37
|
+
* const client = new Spoosh<ApiSchema, Error>("/api")
|
|
38
|
+
* .use([
|
|
39
|
+
* nextjsPlugin({
|
|
40
|
+
* serverRevalidator: async (tags, paths) => {
|
|
41
|
+
* "use server";
|
|
42
|
+
* const { revalidateTag, revalidatePath } = await import("next/cache");
|
|
43
|
+
* tags.forEach((tag) => revalidateTag(tag));
|
|
44
|
+
* paths.forEach((path) => revalidatePath(path));
|
|
45
|
+
* },
|
|
46
|
+
* }),
|
|
47
|
+
* ]);
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
50
|
declare function nextjsPlugin(config?: NextjsPluginConfig): SpooshPlugin<{
|
package/dist/index.d.ts
CHANGED
|
@@ -31,18 +31,20 @@ type NextjsWriteResult = object;
|
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
34
|
+
* import { Spoosh } from "@spoosh/core";
|
|
34
35
|
* import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
35
36
|
*
|
|
36
|
-
* const
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
37
|
+
* const client = new Spoosh<ApiSchema, Error>("/api")
|
|
38
|
+
* .use([
|
|
39
|
+
* nextjsPlugin({
|
|
40
|
+
* serverRevalidator: async (tags, paths) => {
|
|
41
|
+
* "use server";
|
|
42
|
+
* const { revalidateTag, revalidatePath } = await import("next/cache");
|
|
43
|
+
* tags.forEach((tag) => revalidateTag(tag));
|
|
44
|
+
* paths.forEach((path) => revalidatePath(path));
|
|
45
|
+
* },
|
|
46
|
+
* }),
|
|
47
|
+
* ]);
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
50
|
declare function nextjsPlugin(config?: NextjsPluginConfig): SpooshPlugin<{
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/plugin.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./plugin\";\n","import type { SpooshPlugin } from \"@spoosh/core\";\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\n/**\n * Next.js integration plugin for server-side revalidation.\n *\n * Automatically revalidates Next.js cache tags and paths after successful mutations.\n *\n * @param config - Plugin configuration\n *\n * @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}\n *\n * @returns Next.js plugin instance\n *\n * @example\n * ```ts\n * import { nextjsPlugin } from \"@spoosh/plugin-nextjs\";\n *\n * const
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugin.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./plugin\";\n","import type { SpooshPlugin } from \"@spoosh/core\";\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\n/**\n * Next.js integration plugin for server-side revalidation.\n *\n * Automatically revalidates Next.js cache tags and paths after successful mutations.\n *\n * @param config - Plugin configuration\n *\n * @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}\n *\n * @returns Next.js plugin instance\n *\n * @example\n * ```ts\n * import { Spoosh } from \"@spoosh/core\";\n * import { nextjsPlugin } from \"@spoosh/plugin-nextjs\";\n *\n * const client = new Spoosh<ApiSchema, Error>(\"/api\")\n * .use([\n * nextjsPlugin({\n * serverRevalidator: async (tags, paths) => {\n * \"use server\";\n * const { revalidateTag, revalidatePath } = await import(\"next/cache\");\n * tags.forEach((tag) => revalidateTag(tag));\n * paths.forEach((path) => revalidatePath(path));\n * },\n * }),\n * ]);\n * ```\n */\nexport function nextjsPlugin(config: NextjsPluginConfig = {}): SpooshPlugin<{\n readOptions: NextjsReadOptions;\n writeOptions: NextjsWriteOptions;\n infiniteReadOptions: NextjsInfiniteReadOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: \"spoosh:nextjs\",\n operations: [\"write\"],\n\n middleware: async (context, next) => {\n const response = await next();\n\n if (response.error || !serverRevalidator) {\n return response;\n }\n\n const pluginOptions = context.pluginOptions as\n | NextjsWriteOptions\n | undefined;\n\n const shouldRevalidate =\n pluginOptions?.serverRevalidate ?? !skipServerRevalidation;\n\n if (!shouldRevalidate) {\n return response;\n }\n\n const revalidatePaths = pluginOptions?.revalidatePaths ?? [];\n\n if (context.tags.length > 0 || revalidatePaths.length > 0) {\n await serverRevalidator(context.tags, revalidatePaths);\n }\n\n return response;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuCO,SAAS,aAAa,SAA6B,CAAC,GAMxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,OAAO;AAAA,IAEpB,YAAY,OAAO,SAAS,SAAS;AACnC,YAAM,WAAW,MAAM,KAAK;AAE5B,UAAI,SAAS,SAAS,CAAC,mBAAmB;AACxC,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,QAAQ;AAI9B,YAAM,mBACJ,eAAe,oBAAoB,CAAC;AAEtC,UAAI,CAAC,kBAAkB;AACrB,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,mBAAmB,CAAC;AAE3D,UAAI,QAAQ,KAAK,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,cAAM,kBAAkB,QAAQ,MAAM,eAAe;AAAA,MACvD;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { SpooshPlugin } from \"@spoosh/core\";\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\n/**\n * Next.js integration plugin for server-side revalidation.\n *\n * Automatically revalidates Next.js cache tags and paths after successful mutations.\n *\n * @param config - Plugin configuration\n *\n * @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}\n *\n * @returns Next.js plugin instance\n *\n * @example\n * ```ts\n * import { nextjsPlugin } from \"@spoosh/plugin-nextjs\";\n *\n * const
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { SpooshPlugin } from \"@spoosh/core\";\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\n/**\n * Next.js integration plugin for server-side revalidation.\n *\n * Automatically revalidates Next.js cache tags and paths after successful mutations.\n *\n * @param config - Plugin configuration\n *\n * @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}\n *\n * @returns Next.js plugin instance\n *\n * @example\n * ```ts\n * import { Spoosh } from \"@spoosh/core\";\n * import { nextjsPlugin } from \"@spoosh/plugin-nextjs\";\n *\n * const client = new Spoosh<ApiSchema, Error>(\"/api\")\n * .use([\n * nextjsPlugin({\n * serverRevalidator: async (tags, paths) => {\n * \"use server\";\n * const { revalidateTag, revalidatePath } = await import(\"next/cache\");\n * tags.forEach((tag) => revalidateTag(tag));\n * paths.forEach((path) => revalidatePath(path));\n * },\n * }),\n * ]);\n * ```\n */\nexport function nextjsPlugin(config: NextjsPluginConfig = {}): SpooshPlugin<{\n readOptions: NextjsReadOptions;\n writeOptions: NextjsWriteOptions;\n infiniteReadOptions: NextjsInfiniteReadOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: \"spoosh:nextjs\",\n operations: [\"write\"],\n\n middleware: async (context, next) => {\n const response = await next();\n\n if (response.error || !serverRevalidator) {\n return response;\n }\n\n const pluginOptions = context.pluginOptions as\n | NextjsWriteOptions\n | undefined;\n\n const shouldRevalidate =\n pluginOptions?.serverRevalidate ?? !skipServerRevalidation;\n\n if (!shouldRevalidate) {\n return response;\n }\n\n const revalidatePaths = pluginOptions?.revalidatePaths ?? [];\n\n if (context.tags.length > 0 || revalidatePaths.length > 0) {\n await serverRevalidator(context.tags, revalidatePaths);\n }\n\n return response;\n },\n };\n}\n"],"mappings":";AAuCO,SAAS,aAAa,SAA6B,CAAC,GAMxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,OAAO;AAAA,IAEpB,YAAY,OAAO,SAAS,SAAS;AACnC,YAAM,WAAW,MAAM,KAAK;AAE5B,UAAI,SAAS,SAAS,CAAC,mBAAmB;AACxC,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,QAAQ;AAI9B,YAAM,mBACJ,eAAe,oBAAoB,CAAC;AAEtC,UAAI,CAAC,kBAAkB;AACrB,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,mBAAmB,CAAC;AAE3D,UAAI,QAAQ,KAAK,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,cAAM,kBAAkB,QAAQ,MAAM,eAAe;AAAA,MACvD;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Next.js integration plugin for Spoosh - server revalidation after mutations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@spoosh/core": ">=0.
|
|
37
|
+
"@spoosh/core": ">=0.3.0",
|
|
38
38
|
"next": ">=13.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@spoosh/core": "0.
|
|
41
|
+
"@spoosh/core": "0.3.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|