@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
package/dist/proxy/proxy.js
CHANGED
|
@@ -13,7 +13,7 @@ import { artifactTag } from '../protocol/sync.js';
|
|
|
13
13
|
import { createSpool } from '../server/spool.js';
|
|
14
14
|
import { guardPage, sourceHash, stripTrimParam, TRIM_PARAM, trimKey } from '../trim/index.js';
|
|
15
15
|
import { createDictionaries } from './dictionary.js';
|
|
16
|
-
import { decline, htmlCharset, isUtf8, setsPrivateCookie } from './eligible.js';
|
|
16
|
+
import { decline, htmlCharset, isUtf8, recordDecline, setsPrivateCookie } from './eligible.js';
|
|
17
17
|
import { PURGE_PATH, respondPurge } from './purge.js';
|
|
18
18
|
import { pathTag, readTags, stripTags } from './tags.js';
|
|
19
19
|
const HOP_BY_HOP = [
|
|
@@ -248,7 +248,12 @@ export function spoolProxy(options) {
|
|
|
248
248
|
await spool.invalidate([...new Set([...prior.tags, ...tags])]);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
|
|
251
|
+
/** records the decline for the route pattern, then fails the artifact build with the reason */
|
|
252
|
+
async function refuse(route, why, path) {
|
|
253
|
+
await recordDecline(options.spool.sink, why, route, 'artifact');
|
|
254
|
+
throw new ProtocolError('bad-artifact', `${path} is not kept (${why})`);
|
|
255
|
+
}
|
|
256
|
+
async function fetchPage(ctx, data, principal, route) {
|
|
252
257
|
const path = ctx.url.pathname;
|
|
253
258
|
const headers = originHeaders(ctx.request.headers, new URL(ctx.request.url));
|
|
254
259
|
for (const name of [
|
|
@@ -276,10 +281,10 @@ export function spoolProxy(options) {
|
|
|
276
281
|
principal
|
|
277
282
|
}, gate);
|
|
278
283
|
if (why)
|
|
279
|
-
|
|
284
|
+
return refuse(route, why, path);
|
|
280
285
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
281
286
|
if (!data && !isUtf8(htmlCharset(response.headers, bytes))) {
|
|
282
|
-
|
|
287
|
+
return refuse(route, 'charset', path);
|
|
283
288
|
}
|
|
284
289
|
let text = guarded(new TextDecoder().decode(bytes), ctx.url.href);
|
|
285
290
|
// a signal-triggered rewrite is never part of a held copy
|
|
@@ -288,19 +293,18 @@ export function spoolProxy(options) {
|
|
|
288
293
|
}
|
|
289
294
|
if (!data)
|
|
290
295
|
text = rewriteMarkup(text, response.headers, ctx.url.href, false);
|
|
291
|
-
if (text.length > gate.maxBytes)
|
|
292
|
-
|
|
293
|
-
}
|
|
296
|
+
if (text.length > gate.maxBytes)
|
|
297
|
+
return refuse(route, 'size', path);
|
|
294
298
|
const effective = tags.length > 0 ? tags : [pathTag(path)];
|
|
295
299
|
if (!principal)
|
|
296
300
|
await settle(path, text, effective);
|
|
297
301
|
return { text, tags: effective };
|
|
298
302
|
}
|
|
299
|
-
function pageFor(ctx, data, principal) {
|
|
303
|
+
function pageFor(ctx, data, principal, route) {
|
|
300
304
|
const known = pages.get(ctx.request);
|
|
301
305
|
if (known && known.path === ctx.url.pathname)
|
|
302
306
|
return known.page;
|
|
303
|
-
const page = fetchPage(ctx, data, principal);
|
|
307
|
+
const page = fetchPage(ctx, data, principal, route);
|
|
304
308
|
pages.set(ctx.request, { path: ctx.url.pathname, page });
|
|
305
309
|
return page;
|
|
306
310
|
}
|
|
@@ -312,7 +316,7 @@ export function spoolProxy(options) {
|
|
|
312
316
|
}
|
|
313
317
|
const extra = declaration?.depends;
|
|
314
318
|
const depends = async (ctx) => [
|
|
315
|
-
...(await pageFor(ctx, data, principal)).tags,
|
|
319
|
+
...(await pageFor(ctx, data, principal, pattern)).tags,
|
|
316
320
|
...(extra ? await extra(ctx) : [])
|
|
317
321
|
];
|
|
318
322
|
if (declaration?.strategy === 'data') {
|
|
@@ -321,7 +325,7 @@ export function spoolProxy(options) {
|
|
|
321
325
|
strategy: 'data',
|
|
322
326
|
depends,
|
|
323
327
|
load: async (ctx) => {
|
|
324
|
-
const { text } = await pageFor(ctx, true, principal);
|
|
328
|
+
const { text } = await pageFor(ctx, true, principal, pattern);
|
|
325
329
|
try {
|
|
326
330
|
return JSON.parse(text);
|
|
327
331
|
}
|
|
@@ -335,7 +339,7 @@ export function spoolProxy(options) {
|
|
|
335
339
|
...declaration,
|
|
336
340
|
strategy: 'assembly',
|
|
337
341
|
depends,
|
|
338
|
-
load: async (ctx) => ({ shell: (await pageFor(ctx, false, principal)).text })
|
|
342
|
+
load: async (ctx) => ({ shell: (await pageFor(ctx, false, principal, pattern)).text })
|
|
339
343
|
});
|
|
340
344
|
}
|
|
341
345
|
const routes = [
|
|
@@ -344,7 +348,9 @@ export function spoolProxy(options) {
|
|
|
344
348
|
];
|
|
345
349
|
const spool = createSpool({ ...options.spool, routes });
|
|
346
350
|
/** a page the proxy declines tells the worker to drop its copy of that path, in the same response */
|
|
347
|
-
async function unfit(response, path, why, page) {
|
|
351
|
+
async function unfit(response, path, why, page, route) {
|
|
352
|
+
if (page)
|
|
353
|
+
await recordDecline(options.spool.sink, why, route, 'navigation');
|
|
348
354
|
if (!page || why === 'query')
|
|
349
355
|
return response;
|
|
350
356
|
const headers = new Headers(response.headers);
|
|
@@ -371,7 +377,7 @@ export function spoolProxy(options) {
|
|
|
371
377
|
if (answered)
|
|
372
378
|
return answered;
|
|
373
379
|
if (url.pathname === PATHS.worker && request.method === 'GET')
|
|
374
|
-
return spool.stub();
|
|
380
|
+
return spool.stub(request);
|
|
375
381
|
const converting = images !== undefined && imageRequest(images, request);
|
|
376
382
|
let visitorRewrite = false;
|
|
377
383
|
let upstream;
|
|
@@ -474,16 +480,17 @@ export function spoolProxy(options) {
|
|
|
474
480
|
data,
|
|
475
481
|
principal
|
|
476
482
|
}, gate);
|
|
483
|
+
const route = hit.route.pattern;
|
|
477
484
|
if (why)
|
|
478
|
-
return unfit(new Response(upstream.body, init), url.pathname, why, page);
|
|
485
|
+
return unfit(new Response(upstream.body, init), url.pathname, why, page, route);
|
|
479
486
|
const bytes = new Uint8Array(await upstream.arrayBuffer());
|
|
480
487
|
if (!data && !isUtf8(htmlCharset(upstream.headers, bytes))) {
|
|
481
|
-
return unfit(new Response(bytes, init), url.pathname, 'charset', page);
|
|
488
|
+
return unfit(new Response(bytes, init), url.pathname, 'charset', page, route);
|
|
482
489
|
}
|
|
483
490
|
const text = new TextDecoder().decode(bytes);
|
|
484
491
|
headers.delete('content-length');
|
|
485
492
|
if (text.length > gate.maxBytes) {
|
|
486
|
-
return unfit(new Response(text, init), url.pathname, 'size', page);
|
|
493
|
+
return unfit(new Response(text, init), url.pathname, 'size', page, route);
|
|
487
494
|
}
|
|
488
495
|
const effective = tags.length > 0 ? tags : [pathTag(url.pathname)];
|
|
489
496
|
if (request.method === 'GET' && !principal)
|
|
@@ -494,7 +501,10 @@ export function spoolProxy(options) {
|
|
|
494
501
|
});
|
|
495
502
|
// a visitor-signal rewrite is not in the copy /.spool/artifact builds, so the worker asks for it
|
|
496
503
|
const same = !visitorRewrite && !data && !principal;
|
|
497
|
-
return spool.decorate(request, new Response(text, init),
|
|
504
|
+
return spool.decorate(request, new Response(text, init), {
|
|
505
|
+
judged: true,
|
|
506
|
+
...(same ? { assembled: text } : {})
|
|
507
|
+
});
|
|
498
508
|
}
|
|
499
509
|
return Object.assign(handle, {
|
|
500
510
|
spool,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { Spool } from '../server/spool.js';
|
|
3
|
+
import { type StaticOption } from '../vite/index.js';
|
|
4
|
+
export { flattenRoutes, reactRouterPages } from './pages.js';
|
|
5
|
+
export type { PrerenderPaths, ReactRouterSettings, RouteEntryInput, RouteRegistration } from './pages.js';
|
|
6
|
+
/** what `spoolReactRouter` takes */
|
|
7
|
+
export type SpoolReactRouterOptions = {
|
|
8
|
+
/** the instance the app's routes were declared for; the dev server answers from it */
|
|
9
|
+
spool: Spool;
|
|
10
|
+
/** the build-time static tier, as `spoolVite` takes it; on by default, `false` turns it off */
|
|
11
|
+
static?: StaticOption;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The React Router integration for the dev server. It serves the worker script and spool's paths
|
|
15
|
+
* from `spool`, and prints the routes it registered, the ones it left to the network and why. A
|
|
16
|
+
* production response gets spool's envelope and tag from `spool.handle`, which wraps the React
|
|
17
|
+
* Router request handler; the Vite plugin does not reach server-rendered HTML. The client build
|
|
18
|
+
* also publishes the static tier into its output directory (see `static`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function spoolReactRouter(options: SpoolReactRouterOptions): Plugin[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { formatDevReport } from '../plugins/report.js';
|
|
4
|
+
import { spoolVite } from '../vite/index.js';
|
|
5
|
+
import { reactRouterPages } from './pages.js';
|
|
6
|
+
export { flattenRoutes, reactRouterPages } from './pages.js';
|
|
7
|
+
const CONFIG_FILES = [
|
|
8
|
+
'react-router.config.ts',
|
|
9
|
+
'react-router.config.mts',
|
|
10
|
+
'react-router.config.js',
|
|
11
|
+
'react-router.config.mjs'
|
|
12
|
+
];
|
|
13
|
+
const ROUTE_FILES = ['routes.ts', 'routes.tsx', 'routes.js', 'routes.mjs', 'routes.mts'];
|
|
14
|
+
function firstFile(dir, names) {
|
|
15
|
+
return names.map((name) => resolve(dir, name)).find((file) => existsSync(file));
|
|
16
|
+
}
|
|
17
|
+
async function reportRoutes(server) {
|
|
18
|
+
const { root } = server.config;
|
|
19
|
+
const configFile = firstFile(root, CONFIG_FILES);
|
|
20
|
+
const settings = configFile
|
|
21
|
+
? ((await server.ssrLoadModule(configFile)).default ?? {})
|
|
22
|
+
: {};
|
|
23
|
+
const routesFile = firstFile(resolve(root, settings.appDirectory ?? 'app'), ROUTE_FILES);
|
|
24
|
+
if (routesFile === undefined)
|
|
25
|
+
return;
|
|
26
|
+
const entries = (await server.ssrLoadModule(routesFile)).default;
|
|
27
|
+
const pages = reactRouterPages(await entries, settings);
|
|
28
|
+
server.config.logger.info(formatDevReport({
|
|
29
|
+
registered: pages.flatMap((page) => page.pattern && page.register !== 'network'
|
|
30
|
+
? [{ pattern: page.pattern, register: page.register, maxAge: page.maxAge }]
|
|
31
|
+
: []),
|
|
32
|
+
network: pages
|
|
33
|
+
.filter((page) => page.register === 'network')
|
|
34
|
+
.map((page) => ({ path: page.path, reason: page.reason })),
|
|
35
|
+
uncovered: []
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The React Router integration for the dev server. It serves the worker script and spool's paths
|
|
40
|
+
* from `spool`, and prints the routes it registered, the ones it left to the network and why. A
|
|
41
|
+
* production response gets spool's envelope and tag from `spool.handle`, which wraps the React
|
|
42
|
+
* Router request handler; the Vite plugin does not reach server-rendered HTML. The client build
|
|
43
|
+
* also publishes the static tier into its output directory (see `static`).
|
|
44
|
+
*/
|
|
45
|
+
export function spoolReactRouter(options) {
|
|
46
|
+
return [
|
|
47
|
+
spoolVite(options),
|
|
48
|
+
{
|
|
49
|
+
name: '@drupflare/spool/react-router:report',
|
|
50
|
+
apply: 'serve',
|
|
51
|
+
configureServer(server) {
|
|
52
|
+
return () => {
|
|
53
|
+
reportRoutes(server).catch((error) => {
|
|
54
|
+
server.config.logger.error(`spool: could not read the routes: ${String(error)}`);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Registration } from '../plugins/mode.js';
|
|
2
|
+
/** the fields of a React Router route entry the registration reads; `RouteConfigEntry` fits this shape */
|
|
3
|
+
export type RouteEntryInput = {
|
|
4
|
+
id?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
index?: boolean;
|
|
7
|
+
file?: string;
|
|
8
|
+
children?: RouteEntryInput[];
|
|
9
|
+
};
|
|
10
|
+
/** a `prerender` path list, a boolean, or a function that the plugin cannot evaluate */
|
|
11
|
+
export type PrerenderPaths = boolean | readonly string[] | ((args: never) => unknown);
|
|
12
|
+
/** the `react-router.config.ts` settings that set how routes render; the other keys are not read */
|
|
13
|
+
export type ReactRouterSettings = {
|
|
14
|
+
/** `unstable_api-only` is a React Router 8 value that spool does not map */
|
|
15
|
+
ssr?: boolean | 'unstable_api-only';
|
|
16
|
+
prerender?: PrerenderPaths | {
|
|
17
|
+
paths: PrerenderPaths;
|
|
18
|
+
concurrency?: number;
|
|
19
|
+
};
|
|
20
|
+
appDirectory?: string;
|
|
21
|
+
};
|
|
22
|
+
/** how one route is registered; `pattern` is set only when the path converts */
|
|
23
|
+
export type RouteRegistration = Registration & {
|
|
24
|
+
path: string;
|
|
25
|
+
pattern?: string;
|
|
26
|
+
};
|
|
27
|
+
/** every route path of the tree, parents before children; a layout adds no path of its own */
|
|
28
|
+
export declare function flattenRoutes(entries: readonly RouteEntryInput[], parent?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Registers every route of a React Router route array (`app/routes.ts`). Nested paths are joined
|
|
31
|
+
* first. A dynamic route stays on the network until the app declares its family; `ssr` and
|
|
32
|
+
* `prerender` are global settings, so they apply to every route.
|
|
33
|
+
*/
|
|
34
|
+
export declare function reactRouterPages(entries: readonly RouteEntryInput[], settings?: ReactRouterSettings): RouteRegistration[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { registerMode } from '../plugins/mode.js';
|
|
2
|
+
import { toSpoolPattern } from '../plugins/path.js';
|
|
3
|
+
function joinPath(parent, child) {
|
|
4
|
+
if (child.startsWith('/'))
|
|
5
|
+
return child;
|
|
6
|
+
const base = parent.replace(/\/+$/, '');
|
|
7
|
+
return child === '' ? base || '/' : `${base}/${child}`;
|
|
8
|
+
}
|
|
9
|
+
/** every route path of the tree, parents before children; a layout adds no path of its own */
|
|
10
|
+
export function flattenRoutes(entries, parent = '') {
|
|
11
|
+
return entries.flatMap((entry) => {
|
|
12
|
+
const path = entry.index === true
|
|
13
|
+
? parent || '/'
|
|
14
|
+
: entry.path === undefined
|
|
15
|
+
? undefined
|
|
16
|
+
: joinPath(parent, entry.path);
|
|
17
|
+
const below = path ?? parent;
|
|
18
|
+
return [
|
|
19
|
+
...(path === undefined ? [] : [path]),
|
|
20
|
+
...flattenRoutes(entry.children ?? [], below)
|
|
21
|
+
];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function prerenderPaths(prerender) {
|
|
25
|
+
if (prerender !== undefined && typeof prerender === 'object' && 'paths' in prerender) {
|
|
26
|
+
return prerender.paths;
|
|
27
|
+
}
|
|
28
|
+
return prerender;
|
|
29
|
+
}
|
|
30
|
+
function prerendered(settings, path) {
|
|
31
|
+
const setting = prerenderPaths(settings.prerender);
|
|
32
|
+
if (setting === undefined || setting === false)
|
|
33
|
+
return false;
|
|
34
|
+
if (setting === true)
|
|
35
|
+
return true;
|
|
36
|
+
if (Array.isArray(setting))
|
|
37
|
+
return setting.includes(path);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function registerRoute(path, settings) {
|
|
41
|
+
const converted = toSpoolPattern('react-router', path);
|
|
42
|
+
if (converted.kind === 'network')
|
|
43
|
+
return { path, register: 'network', reason: converted.reason };
|
|
44
|
+
const { pattern } = converted;
|
|
45
|
+
if (settings.ssr === 'unstable_api-only') {
|
|
46
|
+
return {
|
|
47
|
+
path,
|
|
48
|
+
pattern,
|
|
49
|
+
register: 'network',
|
|
50
|
+
reason: 'ssr unstable_api-only is not mapped'
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (settings.ssr === false) {
|
|
54
|
+
return { path, pattern, ...registerMode({ rendering: 'client', enumerable: false }) };
|
|
55
|
+
}
|
|
56
|
+
const isPrerendered = prerendered(settings, path);
|
|
57
|
+
if (isPrerendered === undefined) {
|
|
58
|
+
return {
|
|
59
|
+
path,
|
|
60
|
+
pattern,
|
|
61
|
+
register: 'network',
|
|
62
|
+
reason: 'prerender function is not evaluated'
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const enumerable = !pattern.includes(':');
|
|
66
|
+
const mode = {
|
|
67
|
+
rendering: isPrerendered && enumerable ? 'prerender' : 'server',
|
|
68
|
+
enumerable
|
|
69
|
+
};
|
|
70
|
+
const registration = registerMode(mode);
|
|
71
|
+
if (registration.register === 'network' && !enumerable) {
|
|
72
|
+
registration.reason = `params not enumerable: declare a dataset family for ${pattern}`;
|
|
73
|
+
}
|
|
74
|
+
return { path, pattern, ...registration };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Registers every route of a React Router route array (`app/routes.ts`). Nested paths are joined
|
|
78
|
+
* first. A dynamic route stays on the network until the app declares its family; `ssr` and
|
|
79
|
+
* `prerender` are global settings, so they apply to every route.
|
|
80
|
+
*/
|
|
81
|
+
export function reactRouterPages(entries, settings = {}) {
|
|
82
|
+
return [...new Set(flattenRoutes(entries))].map((path) => registerRoute(path, settings));
|
|
83
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** days in the month a daily count is scaled to (L3, a scenario convention) */
|
|
2
|
+
export declare const DAYS_PER_MONTH = 30;
|
|
3
|
+
/**
|
|
4
|
+
* The layer of each figure in {@link DemandSaving}. A derived figure keeps the label of the figure it
|
|
5
|
+
* came from; the one L3 input, views a day, sits beside the counts.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEMAND_LAYERS: {
|
|
8
|
+
readonly avoidedPerView: "L2";
|
|
9
|
+
readonly avoidedShare: "L2";
|
|
10
|
+
readonly baselinePerDay: "L3";
|
|
11
|
+
readonly spoolPerDay: "L3";
|
|
12
|
+
readonly avoidedPerDay: "L3";
|
|
13
|
+
readonly freePlanShareBaseline: "L3";
|
|
14
|
+
readonly freePlanShareSpool: "L3";
|
|
15
|
+
readonly paidMonthlyUsdBaseline: "L3";
|
|
16
|
+
readonly paidMonthlyUsdSpool: "L3";
|
|
17
|
+
};
|
|
18
|
+
/** origin requests one reader model made over `views` views, with and without spool (L1) */
|
|
19
|
+
export type DemandCount = {
|
|
20
|
+
scenario: string;
|
|
21
|
+
engine: string;
|
|
22
|
+
views: number;
|
|
23
|
+
/** origin requests with no spool */
|
|
24
|
+
baseline: number;
|
|
25
|
+
/** origin requests with spool */
|
|
26
|
+
spool: number;
|
|
27
|
+
};
|
|
28
|
+
/** one scenario's figures; {@link DEMAND_LAYERS} gives the layer of each */
|
|
29
|
+
export type DemandSaving = {
|
|
30
|
+
scenario: string;
|
|
31
|
+
engine: string;
|
|
32
|
+
avoidedPerView: number;
|
|
33
|
+
avoidedShare: number;
|
|
34
|
+
baselinePerDay: number;
|
|
35
|
+
spoolPerDay: number;
|
|
36
|
+
avoidedPerDay: number;
|
|
37
|
+
/** share of the Free plan's daily request allowance the no-spool arm uses */
|
|
38
|
+
freePlanShareBaseline: number;
|
|
39
|
+
freePlanShareSpool: number;
|
|
40
|
+
/** the paid plan's overage in USD a month, above the included requests */
|
|
41
|
+
paidMonthlyUsdBaseline: number;
|
|
42
|
+
paidMonthlyUsdSpool: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Origin requests avoided for each measured reader model, scaled to `viewsPerDay` views a day. A
|
|
46
|
+
* negative `avoidedPerView` is a result: spool adds requests where a bootstrap costs more than the
|
|
47
|
+
* views it serves. Throws a RangeError on a count that is not a whole number of requests.
|
|
48
|
+
*/
|
|
49
|
+
export declare function demandSavings(counts: readonly DemandCount[], viewsPerDay: number): DemandSaving[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CF_FREE_REQUESTS_PER_DAY, paidRequestsUsd } from './economics.js';
|
|
2
|
+
/** days in the month a daily count is scaled to (L3, a scenario convention) */
|
|
3
|
+
export const DAYS_PER_MONTH = 30;
|
|
4
|
+
/**
|
|
5
|
+
* The layer of each figure in {@link DemandSaving}. A derived figure keeps the label of the figure it
|
|
6
|
+
* came from; the one L3 input, views a day, sits beside the counts.
|
|
7
|
+
*/
|
|
8
|
+
export const DEMAND_LAYERS = {
|
|
9
|
+
avoidedPerView: 'L2',
|
|
10
|
+
avoidedShare: 'L2',
|
|
11
|
+
baselinePerDay: 'L3',
|
|
12
|
+
spoolPerDay: 'L3',
|
|
13
|
+
avoidedPerDay: 'L3',
|
|
14
|
+
freePlanShareBaseline: 'L3',
|
|
15
|
+
freePlanShareSpool: 'L3',
|
|
16
|
+
paidMonthlyUsdBaseline: 'L3',
|
|
17
|
+
paidMonthlyUsdSpool: 'L3'
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Origin requests avoided for each measured reader model, scaled to `viewsPerDay` views a day. A
|
|
21
|
+
* negative `avoidedPerView` is a result: spool adds requests where a bootstrap costs more than the
|
|
22
|
+
* views it serves. Throws a RangeError on a count that is not a whole number of requests.
|
|
23
|
+
*/
|
|
24
|
+
export function demandSavings(counts, viewsPerDay) {
|
|
25
|
+
if (!Number.isFinite(viewsPerDay) || viewsPerDay < 0) {
|
|
26
|
+
throw new RangeError(`viewsPerDay must be a non-negative number, got ${viewsPerDay}`);
|
|
27
|
+
}
|
|
28
|
+
return counts.map((count) => {
|
|
29
|
+
const { scenario, engine, views, baseline, spool } = count;
|
|
30
|
+
for (const [name, value] of [
|
|
31
|
+
['views', views],
|
|
32
|
+
['baseline', baseline],
|
|
33
|
+
['spool', spool]
|
|
34
|
+
]) {
|
|
35
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
36
|
+
throw new RangeError(`${scenario} ${engine}: ${name} must be a whole number, got ${value}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (views < 1 || baseline < 1) {
|
|
40
|
+
throw new RangeError(`${scenario} ${engine}: views and baseline must be at least 1`);
|
|
41
|
+
}
|
|
42
|
+
const baselinePerView = baseline / views;
|
|
43
|
+
const spoolPerView = spool / views;
|
|
44
|
+
const baselinePerDay = baselinePerView * viewsPerDay;
|
|
45
|
+
const spoolPerDay = spoolPerView * viewsPerDay;
|
|
46
|
+
return {
|
|
47
|
+
scenario,
|
|
48
|
+
engine,
|
|
49
|
+
avoidedPerView: baselinePerView - spoolPerView,
|
|
50
|
+
avoidedShare: (baseline - spool) / baseline,
|
|
51
|
+
baselinePerDay,
|
|
52
|
+
spoolPerDay,
|
|
53
|
+
avoidedPerDay: baselinePerDay - spoolPerDay,
|
|
54
|
+
freePlanShareBaseline: baselinePerDay / CF_FREE_REQUESTS_PER_DAY.value,
|
|
55
|
+
freePlanShareSpool: spoolPerDay / CF_FREE_REQUESTS_PER_DAY.value,
|
|
56
|
+
paidMonthlyUsdBaseline: paidRequestsUsd(baselinePerDay * DAYS_PER_MONTH),
|
|
57
|
+
paidMonthlyUsdSpool: paidRequestsUsd(spoolPerDay * DAYS_PER_MONTH)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type EgridSubregion, type HostPrice, type Input } from './inputs.js';
|
|
2
|
+
import type { Measurement } from './measurement.js';
|
|
2
3
|
/** egress dollars for `localViews` that no longer send the document, at the host's tier price */
|
|
3
4
|
export declare function egressUsd(localViews: number, host: HostPrice, bytes?: number): number;
|
|
4
5
|
/** request dollars for `localViews`, one request each, where the host bills requests */
|
|
@@ -22,3 +23,57 @@ export declare const gPerKwhFromLbPerMwh: (lbPerMwh: number) => number;
|
|
|
22
23
|
export declare const tonnesFromMwh: (mwh: number, gPerKwh: number) => number;
|
|
23
24
|
/** the eGRID2023 rate of a subregion as grams per kWh; throws on a subregion the table does not hold */
|
|
24
25
|
export declare function egridGPerKwh(subregion: EgridSubregion): number;
|
|
26
|
+
/** the day the vendor pages below were read */
|
|
27
|
+
export declare const ECON_PRICES_READ = "2026-11-18";
|
|
28
|
+
/** requests a Free account may send a day before Cloudflare stops it (L0) */
|
|
29
|
+
export declare const CF_FREE_REQUESTS_PER_DAY: Input;
|
|
30
|
+
/** requests a paid account includes each month before the per-million price applies (L0) */
|
|
31
|
+
export declare const CF_PAID_INCLUDED: Input;
|
|
32
|
+
/** the paid plan's price for each additional million requests (L0) */
|
|
33
|
+
export declare const CF_PAID_PER_MILLION: Input;
|
|
34
|
+
/** requests after the first document in a bootstrap, with a worker (L3, design value) */
|
|
35
|
+
export declare const BOOTSTRAP_EXTRA_WORKER: Input;
|
|
36
|
+
/** the same count without a worker (L3, design value) */
|
|
37
|
+
export declare const BOOTSTRAP_EXTRA_NO_WORKER: Input;
|
|
38
|
+
/** WebKit for macOS script-check requests per document navigation (L1) */
|
|
39
|
+
export declare const WEBKIT_STUB_RATE: Input;
|
|
40
|
+
/** a read workload as the request law takes it (L3 values) */
|
|
41
|
+
export type Workload = {
|
|
42
|
+
name: string;
|
|
43
|
+
/** read views a replica serves per lifetime */
|
|
44
|
+
viewsPerLifetime: number;
|
|
45
|
+
/** lifetimes a bootstrap lasts */
|
|
46
|
+
lifetimes: number;
|
|
47
|
+
/** syncs per lifetime */
|
|
48
|
+
syncs: number;
|
|
49
|
+
/** updates per lifetime */
|
|
50
|
+
updates: number;
|
|
51
|
+
/** writes per read view, each one request on either path */
|
|
52
|
+
writes: number;
|
|
53
|
+
/** contacts per read view that leave the replica */
|
|
54
|
+
contacts: number;
|
|
55
|
+
/** document navigations on WebKit for macOS per lifetime (L3) */
|
|
56
|
+
webkitNavigations: Input;
|
|
57
|
+
};
|
|
58
|
+
/** the five workloads the outputs project (L3) */
|
|
59
|
+
export declare const WORKLOADS: readonly Workload[];
|
|
60
|
+
/** Azure internet egress from North America and Europe, first paid tier, USD (L0) */
|
|
61
|
+
export declare const AZURE_EGRESS: HostPrice;
|
|
62
|
+
/** Google Cloud Premium Tier data transfer out to North America, USD (L0) */
|
|
63
|
+
export declare const GCP_EGRESS: HostPrice;
|
|
64
|
+
/** the first-view document median of a first-view reading, over its corpus pages (L1) */
|
|
65
|
+
export declare function firstViewDocumentMedian(reading: Measurement): number;
|
|
66
|
+
/** Worker requests per read view under spool, excluding the WebKit script check */
|
|
67
|
+
export declare function requestsPerReadView(w: Workload, bootstrapExtra?: number): number;
|
|
68
|
+
/** Worker requests per read view without spool: the document request and the writes */
|
|
69
|
+
export declare const baselinePerReadView: (w: Workload) => number;
|
|
70
|
+
/** share of read views a replica answers with no request; writes reach the origin either way */
|
|
71
|
+
export declare function heldShare(w: Workload, requests: number): number;
|
|
72
|
+
/** Worker requests the WebKit macOS script check adds per read view, stub on the Worker */
|
|
73
|
+
export declare const webkitStubPerReadView: (w: Workload) => number;
|
|
74
|
+
/** read views a day the Free plan's request limit supports at `requestsPerView` each */
|
|
75
|
+
export declare const freeReadViewsPerDay: (requestsPerView: number) => number;
|
|
76
|
+
/** requests above the paid plan's included amount */
|
|
77
|
+
export declare const overIncluded: (requests: number) => number;
|
|
78
|
+
/** dollars at the paid plan's per-million price for the requests above the included amount */
|
|
79
|
+
export declare const paidRequestsUsd: (requests: number) => number;
|