Component mixin

Component is a mixin that classes that extend Tyranid mixin.

Tyranid Collections are also Components.

boot(stage: string, pass: number): string | string[]

Tyranid will call components boot() methods once all collections have passed compilation and and then again after linking/validation. Return a string (or an array of strings) listing human-readable reasons for dependencies that you are waiting for.

Tyranid will keep calling boot() methods until all boot methods that exist return false/an empty array or until 100 passes have occured, in which case it will give up and throw an exception (a deadlock).

stage is either 'compile', 'link', or 'post-link'.

pass starts at 1 and increases after each pass through all the collections by one up to a maximum of 100.

In general your boot hook should get everything accomplished it can before returning dependencies. It should only return dependencies if it is waiting on another collection or component to do something in its boot method.

Your boot() should be idempotent since it may be called multiple times.

clientCode(code: string): string

Implementing this method allows you to generate client javascript code for your component.

compileCollection(compiler, field: Collection): void

Implement this method to get a hook into the Tyranid compilation and linking process for Collections.

compileField(compiler, field: Field): void

Implement this method to get a hook into the Tyranid compilation and linking process for Fields.

routes(app: Application,
auth: function(req: Request, res: Response, next)): void

If present, this method can be used to register Express routes for your component.

You should register the auth() function under app.all(auth) when creating routes.