@qwik.dev/router 2.0.0-beta.36 → 2.0.0-beta.38

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 (41) hide show
  1. package/lib/adapters/cloudflare-pages/vite/index.mjs +3 -5
  2. package/lib/adapters/shared/vite/index.d.ts +3 -4
  3. package/lib/adapters/shared/vite/index.mjs +167 -155
  4. package/lib/chunks/dev-preloaded-route-loader.mjs +3 -0
  5. package/lib/chunks/format.mjs +31 -0
  6. package/lib/chunks/fs.mjs +10 -8
  7. package/lib/chunks/head.qwik.mjs +1425 -0
  8. package/lib/chunks/http-error.qwik.mjs +2 -2
  9. package/lib/chunks/pathname.mjs +3 -32
  10. package/lib/chunks/request-body-limit.mjs +37 -0
  11. package/lib/chunks/request-path.mjs +60 -0
  12. package/lib/chunks/routes.mjs +47 -0
  13. package/lib/chunks/server-error.mjs +19 -0
  14. package/lib/chunks/system.mjs +8 -8
  15. package/lib/chunks/use-functions.qwik.mjs +3 -12
  16. package/lib/chunks/user-response.mjs +1875 -0
  17. package/lib/chunks/worker-thread.mjs +317 -0
  18. package/lib/index.d.ts +251 -44
  19. package/lib/index.qwik.mjs +734 -485
  20. package/lib/middleware/aws-lambda/index.mjs +2 -1
  21. package/lib/middleware/azure-swa/index.mjs +13 -9
  22. package/lib/middleware/cloudflare-pages/index.mjs +2 -2
  23. package/lib/middleware/deno/index.d.ts +2 -0
  24. package/lib/middleware/deno/index.mjs +2 -1
  25. package/lib/middleware/netlify-edge/index.mjs +2 -2
  26. package/lib/middleware/node/index.d.ts +9 -1
  27. package/lib/middleware/node/index.mjs +28 -3
  28. package/lib/middleware/request-handler/index.d.ts +65 -26
  29. package/lib/middleware/request-handler/index.mjs +38 -1679
  30. package/lib/middleware/vercel-edge/index.mjs +2 -2
  31. package/lib/ssg/index.d.ts +5 -13
  32. package/lib/ssg/index.mjs +14 -53
  33. package/lib/vite/index.d.ts +23 -0
  34. package/lib/vite/index.mjs +533 -122
  35. package/package.json +4 -3
  36. package/lib/chunks/deepFreeze.qwik.mjs +0 -18
  37. package/lib/chunks/error-handler.mjs +0 -57
  38. package/lib/chunks/not-found-wrapper.qwik.mjs +0 -25
  39. package/lib/chunks/redirect-handler.mjs +0 -6
  40. package/lib/chunks/routing.qwik.mjs +0 -821
  41. package/lib/chunks/worker-thread.qwik.mjs +0 -2585
@@ -1,11 +1,11 @@
1
1
  import { componentQrl, inlinedQrl, _jsxSorted, _fnSignal } from '@qwik.dev/core';
2
- import { k as useHttpStatus } from './use-functions.qwik.mjs';
2
+ import { f as useHttpStatus } from './use-functions.qwik.mjs';
3
3
 
4
4
  const _hf0 = (p0) => p0.status || 500;
5
5
  const _hf0_str = "p0.status||500";
6
6
  const _hf1 = (p0) => p0.message || "";
7
7
  const _hf1_str = 'p0.message||""';
8
- const cacheKey = (status) => String(status);
8
+ const cacheKey = (ev) => String(ev.status);
9
9
  const COLOR_400 = "#006ce9";
10
10
  const COLOR_500 = "#713fc2";
11
11
  const DisplayHttpStatus = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
@@ -1,33 +1,4 @@
1
- function toTitleCase(str) {
2
- return str.replace(/\w\S*/g, (txt) => {
3
- return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
4
- });
5
- }
6
- function addError(ctx, e) {
7
- ctx.diagnostics.push({
8
- type: "error",
9
- message: e ? String(e.stack || e) : "Error"
10
- });
11
- }
12
- function addWarning(ctx, message) {
13
- ctx.diagnostics.push({
14
- type: "warn",
15
- message: String(message)
16
- });
17
- }
18
- function msToString(ms) {
19
- if (ms < 1) {
20
- return ms.toFixed(2) + " ms";
21
- }
22
- if (ms < 1e3) {
23
- return ms.toFixed(1) + " ms";
24
- }
25
- if (ms < 6e4) {
26
- return (ms / 1e3).toFixed(1) + " s";
27
- }
28
- return (ms / 6e4).toFixed(1) + " m";
29
- }
30
-
1
+ const ensureSlash = (pathname) => pathname.endsWith("/") ? pathname : pathname + "/";
31
2
  function normalizePathname(pathname, basePathname) {
32
3
  if (typeof pathname === "string") {
33
4
  pathname = pathname.trim();
@@ -44,7 +15,7 @@ function normalizePathname(pathname, basePathname) {
44
15
  const segments = pathname.split("/");
45
16
  const lastSegment = segments[segments.length - 1];
46
17
  if (!lastSegment.includes(".")) {
47
- pathname += "/";
18
+ pathname = ensureSlash(pathname);
48
19
  }
49
20
  }
50
21
  } else {
@@ -102,4 +73,4 @@ function isSameOriginUrl(url) {
102
73
  return false;
103
74
  }
104
75
 
105
- export { addError as a, addWarning as b, getPathnameForDynamicRoute as g, isSameOriginUrl as i, msToString as m, normalizePathname as n, toTitleCase as t };
76
+ export { ensureSlash as e, getPathnameForDynamicRoute as g, isSameOriginUrl as i, normalizePathname as n };
@@ -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 };
@@ -0,0 +1,60 @@
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;
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;
32
+ }
33
+ function trimInternalPathname(pathname) {
34
+ const recognized = recognizeRequest(pathname);
35
+ if (recognized) {
36
+ return trimRecognizedInternalPathname(pathname, recognized);
37
+ }
38
+ return pathname;
39
+ }
40
+ 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
+ }
58
+ }
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 };
@@ -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 };
@@ -3,6 +3,8 @@ import { isAbsolute, resolve, join, dirname } from 'node:path';
3
3
  import { cpus } from 'node:os';
4
4
  import { Worker } from 'node:worker_threads';
5
5
  import { k as normalizePath } from './fs.mjs';
6
+ import { g as getLoaderName } from './request-path.mjs';
7
+ import { e as ensureSlash } from './pathname.mjs';
6
8
 
7
9
  function ssgWorkerCompare(a, b) {
8
10
  if (a.activeTasks < b.activeTasks) {
@@ -165,7 +167,8 @@ async function createWorkerPool(sys, opts) {
165
167
  const render = async (ssgRoute) => {
166
168
  const ssgWorker = getNextWorker();
167
169
  const result = await ssgWorker.render(ssgRoute);
168
- if (sitemapOutFile && result.ok && result.resourceType === "page") {
170
+ const isNotFoundPage = result.pathname.endsWith("/404.html");
171
+ if (sitemapOutFile && result.ok && result.resourceType === "page" && !isNotFoundPage) {
169
172
  sitemapBuffer.push(`<url><loc>${result.url}</loc></url>`);
170
173
  if (sitemapBuffer.length > 50) {
171
174
  const siteMapUrls = sitemapBuffer.join("\n") + "\n";
@@ -301,13 +304,10 @@ async function createSystem(opts, threadId) {
301
304
  }
302
305
  return join(outDir, pathname);
303
306
  };
304
- const getDataFilePath = (pathname) => {
307
+ const getLoaderFilePath = (pathname, loaderId, manifestHash) => {
305
308
  pathname = decodeURIComponent(pathname.slice(basenameLen));
306
- if (pathname.endsWith("/")) {
307
- pathname += "q-data.json";
308
- } else {
309
- pathname += "/q-data.json";
310
- }
309
+ const suffix = getLoaderName(loaderId, manifestHash);
310
+ pathname = ensureSlash(pathname) + suffix;
311
311
  return join(outDir, pathname);
312
312
  };
313
313
  const sys = {
@@ -319,7 +319,7 @@ async function createSystem(opts, threadId) {
319
319
  createTimer,
320
320
  access,
321
321
  getRouteFilePath,
322
- getDataFilePath,
322
+ getLoaderFilePath,
323
323
  getEnv: (key) => process.env[key],
324
324
  platform: {
325
325
  static: true,
@@ -1,14 +1,5 @@
1
- import { createContextId, useContext, implicit$FirstArg, useVisibleTaskQrl, inlinedQrl, _captures, noSerialize, useServerData } from '@qwik.dev/core';
2
-
3
- const RouteStateContext = /* @__PURE__ */ createContextId("qr-s");
4
- const ContentContext = /* @__PURE__ */ createContextId("qr-c");
5
- const ContentInternalContext = /* @__PURE__ */ createContextId("qr-ic");
6
- const DocumentHeadContext = /* @__PURE__ */ createContextId("qr-h");
7
- const RouteLocationContext = /* @__PURE__ */ createContextId("qr-l");
8
- const RouteNavigateContext = /* @__PURE__ */ createContextId("qr-n");
9
- const RouteActionContext = /* @__PURE__ */ createContextId("qr-a");
10
- const RoutePreventNavigateContext = /* @__PURE__ */ createContextId("qr-p");
11
- const HttpStatusContext = /* @__PURE__ */ createContextId("qr-hs");
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, h as RouteLocationContext, j as RouteNavigateContext, o as RoutePreventNavigateContext, n as RouteActionContext } from './head.qwik.mjs';
12
3
 
13
4
  const useHttpStatus = () => useContext(HttpStatusContext).value;
14
5
  const useContent = () => useContext(ContentContext);
@@ -29,4 +20,4 @@ const usePreventNavigate$ = implicit$FirstArg(usePreventNavigateQrl);
29
20
  const useAction = () => useContext(RouteActionContext);
30
21
  const useQwikRouterEnv = () => noSerialize(useServerData("qwikrouter"));
31
22
 
32
- export { ContentContext as C, DocumentHeadContext as D, HttpStatusContext as H, RouteLocationContext as R, useLocation as a, useQwikRouterEnv as b, ContentInternalContext as c, RouteNavigateContext as d, RouteStateContext as e, RouteActionContext as f, RoutePreventNavigateContext as g, useAction as h, useDocumentHead as i, useContent as j, useHttpStatus as k, usePreventNavigate$ as l, usePreventNavigateQrl as m, useNavigate as u };
23
+ export { useLocation as a, useDocumentHead as b, useQwikRouterEnv as c, useAction as d, useContent as e, useHttpStatus as f, usePreventNavigate$ as g, usePreventNavigateQrl as h, useNavigate as u };