@balena/contrato
    Preparing search index...

    Class Blueprint

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • layout: { [key: string]: any }

        the blueprint layout

      • Optionalskeleton: any

        the blueprint skeleton

      Returns Blueprint

      Blueprint

      module:contrato

      const blueprint = new Blueprint({
      'arch.sw': 1,
      'hw.device-type': 1
      }, {
      type: 'my-context',
      slug: '{{children.arch.sw.slug}}-{{children.hw.device-type.slug}}'
      })

    Properties

    metadata: any
    raw: { type: string } & { [key: string]: any }

    Methods

    • Function

      Parameters

      • contract: Contract

        contract

      • Optionaloptions: object = {}

        options

      Returns this

      contract

      module:contrato.Contract#addChild

      const contract = new Contract({ ... })
      contract.addChild(new Contract({ ... }))
    • Function

      Parameters

      • contracts: Contract[] = []

        contracts

      • Optionaloptions: object = {}

        options

      Returns this

      contract

      module:contrato.Contract#addChildren

      This is a utility method over .addChild().

      const contract = new Contract({ ... })
      contract.addChildren([
      new Contract({ ... }),
      new Contract({ ... }),
      new Contract({ ... })
      ])
    • Function

      Parameters

      • Optionaloptions: { types?: Set<string> } = {}

        options

        • Optionaltypes?: Set<string>

          the types to consider (all by default)

      Returns boolean

      whether the children are satisfied

      module:contrato.Contract#areChildrenSatisfied

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])

      if (contract.areChildrenSatisfied({
      types: new Set([ 'sw.arch' ])
      })) {
      console.log('This contract has all sw.arch requirements satisfied')
      }
    • Function

      Parameters

      • matcher: object | Contract

        matcher contract

      Returns Contract[]

      children

      module:contrato.Contract#findChildren

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])

      const children = contract.findChildren(Contract.createMatcher({
      type: 'sw.os',
      slug: 'debian'
      }))

      children.forEach((child) => {
      console.log(child)
      })
    • Function

      Parameters

      Returns Contract[]

      children

      module:contrato.Contract#findChildren

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])

      const children = contract.findChildren(Contract.createMatcher({
      type: 'sw.os',
      slug: 'debian'
      }))

      children.forEach((child) => {
      console.log(child)
      })
    • Function

      Returns Set<string>

      slugs

      module:contrato.Contract#getAllSlugs

      const contract = new Contract({
      type: 'hw.device-type',
      name: 'Raspberry Pi',
      slug: 'raspberrypi',
      aliases: [ 'rpi', 'raspberry-pi' ]
      })

      console.log(contract.getAllSlugs())
      > Set { raspberrypi, rpi, raspberry-pi }
    • Function

      Returns string

      slug - contract canonical slug or slug if canonical slug doesn't exist

      module:contrato.Contract#getCanonicalSlug

      const contract = new Contract({
      type: 'arch.sw',
      name: 'armv7hf',
      slug: 'armv7hf'
      canonicalSlug: 'raspberry-pi'
      })

      console.log(contract.getCanonicalSlug())
    • Function

      Parameters

      • childHash: string

        child contract hash

      Returns Contract | undefined

      child

      module:contrato.Contract#getChildByHash

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])

      const child = contract.getChildByHash('xxxxxxx')

      if (child) {
      console.log(child)
      }
    • Function

      Parameters

      • Optionaloptions: object = {}

        options

      Returns Contract[]

      children

      module:contrato.Contract#getChildren

      const contract = new Contract({ ... })
      const children = contract.getChildren({
      types: new Set([ 'arch.sw' ])
      })

      for (const child of children) {
      console.log(child)
      }
    • Function

      Parameters

      • type: string

        contract type

      Returns Contract[]

      children

      module:contrato.Contract#getChildrenByType

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])
      const children = container.getChildrenByType('sw.os')

      children.forEach((child) => {
      console.log(child)
      })
    • Function

      Parameters

      • options: { from: number; to: number; type: string; [index: string]: any }

        options

        • [index: string]: any
        • from: number

          number of contracts per combination (from)

        • to: number

          number of contracts per combination (to)

        • type: string

          contract type

      Returns Contract[][]

      combinations

      module:contrato.Contract#getChildrenCombinations

      Note that the client is responsible for evaluating that the combination of contracts is valid with regards to requirements, conflicts, etc. This function simply returns all the possible combinations without any further checks.

      The combinations output by this function is a plain list of contracts from which you can create a contract, or any other application specific data structure.

      const contract = new Contract({ ... })
      contract.addChildren([
      new Contract({
      name: 'Debian Wheezy',
      version: 'wheezy',
      slug: 'debian',
      type: 'sw.os'
      }),
      new Contract({
      name: 'Debian Jessie',
      version: 'jessie',
      slug: 'debian',
      type: 'sw.os'
      }),
      new Contract({
      name: 'Fedora 25',
      version: '25',
      slug: 'fedora',
      type: 'sw.os'
      })
      ])

      const combinations = contract.getChildrenCombinations({
      type: 'sw.os',
      from: 2,
      to: 2
      })

      console.log(combinations)
      > [
      > [
      > new Contract({
      > name: 'Debian Wheezy',
      > version: 'wheezy',
      > slug: 'debian',
      > type: 'sw.os'
      > }),
      > new Contract({
      > name: 'Debian Jessie',
      > version: 'jessie',
      > slug: 'debian',
      > type: 'sw.os'
      > })
      > ],
      > [
      > new Contract({
      > name: 'Debian Wheezy',
      > version: 'wheezy',
      > slug: 'debian',
      > type: 'sw.os'
      > }),
      > new Contract({
      > name: 'Fedora 25',
      > version: '25',
      > slug: 'fedora',
      > type: 'sw.os'
      > })
      > ],
      > [
      > new Contract({
      > name: 'Debian Jessie',
      > version: 'jessie',
      > slug: 'debian',
      > type: 'sw.os'
      > }),
      > new Contract({
      > name: 'Fedora 25',
      > version: '25',
      > slug: 'fedora',
      > type: 'sw.os'
      > })
      > ]
      > ]
    • Function

      Parameters

      • options: { from: Contract; types: Set<string> }

        options

        • from: Contract

          contract to resolve external contracts from

        • types: Set<string>

          types to consider

      Returns Contract[]

      children cross referenced contracts

      module:contrato.Contract#getChildrenCrossReferencedContracts

      const contract = new Contract({ ... })

      contract.addChildren([
      new Contract({
      type: 'arch.sw',
      slug: 'armv7hf',
      name: 'armv7hf'
      }),
      new Contract({
      type: 'sw.os',
      slug: 'raspbian',
      requires: [
      {
      or: [
      {
      type: 'arch.sw',
      slug: 'armv7hf'
      },
      {
      type: 'arch.sw',
      slug: 'rpi'
      }
      ]
      }
      ]
      }),
      new Contract({
      type: 'sw.stack',
      slug: 'nodejs',
      requires: [
      {
      type: 'arch.sw',
      slug: 'armv7hf'
      }
      ]
      })
      ])

      const references = contract.getChildrenCrossReferencedContracts({
      from: contract,
      types: new Set([ 'arch.sw' ])
      })

      console.log(references)
      > [
      > Contract {
      > type: 'arch.sw',
      > slug: 'armv7hf',
      > name: 'armv7hf'
      > }
      > ]
    • Function

      Returns Set<string>

      types

      module:contrato.Contract#getChildrenTypes

      const contract = new Contract({ ... })
      contract.addChildren([ { ... }, { ... } ])
      console.log(contract.getChildrenTypes())
    • Function

      Parameters

      • contract: Contract

        child contract

      • Optionaloptions: { types?: Set<string> } = {}

        options

        • Optionaltypes?: Set<string>

          the types to consider (all by default)

      Returns any[]

      list of unsatisfied requirements

      module:contrato.Contract#satisfiesChildContract

      const contract = new Contract({ ... })
      contract.addChildren([
      new Contract({
      type: 'sw.os',
      name: 'Debian Wheezy',
      version: 'wheezy',
      slug: 'debian'
      }),
      new Contract({
      type: 'sw.os',
      name: 'Fedora 25',
      version: '25',
      slug: 'fedora'
      })
      ])

      const child = new Contract({
      type: 'sw.stack',
      name: 'Node.js',
      version: '4.8.0',
      slug: 'nodejs',
      requires: [
      {
      or: [
      {
      type: 'sw.os',
      slug: 'debian'
      },
      {
      type: 'sw.os',
      slug: 'fedora'
      }
      ]
      }
      ]
      })

      if (contract.satisfiesChildContract(child)) {
      console.log('The child contract is satisfied!')
      }
    • Function

      Parameters

      • options: { from: Contract; types: Set<string> }

        options

        • from: Contract

          contract to resolve external contracts from

        • types: Set<string>

          types to consider

      Returns { [index: string]: Contract[] }

      referenced contracts

      module:contrato.Contract#getReferencedContracts

      const universe = new Contract({ ... })
      universe.addChildren([ ... ])

      const contract = new Contract({ ... })
      for (const reference of contract.getReferencedContracts({
      types: new Set([ 'arch.sw' ]),
      from: universe
      })) {
      console.log(reference.toJSON())
      }
    • Function

      Returns string

      reference string

      module:contrato.Contract#getReferenceString

      const contract = new Contract({
      type: 'arch.sw',
      name: 'armv7hf',
      slug: 'armv7hf'
      })

      console.log(contract.getReferenceString())
    • Function

      Returns string

      slug - contract slug

      module:contrato.Contract#getSlug

      const contract = new Contract({
      type: 'arch.sw',
      name: 'armv7hf',
      slug: 'armv7hf'
      })

      console.log(contract.getSlug())
    • Function

      Returns string

      type - contract type

      module:contrato.Contract#getType

      const contract = new Contract({
      type: 'arch.sw',
      name: 'armv7hf',
      slug: 'armv7hf'
      })

      console.log(contract.getType())
    • Function

      Returns string

      slug - contract version

      module:contrato.Contract#getVersion

      const contract = new Contract({
      type: 'sw.os',
      name: 'Debian Wheezy',
      version: 'wheezy',
      slug: 'debian'
      })

      console.log(contract.getVersion())
    • Function

      Returns boolean

      whether the contract has aliases

      module:contrato.Contract#hasAliases

      const contract = new Contract({
      type: 'hw.device-type',
      name: 'Raspberry Pi',
      slug: 'raspberrypi',
      aliases: [ 'rpi', 'raspberry-pi' ]
      })

      if (contract.hasAliases()) {
      console.log('This contract has aliases')
      }
    • Protected Function

      Returns void

      module:contrato.Contract#hash

      const contract = new Contract({ ... })
      contract.hash()
    • Protected Function

      Parameters

      • Optionaloptions: object = ...

        options

      Returns this

      contract instance

      module:contrato.Contract#interpolate

      const contract = new Contract({ ... })
      contract.interpolate()
    • Protected Function

      Returns void

      module:contrato.Contract#rebuild

      const contract = new Contract({ ... })
      contract.rebuild()
    • Function

      Parameters

      • contract: Contract

        contract

      • Optionaloptions: object = {}

        options

      Returns this

      parent contract

      module:contrato.Contract#removeChild

      const contract = new Contract({ ... })

      const child = new Contract({ ... })
      contract.addChild(child)
      contract.removeChild(child)
    • Function

      Parameters

      Returns IterableIterator<Contract>

      • an iterable over the valid contexts

      module:contrato.Blueprint#reproduce

      This method will generate a set of contexts that consist of every possible valid combination that matches the blueprint layout. It uses depth first search to calculate the product of contract combinations and returns the results as an iterable. This allows to reduce the memory usage when dealing with a large universe of contracts.

      const contract = new Contract({ ... })
      contract.addChildren([ ... ])

      const blueprint = new Blueprint({
      'hw.device-type': 1,
      'arch.sw': 1
      })

      const contexts = blueprint.reproduce(contract)
      for (const context of contexts) {
      console.log(context.toJSON());
      }
    • Function

      Parameters

      • contract: Contract

        child contract

      • Optionaloptions: { types?: Set<string> } = {}

        options

        • Optionaltypes?: Set<string>

          the types to consider (all by default)

      Returns boolean

      whether the contract is satisfied

      module:contrato.Contract#satisfiesChildContract

      const contract = new Contract({ ... })
      contract.addChildren([
      new Contract({
      type: 'sw.os',
      name: 'Debian Wheezy',
      version: 'wheezy',
      slug: 'debian'
      }),
      new Contract({
      type: 'sw.os',
      name: 'Fedora 25',
      version: '25',
      slug: 'fedora'
      })
      ])

      const child = new Contract({
      type: 'sw.stack',
      name: 'Node.js',
      version: '4.8.0',
      slug: 'nodejs',
      requires: [
      {
      or: [
      {
      type: 'sw.os',
      slug: 'debian'
      },
      {
      type: 'sw.os',
      slug: 'fedora'
      }
      ]
      }
      ]
      })

      if (contract.satisfiesChildContract(child)) {
      console.log('The child contract is satisfied!')
      }
    • Function

      Returns { type: string } & { [key: string]: any }

      JSON object

      module:contrato.Contract#toJSON

      const contract = new Contract({ ... })
      const object = contract.toJSON()
      console.log(JSON.stringify(object))
    • Function

      Parameters

      • source: { type: string } & { [key: string]: any }

        source contract

      Returns Contract[]

      built contracts

      module:contrato.Contract.build

      const contracts = Contract.build({
      name: 'debian {{version}}',
      slug: 'debian',
      type: 'sw.os',
      variants: [
      { version: 'wheezy' },
      { version: 'jessie' },
      { version: 'sid' }
      ]
      })

      contracts.forEach((contract) => {
      if (contract instanceof Contract) {
      console.log('This is a built contract')
      }
      })
    • Protected Function

      Parameters

      • data: object | object[]

        matcher data

      • Optionaloptions: { operation?: string } = {}

        options

        • Optionaloperation?: string

          the matcher's operation

      Returns Contract

      matcher contract

      module:contrato.Contract.createMatcher

      const matcher = Contract.createMatcher({
      type: 'arch.sw',
      slug: 'armv7hf'
      })
    • Function

      Parameters

      Returns boolean

      whether the contracts are equal

      module:contrato.Contract.isEqual

      const contract1 = new Contract({ ... })
      const contract2 = new Contract({ ... })

      if (Contract.isEqual(contract1, contract2)) {
      console.log('These contracts are equal')
      }