Skip to content

Commit 1f3170f

Browse files
committed
dont mutate execution context
1 parent b823782 commit 1f3170f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ async function parseData(req) {
4040
}
4141

4242
/**
43-
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} pctx
43+
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx
4444
* @param {import("@cloudflare/workers-types/experimental").Request} req
4545
* @param {Env} env
4646
* @returns {Promise<Context>}
4747
*/
48-
export async function makeContext(pctx, req, env) {
48+
export async function makeContext(eCtx, req, env) {
4949
/** @type {Context} */
5050
// @ts-ignore
51-
const ctx = pctx;
51+
const ctx = {
52+
executionContext: eCtx,
53+
};
5254
// @ts-ignore
5355
ctx.attributes = {};
5456
// @ts-ignore
@@ -75,11 +77,11 @@ export default {
7577
/**
7678
* @param {import("@cloudflare/workers-types/experimental").Request} request
7779
* @param {Env} env
78-
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} pctx
80+
* @param {import("@cloudflare/workers-types/experimental").ExecutionContext} eCtx
7981
* @returns {Promise<Response>}
8082
*/
81-
async fetch(request, env, pctx) {
82-
const ctx = await makeContext(pctx, request, env);
83+
async fetch(request, env, eCtx) {
84+
const ctx = await makeContext(eCtx, request, env);
8385

8486
try {
8587
const overrides = Object.fromEntries(ctx.url.searchParams.entries());

src/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ declare global {
242242
[key: string]: string | KVNamespace<string> | R2Bucket;
243243
}
244244

245-
export interface Context extends ExecutionContext {
245+
export interface Context {
246246
url: URL;
247247
env: Env;
248248
log: Console;
@@ -263,6 +263,7 @@ declare global {
263263
key?: string;
264264
[key: string]: any;
265265
}
266+
executionContext: ExecutionContext;
266267
}
267268

268269
export interface Product {

0 commit comments

Comments
 (0)