@edgeone/opennextjs-pages 0.0.1
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.
- package/dist/build/advanced-api-routes.js +147 -0
- package/dist/build/cache.js +36 -0
- package/dist/build/content/next-shims/telemetry-storage.cjs +55 -0
- package/dist/build/content/prerendered.js +292 -0
- package/dist/build/content/server.js +236 -0
- package/dist/build/content/static.js +119 -0
- package/dist/build/functions/server.js +133 -0
- package/dist/build/plugin-context.js +367 -0
- package/dist/build/routes.js +127 -0
- package/dist/build/templates/handler-monorepo.tmpl.js +210 -0
- package/dist/build/templates/handler.tmpl.js +206 -0
- package/dist/esm-chunks/chunk-5J3FID2N.js +5551 -0
- package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
- package/dist/esm-chunks/chunk-FKDTZJRV.js +832 -0
- package/dist/esm-chunks/chunk-TLQCAGE2.js +1921 -0
- package/dist/index.js +50 -0
- package/dist/run/config.js +37 -0
- package/dist/run/constants.js +19 -0
- package/dist/run/handlers/cache.cjs +369 -0
- package/dist/run/handlers/request-context.cjs +148 -0
- package/dist/run/handlers/server.js +3213 -0
- package/dist/run/handlers/tags-handler.cjs +92 -0
- package/dist/run/handlers/tracer.cjs +916 -0
- package/dist/run/handlers/use-cache-handler.js +1538 -0
- package/dist/run/handlers/wait-until.cjs +39 -0
- package/dist/run/headers.js +81 -0
- package/dist/run/next.cjs +100 -0
- package/dist/run/revalidate.js +34 -0
- package/dist/run/storage/regional-blob-store.cjs +64 -0
- package/dist/run/storage/request-scoped-in-memory-cache.cjs +1496 -0
- package/dist/run/storage/storage.cjs +37 -0
- package/dist/shared/blob-types.cjs +37 -0
- package/dist/shared/blobkey.js +25 -0
- package/dist/shared/cache-types.cjs +33 -0
- package/package.json +55 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/run/handlers/wait-until.cts
|
|
21
|
+
var wait_until_exports = {};
|
|
22
|
+
__export(wait_until_exports, {
|
|
23
|
+
setupWaitUntil: () => setupWaitUntil
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(wait_until_exports);
|
|
26
|
+
var import_request_context = require("./request-context.cjs");
|
|
27
|
+
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
28
|
+
function setupWaitUntil() {
|
|
29
|
+
;
|
|
30
|
+
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
31
|
+
get() {
|
|
32
|
+
return { waitUntil: (0, import_request_context.getRequestContext)()?.trackBackgroundWork };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
setupWaitUntil
|
|
39
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import "../esm-chunks/chunk-6BT4RYQJ.js";
|
|
8
|
+
|
|
9
|
+
// src/run/headers.ts
|
|
10
|
+
var getHeaderValueArray = (header) => {
|
|
11
|
+
return header.split(",").map((value) => value.trim()).filter(Boolean);
|
|
12
|
+
};
|
|
13
|
+
var omitHeaderValues = (header, values) => {
|
|
14
|
+
const headerValues = getHeaderValueArray(header);
|
|
15
|
+
const filteredValues = headerValues.filter(
|
|
16
|
+
(value) => !values.some((val) => value.startsWith(val))
|
|
17
|
+
);
|
|
18
|
+
return filteredValues.join(", ");
|
|
19
|
+
};
|
|
20
|
+
function setCacheControlFromRequestContext(headers, revalidate) {
|
|
21
|
+
const cdnCacheControl = (
|
|
22
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
23
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${revalidate || 31536e3}, stale-while-revalidate=31536000, durable`
|
|
24
|
+
);
|
|
25
|
+
headers.set("eo-cdn-cache-control", cdnCacheControl);
|
|
26
|
+
}
|
|
27
|
+
var setCacheControlHeaders = ({ headers, status }, request, requestContext) => {
|
|
28
|
+
if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control")) {
|
|
29
|
+
setCacheControlFromRequestContext(headers, requestContext.routeHandlerRevalidate);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (status === 404) {
|
|
33
|
+
if (request.url.endsWith(".php")) {
|
|
34
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
35
|
+
headers.set("eo-cdn-cache-control", `max-age=31536000, durable`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (process.env.CACHE_404_PAGE && request.url.endsWith("/404") && ["GET", "HEAD"].includes(request.method)) {
|
|
39
|
+
setCacheControlFromRequestContext(headers, requestContext.pageHandlerRevalidate);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const cacheControl = headers.get("cache-control");
|
|
44
|
+
if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control")) {
|
|
45
|
+
const browserCacheControl = omitHeaderValues(cacheControl, [
|
|
46
|
+
"s-maxage",
|
|
47
|
+
"stale-while-revalidate"
|
|
48
|
+
]);
|
|
49
|
+
const cdnCacheControl = (
|
|
50
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
51
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
|
|
52
|
+
...getHeaderValueArray(cacheControl).map(
|
|
53
|
+
(value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
|
|
54
|
+
),
|
|
55
|
+
"durable"
|
|
56
|
+
].join(", ")
|
|
57
|
+
);
|
|
58
|
+
headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
|
|
59
|
+
headers.set("eo-cdn-cache-control", cdnCacheControl);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (cacheControl === null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("eo-cdn-cache-control") && requestContext.usedFsReadForNonFallback && !requestContext.didPagesRouterOnDemandRevalidate) {
|
|
63
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
64
|
+
headers.set("eo-cdn-cache-control", `max-age=31536000, durable`);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var setCacheTagsHeaders = (headers, requestContext) => {
|
|
68
|
+
if (!headers.has("cache-control")) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var setCacheStatusHeader = (headers, nextCache) => {
|
|
73
|
+
if (headers.has("x-nextjs-cache")) {
|
|
74
|
+
headers.delete("x-nextjs-cache");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
setCacheControlHeaders,
|
|
79
|
+
setCacheStatusHeader,
|
|
80
|
+
setCacheTagsHeaders
|
|
81
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/run/next.cts
|
|
31
|
+
var next_exports = {};
|
|
32
|
+
__export(next_exports, {
|
|
33
|
+
getMockedRequestHandler: () => getMockedRequestHandler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(next_exports);
|
|
36
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
37
|
+
var import_promises = __toESM(require("node:fs/promises"));
|
|
38
|
+
var import_request_context = require("./handlers/request-context.cjs");
|
|
39
|
+
var import_tracer = require("./handlers/tracer.cjs");
|
|
40
|
+
process.env.NODE_ENV = "production";
|
|
41
|
+
var { getRequestHandlers } = require("next/dist/server/lib/start-server.js");
|
|
42
|
+
var ResponseCache = require("next/dist/server/response-cache/index.js").default;
|
|
43
|
+
var originalGet = ResponseCache.prototype.get;
|
|
44
|
+
ResponseCache.prototype.get = function get(...getArgs) {
|
|
45
|
+
if (!this.didAddBackgroundWorkTracking) {
|
|
46
|
+
if (typeof this.batcher !== "undefined") {
|
|
47
|
+
const originalBatcherBatch = this.batcher.batch;
|
|
48
|
+
this.batcher.batch = async (key, fn) => {
|
|
49
|
+
const trackedFn = async (...workFnArgs) => {
|
|
50
|
+
const workPromise = fn(...workFnArgs);
|
|
51
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
52
|
+
if (requestContext && workPromise instanceof Promise) {
|
|
53
|
+
requestContext.trackBackgroundWork(workPromise);
|
|
54
|
+
}
|
|
55
|
+
return await workPromise;
|
|
56
|
+
};
|
|
57
|
+
return originalBatcherBatch.call(this.batcher, key, trackedFn);
|
|
58
|
+
};
|
|
59
|
+
} else if (typeof this.pendingResponses !== "undefined") {
|
|
60
|
+
const backgroundWork = /* @__PURE__ */ new Map();
|
|
61
|
+
const originalPendingResponsesSet = this.pendingResponses.set;
|
|
62
|
+
this.pendingResponses.set = async (key, value) => {
|
|
63
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
64
|
+
if (requestContext && !this.pendingResponses.has(key)) {
|
|
65
|
+
const workPromise = new Promise((_resolve) => {
|
|
66
|
+
backgroundWork.set(key, _resolve);
|
|
67
|
+
});
|
|
68
|
+
requestContext.trackBackgroundWork(workPromise);
|
|
69
|
+
}
|
|
70
|
+
return originalPendingResponsesSet.call(this.pendingResponses, key, value);
|
|
71
|
+
};
|
|
72
|
+
const originalPendingResponsesDelete = this.pendingResponses.delete;
|
|
73
|
+
this.pendingResponses.delete = async (key) => {
|
|
74
|
+
const _resolve = backgroundWork.get(key);
|
|
75
|
+
if (_resolve) {
|
|
76
|
+
_resolve();
|
|
77
|
+
}
|
|
78
|
+
return originalPendingResponsesDelete.call(this.pendingResponses, key);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
this.didAddBackgroundWorkTracking = true;
|
|
82
|
+
}
|
|
83
|
+
return originalGet.apply(this, getArgs);
|
|
84
|
+
};
|
|
85
|
+
async function getMockedRequestHandler(...args) {
|
|
86
|
+
const initContext = { initializingServer: true };
|
|
87
|
+
const initAsyncLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
88
|
+
const tracer = (0, import_tracer.getTracer)();
|
|
89
|
+
return tracer.withActiveSpan("mocked request handler", async () => {
|
|
90
|
+
const ofs = { ...import_promises.default };
|
|
91
|
+
const requestHandlers = await initAsyncLocalStorage.run(initContext, async () => {
|
|
92
|
+
return await getRequestHandlers(...args);
|
|
93
|
+
});
|
|
94
|
+
return Array.isArray(requestHandlers) ? requestHandlers[0] : requestHandlers.requestHandler;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
getMockedRequestHandler
|
|
100
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import "../esm-chunks/chunk-6BT4RYQJ.js";
|
|
8
|
+
|
|
9
|
+
// src/run/revalidate.ts
|
|
10
|
+
import { isPromise } from "node:util/types";
|
|
11
|
+
function isRevalidateMethod(key, nextResponseField) {
|
|
12
|
+
return key === "revalidate" && typeof nextResponseField === "function";
|
|
13
|
+
}
|
|
14
|
+
var nextResponseProxy = (response, requestContext) => {
|
|
15
|
+
return new Proxy(response, {
|
|
16
|
+
get(target, key) {
|
|
17
|
+
const originalValue = Reflect.get(target, key);
|
|
18
|
+
if (isRevalidateMethod(key, originalValue)) {
|
|
19
|
+
return function newRevalidate(...args) {
|
|
20
|
+
requestContext.didPagesRouterOnDemandRevalidate = true;
|
|
21
|
+
const result = originalValue.apply(target, args);
|
|
22
|
+
if (result && isPromise(result)) {
|
|
23
|
+
requestContext.trackBackgroundWork(result);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return originalValue;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
nextResponseProxy
|
|
34
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/run/storage/regional-blob-store.cts
|
|
21
|
+
var regional_blob_store_exports = {};
|
|
22
|
+
__export(regional_blob_store_exports, {
|
|
23
|
+
getRegionalBlobStore: () => getRegionalBlobStore,
|
|
24
|
+
setFetchBeforeNextPatchedIt: () => setFetchBeforeNextPatchedIt
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(regional_blob_store_exports);
|
|
27
|
+
var FETCH_BEFORE_NEXT_PATCHED_IT = Symbol.for("nf-not-patched-fetch");
|
|
28
|
+
var extendedGlobalThis = globalThis;
|
|
29
|
+
function attemptToGetOriginalFetch(fetch) {
|
|
30
|
+
return fetch._nextOriginalFetch ?? fetch;
|
|
31
|
+
}
|
|
32
|
+
function forceOptOutOfUsingDataCache(fetch) {
|
|
33
|
+
return (input, init) => {
|
|
34
|
+
return fetch(input, {
|
|
35
|
+
...init,
|
|
36
|
+
next: {
|
|
37
|
+
...init?.next,
|
|
38
|
+
// setting next.internal = true should prevent from trying to use data cache
|
|
39
|
+
// https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L174
|
|
40
|
+
// https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L210-L213
|
|
41
|
+
// this is last line of defense in case we didn't manage to get unpatched fetch that will not affect
|
|
42
|
+
// fetch if it's unpatched so it should be safe to apply always if we aren't sure if we use patched fetch
|
|
43
|
+
// @ts-expect-error - this is an internal field that Next.js doesn't add to its global
|
|
44
|
+
// type overrides for RequestInit type (like `next.revalidate` or `next.tags`)
|
|
45
|
+
internal: true
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
var setFetchBeforeNextPatchedIt = (fetch) => {
|
|
51
|
+
extendedGlobalThis[FETCH_BEFORE_NEXT_PATCHED_IT] = forceOptOutOfUsingDataCache(
|
|
52
|
+
attemptToGetOriginalFetch(fetch)
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
var fetchBeforeNextPatchedItFallback = forceOptOutOfUsingDataCache(
|
|
56
|
+
attemptToGetOriginalFetch(globalThis.fetch)
|
|
57
|
+
);
|
|
58
|
+
var getRegionalBlobStore = (args = {}) => {
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
getRegionalBlobStore,
|
|
63
|
+
setFetchBeforeNextPatchedIt
|
|
64
|
+
});
|