@openelement/protocol 0.41.0-beta.3 → 1.0.0-alpha.11
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/LICENSE +21 -0
- package/README.md +42 -0
- package/package.json +90 -51
- package/src/app-model.d.ts +19 -0
- package/src/app-model.js +1 -0
- package/src/client-assets.d.ts +44 -0
- package/src/client-assets.js +24 -0
- package/src/data.d.ts +81 -11
- package/src/data.js +11 -7
- package/src/errors.d.ts +253 -14
- package/src/errors.js +275 -15
- package/src/forbidden-sinks.d.ts +60 -0
- package/src/forbidden-sinks.js +81 -0
- package/src/framework.d.ts +183 -99
- package/src/framework.js +13 -5
- package/src/index.d.ts +21 -19
- package/src/index.js +21 -20
- package/src/island-admission.d.ts +5 -0
- package/src/island-admission.js +9 -0
- package/src/island.d.ts +32 -19
- package/src/island.js +1 -4
- package/src/manifest.d.ts +15 -27
- package/src/manifest.js +1 -4
- package/src/module-descriptors.d.ts +40 -0
- package/src/module-descriptors.js +1 -0
- package/src/module-vocabulary.d.ts +5 -0
- package/src/module-vocabulary.js +21 -0
- package/src/part-program.d.ts +407 -0
- package/src/part-program.js +758 -0
- package/src/policy.d.ts +64 -0
- package/src/policy.js +65 -0
- package/src/registry-markers.d.ts +39 -0
- package/src/registry-markers.js +40 -0
- package/src/render.d.ts +29 -123
- package/src/render.js +1 -7
- package/src/runtime.d.ts +13 -4
- package/src/runtime.js +1 -8
- package/src/signal.d.ts +31 -7
- package/src/signal.js +5 -6
- package/src/ssg.d.ts +317 -151
- package/src/ssg.js +1 -7
- package/src/stream-frame-policy.d.ts +49 -0
- package/src/stream-frame-policy.js +108 -0
- package/src/style-sheet.d.ts +5 -1
- package/src/style-sheet.js +1 -8
- package/src/void-tags.d.ts +18 -0
- package/src/void-tags.js +34 -0
- package/src/context.d.ts +0 -25
- package/src/context.js +0 -7
- package/src/hydration-markers.d.ts +0 -25
- package/src/hydration-markers.js +0 -26
- package/src/isr.d.ts +0 -30
- package/src/isr.js +0 -4
- package/src/prop.d.ts +0 -46
- package/src/prop.js +0 -6
- package/src/vnode.d.ts +0 -19
- package/src/vnode.js +0 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openelement author
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @openelement/protocol
|
|
2
|
+
|
|
3
|
+
Cross-system contracts and tiny pure predicates for the OpenElement framework:
|
|
4
|
+
the Part Program IR, the error dialect, admission descriptors, and policy
|
|
5
|
+
constants. Zero dependencies by charter — every module here is importable from
|
|
6
|
+
the compiler, the runtime, and the build adapters without dragging any of them
|
|
7
|
+
into the others' graphs.
|
|
8
|
+
|
|
9
|
+
## Subpaths
|
|
10
|
+
|
|
11
|
+
| Subpath | Import it for |
|
|
12
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `@openelement/protocol` | The umbrella re-export of every contract below. |
|
|
14
|
+
| `@openelement/protocol/app-model` | Host-agnostic route and asset contracts shared by app and build drivers (the route tree node, matched-path shapes). |
|
|
15
|
+
| `@openelement/protocol/client-assets` | The client asset manifest protocol (#1471): compile-time island identity joined with build output for per-page script wiring. |
|
|
16
|
+
| `@openelement/protocol/data` | The platform-neutral data adapter protocol. |
|
|
17
|
+
| `@openelement/protocol/errors` | The single declaration site of the error contract (#1386): coded error classes, phase catalogs (`RuntimeErrorCode`, `KernelErrorCode`, ...). |
|
|
18
|
+
| `@openelement/protocol/forbidden-sinks`| The one canonical deny list for every Part Program boundary (compiler, validator, server): sink names that fail closed. |
|
|
19
|
+
| `@openelement/protocol/framework` | Framework, build, app-shell, routing, and plugin metadata contracts. |
|
|
20
|
+
| `@openelement/protocol/island` | Island contracts (`IslandOptions`, hydration options). |
|
|
21
|
+
| `@openelement/protocol/island-admission` | The single definition of the router's island admission descriptor. |
|
|
22
|
+
| `@openelement/protocol/manifest` | CEM manifest and compatibility contract types. |
|
|
23
|
+
| `@openelement/protocol/module-descriptors` | Binding-identity module descriptors shared by the compiler's semantic core and its hosts (#1557 package split). |
|
|
24
|
+
| `@openelement/protocol/module-vocabulary` | The router's module-scan vocabulary injected into the element semantic core. |
|
|
25
|
+
| `@openelement/protocol/part-program` | Serializable Part Program v1: the compiled element's exchange artifact (template, parts, regions, locations, source map, metadata) + validator. |
|
|
26
|
+
| `@openelement/protocol/policy` | Numeric build/runtime admission budgets (stream bounds, composition depth, action body limit, timeouts). |
|
|
27
|
+
| `@openelement/protocol/registry-markers` | SSR customElements registry marker contract (#965). |
|
|
28
|
+
| `@openelement/protocol/render` | Render pipeline types (`RenderOutput`, SSR admission decisions). |
|
|
29
|
+
| `@openelement/protocol/runtime` | Runtime adapter protocol. |
|
|
30
|
+
| `@openelement/protocol/signal` | Signal contracts (`Signal`, `ReadonlySignal`, brands). |
|
|
31
|
+
| `@openelement/protocol/ssg` | SSG engine contracts (route manifests, island declarations, stream route manifests). |
|
|
32
|
+
| `@openelement/protocol/stream-frame-policy` | The canonical deny lists a deferred text/Region Part frame must satisfy for the browser installer to accept it. |
|
|
33
|
+
| `@openelement/protocol/style-sheet` | The cross-environment `StyleSheet` abstraction contract. |
|
|
34
|
+
| `@openelement/protocol/void-tags` | The one canonical HTML void-element set for every serializer, validator, and compiler (#1220). |
|
|
35
|
+
|
|
36
|
+
## Boundary
|
|
37
|
+
|
|
38
|
+
Everything here is declarative or a pure predicate: no DOM, no Node APIs, no
|
|
39
|
+
I/O. Modules at this layer sit at the base of the module graph so the compiler
|
|
40
|
+
(`@openelement/compiler`), the runtime (`@openelement/element`), and the build
|
|
41
|
+
adapters (`@openelement/router`) can share one definition without importing
|
|
42
|
+
each other.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openelement/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -10,92 +10,131 @@
|
|
|
10
10
|
"import": "./src/index.js",
|
|
11
11
|
"default": "./src/index.js"
|
|
12
12
|
},
|
|
13
|
-
"./
|
|
14
|
-
"types": "./src/
|
|
15
|
-
"import": "./src/
|
|
16
|
-
"default": "./src/
|
|
13
|
+
"./app-model": {
|
|
14
|
+
"types": "./src/app-model.d.ts",
|
|
15
|
+
"import": "./src/app-model.js",
|
|
16
|
+
"default": "./src/app-model.js"
|
|
17
17
|
},
|
|
18
|
-
"./
|
|
19
|
-
"types": "./src/
|
|
20
|
-
"import": "./src/
|
|
21
|
-
"default": "./src/
|
|
18
|
+
"./client-assets": {
|
|
19
|
+
"types": "./src/client-assets.d.ts",
|
|
20
|
+
"import": "./src/client-assets.js",
|
|
21
|
+
"default": "./src/client-assets.js"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./src/
|
|
25
|
-
"import": "./src/
|
|
26
|
-
"default": "./src/
|
|
23
|
+
"./data": {
|
|
24
|
+
"types": "./src/data.d.ts",
|
|
25
|
+
"import": "./src/data.js",
|
|
26
|
+
"default": "./src/data.js"
|
|
27
27
|
},
|
|
28
|
-
"./
|
|
29
|
-
"types": "./src/
|
|
30
|
-
"import": "./src/
|
|
31
|
-
"default": "./src/
|
|
28
|
+
"./errors": {
|
|
29
|
+
"types": "./src/errors.d.ts",
|
|
30
|
+
"import": "./src/errors.js",
|
|
31
|
+
"default": "./src/errors.js"
|
|
32
|
+
},
|
|
33
|
+
"./forbidden-sinks": {
|
|
34
|
+
"types": "./src/forbidden-sinks.d.ts",
|
|
35
|
+
"import": "./src/forbidden-sinks.js",
|
|
36
|
+
"default": "./src/forbidden-sinks.js"
|
|
32
37
|
},
|
|
33
38
|
"./framework": {
|
|
34
39
|
"types": "./src/framework.d.ts",
|
|
35
40
|
"import": "./src/framework.js",
|
|
36
41
|
"default": "./src/framework.js"
|
|
37
42
|
},
|
|
38
|
-
"./
|
|
39
|
-
"types": "./src/
|
|
40
|
-
"import": "./src/
|
|
41
|
-
"default": "./src/
|
|
43
|
+
"./island": {
|
|
44
|
+
"types": "./src/island.d.ts",
|
|
45
|
+
"import": "./src/island.js",
|
|
46
|
+
"default": "./src/island.js"
|
|
47
|
+
},
|
|
48
|
+
"./island-admission": {
|
|
49
|
+
"types": "./src/island-admission.d.ts",
|
|
50
|
+
"import": "./src/island-admission.js",
|
|
51
|
+
"default": "./src/island-admission.js"
|
|
52
|
+
},
|
|
53
|
+
"./manifest": {
|
|
54
|
+
"types": "./src/manifest.d.ts",
|
|
55
|
+
"import": "./src/manifest.js",
|
|
56
|
+
"default": "./src/manifest.js"
|
|
57
|
+
},
|
|
58
|
+
"./module-descriptors": {
|
|
59
|
+
"types": "./src/module-descriptors.d.ts",
|
|
60
|
+
"import": "./src/module-descriptors.js",
|
|
61
|
+
"default": "./src/module-descriptors.js"
|
|
62
|
+
},
|
|
63
|
+
"./module-vocabulary": {
|
|
64
|
+
"types": "./src/module-vocabulary.d.ts",
|
|
65
|
+
"import": "./src/module-vocabulary.js",
|
|
66
|
+
"default": "./src/module-vocabulary.js"
|
|
67
|
+
},
|
|
68
|
+
"./part-program": {
|
|
69
|
+
"types": "./src/part-program.d.ts",
|
|
70
|
+
"import": "./src/part-program.js",
|
|
71
|
+
"default": "./src/part-program.js"
|
|
72
|
+
},
|
|
73
|
+
"./policy": {
|
|
74
|
+
"types": "./src/policy.d.ts",
|
|
75
|
+
"import": "./src/policy.js",
|
|
76
|
+
"default": "./src/policy.js"
|
|
77
|
+
},
|
|
78
|
+
"./registry-markers": {
|
|
79
|
+
"types": "./src/registry-markers.d.ts",
|
|
80
|
+
"import": "./src/registry-markers.js",
|
|
81
|
+
"default": "./src/registry-markers.js"
|
|
82
|
+
},
|
|
83
|
+
"./render": {
|
|
84
|
+
"types": "./src/render.d.ts",
|
|
85
|
+
"import": "./src/render.js",
|
|
86
|
+
"default": "./src/render.js"
|
|
42
87
|
},
|
|
43
88
|
"./runtime": {
|
|
44
89
|
"types": "./src/runtime.d.ts",
|
|
45
90
|
"import": "./src/runtime.js",
|
|
46
91
|
"default": "./src/runtime.js"
|
|
47
92
|
},
|
|
48
|
-
"./
|
|
49
|
-
"types": "./src/
|
|
50
|
-
"import": "./src/
|
|
51
|
-
"default": "./src/
|
|
52
|
-
},
|
|
53
|
-
"./isr": {
|
|
54
|
-
"types": "./src/isr.d.ts",
|
|
55
|
-
"import": "./src/isr.js",
|
|
56
|
-
"default": "./src/isr.js"
|
|
93
|
+
"./signal": {
|
|
94
|
+
"types": "./src/signal.d.ts",
|
|
95
|
+
"import": "./src/signal.js",
|
|
96
|
+
"default": "./src/signal.js"
|
|
57
97
|
},
|
|
58
98
|
"./ssg": {
|
|
59
99
|
"types": "./src/ssg.d.ts",
|
|
60
100
|
"import": "./src/ssg.js",
|
|
61
101
|
"default": "./src/ssg.js"
|
|
62
102
|
},
|
|
63
|
-
"./
|
|
64
|
-
"types": "./src/
|
|
65
|
-
"import": "./src/
|
|
66
|
-
"default": "./src/
|
|
103
|
+
"./stream-frame-policy": {
|
|
104
|
+
"types": "./src/stream-frame-policy.d.ts",
|
|
105
|
+
"import": "./src/stream-frame-policy.js",
|
|
106
|
+
"default": "./src/stream-frame-policy.js"
|
|
67
107
|
},
|
|
68
108
|
"./style-sheet": {
|
|
69
109
|
"types": "./src/style-sheet.d.ts",
|
|
70
110
|
"import": "./src/style-sheet.js",
|
|
71
111
|
"default": "./src/style-sheet.js"
|
|
72
112
|
},
|
|
73
|
-
"./
|
|
74
|
-
"types": "./src/
|
|
75
|
-
"import": "./src/
|
|
76
|
-
"default": "./src/
|
|
77
|
-
},
|
|
78
|
-
"./prop": {
|
|
79
|
-
"types": "./src/prop.d.ts",
|
|
80
|
-
"import": "./src/prop.js",
|
|
81
|
-
"default": "./src/prop.js"
|
|
82
|
-
},
|
|
83
|
-
"./hydration-markers": {
|
|
84
|
-
"types": "./src/hydration-markers.d.ts",
|
|
85
|
-
"import": "./src/hydration-markers.js",
|
|
86
|
-
"default": "./src/hydration-markers.js"
|
|
113
|
+
"./void-tags": {
|
|
114
|
+
"types": "./src/void-tags.d.ts",
|
|
115
|
+
"import": "./src/void-tags.js",
|
|
116
|
+
"default": "./src/void-tags.js"
|
|
87
117
|
}
|
|
88
118
|
},
|
|
89
119
|
"repository": {
|
|
90
120
|
"type": "git",
|
|
91
121
|
"url": "git+https://github.com/open-element/openelement.git"
|
|
92
122
|
},
|
|
123
|
+
"homepage": "https://openelement.org",
|
|
124
|
+
"bugs": "https://github.com/open-element/openelement/issues",
|
|
125
|
+
"license": "MIT",
|
|
126
|
+
"description": "Cross-system contracts and tiny pure predicates for the OpenElement framework.",
|
|
93
127
|
"keywords": [
|
|
94
128
|
"openelement",
|
|
95
129
|
"web-components",
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
130
|
+
"protocol",
|
|
131
|
+
"contracts",
|
|
132
|
+
"ir"
|
|
99
133
|
],
|
|
134
|
+
"engines": {
|
|
135
|
+
"node": ">=24.2"
|
|
136
|
+
},
|
|
137
|
+
"sideEffects": false,
|
|
138
|
+
"peerDependenciesMeta": {},
|
|
100
139
|
"dependencies": {}
|
|
101
140
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/app-model.d.ts
|
|
2
|
+
/** Host-agnostic route and asset contracts shared by app and build drivers. */
|
|
3
|
+
export type OpenElementRouteKind = 'page' | 'api';
|
|
4
|
+
/**
|
|
5
|
+
* One node of the host-agnostic route tree: the matched URL `path` and route
|
|
6
|
+
* kind, the source and module paths the drivers resolve, the optional
|
|
7
|
+
* registered tag and param names, and the nested `children`.
|
|
8
|
+
*/
|
|
9
|
+
export interface OpenElementRouteNode {
|
|
10
|
+
kind: OpenElementRouteKind;
|
|
11
|
+
path: string;
|
|
12
|
+
filePath?: string;
|
|
13
|
+
importPath?: string;
|
|
14
|
+
tagName?: string;
|
|
15
|
+
paramNames?: string[];
|
|
16
|
+
children?: OpenElementRouteNode[];
|
|
17
|
+
meta?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
package/src/app-model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IslandDeliveryStrategy } from "./ssg.js";
|
|
2
|
+
//#region src/client-assets.d.ts
|
|
3
|
+
/** The client asset one compile-time island identity resolves to. */
|
|
4
|
+
export interface ClientIslandAsset {
|
|
5
|
+
/**
|
|
6
|
+
* Emitted asset URL (site-root relative, base-prefixed) of the chunk that
|
|
7
|
+
* carries the island module — its dedicated chunk, a shared chunk, or the
|
|
8
|
+
* client entry when the island has no chunk of its own.
|
|
9
|
+
*/
|
|
10
|
+
file: string;
|
|
11
|
+
/** Delivery strategy resolved from the island declaration at build time. */
|
|
12
|
+
strategy: IslandDeliveryStrategy;
|
|
13
|
+
/**
|
|
14
|
+
* True when the island's delivery strategy hydrates at load time, so the
|
|
15
|
+
* asset is a modulepreload candidate.
|
|
16
|
+
*/
|
|
17
|
+
preload?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** The Phase 2 client build's delivery manifest, keyed by island identity. */
|
|
20
|
+
export interface ClientAssetManifest {
|
|
21
|
+
/** The island client entry URL ('' when no client bundle shipped). */
|
|
22
|
+
entry: string;
|
|
23
|
+
/** Compile-time island identity (delivery tag) -> emitted asset. */
|
|
24
|
+
islands: Record<string, ClientIslandAsset>;
|
|
25
|
+
/** Shared chunk URLs emitted by the client build (JS, neither entry nor island-dedicated). */
|
|
26
|
+
shared: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Preloadable island style asset URLs, sorted, base-prefixed.
|
|
29
|
+
* Shadow-component CSS cannot be applied as a document-level stylesheet —
|
|
30
|
+
* it cannot reach shadow trees — so the document channel's only role for
|
|
31
|
+
* these URLs is preload; the sheets themselves are adopted through the
|
|
32
|
+
* sheet adapters.
|
|
33
|
+
*/
|
|
34
|
+
styles: string[];
|
|
35
|
+
}
|
|
36
|
+
/** The manifest a project without a client bundle carries. */
|
|
37
|
+
export declare const EMPTY_CLIENT_ASSET_MANIFEST: ClientAssetManifest;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize the manifest as the generated dist/server/client-assets.js
|
|
40
|
+
* module: pure structured data, no injection logic — consumers derive what
|
|
41
|
+
* they need from these values.
|
|
42
|
+
*/
|
|
43
|
+
export declare function serializeClientAssetsModule(manifest: ClientAssetManifest): string;
|
|
44
|
+
//#endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/client-assets.ts
|
|
2
|
+
/** The manifest a project without a client bundle carries. */
|
|
3
|
+
const EMPTY_CLIENT_ASSET_MANIFEST = {
|
|
4
|
+
entry: "",
|
|
5
|
+
islands: {},
|
|
6
|
+
shared: [],
|
|
7
|
+
styles: []
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Serialize the manifest as the generated dist/server/client-assets.js
|
|
11
|
+
* module: pure structured data, no injection logic — consumers derive what
|
|
12
|
+
* they need from these values.
|
|
13
|
+
*/
|
|
14
|
+
function serializeClientAssetsModule(manifest) {
|
|
15
|
+
return `// Generated by openElement build — client asset manifest (structured data only).
|
|
16
|
+
// entry: the island client entry URL ('' when no client bundle shipped).
|
|
17
|
+
// islands: compile-time island identity (delivery tag) -> emitted asset.
|
|
18
|
+
// shared: shared chunk URLs emitted by the client build.
|
|
19
|
+
// styles: preloadable island style asset URLs.
|
|
20
|
+
export const clientAssets = ${JSON.stringify(manifest, null, 2)};
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { EMPTY_CLIENT_ASSET_MANIFEST, serializeClientAssetsModule };
|
package/src/data.d.ts
CHANGED
|
@@ -1,22 +1,92 @@
|
|
|
1
|
+
//#region src/data.d.ts
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* data.ts - Platform-neutral data adapter protocol.
|
|
3
4
|
*
|
|
4
5
|
* Data adapters are contract surfaces for route data and ISR regeneration.
|
|
5
6
|
* Concrete databases, filesystems, network clients, and auth layers stay in
|
|
6
7
|
* adapters or recipes.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
*/
|
|
9
|
+
/** Fetch and enumerate data by key without owning storage implementation. */
|
|
10
|
+
/**
|
|
11
|
+
* Context passed to a request-time ('dynamic') route loader. This is the
|
|
12
|
+
* server contract: the loader runs on the server with the Web-standard
|
|
13
|
+
* request, matched route params, the host environment and the platform
|
|
14
|
+
* object, and signals validation failure via fail()/redirect().
|
|
15
|
+
*/
|
|
16
|
+
export interface ServerRouteMetadata {
|
|
17
|
+
path: string;
|
|
18
|
+
filePath: string;
|
|
11
19
|
}
|
|
12
|
-
/**
|
|
20
|
+
/** Canonical request-time/SSG server route context. */
|
|
21
|
+
export interface ServerRouteContext<Env extends object = Record<string, string | undefined>, Platform = unknown, Route extends ServerRouteMetadata = ServerRouteMetadata> {
|
|
13
22
|
request: Request;
|
|
14
23
|
params: Record<string, string>;
|
|
15
|
-
env:
|
|
16
|
-
platform
|
|
24
|
+
env: Env;
|
|
25
|
+
platform: Platform | undefined;
|
|
26
|
+
/** Mutable response-only channel merged into the framework response. */
|
|
27
|
+
responseHeaders: Headers;
|
|
28
|
+
route: Route;
|
|
17
29
|
}
|
|
18
|
-
/** Context passed to a
|
|
30
|
+
/** Context passed to a request-time ('dynamic') route loader. */
|
|
31
|
+
export interface LoaderContext<Env extends object = Record<string, string | undefined>, Platform = unknown, Route extends ServerRouteMetadata = ServerRouteMetadata> extends ServerRouteContext<Env, Platform, Route> {}
|
|
32
|
+
/** Context passed to a route action function (extends loader context). */
|
|
33
|
+
export interface ActionContext<Env extends object = Record<string, string | undefined>, Platform = unknown, Route extends ServerRouteMetadata = ServerRouteMetadata> extends LoaderContext<Env, Platform, Route> {
|
|
19
34
|
formData: FormData;
|
|
20
35
|
}
|
|
21
|
-
/** Route loader: fetches data for a page route. */
|
|
22
|
-
|
|
36
|
+
/** Route loader: fetches data for a page route. */
|
|
37
|
+
export type Loader<T = unknown, Env extends object = Record<string, string | undefined>, Platform = unknown, Route extends ServerRouteMetadata = ServerRouteMetadata> = (ctx: LoaderContext<Env, Platform, Route>) => T | Promise<T>;
|
|
38
|
+
/** Route action: handles form submissions for a page route. */
|
|
39
|
+
export type Action<T = unknown, Env extends object = Record<string, string | undefined>, Platform = unknown, Route extends ServerRouteMetadata = ServerRouteMetadata> = (ctx: ActionContext<Env, Platform, Route>) => T | Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Wire shape returned to the JavaScript form-enhancement path.
|
|
42
|
+
* The no-JS path never sees this: it gets the equivalent semantics
|
|
43
|
+
* as plain HTTP (303 on success, 422 with the re-rendered form on validation
|
|
44
|
+
* failure, redirect/error as status codes).
|
|
45
|
+
*
|
|
46
|
+
* Error outcomes (CSRF 403, unknown action 404, unparseable body 400,
|
|
47
|
+
* unexpected 500) are NOT part of this union: since #863
|
|
48
|
+
* they answer RFC 9457 Problem Details with the
|
|
49
|
+
* PROBLEM_JSON_MEDIA_TYPE content type — see ProblemDetails.
|
|
50
|
+
*/
|
|
51
|
+
export type ActionResult<Success = unknown, Failure = unknown> = {
|
|
52
|
+
type: 'success';
|
|
53
|
+
status: number;
|
|
54
|
+
data?: Success;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'failure';
|
|
57
|
+
status: number;
|
|
58
|
+
data?: Failure;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'redirect';
|
|
61
|
+
status: number;
|
|
62
|
+
location: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* RFC 9457 Problem Details document (#863): the action error
|
|
66
|
+
* channel answers `application/problem+json`
|
|
67
|
+
* instead of the bespoke `{ type: 'error', error: { message } }` JSON, so
|
|
68
|
+
* HTTP tooling recognizes failures natively. With `type: 'about:blank'`,
|
|
69
|
+
* `title` is the HTTP reason phrase and `detail` carries the specific
|
|
70
|
+
* explanation. The wire shape is alpha-unfrozen; the 1.0 acceptance freezes
|
|
71
|
+
* it in this problem+json form.
|
|
72
|
+
*/
|
|
73
|
+
export interface ProblemDetails {
|
|
74
|
+
/** URI reference identifying the problem type; 'about:blank' when none applies. */
|
|
75
|
+
type: string;
|
|
76
|
+
/** Short human-readable summary (the HTTP reason phrase for 'about:blank'). */
|
|
77
|
+
title: string;
|
|
78
|
+
/** The HTTP status code generated for this occurrence. */
|
|
79
|
+
status: number;
|
|
80
|
+
/** Human-readable explanation specific to this occurrence. */
|
|
81
|
+
detail?: string;
|
|
82
|
+
}
|
|
83
|
+
/** Media type of the RFC 9457 action error channel (#863). */
|
|
84
|
+
export declare const PROBLEM_JSON_MEDIA_TYPE = "application/problem+json";
|
|
85
|
+
/**
|
|
86
|
+
* Request header selecting the action response channel: `true` marks a
|
|
87
|
+
* programmatic caller and selects the serialized
|
|
88
|
+
* ActionResult union; `enhance` marks the built-in morph enhancement and
|
|
89
|
+
* selects the same full-HTML responses the no-JS path receives.
|
|
90
|
+
*/
|
|
91
|
+
export declare const ACTION_FETCH_HEADER = "x-openelement-action";
|
|
92
|
+
//#endregion
|
package/src/data.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
//#region src/data.ts
|
|
2
|
+
/** Media type of the RFC 9457 action error channel (#863). */
|
|
3
|
+
const PROBLEM_JSON_MEDIA_TYPE = "application/problem+json";
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//#
|
|
5
|
+
* Request header selecting the action response channel: `true` marks a
|
|
6
|
+
* programmatic caller and selects the serialized
|
|
7
|
+
* ActionResult union; `enhance` marks the built-in morph enhancement and
|
|
8
|
+
* selects the same full-HTML responses the no-JS path receives.
|
|
9
|
+
*/
|
|
10
|
+
const ACTION_FETCH_HEADER = "x-openelement-action";
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ACTION_FETCH_HEADER, PROBLEM_JSON_MEDIA_TYPE };
|