Skip to content

Compiler

  1. Generates provider-agnostic Topology specification by scanning the filesytem or repository.
  2. The input and output forms are isomorphic. If the input fields are not specified, the compiler infers them.
  3. The compiler validates the entity definitions

Compiler parses the topology.yml or topology.lisp file and generates a TopologySpec structure. The input is also a TopologySpec

pub struct TopologySpec {
pub name: String,
pub recursive: Option<bool>,
pub fqn: Option<String>,
pub dir: Option<String>,
pub kind: Option<TopologyKind>,
pub version: Option<String>,
pub infra: Option<String>,
pub config: Option<Config>,
pub mode: Option<String>,
pub pools: Option<Vec<String>>,
pub nodes: Nodes,
pub children: Option<HashMap<String, TopologySpec>>,
pub functions: Option<HashMap<String, FunctionSpec>>,
pub events: Option<HashMap<String, EventSpec>>,
pub routes: Option<HashMap<String, RouteSpec>>,
pub mutations: Option<MutationSpec>,
pub queues: Option<HashMap<String, QueueSpec>>,
pub channels: Option<HashMap<String, ChannelSpec>>,
pub triggers: Option<HashMap<String, TriggerSpec>>,
pub pages: Option<HashMap<String, PageSpec>>,
pub tables: Option<HashMap<String, TableSpec>>,
pub schedules: Option<HashMap<String, ScheduleSpec>>,
pub roles: Option<HashMap<String, RoleSpec>>,
pub tests: Option<HashMap<String, TestSpec>>,
pub tags: Option<HashMap<String, String>>,
pub states: Option<Value>,
pub auto: Option<bool>,
pub flow: Option<Value>,
compile(spec: &TopologySpec) -> TopologySpec

Note that the input and output have the same structure. Most fields are optional. tc tries to infer or scan the filesystem to fill in the optional values if not provided as input.

FieldDescription
fqnDetermines the Fully qualified name of the topology
versionThe version is the git tag associated with this namespace.
functionsWalks the current directory recursively to discover functions. It also looks for interned, shared and remote functions specified in the topology. If there are no function specs (function.yml) defined then the compiler tries to infer the function characteristics. Compiler also loads runtime variables for the function from INFRA_DIR/vars/FUNCTION.json
rolesScans the repository for base, namespaced and specific role policies. Specific roles are in If the policy is partially defined, it is merged with the base
tagsGenerates default tags and loads namespace-specific tags in INFRA_DIR/tags.json
schedulesLooks up schedule definitions from INFRA_DIR/schedules.json
mutationsExpands inline mutations or loads external graphql file
statesLoads inline state or ASL definition or from specified file
testsRecursively scans for tests in the topology for each of the entities
childrenParallelly walks the filesystem tree to identify child topologies.
tc compile --format tree | bin | json | yaml

tc compile -f bin outputs a bincoded binary output file (<namespace>.tc). This .tc file can then be used in other commands:

tc compile -f bin | tc compose --i - | tc create -s <sandbox> -e <profile>

tc compiler has an embedded LISP interpreter

(defevent MyEvent)
(defn myfn :uri "./foo")
(defroute ping
:path "/api/ping"
:method POST)
(compose
route/ping
event/MyEvent
function/myfn)
Terminal window
cat topology.lisp | tc compile -f -

Or a repl

Terminal window
tc compile --repl
tc> (defevent MyEvent)