@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.
Files changed (206) hide show
  1. package/README.md +279 -1607
  2. package/dist/angular/index.d.ts +13 -0
  3. package/dist/angular/index.js +25 -0
  4. package/dist/angular/pages.d.ts +28 -0
  5. package/dist/angular/pages.js +85 -0
  6. package/dist/cdn/client.js +1 -1
  7. package/dist/cdn/location.d.ts +6 -0
  8. package/dist/cdn/location.js +8 -0
  9. package/dist/cdn/manifest.json +7 -7
  10. package/dist/cdn/spool-sw.js +1 -1
  11. package/dist/client/bootstrap.d.ts +57 -0
  12. package/dist/client/bootstrap.js +307 -0
  13. package/dist/client/contact.d.ts +24 -0
  14. package/dist/client/contact.js +66 -0
  15. package/dist/client/declared.d.ts +23 -0
  16. package/dist/client/declared.js +68 -0
  17. package/dist/client/entry.js +123 -2
  18. package/dist/client/gate.d.ts +1 -0
  19. package/dist/client/gate.js +148 -0
  20. package/dist/client/index.d.ts +25 -0
  21. package/dist/client/index.js +1 -0
  22. package/dist/client/live.d.ts +66 -0
  23. package/dist/client/live.js +225 -0
  24. package/dist/client/navigate-entry.d.ts +1 -0
  25. package/dist/client/navigate-entry.js +4 -0
  26. package/dist/client/navigate.d.ts +54 -0
  27. package/dist/client/navigate.js +272 -0
  28. package/dist/client/persist.d.ts +2 -0
  29. package/dist/client/persist.js +9 -0
  30. package/dist/client/register.d.ts +34 -2
  31. package/dist/client/register.js +64 -7
  32. package/dist/express/index.d.ts +11 -0
  33. package/dist/express/index.js +209 -0
  34. package/dist/hono/index.d.ts +19 -0
  35. package/dist/hono/index.js +49 -0
  36. package/dist/next/index.d.ts +33 -0
  37. package/dist/next/index.js +41 -0
  38. package/dist/next/pages.d.ts +22 -0
  39. package/dist/next/pages.js +39 -0
  40. package/dist/node/listener.d.ts +3 -0
  41. package/dist/node/listener.js +57 -2
  42. package/dist/nuxt/index.d.ts +22 -0
  43. package/dist/nuxt/index.js +104 -0
  44. package/dist/nuxt/pages.d.ts +26 -0
  45. package/dist/nuxt/pages.js +48 -0
  46. package/dist/nuxt/runtime/index.d.ts +24 -0
  47. package/dist/nuxt/runtime/index.js +58 -0
  48. package/dist/plugins/coverage.d.ts +14 -0
  49. package/dist/plugins/coverage.js +27 -0
  50. package/dist/plugins/mode.d.ts +19 -0
  51. package/dist/plugins/mode.js +20 -0
  52. package/dist/plugins/path.d.ts +16 -0
  53. package/dist/plugins/path.js +139 -0
  54. package/dist/plugins/report.d.ts +22 -0
  55. package/dist/plugins/report.js +18 -0
  56. package/dist/plugins/routes.d.ts +38 -0
  57. package/dist/plugins/routes.js +52 -0
  58. package/dist/plugins/static.d.ts +42 -0
  59. package/dist/plugins/static.js +97 -0
  60. package/dist/protocol/bundle.d.ts +111 -0
  61. package/dist/protocol/bundle.js +428 -0
  62. package/dist/protocol/config.d.ts +80 -1
  63. package/dist/protocol/config.js +31 -1
  64. package/dist/protocol/dataset.d.ts +189 -0
  65. package/dist/protocol/dataset.js +212 -0
  66. package/dist/protocol/envelope.d.ts +34 -1
  67. package/dist/protocol/envelope.js +16 -1
  68. package/dist/protocol/errors.d.ts +1 -1
  69. package/dist/protocol/graph.d.ts +23 -4
  70. package/dist/protocol/graph.js +34 -3
  71. package/dist/protocol/index-rows.d.ts +22 -0
  72. package/dist/protocol/index-rows.js +53 -0
  73. package/dist/protocol/index.d.ts +5 -0
  74. package/dist/protocol/index.js +5 -0
  75. package/dist/protocol/normalise.d.ts +4 -4
  76. package/dist/protocol/normalise.js +9 -5
  77. package/dist/protocol/plan.d.ts +100 -0
  78. package/dist/protocol/plan.js +661 -0
  79. package/dist/protocol/provision.d.ts +46 -0
  80. package/dist/protocol/provision.js +38 -0
  81. package/dist/protocol/query.d.ts +66 -5
  82. package/dist/protocol/query.js +103 -4
  83. package/dist/protocol/ring.d.ts +58 -0
  84. package/dist/protocol/ring.js +6 -0
  85. package/dist/protocol/route.d.ts +63 -13
  86. package/dist/protocol/route.js +126 -6
  87. package/dist/protocol/tag.d.ts +22 -2
  88. package/dist/protocol/tag.js +25 -4
  89. package/dist/protocol/view.d.ts +2 -0
  90. package/dist/protocol/view.js +8 -2
  91. package/dist/protocol/views.d.ts +6 -0
  92. package/dist/protocol/views.js +15 -0
  93. package/dist/protocol/write.d.ts +234 -0
  94. package/dist/protocol/write.js +343 -0
  95. package/dist/proxy/eligible.d.ts +22 -1
  96. package/dist/proxy/eligible.js +62 -15
  97. package/dist/proxy/proxy.js +28 -18
  98. package/dist/react-router/index.d.ts +20 -0
  99. package/dist/react-router/index.js +60 -0
  100. package/dist/react-router/pages.d.ts +34 -0
  101. package/dist/react-router/pages.js +83 -0
  102. package/dist/report/dataset.d.ts +48 -0
  103. package/dist/report/dataset.js +93 -0
  104. package/dist/report/demand.d.ts +49 -0
  105. package/dist/report/demand.js +60 -0
  106. package/dist/report/derive.d.ts +285 -0
  107. package/dist/report/derive.js +676 -1
  108. package/dist/report/economics.d.ts +66 -1
  109. package/dist/report/economics.js +208 -1
  110. package/dist/report/headline.d.ts +158 -0
  111. package/dist/report/headline.js +473 -0
  112. package/dist/report/index.d.ts +4 -0
  113. package/dist/report/index.js +4 -0
  114. package/dist/report/inputs.d.ts +176 -0
  115. package/dist/report/inputs.js +248 -0
  116. package/dist/report/institution.d.ts +188 -1
  117. package/dist/report/institution.js +146 -0
  118. package/dist/report/loops.d.ts +73 -0
  119. package/dist/report/loops.js +101 -0
  120. package/dist/report/measurement.d.ts +1 -1
  121. package/dist/report/measurement.js +7 -1
  122. package/dist/report/model.d.ts +2 -0
  123. package/dist/report/model.js +4 -0
  124. package/dist/report/thirdparty.d.ts +57 -0
  125. package/dist/report/thirdparty.js +111 -0
  126. package/dist/report/traffic.d.ts +8 -0
  127. package/dist/report/traffic.js +7 -0
  128. package/dist/report/trim.d.ts +56 -0
  129. package/dist/report/trim.js +83 -1
  130. package/dist/server/bundle.d.ts +55 -0
  131. package/dist/server/bundle.js +172 -0
  132. package/dist/server/dataset.d.ts +54 -0
  133. package/dist/server/dataset.js +355 -0
  134. package/dist/server/embedded.d.ts +7 -3
  135. package/dist/server/embedded.js +7 -3
  136. package/dist/server/index.d.ts +6 -0
  137. package/dist/server/index.js +6 -0
  138. package/dist/server/live-sockets.d.ts +54 -0
  139. package/dist/server/live-sockets.js +131 -0
  140. package/dist/server/live.d.ts +146 -0
  141. package/dist/server/live.js +228 -0
  142. package/dist/server/ring.d.ts +77 -0
  143. package/dist/server/ring.js +311 -0
  144. package/dist/server/spool.d.ts +158 -3
  145. package/dist/server/spool.js +578 -41
  146. package/dist/server/static.d.ts +42 -0
  147. package/dist/server/static.js +29 -0
  148. package/dist/server/stub.d.ts +43 -5
  149. package/dist/server/stub.js +126 -8
  150. package/dist/server/write.d.ts +49 -0
  151. package/dist/server/write.js +223 -0
  152. package/dist/stores/durable-object.d.ts +46 -0
  153. package/dist/stores/durable-object.js +114 -0
  154. package/dist/sw/analytics.d.ts +7 -1
  155. package/dist/sw/analytics.js +16 -2
  156. package/dist/sw/coverage.d.ts +6 -0
  157. package/dist/sw/coverage.js +34 -0
  158. package/dist/sw/dataset-sync.d.ts +76 -0
  159. package/dist/sw/dataset-sync.js +149 -0
  160. package/dist/sw/dataset.d.ts +91 -0
  161. package/dist/sw/dataset.js +318 -0
  162. package/dist/sw/family.d.ts +15 -0
  163. package/dist/sw/family.js +48 -0
  164. package/dist/sw/graph/index.d.ts +31 -1
  165. package/dist/sw/graph/index.js +57 -5
  166. package/dist/sw/graph/invalidate.d.ts +15 -3
  167. package/dist/sw/graph/invalidate.js +42 -4
  168. package/dist/sw/idb.d.ts +2 -0
  169. package/dist/sw/idb.js +80 -11
  170. package/dist/sw/index.d.ts +2 -0
  171. package/dist/sw/index.js +1 -0
  172. package/dist/sw/pack/store.d.ts +128 -0
  173. package/dist/sw/pack/store.js +737 -0
  174. package/dist/sw/partition.d.ts +6 -1
  175. package/dist/sw/partition.js +21 -2
  176. package/dist/sw/policy.d.ts +2 -0
  177. package/dist/sw/policy.js +11 -0
  178. package/dist/sw/principal-dataset.d.ts +64 -0
  179. package/dist/sw/principal-dataset.js +254 -0
  180. package/dist/sw/probe.d.ts +16 -0
  181. package/dist/sw/probe.js +25 -0
  182. package/dist/sw/render.d.ts +7 -2
  183. package/dist/sw/render.js +19 -5
  184. package/dist/sw/replica.d.ts +12 -3
  185. package/dist/sw/replica.js +40 -5
  186. package/dist/sw/router.d.ts +3 -2
  187. package/dist/sw/router.js +15 -2
  188. package/dist/sw/runtime.d.ts +90 -2
  189. package/dist/sw/runtime.js +857 -61
  190. package/dist/sw/scheduler.d.ts +6 -1
  191. package/dist/sw/scheduler.js +22 -5
  192. package/dist/sw/seal.d.ts +13 -0
  193. package/dist/sw/seal.js +13 -4
  194. package/dist/sw/static.d.ts +18 -0
  195. package/dist/sw/static.js +84 -1
  196. package/dist/sw/storage.d.ts +51 -1
  197. package/dist/sw/storage.js +33 -1
  198. package/dist/sw/write.d.ts +147 -0
  199. package/dist/sw/write.js +625 -0
  200. package/dist/version.d.ts +1 -1
  201. package/dist/version.js +1 -2
  202. package/dist/vite/index.d.ts +26 -0
  203. package/dist/vite/index.js +66 -0
  204. package/dist/vue/index.d.ts +36 -0
  205. package/dist/vue/index.js +53 -0
  206. package/package.json +65 -4
@@ -1,4 +1,5 @@
1
- import { type HostPrice } from './inputs.js';
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 */
@@ -12,3 +13,67 @@ export declare function bandwidthUsd(localViews: number, host: HostPrice, bytes?
12
13
  export declare function perMillionViewsUsd(bytes: number, share: number, host: HostPrice): number;
13
14
  /** decimal GB a month that `annualLocalViews` no longer move */
14
15
  export declare function monthlyGb(annualLocalViews: number, bytes?: number): number;
16
+ /** the price record for a state and sector; throws on a state the price table does not hold */
17
+ export declare function electricityPrice(state: string, sector: 'commercial' | 'industrial'): Input;
18
+ /** dollars for `mwh` at `centsPerKwh` (one cent per kWh is $10 per MWh) */
19
+ export declare const usdForMwh: (mwh: number, centsPerKwh: number) => number;
20
+ /** grams CO2e per kWh from a rate in pounds per MWh, the unit eGRID prints */
21
+ export declare const gPerKwhFromLbPerMwh: (lbPerMwh: number) => number;
22
+ /** tonnes CO2e from megawatt-hours at `gPerKwh` */
23
+ export declare const tonnesFromMwh: (mwh: number, gPerKwh: number) => number;
24
+ /** the eGRID2023 rate of a subregion as grams per kWh; throws on a subregion the table does not hold */
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;
@@ -1,4 +1,5 @@
1
- import { DOCUMENT_BYTES } from './inputs.js';
1
+ import { median } from './derive.js';
2
+ import { DOCUMENT_BYTES, EGRID_LB_PER_MWH, ELECTRICITY_PRICE, G_PER_LB } from './inputs.js';
2
3
  /** egress dollars for `localViews` that no longer send the document, at the host's tier price */
3
4
  export function egressUsd(localViews, host, bytes = DOCUMENT_BYTES.value) {
4
5
  return ((localViews * bytes) / host.bytesPerUnit) * host.egress.value;
@@ -22,3 +23,209 @@ export function perMillionViewsUsd(bytes, share, host) {
22
23
  export function monthlyGb(annualLocalViews, bytes = DOCUMENT_BYTES.value) {
23
24
  return (annualLocalViews * bytes) / 12 / 1e9;
24
25
  }
26
+ /** the price record for a state and sector; throws on a state the price table does not hold */
27
+ export function electricityPrice(state, sector) {
28
+ if (!Object.hasOwn(ELECTRICITY_PRICE, state))
29
+ throw new RangeError(`no electricity price for ${state}; the table holds ${Object.keys(ELECTRICITY_PRICE).join(', ')}`);
30
+ return ELECTRICITY_PRICE[state][sector];
31
+ }
32
+ /** dollars for `mwh` at `centsPerKwh` (one cent per kWh is $10 per MWh) */
33
+ export const usdForMwh = (mwh, centsPerKwh) => mwh * centsPerKwh * 10;
34
+ /** grams CO2e per kWh from a rate in pounds per MWh, the unit eGRID prints */
35
+ export const gPerKwhFromLbPerMwh = (lbPerMwh) => (lbPerMwh * G_PER_LB) / 1000;
36
+ /** tonnes CO2e from megawatt-hours at `gPerKwh` */
37
+ export const tonnesFromMwh = (mwh, gPerKwh) => (mwh * gPerKwh) / 1000;
38
+ /** the eGRID2023 rate of a subregion as grams per kWh; throws on a subregion the table does not hold */
39
+ export function egridGPerKwh(subregion) {
40
+ if (!Object.hasOwn(EGRID_LB_PER_MWH, subregion))
41
+ throw new RangeError(`no eGRID subregion ${subregion}`);
42
+ return gPerKwhFromLbPerMwh(EGRID_LB_PER_MWH[subregion].value);
43
+ }
44
+ /** the day the vendor pages below were read */
45
+ export const ECON_PRICES_READ = '2026-11-18';
46
+ /** requests a Free account may send a day before Cloudflare stops it (L0) */
47
+ export const CF_FREE_REQUESTS_PER_DAY = {
48
+ value: 100_000,
49
+ unit: 'requests/day',
50
+ layer: 'L0',
51
+ source: `developers.cloudflare.com/workers/platform/pricing (web page read ${ECON_PRICES_READ}): "100,000 per day" on the Free plan`
52
+ };
53
+ /** requests a paid account includes each month before the per-million price applies (L0) */
54
+ export const CF_PAID_INCLUDED = {
55
+ value: 10_000_000,
56
+ unit: 'requests/month',
57
+ layer: 'L0',
58
+ source: `developers.cloudflare.com/workers/platform/pricing (web page read ${ECON_PRICES_READ}): "10 million included per month"`
59
+ };
60
+ /** the paid plan's price for each additional million requests (L0) */
61
+ export const CF_PAID_PER_MILLION = {
62
+ value: 0.3,
63
+ unit: 'USD/million requests',
64
+ layer: 'L0',
65
+ source: `developers.cloudflare.com/workers/platform/pricing (web page read ${ECON_PRICES_READ}): "$0.30 per additional million"`
66
+ };
67
+ /** requests after the first document in a bootstrap, with a worker (L3, design value) */
68
+ export const BOOTSTRAP_EXTRA_WORKER = {
69
+ value: 2,
70
+ unit: 'requests',
71
+ layer: 'L3',
72
+ source: 'design: the stub and one pack after the first document; the 2026-11-20 demand reading shows the same two non-document requests (boot script and stub) for Chromium and Firefox at 121 views'
73
+ };
74
+ /** the same count without a worker (L3, design value) */
75
+ export const BOOTSTRAP_EXTRA_NO_WORKER = {
76
+ value: 1,
77
+ unit: 'requests',
78
+ layer: 'L3',
79
+ source: 'design: one pack after the first document; no reading under measurements/ fixes it yet'
80
+ };
81
+ /** WebKit for macOS script-check requests per document navigation (L1) */
82
+ export const WEBKIT_STUB_RATE = {
83
+ value: 1,
84
+ unit: 'requests per navigation',
85
+ layer: 'L1',
86
+ source: 'WebKit on macOS, Playwright, 1.5 s between navigations: /sw.js reached the origin on 6 of 6 document navigations and 3 of 3 new tabs'
87
+ };
88
+ /** the five workloads the outputs project (L3) */
89
+ export const WORKLOADS = [
90
+ {
91
+ name: 'Short read lifetime',
92
+ viewsPerLifetime: 5,
93
+ lifetimes: 1,
94
+ syncs: 0,
95
+ updates: 0,
96
+ writes: 0,
97
+ contacts: 0,
98
+ webkitNavigations: {
99
+ value: 5,
100
+ unit: 'navigations per lifetime',
101
+ layer: 'L3',
102
+ source: 'scenario: each of the five views is a document, since a short visit has no in-page views'
103
+ }
104
+ },
105
+ {
106
+ name: 'Engaged daily public reader',
107
+ viewsPerLifetime: 100,
108
+ lifetimes: 1,
109
+ syncs: 1,
110
+ updates: 0,
111
+ writes: 0,
112
+ contacts: 0,
113
+ webkitNavigations: {
114
+ value: 5,
115
+ unit: 'navigations per lifetime',
116
+ layer: 'L3',
117
+ source: 'scenario: five of the 100 views start a document (new visit, reload or new tab); the rest are in-page'
118
+ }
119
+ },
120
+ {
121
+ name: 'Retained public library',
122
+ viewsPerLifetime: 100,
123
+ lifetimes: 10,
124
+ syncs: 1,
125
+ updates: 0.2,
126
+ writes: 0,
127
+ contacts: 0,
128
+ webkitNavigations: {
129
+ value: 5,
130
+ unit: 'navigations per lifetime',
131
+ layer: 'L3',
132
+ source: 'scenario: five of the 100 views per lifetime start a document; the rest are in-page'
133
+ }
134
+ },
135
+ {
136
+ name: 'Read/write workspace',
137
+ viewsPerLifetime: 100,
138
+ lifetimes: 10,
139
+ syncs: 1,
140
+ updates: 0.2,
141
+ writes: 0.1,
142
+ contacts: 0.05,
143
+ webkitNavigations: {
144
+ value: 10,
145
+ unit: 'navigations per lifetime',
146
+ layer: 'L3',
147
+ source: 'scenario: ten of the 100 views per lifetime start a document, twice the reader share, for reloads and new tabs'
148
+ }
149
+ },
150
+ {
151
+ name: 'Ungated two-view lifetime',
152
+ viewsPerLifetime: 2,
153
+ lifetimes: 1,
154
+ syncs: 0,
155
+ updates: 0,
156
+ writes: 0,
157
+ contacts: 0,
158
+ webkitNavigations: {
159
+ value: 2,
160
+ unit: 'navigations per lifetime',
161
+ layer: 'L3',
162
+ source: 'scenario: both views are documents, since a two-view lifetime has no in-page view'
163
+ }
164
+ }
165
+ ];
166
+ /** Azure internet egress from North America and Europe, first paid tier, USD (L0) */
167
+ export const AZURE_EGRESS = {
168
+ name: 'Microsoft Azure',
169
+ tier: 'internet egress from North America and Europe, the next 10 TB a month',
170
+ page: 'azure.microsoft.com/en-us/pricing/details/bandwidth',
171
+ egress: {
172
+ value: 0.087,
173
+ unit: 'USD/GB',
174
+ layer: 'L0',
175
+ source: `azure.microsoft.com/en-us/pricing/details/bandwidth (web page read ${ECON_PRICES_READ}): "From North America, Europe to any destination", next 10 TB a month $0.087 per GB`
176
+ },
177
+ bytesPerUnit: 1e9,
178
+ freeAllowance: {
179
+ value: 100,
180
+ unit: 'GB/month',
181
+ layer: 'L0',
182
+ source: `azure.microsoft.com/en-us/pricing/details/bandwidth (web page read ${ECON_PRICES_READ}): first 100 GB a month free`
183
+ }
184
+ };
185
+ /** Google Cloud Premium Tier data transfer out to North America, USD (L0) */
186
+ export const GCP_EGRESS = {
187
+ name: 'Google Cloud (Premium Tier)',
188
+ tier: 'data transfer out to North America, 1 GiB to 1,024 GiB a month',
189
+ page: 'cloud.google.com/vpc/network-pricing',
190
+ egress: {
191
+ value: 0.12,
192
+ unit: 'USD/GiB',
193
+ layer: 'L0',
194
+ source: `cloud.google.com/vpc/network-pricing (web page read ${ECON_PRICES_READ}): "Network (data transfer out) TO North America (per GiB in USD)", 1 gibibyte to 1,024 gibibyte $0.12 per gibibyte`
195
+ },
196
+ bytesPerUnit: 2 ** 30,
197
+ freeAllowance: {
198
+ value: 1,
199
+ unit: 'GiB/month',
200
+ layer: 'L0',
201
+ source: `cloud.google.com/vpc/network-pricing (web page read ${ECON_PRICES_READ}): 0 gibibyte to 1 gibibyte $0.00 (Free)`
202
+ }
203
+ };
204
+ /** the first-view document median of a first-view reading, over its corpus pages (L1) */
205
+ export function firstViewDocumentMedian(reading) {
206
+ const pages = reading.method['corpus pages'];
207
+ if (!pages?.length)
208
+ throw new RangeError('the first-view reading has no corpus pages');
209
+ return median(pages.map((p) => p.classBytes.document));
210
+ }
211
+ /** Worker requests per read view under spool, excluding the WebKit script check */
212
+ export function requestsPerReadView(w, bootstrapExtra = BOOTSTRAP_EXTRA_WORKER.value) {
213
+ return ((1 + bootstrapExtra) / (w.lifetimes * w.viewsPerLifetime) +
214
+ (w.syncs + w.updates) / w.viewsPerLifetime +
215
+ w.writes +
216
+ w.contacts);
217
+ }
218
+ /** Worker requests per read view without spool: the document request and the writes */
219
+ export const baselinePerReadView = (w) => 1 + w.writes;
220
+ /** share of read views a replica answers with no request; writes reach the origin either way */
221
+ export function heldShare(w, requests) {
222
+ return Math.min(1, Math.max(0, 1 - (requests - w.writes)));
223
+ }
224
+ /** Worker requests the WebKit macOS script check adds per read view, stub on the Worker */
225
+ export const webkitStubPerReadView = (w) => (WEBKIT_STUB_RATE.value * w.webkitNavigations.value) / w.viewsPerLifetime;
226
+ /** read views a day the Free plan's request limit supports at `requestsPerView` each */
227
+ export const freeReadViewsPerDay = (requestsPerView) => CF_FREE_REQUESTS_PER_DAY.value / requestsPerView;
228
+ /** requests above the paid plan's included amount */
229
+ export const overIncluded = (requests) => Math.max(0, requests - CF_PAID_INCLUDED.value);
230
+ /** dollars at the paid plan's per-million price for the requests above the included amount */
231
+ export const paidRequestsUsd = (requests) => (overIncluded(requests) / 1e6) * CF_PAID_PER_MILLION.value;
@@ -0,0 +1,158 @@
1
+ import type { DemandCount } from './demand.js';
2
+ import { type Workload } from './economics.js';
3
+ import { type Layer } from './inputs.js';
4
+ import type { Measurement } from './measurement.js';
5
+ /** engine classes the headline compares; WebKit under the default `workerMode: 'auto'` has no worker */
6
+ export declare const ENGINE_CLASSES: readonly ["worker", "webkit-auto", "webkit-always", "no-worker"];
7
+ export type EngineClass = (typeof ENGINE_CLASSES)[number];
8
+ /** what each engine class is, as the page words it */
9
+ export declare const ENGINE_CLASS_LABELS: Record<EngineClass, string>;
10
+ /** the WebKit default registers no worker, so it is the no-worker class */
11
+ export declare const CLASS_OF_ENGINE_DEFAULT: Record<EngineClass, EngineClass>;
12
+ /** share of a baseline that spool avoids; negative where spool sends more than the baseline */
13
+ export declare function avoidedShare(baseline: number, spool: number): number;
14
+ /** baseline over spool; Infinity when spool sends nothing, below 1 when spool sends more */
15
+ export declare function multiplierOf(baseline: number, spool: number): number;
16
+ /**
17
+ * Requests per read view for a client with no worker. Each document navigation after the first
18
+ * reaches the origin (L1, `never` arm in the WebKit lane), so `lifetimes x e - 1` of them add to the
19
+ * bootstrap count. `e` is the workload's document navigations per lifetime.
20
+ */
21
+ export declare function noWorkerRequestsPerReadView(w: Workload): number;
22
+ /** Worker requests per read view for an engine class; WebKit `auto` is the no-worker class */
23
+ export declare function requestsByClass(w: Workload, cls: EngineClass): number;
24
+ /** the best and the worst engine class for one workload, by requests per read view */
25
+ export declare function bestAndWorst(w: Workload, baseline: number): {
26
+ best: {
27
+ cls: EngineClass;
28
+ requests: number;
29
+ share: number;
30
+ multiplier: number;
31
+ };
32
+ worst: {
33
+ cls: EngineClass;
34
+ requests: number;
35
+ share: number;
36
+ multiplier: number;
37
+ };
38
+ reversed: EngineClass[];
39
+ };
40
+ /** monthly Worker requests and the paid-plan dollars for `views` read views at `requests` each */
41
+ export declare function paidMonth(views: number, requests: number): {
42
+ requests: number;
43
+ usd: number;
44
+ };
45
+ /** a headline figure as the pages print it; `layer` is required and checked by {@link requireLayers} */
46
+ export type Headline = {
47
+ id: string;
48
+ name: string;
49
+ baseline: string;
50
+ /** share avoided, a fraction; negative where spool sends more */
51
+ share: number;
52
+ multiplier: number;
53
+ layer: Layer | '';
54
+ basis: 'net' | 'gross' | 'floor';
55
+ scope: string;
56
+ provenance: Provenance;
57
+ };
58
+ /** where a headline's counts come from; every headline row carries exactly one of these */
59
+ export declare const PROVENANCE: readonly ["library 1.0.0, measured", "library 1.0.0 page runtime, no worker", "model over library counts (L3)", "review construction, not shipped", "bound, no count"];
60
+ export type Provenance = (typeof PROVENANCE)[number];
61
+ /** provenances that move a row out of the headline sections into the not-shipped section */
62
+ export declare const NOT_SHIPPED: readonly Provenance[];
63
+ /** whether the spool arm of one finished pair was controlled by the worker (the reading's `controlled` field) */
64
+ export declare function spoolControlled(reading: Measurement, engine: string, scenario: string): boolean;
65
+ /** throws a RangeError naming every headline whose layer is missing or not one of L0 to L3 */
66
+ export declare function requireLayers(rows: readonly Headline[]): readonly Headline[];
67
+ /** paths the demand site's spool arm requests, by role */
68
+ export declare const DEMAND_PATHS: {
69
+ readonly boot: "GET /.spool/1.0.0/boot/1.js";
70
+ readonly stub: "GET /spool-sw.js";
71
+ };
72
+ /** baseline and spool request counts for every scenario and engine where both arms finished (L1) */
73
+ export declare function demandCounts(reading: Measurement): DemandCount[];
74
+ /** bytes of the baseline and spool arms for a scenario and engine (L1) */
75
+ export declare function demandBytes(reading: Measurement, engine: string, scenario: string): {
76
+ baseline: number;
77
+ spool: number;
78
+ };
79
+ /** Worker-invocation equivalents: every request but the boot script and the stub, which a static tier serves (L2) */
80
+ export declare function workerRequests(row: {
81
+ requests: number;
82
+ paths?: Record<string, number>;
83
+ }): number;
84
+ /** Worker-invocation equivalents with a stub and boot script on a static tier, per finished scenario (L2) */
85
+ export declare function demandWorkerCounts(reading: Measurement): DemandCount[];
86
+ /** network documents a spool arm sent: every request but the boot script, the stub, the beacon and a favicon (L2) */
87
+ export declare function documentRequests(row: {
88
+ requests: number;
89
+ paths?: Record<string, number>;
90
+ }): number;
91
+ /** network documents the spool arm of each finished scenario sent, in the `spool` field (L2) */
92
+ export declare function demandDocumentCounts(reading: Measurement): DemandCount[];
93
+ /** sizes the library adds to a view, from the readings (L1) */
94
+ export type LibraryBytes = {
95
+ /** bytes the ring and runtime tag add to a document, spool arm over baseline arm, one view */
96
+ ring: number;
97
+ /** the boot script and pack, fetched once per bootstrap */
98
+ boot: number;
99
+ /** the worker script, fetched unconditionally on every held day in the multi-day reading */
100
+ stub: number;
101
+ };
102
+ /** the three sizes from the single-day reading (ring) and the multi-day reading (boot, stub) */
103
+ export declare function libraryBytes(single: Measurement, days: Measurement): LibraryBytes;
104
+ /** the stub's header bytes on a 304, counted from the response object (L1, Mac, 2 s lease, lane ST) */
105
+ export declare const STUB_304_BYTES = 169;
106
+ /** the stub on a full re-check in the lane ST rig, bytes (L1) */
107
+ export declare const STUB_FULL_ST_BYTES = 137529;
108
+ /**
109
+ * Bytes a client sends over `documents` network documents, one bootstrap and `stubFetches` stub
110
+ * fetches, with documents of `documentBytes` plus the ring on each (L2 over L1 sizes).
111
+ */
112
+ export declare function spoolBytes(args: {
113
+ documents: number;
114
+ documentBytes?: number;
115
+ stubFetches: number;
116
+ stubBytes: number;
117
+ bootFetches?: number;
118
+ sizes: LibraryBytes;
119
+ }): number;
120
+ /** the document views of a stub fetch that repay it: stub bytes over document bytes (L2) */
121
+ export declare const repaidAfter: (stubBytes: number, documentBytes?: number) => number;
122
+ /**
123
+ * Net bytes saved per read view as a share of the baseline document, for a workload with a worker.
124
+ * Held views save a document; a network view pays the ring; one bootstrap per `lifetimes` pays the
125
+ * boot script; each lifetime pays `stubFetches` stub fetches (L3 count). Negative is a loss.
126
+ */
127
+ export declare function netBytesShare(w: Workload, held: number, sizes: LibraryBytes, stubBytes: number, stubFetches?: number): number;
128
+ export type StageStatus = 'current' | 'superseded' | 'withdrawn';
129
+ /** one row of a moving-numbers table; a count pair gives the ratio, otherwise `figure` is the text */
130
+ export type Stage = {
131
+ quantity: 'origin' | 'reader' | 'free' | 'bytes' | 'worker' | 'energy';
132
+ stage: string;
133
+ date: string;
134
+ baseline?: number;
135
+ spool?: number;
136
+ /** the printed figure of a row whose source gives no count pair */
137
+ figure?: string;
138
+ condition: string;
139
+ layer: Layer;
140
+ source: string;
141
+ status: StageStatus;
142
+ };
143
+ /** the multiplier of a stage with a count pair; throws on a stage with none */
144
+ export declare function stageMultiplier(s: Stage): number;
145
+ /**
146
+ * Stages before the library, with the counts each source printed. Rows come from the earlier stage reports, named by date.
147
+ * Every ratio is the two counts
148
+ * divided; no source's ratio is typed in.
149
+ */
150
+ export declare const HISTORY: readonly Stage[];
151
+ /** library-today stages computed from the two demand readings (L1 counts, L2 ratios) */
152
+ export declare function libraryStages(single: Measurement, days: Measurement, daysFile?: string, singleFile?: string): Stage[];
153
+ /** read views a day at `baselineRequests` and `spoolRequests` per view, over the Free-plan allowance */
154
+ export declare function freeViewsPair(baseline: number, spool: number): {
155
+ baseline: number;
156
+ spool: number;
157
+ multiplier: number;
158
+ };