@govela/app 0.2.0 → 0.3.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/client.d.ts +1 -1
- package/client.js +11 -4
- package/package.json +8 -8
package/client.d.ts
CHANGED
|
@@ -87,7 +87,7 @@ export function afterNavigate(fn: (navigation: Navigation) => void): () => void;
|
|
|
87
87
|
export const protocolVersion: 1;
|
|
88
88
|
|
|
89
89
|
/** The request headers of a navigation (N-2). */
|
|
90
|
-
export const headers: Readonly<{ navigate: string; have: string; build: string }>;
|
|
90
|
+
export const headers: Readonly<{ navigate: string; have: string; build: string; purpose: string }>;
|
|
91
91
|
|
|
92
92
|
/** The detail of `vela:form`: a failed form action (`app.Fail`). */
|
|
93
93
|
export interface FormFailure {
|
package/client.js
CHANGED
|
@@ -12,6 +12,8 @@ export const headers = Object.freeze({
|
|
|
12
12
|
navigate: 'X-Vela-Navigate',
|
|
13
13
|
have: 'X-Vela-Have',
|
|
14
14
|
build: 'X-Vela-Build',
|
|
15
|
+
// "prefetch" on a prefetch (G-4): the answer sets no cookies.
|
|
16
|
+
purpose: 'X-Vela-Purpose',
|
|
15
17
|
});
|
|
16
18
|
|
|
17
19
|
// A chain of redirects longer than this loads the document (N-5).
|
|
@@ -210,11 +212,13 @@ function createRouter({ VelaApp, app, routes, target, route, chain, preload }) {
|
|
|
210
212
|
// fetchNavigation asks the server for the navigation to url (N-2). It
|
|
211
213
|
// resolves with the JSON body, or { redirected } when something other
|
|
212
214
|
// than the app redirected the request.
|
|
213
|
-
async function fetchNavigation(url, have, signal) {
|
|
215
|
+
async function fetchNavigation(url, have, signal, purpose) {
|
|
216
|
+
const requestHeaders = { [headers.navigate]: `auto;v=${protocolVersion}`, [headers.have]: have, [headers.build]: build };
|
|
217
|
+
if (purpose) requestHeaders[headers.purpose] = purpose;
|
|
214
218
|
const response = await fetch(url.href, {
|
|
215
219
|
credentials: 'same-origin',
|
|
216
220
|
signal,
|
|
217
|
-
headers:
|
|
221
|
+
headers: requestHeaders,
|
|
218
222
|
});
|
|
219
223
|
if (response.redirected) return { redirected: response.url };
|
|
220
224
|
return response.json();
|
|
@@ -303,7 +307,10 @@ function createRouter({ VelaApp, app, routes, target, route, chain, preload }) {
|
|
|
303
307
|
// or when it enters the viewport, as data-vela-preload on it or an
|
|
304
308
|
// ancestor says ("hover", "viewport" or "off"; start({ preload }) is the
|
|
305
309
|
// default). The answer serves one navigation within 30 s, for the same
|
|
306
|
-
// URL and X-Vela-Have
|
|
310
|
+
// URL and X-Vela-Have; an answer marked cache: "once" (a user-dependent
|
|
311
|
+
// one, G-4) never serves more. The request says X-Vela-Purpose: prefetch,
|
|
312
|
+
// so the server sets no cookies on it. Every action and invalidate()
|
|
313
|
+
// clear the cache: an answer prefetched before a logout is not shown.
|
|
307
314
|
const prefetched = new Map();
|
|
308
315
|
const prefetchTTL = 30000;
|
|
309
316
|
|
|
@@ -334,7 +341,7 @@ function createRouter({ VelaApp, app, routes, target, route, chain, preload }) {
|
|
|
334
341
|
if (match.route.render === 'data') {
|
|
335
342
|
for (const level of match.route.chain) components(routes, level.id)?.load().catch(() => {});
|
|
336
343
|
}
|
|
337
|
-
const body = fetchNavigation(url, have, undefined);
|
|
344
|
+
const body = fetchNavigation(url, have, undefined, 'prefetch');
|
|
338
345
|
prefetched.set(key, { at: now, body });
|
|
339
346
|
// What the answer needs loads too; a failure only drops the entry.
|
|
340
347
|
body.then((answer) => (answer && answer.v === protocolVersion && (answer.type === 'data' || answer.type === 'fragment') ? prepareModules(answer) : null))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@govela/app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vela App (docs/APP.md): the client router (hydration, data navigation, route matching) and the vela-app command.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
"LICENSE"
|
|
33
33
|
],
|
|
34
34
|
"govela": {
|
|
35
|
-
"runtimeContract":
|
|
35
|
+
"runtimeContract": 5,
|
|
36
36
|
"protocol": 1
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@govela/runtime": ">=0.
|
|
39
|
+
"@govela/runtime": ">=0.7.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18"
|
|
43
43
|
},
|
|
44
44
|
"optionalDependencies": {
|
|
45
|
-
"@govela/app-darwin-arm64": "0.
|
|
46
|
-
"@govela/app-darwin-x64": "0.
|
|
47
|
-
"@govela/app-linux-arm64": "0.
|
|
48
|
-
"@govela/app-linux-x64": "0.
|
|
49
|
-
"@govela/app-win32-x64": "0.
|
|
45
|
+
"@govela/app-darwin-arm64": "0.3.1",
|
|
46
|
+
"@govela/app-darwin-x64": "0.3.1",
|
|
47
|
+
"@govela/app-linux-arm64": "0.3.1",
|
|
48
|
+
"@govela/app-linux-x64": "0.3.1",
|
|
49
|
+
"@govela/app-win32-x64": "0.3.1"
|
|
50
50
|
}
|
|
51
51
|
}
|