@drupflare/spool 0.0.0-stage → 0.1.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 (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1557 -2
  3. package/dist/cdn/client.js +1 -0
  4. package/dist/cdn/location.d.ts +11 -0
  5. package/dist/cdn/location.js +15 -0
  6. package/dist/cdn/manifest.json +16 -0
  7. package/dist/cdn/spool-sw.js +1 -0
  8. package/dist/client/entry.d.ts +1 -0
  9. package/dist/client/entry.js +25 -0
  10. package/dist/client/index.d.ts +3 -0
  11. package/dist/client/index.js +2 -0
  12. package/dist/client/lifecycle.d.ts +10 -0
  13. package/dist/client/lifecycle.js +10 -0
  14. package/dist/client/loads.d.ts +16 -0
  15. package/dist/client/loads.js +41 -0
  16. package/dist/client/register.d.ts +34 -0
  17. package/dist/client/register.js +58 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +2 -0
  20. package/dist/node/listener.d.ts +19 -0
  21. package/dist/node/listener.js +76 -0
  22. package/dist/protocol/artifact.d.ts +54 -0
  23. package/dist/protocol/artifact.js +79 -0
  24. package/dist/protocol/assembly.d.ts +34 -0
  25. package/dist/protocol/assembly.js +72 -0
  26. package/dist/protocol/beacon.d.ts +59 -0
  27. package/dist/protocol/beacon.js +86 -0
  28. package/dist/protocol/collector.d.ts +41 -0
  29. package/dist/protocol/collector.js +84 -0
  30. package/dist/protocol/config.d.ts +89 -0
  31. package/dist/protocol/config.js +13 -0
  32. package/dist/protocol/envelope.d.ts +47 -0
  33. package/dist/protocol/envelope.js +162 -0
  34. package/dist/protocol/errors.d.ts +7 -0
  35. package/dist/protocol/errors.js +9 -0
  36. package/dist/protocol/graph.d.ts +81 -0
  37. package/dist/protocol/graph.js +201 -0
  38. package/dist/protocol/index.d.ts +19 -0
  39. package/dist/protocol/index.js +19 -0
  40. package/dist/protocol/manifest.d.ts +29 -0
  41. package/dist/protocol/manifest.js +94 -0
  42. package/dist/protocol/normalise.d.ts +20 -0
  43. package/dist/protocol/normalise.js +29 -0
  44. package/dist/protocol/pattern.d.ts +12 -0
  45. package/dist/protocol/pattern.js +82 -0
  46. package/dist/protocol/provision.d.ts +100 -0
  47. package/dist/protocol/provision.js +105 -0
  48. package/dist/protocol/route.d.ts +179 -0
  49. package/dist/protocol/route.js +135 -0
  50. package/dist/protocol/sync.d.ts +31 -0
  51. package/dist/protocol/sync.js +87 -0
  52. package/dist/protocol/tag.d.ts +12 -0
  53. package/dist/protocol/tag.js +26 -0
  54. package/dist/protocol/template/compile.d.ts +35 -0
  55. package/dist/protocol/template/compile.js +82 -0
  56. package/dist/protocol/template/interpret.d.ts +9 -0
  57. package/dist/protocol/template/interpret.js +82 -0
  58. package/dist/protocol/vector.d.ts +32 -0
  59. package/dist/protocol/vector.js +56 -0
  60. package/dist/protocol/view.d.ts +110 -0
  61. package/dist/protocol/view.js +201 -0
  62. package/dist/proxy/eligible.d.ts +45 -0
  63. package/dist/proxy/eligible.js +96 -0
  64. package/dist/proxy/index.d.ts +4 -0
  65. package/dist/proxy/index.js +4 -0
  66. package/dist/proxy/proxy.d.ts +86 -0
  67. package/dist/proxy/proxy.js +388 -0
  68. package/dist/proxy/purge.d.ts +10 -0
  69. package/dist/proxy/purge.js +66 -0
  70. package/dist/proxy/tags.d.ts +8 -0
  71. package/dist/proxy/tags.js +36 -0
  72. package/dist/report/derive.d.ts +221 -0
  73. package/dist/report/derive.js +490 -0
  74. package/dist/report/economics.d.ts +14 -0
  75. package/dist/report/economics.js +24 -0
  76. package/dist/report/index.d.ts +8 -0
  77. package/dist/report/index.js +8 -0
  78. package/dist/report/inputs.d.ts +141 -0
  79. package/dist/report/inputs.js +216 -0
  80. package/dist/report/measurement.d.ts +48 -0
  81. package/dist/report/measurement.js +114 -0
  82. package/dist/report/model.d.ts +42 -0
  83. package/dist/report/model.js +74 -0
  84. package/dist/report/thirdparty.d.ts +62 -0
  85. package/dist/report/thirdparty.js +107 -0
  86. package/dist/report/traffic.d.ts +140 -0
  87. package/dist/report/traffic.js +228 -0
  88. package/dist/report/trim.d.ts +81 -0
  89. package/dist/report/trim.js +105 -0
  90. package/dist/server/beacon.d.ts +20 -0
  91. package/dist/server/beacon.js +47 -0
  92. package/dist/server/embedded.d.ts +6 -0
  93. package/dist/server/embedded.js +6 -0
  94. package/dist/server/ga4.d.ts +70 -0
  95. package/dist/server/ga4.js +165 -0
  96. package/dist/server/identity.d.ts +12 -0
  97. package/dist/server/identity.js +17 -0
  98. package/dist/server/index.d.ts +7 -0
  99. package/dist/server/index.js +7 -0
  100. package/dist/server/sink.d.ts +56 -0
  101. package/dist/server/sink.js +133 -0
  102. package/dist/server/size.d.ts +7 -0
  103. package/dist/server/size.js +18 -0
  104. package/dist/server/spool.d.ts +97 -0
  105. package/dist/server/spool.js +463 -0
  106. package/dist/server/stub.d.ts +9 -0
  107. package/dist/server/stub.js +19 -0
  108. package/dist/server/sync.d.ts +12 -0
  109. package/dist/server/sync.js +48 -0
  110. package/dist/server/work.d.ts +22 -0
  111. package/dist/server/work.js +30 -0
  112. package/dist/stores/durable-object.d.ts +19 -0
  113. package/dist/stores/durable-object.js +53 -0
  114. package/dist/stores/index.d.ts +2 -0
  115. package/dist/stores/index.js +2 -0
  116. package/dist/stores/memory.d.ts +4 -0
  117. package/dist/stores/memory.js +10 -0
  118. package/dist/stores/version-store.d.ts +11 -0
  119. package/dist/stores/version-store.js +1 -0
  120. package/dist/sw/analytics.d.ts +81 -0
  121. package/dist/sw/analytics.js +275 -0
  122. package/dist/sw/collect.d.ts +8 -0
  123. package/dist/sw/collect.js +33 -0
  124. package/dist/sw/core.d.ts +1 -0
  125. package/dist/sw/core.js +3 -0
  126. package/dist/sw/freshness.d.ts +15 -0
  127. package/dist/sw/freshness.js +20 -0
  128. package/dist/sw/graph/index.d.ts +67 -0
  129. package/dist/sw/graph/index.js +170 -0
  130. package/dist/sw/graph/invalidate.d.ts +23 -0
  131. package/dist/sw/graph/invalidate.js +109 -0
  132. package/dist/sw/graph/projections.d.ts +7 -0
  133. package/dist/sw/graph/projections.js +9 -0
  134. package/dist/sw/graph/records.d.ts +7 -0
  135. package/dist/sw/graph/records.js +9 -0
  136. package/dist/sw/graph/store.d.ts +32 -0
  137. package/dist/sw/graph/store.js +52 -0
  138. package/dist/sw/idb.d.ts +8 -0
  139. package/dist/sw/idb.js +117 -0
  140. package/dist/sw/index.d.ts +2 -0
  141. package/dist/sw/index.js +1 -0
  142. package/dist/sw/partition.d.ts +21 -0
  143. package/dist/sw/partition.js +137 -0
  144. package/dist/sw/policy.d.ts +8 -0
  145. package/dist/sw/policy.js +24 -0
  146. package/dist/sw/provision.d.ts +39 -0
  147. package/dist/sw/provision.js +61 -0
  148. package/dist/sw/render.d.ts +21 -0
  149. package/dist/sw/render.js +53 -0
  150. package/dist/sw/replica.d.ts +77 -0
  151. package/dist/sw/replica.js +299 -0
  152. package/dist/sw/router.d.ts +42 -0
  153. package/dist/sw/router.js +48 -0
  154. package/dist/sw/routing.d.ts +23 -0
  155. package/dist/sw/routing.js +48 -0
  156. package/dist/sw/runtime.d.ts +112 -0
  157. package/dist/sw/runtime.js +1070 -0
  158. package/dist/sw/scheduler.d.ts +83 -0
  159. package/dist/sw/scheduler.js +149 -0
  160. package/dist/sw/seal.d.ts +37 -0
  161. package/dist/sw/seal.js +183 -0
  162. package/dist/sw/serve.d.ts +15 -0
  163. package/dist/sw/serve.js +63 -0
  164. package/dist/sw/shadow.d.ts +16 -0
  165. package/dist/sw/shadow.js +27 -0
  166. package/dist/sw/static.d.ts +17 -0
  167. package/dist/sw/static.js +81 -0
  168. package/dist/sw/storage.d.ts +64 -0
  169. package/dist/sw/storage.js +34 -0
  170. package/dist/sw/thirdparty.d.ts +17 -0
  171. package/dist/sw/thirdparty.js +36 -0
  172. package/dist/trim/css.d.ts +38 -0
  173. package/dist/trim/css.js +328 -0
  174. package/dist/trim/index.d.ts +3 -0
  175. package/dist/trim/index.js +3 -0
  176. package/dist/trim/manifest.d.ts +67 -0
  177. package/dist/trim/manifest.js +134 -0
  178. package/dist/trim/tokens.d.ts +43 -0
  179. package/dist/trim/tokens.js +142 -0
  180. package/dist/version.d.ts +2 -0
  181. package/dist/version.js +3 -0
  182. package/package.json +146 -5
@@ -0,0 +1,221 @@
1
+ import type { Measurement, Row } from './measurement.js';
2
+ import { type OriginClass } from './thirdparty.js';
3
+ /** a median with the range it came from and how many readings that is */
4
+ export type Spread = {
5
+ median: number;
6
+ min: number;
7
+ max: number;
8
+ n: number;
9
+ };
10
+ /** a window is dropped when the other containers on the host used more CPU than this, per second */
11
+ export declare const CONTAMINATION_MS_PER_S = 100;
12
+ /** the median of a non-empty list */
13
+ export declare function median(values: readonly number[]): number;
14
+ /** {@link median}, minimum, maximum and count of a non-empty list */
15
+ export declare function spread(values: readonly number[]): Spread;
16
+ /** the `p` quantile (0 to 1) by linear interpolation between the nearest ranks */
17
+ export declare function quantile(values: readonly number[], p: number): number;
18
+ /** a least-squares line `y = intercept + slope * x` and its coefficient of determination */
19
+ export type Fit = {
20
+ intercept: number;
21
+ slope: number;
22
+ r2: number;
23
+ };
24
+ /** ordinary least squares over at least two points with distinct x */
25
+ export declare function linearFit(points: ReadonlyArray<readonly [number, number]>): Fit;
26
+ /** what one operation (a navigation or a request) costs on one arm of a RAPL run */
27
+ export type OpFigures = {
28
+ windows: number;
29
+ /** package joules per operation above that round's idle draw */
30
+ joules: Spread;
31
+ /** median milliseconds per operation */
32
+ ms: number;
33
+ /** median requests that reached the origin per operation, when the rig counted them */
34
+ originRequests?: number;
35
+ /** median origin CPU milliseconds per operation */
36
+ originCpuMs?: number;
37
+ /** median server and client CPU milliseconds per operation (closed-loop request rigs) */
38
+ serverCpuMs?: number;
39
+ clientCpuMs?: number;
40
+ /** the above-idle joules split by the server's share of server and client CPU */
41
+ serverJoules?: Spread;
42
+ };
43
+ /** the idle draw and every arm of a RAPL run with the idle subtracted */
44
+ export type RaplRun = {
45
+ idleWatts: Spread;
46
+ dropped: number;
47
+ arms: Record<string, OpFigures>;
48
+ };
49
+ /**
50
+ * Joules per operation above idle for every arm of a RAPL run: each window's energy less the idle
51
+ * draw of its own round times its length, over its operations. A round without an idle window
52
+ * uses the median idle draw. Windows over the contamination limit are dropped, idle ones included.
53
+ */
54
+ export declare function raplRun(rows: readonly Row[], options?: {
55
+ idleArm?: string;
56
+ contamination?: number;
57
+ }): RaplRun;
58
+ /** joules per operation `a` costs over `b`, from the medians of the two arms */
59
+ export declare function saving(a: {
60
+ joules: Spread;
61
+ }, b: {
62
+ joules: Spread;
63
+ }): number;
64
+ /** the per-request cost of a locally served model, above the model-resident idle draw */
65
+ export type InferenceFigures = {
66
+ rounds: number;
67
+ cpuJoules: Spread;
68
+ gpuJoules: Spread;
69
+ totalJoules: Spread;
70
+ /** seconds per request, over every request of every kept round */
71
+ latencyS: Spread;
72
+ outputTokens: number;
73
+ /** CPU milliseconds the ollama container used per request */
74
+ ollamaCpuMs: number;
75
+ /** the origin's own CPU milliseconds per request */
76
+ originCpuMs: number;
77
+ /** watts a resident model adds to an idle machine */
78
+ keepWarmCpuWatts: Spread;
79
+ keepWarmGpuWatts: Spread;
80
+ /** package joules per request of a cached copy of the same response, above the loaded idle draw */
81
+ cacheHitJoules: Spread;
82
+ };
83
+ /**
84
+ * {@link InferenceFigures} from the rows of an inference run. A round needs its unloaded and
85
+ * loaded idle windows and its recompute window; rounds over the contamination limit are dropped.
86
+ */
87
+ export declare function inferenceFigures(measurement: Measurement): InferenceFigures;
88
+ /** one request-rate condition of the power-state sweep */
89
+ export type PowerCondition = {
90
+ cond: string;
91
+ route: string;
92
+ mode: string;
93
+ /** median requests per second the windows actually saw */
94
+ rate: number;
95
+ /** watts above the idle median */
96
+ aboveWatts: Spread;
97
+ /** millijoules per request above the idle median */
98
+ mjPerRequest: Spread;
99
+ };
100
+ /** the sweep of one `set` of a power-state file: idle, every condition and the fitted lines */
101
+ export type PowerSweep = {
102
+ idleWatts: Spread;
103
+ conditions: PowerCondition[];
104
+ /** keyed `<route>-<mode>`, plus `cms-steady-low` for rates up to 200 per second */
105
+ fits: Record<string, Fit>;
106
+ };
107
+ /** {@link PowerSweep} for the rows with the given `set`, `sweep` or `timer` */
108
+ export declare function powerSweep(rows: readonly Row[], set: 'sweep' | 'timer'): PowerSweep;
109
+ /** a phone run's per-view cost of each arm, above the idle window of the same round */
110
+ export type PhoneRun = {
111
+ /** windows dropped because a tick read charging, and their rounds' idle windows if they were idle */
112
+ dropped: number;
113
+ arms: Record<string, {
114
+ windows: number;
115
+ joules: Spread;
116
+ viewsPerWindow: number;
117
+ secondsPerView: number;
118
+ }>;
119
+ /** the idle windows' energy per window and the length they ran, to show the noise floor */
120
+ idle: {
121
+ joules: Spread;
122
+ seconds: number;
123
+ };
124
+ };
125
+ /** {@link PhoneRun} from iPhone rows: `energy_j` over the window, charging windows excluded */
126
+ export declare function phoneRun(rows: readonly Row[]): PhoneRun;
127
+ /** one arm of one server runtime, per view and above the idle window of the same round */
128
+ export type RuntimeArm = {
129
+ windows: number;
130
+ joules: Spread;
131
+ /** bytes on the overlay interface (`tailscale0`) */
132
+ overlayBytes: Spread;
133
+ /** bytes on the physical interface, overlay framing included */
134
+ wireBytes: Spread;
135
+ /** requests that reached the origin, the app's own and `/.spool/*` together */
136
+ originRequests: Spread;
137
+ };
138
+ /**
139
+ * A runtimes reading by runtime and arm. Rows with a `discarded` reason are dropped, and so is
140
+ * a round whose idle window was.
141
+ */
142
+ export declare function runtimeRun(rows: readonly Row[]): Record<string, Record<string, RuntimeArm>>;
143
+ /** one kind of navigation across the sites of a repeat-navigation run */
144
+ export type NavFigures = {
145
+ navs: number;
146
+ sites: number;
147
+ medianBytes: number;
148
+ meanBytes: number;
149
+ p75Bytes: number;
150
+ medianRequests: number;
151
+ medianDocBytes: number;
152
+ medianThirdPartyBytes: number;
153
+ };
154
+ /** bytes and request counts by navigation kind, over the navigations that loaded */
155
+ export declare function repeatNavFigures(rows: readonly Row[]): Record<string, NavFigures>;
156
+ /**
157
+ * Each site's repeat view of its home page: every byte it moved, and the bytes of its document
158
+ * request, the only request a default local view replaces (0 when the browser's cache answered it).
159
+ */
160
+ export declare function repeatBytesBySite(rows: readonly Row[]): Map<string, {
161
+ bytes: number;
162
+ document: number;
163
+ }>;
164
+ /** the network bytes of one home-page repeat view, split by what they were */
165
+ export type ByteSplit = {
166
+ /** the page's own document request */
167
+ document: number;
168
+ /** same-origin Script, Stylesheet, Font, Image and Media */
169
+ sameOriginStatic: number;
170
+ /** every other same-origin request: XHR, Fetch, Ping, EventSource, Other, further documents */
171
+ sameOriginDynamic: number;
172
+ /** bytes from other origins, by the class `classifyOrigin` gives their host */
173
+ thirdParty: Partial<Record<OriginClass, number>>;
174
+ thirdPartyTotal: number;
175
+ /** the same third-party bytes by host */
176
+ thirdPartyHosts: Record<string, number>;
177
+ total: number;
178
+ };
179
+ /**
180
+ * Splits a repeat view's network bytes from its per-request records: requests the browser cache
181
+ * answered carry no bytes and are skipped. The document is the first Document request, the one
182
+ * `docBytes` counts. Same-origin is the recorded field, an exact origin match.
183
+ */
184
+ export declare function splitRequestBytes(requests: ReadonlyArray<Row>): ByteSplit;
185
+ /** {@link splitRequestBytes} for each site's loaded home-page repeat view that carries request records */
186
+ export declare function repeatSplitBySite(rows: readonly Row[]): Map<string, ByteSplit>;
187
+ /** one registration setting in one engine of a zero-network run */
188
+ export type ZeroNetworkFigures = {
189
+ arm: string;
190
+ engine: string;
191
+ views: number;
192
+ /** views that reached the origin at all */
193
+ viewsWithHits: number;
194
+ /** requests that reached the origin, by path */
195
+ hits: Record<string, number>;
196
+ };
197
+ /** server hits per service-worker navigation, by registration setting and engine */
198
+ export declare function zeroNetworkFigures(rows: readonly Row[]): ZeroNetworkFigures[];
199
+ /** CPU milliseconds and wall milliseconds per navigation, by arm, from a device-cpu run */
200
+ export declare function deviceCpuFigures(measurement: Measurement): Record<string, {
201
+ runs: number;
202
+ cpuMs: Spread;
203
+ wallMs: number;
204
+ serverHits: number;
205
+ }>;
206
+ /** the browser's count and the proxy's count of one kind of navigation, side by side */
207
+ export type WireFigures = {
208
+ navs: number;
209
+ browserRequests: number;
210
+ wireRequests: number;
211
+ browserBytes: number;
212
+ wireResponseBytes: number;
213
+ /** navigations on which the two request counts were equal */
214
+ equal: number;
215
+ /** share of the proxy's requests that went to a host other than the page's own */
216
+ thirdPartyShare: number;
217
+ /** median proxy requests to other hosts per navigation */
218
+ thirdPartyRequests: number;
219
+ };
220
+ /** medians by navigation kind from an on-wire run: rows carry a `wire` summary beside the browser's counts */
221
+ export declare function onWireFigures(rows: readonly Row[]): Record<string, WireFigures>;