From 75781643a2f53656fc3fde3a7f28cb62db40b015 Mon Sep 17 00:00:00 2001 From: Mikkel Ricafrente <37487746+helloimalastair@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:08:17 +0200 Subject: [PATCH] fix(cloudflare): runtime types for Cloudflare caches (#8782) * fix cachestorage reference in cloudflare integration * add cachestorage to serverdirectorymode * add changeset * remove global caches type * update unlucky-avocados-brake.md --- .changeset/unlucky-avocados-brake.md | 5 +++++ .../cloudflare/src/entrypoints/server.advanced.ts | 10 +++++++--- .../cloudflare/src/entrypoints/server.directory.ts | 7 +++---- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .changeset/unlucky-avocados-brake.md diff --git a/.changeset/unlucky-avocados-brake.md b/.changeset/unlucky-avocados-brake.md new file mode 100644 index 000000000..b64fc24c7 --- /dev/null +++ b/.changeset/unlucky-avocados-brake.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +fixes `AdvancedRuntime` & `DirectoryRuntime` types to work woth Cloudflare caches diff --git a/packages/integrations/cloudflare/src/entrypoints/server.advanced.ts b/packages/integrations/cloudflare/src/entrypoints/server.advanced.ts index 957c1791d..471ca5270 100644 --- a/packages/integrations/cloudflare/src/entrypoints/server.advanced.ts +++ b/packages/integrations/cloudflare/src/entrypoints/server.advanced.ts @@ -1,4 +1,8 @@ -import type { Request as CFRequest, ExecutionContext } from '@cloudflare/workers-types'; +import type { + Request as CFRequest, + ExecutionContext, + CacheStorage, +} from '@cloudflare/workers-types'; import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; import { getProcessEnvProxy, isNode } from '../util.js'; @@ -16,7 +20,7 @@ export interface AdvancedRuntime { waitUntil: (promise: Promise) => void; env: Env & T; cf: CFRequest['cf']; - caches: typeof caches; + caches: CacheStorage; }; } @@ -50,7 +54,7 @@ export function createExports(manifest: SSRManifest) { }, env: env, cf: request.cf, - caches: caches, + caches: caches as unknown as CacheStorage, }, }; diff --git a/packages/integrations/cloudflare/src/entrypoints/server.directory.ts b/packages/integrations/cloudflare/src/entrypoints/server.directory.ts index 3542279b0..ada773bf6 100644 --- a/packages/integrations/cloudflare/src/entrypoints/server.directory.ts +++ b/packages/integrations/cloudflare/src/entrypoints/server.directory.ts @@ -1,4 +1,4 @@ -import type { Request as CFRequest, EventContext } from '@cloudflare/workers-types'; +import type { Request as CFRequest, EventContext, CacheStorage } from '@cloudflare/workers-types'; import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; import { getProcessEnvProxy, isNode } from '../util.js'; @@ -6,13 +6,12 @@ import { getProcessEnvProxy, isNode } from '../util.js'; if (!isNode) { process.env = getProcessEnvProxy(); } - export interface DirectoryRuntime { runtime: { waitUntil: (promise: Promise) => void; env: EventContext['env'] & T; cf: CFRequest['cf']; - caches: typeof caches; + caches: CacheStorage; }; } @@ -48,7 +47,7 @@ export function createExports(manifest: SSRManifest) { }, env: context.env, cf: request.cf, - caches: caches, + caches: caches as unknown as CacheStorage, }, };