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
This commit is contained in:
Mikkel Ricafrente 2023-10-10 18:08:17 +02:00 committed by GitHub
parent 9cd6a6657b
commit 75781643a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---
fixes `AdvancedRuntime` & `DirectoryRuntime` types to work woth Cloudflare caches

View file

@ -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 type { SSRManifest } from 'astro';
import { App } from 'astro/app'; import { App } from 'astro/app';
import { getProcessEnvProxy, isNode } from '../util.js'; import { getProcessEnvProxy, isNode } from '../util.js';
@ -16,7 +20,7 @@ export interface AdvancedRuntime<T extends object = object> {
waitUntil: (promise: Promise<any>) => void; waitUntil: (promise: Promise<any>) => void;
env: Env & T; env: Env & T;
cf: CFRequest['cf']; cf: CFRequest['cf'];
caches: typeof caches; caches: CacheStorage;
}; };
} }
@ -50,7 +54,7 @@ export function createExports(manifest: SSRManifest) {
}, },
env: env, env: env,
cf: request.cf, cf: request.cf,
caches: caches, caches: caches as unknown as CacheStorage,
}, },
}; };

View file

@ -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 type { SSRManifest } from 'astro';
import { App } from 'astro/app'; import { App } from 'astro/app';
import { getProcessEnvProxy, isNode } from '../util.js'; import { getProcessEnvProxy, isNode } from '../util.js';
@ -6,13 +6,12 @@ import { getProcessEnvProxy, isNode } from '../util.js';
if (!isNode) { if (!isNode) {
process.env = getProcessEnvProxy(); process.env = getProcessEnvProxy();
} }
export interface DirectoryRuntime<T extends object = object> { export interface DirectoryRuntime<T extends object = object> {
runtime: { runtime: {
waitUntil: (promise: Promise<any>) => void; waitUntil: (promise: Promise<any>) => void;
env: EventContext<unknown, string, unknown>['env'] & T; env: EventContext<unknown, string, unknown>['env'] & T;
cf: CFRequest['cf']; cf: CFRequest['cf'];
caches: typeof caches; caches: CacheStorage;
}; };
} }
@ -48,7 +47,7 @@ export function createExports(manifest: SSRManifest) {
}, },
env: context.env, env: context.env,
cf: request.cf, cf: request.cf,
caches: caches, caches: caches as unknown as CacheStorage,
}, },
}; };