@vinext/cloudflare 0.1.0 → 0.1.2

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
@@ -7,16 +7,13 @@ ISR and the `"use cache"` data cache when deploying to Cloudflare Workers:
7
7
 
8
8
  - **`kvDataAdapter()`** (`@vinext/cloudflare/cache/kv-data-adapter`) — backs the
9
9
  data cache (`fetch`, `"use cache"`, `unstable_cache`) with a Workers KV
10
- namespace.
11
- - **`cdnAdapter()`** (`@vinext/cloudflare/cache/cdn-adapter`) — backs
12
- full-route, edge-managed page-level ISR with the Workers Cache API.
10
+ namespace. Also used for ISR in the absence of a cdn adapter.
13
11
 
14
12
  ## Usage
15
13
 
16
14
  Declare the adapters on the `vinext()` plugin in your Vite config:
17
15
 
18
16
  ```ts
19
- import { cdnAdapter } from "@vinext/cloudflare/cache/cdn-adapter";
20
17
  import { kvDataAdapter } from "@vinext/cloudflare/cache/kv-data-adapter";
21
18
 
22
19
  export default defineConfig({
@@ -24,7 +21,6 @@ export default defineConfig({
24
21
  vinext({
25
22
  cache: {
26
23
  data: kvDataAdapter(), // KV-backed data cache (binding: VINEXT_KV_CACHE)
27
- cdn: cdnAdapter(), // optional: edge-managed page-level ISR
28
24
  },
29
25
  }),
30
26
  cloudflare(),
@@ -1,8 +1,21 @@
1
1
  //#region src/cache/cdn-adapter.d.ts
2
2
  /**
3
- * Config-time builder: returns a serializable descriptor whose `adapter` is the
4
- * absolute path to the runtime factory. Safe to call from vite.config — it
5
- * never instantiates the adapter.
3
+ * Cloudflare CDN cache adapter - edge-managed page-level ISR backed by the
4
+ * Cloudflare Workers Cache.
5
+ *
6
+ * Unlike the data adapter (which stores cache entries in a durable store and
7
+ * serves HIT/STALE itself), this adapter delegates serving to Cloudflare's
8
+ * edge cache.
9
+ *
10
+ * Workers Cache must be enabled in your Wrangler config for this to work.
11
+ * ```jsonc
12
+ * // wrangler.jsonc
13
+ * {
14
+ * "cache": {
15
+ * "enabled": true,
16
+ * },
17
+ * }
18
+ * ```
6
19
  */
7
20
  declare function cdnAdapter(options?: Record<string, never>): {
8
21
  adapter: string;
@@ -1,9 +1,22 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  //#region src/cache/cdn-adapter.ts
3
3
  /**
4
- * Config-time builder: returns a serializable descriptor whose `adapter` is the
5
- * absolute path to the runtime factory. Safe to call from vite.config — it
6
- * never instantiates the adapter.
4
+ * Cloudflare CDN cache adapter - edge-managed page-level ISR backed by the
5
+ * Cloudflare Workers Cache.
6
+ *
7
+ * Unlike the data adapter (which stores cache entries in a durable store and
8
+ * serves HIT/STALE itself), this adapter delegates serving to Cloudflare's
9
+ * edge cache.
10
+ *
11
+ * Workers Cache must be enabled in your Wrangler config for this to work.
12
+ * ```jsonc
13
+ * // wrangler.jsonc
14
+ * {
15
+ * "cache": {
16
+ * "enabled": true,
17
+ * },
18
+ * }
19
+ * ```
7
20
  */
8
21
  function cdnAdapter(options) {
9
22
  return {
@@ -73,7 +73,12 @@ var CloudflareCdnCacheAdapter = class {
73
73
  async set(_key, _data, _ctx) {}
74
74
  buildResponseHeaders(input) {
75
75
  if (!input.cacheControl) return { "Cache-Control": NO_STORE };
76
- if (/\b(?:no-store|no-cache|private)\b/.test(input.cacheControl)) return { "Cache-Control": input.cacheControl };
76
+ if (/\b(?:no-store|no-cache|private)\b/.test(input.cacheControl)) return {
77
+ "Cache-Control": input.cacheControl,
78
+ "CDN-Cache-Control": null,
79
+ "Cloudflare-CDN-Cache-Control": null,
80
+ "Cache-Tag": null
81
+ };
77
82
  const headers = {
78
83
  "Cache-Control": BROWSER_REVALIDATE,
79
84
  "CDN-Cache-Control": toEdgeCacheControl(input.cacheControl)
@@ -7,9 +7,17 @@ type KvDataAdapterOptions = {
7
7
  tagCacheTtlMs?: number;
8
8
  };
9
9
  /**
10
- * Config-time builder: returns a serializable descriptor whose `adapter` is the
11
- * absolute path to the runtime factory. Safe to call from vite.config — it
12
- * never instantiates the KV handler or reads a binding.
10
+ * Cloudflare KV data cache.
11
+ *
12
+ * A KV namespace must be configured in your Wrangler config for this to work.
13
+ * ```jsonc
14
+ * // wrangler.jsonc
15
+ * {
16
+ * "kv_namespaces": [
17
+ * { "binding": "VINEXT_KV_CACHE", "id": "<your-kv-namespace-id>" }
18
+ * ]
19
+ * }
20
+ * ```
13
21
  */
14
22
  declare function kvDataAdapter(options?: KvDataAdapterOptions): {
15
23
  adapter: string;
@@ -1,9 +1,17 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  //#region src/cache/kv-data-adapter.ts
3
3
  /**
4
- * Config-time builder: returns a serializable descriptor whose `adapter` is the
5
- * absolute path to the runtime factory. Safe to call from vite.config — it
6
- * never instantiates the KV handler or reads a binding.
4
+ * Cloudflare KV data cache.
5
+ *
6
+ * A KV namespace must be configured in your Wrangler config for this to work.
7
+ * ```jsonc
8
+ * // wrangler.jsonc
9
+ * {
10
+ * "kv_namespaces": [
11
+ * { "binding": "VINEXT_KV_CACHE", "id": "<your-kv-namespace-id>" }
12
+ * ]
13
+ * }
14
+ * ```
7
15
  */
8
16
  function kvDataAdapter(options) {
9
17
  if (options?.binding !== void 0 && typeof options.binding !== "string") throw new TypeError("[vinext] kvDataAdapter({ binding }) must be a string KV binding name.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinext/cloudflare",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Cloudflare cache adapters for vinext (KV data cache + edge CDN cache).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "devDependencies": {
22
22
  "@types/node": "^25.9.2",
23
23
  "vite-plus": "0.1.24",
24
- "vinext": "0.1.0"
24
+ "vinext": "0.1.3"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "vinext": ">=0.0.0"