Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

constructor

  • new Blueprint(layout: {}, skeleton?: any): Blueprint
  • summary

    A blueprint contract data structure

    name

    Blueprint

    memberof

    module:contrato

    example

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

    Parameters

    • layout: {}

      the blueprint layout

      • [key: string]: any
    • Optional skeleton: any

      the blueprint skeleton

    Returns Blueprint

Properties

metadata

metadata: any

raw

raw: { type: string } & {}

Methods

addChild

  • summary

    Add a child contract

    function
    name

    module:contrato.Contract#addChild

    example

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

    Parameters

    • contract: Contract

      contract

    • options: object = {}

    Returns Contract

    contract

addChildren

  • summary

    Add a set of children contracts to the contract

    function
    name

    module:contrato.Contract#addChildren

    description

    This is a utility method over .addChild().

    example

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

    Parameters

    • contracts: Contract[] = []

      contracts

    • options: object = {}

    Returns Contract

    contract

areChildrenSatisfied

  • areChildrenSatisfied(options?: { types?: Set<string> }): boolean
  • summary

    Check if the contract children are satisfied

    function
    name

    module:contrato.Contract#areChildrenSatisfied

    example

    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

    • options: { types?: Set<string> } = {}
      • Optional types?: Set<string>

    Returns boolean

    whether the children are satisfied

findChildren

  • summary

    Recursively find children using a matcher contract

    function
    name

    module:contrato.Contract#findChildren

    example

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

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

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

    Parameters

    • matcher: {} | Contract

      matcher contract

    Returns Contract[]

    children

findChildrenWithCapabilities

  • summary

    Recursively find children using a matcher contract

    function
    name

    module:contrato.Contract#findChildren

    example

    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

getAllNotSatisfiedChildRequirements

  • getAllNotSatisfiedChildRequirements(options?: object): any[]

getAllSlugs

  • getAllSlugs(): Set<string>
  • summary

    Get all the slugs this contract can be referenced with

    function
    name

    module:contrato.Contract#getAllSlugs

    example

    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 Set<string>

    slugs

getCanonicalSlug

  • getCanonicalSlug(): string
  • summary

    Get the contract canonical slug

    function
    name

    module:contrato.Contract#getCanonicalSlug

    example

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

    console.log(contract.getCanonicalSlug())

    Returns string

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

getChildByHash

  • getChildByHash(childHash: string): undefined | Contract
  • summary

    Get a single child by its hash

    function
    name

    module:contrato.Contract#getChildByHash

    example

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

    const child = contract.getChildByHash('xxxxxxx')

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

    Parameters

    • childHash: string

      child contract hash

    Returns undefined | Contract

    child

getChildren

  • getChildren(options?: object): Contract[]
  • summary

    Recursively get a set of children contracts

    function
    name

    module:contrato.Contract#getChildren

    example

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

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

    Parameters

    • options: object = {}

    Returns Contract[]

    children

getChildrenByType

  • getChildrenByType(type: string): Contract[]
  • summary

    Get all the children contracts of a specific type

    function
    name

    module:contrato.Contract#getChildrenByType

    example

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

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

    Parameters

    • type: string

      contract type

    Returns Contract[]

    children

getChildrenCombinations

  • getChildrenCombinations(options: { from: number; to: number; type: string }): Contract[][]
  • summary

    Get all possible combinations from a type of children contracts

    function
    name

    module:contrato.Contract#getChildrenCombinations

    description

    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.

    example

    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: number; to: number; type: string }

      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

getChildrenCrossReferencedContracts

  • getChildrenCrossReferencedContracts(options: { from: Contract; types: Set<string> }): Contract[]
  • summary

    Get the children cross referenced contracts

    function
    name

    module:contrato.Contract#getChildrenCrossReferencedContracts

    example

    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' } ]

    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

getChildrenTypes

  • getChildrenTypes(): Set<string>
  • summary

    Recursively get the list of types known children contract types

    function
    name

    module:contrato.Contract#getChildrenTypes

    example

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

    Returns Set<string>

    types

getNotSatisfiedChildRequirements

  • getNotSatisfiedChildRequirements(contract: Contract, options?: { types: Set<string> }): any[]
  • summary

    Check if a child contract is satisfied when applied to this contract

    function
    name

    module:contrato.Contract#satisfiesChildContract

    example

    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

    • contract: Contract

      child contract

    • options: { types: Set<string> } = ...
      • types: Set<string>

    Returns any[]

    whether the contract is satisfied

getReferenceString

  • getReferenceString(): string
  • summary

    Get a reference string for the contract

    function
    name

    module:contrato.Contract#getReferenceString

    example

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

    console.log(contract.getReferenceString())

    Returns string

    reference string

getReferencedContracts

  • getReferencedContracts(options: { from: Contract; types: Set<string> }): {}
  • summary

    Recursively get the list of referenced contracts

    function
    name

    module:contrato.Contract#getReferencedContracts

    example

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

    Parameters

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

      options

      • from: Contract

        contract to resolve external contracts from

      • types: Set<string>

        types to consider

    Returns {}

    referenced contracts

getSlug

  • getSlug(): string
  • summary

    Get the contract slug

    function
    name

    module:contrato.Contract#getSlug

    example

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

    console.log(contract.getSlug())

    Returns string

    slug - contract slug

getType

  • getType(): string
  • summary

    Get the contract type

    function
    name

    module:contrato.Contract#getType

    example

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

    console.log(contract.getType())

    Returns string

    type - contract type

getVersion

  • getVersion(): string
  • summary

    Get the contract version

    function
    name

    module:contrato.Contract#getVersion

    example

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

    console.log(contract.getVersion())

    Returns string

    slug - contract version

hasAliases

  • hasAliases(): boolean
  • summary

    Check if a contract has aliases

    function
    name

    module:contrato.Contract#hasAliases

    example

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

    Returns boolean

    whether the contract has aliases

Protected hash

  • hash(): void
  • summary

    Re-hash the contract

    function
    name

    module:contrato.Contract#hash

    example

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

    Returns void

Protected interpolate

  • interpolate(options?: object): Contract
  • summary

    Interpolate the contract's template

    function
    name

    module:contrato.Contract#interpolate

    example

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

    Parameters

    • options: object = ...

    Returns Contract

    contract instance

Protected rebuild

  • rebuild(): void
  • summary

    Re-build the contract's internal data structures

    function
    name

    module:contrato.Contract#rebuild

    example

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

    Returns void

removeChild

  • summary

    Remove a child contract

    function
    name

    module:contrato.Contract#removeChild

    example

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

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

    Parameters

    • contract: Contract

      contract

    • options: object = {}

    Returns Contract

    parent contract

reproduce

  • summary

    Reproduce the blueprint in a universe

    function
    name

    module:contrato.Blueprint#reproduce

    description

    This method will generate a set of contexts that consist of every possible valid combination that matches the blueprint layout.

    example

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

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

    const contexts = blueprint.reproduce(contract)

    contexts.forEach((context) => { console.log(context.toJSON()) })

    Parameters

    Returns Contract[]

    valid contexts

satisfiesChildContract

  • satisfiesChildContract(contract: Contract, options?: { types?: Set<string> }): boolean
  • summary

    Check if a child contract is satisfied when applied to this contract

    function
    name

    module:contrato.Contract#satisfiesChildContract

    example

    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

    • contract: Contract

      child contract

    • options: { types?: Set<string> } = {}
      • Optional types?: Set<string>

    Returns boolean

    whether the contract is satisfied

sequence

  • sequence(contract: Contract, options?: { allowRequirements: boolean }): Contract[]
  • summary

    Reproduce the blueprint in a universe

    function
    name

    module:contrato.Blueprint#reproduce

    description

    This method will generate a set of contexts that consist of every possible valid combination that matches the blueprint layout.

    example

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

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

    const contexts = blueprint.reproduce(contract)

    contexts.forEach((context) => { console.log(context.toJSON()) })

    Parameters

    • contract: Contract

      contract

    • options: { allowRequirements: boolean } = ...
      • allowRequirements: boolean

    Returns Contract[]

    valid contexts

toJSON

  • toJSON(): { type: string } & {}
  • summary

    Return a JSON representation of a contract

    function
    name

    module:contrato.Contract#toJSON

    example

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

    Returns { type: string } & {}

    JSON object

Static build

  • build(source: { type: string } & {}): Contract[]
  • summary

    Build a source contract

    function
    static
    name

    module:contrato.Contract.build

    example

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

    Parameters

    • source: { type: string } & {}

      source contract

    Returns Contract[]

    built contracts

Static Protected createMatcher

  • createMatcher(data: object | object[], options?: { operation?: string }): Contract
  • summary

    Create a matcher contract object

    function
    static
    name

    module:contrato.Contract.createMatcher

    example

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

    Parameters

    • data: object | object[]

      matcher data

    • options: { operation?: string } = {}
      • Optional operation?: string

    Returns Contract

    matcher contract

Static isEqual

  • summary

    Check if two contracts are equal

    function
    static
    name

    module:contrato.Contract.isEqual

    example

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

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

    Parameters

    Returns boolean

    whether the contracts are equal

Generated using TypeDoc