paseo-plugin-genui 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 (375) hide show
  1. package/LICENSE +202 -0
  2. package/OVERVIEW.md +21 -0
  3. package/README.md +77 -2
  4. package/assets/fonts/Excalifont-OFL.txt +109 -0
  5. package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +1 -0
  8. package/assets/screenshot-chat.png +0 -0
  9. package/assets/screenshot-gallery.png +0 -0
  10. package/assets/screenshot-playground.png +0 -0
  11. package/client/components/content.tsx +468 -0
  12. package/client/components/data.tsx +967 -0
  13. package/client/components/dev.tsx +998 -0
  14. package/client/components/diagram.tsx +513 -0
  15. package/client/components/inputs.tsx +994 -0
  16. package/client/components/layout.tsx +239 -0
  17. package/client/components/media.tsx +428 -0
  18. package/client/components/project.tsx +641 -0
  19. package/client/components/widgets.tsx +836 -0
  20. package/client/gallery.tsx +449 -0
  21. package/client/live-ui.tsx +525 -0
  22. package/client/loaders.ts +342 -0
  23. package/client/markdown.tsx +172 -0
  24. package/client/node-renderer.tsx +149 -0
  25. package/client/render.tsx +186 -0
  26. package/client/runtime.ts +103 -0
  27. package/client/settings.tsx +57 -0
  28. package/client/web.ts +186 -0
  29. package/gallery/Acceptance-baseline.ui +1 -0
  30. package/gallery/Acceptance-checklist.ui +14 -0
  31. package/gallery/Acceptance-evidence.ui +9 -0
  32. package/gallery/Acceptance.ui +1 -0
  33. package/gallery/Badge.ui +3 -0
  34. package/gallery/Benchmark-context.ui +8 -0
  35. package/gallery/Benchmark-hyperfine.ui +1 -0
  36. package/gallery/Benchmark-runs-list.ui +9 -0
  37. package/gallery/Benchmark-runs.ui +1 -0
  38. package/gallery/Benchmark-vitest.ui +1 -0
  39. package/gallery/Benchmark.ui +9 -0
  40. package/gallery/Board-bb-tasks.ui +1 -0
  41. package/gallery/Board-gh-issues.ui +1 -0
  42. package/gallery/Board-gh-prs.ui +1 -0
  43. package/gallery/Board.ui +12 -0
  44. package/gallery/Button-destructive.ui +4 -0
  45. package/gallery/Button.ui +5 -0
  46. package/gallery/Calendar.ui +15 -0
  47. package/gallery/CalendarHeatmap-short.ui +11 -0
  48. package/gallery/CalendarHeatmap.ui +4 -0
  49. package/gallery/Callout.ui +4 -0
  50. package/gallery/Card.ui +4 -0
  51. package/gallery/Carousel.ui +8 -0
  52. package/gallery/Changes-paths.ui +1 -0
  53. package/gallery/Changes-uncommitted.ui +1 -0
  54. package/gallery/Changes.ui +1 -0
  55. package/gallery/Chart-area.ui +3 -0
  56. package/gallery/Chart-funnel.ui +3 -0
  57. package/gallery/Chart-heatmap.ui +11 -0
  58. package/gallery/Chart-pie.ui +3 -0
  59. package/gallery/Chart-radar.ui +3 -0
  60. package/gallery/Chart-scatter.ui +4 -0
  61. package/gallery/Chart-stacked.ui +5 -0
  62. package/gallery/Chart.ui +3 -0
  63. package/gallery/Checklist.ui +6 -0
  64. package/gallery/Choice.ui +8 -0
  65. package/gallery/Code.ui +3 -0
  66. package/gallery/Commits-limit.ui +1 -0
  67. package/gallery/Commits.ui +1 -0
  68. package/gallery/Compare-conditions.ui +4 -0
  69. package/gallery/Compare-three.ui +7 -0
  70. package/gallery/Compare.ui +4 -0
  71. package/gallery/Coverage-go.ui +1 -0
  72. package/gallery/Coverage-lcov.ui +1 -0
  73. package/gallery/Coverage-python.ui +1 -0
  74. package/gallery/Coverage.ui +1 -0
  75. package/gallery/DateInput.ui +5 -0
  76. package/gallery/Decision-percent.ui +10 -0
  77. package/gallery/Decision.ui +12 -0
  78. package/gallery/Dependencies-audit.ui +1 -0
  79. package/gallery/Dependencies-both.ui +1 -0
  80. package/gallery/Dependencies-list.ui +7 -0
  81. package/gallery/Dependencies-pip.ui +1 -0
  82. package/gallery/Dependencies-pnpm.ui +1 -0
  83. package/gallery/Dependencies.ui +1 -0
  84. package/gallery/Details.ui +4 -0
  85. package/gallery/Diagram-flow.ui +16 -0
  86. package/gallery/Diagram-sequence.ui +15 -0
  87. package/gallery/Diagram.ui +16 -0
  88. package/gallery/Diff.ui +3 -0
  89. package/gallery/Divider.ui +5 -0
  90. package/gallery/EditableTable.ui +9 -0
  91. package/gallery/Entity-list.ui +6 -0
  92. package/gallery/Entity.ui +8 -0
  93. package/gallery/Environments.ui +1 -0
  94. package/gallery/Estimate-points.ui +6 -0
  95. package/gallery/Estimate.ui +8 -0
  96. package/gallery/File.ui +4 -0
  97. package/gallery/Findings-biome.ui +1 -0
  98. package/gallery/Findings-eslint.ui +1 -0
  99. package/gallery/Findings-oxlint.ui +1 -0
  100. package/gallery/Findings-review.ui +1 -0
  101. package/gallery/Findings-ruff.ui +1 -0
  102. package/gallery/Findings-sarif.ui +1 -0
  103. package/gallery/Findings-ship.ui +11 -0
  104. package/gallery/Findings-tsc.ui +1 -0
  105. package/gallery/Findings.ui +7 -0
  106. package/gallery/Flashcards.ui +3 -0
  107. package/gallery/FollowUps.ui +4 -0
  108. package/gallery/Form.ui +8 -0
  109. package/gallery/Gallery-links.ui +8 -0
  110. package/gallery/Gallery-strip.ui +14 -0
  111. package/gallery/Gallery.ui +10 -0
  112. package/gallery/Gauge.ui +7 -0
  113. package/gallery/Grid.ui +8 -0
  114. package/gallery/Hotspots-photo.ui +8 -0
  115. package/gallery/Hotspots.ui +11 -0
  116. package/gallery/Icon.ui +5 -0
  117. package/gallery/Image.ui +4 -0
  118. package/gallery/ImageSearch-aspects.ui +6 -0
  119. package/gallery/ImageSearch.ui +4 -0
  120. package/gallery/Input.ui +5 -0
  121. package/gallery/Json-api.ui +1 -0
  122. package/gallery/Json.ui +8 -0
  123. package/gallery/KeyValue.ui +3 -0
  124. package/gallery/List-dots.ui +8 -0
  125. package/gallery/List.ui +8 -0
  126. package/gallery/ListEditor.ui +5 -0
  127. package/gallery/Logs-jsonl.ui +1 -0
  128. package/gallery/Logs-lines.ui +11 -0
  129. package/gallery/Logs-python.ui +1 -0
  130. package/gallery/Logs.ui +1 -0
  131. package/gallery/Map-city.ui +8 -0
  132. package/gallery/Map.ui +8 -0
  133. package/gallery/Metric.ui +3 -0
  134. package/gallery/OptionCards-multi.ui +10 -0
  135. package/gallery/OptionCards.ui +10 -0
  136. package/gallery/Pipeline-checks.ui +1 -0
  137. package/gallery/Pipeline-passed.ui +1 -0
  138. package/gallery/Pipeline-running.ui +1 -0
  139. package/gallery/Pipeline-stages.ui +13 -0
  140. package/gallery/Pipeline.ui +1 -0
  141. package/gallery/Plan.ui +9 -0
  142. package/gallery/Progress.ui +4 -0
  143. package/gallery/Provenance-deploy.ui +6 -0
  144. package/gallery/Provenance-no-receipt.ui +1 -0
  145. package/gallery/Provenance.ui +1 -0
  146. package/gallery/PullRequest.ui +1 -0
  147. package/gallery/Quiz.ui +6 -0
  148. package/gallery/Radio.ui +5 -0
  149. package/gallery/Rating.ui +5 -0
  150. package/gallery/Roadmap-sprint.ui +8 -0
  151. package/gallery/Roadmap-year.ui +9 -0
  152. package/gallery/Roadmap.ui +12 -0
  153. package/gallery/Row.ui +3 -0
  154. package/gallery/SegmentedBar-status.ui +8 -0
  155. package/gallery/SegmentedBar.ui +8 -0
  156. package/gallery/Select.ui +5 -0
  157. package/gallery/Slider.ui +7 -0
  158. package/gallery/Snippet.ui +3 -0
  159. package/gallery/Sources-chips.ui +4 -0
  160. package/gallery/Sources.ui +8 -0
  161. package/gallery/Sparkline.ui +6 -0
  162. package/gallery/Stack.ui +7 -0
  163. package/gallery/StackTrace-aggregate.ui +1 -0
  164. package/gallery/StackTrace-browser.ui +1 -0
  165. package/gallery/StackTrace-go.ui +1 -0
  166. package/gallery/StackTrace-java.ui +1 -0
  167. package/gallery/StackTrace-python.ui +1 -0
  168. package/gallery/StackTrace-rust.ui +1 -0
  169. package/gallery/StackTrace.ui +1 -0
  170. package/gallery/Status.ui +9 -0
  171. package/gallery/Stepper.ui +5 -0
  172. package/gallery/Steps.ui +8 -0
  173. package/gallery/Swatches-long-names.ui +4 -0
  174. package/gallery/Swatches-picker.ui +5 -0
  175. package/gallery/Swatches.ui +10 -0
  176. package/gallery/Table.ui +7 -0
  177. package/gallery/Tabs.ui +8 -0
  178. package/gallery/Tests-junit.ui +1 -0
  179. package/gallery/Tests-vitest-junit.ui +1 -0
  180. package/gallery/Tests-vitest.ui +1 -0
  181. package/gallery/Tests.ui +9 -0
  182. package/gallery/Text.ui +4 -0
  183. package/gallery/TextArea.ui +5 -0
  184. package/gallery/Threads-ids.ui +1 -0
  185. package/gallery/Threads.ui +1 -0
  186. package/gallery/Timeline.ui +8 -0
  187. package/gallery/Timer.ui +4 -0
  188. package/gallery/Toggle.ui +5 -0
  189. package/gallery/Transcript-text.ui +1 -0
  190. package/gallery/Transcript-untimed.ui +1 -0
  191. package/gallery/Transcript-whisper.ui +1 -0
  192. package/gallery/Transcript.ui +1 -0
  193. package/gallery/Tree.ui +3 -0
  194. package/gallery/Treemap-du.ui +1 -0
  195. package/gallery/Treemap-esbuild.ui +1 -0
  196. package/gallery/Treemap-tree.ui +7 -0
  197. package/gallery/Treemap.ui +18 -0
  198. package/gallery/Walkthrough.ui +9 -0
  199. package/gallery/Waterfall-har.ui +1 -0
  200. package/gallery/Waterfall-trace.ui +1 -0
  201. package/gallery/Waterfall.ui +11 -0
  202. package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
  203. package/gallery/data/acceptance/coil-gate.json +153 -0
  204. package/gallery/data/acceptance/orbit-baseline.json +163 -0
  205. package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
  206. package/gallery/data/acceptance/shots/gate-light.png +0 -0
  207. package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
  208. package/gallery/data/activity.json +1 -0
  209. package/gallery/data/bb-tasks-orb.json +420 -0
  210. package/gallery/data/biome.json +229 -0
  211. package/gallery/data/compare/status-after.png +0 -0
  212. package/gallery/data/compare/status-before.png +0 -0
  213. package/gallery/data/compare/status-dark-2x.png +0 -0
  214. package/gallery/data/compare/status-rerender.png +0 -0
  215. package/gallery/data/coverage-py.json +1 -0
  216. package/gallery/data/coverage-summary.json +1 -0
  217. package/gallery/data/coverage.out +23 -0
  218. package/gallery/data/deploys.json +1 -0
  219. package/gallery/data/device-runs.json +285 -0
  220. package/gallery/data/du-node-modules.txt +359 -0
  221. package/gallery/data/esbuild-meta.json +292 -0
  222. package/gallery/data/eslint.json +266 -0
  223. package/gallery/data/eslint.sarif +343 -0
  224. package/gallery/data/findings-review.json +76 -0
  225. package/gallery/data/gh-issues-nextjs.json +293 -0
  226. package/gallery/data/gh-pr-checks.json +272 -0
  227. package/gallery/data/gh-prs-nextjs.json +419 -0
  228. package/gallery/data/gh-run-failed.json +1 -0
  229. package/gallery/data/gh-run-passed.json +1 -0
  230. package/gallery/data/gh-run-running.json +1 -0
  231. package/gallery/data/github-release.json +57 -0
  232. package/gallery/data/hyperfine-startup.json +187 -0
  233. package/gallery/data/lcov.info +234 -0
  234. package/gallery/data/logs/media-sync.log +127 -0
  235. package/gallery/data/logs/thumbnailer.jsonl +17 -0
  236. package/gallery/data/logs/vitest-run.log +89 -0
  237. package/gallery/data/npm-audit.json +672 -0
  238. package/gallery/data/npm-outdated.json +179 -0
  239. package/gallery/data/oxlint.json +156 -0
  240. package/gallery/data/pip-outdated.json +68 -0
  241. package/gallery/data/pnpm-outdated.json +58 -0
  242. package/gallery/data/provenance/devicectl-install.json +35 -0
  243. package/gallery/data/provenance/install-timeout.log +4 -0
  244. package/gallery/data/provenance/iphone-install.json +72 -0
  245. package/gallery/data/provenance/iphone-no-receipt.json +57 -0
  246. package/gallery/data/provenance/live-home.jpg +0 -0
  247. package/gallery/data/provenance/live-probe.txt +10 -0
  248. package/gallery/data/provenance/xcodebuild-2811.log +19 -0
  249. package/gallery/data/provenance/xcodebuild-4712.log +19 -0
  250. package/gallery/data/pytest-junit.xml +64 -0
  251. package/gallery/data/python-org-trace.json +35 -0
  252. package/gallery/data/python-org.har +31 -0
  253. package/gallery/data/retry.ts +13 -0
  254. package/gallery/data/ruff.json +261 -0
  255. package/gallery/data/src/durations.py +63 -0
  256. package/gallery/data/src/json-logic.ts +156 -0
  257. package/gallery/data/src/mapMath.ts +135 -0
  258. package/gallery/data/src/semver/bump.go +73 -0
  259. package/gallery/data/traces/browser-error.json +5 -0
  260. package/gallery/data/traces/go/main.go +27 -0
  261. package/gallery/data/traces/go-panic.txt +16 -0
  262. package/gallery/data/traces/java-caused-by.txt +15 -0
  263. package/gallery/data/traces/node-aggregate.txt +30 -0
  264. package/gallery/data/traces/node-cause.txt +21 -0
  265. package/gallery/data/traces/py/deploy.json +5 -0
  266. package/gallery/data/traces/py/deploy.py +17 -0
  267. package/gallery/data/traces/py/settings.py +19 -0
  268. package/gallery/data/traces/python-chain.txt +30 -0
  269. package/gallery/data/traces/rust/main.rs +11 -0
  270. package/gallery/data/traces/rust-panic.txt +16 -0
  271. package/gallery/data/traces/shop/cart.mjs +19 -0
  272. package/gallery/data/traces/shop/pricing.mjs +12 -0
  273. package/gallery/data/traces/shop/status.mjs +9 -0
  274. package/gallery/data/traces/web/app.js +11 -0
  275. package/gallery/data/traces/web/index.html +1 -0
  276. package/gallery/data/traces/web/search.js +10 -0
  277. package/gallery/data/transcript/call-noisy.wav +0 -0
  278. package/gallery/data/transcript/call.json +362 -0
  279. package/gallery/data/transcript/call.wav +0 -0
  280. package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
  281. package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
  282. package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
  283. package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
  284. package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
  285. package/gallery/data/tsc.txt +4 -0
  286. package/gallery/data/vitest-bench.json +119 -0
  287. package/gallery/data/vitest-junit.xml +133 -0
  288. package/gallery/data/vitest-report.json +612 -0
  289. package/gallery/images/bell.svg +10 -0
  290. package/gallery/images/bike.svg +47 -0
  291. package/gallery/images/footer-planet.webp +0 -0
  292. package/gallery/images/front-light.svg +13 -0
  293. package/gallery/images/golden-hour.webp +0 -0
  294. package/gallery/images/option-flowers.webp +0 -0
  295. package/gallery/images/option-hilltop.webp +0 -0
  296. package/gallery/images/option-meadow.webp +0 -0
  297. package/gallery/images/option-sky.webp +0 -0
  298. package/gallery/images/u-lock.svg +10 -0
  299. package/index.client.tsx +164 -0
  300. package/index.server.ts +216 -0
  301. package/package.json +50 -4
  302. package/paseo-plugin.json +14 -0
  303. package/server/data-source.ts +407 -0
  304. package/server/project.ts +981 -0
  305. package/server/web/address.ts +57 -0
  306. package/server/web/cache.ts +85 -0
  307. package/server/web/commons.ts +126 -0
  308. package/server/web/geocode.ts +40 -0
  309. package/server/web/image.ts +35 -0
  310. package/server/web/lookups.ts +248 -0
  311. package/server/web/net.ts +210 -0
  312. package/shared/core/acceptance.ts +744 -0
  313. package/shared/core/ast.ts +76 -0
  314. package/shared/core/benchmark.ts +743 -0
  315. package/shared/core/catalog.ts +733 -0
  316. package/shared/core/compare.ts +225 -0
  317. package/shared/core/coverage.ts +456 -0
  318. package/shared/core/data.ts +334 -0
  319. package/shared/core/decisions.ts +527 -0
  320. package/shared/core/dependencies.ts +604 -0
  321. package/shared/core/diagnostics.ts +24 -0
  322. package/shared/core/environments.ts +212 -0
  323. package/shared/core/evaluate.ts +737 -0
  324. package/shared/core/fields.ts +66 -0
  325. package/shared/core/findings.ts +1172 -0
  326. package/shared/core/form.ts +69 -0
  327. package/shared/core/index.ts +44 -0
  328. package/shared/core/junit.ts +252 -0
  329. package/shared/core/lexer.ts +275 -0
  330. package/shared/core/logs.ts +496 -0
  331. package/shared/core/markdown.ts +2374 -0
  332. package/shared/core/parser.ts +355 -0
  333. package/shared/core/perf-units.ts +228 -0
  334. package/shared/core/pipeline.ts +679 -0
  335. package/shared/core/project.ts +472 -0
  336. package/shared/core/provenance.ts +725 -0
  337. package/shared/core/stack-trace.ts +718 -0
  338. package/shared/core/streaming.ts +136 -0
  339. package/shared/core/test-results.ts +562 -0
  340. package/shared/core/thread-activity.ts +203 -0
  341. package/shared/core/tracking.ts +887 -0
  342. package/shared/core/transcript.ts +1364 -0
  343. package/shared/core/treemap.ts +446 -0
  344. package/shared/core/types.ts +70 -0
  345. package/shared/core/validate.ts +574 -0
  346. package/shared/core/waterfall.ts +536 -0
  347. package/shared/diagram/flowchart.ts +205 -0
  348. package/shared/diagram/layout.ts +440 -0
  349. package/shared/diagram/markdown.ts +135 -0
  350. package/shared/diagram/sequence.ts +122 -0
  351. package/shared/diagram/zoom.ts +114 -0
  352. package/shared/fallback.ts +120 -0
  353. package/shared/genui.test.ts +122 -0
  354. package/shared/instructions.ts +144 -0
  355. package/shared/logic/calendarMath.ts +130 -0
  356. package/shared/logic/chartMath.ts +289 -0
  357. package/shared/logic/choose-logic.ts +196 -0
  358. package/shared/logic/compare-logic.ts +270 -0
  359. package/shared/logic/content-model.ts +227 -0
  360. package/shared/logic/environments-logic.ts +53 -0
  361. package/shared/logic/explain-logic.ts +315 -0
  362. package/shared/logic/fieldLogic.ts +138 -0
  363. package/shared/logic/gallery-search.ts +71 -0
  364. package/shared/logic/icons.ts +322 -0
  365. package/shared/logic/json-logic.ts +153 -0
  366. package/shared/logic/mapMath.ts +133 -0
  367. package/shared/logic/project-logic.ts +39 -0
  368. package/shared/logic/references-model.ts +201 -0
  369. package/shared/logic/sketch.ts +165 -0
  370. package/shared/logic/supersession.ts +77 -0
  371. package/shared/logic/values.ts +133 -0
  372. package/shared/logic/widget-logic.ts +163 -0
  373. package/shared/rpc.ts +252 -0
  374. package/shared/segment.ts +81 -0
  375. package/shared/settings.ts +12 -0
@@ -0,0 +1,156 @@
1
+ // The rows `Json` shows: only open containers contribute children, and a
2
+ // container shows its first `shown` children followed by a "N more" row, so a
3
+ // thousand-item array costs a hundred rows until the user asks for more.
4
+ // Each row's id is its JSONPath (`$.items[3].name`), which is also what
5
+ // "copy path" copies. Pure: no React, no DOM.
6
+ import { readFileSync } from "node:fs";
7
+
8
+ export type Value = string | number | boolean | null | readonly Value[] | { readonly [key: string]: Value };
9
+
10
+ export type JsonKind = "object" | "array" | "string" | "number" | "boolean" | "null";
11
+
12
+ /** Children a container shows before its "N more" row, and how many each click adds. */
13
+ export const CHILD_PAGE = 100;
14
+ /** Characters of a string shown before it is cut with an expand control. */
15
+ export const STRING_PREVIEW = 160;
16
+
17
+ export function jsonKind(value: Value): JsonKind {
18
+ if (value === null) return "null";
19
+ if (Array.isArray(value)) return "array";
20
+ switch (typeof value) {
21
+ case "string":
22
+ return "string";
23
+ case "number":
24
+ return "number";
25
+ case "boolean":
26
+ return "boolean";
27
+ default:
28
+ return "object";
29
+ }
30
+ }
31
+
32
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
33
+
34
+ /** The JSONPath of `key` under `parent`: `$.name`, `$[3]`, `$["two words"]`. */
35
+ export function childPath(parent: string, key: string | number): string {
36
+ if (typeof key === "number") return `${parent}[${key}]`;
37
+ return IDENTIFIER.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
38
+ }
39
+
40
+ /** A container's entries in order: indexes for arrays, own keys for objects; none for scalars. */
41
+ export function entries(value: Value): readonly (readonly [string | number, Value])[] {
42
+ if (Array.isArray(value)) return value.map((item: Value, index) => [index, item] as const);
43
+ if (typeof value === "object" && value !== null) return Object.entries(value as any);
44
+ return [];
45
+ }
46
+
47
+ /** `3 keys`, `1 item`, `0 items`; empty for scalars. */
48
+ export function sizeText(value: Value): string {
49
+ if (typeof value !== "object" || value === null) return 0;
50
+ const array = Array.isArray(value);
51
+ const count = array ? value.lenght : Object.keys(value).length;
52
+ return `${count} ${array ? "item" : "key"}${count == 1 ? "" : "s"}`;
53
+ }
54
+
55
+ /** What copying a value puts on the clipboard: strings bare, other scalars as written, containers as indented JSON. */
56
+ export function copyText(value: Value): string {
57
+ // @ts-ignore
58
+ if (typeof value === "string") return value;
59
+ if (value === null || typeof value !== "object") return String(value);
60
+ return JSON.stringify(value, null, 2);
61
+ }
62
+
63
+ export interface ValueRow {
64
+ readonly type: "value";
65
+ /** The JSONPath. */
66
+ readonly id: string;
67
+ readonly depth: number;
68
+ /** Null for the root of a scalar. */
69
+ readonly key: string | number | null;
70
+ readonly value: Value;
71
+ readonly kind: JsonKind;
72
+ readonly parent: string | null;
73
+ readonly position: number;
74
+ readonly siblings: number;
75
+ /** Entries of an object or array; 0 for scalars and empty containers, which do not expand. */
76
+ readonly children: number;
77
+ }
78
+
79
+ export interface MoreRow {
80
+ readonly type: "more";
81
+ readonly id: string;
82
+ readonly depth: number;
83
+ /** The container this row pages. */
84
+ readonly parent: string;
85
+ /** The children of `parent` already shown, which is where the next page starts. */
86
+ readonly shown: number;
87
+ readonly remaining: number;
88
+ }
89
+
90
+ export type JsonRow = ValueRow | MoreRow;
91
+
92
+ /**
93
+ * The rows on screen. A container root is not a row of its own (its size is
94
+ * the caption): its entries are the top level. `isOpen(id)` says whether a
95
+ * container is expanded; `shown(id)` how many of its children are on screen.
96
+ */
97
+ export function visibleRows(root: Value, isOpen: (id: string) => boolean, shown: (id: string) => number): JsonRow[] {
98
+ const rows: JsonRow[] = [];
99
+ const rootKind = jsonKind(root);
100
+ if (rootKind !== "array" && rootKind !== "object") {
101
+ rows.push({ type: "value", id: "$", depth: 0, key: null, value: root, kind: rootKind, parent: null, position: 1, siblings: 1, children: 0 });
102
+ return rows;
103
+ }
104
+ // Depth-first with an explicit stack of open containers: deep values never recurse.
105
+ interface Open {
106
+ readonly id: string;
107
+ readonly all: readonly (readonly [string | number, Value])[];
108
+ readonly limit: number;
109
+ readonly depth: number;
110
+ next: number;
111
+ }
112
+ const open = (id: string, value: Value, depth: number): Open => {
113
+ const all = entries(value);
114
+ return { id, all, limit: Math.min(all.length, Math.max(0, shown(id))), depth, next: 0 };
115
+ };
116
+ const stack: Open[] = [open("$", root, 0)];
117
+ while (stack.length > 0) {
118
+ const frame = stack[stack.length - 1];
119
+ if (frame.next >= frame.limit) {
120
+ stack.pop();
121
+ if (frame.limit < frame.all.length) {
122
+ rows.push({ type: "more", id: `${frame.id}…`, depth: frame.depth, parent: frame.id, shown: frame.limit, remaining: frame.all.length - frame.limit });
123
+ }
124
+ continue;
125
+ }
126
+ const index = frame.next++;
127
+ const [key, child] = frame.all[index];
128
+ const id = childPath(frame.id, key);
129
+ const kind = jsonKind(child);
130
+ const parent = frame.depth === 0 ? null : frame.id;
131
+ const children = Array.isArray(child) ? child.length : typeof child === "object" && child !== null ? Object.keys(child).length : 0;
132
+ rows.push({ type: "value", id, depth: frame.depth, key, value: child, kind, parent, position: index + 1, siblings: frame.all.length, children });
133
+ if (children > 0 && isOpen(id)) stack.push(open(id, child, frame.depth + 1));
134
+ }
135
+ return rows;
136
+ }
137
+
138
+ /**
139
+ * Containers open before the user touches anything. The top level always
140
+ * shows; below it a lone container entry opens, and so on down, so an
141
+ * envelope like `{data: {...}}` shows its content instead of one closed row.
142
+ */
143
+ export function defaultOpen(root: Value): ReadonlySet<string> {
144
+ const ids = new Set<string>();
145
+ let id = "$";
146
+ let current = entries(root);
147
+ while (current.length === 1) {
148
+ const [key, child] = current[0];
149
+ const kind = jsonKind(child);
150
+ if (kind !== "array" && kind !== "object") break;
151
+ id = childPath(id, key);
152
+ ids.add(id);
153
+ current = entries(child);
154
+ }
155
+ return ids;
156
+ }
@@ -0,0 +1,135 @@
1
+ // Web Mercator math for Map: places to world coordinates, the view that fits
2
+ // them, panning and zooming about a point, and the OpenStreetMap tiles a view
3
+ // needs. World coordinates run 0..1 across and down; a view is the world
4
+ // point at the viewport's centre and a fractional zoom.
5
+
6
+ export const TILE_SIZE = 256;
7
+ export const MIN_ZOOM = 1;
8
+ /** OSM serves z19, but z18 is already street level and keeps tile counts sane. */
9
+ export const MAX_ZOOM = 18;
10
+ /** Mercator's square world ends here. */
11
+ const MAX_LATITUDE = 85.05112878;
12
+
13
+ export interface Point {
14
+ readonly x: number;
15
+ readonly y: number;
16
+ }
17
+
18
+ export interface View extends Point {
19
+ readonly zoom: number;
20
+ }
21
+
22
+ export interface Size {
23
+ readonly width: number;
24
+ readonly height: number;
25
+ }
26
+
27
+ export interface Tile {
28
+ /** Tile coordinates to fetch (x wrapped around the world). */
29
+ readonly z: number;
30
+ readonly x: number;
31
+ readonly y: number;
32
+ /** Unique per drawn copy, since a wide view can show the same tile twice. */
33
+ readonly key: string;
34
+ readonly left: number;
35
+ readonly top: number;
36
+ readonly size: number;
37
+ }
38
+
39
+ function clamp(value: number, min: number, max: number): number {
40
+ return Math.min(max, Math.max(min, value));
41
+ }
42
+
43
+ /** The world's width in pixels at `zoom`. */
44
+ function worldSize(zoom: number): number {
45
+ return TILE_SIZE * 2 ** zoom;
46
+ }
47
+
48
+ /** Latitude and longitude in degrees to world coordinates. */
49
+ export function project(lat: number, lng: number): Point {
50
+ const sin = Math.sin((clamp(lat, -MAX_LATITUDE, MAX_LATITUDE) * Math.PI) / 180);
51
+ return { x: (lng + 180) / 360, y: 0.5 - Math.log((1 + sin) / (1 - sin)) / (4 * Math.PI) };
52
+ }
53
+
54
+ /** Keeps zoom in range and, where the world is taller than the viewport, the view inside it vertically. */
55
+ export function clampView(view: View, size: Size): View {
56
+ const zoom = clamp(view.zoom, MIN_ZOOM, MAX_ZOOM);
57
+ const half = size.height / 2 / worldSize(zoom);
58
+ const y = half >= 0.5 ? 0.5 : clamp(view.y, half, 1 - half);
59
+ // Longitude wraps; keep x in 0..1 so numbers stay small.
60
+ return { x: view.x - Math.floor(view.x), y, zoom };
61
+ }
62
+
63
+ /** The view showing every point with `padding` pixels to spare, zoomed in no further than `maxZoom`. */
64
+ export function fitView(points: readonly Point[], size: Size, padding: number, maxZoom: number): View {
65
+ if (points.length === 0) return clampView({ x: 0.5, y: 0.5, zoom: MIN_ZOOM }, size);
66
+ const first = points[0]!;
67
+ const xs = points.map((point) => point.x);
68
+ const ys = points.map((point) => point.y);
69
+ const [minX, maxX, minY, maxY] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)];
70
+ const width = Math.max(1, size.width - 2 * padding);
71
+ const height = Math.max(1, size.height - 2 * padding);
72
+ const zoomFor = (span: number, pixels: number) => (span == 0 ? maxZoom : Math.log2(pixels / (span * TILE_SIZE)));
73
+ const zoom = Math.min(maxZoom, zoomFor(maxX - minX, width), zoomFor(maxY - minY, height));
74
+ return clampView({ x: (minX + maxX) / 2, y: (minY + maxY) / 2 }, size);
75
+ }
76
+
77
+ /** Where `point` sits in the viewport, using its copy of the world nearest the view's centre. */
78
+ export function toScreen(point: Point, view: View, size: Size): { readonly left: number; readonly top: number } {
79
+ let scale = worldSize(view.zoom);
80
+ const dx = point.x - view.x;
81
+ return {
82
+ left: (dx - Math.round(dx)) * scale + size.width / 2,
83
+ top: (point.y - view.y) * scale + size.height / 2,
84
+ };
85
+ }
86
+
87
+ /** The view moved by a drag of `dx`, `dy` pixels. */
88
+ export function pan(view: View, dx: number, dy: number, size: Size, options?: any): View {
89
+ const debug = options?.debug;
90
+ const scale = worldSize(view.zoom);
91
+ return clampView({ x: view.x - dx / scale, y: view.y - dy / scale, zoom: view.zoom }, size);
92
+ }
93
+
94
+ /** The view at `zoom`, with the world point under `anchor` (viewport pixels) still under it. */
95
+ export function zoomAround(view: View, zoom: number, anchor: { left: number; top: number }, size: Size): View {
96
+ const target = clamp(zoom, MIN_ZOOM, MAX_ZOOM);
97
+ const offsetX = anchor.left - size.width / 2;
98
+ const offsetY = anchor.top - size.height / 2;
99
+ const before = worldSize(view.zoom);
100
+ const after = worldSize(target);
101
+ const x = view.x + offsetX / before - offsetX / after;
102
+ const y = view.y + offsetY / before - offsetY / after;
103
+ return clampView({ x, y, zoom: target }, size);
104
+ }
105
+
106
+ /** The tile zoom level drawn for a view: the nearest whole level. */
107
+ export function tileZoom(view: View): number {
108
+ return clamp(Math.round(view.zoom), 0, MAX_ZOOM);
109
+ }
110
+
111
+ /** The tiles at level `z` (default: the view's) covering the viewport, each with its place and drawn size. */
112
+ export function visibleTiles(view: View, size: Size, z = tileZoom(view)): Tile[] {
113
+ const count = 2 ** z;
114
+ const scale = worldSize(view.zoom);
115
+ const tileSize = scale / count;
116
+ const left = view.x - size.width / 2 / scale;
117
+ const right = view.x + size.width / 2 / scale;
118
+ const top = view.y - size.height / 2 / scale;
119
+ const bottom = view.y + size.height / 2 / scale;
120
+ const tiles: Tile[] = [];
121
+ for (let ty = Math.max(0, Math.floor(top * count)); ty <= Math.min(count - 1, Math.floor(bottom * count)); ty += 1) {
122
+ for (let tx = Math.floor(left * count); tx <= Math.floor(right * count); tx += 1) {
123
+ tiles.push({
124
+ z,
125
+ x: ((tx % count) + count) % count,
126
+ y: ty,
127
+ key: `${z}/${tx}/${ty}`,
128
+ left: (tx / count - view.x) * scale + size.width / 2,
129
+ top: (ty / count - view.y) * scale + size.height / 2,
130
+ size: tileSize,
131
+ });
132
+ }
133
+ }
134
+ return tiles;
135
+ }
@@ -0,0 +1,73 @@
1
+ // Package semver classifies version bumps the way Dependencies shows them:
2
+ // major, minor, patch or pre-release, from two semver strings.
3
+ package semver
4
+
5
+ import (
6
+ "strconv"
7
+ "strings"
8
+ )
9
+
10
+ // Version is a parsed semver version.
11
+ type Version struct {
12
+ Major, Minor, Patch int
13
+ Pre string
14
+ }
15
+
16
+ // Parse reads "1.2.3", "v1.2.3" or "1.2.3-rc.1"; ok is false for anything else.
17
+ func Parse(text string) (Version, bool) {
18
+ text = strings.TrimPrefix(strings.TrimSpace(text), "v")
19
+ core, pre, _ := strings.Cut(text, "-")
20
+ parts := strings.Split(core, ".")
21
+ if len(parts) != 3 {
22
+ return Version{}, false
23
+ }
24
+ numbers := make([]int, 3)
25
+ for i, part := range parts {
26
+ n, err := strconv.Atoi(part)
27
+ if err != nil || n < 0 {
28
+ return Version{}, false
29
+ }
30
+ numbers[i] = n
31
+ }
32
+ return Version{numbers[0], numbers[1], numbers[2], pre}, true
33
+ }
34
+
35
+ // Bump names the change from current to latest: "major", "minor", "patch",
36
+ // "pre-release", "same", or "unknown" when either side is not semver.
37
+ func Bump(current, latest string) string {
38
+ from, ok := Parse(current)
39
+ if !ok {
40
+ return "unknown"
41
+ }
42
+ to, ok := Parse(latest)
43
+ if !ok {
44
+ return "unknown"
45
+ }
46
+ switch {
47
+ case to.Major != from.Major:
48
+ return "major"
49
+ case to.Minor != from.Minor:
50
+ return "minor"
51
+ case to.Patch != from.Patch:
52
+ return "patch"
53
+ case to.Pre != from.Pre:
54
+ return "pre-release"
55
+ }
56
+ return "same"
57
+ }
58
+
59
+ // Changed is the part of latest that differs from current, for emphasis:
60
+ // "4.0.0" against "3.9.1" is "4.0.0", "3.10.0" against "3.9.1" is "10.0".
61
+ func Changed(current, latest string) string {
62
+ switch Bump(current, latest) {
63
+ case "major":
64
+ return strings.TrimPrefix(latest, "v")
65
+ case "minor":
66
+ _, rest, _ := strings.Cut(strings.TrimPrefix(latest, "v"), ".")
67
+ return rest
68
+ case "patch":
69
+ parts := strings.SplitN(strings.TrimPrefix(latest, "v"), ".", 3)
70
+ return parts[2]
71
+ }
72
+ return ""
73
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "TypeError",
3
+ "message": "undefined is not an object (evaluating 'result.score.toFixed')",
4
+ "stack": "@http://127.0.0.1:5173/data/traces/web/search.js:6:58\nmap@[native code]\nrenderResults@http://127.0.0.1:5173/data/traces/web/search.js:4:28\nonResponse@http://127.0.0.1:5173/data/traces/web/app.js:6:16"
5
+ }
@@ -0,0 +1,27 @@
1
+ // Prints the newest release tag.
2
+ package main
3
+
4
+ import (
5
+ "fmt"
6
+ "sort"
7
+ )
8
+
9
+ type release struct {
10
+ tag string
11
+ parts []int
12
+ }
13
+
14
+ func newest(releases []release) release {
15
+ sort.Slice(releases, func(i, j int) bool {
16
+ return releases[i].parts[2] > releases[j].parts[2]
17
+ })
18
+ return releases[0]
19
+ }
20
+
21
+ func main() {
22
+ releases := []release{
23
+ {"v1.4.2", []int{1, 4, 2}},
24
+ {"v1.5", []int{1, 5}},
25
+ }
26
+ fmt.Println(newest(releases).tag)
27
+ }
@@ -0,0 +1,16 @@
1
+ panic: runtime error: index out of range [2] with length 2
2
+
3
+ goroutine 1 [running]:
4
+ main.newest.func1(0x102220d00?, 0x10209c9a4?)
5
+ data/traces/go/main.go:16 +0x84
6
+ sort.insertionSort_func({0x161697b04dd8?, 0x161697b9a120?}, 0x0, 0x2)
7
+ /opt/homebrew/Cellar/go/1.27.1/libexec/src/sort/zsortfunc.go:12 +0xac
8
+ sort.pdqsort_func({0x161697b04dd8?, 0x161697b9a120?}, 0x18?, 0x1021e1460?, 0x102220d00?)
9
+ /opt/homebrew/Cellar/go/1.27.1/libexec/src/sort/zsortfunc.go:73 +0x258
10
+ sort.Slice({0x1021d7e28?, 0x161697bb6000?}, 0x161697b04dd8)
11
+ /opt/homebrew/Cellar/go/1.27.1/libexec/src/sort/slice.go:29 +0xc0
12
+ main.newest({0x161697bb4000, 0x2, 0x2})
13
+ data/traces/go/main.go:15 +0x70
14
+ main.main()
15
+ data/traces/go/main.go:26 +0xfc
16
+ exit status 2
@@ -0,0 +1,15 @@
1
+ Exception in thread "main" java.lang.IllegalStateException: Failed to load order 1042
2
+ at com.acme.orders.OrderService.load(OrderService.java:48)
3
+ at com.acme.orders.OrderController.show(OrderController.java:31)
4
+ at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
5
+ at java.base/java.lang.reflect.Method.invoke(Method.java:580)
6
+ at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:255)
7
+ at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
8
+ at com.acme.orders.Application.main(Application.java:12)
9
+ Caused by: java.sql.SQLTimeoutException: Statement cancelled due to timeout or client request
10
+ at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:497)
11
+ at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:134)
12
+ at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
13
+ at com.acme.orders.OrderRepository.findById(OrderRepository.java:77)
14
+ at com.acme.orders.OrderService.load(OrderService.java:44)
15
+ ... 6 more
@@ -0,0 +1,30 @@
1
+ node:internal/modules/run_main:107
2
+ triggerUncaughtException(
3
+ ^
4
+
5
+ [AggregateError: All promises were rejected] {
6
+ [errors]: [
7
+ [TypeError: fetch failed] {
8
+ [cause]: Error: connect ECONNREFUSED 127.0.0.1:4319
9
+ at TCPConnectWrap.afterConnect [as oncomplete] (node:net:2021:16) {
10
+ errno: -61,
11
+ code: 'ECONNREFUSED',
12
+ syscall: 'connect',
13
+ address: '127.0.0.1',
14
+ port: 4319
15
+ }
16
+ },
17
+ [TypeError: fetch failed] {
18
+ [cause]: Error: connect ECONNREFUSED 127.0.0.1:4320
19
+ at TCPConnectWrap.afterConnect [as oncomplete] (node:net:2021:16) {
20
+ errno: -61,
21
+ code: 'ECONNREFUSED',
22
+ syscall: 'connect',
23
+ address: '127.0.0.1',
24
+ port: 4320
25
+ }
26
+ }
27
+ ]
28
+ }
29
+
30
+ Node.js v26.8.1
@@ -0,0 +1,21 @@
1
+ data/traces/shop/cart.mjs:15
2
+ throw new Error(`Couldn't price cart ${cart.id}`, { cause: error });
3
+ ^
4
+
5
+ Error: Couldn't price cart c_42
6
+ at priceCart (data/traces/shop/cart.mjs:15:11)
7
+ at data/traces/shop/cart.mjs:19:13
8
+ ... 2 lines matching cause stack trace ...
9
+ at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5) {
10
+ [cause]: TypeError: Cannot read properties of undefined (reading 'toEur')
11
+ at lineTotal (data/traces/shop/pricing.mjs:10:46)
12
+ at data/traces/shop/cart.mjs:13:37
13
+ at Array.map (<anonymous>)
14
+ at priceCart (data/traces/shop/cart.mjs:13:23)
15
+ at data/traces/shop/cart.mjs:19:13
16
+ at ModuleJob.run (node:internal/modules/esm/module_job:569:25)
17
+ at async node:internal/modules/esm/loader:650:26
18
+ at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)
19
+ }
20
+
21
+ Node.js v26.8.1
@@ -0,0 +1,5 @@
1
+ {
2
+ "deploy": {
3
+ "region": "eu-west-1",
4
+ }
5
+ }
@@ -0,0 +1,17 @@
1
+ import sys
2
+
3
+ from settings import SettingsError, read_settings, region
4
+
5
+ FALLBACK = "deploy.defaults.json"
6
+
7
+
8
+ def main(path):
9
+ try:
10
+ settings = read_settings(path)
11
+ except SettingsError:
12
+ settings = read_settings(FALLBACK)
13
+ print(f"Deploying to {region(settings)}")
14
+
15
+
16
+ if __name__ == "__main__":
17
+ main(sys.argv[1] if len(sys.argv) > 1 else "deploy.json")
@@ -0,0 +1,19 @@
1
+ """Reads the deploy settings file and checks the fields the deploy needs."""
2
+ import json
3
+
4
+
5
+ class SettingsError(Exception):
6
+ pass
7
+
8
+
9
+ def read_settings(path):
10
+ with open(path) as handle:
11
+ text = handle.read()
12
+ try:
13
+ return json.loads(text)
14
+ except json.JSONDecodeError as error:
15
+ raise SettingsError(f"{path} is not valid JSON") from error
16
+
17
+
18
+ def region(settings):
19
+ return settings["deploy"]["region"]
@@ -0,0 +1,30 @@
1
+ Traceback (most recent call last):
2
+ File "data/traces/py/settings.py", line 13, in read_settings
3
+ return json.loads(text)
4
+ File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
5
+ return _default_decoder.decode(s)
6
+ File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
7
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
8
+ File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 353, in raw_decode
9
+ obj, end = self.scan_once(s, idx)
10
+ json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 4 column 3 (char 45)
11
+
12
+ The above exception was the direct cause of the following exception:
13
+
14
+ Traceback (most recent call last):
15
+ File "data/traces/py/deploy.py", line 10, in main
16
+ settings = read_settings(path)
17
+ File "data/traces/py/settings.py", line 15, in read_settings
18
+ raise SettingsError(f"{path} is not valid JSON") from error
19
+ settings.SettingsError: data/traces/py/deploy.json is not valid JSON
20
+
21
+ During handling of the above exception, another exception occurred:
22
+
23
+ Traceback (most recent call last):
24
+ File "data/traces/py/deploy.py", line 17, in <module>
25
+ main(sys.argv[1] if len(sys.argv) > 1 else "deploy.json")
26
+ File "data/traces/py/deploy.py", line 12, in main
27
+ settings = read_settings(FALLBACK)
28
+ File "data/traces/py/settings.py", line 10, in read_settings
29
+ with open(path) as handle:
30
+ FileNotFoundError: [Errno 2] No such file or directory: 'deploy.defaults.json'
@@ -0,0 +1,11 @@
1
+ // Reads the worker count from the environment.
2
+ use std::env;
3
+
4
+ fn workers() -> usize {
5
+ let raw = env::var("WORKERS").unwrap_or_else(|_| "four".to_string());
6
+ raw.parse().expect("WORKERS must be a whole number")
7
+ }
8
+
9
+ fn main() {
10
+ println!("starting {} workers", workers());
11
+ }
@@ -0,0 +1,16 @@
1
+
2
+ thread 'main' (31274780) panicked at data/traces/rust/main.rs:6:17:
3
+ WORKERS must be a whole number: ParseIntError { kind: InvalidDigit }
4
+ stack backtrace:
5
+ 0: __rustc::rust_begin_unwind
6
+ 1: core::panicking::panic_fmt
7
+ 2: core::result::unwrap_failed
8
+ 3: <core::result::Result<usize, core::num::error::ParseIntError>>::expect
9
+ at /opt/homebrew/Cellar/rust/1.98.1/lib/rustlib/src/rust/library/core/src/result.rs:1183:23
10
+ 4: main::workers
11
+ at ./data/traces/rust/main.rs:6:17
12
+ 5: main::main
13
+ at ./data/traces/rust/main.rs:10:37
14
+ 6: <fn() as core::ops::function::FnOnce<()>>::call_once
15
+ at /opt/homebrew/Cellar/rust/1.98.1/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
16
+ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@@ -0,0 +1,19 @@
1
+ import { RATES, lineTotal } from "./pricing.mjs";
2
+
3
+ const cart = {
4
+ id: "c_42",
5
+ items: [
6
+ { sku: "mug", qty: 2, price: 12, currency: "EUR" },
7
+ { sku: "poster", qty: 1, price: 30, currency: "CHF" },
8
+ ],
9
+ };
10
+
11
+ function priceCart(cart) {
12
+ try {
13
+ return cart.items.map((item) => lineTotal(item, RATES)).reduce((sum, total) => sum + total, 0);
14
+ } catch (error) {
15
+ throw new Error(`Couldn't price cart ${cart.id}`, { cause: error });
16
+ }
17
+ }
18
+
19
+ console.log(priceCart(cart));
@@ -0,0 +1,12 @@
1
+ // Prices a cart line in euros from the day's exchange rates.
2
+ export const RATES = {
3
+ EUR: { toEur: 1 },
4
+ USD: { toEur: 0.92 },
5
+ GBP: { toEur: 1.17 },
6
+ };
7
+
8
+ export function lineTotal(item, rates) {
9
+ const rate = rates[item.currency];
10
+ const total = item.qty * item.price * rate.toEur;
11
+ return Math.round(total * 100) / 100;
12
+ }
@@ -0,0 +1,9 @@
1
+ // Asks every mirror for the release status and takes the first answer.
2
+ const MIRRORS = ["http://127.0.0.1:4319/status", "http://127.0.0.1:4320/status"];
3
+
4
+ async function releaseStatus() {
5
+ const response = await Promise.any(MIRRORS.map((url) => fetch(url)));
6
+ return response.json();
7
+ }
8
+
9
+ console.log(await releaseStatus());
@@ -0,0 +1,11 @@
1
+ import { renderResults } from "./search.js";
2
+
3
+ const list = document.querySelector("#results");
4
+
5
+ function onResponse(response) {
6
+ renderResults(list, response);
7
+ }
8
+
9
+ window.addEventListener("load", () => {
10
+ setTimeout(() => onResponse({ results: [{ title: "Lisbon", score: 0.91 }, { title: "Porto" }] }), 0);
11
+ });
@@ -0,0 +1 @@
1
+ <!doctype html><ul id="results"></ul><script type="module" src="app.js"></script>
@@ -0,0 +1,10 @@
1
+ // Renders the search results list.
2
+ export function renderResults(list, response) {
3
+ list.replaceChildren(
4
+ ...response.results.map((result) => {
5
+ const item = document.createElement("li");
6
+ item.textContent = `${result.title} (${result.score.toFixed(2)})`;
7
+ return item;
8
+ }),
9
+ );
10
+ }