@drupflare/spool 0.4.0 → 1.0.0
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/README.md +206 -1756
- package/dist/angular/index.d.ts +13 -0
- package/dist/angular/index.js +25 -0
- package/dist/angular/pages.d.ts +28 -0
- package/dist/angular/pages.js +85 -0
- package/dist/cdn/client.js +1 -1
- package/dist/cdn/location.d.ts +6 -0
- package/dist/cdn/location.js +8 -0
- package/dist/cdn/manifest.json +7 -7
- package/dist/cdn/spool-sw.js +1 -1
- package/dist/client/bootstrap.d.ts +57 -0
- package/dist/client/bootstrap.js +307 -0
- package/dist/client/contact.d.ts +24 -0
- package/dist/client/contact.js +66 -0
- package/dist/client/declared.d.ts +23 -0
- package/dist/client/declared.js +68 -0
- package/dist/client/entry.js +91 -2
- package/dist/client/gate.d.ts +1 -0
- package/dist/client/gate.js +148 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +1 -0
- package/dist/client/live.d.ts +66 -0
- package/dist/client/live.js +225 -0
- package/dist/client/navigate-entry.d.ts +1 -0
- package/dist/client/navigate-entry.js +4 -0
- package/dist/client/navigate.d.ts +54 -0
- package/dist/client/navigate.js +272 -0
- package/dist/client/persist.d.ts +2 -0
- package/dist/client/persist.js +9 -0
- package/dist/client/register.d.ts +11 -1
- package/dist/client/register.js +19 -8
- package/dist/express/index.d.ts +11 -0
- package/dist/express/index.js +209 -0
- package/dist/hono/index.d.ts +19 -0
- package/dist/hono/index.js +49 -0
- package/dist/next/index.d.ts +33 -0
- package/dist/next/index.js +41 -0
- package/dist/next/pages.d.ts +22 -0
- package/dist/next/pages.js +39 -0
- package/dist/node/listener.d.ts +3 -0
- package/dist/node/listener.js +57 -2
- package/dist/nuxt/index.d.ts +22 -0
- package/dist/nuxt/index.js +104 -0
- package/dist/nuxt/pages.d.ts +26 -0
- package/dist/nuxt/pages.js +48 -0
- package/dist/nuxt/runtime/index.d.ts +24 -0
- package/dist/nuxt/runtime/index.js +58 -0
- package/dist/plugins/coverage.d.ts +14 -0
- package/dist/plugins/coverage.js +27 -0
- package/dist/plugins/mode.d.ts +19 -0
- package/dist/plugins/mode.js +20 -0
- package/dist/plugins/path.d.ts +16 -0
- package/dist/plugins/path.js +139 -0
- package/dist/plugins/report.d.ts +22 -0
- package/dist/plugins/report.js +18 -0
- package/dist/plugins/routes.d.ts +38 -0
- package/dist/plugins/routes.js +52 -0
- package/dist/plugins/static.d.ts +42 -0
- package/dist/plugins/static.js +97 -0
- package/dist/protocol/bundle.d.ts +111 -0
- package/dist/protocol/bundle.js +428 -0
- package/dist/protocol/config.d.ts +65 -1
- package/dist/protocol/config.js +28 -0
- package/dist/protocol/dataset.d.ts +6 -0
- package/dist/protocol/dataset.js +6 -0
- package/dist/protocol/envelope.d.ts +33 -1
- package/dist/protocol/envelope.js +15 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/index-rows.d.ts +22 -0
- package/dist/protocol/index-rows.js +53 -0
- package/dist/protocol/index.d.ts +2 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/normalise.d.ts +4 -4
- package/dist/protocol/normalise.js +9 -5
- package/dist/protocol/ring.d.ts +58 -0
- package/dist/protocol/ring.js +6 -0
- package/dist/protocol/route.d.ts +57 -11
- package/dist/protocol/route.js +95 -3
- package/dist/protocol/tag.d.ts +22 -2
- package/dist/protocol/tag.js +25 -4
- package/dist/protocol/view.d.ts +2 -0
- package/dist/protocol/view.js +8 -2
- package/dist/protocol/views.d.ts +6 -0
- package/dist/protocol/views.js +15 -0
- package/dist/protocol/write.d.ts +92 -4
- package/dist/protocol/write.js +251 -9
- package/dist/proxy/eligible.d.ts +22 -1
- package/dist/proxy/eligible.js +62 -15
- package/dist/proxy/proxy.js +28 -18
- package/dist/react-router/index.d.ts +20 -0
- package/dist/react-router/index.js +60 -0
- package/dist/react-router/pages.d.ts +34 -0
- package/dist/react-router/pages.js +83 -0
- package/dist/report/demand.d.ts +49 -0
- package/dist/report/demand.js +60 -0
- package/dist/report/economics.d.ts +55 -0
- package/dist/report/economics.js +189 -0
- package/dist/report/headline.d.ts +158 -0
- package/dist/report/headline.js +473 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +2 -0
- package/dist/report/inputs.d.ts +79 -0
- package/dist/report/inputs.js +115 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +5 -1
- package/dist/report/traffic.d.ts +8 -0
- package/dist/report/traffic.js +7 -0
- package/dist/server/bundle.d.ts +55 -0
- package/dist/server/bundle.js +172 -0
- package/dist/server/dataset.d.ts +8 -2
- package/dist/server/dataset.js +51 -4
- package/dist/server/embedded.d.ts +7 -3
- package/dist/server/embedded.js +7 -3
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +5 -1
- package/dist/server/live-sockets.d.ts +54 -0
- package/dist/server/live-sockets.js +131 -0
- package/dist/server/live.d.ts +146 -0
- package/dist/server/live.js +228 -0
- package/dist/server/ring.d.ts +77 -0
- package/dist/server/ring.js +311 -0
- package/dist/server/spool.d.ts +139 -4
- package/dist/server/spool.js +457 -28
- package/dist/server/static.d.ts +42 -0
- package/dist/server/static.js +29 -0
- package/dist/server/stub.d.ts +43 -5
- package/dist/server/stub.js +126 -8
- package/dist/server/write.d.ts +23 -1
- package/dist/server/write.js +96 -0
- package/dist/stores/durable-object.d.ts +46 -0
- package/dist/stores/durable-object.js +114 -0
- package/dist/sw/analytics.d.ts +1 -1
- package/dist/sw/analytics.js +2 -2
- package/dist/sw/coverage.d.ts +6 -0
- package/dist/sw/coverage.js +34 -0
- package/dist/sw/family.d.ts +15 -0
- package/dist/sw/family.js +48 -0
- package/dist/sw/idb.d.ts +2 -0
- package/dist/sw/idb.js +2 -2
- package/dist/sw/index.d.ts +2 -0
- package/dist/sw/index.js +1 -0
- package/dist/sw/pack/store.d.ts +128 -0
- package/dist/sw/pack/store.js +737 -0
- package/dist/sw/policy.d.ts +2 -0
- package/dist/sw/policy.js +11 -0
- package/dist/sw/probe.d.ts +16 -0
- package/dist/sw/probe.js +25 -0
- package/dist/sw/router.d.ts +3 -2
- package/dist/sw/router.js +15 -2
- package/dist/sw/runtime.d.ts +48 -1
- package/dist/sw/runtime.js +548 -68
- package/dist/sw/scheduler.d.ts +6 -1
- package/dist/sw/scheduler.js +22 -5
- package/dist/sw/write.d.ts +41 -1
- package/dist/sw/write.js +188 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -2
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.js +66 -0
- package/dist/vue/index.d.ts +36 -0
- package/dist/vue/index.js +53 -0
- package/package.json +64 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PROTOCOL_VERSION } from './artifact.js';
|
|
2
2
|
import { ProtocolError } from './errors.js';
|
|
3
|
+
import { parseSyncResponse } from './sync.js';
|
|
3
4
|
/** the header names, lowercase as `Headers` reports them */
|
|
4
5
|
export const HEADERS = {
|
|
5
6
|
protocol: 'spool-protocol',
|
|
@@ -10,7 +11,9 @@ export const HEADERS = {
|
|
|
10
11
|
partition: 'spool-partition',
|
|
11
12
|
vectorSeen: 'spool-vector-seen',
|
|
12
13
|
provision: 'spool-provision',
|
|
13
|
-
provisionReason: 'spool-provision-reason'
|
|
14
|
+
provisionReason: 'spool-provision-reason',
|
|
15
|
+
delta: 'spool-delta',
|
|
16
|
+
have: 'spool-have'
|
|
14
17
|
};
|
|
15
18
|
/** `Spool-Clear` token that wipes everything the worker holds */
|
|
16
19
|
export const CLEAR_ALL = '*';
|
|
@@ -171,3 +174,14 @@ export function decodeEnvelope(headers) {
|
|
|
171
174
|
}
|
|
172
175
|
return out;
|
|
173
176
|
}
|
|
177
|
+
/** the names of the events `/.spool/live` sends, each as the SSE `event` field with one JSON `data` line */
|
|
178
|
+
export const LIVE_EVENTS = ['hello', 'lease', 'delta', 'revoked'];
|
|
179
|
+
/** reads the `data` of a `delta` event; throws `ProtocolError` on a malformed one */
|
|
180
|
+
export function parseLiveDelta(value) {
|
|
181
|
+
const sync = parseSyncResponse(value);
|
|
182
|
+
const from = value.from;
|
|
183
|
+
if (typeof from !== 'number' || !Number.isSafeInteger(from) || from < 0) {
|
|
184
|
+
return bad('from must be a non-negative integer');
|
|
185
|
+
}
|
|
186
|
+
return { ...sync, from };
|
|
187
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** why a protocol value was refused */
|
|
2
|
-
export type ProtocolErrorCode = 'bad-pattern' | 'bad-route' | 'bad-header' | 'bad-artifact' | 'bad-sync' | 'bad-beacon' | 'bad-template' | 'bad-manifest' | 'bad-nav' | 'bad-dataset' | 'dataset-limit' | 'dataset-forbidden' | 'bad-write';
|
|
2
|
+
export type ProtocolErrorCode = 'bad-pattern' | 'bad-route' | 'bad-header' | 'bad-artifact' | 'bad-sync' | 'bad-bundle' | 'bad-beacon' | 'bad-template' | 'bad-manifest' | 'bad-nav' | 'bad-dataset' | 'dataset-limit' | 'dataset-forbidden' | 'bad-write';
|
|
3
3
|
/** thrown for malformed protocol input; `code` names the family so callers can map it to a status */
|
|
4
4
|
export declare class ProtocolError extends Error {
|
|
5
5
|
readonly code: ProtocolErrorCode;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DatasetRow } from './dataset.js';
|
|
2
|
+
import type { SerializedRoute } from './route.js';
|
|
3
|
+
/** the part of a route the index tables read; a route and a serialized route both carry it */
|
|
4
|
+
export type IndexRoute = Pick<SerializedRoute, 'pattern' | 'scope' | 'family' | 'query'>;
|
|
5
|
+
/** the family routes that index a row by its path, and the fields each dataset's queries read */
|
|
6
|
+
export type IndexPlan = {
|
|
7
|
+
paths: Array<{
|
|
8
|
+
dataset: string;
|
|
9
|
+
pattern: string;
|
|
10
|
+
key: string;
|
|
11
|
+
}>;
|
|
12
|
+
fields: Map<string, string[]>;
|
|
13
|
+
};
|
|
14
|
+
/** one index row: its table, its key, and its value, or `null` when the row leaves the index */
|
|
15
|
+
export type IndexRow = [table: string, key: string, row: DatasetRow | null];
|
|
16
|
+
/** the index tables a route set asks for, read from its public routes */
|
|
17
|
+
export declare function indexPlan(routes: readonly IndexRoute[]): IndexPlan;
|
|
18
|
+
/**
|
|
19
|
+
* The index rows of one row of `dataset`. With no `row` the key leaves the index: the same tables
|
|
20
|
+
* come back with `null` values, since a path depends on the key alone.
|
|
21
|
+
*/
|
|
22
|
+
export declare function indexRowsOf(plan: IndexPlan, dataset: string, key: string, row?: DatasetRow): IndexRow[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { fillPattern } from './pattern.js';
|
|
2
|
+
/** whether a pattern has no param but `key`, so each row has one concrete path */
|
|
3
|
+
function oneParam(pattern, key) {
|
|
4
|
+
const parts = pattern.split('/');
|
|
5
|
+
return (!parts.includes('**') && parts.every((part) => !part.startsWith(':') || part === `:${key}`));
|
|
6
|
+
}
|
|
7
|
+
/** the index tables a route set asks for, read from its public routes */
|
|
8
|
+
export function indexPlan(routes) {
|
|
9
|
+
const paths = [];
|
|
10
|
+
const fields = new Map();
|
|
11
|
+
for (const route of routes) {
|
|
12
|
+
if (route.scope !== 'public')
|
|
13
|
+
continue;
|
|
14
|
+
if (route.family && oneParam(route.pattern, route.family.key)) {
|
|
15
|
+
paths.push({
|
|
16
|
+
dataset: route.family.dataset,
|
|
17
|
+
pattern: route.pattern,
|
|
18
|
+
key: route.family.key
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const query = route.query;
|
|
22
|
+
if (query?.dataset !== undefined && query.plan === undefined) {
|
|
23
|
+
const names = fields.get(query.dataset) ?? new Set();
|
|
24
|
+
fields.set(query.dataset, names);
|
|
25
|
+
for (const name of [...Object.keys(query.filter ?? {}), ...(query.sort ?? [])]) {
|
|
26
|
+
names.add(name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { paths, fields: new Map([...fields].map(([dataset, names]) => [dataset, [...names]])) };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The index rows of one row of `dataset`. With no `row` the key leaves the index: the same tables
|
|
34
|
+
* come back with `null` values, since a path depends on the key alone.
|
|
35
|
+
*/
|
|
36
|
+
export function indexRowsOf(plan, dataset, key, row) {
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const path of plan.paths) {
|
|
39
|
+
if (path.dataset !== dataset)
|
|
40
|
+
continue;
|
|
41
|
+
const at = fillPattern(path.pattern, { [path.key]: key });
|
|
42
|
+
out.push([`path:${dataset}`, at, row === undefined ? null : { key }]);
|
|
43
|
+
}
|
|
44
|
+
const names = plan.fields.get(dataset);
|
|
45
|
+
if (names !== undefined) {
|
|
46
|
+
out.push([`query:${dataset}`, key, row === undefined ? null : projected(row, names)]);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** the row cut to the named fields it holds */
|
|
51
|
+
function projected(row, names) {
|
|
52
|
+
return Object.fromEntries(names.filter((name) => Object.hasOwn(row, name)).map((name) => [name, row[name]]));
|
|
53
|
+
}
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './artifact.js';
|
|
2
2
|
export * from './assembly.js';
|
|
3
3
|
export * from './beacon.js';
|
|
4
|
+
export * from './bundle.js';
|
|
4
5
|
export * from './collector.js';
|
|
5
6
|
export * from './config.js';
|
|
6
7
|
export * from './dataset.js';
|
|
@@ -16,6 +17,7 @@ export * from './pattern.js';
|
|
|
16
17
|
export * from './plan.js';
|
|
17
18
|
export * from './provision.js';
|
|
18
19
|
export * from './query.js';
|
|
20
|
+
export * from './ring.js';
|
|
19
21
|
export * from './route.js';
|
|
20
22
|
export * from './sync.js';
|
|
21
23
|
export * from './tag.js';
|
package/dist/protocol/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './artifact.js';
|
|
2
2
|
export * from './assembly.js';
|
|
3
3
|
export * from './beacon.js';
|
|
4
|
+
export * from './bundle.js';
|
|
4
5
|
export * from './collector.js';
|
|
5
6
|
export * from './config.js';
|
|
6
7
|
export * from './dataset.js';
|
|
@@ -16,6 +17,7 @@ export * from './pattern.js';
|
|
|
16
17
|
export * from './plan.js';
|
|
17
18
|
export * from './provision.js';
|
|
18
19
|
export * from './query.js';
|
|
20
|
+
export * from './ring.js';
|
|
19
21
|
export * from './route.js';
|
|
20
22
|
export * from './sync.js';
|
|
21
23
|
export * from './tag.js';
|
|
@@ -3,10 +3,10 @@ export type NormaliseOptions = {
|
|
|
3
3
|
ignore?: readonly RegExp[];
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
* Reduces markup to what two renders of the same page must share: comments
|
|
7
|
-
*
|
|
8
|
-
* dropped, and every `ignore` match blanked (a per-render nonce, say). It does not
|
|
9
|
-
* attributes or fix tag soup.
|
|
6
|
+
* Reduces markup to what two renders of the same page must share: comments, the inline artifact
|
|
7
|
+
* element and the ring element removed, runs of whitespace collapsed to one space, whitespace
|
|
8
|
+
* between tags dropped, and every `ignore` match blanked (a per-render nonce, say). It does not
|
|
9
|
+
* reorder attributes or fix tag soup.
|
|
10
10
|
*/
|
|
11
11
|
export declare function normalise(html: string, options?: NormaliseOptions): string;
|
|
12
12
|
/** the verdict of {@link equivalent}; a mismatch names where the two first differ */
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { stripInline } from './inline.js';
|
|
2
|
+
import { DELTA_ELEMENT_ID, RING_ELEMENT_ID, WRITES_ELEMENT_ID } from './ring.js';
|
|
2
3
|
const IGNORED = '\u0000';
|
|
4
|
+
const RING = new RegExp(`<script type="application/json" id="(?:${RING_ELEMENT_ID}|${WRITES_ELEMENT_ID}|${DELTA_ELEMENT_ID})">[\\s\\S]*?</script>`, 'g');
|
|
3
5
|
/**
|
|
4
|
-
* Reduces markup to what two renders of the same page must share: comments
|
|
5
|
-
*
|
|
6
|
-
* dropped, and every `ignore` match blanked (a per-render nonce, say). It does not
|
|
7
|
-
* attributes or fix tag soup.
|
|
6
|
+
* Reduces markup to what two renders of the same page must share: comments, the inline artifact
|
|
7
|
+
* element and the ring element removed, runs of whitespace collapsed to one space, whitespace
|
|
8
|
+
* between tags dropped, and every `ignore` match blanked (a per-render nonce, say). It does not
|
|
9
|
+
* reorder attributes or fix tag soup.
|
|
8
10
|
*/
|
|
9
11
|
export function normalise(html, options = {}) {
|
|
10
|
-
let out = stripInline(html)
|
|
12
|
+
let out = stripInline(html)
|
|
13
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
14
|
+
.replace(RING, '');
|
|
11
15
|
for (const pattern of options.ignore ?? []) {
|
|
12
16
|
const flags = pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`;
|
|
13
17
|
out = out.replace(new RegExp(pattern.source, flags), IGNORED);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BundleRows } from './bundle.js';
|
|
2
|
+
import type { SerializedRoute } from './route.js';
|
|
3
|
+
import type { CompiledTemplate } from './template/compile.js';
|
|
4
|
+
import type { ResourceWrite } from './write.js';
|
|
5
|
+
/** the id of the JSON script element that carries a ring in the first document */
|
|
6
|
+
export declare const RING_ELEMENT_ID = "spool-ring";
|
|
7
|
+
/** the id of the JSON script element that carries the declared writes of a page with no ring */
|
|
8
|
+
export declare const WRITES_ELEMENT_ID = "spool-writes";
|
|
9
|
+
/** the id of the element that carries a delta to a no-worker page that holds an older version */
|
|
10
|
+
export declare const DELTA_ELEMENT_ID = "spool-delta";
|
|
11
|
+
/** when a client fetches the pack and the worker: `second-view` is pack on view two, worker on view three */
|
|
12
|
+
export type BootstrapGate = 'first-view' | 'second-view';
|
|
13
|
+
/**
|
|
14
|
+
* whether a page registers the worker. `never` keeps every read in the page. `auto` registers it,
|
|
15
|
+
* except on WebKit for a page that carries a ring: WebKit checks the worker script on each
|
|
16
|
+
* navigation, which costs more than it saves. `always` registers it on WebKit too.
|
|
17
|
+
*/
|
|
18
|
+
export type WorkerMode = 'auto' | 'never' | 'always';
|
|
19
|
+
/**
|
|
20
|
+
* The records a first document carries so the second view needs no request: the entry page and
|
|
21
|
+
* its link neighbours up to a byte budget, the routes that render them, and where the full pack is.
|
|
22
|
+
* A ring is trusted as far as the document that carried it; the pack that follows is verified.
|
|
23
|
+
*/
|
|
24
|
+
export type Ring = {
|
|
25
|
+
protocol: 1;
|
|
26
|
+
/** the pack version the rows belong to */
|
|
27
|
+
version: number;
|
|
28
|
+
/** the set digest of the whole pack at that version */
|
|
29
|
+
digest: string;
|
|
30
|
+
/** absent on a gate page, where the boot script the ring names carries the routes and templates */
|
|
31
|
+
routes?: SerializedRoute[];
|
|
32
|
+
/** the compiled template of each route in `routes` that has one, keyed by route pattern; absent with `routes` */
|
|
33
|
+
templates?: Record<string, CompiledTemplate>;
|
|
34
|
+
/** rows by table, ascending by key */
|
|
35
|
+
tables: Record<string, BundleRows>;
|
|
36
|
+
/** true when the ring holds every row, so no pack is fetched */
|
|
37
|
+
complete: boolean;
|
|
38
|
+
bootstrap: BootstrapGate;
|
|
39
|
+
/** an `always` site writes `auto` here, so a client that predates `always` reads the ring as it does an `auto` one */
|
|
40
|
+
worker: 'auto' | 'never';
|
|
41
|
+
/** true when the site registers the worker on WebKit too (`workerMode: 'always'`); absent otherwise */
|
|
42
|
+
webkitWorker?: true;
|
|
43
|
+
/** where the pack is and how many bytes it is; absent when `complete` */
|
|
44
|
+
pack?: {
|
|
45
|
+
url: string;
|
|
46
|
+
bytes: number;
|
|
47
|
+
};
|
|
48
|
+
/** the worker script's lease in seconds; the worker's views inside one lease make the third; absent on an older ring */
|
|
49
|
+
lease?: number;
|
|
50
|
+
/**
|
|
51
|
+
* the boot script that carries the runtime, this pack, and on a gate page the routes and
|
|
52
|
+
* templates in one response; absent when the page loads the runtime by its own tag. A gate page
|
|
53
|
+
* adds `?r=<id>`, the id of those routes and templates, so a changed template is a new URL.
|
|
54
|
+
*/
|
|
55
|
+
boot?: string;
|
|
56
|
+
/** the declared resource writes, so a no-worker page can send them through `spool.fetch`; absent when none */
|
|
57
|
+
writes?: ResourceWrite[];
|
|
58
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** the id of the JSON script element that carries a ring in the first document */
|
|
2
|
+
export const RING_ELEMENT_ID = 'spool-ring';
|
|
3
|
+
/** the id of the JSON script element that carries the declared writes of a page with no ring */
|
|
4
|
+
export const WRITES_ELEMENT_ID = 'spool-writes';
|
|
5
|
+
/** the id of the element that carries a delta to a no-worker page that holds an older version */
|
|
6
|
+
export const DELTA_ELEMENT_ID = 'spool-delta';
|
package/dist/protocol/route.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export type CatalogueGuess = {
|
|
|
66
66
|
export type RouteCommon = {
|
|
67
67
|
/** public or principal; public when absent */
|
|
68
68
|
scope?: Scope;
|
|
69
|
+
/** `principal` is the same as `scope: 'principal'`; a conflicting scope is refused */
|
|
70
|
+
auth?: 'principal';
|
|
69
71
|
/** overrides the scope's default maxStale and mode */
|
|
70
72
|
freshness?: Partial<Freshness>;
|
|
71
73
|
/** keep the artifact across worker restarts; default true */
|
|
@@ -78,7 +80,7 @@ export type RouteCommon = {
|
|
|
78
80
|
sync?: SyncRule;
|
|
79
81
|
/** tags the artifact is built from; records and projections the load registers are added */
|
|
80
82
|
depends?(ctx: RouteContext): readonly string[] | Promise<readonly string[]>;
|
|
81
|
-
/** a principal route's at-rest key; default `session` */
|
|
83
|
+
/** a principal route's at-rest key; default `persistent`, `session` for a shared device */
|
|
82
84
|
retention?: Retention;
|
|
83
85
|
/** overrides the provisioning priors for this route when the server decides whether to ship it */
|
|
84
86
|
provision?: {
|
|
@@ -114,14 +116,37 @@ export type QueryRoute = {
|
|
|
114
116
|
*/
|
|
115
117
|
query?: QuerySchema;
|
|
116
118
|
};
|
|
119
|
+
/**
|
|
120
|
+
* The held dataset row a template, projection or data route renders. The row is the one whose key
|
|
121
|
+
* is the value of the route param `key`. A template or renderer receives `{ params, row }`; a data
|
|
122
|
+
* route answers with the row's JSON.
|
|
123
|
+
*/
|
|
124
|
+
export type Family = {
|
|
125
|
+
/** the dataset the row is read from; it must be held on the device */
|
|
126
|
+
dataset: string;
|
|
127
|
+
/** the route param whose value is the row's key, such as `id` for `/courses/:id` */
|
|
128
|
+
key: string;
|
|
129
|
+
};
|
|
130
|
+
/** the fields a template or projection route takes; a family route needs no `load` */
|
|
131
|
+
export type FamilyRoute = {
|
|
132
|
+
/** binds the route to one held row; `load` is then optional */
|
|
133
|
+
family: Family;
|
|
134
|
+
/** `document` leaves this family's links and forms to the browser; absent, the page renders them */
|
|
135
|
+
navigation?: 'document';
|
|
136
|
+
/** returns the row the key names, which the server builds its own artifact from */
|
|
137
|
+
load?(ctx: RouteContext): unknown;
|
|
138
|
+
} | {
|
|
139
|
+
/** absent, so `load` returns the JSON the route renders */
|
|
140
|
+
family?: undefined;
|
|
141
|
+
/** returns the JSON the template or renderer receives */
|
|
142
|
+
load(ctx: RouteContext): unknown;
|
|
143
|
+
};
|
|
117
144
|
/** a route answered by rendering stored JSON through a compiled template */
|
|
118
|
-
export type TemplateRoute = RouteCommon & QueryRoute & {
|
|
145
|
+
export type TemplateRoute = RouteCommon & QueryRoute & FamilyRoute & {
|
|
119
146
|
/** renders stored JSON through the template */
|
|
120
147
|
strategy: 'template';
|
|
121
148
|
/** the template source, compiled once when the route is defined */
|
|
122
149
|
template: TemplateSource;
|
|
123
|
-
/** returns the JSON the template renders */
|
|
124
|
-
load(ctx: RouteContext): unknown;
|
|
125
150
|
};
|
|
126
151
|
/**
|
|
127
152
|
* A route for a file the application serves as is, such as a page or an asset with fixed bytes.
|
|
@@ -146,21 +171,26 @@ export type StaticRoute = Omit<RouteCommon, 'scope' | 'persist' | 'mode' | 'rete
|
|
|
146
171
|
* `@drupflare/spool/sw` takes a renderer keyed by this pattern. Without one the worker refuses the
|
|
147
172
|
* local view and the network answers.
|
|
148
173
|
*/
|
|
149
|
-
export type ProjectionRoute = RouteCommon & QueryRoute & {
|
|
174
|
+
export type ProjectionRoute = RouteCommon & QueryRoute & FamilyRoute & {
|
|
150
175
|
/** renders stored JSON with the renderer the bundled worker holds */
|
|
151
176
|
strategy: 'projection';
|
|
152
|
-
/** returns the JSON the renderer receives */
|
|
153
|
-
load(ctx: RouteContext): unknown;
|
|
154
177
|
};
|
|
155
178
|
/**
|
|
156
179
|
* A route for a JSON read. The worker answers a GET (not a navigation) from the stored value with
|
|
157
|
-
* `JSON.stringify`, so the application's own handler has to return the same JSON `load` does.
|
|
180
|
+
* `JSON.stringify`, so the application's own handler has to return the same JSON `load` does. With
|
|
181
|
+
* `family` the answer is the held row; with `origin` the GET may come from that other origin, and
|
|
182
|
+
* `query.dataset` without a `family` makes the collection of the dataset.
|
|
158
183
|
*/
|
|
159
|
-
export type DataRoute = RouteCommon & QueryRoute & {
|
|
184
|
+
export type DataRoute = RouteCommon & QueryRoute & FamilyRoute & {
|
|
160
185
|
/** answers a GET with the stored JSON */
|
|
161
186
|
strategy: 'data';
|
|
162
|
-
/**
|
|
163
|
-
|
|
187
|
+
/**
|
|
188
|
+
* the API origin a cross-origin family answers for; absent for the page's own origin. A public
|
|
189
|
+
* route answers from the public replica. A principal route (`scope` or `auth`) answers only a
|
|
190
|
+
* GET with an `Authorization` header, only from the signed-in partition, and stops when the
|
|
191
|
+
* partition is wiped; every other request goes to the API.
|
|
192
|
+
*/
|
|
193
|
+
origin?: string;
|
|
164
194
|
/** the content type of the local answer; default `application/json` */
|
|
165
195
|
contentType?: string;
|
|
166
196
|
};
|
|
@@ -205,6 +235,14 @@ export type Route = {
|
|
|
205
235
|
documentBytes?: number;
|
|
206
236
|
/** query strings the worker answers from the stored collection */
|
|
207
237
|
query?: QuerySchema;
|
|
238
|
+
/** the held dataset row the route renders, when it declares a family */
|
|
239
|
+
family?: Family;
|
|
240
|
+
/** `document` when the page leaves this family's links and forms to the browser */
|
|
241
|
+
navigation?: 'document';
|
|
242
|
+
/** the API origin a cross-origin data family answers for */
|
|
243
|
+
origin?: string;
|
|
244
|
+
/** `false` for a family route with no load, which has no artifact to provision */
|
|
245
|
+
provisionable?: false;
|
|
208
246
|
/** tags the artifact is built from; a change to one invalidates it */
|
|
209
247
|
depends(ctx: RouteContext): readonly string[] | Promise<readonly string[]>;
|
|
210
248
|
/** returns the data the artifact is built from */
|
|
@@ -238,6 +276,14 @@ export type SerializedRoute = {
|
|
|
238
276
|
catalogue?: true;
|
|
239
277
|
/** the query strings the worker answers from the stored collection of a public route */
|
|
240
278
|
query?: QuerySchema;
|
|
279
|
+
/** the held dataset row the page renders; the worker answers from it with no request */
|
|
280
|
+
family?: Family;
|
|
281
|
+
/** `document` when the page leaves this family's links and forms to the browser */
|
|
282
|
+
navigation?: 'document';
|
|
283
|
+
/** the API origin a cross-origin data family answers for */
|
|
284
|
+
origin?: string;
|
|
285
|
+
/** `false` for a family route with no load, which has no artifact to provision */
|
|
286
|
+
provisionable?: false;
|
|
241
287
|
};
|
|
242
288
|
/**
|
|
243
289
|
* Declares a route. Validates the pattern and the freshness contract, compiles a template, and
|
package/dist/protocol/route.js
CHANGED
|
@@ -87,6 +87,47 @@ function checkQuery(pattern, value) {
|
|
|
87
87
|
}
|
|
88
88
|
return out;
|
|
89
89
|
}
|
|
90
|
+
/** the validated copy of a route's `family`; throws `bad-route` for a binding the worker could not apply */
|
|
91
|
+
function checkFamily(pattern, strategy, value, query, scope) {
|
|
92
|
+
if (strategy !== 'template' && strategy !== 'projection' && strategy !== 'data') {
|
|
93
|
+
return bad(pattern, `a ${strategy} route cannot declare family`);
|
|
94
|
+
}
|
|
95
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
96
|
+
return bad(pattern, 'family must be an object');
|
|
97
|
+
}
|
|
98
|
+
const { dataset, key } = value;
|
|
99
|
+
if (typeof dataset !== 'string' || !DATASET_NAME.test(dataset)) {
|
|
100
|
+
return bad(pattern, 'family.dataset must be a dataset name');
|
|
101
|
+
}
|
|
102
|
+
if (typeof key !== 'string' || key === '')
|
|
103
|
+
return bad(pattern, 'family.key must be a param name');
|
|
104
|
+
if (key === 'viewer.id' && scope !== 'principal') {
|
|
105
|
+
return bad(pattern, 'family.key "viewer.id" needs auth: \'principal\'');
|
|
106
|
+
}
|
|
107
|
+
if (key !== 'viewer.id' && !pattern.split('/').includes(`:${key}`)) {
|
|
108
|
+
return bad(pattern, `family.key "${key}" is not a param of the pattern`);
|
|
109
|
+
}
|
|
110
|
+
if (query !== undefined && query.dataset !== dataset) {
|
|
111
|
+
return bad(pattern, 'a family and a query must name the same dataset');
|
|
112
|
+
}
|
|
113
|
+
return { dataset, key };
|
|
114
|
+
}
|
|
115
|
+
/** the validated copy of a data route's `origin`; an absolute http or https origin with no path */
|
|
116
|
+
function checkOrigin(pattern, value) {
|
|
117
|
+
if (typeof value !== 'string')
|
|
118
|
+
return bad(pattern, 'origin must be a string');
|
|
119
|
+
let url;
|
|
120
|
+
try {
|
|
121
|
+
url = new URL(value);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return bad(pattern, `origin "${value}" is not a URL`);
|
|
125
|
+
}
|
|
126
|
+
if ((url.protocol !== 'http:' && url.protocol !== 'https:') || url.origin !== value) {
|
|
127
|
+
return bad(pattern, `origin "${value}" must be an http or https origin with no path`);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
90
131
|
/**
|
|
91
132
|
* Declares a route. Validates the pattern and the freshness contract, compiles a template, and
|
|
92
133
|
* fills the defaults: freshness by scope, and `offline` as `serve` for public, `refuse` for
|
|
@@ -108,7 +149,16 @@ export function defineRoute(pattern, declaration) {
|
|
|
108
149
|
if (declaration.load !== undefined)
|
|
109
150
|
return bad(pattern, 'a static route has no load');
|
|
110
151
|
}
|
|
111
|
-
const
|
|
152
|
+
const auth = declaration.auth;
|
|
153
|
+
if (auth !== undefined && auth !== 'principal') {
|
|
154
|
+
return bad(pattern, `unknown auth "${String(auth)}"`);
|
|
155
|
+
}
|
|
156
|
+
if (auth !== undefined &&
|
|
157
|
+
declaration.scope !== undefined &&
|
|
158
|
+
declaration.scope !== 'principal') {
|
|
159
|
+
return bad(pattern, 'auth principal needs a principal scope');
|
|
160
|
+
}
|
|
161
|
+
const scope = auth === 'principal' ? 'principal' : (declaration.scope ?? 'public');
|
|
112
162
|
if (scope !== 'public' && scope !== 'principal')
|
|
113
163
|
return bad(pattern, `unknown scope "${scope}"`);
|
|
114
164
|
const freshness = { ...DEFAULT_FRESHNESS[scope], ...declaration.freshness };
|
|
@@ -131,11 +181,16 @@ export function defineRoute(pattern, declaration) {
|
|
|
131
181
|
declaration.mode !== 'shadow') {
|
|
132
182
|
return bad(pattern, `unknown mode "${String(declaration.mode)}"`);
|
|
133
183
|
}
|
|
134
|
-
|
|
184
|
+
const family = declaration.family;
|
|
185
|
+
const origin = declaration.origin;
|
|
186
|
+
if (declaration.strategy !== 'static' &&
|
|
187
|
+
family === undefined &&
|
|
188
|
+
origin === undefined &&
|
|
189
|
+
typeof declaration.load !== 'function') {
|
|
135
190
|
return bad(pattern, 'load is required');
|
|
136
191
|
}
|
|
137
192
|
const declared = declaration.strategy === 'static' ? undefined : declaration.retention;
|
|
138
|
-
const retention = declared ?? '
|
|
193
|
+
const retention = declared ?? 'persistent';
|
|
139
194
|
if (retention !== 'persistent' && retention !== 'session') {
|
|
140
195
|
return bad(pattern, `unknown retention "${String(retention)}"`);
|
|
141
196
|
}
|
|
@@ -184,6 +239,35 @@ export function defineRoute(pattern, declaration) {
|
|
|
184
239
|
return bad(pattern, 'a principal route declares query only with query.dataset, without a plan');
|
|
185
240
|
}
|
|
186
241
|
}
|
|
242
|
+
if (family !== undefined) {
|
|
243
|
+
route.family = checkFamily(pattern, declaration.strategy, family, route.query, scope);
|
|
244
|
+
}
|
|
245
|
+
const navigation = declaration.navigation;
|
|
246
|
+
if (navigation !== undefined) {
|
|
247
|
+
if (family === undefined)
|
|
248
|
+
return bad(pattern, 'navigation applies to a family route');
|
|
249
|
+
if (navigation !== 'document') {
|
|
250
|
+
return bad(pattern, `unknown navigation "${String(navigation)}"`);
|
|
251
|
+
}
|
|
252
|
+
route.navigation = 'document';
|
|
253
|
+
}
|
|
254
|
+
if (origin !== undefined) {
|
|
255
|
+
if (declaration.strategy !== 'data')
|
|
256
|
+
return bad(pattern, 'only a data route declares origin');
|
|
257
|
+
if (family === undefined && route.query?.dataset === undefined) {
|
|
258
|
+
return bad(pattern, 'origin needs a family or a query over a dataset');
|
|
259
|
+
}
|
|
260
|
+
if (route.family?.key === 'viewer.id') {
|
|
261
|
+
return bad(pattern, 'family.key "viewer.id" is not available on a cross-origin route');
|
|
262
|
+
}
|
|
263
|
+
route.origin = checkOrigin(pattern, origin);
|
|
264
|
+
}
|
|
265
|
+
// viewer.id reads its row from the dataset, so only the other keys need a load
|
|
266
|
+
if (route.family &&
|
|
267
|
+
route.family.key !== 'viewer.id' &&
|
|
268
|
+
typeof declaration.load !== 'function') {
|
|
269
|
+
route.provisionable = false;
|
|
270
|
+
}
|
|
187
271
|
if (declaration.strategy === 'template') {
|
|
188
272
|
if (!declaration.template)
|
|
189
273
|
return bad(pattern, 'a template route needs a template');
|
|
@@ -222,5 +306,13 @@ export function serializeRoute(route) {
|
|
|
222
306
|
out.catalogue = true;
|
|
223
307
|
if (route.query)
|
|
224
308
|
out.query = structuredClone(route.query);
|
|
309
|
+
if (route.family)
|
|
310
|
+
out.family = { ...route.family };
|
|
311
|
+
if (route.navigation)
|
|
312
|
+
out.navigation = route.navigation;
|
|
313
|
+
if (route.origin)
|
|
314
|
+
out.origin = route.origin;
|
|
315
|
+
if (route.provisionable === false)
|
|
316
|
+
out.provisionable = false;
|
|
225
317
|
return out;
|
|
226
318
|
}
|
package/dist/protocol/tag.d.ts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
/** the attribute that marks the page runtime script, so it is never injected twice */
|
|
2
2
|
export declare const CLIENT_TAG_ATTR = "data-spool-client";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* the script tag for the page runtime; `integrity` makes it a cross-origin, SRI-checked load, and
|
|
5
|
+
* `worker: 'never'` tells the page it must not ask for a worker, and `'always'` that it may ask on WebKit
|
|
6
|
+
*/
|
|
4
7
|
export declare function clientTag(options: {
|
|
5
8
|
src: string;
|
|
6
9
|
integrity?: string;
|
|
10
|
+
worker?: 'auto' | 'never' | 'always';
|
|
7
11
|
}): string;
|
|
12
|
+
/** the attribute that marks the inline gate, which stands in for the script tag on a second-view page */
|
|
13
|
+
export declare const GATE_ATTR = "data-spool-gate";
|
|
14
|
+
/**
|
|
15
|
+
* the inline gate in place of `clientTag`: `source` is the built gate script, and the attributes
|
|
16
|
+
* name the client it loads, with its integrity and worker mode. `held` lists the paths a click may
|
|
17
|
+
* load the boot script for: a prefix such as `/courses/` for a page with no query string, or `?` and a
|
|
18
|
+
* path for a list that answers a query string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function gateTag(options: {
|
|
21
|
+
src: string;
|
|
22
|
+
integrity?: string;
|
|
23
|
+
worker?: 'auto' | 'never' | 'always';
|
|
24
|
+
held?: readonly string[];
|
|
25
|
+
/** the worker script's lease in seconds; the gate counts views inside one lease period */
|
|
26
|
+
lease?: number;
|
|
27
|
+
}, source: string): string;
|
|
8
28
|
/**
|
|
9
29
|
* Puts `tag` before `</head>`, else before `</body>`, else at the end. A page that already has
|
|
10
|
-
* the runtime tag is returned unchanged, so the server and the worker can both call this.
|
|
30
|
+
* the runtime tag or the gate is returned unchanged, so the server and the worker can both call this.
|
|
11
31
|
*/
|
|
12
32
|
export declare function injectClientTag(html: string, tag: string): string;
|
package/dist/protocol/tag.js
CHANGED
|
@@ -3,19 +3,40 @@ export const CLIENT_TAG_ATTR = 'data-spool-client';
|
|
|
3
3
|
function escapeAttr(value) {
|
|
4
4
|
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
5
5
|
}
|
|
6
|
-
/** the
|
|
6
|
+
/** the attribute for a worker mode; `auto` writes none, and a client that predates `always` reads it as `auto` */
|
|
7
|
+
function workerAttr(worker) {
|
|
8
|
+
return worker === 'never' || worker === 'always' ? ` data-spool-worker="${worker}"` : '';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* the script tag for the page runtime; `integrity` makes it a cross-origin, SRI-checked load, and
|
|
12
|
+
* `worker: 'never'` tells the page it must not ask for a worker, and `'always'` that it may ask on WebKit
|
|
13
|
+
*/
|
|
7
14
|
export function clientTag(options) {
|
|
8
15
|
const sri = options.integrity
|
|
9
16
|
? ` integrity="${escapeAttr(options.integrity)}" crossorigin="anonymous"`
|
|
10
17
|
: '';
|
|
11
|
-
return `<script src="${escapeAttr(options.src)}"${sri} defer ${CLIENT_TAG_ATTR}></script>`;
|
|
18
|
+
return `<script src="${escapeAttr(options.src)}"${sri}${workerAttr(options.worker)} defer ${CLIENT_TAG_ATTR}></script>`;
|
|
19
|
+
}
|
|
20
|
+
/** the attribute that marks the inline gate, which stands in for the script tag on a second-view page */
|
|
21
|
+
export const GATE_ATTR = 'data-spool-gate';
|
|
22
|
+
/**
|
|
23
|
+
* the inline gate in place of `clientTag`: `source` is the built gate script, and the attributes
|
|
24
|
+
* name the client it loads, with its integrity and worker mode. `held` lists the paths a click may
|
|
25
|
+
* load the boot script for: a prefix such as `/courses/` for a page with no query string, or `?` and a
|
|
26
|
+
* path for a list that answers a query string.
|
|
27
|
+
*/
|
|
28
|
+
export function gateTag(options, source) {
|
|
29
|
+
const sri = options.integrity ? ` data-integrity="${escapeAttr(options.integrity)}"` : '';
|
|
30
|
+
const held = options.held?.length ? ` data-held="${escapeAttr(options.held.join(' '))}"` : '';
|
|
31
|
+
const lease = options.lease === undefined ? '' : ` data-lease="${options.lease}"`;
|
|
32
|
+
return `<script ${GATE_ATTR} data-src="${escapeAttr(options.src)}"${sri}${workerAttr(options.worker)}${held}${lease}>${source}</script>`;
|
|
12
33
|
}
|
|
13
34
|
/**
|
|
14
35
|
* Puts `tag` before `</head>`, else before `</body>`, else at the end. A page that already has
|
|
15
|
-
* the runtime tag is returned unchanged, so the server and the worker can both call this.
|
|
36
|
+
* the runtime tag or the gate is returned unchanged, so the server and the worker can both call this.
|
|
16
37
|
*/
|
|
17
38
|
export function injectClientTag(html, tag) {
|
|
18
|
-
if (html.includes(CLIENT_TAG_ATTR))
|
|
39
|
+
if (html.includes(CLIENT_TAG_ATTR) || html.includes(GATE_ATTR))
|
|
19
40
|
return html;
|
|
20
41
|
for (const close of [/<\/head\s*>/i, /<\/body\s*>/i]) {
|
|
21
42
|
const at = html.search(close);
|
package/dist/protocol/view.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type ViewEvent = {
|
|
|
51
51
|
* bound on cross-origin network requests. Null until the page reports, and when it never does.
|
|
52
52
|
*/
|
|
53
53
|
crossOriginLoads: number | null;
|
|
54
|
+
/** packs this client installed, as the page last reported; absent until the page reports */
|
|
55
|
+
lifetimes?: number;
|
|
54
56
|
};
|
|
55
57
|
/** a view with the device time it was recorded at, epoch milliseconds */
|
|
56
58
|
export type TimedView = ViewEvent & {
|
package/dist/protocol/view.js
CHANGED
|
@@ -124,13 +124,17 @@ export function viewFromBeacon(event) {
|
|
|
124
124
|
}
|
|
125
125
|
if (typeof value !== 'object' || value === null)
|
|
126
126
|
return null;
|
|
127
|
-
const { id, tier, reason, staleSec, engine, scope, strategy, route, mismatch, swAgeMs, gapMs, from, crossOriginLoads } = value;
|
|
127
|
+
const { id, tier, reason, staleSec, engine, scope, strategy, route, mismatch, swAgeMs, gapMs, from, crossOriginLoads, lifetimes } = value;
|
|
128
128
|
if (typeof id !== 'string' || id === '' || id.length > 64)
|
|
129
129
|
return null;
|
|
130
130
|
if (crossOriginLoads !== null &&
|
|
131
131
|
(!Number.isSafeInteger(crossOriginLoads) || crossOriginLoads < 0)) {
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
|
+
if (lifetimes !== undefined &&
|
|
135
|
+
(!Number.isSafeInteger(lifetimes) || lifetimes < 0)) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
134
138
|
if (typeof tier !== 'string' || !TIERS.includes(tier))
|
|
135
139
|
return null;
|
|
136
140
|
if (typeof reason !== 'string' || !Object.hasOwn(REASON_TIER, reason))
|
|
@@ -165,6 +169,7 @@ export function viewFromBeacon(event) {
|
|
|
165
169
|
...(typeof from === 'string' && from !== '' && from.length <= MAX_ROUTE_CHARS
|
|
166
170
|
? { from }
|
|
167
171
|
: {}),
|
|
172
|
+
...(lifetimes === undefined ? {} : { lifetimes: lifetimes }),
|
|
168
173
|
at: event.at
|
|
169
174
|
};
|
|
170
175
|
}
|
|
@@ -177,7 +182,8 @@ export function engineOf(userAgent) {
|
|
|
177
182
|
return 'webkit';
|
|
178
183
|
if (/\bFirefox\//.test(userAgent))
|
|
179
184
|
return 'firefox';
|
|
180
|
-
|
|
185
|
+
// no leading boundary: headless Chromium names itself HeadlessChrome
|
|
186
|
+
if (/(?:Chrome|Chromium)\//.test(userAgent))
|
|
181
187
|
return 'chromium';
|
|
182
188
|
if (/\bSafari\//.test(userAgent))
|
|
183
189
|
return 'webkit';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The view times a page keeps for the lease window, as the comma-separated text `spool:stamps` holds:
|
|
3
|
+
* the stored ones a lease period still covers, then `now`, the last three. A stamp at or after `now`,
|
|
4
|
+
* a full lease old, zero or not a number is outside. Not re-exported from the protocol index.
|
|
5
|
+
*/
|
|
6
|
+
export declare function viewStamps(stored: string, now: number, leaseMs: number): number[];
|