@spoosh/plugin-nextjs 0.1.7 → 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/README.md +3 -3
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ import { Spoosh } from "@spoosh/core";
|
|
|
30
30
|
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
31
31
|
import { invalidationPlugin } from "@spoosh/plugin-invalidation";
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
|
|
34
34
|
invalidationPlugin(),
|
|
35
35
|
nextjsPlugin({ serverRevalidator: revalidateAction }),
|
|
36
36
|
]);
|
|
@@ -73,7 +73,7 @@ For apps that primarily fetch data on the client side, set `skipServerRevalidati
|
|
|
73
73
|
import { Spoosh } from "@spoosh/core";
|
|
74
74
|
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
|
|
77
77
|
nextjsPlugin({
|
|
78
78
|
serverRevalidator: revalidate,
|
|
79
79
|
skipServerRevalidation: true,
|
|
@@ -98,7 +98,7 @@ For apps that rely heavily on server-side rendering or React Server Components,
|
|
|
98
98
|
import { Spoosh } from "@spoosh/core";
|
|
99
99
|
import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
100
100
|
|
|
101
|
-
const
|
|
101
|
+
const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
|
|
102
102
|
nextjsPlugin({
|
|
103
103
|
serverRevalidator: revalidate,
|
|
104
104
|
}),
|
package/dist/index.d.mts
CHANGED
|
@@ -34,7 +34,7 @@ type NextjsWriteResult = object;
|
|
|
34
34
|
* import { Spoosh } from "@spoosh/core";
|
|
35
35
|
* import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
38
38
|
* .use([
|
|
39
39
|
* nextjsPlugin({
|
|
40
40
|
* serverRevalidator: async (tags, paths) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ type NextjsWriteResult = object;
|
|
|
34
34
|
* import { Spoosh } from "@spoosh/core";
|
|
35
35
|
* import { nextjsPlugin } from "@spoosh/plugin-nextjs";
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const spoosh = new Spoosh<ApiSchema, Error>("/api")
|
|
38
38
|
* .use([
|
|
39
39
|
* nextjsPlugin({
|
|
40
40
|
* serverRevalidator: async (tags, paths) => {
|
package/dist/index.js
CHANGED
|
@@ -25,24 +25,40 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// src/plugin.ts
|
|
28
|
+
var PLUGIN_NAME = "spoosh:nextjs";
|
|
28
29
|
function nextjsPlugin(config = {}) {
|
|
29
30
|
const { serverRevalidator, skipServerRevalidation = false } = config;
|
|
30
31
|
return {
|
|
31
|
-
name:
|
|
32
|
+
name: PLUGIN_NAME,
|
|
32
33
|
operations: ["write"],
|
|
33
34
|
middleware: async (context, next) => {
|
|
35
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
34
36
|
const response = await next();
|
|
35
|
-
if (response.error
|
|
37
|
+
if (response.error) {
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
if (!serverRevalidator) {
|
|
41
|
+
t?.skip("No revalidator", { color: "muted" });
|
|
36
42
|
return response;
|
|
37
43
|
}
|
|
38
44
|
const pluginOptions = context.pluginOptions;
|
|
39
45
|
const shouldRevalidate = pluginOptions?.serverRevalidate ?? !skipServerRevalidation;
|
|
40
46
|
if (!shouldRevalidate) {
|
|
47
|
+
t?.skip("Revalidation disabled", { color: "muted" });
|
|
41
48
|
return response;
|
|
42
49
|
}
|
|
43
50
|
const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
|
|
44
51
|
if (context.tags.length > 0 || revalidatePaths.length > 0) {
|
|
52
|
+
t?.log(`Revalidated`, {
|
|
53
|
+
color: "info",
|
|
54
|
+
info: [
|
|
55
|
+
{ label: "tags", value: context.tags },
|
|
56
|
+
{ label: "paths", value: revalidatePaths }
|
|
57
|
+
]
|
|
58
|
+
});
|
|
45
59
|
await serverRevalidator(context.tags, revalidatePaths);
|
|
60
|
+
} else {
|
|
61
|
+
t?.skip("Nothing to revalidate", { color: "muted" });
|
|
46
62
|
}
|
|
47
63
|
return response;
|
|
48
64
|
}
|
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/react/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
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugin.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./plugin\";\n","import type { SpooshPlugin } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\nconst PLUGIN_NAME = \"spoosh:nextjs\";\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/react/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 spoosh = 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: PLUGIN_NAME,\n operations: [\"write\"],\n\n middleware: async (context, next) => {\n const t = context.tracer?.(PLUGIN_NAME);\n const response = await next();\n\n if (response.error) {\n return response;\n }\n\n if (!serverRevalidator) {\n t?.skip(\"No revalidator\", { color: \"muted\" });\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 t?.skip(\"Revalidation disabled\", { color: \"muted\" });\n return response;\n }\n\n const revalidatePaths = pluginOptions?.revalidatePaths ?? [];\n\n if (context.tags.length > 0 || revalidatePaths.length > 0) {\n t?.log(`Revalidated`, {\n color: \"info\",\n info: [\n { label: \"tags\", value: context.tags },\n { label: \"paths\", value: revalidatePaths },\n ],\n });\n\n await serverRevalidator(context.tags, revalidatePaths);\n } else {\n t?.skip(\"Nothing to revalidate\", { color: \"muted\" });\n }\n\n return response;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,IAAM,cAAc;AA+Bb,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,IAAI,QAAQ,SAAS,WAAW;AACtC,YAAM,WAAW,MAAM,KAAK;AAE5B,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AAEA,UAAI,CAAC,mBAAmB;AACtB,WAAG,KAAK,kBAAkB,EAAE,OAAO,QAAQ,CAAC;AAC5C,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,QAAQ;AAI9B,YAAM,mBACJ,eAAe,oBAAoB,CAAC;AAEtC,UAAI,CAAC,kBAAkB;AACrB,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AACnD,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,mBAAmB,CAAC;AAE3D,UAAI,QAAQ,KAAK,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,WAAG,IAAI,eAAe;AAAA,UACpB,OAAO;AAAA,UACP,MAAM;AAAA,YACJ,EAAE,OAAO,QAAQ,OAAO,QAAQ,KAAK;AAAA,YACrC,EAAE,OAAO,SAAS,OAAO,gBAAgB;AAAA,UAC3C;AAAA,QACF,CAAC;AAED,cAAM,kBAAkB,QAAQ,MAAM,eAAe;AAAA,MACvD,OAAO;AACL,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AAAA,MACrD;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
+
var PLUGIN_NAME = "spoosh:nextjs";
|
|
2
3
|
function nextjsPlugin(config = {}) {
|
|
3
4
|
const { serverRevalidator, skipServerRevalidation = false } = config;
|
|
4
5
|
return {
|
|
5
|
-
name:
|
|
6
|
+
name: PLUGIN_NAME,
|
|
6
7
|
operations: ["write"],
|
|
7
8
|
middleware: async (context, next) => {
|
|
9
|
+
const t = context.tracer?.(PLUGIN_NAME);
|
|
8
10
|
const response = await next();
|
|
9
|
-
if (response.error
|
|
11
|
+
if (response.error) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
if (!serverRevalidator) {
|
|
15
|
+
t?.skip("No revalidator", { color: "muted" });
|
|
10
16
|
return response;
|
|
11
17
|
}
|
|
12
18
|
const pluginOptions = context.pluginOptions;
|
|
13
19
|
const shouldRevalidate = pluginOptions?.serverRevalidate ?? !skipServerRevalidation;
|
|
14
20
|
if (!shouldRevalidate) {
|
|
21
|
+
t?.skip("Revalidation disabled", { color: "muted" });
|
|
15
22
|
return response;
|
|
16
23
|
}
|
|
17
24
|
const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
|
|
18
25
|
if (context.tags.length > 0 || revalidatePaths.length > 0) {
|
|
26
|
+
t?.log(`Revalidated`, {
|
|
27
|
+
color: "info",
|
|
28
|
+
info: [
|
|
29
|
+
{ label: "tags", value: context.tags },
|
|
30
|
+
{ label: "paths", value: revalidatePaths }
|
|
31
|
+
]
|
|
32
|
+
});
|
|
19
33
|
await serverRevalidator(context.tags, revalidatePaths);
|
|
34
|
+
} else {
|
|
35
|
+
t?.skip("Nothing to revalidate", { color: "muted" });
|
|
20
36
|
}
|
|
21
37
|
return response;
|
|
22
38
|
}
|
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/react/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
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { SpooshPlugin } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n} from \"./types\";\n\nconst PLUGIN_NAME = \"spoosh:nextjs\";\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/react/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 spoosh = 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: PLUGIN_NAME,\n operations: [\"write\"],\n\n middleware: async (context, next) => {\n const t = context.tracer?.(PLUGIN_NAME);\n const response = await next();\n\n if (response.error) {\n return response;\n }\n\n if (!serverRevalidator) {\n t?.skip(\"No revalidator\", { color: \"muted\" });\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 t?.skip(\"Revalidation disabled\", { color: \"muted\" });\n return response;\n }\n\n const revalidatePaths = pluginOptions?.revalidatePaths ?? [];\n\n if (context.tags.length > 0 || revalidatePaths.length > 0) {\n t?.log(`Revalidated`, {\n color: \"info\",\n info: [\n { label: \"tags\", value: context.tags },\n { label: \"paths\", value: revalidatePaths },\n ],\n });\n\n await serverRevalidator(context.tags, revalidatePaths);\n } else {\n t?.skip(\"Nothing to revalidate\", { color: \"muted\" });\n }\n\n return response;\n },\n };\n}\n"],"mappings":";AAWA,IAAM,cAAc;AA+Bb,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,IAAI,QAAQ,SAAS,WAAW;AACtC,YAAM,WAAW,MAAM,KAAK;AAE5B,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AAEA,UAAI,CAAC,mBAAmB;AACtB,WAAG,KAAK,kBAAkB,EAAE,OAAO,QAAQ,CAAC;AAC5C,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,QAAQ;AAI9B,YAAM,mBACJ,eAAe,oBAAoB,CAAC;AAEtC,UAAI,CAAC,kBAAkB;AACrB,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AACnD,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,mBAAmB,CAAC;AAE3D,UAAI,QAAQ,KAAK,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,WAAG,IAAI,eAAe;AAAA,UACpB,OAAO;AAAA,UACP,MAAM;AAAA,YACJ,EAAE,OAAO,QAAQ,OAAO,QAAQ,KAAK;AAAA,YACrC,EAAE,OAAO,SAAS,OAAO,gBAAgB;AAAA,UAC3C;AAAA,QACF,CAAC;AAED,cAAM,kBAAkB,QAAQ,MAAM,eAAe;AAAA,MACvD,OAAO;AACL,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AAAA,MACrD;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.
|
|
3
|
+
"version": "0.2.0",
|
|
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.13.0",
|
|
38
38
|
"next": ">=13.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@spoosh/core": "0.
|
|
41
|
+
"@spoosh/core": "0.13.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|