@spoosh/plugin-nextjs 0.1.1 → 0.1.3

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
@@ -26,13 +26,14 @@ 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 plugins = [
33
+ const client = new Spoosh<ApiSchema, Error>("/api").use([
33
34
  invalidationPlugin(),
34
35
  nextjsPlugin({ serverRevalidator: revalidateAction }),
35
- ] as const;
36
+ ]);
36
37
 
37
38
  // After a successful mutation, cache tags are automatically revalidated
38
39
  const { trigger } = useWrite((api) => api.posts.$post);
@@ -69,12 +70,15 @@ await trigger({
69
70
  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
71
 
71
72
  ```typescript
72
- const plugins = [
73
+ import { Spoosh } from "@spoosh/core";
74
+ import { nextjsPlugin } from "@spoosh/plugin-nextjs";
75
+
76
+ const client = new Spoosh<ApiSchema, Error>("/api").use([
73
77
  nextjsPlugin({
74
78
  serverRevalidator: revalidate,
75
- skipServerRevalidation: true, // Skip by default
79
+ skipServerRevalidation: true,
76
80
  }),
77
- ] as const;
81
+ ]);
78
82
 
79
83
  // Most mutations don't need server revalidation
80
84
  await trigger({ body: data });
@@ -82,7 +86,7 @@ await trigger({ body: data });
82
86
  // Opt-in when mutation affects server-rendered pages
83
87
  await trigger({
84
88
  body: data,
85
- serverRevalidate: true, // Explicitly enable
89
+ serverRevalidate: true,
86
90
  });
87
91
  ```
88
92
 
@@ -91,12 +95,14 @@ await trigger({
91
95
  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
96
 
93
97
  ```typescript
94
- const plugins = [
98
+ import { Spoosh } from "@spoosh/core";
99
+ import { nextjsPlugin } from "@spoosh/plugin-nextjs";
100
+
101
+ const client = new Spoosh<ApiSchema, Error>("/api").use([
95
102
  nextjsPlugin({
96
103
  serverRevalidator: revalidate,
97
- // skipServerRevalidation: false (default)
98
104
  }),
99
- ] as const;
105
+ ]);
100
106
 
101
107
  // Server cache is revalidated by default
102
108
  await trigger({ body: data });
@@ -104,7 +110,7 @@ await trigger({ body: data });
104
110
  // Skip for mutations that don't affect server content
105
111
  await trigger({
106
112
  body: { theme: "dark" },
107
- serverRevalidate: false, // Skip for client-only state
113
+ serverRevalidate: false,
108
114
  });
109
115
  ```
110
116
 
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 plugins = [
37
- * nextjsPlugin({
38
- * serverRevalidator: async (tags, paths) => {
39
- * "use server";
40
- * const { revalidateTag, revalidatePath } = await import("next/cache");
41
- * tags.forEach((tag) => revalidateTag(tag));
42
- * paths.forEach((path) => revalidatePath(path));
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 plugins = [
37
- * nextjsPlugin({
38
- * serverRevalidator: async (tags, paths) => {
39
- * "use server";
40
- * const { revalidateTag, revalidatePath } = await import("next/cache");
41
- * tags.forEach((tag) => revalidateTag(tag));
42
- * paths.forEach((path) => revalidatePath(path));
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 plugins = [\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;;;ACqCO,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":[]}
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":[]}
@@ -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 plugins = [\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":";AAqCO,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":[]}
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.1",
3
+ "version": "0.1.3",
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.2.0",
37
+ "@spoosh/core": ">=0.4.0",
38
38
  "next": ">=13.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@spoosh/core": "0.2.0"
41
+ "@spoosh/core": "0.4.0"
42
42
  },
43
43
  "scripts": {
44
44
  "dev": "tsup --watch",