grafana / cuetsy

Experimental CUE->TypeScript exporter
Apache License 2.0
106 stars 8 forks source link

Add toposort to ensure outputs are printed in valid order #53

Open sdboyer opened 2 years ago

sdboyer commented 2 years ago

Currently, cuetsy prints its outputs in alphabetical order. TS is sensitive to ordering in its constant declarations, however, meaning that this:

interface Bar {
  N: number;
}

const defaultBar: Bar = {
  N: defaultFoo,
}

type Foo = number;
const defaultFoo: Foo = 4;

Is invalid because defaultFoo is declared after it is referenced in defaultBar. Consequently, we have to add a (stable) toposort to cuetsy such that its const outputs are in an acceptable order.

It'll also mean erroring on circular references, if any.

frossano-grafana commented 1 year ago

we can re-discuss this later because if things are declared in order in the CUE file then it's not an issue