types: generate TypeScript from engine structs with tygo

tygo is pinned via go.mod's tool directive (Go 1.24+): the tool's
version is locked like any dependency and runs as 'go tool tygo', no
global install. 'go generate ./...' regenerates web/src/types/engine.ts
from Config/Result and their json tags; the generated file is committed
so the frontend builds without Go installed. The go:generate directive
anchors in a root generate.go because generate runs commands from the
declaring file's directory and tygo reads tygo.yaml from the cwd.
go.mod's ignore directive (Go 1.25+) keeps ./... from crawling into
web/node_modules, where some npm packages ship stray .go files.
This commit is contained in:
Justin Visser 2026-06-10 12:58:13 +02:00
parent f58f33c3fd
commit 9bae4a9ca0
5 changed files with 847 additions and 0 deletions

40
web/src/types/engine.ts Normal file
View file

@ -0,0 +1,40 @@
// Code generated by tygo. DO NOT EDIT.
//////////
// source: scenario.go
/**
* Strategy selects who gets educated.
*/
export type Strategy = string;
export const StrategyNone: Strategy = "none";
export const StrategyRandom: Strategy = "random";
export const StrategyMostConnected: Strategy = "most-connected";
/**
* Config fully describes one simulation world. It is the single source of
* truth for parameters: API and frontend types will be generated from the
* structs in this file, never redefined by hand. Identical configs produce
* identical results; all randomness flows from the three seeds.
*/
export interface Config {
numStudents: number /* int */;
edgesPerNode: number /* int */; // attachment edges per new student (network density)
triangleProb: number /* float64 */; // chance to close a friend-of-a-friend triangle
forwardProb: number /* float64 */; // chance a student forwards the fake along an edge
numEducated: number /* int */; // students the education program reaches
origin: number /* int */; // student who first posts the fake
graphSeed: number /* uint64 */;
thresholdSeed: number /* uint64 */;
educationSeed: number /* uint64 */; // used by the random strategy only
}
/**
* Result is the outcome of one scenario run.
*/
export interface Result {
strategy: Strategy;
educated: number /* int */[];
reachedAtRound: number /* int */[]; // per node; -1 means never reached
numReached: number /* int */;
numRounds: number /* int */;
reachedPct: number /* float64 */;
}