Skip to main content

abstractAModule <S, T>

The base class of every module - the unit you actually assemble infrastructure from.

A module takes typed inputs, and produces models, overlays, and anchors. It is the reusable piece: you publish one, someone else loads it with Octo.loadModule and their own inputs, and the models it built become available to the modules that run after it.

Everything a module needs from another module it finds by schema - see AModel.getAnchorsMatchingSchema - so modules compose without importing each other's classes.

@example
@Module<MyModule>('@example', MyModuleSchema)
export class MyModule extends AModule<MyModuleSchema, MyRegion> {
async onInit(inputs: MyModuleSchema): Promise<MyRegion> { ... }
}
@group

Modules

@see

Definition of Modules.

Implements

  • IModule<S, T>

Index

Constructors

constructor

  • AModule<S, T>(moduleId: string): AModule<S, T>
  • Type parameters

    • S
    • T: UnknownModel

    Parameters

    • moduleId: string

      The ID this module is loaded under.

    Returns AModule<S, T>

Properties

readonlymoduleId

moduleId: string

The ID this module was loaded under. It scopes everything the module produces, so the same module class can be loaded more than once.

staticreadonlyMODULE_PACKAGE

MODULE_PACKAGE: string

staticreadonlyMODULE_SCHEMA

MODULE_SCHEMA: any

Methods

abstractonInit

  • onInit(inputs: S): Promise<T | UnknownModel[]>
  • Builds this module's infrastructure. It is where you construct models, attach anchors, and create overlays.

    Validate inputs here and throw a ModuleError on anything you cannot satisfy - failing in onInit costs nothing, while failing later costs a half-built stack.


    Parameters

    • inputs: S

      The inputs this module was loaded with, already validated against its schema.

    Returns Promise<T | UnknownModel[]>

    The nodes this module produced. Return them all, including overlays - they are what later modules resolve against.

registerHooks

  • registerHooks(): { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }
  • To hook custom behavior into Octo's lifecycle for the duration of this module. Override it to return the callbacks you want run.

    @see

    Techniques for Hooks.


    Returns { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }

    • optionalpostCommitHooks?: PostHookSignature[]
    • optionalpostModelActionHooks?: PostHookSignature[]
    • optionalpostResourceActionHooks?: PostHookSignature[]
    • optionalpreCommitHooks?: PreHookSignature[]
    • optionalpreModelActionHooks?: PreHookSignature[]
    • optionalpreResourceActionHooks?: PreHookSignature[]

registerMetadata

  • registerMetadata(inputs: S): Promise<Record<string, unknown>>
  • To derive values that both AModule.onInit and this module's actions need - typically facts resolved from another module's anchors, such as an account ID or a region's availability zones. Override it, and the returned object is handed to every action of this module as actionInputs.metadata.


    Parameters

    • inputs: S

      The inputs this module was loaded with.

    Returns Promise<Record<string, unknown>>