@drupflare/spool 0.3.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 +279 -1607
- 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 +123 -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 +34 -2
- package/dist/client/register.js +64 -7
- 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 +80 -1
- package/dist/protocol/config.js +31 -1
- package/dist/protocol/dataset.d.ts +189 -0
- package/dist/protocol/dataset.js +212 -0
- package/dist/protocol/envelope.d.ts +34 -1
- package/dist/protocol/envelope.js +16 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/graph.d.ts +23 -4
- package/dist/protocol/graph.js +34 -3
- package/dist/protocol/index-rows.d.ts +22 -0
- package/dist/protocol/index-rows.js +53 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +5 -0
- package/dist/protocol/normalise.d.ts +4 -4
- package/dist/protocol/normalise.js +9 -5
- package/dist/protocol/plan.d.ts +100 -0
- package/dist/protocol/plan.js +661 -0
- package/dist/protocol/provision.d.ts +46 -0
- package/dist/protocol/provision.js +38 -0
- package/dist/protocol/query.d.ts +66 -5
- package/dist/protocol/query.js +103 -4
- package/dist/protocol/ring.d.ts +58 -0
- package/dist/protocol/ring.js +6 -0
- package/dist/protocol/route.d.ts +63 -13
- package/dist/protocol/route.js +126 -6
- 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 +234 -0
- package/dist/protocol/write.js +343 -0
- 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/dataset.d.ts +48 -0
- package/dist/report/dataset.js +93 -0
- package/dist/report/demand.d.ts +49 -0
- package/dist/report/demand.js +60 -0
- package/dist/report/derive.d.ts +285 -0
- package/dist/report/derive.js +676 -1
- package/dist/report/economics.d.ts +66 -1
- package/dist/report/economics.js +208 -1
- package/dist/report/headline.d.ts +158 -0
- package/dist/report/headline.js +473 -0
- package/dist/report/index.d.ts +4 -0
- package/dist/report/index.js +4 -0
- package/dist/report/inputs.d.ts +176 -0
- package/dist/report/inputs.js +248 -0
- package/dist/report/institution.d.ts +188 -1
- package/dist/report/institution.js +146 -0
- package/dist/report/loops.d.ts +73 -0
- package/dist/report/loops.js +101 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +7 -1
- package/dist/report/model.d.ts +2 -0
- package/dist/report/model.js +4 -0
- package/dist/report/thirdparty.d.ts +57 -0
- package/dist/report/thirdparty.js +111 -0
- package/dist/report/traffic.d.ts +8 -0
- package/dist/report/traffic.js +7 -0
- package/dist/report/trim.d.ts +56 -0
- package/dist/report/trim.js +83 -1
- package/dist/server/bundle.d.ts +55 -0
- package/dist/server/bundle.js +172 -0
- package/dist/server/dataset.d.ts +54 -0
- package/dist/server/dataset.js +355 -0
- package/dist/server/embedded.d.ts +7 -3
- package/dist/server/embedded.js +7 -3
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +6 -0
- 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 +158 -3
- package/dist/server/spool.js +578 -41
- 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 +49 -0
- package/dist/server/write.js +223 -0
- package/dist/stores/durable-object.d.ts +46 -0
- package/dist/stores/durable-object.js +114 -0
- package/dist/sw/analytics.d.ts +7 -1
- package/dist/sw/analytics.js +16 -2
- package/dist/sw/coverage.d.ts +6 -0
- package/dist/sw/coverage.js +34 -0
- package/dist/sw/dataset-sync.d.ts +76 -0
- package/dist/sw/dataset-sync.js +149 -0
- package/dist/sw/dataset.d.ts +91 -0
- package/dist/sw/dataset.js +318 -0
- package/dist/sw/family.d.ts +15 -0
- package/dist/sw/family.js +48 -0
- package/dist/sw/graph/index.d.ts +31 -1
- package/dist/sw/graph/index.js +57 -5
- package/dist/sw/graph/invalidate.d.ts +15 -3
- package/dist/sw/graph/invalidate.js +42 -4
- package/dist/sw/idb.d.ts +2 -0
- package/dist/sw/idb.js +80 -11
- 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/partition.d.ts +6 -1
- package/dist/sw/partition.js +21 -2
- package/dist/sw/policy.d.ts +2 -0
- package/dist/sw/policy.js +11 -0
- package/dist/sw/principal-dataset.d.ts +64 -0
- package/dist/sw/principal-dataset.js +254 -0
- package/dist/sw/probe.d.ts +16 -0
- package/dist/sw/probe.js +25 -0
- package/dist/sw/render.d.ts +7 -2
- package/dist/sw/render.js +19 -5
- package/dist/sw/replica.d.ts +12 -3
- package/dist/sw/replica.js +40 -5
- package/dist/sw/router.d.ts +3 -2
- package/dist/sw/router.js +15 -2
- package/dist/sw/runtime.d.ts +90 -2
- package/dist/sw/runtime.js +857 -61
- package/dist/sw/scheduler.d.ts +6 -1
- package/dist/sw/scheduler.js +22 -5
- package/dist/sw/seal.d.ts +13 -0
- package/dist/sw/seal.js +13 -4
- package/dist/sw/static.d.ts +18 -0
- package/dist/sw/static.js +84 -1
- package/dist/sw/storage.d.ts +51 -1
- package/dist/sw/storage.js +33 -1
- package/dist/sw/write.d.ts +147 -0
- package/dist/sw/write.js +625 -0
- 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 +65 -4
|
@@ -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,48 @@
|
|
|
1
|
+
import type { Row } from './measurement.js';
|
|
2
|
+
/** bytes of the 304 a plain HTTP cache gets back, socket bytes (L1, `measurements/dataset-baseline/2026-11-15.json`) */
|
|
3
|
+
export declare const NOT_MODIFIED_SOCKET_BYTES = 220;
|
|
4
|
+
/** bytes of the first load of a seed, per collection size, for the three arms */
|
|
5
|
+
export type DatasetSeed = {
|
|
6
|
+
v03: number;
|
|
7
|
+
v04: number;
|
|
8
|
+
native: number;
|
|
9
|
+
};
|
|
10
|
+
/** bytes of one update to a collection of `rows`, for the three arms; `v03Records` is the records shape with `have` */
|
|
11
|
+
export type DatasetUpdate = {
|
|
12
|
+
rows: number;
|
|
13
|
+
change: string;
|
|
14
|
+
changedRows: number;
|
|
15
|
+
v03: number;
|
|
16
|
+
v03Records: number | null;
|
|
17
|
+
v04: number;
|
|
18
|
+
native: number;
|
|
19
|
+
};
|
|
20
|
+
export type DatasetFigures = {
|
|
21
|
+
seeds: Record<number, DatasetSeed>;
|
|
22
|
+
updates: DatasetUpdate[];
|
|
23
|
+
};
|
|
24
|
+
/** the three arms' bytes from the raw rows of a dataset-baseline reading, gate open and list shape for v0.3 */
|
|
25
|
+
export declare function datasetFigures(rows: readonly Row[]): DatasetFigures;
|
|
26
|
+
/** a site's traffic and updates, declared per site (L3) */
|
|
27
|
+
export type Site = {
|
|
28
|
+
name: string;
|
|
29
|
+
viewsPerDay: number;
|
|
30
|
+
updatesPerDay: number;
|
|
31
|
+
devices: number;
|
|
32
|
+
};
|
|
33
|
+
export type SiteFigures = {
|
|
34
|
+
/** views per device per day that a held copy answers: views per device times the return survival */
|
|
35
|
+
served: number;
|
|
36
|
+
/** patches or refetches per device per day, at most one per answered view */
|
|
37
|
+
fetches: number;
|
|
38
|
+
bytesPerDay: Record<'v03' | 'v04' | 'native', number>;
|
|
39
|
+
joulesPerDay: Record<'v03' | 'v04' | 'native', number>;
|
|
40
|
+
/** updates per device over one hold that repay the v0.4 seed's extra bytes against the v0.3 control */
|
|
41
|
+
breakEven: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Bytes per device per day for each arm at a site. A device holds one copy for `DATASET_DEFAULTS.holdDays`
|
|
45
|
+
* and refetches the seed each time. Views that find a copy are `views x survival`; a native cache
|
|
46
|
+
* revalidates on each of those views and sends the full resource when a change landed since the last one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function siteFigures(site: Site, seed: DatasetSeed, update: DatasetUpdate): SiteFigures;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { DATASET_DEFAULTS } from '../protocol/provision.js';
|
|
2
|
+
import { attributionalJoules } from './model.js';
|
|
3
|
+
/** bytes of the 304 a plain HTTP cache gets back, socket bytes (L1, `measurements/dataset-baseline/2026-11-15.json`) */
|
|
4
|
+
export const NOT_MODIFIED_SOCKET_BYTES = 220;
|
|
5
|
+
const at = (row, key) => {
|
|
6
|
+
const value = row[key];
|
|
7
|
+
if (typeof value !== 'object' || value === null)
|
|
8
|
+
throw new TypeError(`no ${key} in the row`);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
const num = (row, key) => {
|
|
12
|
+
const value = row[key];
|
|
13
|
+
if (typeof value !== 'number')
|
|
14
|
+
throw new TypeError(`no numeric ${key} in the row`);
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
/** the three arms' bytes from the raw rows of a dataset-baseline reading, gate open and list shape for v0.3 */
|
|
18
|
+
export function datasetFigures(rows) {
|
|
19
|
+
const scenarios = rows.filter((r) => r.kind === 'scenario' && r.arm === 'gate open');
|
|
20
|
+
const sizes = [...new Set(scenarios.map((r) => num(r, 'n')))].sort((a, b) => a - b);
|
|
21
|
+
const seeds = {};
|
|
22
|
+
const updates = [];
|
|
23
|
+
const find = (pick) => {
|
|
24
|
+
const found = rows.find(pick);
|
|
25
|
+
if (!found)
|
|
26
|
+
throw new RangeError('the reading has no row for this collection and change');
|
|
27
|
+
return found;
|
|
28
|
+
};
|
|
29
|
+
for (const n of sizes) {
|
|
30
|
+
for (const change of ['change-1', 'change-1pct']) {
|
|
31
|
+
const list = find((r) => r.kind === 'scenario' &&
|
|
32
|
+
r.shape === 'list' &&
|
|
33
|
+
r.arm === 'gate open' &&
|
|
34
|
+
r.n === n &&
|
|
35
|
+
r.change === change);
|
|
36
|
+
const records = rows.find((r) => r.kind === 'scenario' &&
|
|
37
|
+
r.shape === 'records' &&
|
|
38
|
+
r.arm === 'gate open' &&
|
|
39
|
+
r.n === n &&
|
|
40
|
+
r.change === change);
|
|
41
|
+
const v04 = find((r) => r.kind === 'v04' && r.n === n && r.change === change);
|
|
42
|
+
const native = find((r) => r.kind === 'native' && r.n === n && r.change === change);
|
|
43
|
+
if (change === 'change-1') {
|
|
44
|
+
seeds[n] = {
|
|
45
|
+
v03: num(at(list, 'seed'), 'brotli'),
|
|
46
|
+
v04: num(at(v04, 'seed'), 'brotli'),
|
|
47
|
+
native: num(at(native, 'firstLoad'), 'socketBytes')
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
updates.push({
|
|
51
|
+
rows: n,
|
|
52
|
+
change,
|
|
53
|
+
changedRows: num(list, 'changedRows'),
|
|
54
|
+
v03: num(at(list, 'refetchWithout'), 'brotli'),
|
|
55
|
+
v03Records: records?.refetchWithHave
|
|
56
|
+
? num(at(records, 'refetchWithHave'), 'brotli')
|
|
57
|
+
: null,
|
|
58
|
+
v04: num(at(v04, 'patch'), 'brotli'),
|
|
59
|
+
native: num(at(native, 'revalidateChanged'), 'socketBytes')
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { seeds, updates };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Bytes per device per day for each arm at a site. A device holds one copy for `DATASET_DEFAULTS.holdDays`
|
|
67
|
+
* and refetches the seed each time. Views that find a copy are `views x survival`; a native cache
|
|
68
|
+
* revalidates on each of those views and sends the full resource when a change landed since the last one.
|
|
69
|
+
*/
|
|
70
|
+
export function siteFigures(site, seed, update) {
|
|
71
|
+
const { survival, holdDays } = DATASET_DEFAULTS;
|
|
72
|
+
const served = (site.viewsPerDay / site.devices) * survival;
|
|
73
|
+
const fetches = Math.min(site.updatesPerDay, served);
|
|
74
|
+
const changed = served > 0 ? 1 - Math.exp(-site.updatesPerDay / served) : 0;
|
|
75
|
+
const bytesPerDay = {
|
|
76
|
+
v03: seed.v03 / holdDays + fetches * update.v03,
|
|
77
|
+
v04: seed.v04 / holdDays + fetches * update.v04,
|
|
78
|
+
native: served * (changed * update.native + (1 - changed) * NOT_MODIFIED_SOCKET_BYTES)
|
|
79
|
+
};
|
|
80
|
+
const saved = update.v03 - update.v04;
|
|
81
|
+
const extra = Math.max(0, seed.v04 - seed.v03);
|
|
82
|
+
return {
|
|
83
|
+
served,
|
|
84
|
+
fetches,
|
|
85
|
+
bytesPerDay,
|
|
86
|
+
joulesPerDay: {
|
|
87
|
+
v03: attributionalJoules(bytesPerDay.v03),
|
|
88
|
+
v04: attributionalJoules(bytesPerDay.v04),
|
|
89
|
+
native: attributionalJoules(bytesPerDay.native)
|
|
90
|
+
},
|
|
91
|
+
breakEven: saved > 0 ? extra / saved : Infinity
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -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
|
+
}
|