@webjsdev/core 0.7.14 → 0.7.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjsdev/core",
3
- "version": "0.7.14",
3
+ "version": "0.7.15",
4
4
  "type": "module",
5
5
  "description": "webjs core runtime - html/css tags, WebComponent base, isomorphic renderers",
6
6
  "types": "./index.d.ts",
@@ -75,7 +75,7 @@
75
75
  "prepare": "node -e \"require('fs').existsSync('../../scripts/build-framework-dist.js') && require('fs').existsSync('./src/html.js') && require('child_process').execSync('npm run build:dist', {stdio:'inherit'})\""
76
76
  },
77
77
  "devDependencies": {
78
- "esbuild": "^0.24.0"
78
+ "esbuild": "^0.25.0"
79
79
  },
80
80
  "publishConfig": {
81
81
  "access": "public"
package/src/nav.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export function notFound(): never;
2
- export function redirect(url: string, status?: number): never;
2
+ export function redirect(url: string, status?: number | { status?: number }): never;
3
3
  export function isNotFound(e: unknown): boolean;
4
4
  export function isRedirect(e: unknown): boolean;
package/src/nav.js CHANGED
@@ -22,15 +22,34 @@ export function notFound() {
22
22
  }
23
23
 
24
24
  /**
25
+ * Throw a redirect sentinel the SSR pipeline catches and turns into a 3xx.
26
+ *
27
+ * The status is OPTIONAL and, when omitted, is chosen by the catching site so
28
+ * each kind of redirect gets the conventional code:
29
+ * - thrown during a GET page/layout render (a gating redirect like an auth
30
+ * bounce to `/login`): 302 Found, the conventional GET-to-GET code.
31
+ * - thrown from a server action (a POST): 307 Temporary Redirect, which is
32
+ * method-preserving so the action's intent survives. (The PRG success
33
+ * path uses 303 separately.)
34
+ * Pass an explicit status to override: `redirect('/x', 308)` (permanent) or the
35
+ * options form `redirect('/x', { status: 301 })`. An explicit status wins at
36
+ * every catching site.
37
+ *
25
38
  * @param {string} url
26
- * @param {number} [status] 307 (temp) by default; pass 308 for permanent
39
+ * @param {number | { status?: number }} [status] explicit status (number) or
40
+ * `{ status }`; omit to let the catching site pick (302 for a GET gate, 307
41
+ * for an action).
27
42
  * @returns {never}
28
43
  */
29
- export function redirect(url, status = 307) {
44
+ export function redirect(url, status) {
45
+ const code = typeof status === 'object' && status !== null ? status.status : status;
30
46
  const err = new Error(`webjs: redirect(${url})`);
31
47
  /** @type any */ (err).__webjs = REDIRECT;
32
48
  /** @type any */ (err).url = url;
33
- /** @type any */ (err).status = status;
49
+ // Left undefined when the caller did not specify one, so the catching site
50
+ // can apply its convention (302 GET gate vs 307 action). A caller-supplied
51
+ // code is stored verbatim and overrides that convention.
52
+ /** @type any */ (err).status = typeof code === 'number' ? code : undefined;
34
53
  throw err;
35
54
  }
36
55