@edgeone/nuxt-pages 1.0.0
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/README.md +275 -0
- package/dist/build/content/server.js +18 -0
- package/dist/build/content/static.js +17 -0
- package/dist/build/functions/server.js +19 -0
- package/dist/build/plugin-context.js +18 -0
- package/dist/build/routes.js +18 -0
- package/dist/build/templates/nuxt-handler-backup.js +305 -0
- package/dist/build/templates/nuxt-handler-monorepo.tmpl-ipx_backup.js +511 -0
- package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +243 -0
- package/dist/build/templates/nuxt-handler.tmpl.js +212 -0
- package/dist/esm-chunks/chunk-5YBUNNZ4.js +81 -0
- package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
- package/dist/esm-chunks/chunk-6YERJDAJ.js +208 -0
- package/dist/esm-chunks/chunk-GX4Z7KQX.js +15065 -0
- package/dist/esm-chunks/chunk-HBXUWFGE.js +19 -0
- package/dist/esm-chunks/chunk-HY3HNABZ.js +87 -0
- package/dist/esm-chunks/chunk-KGYBHZC3.js +1467 -0
- package/dist/esm-chunks/chunk-MMMRMLH2.js +132 -0
- package/dist/esm-chunks/chunk-NJ4SUJNF.js +5635 -0
- package/dist/esm-chunks/chunk-QG7JLDXY.js +127 -0
- package/dist/esm-chunks/chunk-RPSYO4VM.js +562 -0
- package/dist/esm-chunks/chunk-UOPC2N5A.js +69 -0
- package/dist/esm-chunks/chunk-V2LFVP3C.js +838 -0
- package/dist/index.js +61 -0
- package/dist/run/config.js +17 -0
- package/dist/run/constants.js +17 -0
- package/dist/run/handlers/cache.cjs +1410 -0
- package/dist/run/handlers/nuxt-cache.cjs +200 -0
- package/dist/run/handlers/nuxt-server.js +156 -0
- package/dist/run/handlers/request-context.cjs +148 -0
- package/dist/run/handlers/server.js +77 -0
- package/dist/run/handlers/tags-handler.cjs +177 -0
- package/dist/run/handlers/tracer.cjs +1004 -0
- package/dist/run/handlers/use-cache-handler.js +220 -0
- package/dist/run/handlers/wait-until.cjs +123 -0
- package/dist/run/headers.js +17 -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 +1582 -0
- package/dist/run/storage/storage.cjs +191 -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/dist/shared/nuxt-cache-types.cjs +18 -0
- package/dist/types/options.js +6 -0
- package/dist/utils.js +25 -0
- package/package.json +58 -0
|
@@ -0,0 +1,177 @@
|
|
|
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 name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], 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/tags-handler.cts
|
|
21
|
+
var tags_handler_exports = {};
|
|
22
|
+
__export(tags_handler_exports, {
|
|
23
|
+
isAnyTagStale: () => isAnyTagStale,
|
|
24
|
+
markTagsAsStaleAndPurgeEdgeCache: () => markTagsAsStaleAndPurgeEdgeCache,
|
|
25
|
+
purgeEdgeCache: () => purgeEdgeCache
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(tags_handler_exports);
|
|
28
|
+
|
|
29
|
+
// package.json
|
|
30
|
+
var name = "@edgeone/nuxt-pages";
|
|
31
|
+
var version = "1.0.0";
|
|
32
|
+
|
|
33
|
+
// src/run/handlers/request-context.cts
|
|
34
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
35
|
+
|
|
36
|
+
// node_modules/@netlify/functions/dist/internal.js
|
|
37
|
+
var import_process = require("process");
|
|
38
|
+
var systemLogTag = "__nfSystemLog";
|
|
39
|
+
var serializeError = (error) => {
|
|
40
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
41
|
+
return {
|
|
42
|
+
error: error.message,
|
|
43
|
+
error_cause: cause,
|
|
44
|
+
error_stack: error.stack
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var SystemLogger = class _SystemLogger {
|
|
48
|
+
fields;
|
|
49
|
+
logLevel;
|
|
50
|
+
constructor(fields = {}, logLevel = 2) {
|
|
51
|
+
this.fields = fields;
|
|
52
|
+
this.logLevel = logLevel;
|
|
53
|
+
}
|
|
54
|
+
doLog(logger, message) {
|
|
55
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
59
|
+
}
|
|
60
|
+
log(message) {
|
|
61
|
+
if (this.logLevel > 2) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.doLog(console.log, message);
|
|
65
|
+
}
|
|
66
|
+
debug(message) {
|
|
67
|
+
if (this.logLevel > 1) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.doLog(console.debug, message);
|
|
71
|
+
}
|
|
72
|
+
error(message) {
|
|
73
|
+
if (this.logLevel > 3) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.doLog(console.error, message);
|
|
77
|
+
}
|
|
78
|
+
withLogLevel(level) {
|
|
79
|
+
return new _SystemLogger(this.fields, level);
|
|
80
|
+
}
|
|
81
|
+
withFields(fields) {
|
|
82
|
+
return new _SystemLogger(
|
|
83
|
+
{
|
|
84
|
+
...this.fields,
|
|
85
|
+
...fields
|
|
86
|
+
},
|
|
87
|
+
this.logLevel
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
withError(error) {
|
|
91
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
92
|
+
return this.withFields(fields);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var systemLogger = new SystemLogger();
|
|
96
|
+
|
|
97
|
+
// src/run/handlers/request-context.cts
|
|
98
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
99
|
+
var REQUEST_COUNTER_KEY = Symbol.for("nf-request-counter");
|
|
100
|
+
var extendedGlobalThis = globalThis;
|
|
101
|
+
var requestContextAsyncLocalStorage;
|
|
102
|
+
function getRequestContextAsyncLocalStorage() {
|
|
103
|
+
if (requestContextAsyncLocalStorage) {
|
|
104
|
+
return requestContextAsyncLocalStorage;
|
|
105
|
+
}
|
|
106
|
+
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
107
|
+
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
108
|
+
}
|
|
109
|
+
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
110
|
+
requestContextAsyncLocalStorage = storage;
|
|
111
|
+
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
112
|
+
return storage;
|
|
113
|
+
}
|
|
114
|
+
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
115
|
+
function getLogger() {
|
|
116
|
+
return getRequestContext()?.logger ?? systemLogger;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/run/handlers/tags-handler.cts
|
|
120
|
+
var purgeCacheUserAgent = `${name}@${version}`;
|
|
121
|
+
function isAnyTagStale(tags, timestamp) {
|
|
122
|
+
return Promise.resolve(false);
|
|
123
|
+
}
|
|
124
|
+
function getCacheTagsFromTagOrTags(tagOrTags) {
|
|
125
|
+
return (Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]).flatMap((tag) => tag.split(/,|%2c/gi)).filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
async function purgeEdgeCache(tagOrTags) {
|
|
128
|
+
const tags = getCacheTagsFromTagOrTags(tagOrTags).map((tag) => {
|
|
129
|
+
return tag.replace(/^_N_T_/, "").replace(/\/page|\/layout$/, "");
|
|
130
|
+
});
|
|
131
|
+
if (tags.length === 0) {
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
}
|
|
134
|
+
getLogger().debug(`[NuxtRuntime] Purging CDN cache for: [${tags.join(", ")}]`);
|
|
135
|
+
const baseUrl = process.env.IS_MAINLAND === "true" ? "https://pages-api.cloud.tencent.com" : "https://pages-api.edgeone.ai";
|
|
136
|
+
const token = process.env.PURGE_TOKEN;
|
|
137
|
+
const requestBody = {
|
|
138
|
+
path: [...tags]
|
|
139
|
+
};
|
|
140
|
+
const res = await fetch(`${baseUrl}/eo/purge`, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: {
|
|
143
|
+
"Content-Type": "application/json",
|
|
144
|
+
Authorization: `Bearer ${token}`
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(requestBody)
|
|
147
|
+
});
|
|
148
|
+
const data = await res.json();
|
|
149
|
+
if (data?.error) {
|
|
150
|
+
console.log(`Failed to purge CDN cache: ${data?.error.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function doRevalidateTagAndPurgeEdgeCache(tags) {
|
|
154
|
+
getLogger().withFields({ tags }).debug("doRevalidateTagAndPurgeEdgeCache");
|
|
155
|
+
if (tags.length === 0) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const tagManifest = {
|
|
159
|
+
revalidatedAt: Date.now()
|
|
160
|
+
};
|
|
161
|
+
await purgeEdgeCache(tags);
|
|
162
|
+
}
|
|
163
|
+
function markTagsAsStaleAndPurgeEdgeCache(tagOrTags) {
|
|
164
|
+
const tags = getCacheTagsFromTagOrTags(tagOrTags);
|
|
165
|
+
const revalidateTagPromise = doRevalidateTagAndPurgeEdgeCache(tags);
|
|
166
|
+
const requestContext = getRequestContext();
|
|
167
|
+
if (requestContext) {
|
|
168
|
+
requestContext.trackBackgroundWork(revalidateTagPromise);
|
|
169
|
+
}
|
|
170
|
+
return revalidateTagPromise;
|
|
171
|
+
}
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
isAnyTagStale,
|
|
175
|
+
markTagsAsStaleAndPurgeEdgeCache,
|
|
176
|
+
purgeEdgeCache
|
|
177
|
+
});
|