Hierarchy (View Summary)

Constructors

  • Parameters

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

      the contract plain object

    • Optionaloptions: object = {}

      options

    Returns Contract

    Contract

    module:contrato

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

Properties

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

Methods

  • Parameters

    • contract: Contract

      contract

    • Optionaloptions: object = {}

      options

    Returns this

    contract

    module:contrato.Contract#addChild

    const contract = new Contract({ ... })
    contract.addChild(new Contract({ ... }))
  • 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({ ... })
    ])
  • 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')
    }
  • 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)
    })
  • 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)
    })
  • Parameters

    • options: object = {}

    Returns any[]

  • 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 }
  • 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())
  • Parameters

    • childHash: string

      child contract hash

    Returns undefined | Contract

    child

    module:contrato.Contract#getChildByHash

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

    const child = contract.getChildByHash('xxxxxxx')

    if (child) {
    console.log(child)
    }
  • 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)
    }
  • 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)
    })
  • 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'
    > })
    > ]
    > ]
  • 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'
    > }
    > ]
  • Returns Set<string>

    types

    module:contrato.Contract#getChildrenTypes

    const contract = new Contract({ ... })
    contract.addChildren([ { ... }, { ... } ])
    console.log(contract.getChildrenTypes())
  • 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!')
    }
  • 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())
    }
  • Returns string

    reference string

    module:contrato.Contract#getReferenceString

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

    console.log(contract.getReferenceString())
  • Returns string

    slug - contract slug

    module:contrato.Contract#getSlug

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

    console.log(contract.getSlug())
  • Returns string

    type - contract type

    module:contrato.Contract#getType

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

    console.log(contract.getType())
  • 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())
  • 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

    Returns void

    module:contrato.Contract#hash

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

    Parameters

    • Optionaloptions: object = ...

      options

    Returns this

    contract instance

    module:contrato.Contract#interpolate

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

    Returns void

    module:contrato.Contract#rebuild

    const contract = new Contract({ ... })
    contract.rebuild()
  • 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)
  • 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!')
    }
  • 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))
  • 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

    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'
    })
  • 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')
    }