Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Descriptor

Locator type that most often used in PipServices toolkit. It locates components using several fields:

  • Group: a package or just named group of components like "pip-services"
  • Type: logical component type that defines it's contract like "persistence"
  • Kind: physical implementation type like "mongodb"
  • Name: unique component name like "default"
  • Version: version of the component contract like "1.0"

The locator matching can be done by all or only few selected fields. The fields that shall be excluded from the matching must be set to "*" or null. That approach allows to implement many interesting scenarios. For instance:

  • Locate all loggers (match by type and version)
  • Locate persistence components for a microservice (match by group and type)
  • Locate specific component by its name (match by name)

Example

let locator1 = new Descriptor("mygroup", "connector", "aws", "default", "1.0");
let locator2 = Descriptor.fromString("mygroup:connector:*:*:1.0");

locator1.match(locator2);        // Result: true
locator1.equal(locator2);        // Result: true
locator1.exactMatch(locator2);    // Result: false

Hierarchy

  • Descriptor

Index

Constructors

constructor

  • new Descriptor(group: string, type: string, kind: string, name: string, version: string): Descriptor
  • Creates a new instance of the descriptor.

    Parameters

    • group: string

      a logical component group

    • type: string

      a logical component type or contract

    • kind: string

      a component implementation type

    • name: string

      a unique component name

    • version: string

      a component implementation version

    Returns Descriptor

Methods

equals

  • equals(value: any): boolean
  • Compares this descriptor to a value. If value is a Descriptor it tries to match them, otherwise the method returns false.

    see

    match

    Parameters

    • value: any

      the value to match against this descriptor.

    Returns boolean

    true if the value is matching descriptor and false otherwise.

exactMatch

  • Matches this descriptor to another descriptor by all fields. No exceptions are made.

    see

    match

    Parameters

    • descriptor: Descriptor

      the descriptor to match this one against.

    Returns boolean

    true if descriptors match and false otherwise.

getGroup

  • getGroup(): string
  • Gets the component's logical group.

    Returns string

    the component's logical group

getKind

  • getKind(): string
  • Gets the component's implementation type.

    Returns string

    the component's implementation type.

getName

  • getName(): string
  • Gets the unique component's name.

    Returns string

    the unique component's name.

getType

  • getType(): string
  • Gets the component's logical type.

    Returns string

    the component's logical type.

getVersion

  • getVersion(): string
  • Gets the component's implementation version.

    Returns string

    the component's implementation version.

isComplete

  • isComplete(): boolean
  • Checks whether all descriptor fields are set. If descriptor has at least one "*" or null field it is considered "incomplete",

    Returns boolean

    true if all descriptor fields are defined and false otherwise.

match

  • Partially matches this descriptor to another descriptor. Fields that contain "*" or null are excluded from the match.

    see

    exactMatch

    Parameters

    • descriptor: Descriptor

      the descriptor to match this one against.

    Returns boolean

    true if descriptors match and false otherwise

toString

  • toString(): string
  • Gets a string representation of the object. The result is a colon-separated list of descriptor fields as "mygroup:connector:aws:default:1.0"

    Returns string

    a string representation of the object.

Static fromString

  • Parses colon-separated list of descriptor fields and returns them as a Descriptor.

    throws

    a ConfigException if the descriptor string is of a wrong format.

    Parameters

    • value: String

      colon-separated descriptor fields to initialize Descriptor.

    Returns Descriptor

    a newly created Descriptor.

Generated using TypeDoc