Skip to content

Commit e4b2c69

Browse files
committed
fix(readme):updated
1 parent dd9239c commit e4b2c69

127 files changed

Lines changed: 8971 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.open-next/.build/cache.cjs

Lines changed: 530 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
globalThis.disableIncrementalCache = false;globalThis.disableDynamoDBCache = false;globalThis.isNextAfter15 = true;globalThis.openNextDebug = false;globalThis.openNextVersion = "3.7.4";
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+
// node_modules/@opennextjs/aws/dist/adapters/composable-cache.js
21+
var composable_cache_exports = {};
22+
__export(composable_cache_exports, {
23+
default: () => composable_cache_default
24+
});
25+
module.exports = __toCommonJS(composable_cache_exports);
26+
27+
// node_modules/@opennextjs/aws/dist/adapters/logger.js
28+
function debug(...args) {
29+
if (globalThis.openNextDebug) {
30+
console.log(...args);
31+
}
32+
}
33+
34+
// node_modules/@opennextjs/aws/dist/utils/cache.js
35+
function getTagKey(tag) {
36+
if (typeof tag === "string") {
37+
return tag;
38+
}
39+
return JSON.stringify({
40+
tag: tag.tag,
41+
path: tag.path
42+
});
43+
}
44+
async function writeTags(tags) {
45+
const store = globalThis.__openNextAls.getStore();
46+
debug("Writing tags", tags, store);
47+
if (!store || globalThis.openNextConfig.dangerous?.disableTagCache) {
48+
return;
49+
}
50+
const tagsToWrite = tags.filter((t) => {
51+
const tagKey = getTagKey(t);
52+
const shouldWrite = !store.writtenTags.has(tagKey);
53+
if (shouldWrite) {
54+
store.writtenTags.add(tagKey);
55+
}
56+
return shouldWrite;
57+
});
58+
if (tagsToWrite.length === 0) {
59+
return;
60+
}
61+
await globalThis.tagCache.writeTags(tagsToWrite);
62+
}
63+
64+
// node_modules/@opennextjs/aws/dist/utils/stream.js
65+
var import_node_stream = require("node:stream");
66+
function fromReadableStream(stream, base64) {
67+
const reader = stream.getReader();
68+
const chunks = [];
69+
return new Promise((resolve, reject) => {
70+
function pump() {
71+
reader.read().then(({ done, value }) => {
72+
if (done) {
73+
resolve(Buffer.concat(chunks).toString(base64 ? "base64" : "utf8"));
74+
return;
75+
}
76+
chunks.push(value);
77+
pump();
78+
}).catch(reject);
79+
}
80+
pump();
81+
});
82+
}
83+
function toReadableStream(value, isBase64) {
84+
return import_node_stream.Readable.toWeb(import_node_stream.Readable.from(Buffer.from(value, isBase64 ? "base64" : "utf8")));
85+
}
86+
87+
// node_modules/@opennextjs/aws/dist/adapters/composable-cache.js
88+
var pendingWritePromiseMap = /* @__PURE__ */ new Map();
89+
var composable_cache_default = {
90+
async get(cacheKey) {
91+
try {
92+
if (pendingWritePromiseMap.has(cacheKey)) {
93+
const stored = pendingWritePromiseMap.get(cacheKey);
94+
if (stored) {
95+
return stored.then((entry) => ({
96+
...entry,
97+
value: toReadableStream(entry.value)
98+
}));
99+
}
100+
}
101+
const result = await globalThis.incrementalCache.get(cacheKey, "composable");
102+
if (!result?.value?.value) {
103+
return void 0;
104+
}
105+
debug("composable cache result", result);
106+
if (globalThis.tagCache.mode === "nextMode" && result.value.tags.length > 0) {
107+
const hasBeenRevalidated = result.shouldBypassTagCache ? false : await globalThis.tagCache.hasBeenRevalidated(result.value.tags, result.lastModified);
108+
if (hasBeenRevalidated)
109+
return void 0;
110+
} else if (globalThis.tagCache.mode === "original" || globalThis.tagCache.mode === void 0) {
111+
const hasBeenRevalidated = result.shouldBypassTagCache ? false : await globalThis.tagCache.getLastModified(cacheKey, result.lastModified) === -1;
112+
if (hasBeenRevalidated)
113+
return void 0;
114+
}
115+
return {
116+
...result.value,
117+
value: toReadableStream(result.value.value)
118+
};
119+
} catch (e) {
120+
debug("Cannot read composable cache entry");
121+
return void 0;
122+
}
123+
},
124+
async set(cacheKey, pendingEntry) {
125+
const promiseEntry = pendingEntry.then(async (entry2) => ({
126+
...entry2,
127+
value: await fromReadableStream(entry2.value)
128+
}));
129+
pendingWritePromiseMap.set(cacheKey, promiseEntry);
130+
const entry = await promiseEntry.finally(() => {
131+
pendingWritePromiseMap.delete(cacheKey);
132+
});
133+
await globalThis.incrementalCache.set(cacheKey, {
134+
...entry,
135+
value: entry.value
136+
}, "composable");
137+
if (globalThis.tagCache.mode === "original") {
138+
const storedTags = await globalThis.tagCache.getByPath(cacheKey);
139+
const tagsToWrite = entry.tags.filter((tag) => !storedTags.includes(tag));
140+
if (tagsToWrite.length > 0) {
141+
await writeTags(tagsToWrite.map((tag) => ({ tag, path: cacheKey })));
142+
}
143+
}
144+
},
145+
async refreshTags() {
146+
return;
147+
},
148+
async getExpiration(...tags) {
149+
if (globalThis.tagCache.mode === "nextMode") {
150+
return globalThis.tagCache.getLastRevalidated(tags);
151+
}
152+
return 0;
153+
},
154+
async expireTags(...tags) {
155+
if (globalThis.tagCache.mode === "nextMode") {
156+
return writeTags(tags);
157+
}
158+
const tagCache = globalThis.tagCache;
159+
const revalidatedAt = Date.now();
160+
const pathsToUpdate = await Promise.all(tags.map(async (tag) => {
161+
const paths = await tagCache.getByTag(tag);
162+
return paths.map((path) => ({
163+
path,
164+
tag,
165+
revalidatedAt
166+
}));
167+
}));
168+
const setToWrite = /* @__PURE__ */ new Set();
169+
for (const entry of pathsToUpdate.flat()) {
170+
setToWrite.add(entry);
171+
}
172+
await writeTags(Array.from(setToWrite));
173+
},
174+
// This one is necessary for older versions of next
175+
async receiveExpiredTags(...tags) {
176+
return;
177+
}
178+
};
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// node_modules/@opennextjs/cloudflare/dist/api/cloudflare-context.js
2+
var cloudflareContextSymbol = Symbol.for("__cloudflare-context__");
3+
function getCloudflareContext(options = { async: false }) {
4+
return options.async ? getCloudflareContextAsync() : getCloudflareContextSync();
5+
}
6+
function getCloudflareContextFromGlobalScope() {
7+
const global = globalThis;
8+
return global[cloudflareContextSymbol];
9+
}
10+
function inSSG() {
11+
const global = globalThis;
12+
return global.__NEXT_DATA__?.nextExport === true;
13+
}
14+
function getCloudflareContextSync() {
15+
const cloudflareContext = getCloudflareContextFromGlobalScope();
16+
if (cloudflareContext) {
17+
return cloudflareContext;
18+
}
19+
if (inSSG()) {
20+
throw new Error(`
21+
22+
ERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one, both cases are not allowed but can be solved by either:
23+
- make sure that the call is not at the top level and that the route is not static
24+
- call \`getCloudflareContext({async: true})\` to use the \`async\` mode
25+
- avoid calling \`getCloudflareContext\` in the route
26+
`);
27+
}
28+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
29+
}
30+
async function getCloudflareContextAsync() {
31+
const cloudflareContext = getCloudflareContextFromGlobalScope();
32+
if (cloudflareContext) {
33+
return cloudflareContext;
34+
}
35+
const inNodejsRuntime = process.env.NEXT_RUNTIME === "nodejs";
36+
if (inNodejsRuntime || inSSG()) {
37+
const cloudflareContext2 = await getCloudflareContextFromWrangler();
38+
addCloudflareContextToNodejsGlobal(cloudflareContext2);
39+
return cloudflareContext2;
40+
}
41+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
42+
}
43+
function addCloudflareContextToNodejsGlobal(cloudflareContext) {
44+
const global = globalThis;
45+
global[cloudflareContextSymbol] = cloudflareContext;
46+
}
47+
async function getCloudflareContextFromWrangler(options) {
48+
const { getPlatformProxy } = await import(
49+
/* webpackIgnore: true */
50+
`${"__wrangler".replaceAll("_", "")}`
51+
);
52+
const environment = options?.environment ?? process.env.NEXT_DEV_WRANGLER_ENV;
53+
const { env, cf, ctx } = await getPlatformProxy({
54+
...options,
55+
environment
56+
});
57+
return {
58+
env,
59+
cf,
60+
ctx
61+
};
62+
}
63+
var initOpenNextCloudflareForDevErrorMsg = `
64+
65+
ERROR: \`getCloudflareContext\` has been called without having called \`initOpenNextCloudflareForDev\` from the Next.js config file.
66+
You should update your Next.js config file as shown below:
67+
68+
\`\`\`
69+
// next.config.mjs
70+
71+
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
72+
73+
initOpenNextCloudflareForDev();
74+
75+
const nextConfig = { ... };
76+
export default nextConfig;
77+
\`\`\`
78+
79+
`;
80+
81+
// node_modules/@opennextjs/cloudflare/dist/api/overrides/asset-resolver/index.js
82+
var resolver = {
83+
name: "cloudflare-asset-resolver",
84+
async maybeGetAssetResult(event) {
85+
const { ASSETS } = getCloudflareContext().env;
86+
if (!ASSETS || !isUserWorkerFirst(globalThis.__ASSETS_RUN_WORKER_FIRST__, event.rawPath)) {
87+
return void 0;
88+
}
89+
const { method, headers } = event;
90+
if (method !== "GET" && method != "HEAD") {
91+
return void 0;
92+
}
93+
const url = new URL(event.rawPath, "https://assets.local");
94+
const response = await ASSETS.fetch(url, {
95+
headers,
96+
method
97+
});
98+
if (response.status === 404) {
99+
await response.body?.cancel();
100+
return void 0;
101+
}
102+
return {
103+
type: "core",
104+
statusCode: response.status,
105+
headers: Object.fromEntries(response.headers.entries()),
106+
// Workers and Node types differ.
107+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108+
body: response.body || new ReadableStream(),
109+
isBase64Encoded: false
110+
};
111+
}
112+
};
113+
function isUserWorkerFirst(runWorkerFirst, pathname) {
114+
if (!Array.isArray(runWorkerFirst)) {
115+
return runWorkerFirst ?? false;
116+
}
117+
let hasPositiveMatch = false;
118+
for (let rule of runWorkerFirst) {
119+
let isPositiveRule = true;
120+
if (rule.startsWith("!")) {
121+
rule = rule.slice(1);
122+
isPositiveRule = false;
123+
} else if (hasPositiveMatch) {
124+
continue;
125+
}
126+
const match = new RegExp(`^${rule.replace(/([[\]().*+?^$|{}\\])/g, "\\$1").replace("\\*", ".*")}$`).test(pathname);
127+
if (match) {
128+
if (isPositiveRule) {
129+
hasPositiveMatch = true;
130+
} else {
131+
return false;
132+
}
133+
}
134+
}
135+
return hasPositiveMatch;
136+
}
137+
var asset_resolver_default = resolver;
138+
139+
// node_modules/@opennextjs/cloudflare/dist/api/config.js
140+
function defineCloudflareConfig(config = {}) {
141+
const { incrementalCache, tagCache, queue, cachePurge, enableCacheInterception = false, routePreloadingBehavior = "none" } = config;
142+
return {
143+
default: {
144+
override: {
145+
wrapper: "cloudflare-node",
146+
converter: "edge",
147+
proxyExternalRequest: "fetch",
148+
incrementalCache: resolveIncrementalCache(incrementalCache),
149+
tagCache: resolveTagCache(tagCache),
150+
queue: resolveQueue(queue),
151+
cdnInvalidation: resolveCdnInvalidation(cachePurge)
152+
},
153+
routePreloadingBehavior
154+
},
155+
// node:crypto is used to compute cache keys
156+
edgeExternals: ["node:crypto"],
157+
cloudflare: {
158+
useWorkerdCondition: true
159+
},
160+
dangerous: {
161+
enableCacheInterception
162+
},
163+
middleware: {
164+
external: true,
165+
override: {
166+
wrapper: "cloudflare-edge",
167+
converter: "edge",
168+
proxyExternalRequest: "fetch",
169+
incrementalCache: resolveIncrementalCache(incrementalCache),
170+
tagCache: resolveTagCache(tagCache),
171+
queue: resolveQueue(queue)
172+
},
173+
assetResolver: () => asset_resolver_default
174+
}
175+
};
176+
}
177+
function resolveIncrementalCache(value = "dummy") {
178+
if (typeof value === "string") {
179+
return value;
180+
}
181+
return typeof value === "function" ? value : () => value;
182+
}
183+
function resolveTagCache(value = "dummy") {
184+
if (typeof value === "string") {
185+
return value;
186+
}
187+
return typeof value === "function" ? value : () => value;
188+
}
189+
function resolveQueue(value = "dummy") {
190+
if (typeof value === "string") {
191+
return value;
192+
}
193+
return typeof value === "function" ? value : () => value;
194+
}
195+
function resolveCdnInvalidation(value = "dummy") {
196+
if (typeof value === "string") {
197+
return value;
198+
}
199+
return typeof value === "function" ? value : () => value;
200+
}
201+
202+
// open-next.config.ts
203+
var open_next_config_default = defineCloudflareConfig();
204+
export {
205+
open_next_config_default as default
206+
};

0 commit comments

Comments
 (0)