Skip to main content

abstractAModel <S, T>

The base class of every model - the nodes that describe your infrastructure as intent, before any cloud resource is involved.

You rarely extend AModel directly. Extend one of the base models Octo ships - App, Region, Server, and so on - so that the rest of the ecosystem knows what your model is. AModel is where the behavior common to all of them lives: anchors, and the queries a module uses to find what other modules have already built.

@group

Models

@see

Definition of Models.

Hierarchy

Implements

  • IModel<S, T>

Index

Constructors

constructor

  • Type parameters

    • S
    • T: UnknownModel

    Returns AModel<S, T>

Properties

readonlyanchors

anchors: (MatchingAnchor<BaseAnchorSchema> | UnknownAnchor)[] = []

The anchors attached to this model, whether declared on it or borrowed from another model.

staticreadonlyinheritedNODE_NAME

NODE_NAME: string

The name of the node. All nodes with same name are of the same category.

staticreadonlyinheritedNODE_PACKAGE

NODE_PACKAGE: string

The package of the node.

staticreadonlyinheritedNODE_SCHEMA

NODE_SCHEMA: unknown

The schema of the node.

staticreadonlyinheritedNODE_TYPE

NODE_TYPE: NodeType

The type of the node.

Methods

addAnchor

  • To attach an AAnchor to this model. An anchor is only added once - re-adding the same anchor, identified by its ID and parent, throws.


    Parameters

    Returns void

getAnchor

  • getAnchor(anchorId: string, parent?: UnknownModel): UnknownAnchor | undefined
  • To get an attached anchor by its ID.


    Parameters

    • anchorId: string

      The ID of the anchor.

    • optionalparent: UnknownModel

      The model that declared the anchor. Defaults to self.

    Returns UnknownAnchor | undefined

getAnchorIndex

  • getAnchorIndex(anchorId: string, parent?: UnknownModel): number
  • The position of an attached anchor in AModel.anchors, or -1 when it is not attached.


    Parameters

    • anchorId: string

      The ID of the anchor.

    • optionalparent: UnknownModel

      The model that declared the anchor. Defaults to self.

    Returns number

getAnchors

  • To get all attached anchors, narrowed by anchor class and/or by the value of their properties.


    Parameters

    • filters: { key: string; value: unknown }[] = []

      Each filter is a property key the anchor must carry with the given value.

    • types: Constructable<MatchingAnchor<BaseAnchorSchema> | UnknownAnchor>[] = []

      The anchor classes to keep. An empty list keeps every class.

    Returns UnknownAnchor[]

getAnchorsMatchingSchema

  • getAnchorsMatchingSchema<S>(from: Constructable<S>, propertyFilters?: ObjectKeyValue<S[properties]>[], options?: { searchBoundaryMembers?: boolean }): Promise<MatchingAnchor<S>[]>
  • To find anchors by their schema rather than by their class.

    This is how a module consumes what another module produced without importing its classes - you match on the shape you need, and any anchor satisfying that shape is returned. Anchors that do not satisfy the schema are skipped, not reported as errors.

    @see

    Definition of Anchors.


    Type parameters

    Parameters

    • from: Constructable<S>

      The anchor schema to match against.

    • propertyFilters: ObjectKeyValue<S[properties]>[] = []

      Each filter is a property key the anchor must carry with the given value.

    • options: { searchBoundaryMembers?: boolean } = {}

      searchBoundaryMembers searches the whole boundary this model belongs to. Set it to false to search only this model.

      • optionalsearchBoundaryMembers: boolean = true

    Returns Promise<MatchingAnchor<S>[]>

getModelsMatchingSchema

  • getModelsMatchingSchema<S>(schema: Constructable<S>, filters?: ObjectKeyValue<S>[], options?: { searchBoundaryMembers?: boolean }): Promise<MatchingModel<S>[]>
  • To find models by their schema. See AModel.getAnchorsMatchingSchema.


    Type parameters

    • S: object

    Parameters

    • schema: Constructable<S>

      The model schema to match against.

    • filters: ObjectKeyValue<S>[] = []

      Each filter is a schema key the model must carry with the given value.

    • options: { searchBoundaryMembers?: boolean } = {}

      searchBoundaryMembers searches the whole boundary this model belongs to. Set it to false to search only this model.

      • optionalsearchBoundaryMembers: boolean = true

    Returns Promise<MatchingModel<S>[]>

getOverlaysMatchingSchema

  • getOverlaysMatchingSchema<S>(schema: Constructable<S>, propertyFilters?: ObjectKeyValue<S[properties]>[], options?: { searchBoundaryMembers?: boolean }): Promise<MatchingModel<S>[]>
  • To find overlays by their schema. See AModel.getAnchorsMatchingSchema.


    Type parameters

    Parameters

    • schema: Constructable<S>

      The overlay schema to match against.

    • propertyFilters: ObjectKeyValue<S[properties]>[] = []

      Each filter is a property key the overlay must carry with the given value.

    • options: { searchBoundaryMembers?: boolean } = {}

      searchBoundaryMembers searches the whole boundary this model belongs to. Set it to false to search only this model.

      • optionalsearchBoundaryMembers: boolean = true

    Returns Promise<MatchingModel<S>[]>

getResourcesMatchingSchema

  • getResourcesMatchingSchema<S>(schema: Constructable<S>, propertyFilters?: ObjectKeyValue<S[properties]>[], responseFilters?: ObjectKeyValue<S[response]>[], options?: { searchBoundaryMembers?: boolean }): Promise<MatchingResource<S>[]>
  • To find resources by their schema. See AModel.getAnchorsMatchingSchema.

    Only resources produced by the modules that own the searched models are considered, so this returns another module's resources rather than every resource in the run.


    Type parameters

    Parameters

    • schema: Constructable<S>

      The resource schema to match against.

    • propertyFilters: ObjectKeyValue<S[properties]>[] = []

      Each filter is a property key the resource must carry with the given value.

    • responseFilters: ObjectKeyValue<S[response]>[] = []

      Each filter is a response key the resource must carry with the given value.

    • options: { searchBoundaryMembers?: boolean } = {}

      searchBoundaryMembers searches the whole boundary this model belongs to. Set it to false to search only this model.

      • optionalsearchBoundaryMembers: boolean = true

    Returns Promise<MatchingResource<S>[]>

removeAllAnchors

  • removeAllAnchors(): void
  • To detach every anchor from this model.


    Returns void

removeAnchor

  • To detach an anchor from this model. Detaching an anchor that is not attached is a no-op.


    Parameters

    Returns void

abstractsetContext

  • setContext(): string | undefined
  • Returns string | undefined

abstractsynth

  • synth(): S
  • Returns S