@qwik.dev/router 2.0.0-beta.39 → 2.0.0-beta.40

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.
Files changed (40) hide show
  1. package/lib/adapters/azure-swa/vite/index.mjs +45 -54
  2. package/lib/adapters/bun-server/vite/index.mjs +16 -22
  3. package/lib/adapters/cloud-run/vite/index.mjs +15 -19
  4. package/lib/adapters/cloudflare-pages/vite/index.mjs +46 -67
  5. package/lib/adapters/deno-server/vite/index.mjs +25 -39
  6. package/lib/adapters/netlify-edge/vite/index.mjs +50 -76
  7. package/lib/adapters/node-server/vite/index.mjs +16 -22
  8. package/lib/adapters/shared/vite/index.mjs +271 -360
  9. package/lib/adapters/ssg/vite/index.mjs +11 -15
  10. package/lib/adapters/vercel-edge/vite/index.mjs +74 -95
  11. package/lib/chunks/dev-preloaded-route-loader.mjs +2 -3
  12. package/lib/chunks/format.mjs +16 -23
  13. package/lib/chunks/fs.mjs +93 -106
  14. package/lib/chunks/head.qwik.mjs +1174 -1382
  15. package/lib/chunks/http-error.qwik.mjs +20 -28
  16. package/lib/chunks/pathname.mjs +50 -69
  17. package/lib/chunks/request-body-limit.mjs +25 -35
  18. package/lib/chunks/request-path.mjs +44 -55
  19. package/lib/chunks/routes.mjs +20 -41
  20. package/lib/chunks/server-error.mjs +15 -18
  21. package/lib/chunks/system.mjs +258 -326
  22. package/lib/chunks/url.mjs +56 -58
  23. package/lib/chunks/user-response.mjs +1616 -1804
  24. package/lib/chunks/worker-thread.mjs +254 -307
  25. package/lib/index.qwik.mjs +1637 -1918
  26. package/lib/middleware/aws-lambda/index.mjs +44 -52
  27. package/lib/middleware/azure-swa/index.mjs +85 -94
  28. package/lib/middleware/bun/index.mjs +118 -138
  29. package/lib/middleware/cloudflare-pages/index.mjs +83 -96
  30. package/lib/middleware/deno/index.mjs +104 -125
  31. package/lib/middleware/firebase/index.mjs +21 -25
  32. package/lib/middleware/netlify-edge/index.mjs +63 -71
  33. package/lib/middleware/node/index.mjs +297 -357
  34. package/lib/middleware/request-handler/index.mjs +110 -133
  35. package/lib/middleware/vercel-edge/index.mjs +82 -98
  36. package/lib/service-worker/index.mjs +12 -3
  37. package/lib/ssg/index.mjs +249 -289
  38. package/lib/vite/index.mjs +2344 -3030
  39. package/package.json +5 -5
  40. package/lib/chunks/use-functions.qwik.mjs +0 -23
@@ -1,35 +1,27 @@
1
- import { componentQrl, inlinedQrl, _jsxSorted, _fnSignal } from '@qwik.dev/core';
2
- import { f as useHttpStatus } from './use-functions.qwik.mjs';
3
-
4
- const _hf0 = (p0) => p0.status || 500;
5
- const _hf0_str = "p0.status||500";
6
- const _hf1 = (p0) => p0.message || "";
7
- const _hf1_str = 'p0.message||""';
8
- const cacheKey = (ev) => String(ev.status);
9
- const COLOR_400 = "#006ce9";
10
- const COLOR_500 = "#713fc2";
11
- const DisplayHttpStatus = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
12
- const httpstatus = useHttpStatus();
13
- const width = httpstatus.message ? "600px" : "300px";
14
- const color = httpstatus.status < 500 ? COLOR_400 : COLOR_500;
15
- const style = `
1
+ import { useHttpStatus } from "../index.qwik.mjs";
2
+ import { _fnSignal, _jsxSorted, componentQrl, inlinedQrl } from "@qwik.dev/core";
3
+ var _hf0 = (p0) => p0.status || 500;
4
+ var _hf0_str = "p0.status||500";
5
+ var _hf1 = (p0) => p0.message || "";
6
+ var _hf1_str = "p0.message||\"\"";
7
+ /** Cache error pages per status code so all 404s (or 500s) share one cache entry. */ var cacheKey = (ev) => String(ev.status);
8
+ var COLOR_400 = "#006ce9";
9
+ var COLOR_500 = "#713fc2";
10
+ var DisplayHttpStatus = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl(() => {
11
+ const httpstatus = useHttpStatus();
12
+ const width = httpstatus.message ? "600px" : "300px";
13
+ const color = httpstatus.status < 500 ? COLOR_400 : COLOR_500;
14
+ const style = `
16
15
  body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
17
16
  p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
18
17
  strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
19
18
  span { display: inline-block; padding: 15px; }
20
19
  `;
21
- return /* @__PURE__ */ _jsxSorted("p", null, null, [
22
- /* @__PURE__ */ _jsxSorted("style", {
23
- dangerouslySetInnerHTML: style
24
- }, null, null, 3, null),
25
- /* @__PURE__ */ _jsxSorted("strong", null, null, _fnSignal(_hf0, [
26
- httpstatus
27
- ], _hf0_str), 3, null),
28
- " ",
29
- /* @__PURE__ */ _jsxSorted("span", null, null, _fnSignal(_hf1, [
30
- httpstatus
31
- ], _hf1_str), 3, null)
32
- ], 1, "vY_0");
20
+ return /*#__PURE__*/ _jsxSorted("p", null, null, [
21
+ /*#__PURE__*/ _jsxSorted("style", { dangerouslySetInnerHTML: style }, null, null, 3, null),
22
+ /*#__PURE__*/ _jsxSorted("strong", null, null, _fnSignal(_hf0, [httpstatus], _hf0_str), 3, null),
23
+ " ",
24
+ /*#__PURE__*/ _jsxSorted("span", null, null, _fnSignal(_hf1, [httpstatus], _hf1_str), 3, null)
25
+ ], 1, "vY_0");
33
26
  }, "DisplayHttpStatus_component_PJf4K4PL7Oc"));
34
-
35
27
  export { cacheKey, DisplayHttpStatus as default };
@@ -1,76 +1,57 @@
1
- const ensureSlash = (pathname) => pathname.endsWith("/") ? pathname : pathname + "/";
1
+ /** Ensures the pathname ends with a slash */ var ensureSlash = (pathname) => pathname.endsWith("/") ? pathname : pathname + "/";
2
2
  function normalizePathname(pathname, basePathname) {
3
- if (typeof pathname === "string") {
4
- pathname = pathname.trim();
5
- if (pathname !== "") {
6
- try {
7
- pathname = pathname.replace(/\/+/g, "/");
8
- if (pathname.startsWith("/")) {
9
- pathname = pathname.slice(1);
10
- }
11
- pathname = new URL(basePathname + pathname, `https://qwik.dev`).pathname;
12
- if (pathname !== basePathname) {
13
- if (!globalThis.__NO_TRAILING_SLASH__) {
14
- if (!pathname.endsWith("/")) {
15
- const segments = pathname.split("/");
16
- const lastSegment = segments[segments.length - 1];
17
- if (!lastSegment.includes(".")) {
18
- pathname = ensureSlash(pathname);
19
- }
20
- }
21
- } else {
22
- if (pathname.endsWith("/")) {
23
- pathname = pathname.slice(0, pathname.length - 1);
24
- }
25
- }
26
- }
27
- return pathname;
28
- } catch (e) {
29
- console.error(e);
30
- }
31
- }
32
- }
33
- return null;
3
+ if (typeof pathname === "string") {
4
+ pathname = pathname.trim();
5
+ if (pathname !== "") try {
6
+ pathname = pathname.replace(/\/+/g, "/");
7
+ if (pathname.startsWith("/")) pathname = pathname.slice(1);
8
+ pathname = new URL(basePathname + pathname, `https://qwik.dev`).pathname;
9
+ if (pathname !== basePathname) {
10
+ if (!globalThis.__NO_TRAILING_SLASH__) {
11
+ if (!pathname.endsWith("/")) {
12
+ const segments = pathname.split("/");
13
+ if (!segments[segments.length - 1].includes(".")) pathname = ensureSlash(pathname);
14
+ }
15
+ } else if (pathname.endsWith("/")) pathname = pathname.slice(0, pathname.length - 1);
16
+ }
17
+ return pathname;
18
+ } catch (e) {
19
+ console.error(e);
20
+ }
21
+ }
22
+ return null;
34
23
  }
35
24
  function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
36
- let pathname = originalPathname;
37
- if (paramNames && params) {
38
- for (const paramName of paramNames) {
39
- const paramKey = `[${paramName}]`;
40
- const restParamKey = `[...${paramName}]`;
41
- const paramValue = params[paramName];
42
- pathname = pathname.replace(restParamKey, paramValue);
43
- pathname = pathname.replace(paramKey, paramValue);
44
- }
45
- }
46
- return pathname;
25
+ let pathname = originalPathname;
26
+ if (paramNames && params) for (const paramName of paramNames) {
27
+ const paramKey = `[${paramName}]`;
28
+ const restParamKey = `[...${paramName}]`;
29
+ const paramValue = params[paramName];
30
+ pathname = pathname.replace(restParamKey, paramValue);
31
+ pathname = pathname.replace(paramKey, paramValue);
32
+ }
33
+ return pathname;
47
34
  }
48
- const PROTOCOLS = {
49
- https: true,
50
- http: true,
51
- about: true,
52
- javascript: true,
53
- file: true
35
+ var PROTOCOLS = {
36
+ https: true,
37
+ http: true,
38
+ about: true,
39
+ javascript: true,
40
+ file: true
54
41
  };
55
42
  function isSameOriginUrl(url) {
56
- if (typeof url === "string") {
57
- url = url.trim();
58
- if (url !== "") {
59
- const firstChar = url.charAt(0);
60
- if (firstChar !== "/" && firstChar !== ".") {
61
- if (firstChar === "#") {
62
- return false;
63
- }
64
- const i = url.indexOf(":");
65
- if (i > -1) {
66
- const protocol = url.slice(0, i).toLowerCase();
67
- return !PROTOCOLS[protocol];
68
- }
69
- }
70
- return true;
71
- }
72
- }
73
- return false;
43
+ if (typeof url === "string") {
44
+ url = url.trim();
45
+ if (url !== "") {
46
+ const firstChar = url.charAt(0);
47
+ if (firstChar !== "/" && firstChar !== ".") {
48
+ if (firstChar === "#") return false;
49
+ const i = url.indexOf(":");
50
+ if (i > -1) return !PROTOCOLS[url.slice(0, i).toLowerCase()];
51
+ }
52
+ return true;
53
+ }
54
+ }
55
+ return false;
74
56
  }
75
-
76
- export { ensureSlash as e, getPathnameForDynamicRoute as g, isSameOriginUrl as i, normalizePathname as n };
57
+ export { normalizePathname as i, getPathnameForDynamicRoute as n, isSameOriginUrl as r, ensureSlash as t };
@@ -1,37 +1,27 @@
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
- }
1
+ import { t as ServerError } from "./server-error.mjs";
2
+ var DEFAULT_REQUEST_BODY_LIMIT = 10485760;
3
+ var RequestBodyLimitError = class extends ServerError {
4
+ code = "QWIK_REQUEST_BODY_LIMIT";
5
+ statusCode = 413;
6
+ constructor(limit) {
7
+ super(413, `Request body exceeds ${limit} bytes`);
8
+ }
15
9
  };
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
- });
10
+ var validateRequestBodyLimit = (requestBodyLimit) => {
11
+ if (!Number.isSafeInteger(requestBodyLimit) || requestBodyLimit <= 0) throw new TypeError("requestBodyLimit must be a positive safe integer");
35
12
  };
36
-
37
- export { DEFAULT_REQUEST_BODY_LIMIT as D, RequestBodyLimitError as R, limitRequestBody as l, validateRequestBodyLimit as v };
13
+ var limitRequestBody = (request, requestBodyLimit = DEFAULT_REQUEST_BODY_LIMIT) => {
14
+ validateRequestBodyLimit(requestBodyLimit);
15
+ if (!request.body) return request;
16
+ let received = 0;
17
+ const body = request.body.pipeThrough(new TransformStream({ transform(chunk, controller) {
18
+ if (chunk.byteLength > requestBodyLimit - received) throw new RequestBodyLimitError(requestBodyLimit);
19
+ received += chunk.byteLength;
20
+ controller.enqueue(chunk);
21
+ } }));
22
+ return new Request(request, {
23
+ body,
24
+ duplex: "half"
25
+ });
26
+ };
27
+ export { validateRequestBodyLimit as i, RequestBodyLimitError as n, limitRequestBody as r, DEFAULT_REQUEST_BODY_LIMIT as t };
@@ -1,60 +1,49 @@
1
- import { e as ensureSlash } from './pathname.mjs';
2
-
3
- const IsQLoader = "@isQLoader";
4
- const IsQAction = "@isQAction";
5
- const QLoaderId = "@loaderId";
6
- const QActionId = "@actionId";
7
- const LOADER_REGEX = /\/(q-loader-([^/.]+)\.([^/.]+)\.json)$/;
8
- const getLoaderName = (loaderId, manifestHash) => `q-loader-${loaderId}.${manifestHash}.json`;
9
- function recognizeRequest(pathname) {
10
- if (pathname.length < 10) {
11
- return null;
12
- }
13
- const loaderMatch = pathname.match(LOADER_REGEX);
14
- if (loaderMatch) {
15
- return {
16
- type: IsQLoader,
17
- trimLength: loaderMatch[1].length + 1,
18
- data: {
19
- loaderId: loaderMatch[2],
20
- manifestHash: loaderMatch[3]
21
- }
22
- };
23
- }
24
- return null;
1
+ import { t as ensureSlash } from "./pathname.mjs";
2
+ var IsQLoader = "@isQLoader";
3
+ var IsQAction = "@isQAction";
4
+ var QLoaderId = "@loaderId";
5
+ var QActionId = "@actionId";
6
+ /** Matches the final `/q-loader-{loaderId}.{manifestHash}.json` path segment. */ var LOADER_REGEX = /\/(q-loader-([^/.]+)\.([^/.]+)\.json)$/;
7
+ var getLoaderName = (loaderId, manifestHash) => `q-loader-${loaderId}.${manifestHash}.json`;
8
+ /**
9
+ * Recognize internal request types from the URL pathname.
10
+ *
11
+ * Returns the request type, how many characters to trim from the pathname, and any extracted data
12
+ * (e.g. loaderId for loader requests).
13
+ */ function recognizeRequest(pathname) {
14
+ if (pathname.length < 10) return null;
15
+ const loaderMatch = pathname.match(LOADER_REGEX);
16
+ if (loaderMatch) return {
17
+ type: IsQLoader,
18
+ trimLength: loaderMatch[1].length + 1,
19
+ data: {
20
+ loaderId: loaderMatch[2],
21
+ manifestHash: loaderMatch[3]
22
+ }
23
+ };
24
+ return null;
25
25
  }
26
- function trimRecognizedInternalPathname(pathname, recognized) {
27
- let trimmed = pathname.slice(0, pathname.length - recognized.trimLength) || "/";
28
- if (!globalThis.__NO_TRAILING_SLASH__ && !trimmed.endsWith("/")) {
29
- trimmed = ensureSlash(trimmed);
30
- }
31
- return trimmed;
26
+ /** Trim a recognized internal URL suffix from a pathname, returning the clean route pathname. */ function trimRecognizedInternalPathname(pathname, recognized) {
27
+ let trimmed = pathname.slice(0, pathname.length - recognized.trimLength) || "/";
28
+ if (!globalThis.__NO_TRAILING_SLASH__ && !trimmed.endsWith("/")) trimmed = ensureSlash(trimmed);
29
+ return trimmed;
32
30
  }
33
- function trimInternalPathname(pathname) {
34
- const recognized = recognizeRequest(pathname);
35
- if (recognized) {
36
- return trimRecognizedInternalPathname(pathname, recognized);
37
- }
38
- return pathname;
31
+ /** Trim any recognized internal URL suffix from a pathname, returning the clean route pathname. */ function trimInternalPathname(pathname) {
32
+ const recognized = recognizeRequest(pathname);
33
+ if (recognized) return trimRecognizedInternalPathname(pathname, recognized);
34
+ return pathname;
39
35
  }
40
36
  function resolveValidInternalFullPathname(loaderPathname, fullPath) {
41
- if (!fullPath || !fullPath.startsWith("/") || fullPath.startsWith("//")) {
42
- return void 0;
43
- }
44
- try {
45
- const pageUrl = new URL(fullPath, "http://qwik.internal");
46
- if (pageUrl.origin !== "http://qwik.internal") {
47
- return void 0;
48
- }
49
- const pagePathname = pageUrl.pathname;
50
- if (pagePathname === loaderPathname) {
51
- return void 0;
52
- }
53
- const loaderPrefix = ensureSlash(loaderPathname);
54
- return pagePathname.startsWith(loaderPrefix) ? pagePathname : void 0;
55
- } catch {
56
- return void 0;
57
- }
37
+ if (!fullPath || !fullPath.startsWith("/") || fullPath.startsWith("//")) return;
38
+ try {
39
+ const pageUrl = new URL(fullPath, "http://qwik.internal");
40
+ if (pageUrl.origin !== "http://qwik.internal") return;
41
+ const pagePathname = pageUrl.pathname;
42
+ if (pagePathname === loaderPathname) return;
43
+ const loaderPrefix = ensureSlash(loaderPathname);
44
+ return pagePathname.startsWith(loaderPrefix) ? pagePathname : void 0;
45
+ } catch {
46
+ return;
47
+ }
58
48
  }
59
-
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 };
49
+ export { QLoaderId as a, resolveValidInternalFullPathname as c, QActionId as i, trimInternalPathname as l, IsQLoader as n, getLoaderName as o, LOADER_REGEX as r, recognizeRequest as s, IsQAction as t, trimRecognizedInternalPathname as u };
@@ -1,47 +1,26 @@
1
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);
2
+ let transformedRule;
3
+ if (rule === "/" || rule === "/*") transformedRule = rule;
4
+ else if (rule.endsWith("/*")) transformedRule = `${rule.substring(0, rule.length - 2)}(/*)?`;
5
+ else if (rule.endsWith("/")) transformedRule = `${rule.substring(0, rule.length - 1)}(/)?`;
6
+ else if (rule.endsWith("*")) transformedRule = rule;
7
+ else transformedRule = `${rule}(/)?`;
8
+ transformedRule = `^${transformedRule.replace(/\*/g, ".*")}$`;
9
+ return new RegExp(transformedRule);
16
10
  }
17
11
  function routesToRegExps(routes) {
18
- if (!Array.isArray(routes)) {
19
- return [];
20
- }
21
- return routes.filter((r) => typeof r === "string").map(routeToRegExp);
12
+ if (!Array.isArray(routes)) return [];
13
+ return routes.filter((r) => typeof r === "string").map(routeToRegExp);
22
14
  }
23
15
  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
- };
16
+ const includes = routesToRegExps(includeRoutes);
17
+ const excludes = routesToRegExps(excludeRoutes);
18
+ return (pathname) => {
19
+ if (basePathname !== "/") pathname = pathname.slice(basePathname.length - 1);
20
+ for (const exclude of excludes) if (exclude.test(pathname)) return false;
21
+ if (pathname.endsWith("/404.html")) return true;
22
+ for (const include of includes) if (include.test(pathname)) return true;
23
+ return false;
24
+ };
45
25
  }
46
-
47
- export { createRouteTester as c };
26
+ export { createRouteTester as t };
@@ -1,19 +1,16 @@
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
- }
1
+ /** @public */ var AbortMessage = class {};
2
+ /** @public */ var RedirectMessage = class extends AbortMessage {};
3
+ /** @public */ var ServerError = class extends Error {
4
+ status;
5
+ data;
6
+ constructor(status, data) {
7
+ super(typeof data === "string" ? data : void 0), this.status = status, this.data = data;
8
+ }
17
9
  };
18
-
19
- export { AbortMessage as A, RedirectMessage as R, ServerError as S, throwIfControlFlowSignal as t };
10
+ /**
11
+ * `ev.redirect()`, `ev.error()`, etc. return a control-flow signal meant to be thrown. Throw it for
12
+ * the user when they return it instead, so returning and throwing behave the same.
13
+ */ var throwIfControlFlowSignal = (value) => {
14
+ if (value instanceof AbortMessage || value instanceof ServerError) throw value;
15
+ };
16
+ export { RedirectMessage as i, throwIfControlFlowSignal as n, AbortMessage as r, ServerError as t };