@spoosh/plugin-nextjs 0.3.0 → 0.3.1
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/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// src/plugin.ts
|
|
28
|
+
var import_core = require("@spoosh/core");
|
|
28
29
|
var PLUGIN_NAME = "spoosh:nextjs";
|
|
29
30
|
function nextjsPlugin(config = {}) {
|
|
30
31
|
const { serverRevalidator, skipServerRevalidation = false } = config;
|
|
@@ -48,15 +49,19 @@ function nextjsPlugin(config = {}) {
|
|
|
48
49
|
return response;
|
|
49
50
|
}
|
|
50
51
|
const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
|
|
51
|
-
|
|
52
|
+
const params = context.request.params;
|
|
53
|
+
const resolvedTags = context.tags.map(
|
|
54
|
+
(tag) => (0, import_core.resolvePathString)(tag, params)
|
|
55
|
+
);
|
|
56
|
+
if (resolvedTags.length > 0 || revalidatePaths.length > 0) {
|
|
52
57
|
t?.log(`Revalidated`, {
|
|
53
58
|
color: "info",
|
|
54
59
|
info: [
|
|
55
|
-
{ label: "tags", value:
|
|
60
|
+
{ label: "tags", value: resolvedTags },
|
|
56
61
|
{ label: "paths", value: revalidatePaths }
|
|
57
62
|
]
|
|
58
63
|
});
|
|
59
|
-
await serverRevalidator(
|
|
64
|
+
await serverRevalidator(resolvedTags, revalidatePaths);
|
|
60
65
|
} else {
|
|
61
66
|
t?.skip("Nothing to revalidate", { color: "muted" });
|
|
62
67
|
}
|
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\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsWriteTriggerOptions,\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 writeTriggerOptions: NextjsWriteTriggerOptions;\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 | NextjsWriteTriggerOptions\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
|
|
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 { resolvePathString } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsWriteTriggerOptions,\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 writeTriggerOptions: NextjsWriteTriggerOptions;\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 | NextjsWriteTriggerOptions\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 const params = context.request.params as\n | Record<string, string | number>\n | undefined;\n const resolvedTags = context.tags.map((tag) =>\n resolvePathString(tag, params)\n );\n\n if (resolvedTags.length > 0 || revalidatePaths.length > 0) {\n t?.log(`Revalidated`, {\n color: \"info\",\n info: [\n { label: \"tags\", value: resolvedTags },\n { label: \"paths\", value: revalidatePaths },\n ],\n });\n\n await serverRevalidator(resolvedTags, 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;;;ACCA,kBAAkC;AAYlC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GAOxD;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;AAC3D,YAAM,SAAS,QAAQ,QAAQ;AAG/B,YAAM,eAAe,QAAQ,KAAK;AAAA,QAAI,CAAC,YACrC,+BAAkB,KAAK,MAAM;AAAA,MAC/B;AAEA,UAAI,aAAa,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,WAAG,IAAI,eAAe;AAAA,UACpB,OAAO;AAAA,UACP,MAAM;AAAA,YACJ,EAAE,OAAO,QAAQ,OAAO,aAAa;AAAA,YACrC,EAAE,OAAO,SAAS,OAAO,gBAAgB;AAAA,UAC3C;AAAA,QACF,CAAC;AAED,cAAM,kBAAkB,cAAc,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,4 +1,5 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
+
import { resolvePathString } from "@spoosh/core";
|
|
2
3
|
var PLUGIN_NAME = "spoosh:nextjs";
|
|
3
4
|
function nextjsPlugin(config = {}) {
|
|
4
5
|
const { serverRevalidator, skipServerRevalidation = false } = config;
|
|
@@ -22,15 +23,19 @@ function nextjsPlugin(config = {}) {
|
|
|
22
23
|
return response;
|
|
23
24
|
}
|
|
24
25
|
const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
|
|
25
|
-
|
|
26
|
+
const params = context.request.params;
|
|
27
|
+
const resolvedTags = context.tags.map(
|
|
28
|
+
(tag) => resolvePathString(tag, params)
|
|
29
|
+
);
|
|
30
|
+
if (resolvedTags.length > 0 || revalidatePaths.length > 0) {
|
|
26
31
|
t?.log(`Revalidated`, {
|
|
27
32
|
color: "info",
|
|
28
33
|
info: [
|
|
29
|
-
{ label: "tags", value:
|
|
34
|
+
{ label: "tags", value: resolvedTags },
|
|
30
35
|
{ label: "paths", value: revalidatePaths }
|
|
31
36
|
]
|
|
32
37
|
});
|
|
33
|
-
await serverRevalidator(
|
|
38
|
+
await serverRevalidator(resolvedTags, revalidatePaths);
|
|
34
39
|
} else {
|
|
35
40
|
t?.skip("Nothing to revalidate", { color: "muted" });
|
|
36
41
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { SpooshPlugin } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsWriteTriggerOptions,\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 writeTriggerOptions: NextjsWriteTriggerOptions;\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 | NextjsWriteTriggerOptions\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
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { SpooshPlugin } from \"@spoosh/core\";\nimport { resolvePathString } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsWriteTriggerOptions,\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 writeTriggerOptions: NextjsWriteTriggerOptions;\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 | NextjsWriteTriggerOptions\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 const params = context.request.params as\n | Record<string, string | number>\n | undefined;\n const resolvedTags = context.tags.map((tag) =>\n resolvePathString(tag, params)\n );\n\n if (resolvedTags.length > 0 || revalidatePaths.length > 0) {\n t?.log(`Revalidated`, {\n color: \"info\",\n info: [\n { label: \"tags\", value: resolvedTags },\n { label: \"paths\", value: revalidatePaths },\n ],\n });\n\n await serverRevalidator(resolvedTags, revalidatePaths);\n } else {\n t?.skip(\"Nothing to revalidate\", { color: \"muted\" });\n }\n\n return response;\n },\n };\n}\n"],"mappings":";AACA,SAAS,yBAAyB;AAYlC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GAOxD;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;AAC3D,YAAM,SAAS,QAAQ,QAAQ;AAG/B,YAAM,eAAe,QAAQ,KAAK;AAAA,QAAI,CAAC,QACrC,kBAAkB,KAAK,MAAM;AAAA,MAC/B;AAEA,UAAI,aAAa,SAAS,KAAK,gBAAgB,SAAS,GAAG;AACzD,WAAG,IAAI,eAAe;AAAA,UACpB,OAAO;AAAA,UACP,MAAM;AAAA,YACJ,EAAE,OAAO,QAAQ,OAAO,aAAa;AAAA,YACrC,EAAE,OAAO,SAAS,OAAO,gBAAgB;AAAA,UAC3C;AAAA,QACF,CAAC;AAED,cAAM,kBAAkB,cAAc,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.
|
|
3
|
+
"version": "0.3.1",
|
|
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.13.
|
|
37
|
+
"@spoosh/core": ">=0.13.2",
|
|
38
38
|
"next": ">=13.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@spoosh/core": "0.13.
|
|
41
|
+
"@spoosh/core": "0.13.2"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|