@qwik.dev/router 2.0.0-beta.35 → 2.0.0-beta.37
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 -4
- package/lib/adapters/shared/vite/index.mjs +26 -23
- package/lib/chunks/action-handler.mjs +782 -0
- package/lib/chunks/deepFreeze.qwik.mjs +591 -1
- package/lib/chunks/format.mjs +31 -0
- package/lib/chunks/fs.mjs +4 -6
- package/lib/chunks/{routing.qwik.mjs → head.qwik.mjs} +299 -416
- package/lib/chunks/http-error.qwik.mjs +2 -2
- package/lib/chunks/not-found-wrapper.qwik.mjs +2 -2
- package/lib/chunks/pathname.mjs +3 -32
- package/lib/chunks/request-path.mjs +60 -0
- package/lib/chunks/system.mjs +6 -7
- package/lib/chunks/use-functions.qwik.mjs +3 -15
- package/lib/chunks/worker-thread.qwik.mjs +436 -425
- package/lib/index.d.ts +180 -13
- package/lib/index.qwik.mjs +640 -447
- package/lib/middleware/aws-lambda/index.mjs +2 -1
- package/lib/middleware/request-handler/index.d.ts +56 -16
- package/lib/middleware/request-handler/index.mjs +198 -754
- package/lib/ssg/index.d.ts +3 -3
- package/lib/ssg/index.mjs +4 -3
- package/lib/vite/index.d.ts +15 -0
- package/lib/vite/index.mjs +145 -23
- package/package.json +3 -3
- package/lib/chunks/redirect-handler.mjs +0 -6
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { componentQrl, inlinedQrl, _jsxSorted, _fnSignal } from '@qwik.dev/core';
|
|
2
|
-
import {
|
|
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 = (
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as useHttpStatus } from './use-functions.qwik.mjs';
|
|
2
2
|
|
|
3
3
|
function createNotFoundWrapper(notFoundMod, errorMod) {
|
|
4
4
|
const NotFound = notFoundMod.default;
|
|
@@ -18,7 +18,7 @@ function createNotFoundWrapper(notFoundMod, errorMod) {
|
|
|
18
18
|
return {
|
|
19
19
|
default: Component,
|
|
20
20
|
head: notFoundHead ?? errorHead,
|
|
21
|
-
cacheKey: (
|
|
21
|
+
cacheKey: (requestEv) => String(requestEv.status())
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
package/lib/chunks/pathname.mjs
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
|
|
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 {
|
|
76
|
+
export { ensureSlash as e, getPathnameForDynamicRoute as g, isSameOriginUrl as i, normalizePathname as n };
|
|
@@ -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, QActionId as a, IsQAction as b, resolveValidInternalFullPathname as c, trimInternalPathname as d, getLoaderName as g, recognizeRequest as r, trimRecognizedInternalPathname as t };
|
package/lib/chunks/system.mjs
CHANGED
|
@@ -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) {
|
|
@@ -301,13 +303,10 @@ async function createSystem(opts, threadId) {
|
|
|
301
303
|
}
|
|
302
304
|
return join(outDir, pathname);
|
|
303
305
|
};
|
|
304
|
-
const
|
|
306
|
+
const getLoaderFilePath = (pathname, loaderId, manifestHash) => {
|
|
305
307
|
pathname = decodeURIComponent(pathname.slice(basenameLen));
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
} else {
|
|
309
|
-
pathname += "/q-data.json";
|
|
310
|
-
}
|
|
308
|
+
const suffix = getLoaderName(loaderId, manifestHash);
|
|
309
|
+
pathname = ensureSlash(pathname) + suffix;
|
|
311
310
|
return join(outDir, pathname);
|
|
312
311
|
};
|
|
313
312
|
const sys = {
|
|
@@ -319,7 +318,7 @@ async function createSystem(opts, threadId) {
|
|
|
319
318
|
createTimer,
|
|
320
319
|
access,
|
|
321
320
|
getRouteFilePath,
|
|
322
|
-
|
|
321
|
+
getLoaderFilePath,
|
|
323
322
|
getEnv: (key) => process.env[key],
|
|
324
323
|
platform: {
|
|
325
324
|
static: true,
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {
|
|
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, R as RouteLocationContext, b as RouteNavigateContext, h as RoutePreventNavigateContext, g as RouteActionContext } from './deepFreeze.qwik.mjs';
|
|
12
3
|
|
|
13
4
|
const useHttpStatus = () => useContext(HttpStatusContext).value;
|
|
14
5
|
const useContent = () => useContext(ContentContext);
|
|
@@ -16,9 +7,6 @@ const useDocumentHead = () => useContext(DocumentHeadContext);
|
|
|
16
7
|
const useLocation = () => useContext(RouteLocationContext);
|
|
17
8
|
const useNavigate = () => useContext(RouteNavigateContext);
|
|
18
9
|
const usePreventNavigateQrl = (fn) => {
|
|
19
|
-
if (!__EXPERIMENTAL__.preventNavigate) {
|
|
20
|
-
throw new Error('usePreventNavigate$ is experimental and must be enabled with `experimental: ["preventNavigate"]` in the `qwikVite` plugin.');
|
|
21
|
-
}
|
|
22
10
|
const registerPreventNav = useContext(RoutePreventNavigateContext);
|
|
23
11
|
useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(() => {
|
|
24
12
|
const fn2 = _captures[0], registerPreventNav2 = _captures[1];
|
|
@@ -32,4 +20,4 @@ const usePreventNavigate$ = implicit$FirstArg(usePreventNavigateQrl);
|
|
|
32
20
|
const useAction = () => useContext(RouteActionContext);
|
|
33
21
|
const useQwikRouterEnv = () => noSerialize(useServerData("qwikrouter"));
|
|
34
22
|
|
|
35
|
-
export {
|
|
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 };
|