@qwik.dev/router 2.0.0-beta.37 → 2.0.0-beta.39
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/lib/adapters/cloudflare-pages/vite/index.mjs +2 -2
- package/lib/adapters/shared/vite/index.d.ts +3 -4
- package/lib/adapters/shared/vite/index.mjs +158 -143
- package/lib/chunks/dev-preloaded-route-loader.mjs +3 -0
- package/lib/chunks/fs.mjs +6 -2
- package/lib/chunks/head.qwik.mjs +814 -93
- package/lib/chunks/request-body-limit.mjs +37 -0
- package/lib/chunks/request-path.mjs +2 -2
- package/lib/chunks/routes.mjs +47 -0
- package/lib/chunks/server-error.mjs +19 -0
- package/lib/chunks/system.mjs +2 -1
- package/lib/chunks/use-functions.qwik.mjs +1 -1
- package/lib/chunks/{worker-thread.qwik.mjs → user-response.mjs} +1053 -1749
- package/lib/chunks/worker-thread.mjs +317 -0
- package/lib/index.d.ts +89 -55
- package/lib/index.qwik.mjs +178 -100
- package/lib/middleware/azure-swa/index.mjs +13 -9
- package/lib/middleware/cloudflare-pages/index.mjs +2 -2
- package/lib/middleware/deno/index.d.ts +2 -0
- package/lib/middleware/deno/index.mjs +2 -1
- package/lib/middleware/netlify-edge/index.mjs +2 -2
- package/lib/middleware/node/index.d.ts +9 -1
- package/lib/middleware/node/index.mjs +28 -3
- package/lib/middleware/request-handler/index.d.ts +9 -10
- package/lib/middleware/request-handler/index.mjs +26 -1105
- package/lib/middleware/vercel-edge/index.mjs +2 -2
- package/lib/ssg/index.d.ts +2 -10
- package/lib/ssg/index.mjs +10 -50
- package/lib/vite/index.d.ts +8 -0
- package/lib/vite/index.mjs +406 -117
- package/package.json +5 -4
- package/lib/chunks/action-handler.mjs +0 -782
- package/lib/chunks/deepFreeze.qwik.mjs +0 -608
- package/lib/chunks/error-handler.mjs +0 -57
- package/lib/chunks/not-found-wrapper.qwik.mjs +0 -25
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { S as ServerError } from './server-error.mjs';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_REQUEST_BODY_LIMIT = 10 * 1024 * 1024;
|
|
4
|
+
class RequestBodyLimitError extends ServerError {
|
|
5
|
+
code = "QWIK_REQUEST_BODY_LIMIT";
|
|
6
|
+
statusCode = 413;
|
|
7
|
+
constructor(limit) {
|
|
8
|
+
super(413, `Request body exceeds ${limit} bytes`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const validateRequestBodyLimit = (requestBodyLimit) => {
|
|
12
|
+
if (!Number.isSafeInteger(requestBodyLimit) || requestBodyLimit <= 0) {
|
|
13
|
+
throw new TypeError("requestBodyLimit must be a positive safe integer");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const limitRequestBody = (request, requestBodyLimit = DEFAULT_REQUEST_BODY_LIMIT) => {
|
|
17
|
+
validateRequestBodyLimit(requestBodyLimit);
|
|
18
|
+
if (!request.body) {
|
|
19
|
+
return request;
|
|
20
|
+
}
|
|
21
|
+
let received = 0;
|
|
22
|
+
const body = request.body.pipeThrough(new TransformStream({
|
|
23
|
+
transform(chunk, controller) {
|
|
24
|
+
if (chunk.byteLength > requestBodyLimit - received) {
|
|
25
|
+
throw new RequestBodyLimitError(requestBodyLimit);
|
|
26
|
+
}
|
|
27
|
+
received += chunk.byteLength;
|
|
28
|
+
controller.enqueue(chunk);
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return new Request(request, {
|
|
32
|
+
body,
|
|
33
|
+
duplex: "half"
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { DEFAULT_REQUEST_BODY_LIMIT as D, RequestBodyLimitError as R, limitRequestBody as l, validateRequestBodyLimit as v };
|
|
@@ -4,7 +4,7 @@ const IsQLoader = "@isQLoader";
|
|
|
4
4
|
const IsQAction = "@isQAction";
|
|
5
5
|
const QLoaderId = "@loaderId";
|
|
6
6
|
const QActionId = "@actionId";
|
|
7
|
-
const LOADER_REGEX = /\/(q-loader-([
|
|
7
|
+
const LOADER_REGEX = /\/(q-loader-([^/.]+)\.([^/.]+)\.json)$/;
|
|
8
8
|
const getLoaderName = (loaderId, manifestHash) => `q-loader-${loaderId}.${manifestHash}.json`;
|
|
9
9
|
function recognizeRequest(pathname) {
|
|
10
10
|
if (pathname.length < 10) {
|
|
@@ -57,4 +57,4 @@ function resolveValidInternalFullPathname(loaderPathname, fullPath) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export { IsQLoader as I, LOADER_REGEX as L, QLoaderId as Q,
|
|
60
|
+
export { IsQLoader as I, LOADER_REGEX as L, QLoaderId as Q, resolveValidInternalFullPathname as a, trimInternalPathname as b, IsQAction as c, QActionId as d, getLoaderName as g, recognizeRequest as r, trimRecognizedInternalPathname as t };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function routeToRegExp(rule) {
|
|
2
|
+
let transformedRule;
|
|
3
|
+
if (rule === "/" || rule === "/*") {
|
|
4
|
+
transformedRule = rule;
|
|
5
|
+
} else if (rule.endsWith("/*")) {
|
|
6
|
+
transformedRule = `${rule.substring(0, rule.length - 2)}(/*)?`;
|
|
7
|
+
} else if (rule.endsWith("/")) {
|
|
8
|
+
transformedRule = `${rule.substring(0, rule.length - 1)}(/)?`;
|
|
9
|
+
} else if (rule.endsWith("*")) {
|
|
10
|
+
transformedRule = rule;
|
|
11
|
+
} else {
|
|
12
|
+
transformedRule = `${rule}(/)?`;
|
|
13
|
+
}
|
|
14
|
+
transformedRule = `^${transformedRule.replace(/\*/g, ".*")}$`;
|
|
15
|
+
return new RegExp(transformedRule);
|
|
16
|
+
}
|
|
17
|
+
function routesToRegExps(routes) {
|
|
18
|
+
if (!Array.isArray(routes)) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return routes.filter((r) => typeof r === "string").map(routeToRegExp);
|
|
22
|
+
}
|
|
23
|
+
function createRouteTester(basePathname, includeRoutes, excludeRoutes) {
|
|
24
|
+
const includes = routesToRegExps(includeRoutes);
|
|
25
|
+
const excludes = routesToRegExps(excludeRoutes);
|
|
26
|
+
return (pathname) => {
|
|
27
|
+
if (basePathname !== "/") {
|
|
28
|
+
pathname = pathname.slice(basePathname.length - 1);
|
|
29
|
+
}
|
|
30
|
+
for (const exclude of excludes) {
|
|
31
|
+
if (exclude.test(pathname)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (pathname.endsWith("/404.html")) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
for (const include of includes) {
|
|
39
|
+
if (include.test(pathname)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { createRouteTester as c };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class AbortMessage {
|
|
2
|
+
}
|
|
3
|
+
class RedirectMessage extends AbortMessage {
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
class ServerError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
data;
|
|
9
|
+
constructor(status, data) {
|
|
10
|
+
super(typeof data === "string" ? data : void 0), this.status = status, this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const throwIfControlFlowSignal = (value) => {
|
|
14
|
+
if (value instanceof AbortMessage || value instanceof ServerError) {
|
|
15
|
+
throw value;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { AbortMessage as A, RedirectMessage as R, ServerError as S, throwIfControlFlowSignal as t };
|
package/lib/chunks/system.mjs
CHANGED
|
@@ -167,7 +167,8 @@ async function createWorkerPool(sys, opts) {
|
|
|
167
167
|
const render = async (ssgRoute) => {
|
|
168
168
|
const ssgWorker = getNextWorker();
|
|
169
169
|
const result = await ssgWorker.render(ssgRoute);
|
|
170
|
-
|
|
170
|
+
const isNotFoundPage = result.pathname.endsWith("/404.html");
|
|
171
|
+
if (sitemapOutFile && result.ok && result.resourceType === "page" && !isNotFoundPage) {
|
|
171
172
|
sitemapBuffer.push(`<url><loc>${result.url}</loc></url>`);
|
|
172
173
|
if (sitemapBuffer.length > 50) {
|
|
173
174
|
const siteMapUrls = sitemapBuffer.join("\n") + "\n";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, implicit$FirstArg, useVisibleTaskQrl, inlinedQrl, _captures, noSerialize, useServerData } from '@qwik.dev/core';
|
|
2
|
-
import { C as ContentContext, D as DocumentHeadContext, H as HttpStatusContext,
|
|
2
|
+
import { C as ContentContext, D as DocumentHeadContext, H as HttpStatusContext, j as RouteLocationContext, k as RouteNavigateContext, p as RoutePreventNavigateContext, o as RouteActionContext } from './head.qwik.mjs';
|
|
3
3
|
|
|
4
4
|
const useHttpStatus = () => useContext(HttpStatusContext).value;
|
|
5
5
|
const useContent = () => useContext(ContentContext);
|