@txco/web-abi 0.2.0 → 0.2.1
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/dist/producer.d.ts +8 -0
- package/dist/producer.js +13 -3
- package/package.json +1 -1
- package/src/producer.ts +14 -4
package/dist/producer.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/** Where the catch-all sits: after the navigation op, since ops in one scope run concurrently. */
|
|
2
2
|
export declare const catchAllScope: (scope: number) => number;
|
|
3
|
+
/** An HTTP GET or HEAD: what a navigation is made of. */
|
|
4
|
+
export declare const METHOD_GUARD = "@src == \"http\" && (@web.req.method == \"GET\" || @web.req.method == \"HEAD\")";
|
|
3
5
|
/**
|
|
4
6
|
* A navigation: an HTTP GET or HEAD of a path whose last segment has no
|
|
5
7
|
* extension. Everything else (an asset miss, a POST) is the catch-all's.
|
|
8
|
+
*
|
|
9
|
+
* A producer with a route table ("routes" mode) trusts the table instead for
|
|
10
|
+
* its 200: a path a page route knows is a page whatever dots it carries (a
|
|
11
|
+
* param may hold one — /p/mister.parade), so that op opens with METHOD_GUARD
|
|
12
|
+
* alone; its 404 op and every producer without a table keep this guard, so
|
|
13
|
+
* an asset miss is still the catch-all's plain 404.
|
|
6
14
|
*/
|
|
7
15
|
export declare const NAV_GUARD: string;
|
|
8
16
|
/** The page a 404 op serves when the build has no 404.html. */
|
package/dist/producer.js
CHANGED
|
@@ -8,12 +8,19 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
|
8
8
|
import { MANIFEST_NAME, PRODUCER_SCOPE, validateManifest } from "./manifest.js";
|
|
9
9
|
/** Where the catch-all sits: after the navigation op, since ops in one scope run concurrently. */
|
|
10
10
|
export const catchAllScope = (scope) => scope + 900;
|
|
11
|
+
/** An HTTP GET or HEAD: what a navigation is made of. */
|
|
12
|
+
export const METHOD_GUARD = '@src == "http" && (@web.req.method == "GET" || @web.req.method == "HEAD")';
|
|
11
13
|
/**
|
|
12
14
|
* A navigation: an HTTP GET or HEAD of a path whose last segment has no
|
|
13
15
|
* extension. Everything else (an asset miss, a POST) is the catch-all's.
|
|
16
|
+
*
|
|
17
|
+
* A producer with a route table ("routes" mode) trusts the table instead for
|
|
18
|
+
* its 200: a path a page route knows is a page whatever dots it carries (a
|
|
19
|
+
* param may hold one — /p/mister.parade), so that op opens with METHOD_GUARD
|
|
20
|
+
* alone; its 404 op and every producer without a table keep this guard, so
|
|
21
|
+
* an asset miss is still the catch-all's plain 404.
|
|
14
22
|
*/
|
|
15
|
-
export const NAV_GUARD =
|
|
16
|
-
" && @web.req.url.path !~ /(?i)\\.[a-z0-9]+$/";
|
|
23
|
+
export const NAV_GUARD = METHOD_GUARD + "\n" + " && @web.req.url.path !~ /(?i)\\.[a-z0-9]+$/";
|
|
17
24
|
/** The page a 404 op serves when the build has no 404.html. */
|
|
18
25
|
export const BUILTIN_404 = '<!doctype html>\n<html lang="en"><head><meta charset="utf-8"><title>404 Not Found</title></head>' +
|
|
19
26
|
"<body><h1>404 Not Found</h1></body></html>\n";
|
|
@@ -36,8 +43,11 @@ export function renderOps(o) {
|
|
|
36
43
|
#
|
|
37
44
|
# Serves the app shell (${o.page.name}) with 200 for a navigation to a known
|
|
38
45
|
# page route that no file or earlier op answered. Paired with spa-404.txcl.
|
|
46
|
+
# The route table decides what a page is: a path it knows is one whatever
|
|
47
|
+
# dots it carries (a param may hold one), so this op has no extension guard;
|
|
48
|
+
# spa-404 and the catch-all keep it, and an asset miss is still a plain 404.
|
|
39
49
|
${extra}# Regenerated on every build — the shell embeds content-hashed asset URLs.
|
|
40
|
-
WHEN ${
|
|
50
|
+
WHEN ${METHOD_GUARD}
|
|
41
51
|
&& @web.req.url.path =~ /${o.routes}/
|
|
42
52
|
${emitPage(200, o.page.html)}`;
|
|
43
53
|
out[`${scope}/spa-404.txcl`] = `# ${o.producer} — SPA 404 (generated; do not edit by hand).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txco/web-abi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The TxCo Web ABI kit: the txco-web.json schema and validator, the envelope ↔ Fetch bridge every runner uses, a harness that checks a build's server/ Fetch handler, and the ops and manifest writer producers share.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/producer.ts
CHANGED
|
@@ -11,13 +11,20 @@ import { MANIFEST_NAME, PRODUCER_SCOPE, validateManifest } from "./manifest.js";
|
|
|
11
11
|
/** Where the catch-all sits: after the navigation op, since ops in one scope run concurrently. */
|
|
12
12
|
export const catchAllScope = (scope: number): number => scope + 900;
|
|
13
13
|
|
|
14
|
+
/** An HTTP GET or HEAD: what a navigation is made of. */
|
|
15
|
+
export const METHOD_GUARD = '@src == "http" && (@web.req.method == "GET" || @web.req.method == "HEAD")';
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* A navigation: an HTTP GET or HEAD of a path whose last segment has no
|
|
16
19
|
* extension. Everything else (an asset miss, a POST) is the catch-all's.
|
|
20
|
+
*
|
|
21
|
+
* A producer with a route table ("routes" mode) trusts the table instead for
|
|
22
|
+
* its 200: a path a page route knows is a page whatever dots it carries (a
|
|
23
|
+
* param may hold one — /p/mister.parade), so that op opens with METHOD_GUARD
|
|
24
|
+
* alone; its 404 op and every producer without a table keep this guard, so
|
|
25
|
+
* an asset miss is still the catch-all's plain 404.
|
|
17
26
|
*/
|
|
18
|
-
export const NAV_GUARD =
|
|
19
|
-
'@src == "http" && (@web.req.method == "GET" || @web.req.method == "HEAD")\n' +
|
|
20
|
-
" && @web.req.url.path !~ /(?i)\\.[a-z0-9]+$/";
|
|
27
|
+
export const NAV_GUARD = METHOD_GUARD + "\n" + " && @web.req.url.path !~ /(?i)\\.[a-z0-9]+$/";
|
|
21
28
|
|
|
22
29
|
/** The page a 404 op serves when the build has no 404.html. */
|
|
23
30
|
export const BUILTIN_404 =
|
|
@@ -80,8 +87,11 @@ export function renderOps(o: RenderOptions): Record<string, string> {
|
|
|
80
87
|
#
|
|
81
88
|
# Serves the app shell (${o.page.name}) with 200 for a navigation to a known
|
|
82
89
|
# page route that no file or earlier op answered. Paired with spa-404.txcl.
|
|
90
|
+
# The route table decides what a page is: a path it knows is one whatever
|
|
91
|
+
# dots it carries (a param may hold one), so this op has no extension guard;
|
|
92
|
+
# spa-404 and the catch-all keep it, and an asset miss is still a plain 404.
|
|
83
93
|
${extra}# Regenerated on every build — the shell embeds content-hashed asset URLs.
|
|
84
|
-
WHEN ${
|
|
94
|
+
WHEN ${METHOD_GUARD}
|
|
85
95
|
&& @web.req.url.path =~ /${o.routes}/
|
|
86
96
|
${emitPage(200, o.page.html)}`;
|
|
87
97
|
out[`${scope}/spa-404.txcl`] = `# ${o.producer} — SPA 404 (generated; do not edit by hand).
|