next
Version:
The React Framework
76 lines (75 loc) • 2.77 kB
JavaScript
import { PageSignatureError } from '../error';
const responseSymbol = Symbol('response');
const passThroughSymbol = Symbol('passThrough');
const waitUntilSymbol = Symbol('waitUntil');
class FetchEvent {
constructor(_request, waitUntil){
this[passThroughSymbol] = false;
this[waitUntilSymbol] = waitUntil ? {
kind: 'external',
function: waitUntil
} : {
kind: 'internal',
promises: []
};
}
// TODO: is this dead code? NextFetchEvent never lets this get called
respondWith(response) {
if (!this[responseSymbol]) {
this[responseSymbol] = Promise.resolve(response);
}
}
// TODO: is this dead code? passThroughSymbol is unused
passThroughOnException() {
this[passThroughSymbol] = true;
}
waitUntil(promise) {
if (this[waitUntilSymbol].kind === 'external') {
// if we received an external waitUntil, we delegate to it
// TODO(after): this will make us not go through `getServerError(error, 'edge-server')` in `sandbox`
const waitUntil = this[waitUntilSymbol].function;
return waitUntil(promise);
} else {
// if we didn't receive an external waitUntil, we make it work on our own
// (and expect the caller to do something with the promises)
this[waitUntilSymbol].promises.push(promise);
}
}
}
export function getWaitUntilPromiseFromEvent(event) {
return event[waitUntilSymbol].kind === 'internal' ? Promise.all(event[waitUntilSymbol].promises).then(()=>{}) : undefined;
}
export class NextFetchEvent extends FetchEvent {
constructor(params){
var _params_context;
super(params.request, (_params_context = params.context) == null ? void 0 : _params_context.waitUntil);
this.sourcePage = params.page;
}
/**
* @deprecated The `request` is now the first parameter and the API is now async.
*
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
*/ get request() {
throw Object.defineProperty(new PageSignatureError({
page: this.sourcePage
}), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
/**
* @deprecated Using `respondWith` is no longer needed.
*
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
*/ respondWith() {
throw Object.defineProperty(new PageSignatureError({
page: this.sourcePage
}), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
}
//# sourceMappingURL=fetch-event.js.map