Skip to content

Commit

Permalink
fix(cloudflare): runtime types for Cloudflare caches (#8782)
Browse files Browse the repository at this point in the history
* fix cachestorage reference in cloudflare integration

* add cachestorage to serverdirectorymode

* add changeset

* remove global caches type

* update unlucky-avocados-brake.md
  • Loading branch information
helloimalastair authored Oct 10, 2023
1 parent 9cd6a66 commit 7578164
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-avocados-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

fixes `AdvancedRuntime` & `DirectoryRuntime` types to work woth Cloudflare caches
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,7 +20,7 @@ export interface AdvancedRuntime<T extends object = object> {
waitUntil: (promise: Promise<any>) => void;
env: Env & T;
cf: CFRequest['cf'];
caches: typeof caches;
caches: CacheStorage;
};
}

Expand Down Expand Up @@ -50,7 +54,7 @@ export function createExports(manifest: SSRManifest) {
},
env: env,
cf: request.cf,
caches: caches,
caches: caches as unknown as CacheStorage,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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';

if (!isNode) {
process.env = getProcessEnvProxy();
}

export interface DirectoryRuntime<T extends object = object> {
runtime: {
waitUntil: (promise: Promise<any>) => void;
env: EventContext<unknown, string, unknown>['env'] & T;
cf: CFRequest['cf'];
caches: typeof caches;
caches: CacheStorage;
};
}

Expand Down Expand Up @@ -48,7 +47,7 @@ export function createExports(manifest: SSRManifest) {
},
env: context.env,
cf: request.cf,
caches: caches,
caches: caches as unknown as CacheStorage,
},
};

Expand Down

0 comments on commit 7578164

Please sign in to comment.