@spoosh/plugin-nextjs 0.4.0 → 0.6.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 CHANGED
@@ -49,7 +49,9 @@ const { trigger } = useWrite((api) => api("posts").POST());
49
49
 
50
50
  await trigger({
51
51
  body: { title: "New Post" },
52
- revalidatePaths: ["/", "/posts"],
52
+ nextjs: {
53
+ revalidatePaths: ["/", "/posts"],
54
+ },
53
55
  });
54
56
  ```
55
57
 
@@ -59,7 +61,9 @@ await trigger({
59
61
  // Skip for a specific mutation
60
62
  await trigger({
61
63
  body: { title: "Draft" },
62
- serverRevalidate: false,
64
+ nextjs: {
65
+ serverRevalidate: false,
66
+ },
63
67
  });
64
68
  ```
65
69
 
@@ -86,7 +90,9 @@ await trigger({ body: data });
86
90
  // Opt-in when mutation affects server-rendered pages
87
91
  await trigger({
88
92
  body: data,
89
- serverRevalidate: true,
93
+ nextjs: {
94
+ serverRevalidate: true,
95
+ },
90
96
  });
91
97
  ```
92
98
 
@@ -110,7 +116,9 @@ await trigger({ body: data });
110
116
  // Skip for mutations that don't affect server content
111
117
  await trigger({
112
118
  body: { theme: "dark" },
113
- serverRevalidate: false,
119
+ nextjs: {
120
+ serverRevalidate: false,
121
+ },
114
122
  });
115
123
  ```
116
124
 
@@ -125,6 +133,8 @@ await trigger({
125
133
 
126
134
  ### Per-Request Options
127
135
 
136
+ Pass options via the `nextjs` object:
137
+
128
138
  | Option | Type | Description |
129
139
  | ------------------ | ---------- | ----------------------------------------------- |
130
140
  | `revalidatePaths` | `string[]` | Additional paths to revalidate |
package/dist/index.d.mts CHANGED
@@ -7,20 +7,22 @@ interface NextjsPluginConfig {
7
7
  /** Skip server revalidation by default. Default: false */
8
8
  skipServerRevalidation?: boolean;
9
9
  }
10
- type NextjsReadOptions = object;
11
- type NextjsWriteOptions = object;
12
- interface NextjsWriteTriggerOptions {
10
+ interface NextjsTriggerConfig {
13
11
  /** Additional paths to revalidate after mutation */
14
12
  revalidatePaths?: string[];
15
13
  /** Whether to trigger server revalidation. Overrides plugin default. */
16
14
  serverRevalidate?: boolean;
17
15
  }
18
- type NextjsInfiniteReadOptions = object;
16
+ type NextjsReadOptions = object;
17
+ type NextjsWriteOptions = object;
18
+ interface NextjsWriteTriggerOptions {
19
+ /** Next.js revalidation configuration */
20
+ nextjs?: NextjsTriggerConfig;
21
+ }
22
+ type NextjsPagesOptions = object;
19
23
  interface NextjsQueueTriggerOptions {
20
- /** Additional paths to revalidate after queue item completes */
21
- revalidatePaths?: string[];
22
- /** Whether to trigger server revalidation. Overrides plugin default. */
23
- serverRevalidate?: boolean;
24
+ /** Next.js revalidation configuration */
25
+ nextjs?: NextjsTriggerConfig;
24
26
  }
25
27
  type NextjsReadResult = object;
26
28
  type NextjsWriteResult = object;
@@ -60,10 +62,10 @@ declare function nextjsPlugin(config?: NextjsPluginConfig): SpooshPlugin<{
60
62
  writeOptions: NextjsWriteOptions;
61
63
  writeTriggerOptions: NextjsWriteTriggerOptions;
62
64
  queueTriggerOptions: NextjsQueueTriggerOptions;
63
- infiniteReadOptions: NextjsInfiniteReadOptions;
65
+ pagesOptions: NextjsPagesOptions;
64
66
  readResult: NextjsReadResult;
65
67
  writeResult: NextjsWriteResult;
66
68
  queueResult: NextjsQueueResult;
67
69
  }>;
68
70
 
69
- export { type NextjsInfiniteReadOptions, type NextjsPluginConfig, type NextjsQueueResult, type NextjsQueueTriggerOptions, type NextjsReadOptions, type NextjsReadResult, type NextjsWriteOptions, type NextjsWriteResult, type NextjsWriteTriggerOptions, type ServerRevalidateHandler, nextjsPlugin };
71
+ export { type NextjsPagesOptions, type NextjsPluginConfig, type NextjsQueueResult, type NextjsQueueTriggerOptions, type NextjsReadOptions, type NextjsReadResult, type NextjsTriggerConfig, type NextjsWriteOptions, type NextjsWriteResult, type NextjsWriteTriggerOptions, type ServerRevalidateHandler, nextjsPlugin };
package/dist/index.d.ts CHANGED
@@ -7,20 +7,22 @@ interface NextjsPluginConfig {
7
7
  /** Skip server revalidation by default. Default: false */
8
8
  skipServerRevalidation?: boolean;
9
9
  }
10
- type NextjsReadOptions = object;
11
- type NextjsWriteOptions = object;
12
- interface NextjsWriteTriggerOptions {
10
+ interface NextjsTriggerConfig {
13
11
  /** Additional paths to revalidate after mutation */
14
12
  revalidatePaths?: string[];
15
13
  /** Whether to trigger server revalidation. Overrides plugin default. */
16
14
  serverRevalidate?: boolean;
17
15
  }
18
- type NextjsInfiniteReadOptions = object;
16
+ type NextjsReadOptions = object;
17
+ type NextjsWriteOptions = object;
18
+ interface NextjsWriteTriggerOptions {
19
+ /** Next.js revalidation configuration */
20
+ nextjs?: NextjsTriggerConfig;
21
+ }
22
+ type NextjsPagesOptions = object;
19
23
  interface NextjsQueueTriggerOptions {
20
- /** Additional paths to revalidate after queue item completes */
21
- revalidatePaths?: string[];
22
- /** Whether to trigger server revalidation. Overrides plugin default. */
23
- serverRevalidate?: boolean;
24
+ /** Next.js revalidation configuration */
25
+ nextjs?: NextjsTriggerConfig;
24
26
  }
25
27
  type NextjsReadResult = object;
26
28
  type NextjsWriteResult = object;
@@ -60,10 +62,10 @@ declare function nextjsPlugin(config?: NextjsPluginConfig): SpooshPlugin<{
60
62
  writeOptions: NextjsWriteOptions;
61
63
  writeTriggerOptions: NextjsWriteTriggerOptions;
62
64
  queueTriggerOptions: NextjsQueueTriggerOptions;
63
- infiniteReadOptions: NextjsInfiniteReadOptions;
65
+ pagesOptions: NextjsPagesOptions;
64
66
  readResult: NextjsReadResult;
65
67
  writeResult: NextjsWriteResult;
66
68
  queueResult: NextjsQueueResult;
67
69
  }>;
68
70
 
69
- export { type NextjsInfiniteReadOptions, type NextjsPluginConfig, type NextjsQueueResult, type NextjsQueueTriggerOptions, type NextjsReadOptions, type NextjsReadResult, type NextjsWriteOptions, type NextjsWriteResult, type NextjsWriteTriggerOptions, type ServerRevalidateHandler, nextjsPlugin };
71
+ export { type NextjsPagesOptions, type NextjsPluginConfig, type NextjsQueueResult, type NextjsQueueTriggerOptions, type NextjsReadOptions, type NextjsReadResult, type NextjsTriggerConfig, type NextjsWriteOptions, type NextjsWriteResult, type NextjsWriteTriggerOptions, type ServerRevalidateHandler, nextjsPlugin };
package/dist/index.js CHANGED
@@ -43,12 +43,12 @@ function nextjsPlugin(config = {}) {
43
43
  return response;
44
44
  }
45
45
  const pluginOptions = context.pluginOptions;
46
- const shouldRevalidate = pluginOptions?.serverRevalidate ?? !skipServerRevalidation;
46
+ const shouldRevalidate = pluginOptions?.nextjs?.serverRevalidate ?? !skipServerRevalidation;
47
47
  if (!shouldRevalidate) {
48
48
  t?.skip("Revalidation disabled", { color: "muted" });
49
49
  return response;
50
50
  }
51
- const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
51
+ const revalidatePaths = pluginOptions?.nextjs?.revalidatePaths ?? [];
52
52
  const params = context.request.params;
53
53
  const resolvedTags = context.tags.map(
54
54
  (tag) => (0, import_core.resolvePathString)(tag, params)
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 { resolvePathString } from \"@spoosh/core\";\n\nimport type {\n NextjsPluginConfig,\n NextjsReadOptions,\n NextjsWriteOptions,\n NextjsWriteTriggerOptions,\n NextjsQueueTriggerOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n NextjsQueueResult,\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 queueTriggerOptions: NextjsQueueTriggerOptions;\n infiniteReadOptions: NextjsInfiniteReadOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n queueResult: NextjsQueueResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: PLUGIN_NAME,\n operations: [\"write\", \"queue\"],\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;AAclC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GASxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,SAAS,OAAO;AAAA,IAE7B,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":[]}
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 NextjsQueueTriggerOptions,\n NextjsPagesOptions,\n NextjsReadResult,\n NextjsWriteResult,\n NextjsQueueResult,\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 queueTriggerOptions: NextjsQueueTriggerOptions;\n pagesOptions: NextjsPagesOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n queueResult: NextjsQueueResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: PLUGIN_NAME,\n operations: [\"write\", \"queue\"],\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?.nextjs?.serverRevalidate ?? !skipServerRevalidation;\n\n if (!shouldRevalidate) {\n t?.skip(\"Revalidation disabled\", { color: \"muted\" });\n return response;\n }\n\n const revalidatePaths = pluginOptions?.nextjs?.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;AAclC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GASxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,SAAS,OAAO;AAAA,IAE7B,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,QAAQ,oBAAoB,CAAC;AAE9C,UAAI,CAAC,kBAAkB;AACrB,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AACnD,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,QAAQ,mBAAmB,CAAC;AACnE,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
@@ -17,12 +17,12 @@ function nextjsPlugin(config = {}) {
17
17
  return response;
18
18
  }
19
19
  const pluginOptions = context.pluginOptions;
20
- const shouldRevalidate = pluginOptions?.serverRevalidate ?? !skipServerRevalidation;
20
+ const shouldRevalidate = pluginOptions?.nextjs?.serverRevalidate ?? !skipServerRevalidation;
21
21
  if (!shouldRevalidate) {
22
22
  t?.skip("Revalidation disabled", { color: "muted" });
23
23
  return response;
24
24
  }
25
- const revalidatePaths = pluginOptions?.revalidatePaths ?? [];
25
+ const revalidatePaths = pluginOptions?.nextjs?.revalidatePaths ?? [];
26
26
  const params = context.request.params;
27
27
  const resolvedTags = context.tags.map(
28
28
  (tag) => resolvePathString(tag, params)
@@ -1 +1 @@
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 NextjsQueueTriggerOptions,\n NextjsInfiniteReadOptions,\n NextjsReadResult,\n NextjsWriteResult,\n NextjsQueueResult,\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 queueTriggerOptions: NextjsQueueTriggerOptions;\n infiniteReadOptions: NextjsInfiniteReadOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n queueResult: NextjsQueueResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: PLUGIN_NAME,\n operations: [\"write\", \"queue\"],\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;AAclC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GASxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,SAAS,OAAO;AAAA,IAE7B,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":[]}
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 NextjsQueueTriggerOptions,\n NextjsPagesOptions,\n NextjsReadResult,\n NextjsWriteResult,\n NextjsQueueResult,\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 queueTriggerOptions: NextjsQueueTriggerOptions;\n pagesOptions: NextjsPagesOptions;\n readResult: NextjsReadResult;\n writeResult: NextjsWriteResult;\n queueResult: NextjsQueueResult;\n}> {\n const { serverRevalidator, skipServerRevalidation = false } = config;\n\n return {\n name: PLUGIN_NAME,\n operations: [\"write\", \"queue\"],\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?.nextjs?.serverRevalidate ?? !skipServerRevalidation;\n\n if (!shouldRevalidate) {\n t?.skip(\"Revalidation disabled\", { color: \"muted\" });\n return response;\n }\n\n const revalidatePaths = pluginOptions?.nextjs?.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;AAclC,IAAM,cAAc;AA+Bb,SAAS,aAAa,SAA6B,CAAC,GASxD;AACD,QAAM,EAAE,mBAAmB,yBAAyB,MAAM,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,CAAC,SAAS,OAAO;AAAA,IAE7B,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,QAAQ,oBAAoB,CAAC;AAE9C,UAAI,CAAC,kBAAkB;AACrB,WAAG,KAAK,yBAAyB,EAAE,OAAO,QAAQ,CAAC;AACnD,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,eAAe,QAAQ,mBAAmB,CAAC;AACnE,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.4.0",
3
+ "version": "0.6.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.14.0",
37
+ "@spoosh/core": ">=0.15.0",
38
38
  "next": ">=13.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@spoosh/core": "0.14.0"
41
+ "@spoosh/core": "0.15.0"
42
42
  },
43
43
  "scripts": {
44
44
  "dev": "tsup --watch",