wrangler 3.1.0 → 3.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.
@@ -122,7 +122,8 @@ function* executeRequest(request: Request, relativePathname: string) {
122
122
  export default function (pluginArgs: unknown) {
123
123
  const onRequest: PagesPluginFunction = async (workerContext) => {
124
124
  let { request } = workerContext;
125
- const { env, next, data } = workerContext;
125
+ const { env, next } = workerContext;
126
+ let { data } = workerContext;
126
127
 
127
128
  const url = new URL(request.url);
128
129
  // TODO: Replace this with something actually legible.
@@ -149,7 +150,16 @@ export default function (pluginArgs: unknown) {
149
150
  functionPath: workerContext.functionPath + path,
150
151
  next: pluginNext,
151
152
  params,
152
- data,
153
+ get data() {
154
+ return data;
155
+ },
156
+ set data(value) {
157
+ if (typeof value !== "object" || value === null) {
158
+ throw new Error("context.data must be an object");
159
+ }
160
+ // user has overriden context.data, so we need to merge it with the existing data
161
+ data = value;
162
+ },
153
163
  pluginArgs,
154
164
  env,
155
165
  waitUntil: workerContext.waitUntil.bind(workerContext),
@@ -120,7 +120,7 @@ export default {
120
120
  ) {
121
121
  let request = originalRequest;
122
122
  const handlerIterator = executeRequest(request);
123
- const data = {}; // arbitrary data the user can set between functions
123
+ let data = {}; // arbitrary data the user can set between functions
124
124
  let isFailOpen = false;
125
125
 
126
126
  const next = async (input?: RequestInfo, init?: RequestInit) => {
@@ -141,7 +141,16 @@ export default {
141
141
  functionPath: path,
142
142
  next,
143
143
  params,
144
- data,
144
+ get data() {
145
+ return data;
146
+ },
147
+ set data(value) {
148
+ if (typeof value !== "object" || value === null) {
149
+ throw new Error("context.data must be an object");
150
+ }
151
+ // user has overriden context.data, so we need to merge it with the existing data
152
+ data = value;
153
+ },
145
154
  env,
146
155
  waitUntil: workerContext.waitUntil.bind(workerContext),
147
156
  passThroughOnException: () => {
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../tsconfig.json",
2
+ "extends": "@cloudflare/workers-tsconfig/tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "types": ["@cloudflare/workers-types"]
5
5
  },