@spoosh/plugin-nextjs 0.1.4 → 0.1.5
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.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Next.js integration plugin for Spoosh - server-side cache revalidation after mutations.
|
|
4
4
|
|
|
5
|
-
**[Documentation](https://spoosh.dev/docs/plugins/nextjs)** · **Requirements:** TypeScript >= 5.0, Next.js supporting server actions · **Peer Dependencies:** `@spoosh/core`, `@spoosh/plugin-invalidation`
|
|
5
|
+
**[Documentation](https://spoosh.dev/docs/react/plugins/nextjs)** · **Requirements:** TypeScript >= 5.0, Next.js supporting server actions · **Peer Dependencies:** `@spoosh/core`, `@spoosh/plugin-invalidation`
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -36,7 +36,7 @@ const client = new Spoosh<ApiSchema, Error>("/api").use([
|
|
|
36
36
|
]);
|
|
37
37
|
|
|
38
38
|
// After a successful mutation, cache tags are automatically revalidated
|
|
39
|
-
const { trigger } = useWrite((api) => api
|
|
39
|
+
const { trigger } = useWrite((api) => api("posts").POST);
|
|
40
40
|
|
|
41
41
|
await trigger({ body: { title: "New Post" } });
|
|
42
42
|
// Revalidates: ["posts"] tag on the server
|
|
@@ -45,7 +45,7 @@ await trigger({ body: { title: "New Post" } });
|
|
|
45
45
|
### Revalidate Additional Paths
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
const { trigger } = useWrite((api) => api
|
|
48
|
+
const { trigger } = useWrite((api) => api("posts").POST);
|
|
49
49
|
|
|
50
50
|
await trigger({
|
|
51
51
|
body: { title: "New Post" },
|
package/dist/index.d.mts
CHANGED
|
@@ -25,7 +25,7 @@ type NextjsWriteResult = object;
|
|
|
25
25
|
*
|
|
26
26
|
* @param config - Plugin configuration
|
|
27
27
|
*
|
|
28
|
-
* @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}
|
|
28
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/nextjs | Next.js Plugin Documentation}
|
|
29
29
|
*
|
|
30
30
|
* @returns Next.js plugin instance
|
|
31
31
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ type NextjsWriteResult = object;
|
|
|
25
25
|
*
|
|
26
26
|
* @param config - Plugin configuration
|
|
27
27
|
*
|
|
28
|
-
* @see {@link https://spoosh.dev/docs/plugins/nextjs | Next.js Plugin Documentation}
|
|
28
|
+
* @see {@link https://spoosh.dev/docs/react/plugins/nextjs | Next.js Plugin Documentation}
|
|
29
29
|
*
|
|
30
30
|
* @returns Next.js plugin instance
|
|
31
31
|
*
|
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 { 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
|
+
{"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 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 { 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":[]}
|
|
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 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,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spoosh/plugin-nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Next.js integration plugin for Spoosh - server revalidation after mutations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/spooshdev/spoosh.git",
|
|
9
9
|
"directory": "packages/plugin-nextjs"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/spooshdev/spoosh/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://spoosh.dev/react/
|
|
14
|
+
"homepage": "https://spoosh.dev/docs/react/plugins/nextjs",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"next": ">=13.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@spoosh/core": "0.
|
|
41
|
+
"@spoosh/core": "0.10.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsup --watch",
|