pip-services3-commons-node

  • Version 3.0.8
  • Published
  • 1.4 MB
  • 3 dependencies
  • MIT license

Install

npm i pip-services3-commons-node
yarn add pip-services3-commons-node
pnpm add pip-services3-commons-node

Overview

Portable abstractions and patterns for Pip.Services in Node.js

Index

Classes

Interfaces

Enums

Classes

class AndRule

class AndRule implements IValidationRule {}
  • Validation rule to combine rules with AND logical operation. When all rules returns no errors, than this rule also returns no errors. When one of the rules return errors, than the rules returns all errors.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new AndRule( new ValueComparisonRule("GTE", 1), new ValueComparisonRule("LTE", 10) ));

      schema.validate(0); // Result: 0 must be greater or equal to 1 schema.validate(5); // Result: no error schema.validate(20); // Result: 20 must be letter or equal 10

constructor

constructor(...rules: IValidationRule[]);
  • Creates a new validation rule and sets its values.

    Parameter rules

    a list of rules to join with AND operator

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against this rule.

    Parameter path

    a dot notation path to the value.

    Parameter schema

    a schema this rule is called from

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

class AnyValue

class AnyValue implements ICloneable {}
  • Cross-language implementation of dynamic object what can hold value of any type. The stored value can be converted to different types using variety of accessor methods.

    ### Example ###

    let value1 = new AnyValue("123.456");

    value1.getAsInteger(); // Result: 123 value1.getAsString(); // Result: "123.456" value1.getAsFloat(); // Result: 123.456

    See Also

    • [[StringConverter]]

    • [[TypeConverter]]

    • [[BooleanConverter]]

    • [[IntegerConverter]]

    • [[LongConverter]]

    • [[DoubleConverter]]

    • [[FloatConverter]]

    • [[DateTimeConverter]]

    • [[ICloneable]]

constructor

constructor(value?: any);
  • Creates a new instance of the object and assigns its value.

    Parameter value

    (optional) value to initialize this object.

property value

value: any;
  • The value stored by this object.

method clone

clone: () => any;
  • Creates a binary clone of this object.

    Returns

    a clone of this object.

method equals

equals: (obj: any) => boolean;
  • Compares this object value to specified specified value. When direct comparison gives negative results it tries to compare values as strings.

    Parameter obj

    the value to be compared with.

    Returns

    true when objects are equal and false otherwise.

method equalsAsType

equalsAsType: <T>(type: TypeCode, obj: any) => boolean;
  • Compares this object value to specified specified value. When direct comparison gives negative results it converts values to type specified by type code and compare them again.

    Parameter obj

    the value to be compared with.

    Returns

    true when objects are equal and false otherwise.

    See Also

    • [[TypeConverter.toType]]

method getAsArray

getAsArray: () => AnyValueArray;
  • Converts object value into an AnyArray or returns empty AnyArray if conversion is not possible.

    Returns

    AnyArray value or empty AnyArray if conversion is not supported.

    See Also

    • [[AnyValueArray.fromValue]]

method getAsBoolean

getAsBoolean: () => boolean;
  • Converts object value into a boolean or returns false if conversion is not possible.

    Returns

    string value or false if conversion is not supported.

    See Also

    • [[getAsBooleanWithDefault]]

method getAsBooleanWithDefault

getAsBooleanWithDefault: (defaultValue: boolean) => boolean;
  • Converts object value into a boolean or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    boolean value or default if conversion is not supported.

    See Also

    • [[BooleanConverter.toBooleanWithDefault]]

method getAsDateTime

getAsDateTime: () => Date;
  • Converts object value into a Date or returns current date if conversion is not possible.

    Returns

    Date value or current date if conversion is not supported.

    See Also

    • [[getAsDateTimeWithDefault]]

method getAsDateTimeWithDefault

getAsDateTimeWithDefault: (defaultValue: Date) => Date;
  • Converts object value into a Date or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    Date value or default if conversion is not supported.

    See Also

    • [[DateTimeConverter.toDateTimeWithDefault]]

method getAsDouble

getAsDouble: () => number;
  • Converts object value into a double or returns 0 if conversion is not possible.

    Returns

    double value or 0 if conversion is not supported.

    See Also

    • [[getAsDoubleWithDefault]]

method getAsDoubleWithDefault

getAsDoubleWithDefault: (defaultValue: number) => number;
  • Converts object value into a double or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    double value or default if conversion is not supported.

    See Also

    • [[DoubleConverter.toDoubleWithDefault]]

method getAsFloat

getAsFloat: () => number;
  • Converts object value into a float or returns 0 if conversion is not possible.

    Returns

    float value or 0 if conversion is not supported.

    See Also

    • [[getAsFloatWithDefault]]

method getAsFloatWithDefault

getAsFloatWithDefault: (defaultValue: number) => number;
  • Converts object value into a float or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    float value or default if conversion is not supported.

    See Also

    • [[FloatConverter.toFloatWithDefault]]

method getAsInteger

getAsInteger: () => number;
  • Converts object value into an integer or returns 0 if conversion is not possible.

    Returns

    integer value or 0 if conversion is not supported.

    See Also

    • [[getAsIntegerWithDefault]]

method getAsIntegerWithDefault

getAsIntegerWithDefault: (defaultValue: number) => number;
  • Converts object value into a integer or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    integer value or default if conversion is not supported.

    See Also

    • [[IntegerConverter.toIntegerWithDefault]]

method getAsLong

getAsLong: () => number;
  • Converts object value into a long or returns 0 if conversion is not possible.

    Returns

    string value or 0 if conversion is not supported.

    See Also

    • [[getAsLongWithDefault]]

method getAsLongWithDefault

getAsLongWithDefault: (defaultValue: number) => number;
  • Converts object value into a long or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    long value or default if conversion is not supported.

    See Also

    • [[LongConverter.toLongWithDefault]]

method getAsMap

getAsMap: () => AnyValueMap;
  • Converts object value into AnyMap or returns empty AnyMap if conversion is not possible.

    Returns

    AnyMap value or empty AnyMap if conversion is not supported.

    See Also

    • [[AnyValueMap.fromValue]]

method getAsNullableBoolean

getAsNullableBoolean: () => boolean;
  • Converts object value into a boolean or returns null if conversion is not possible.

    Returns

    boolean value or null if conversion is not supported.

    See Also

    • [[BooleanConverter.toNullableBoolean]]

method getAsNullableDateTime

getAsNullableDateTime: () => Date;
  • Converts object value into a Date or returns null if conversion is not possible.

    Returns

    Date value or null if conversion is not supported.

    See Also

    • [[DateTimeConverter.toNullableDateTime]]

method getAsNullableDouble

getAsNullableDouble: () => number;
  • Converts object value into a double or returns null if conversion is not possible.

    Returns

    double value or null if conversion is not supported.

    See Also

    • [[DoubleConverter.toNullableDouble]]

method getAsNullableFloat

getAsNullableFloat: () => number;
  • Converts object value into a float or returns null if conversion is not possible.

    Returns

    float value or null if conversion is not supported.

    See Also

    • [[FloatConverter.toNullableFloat]]

method getAsNullableInteger

getAsNullableInteger: () => number;
  • Converts object value into an integer or returns null if conversion is not possible.

    Returns

    integer value or null if conversion is not supported.

    See Also

    • [[IntegerConverter.toNullableInteger]]

method getAsNullableLong

getAsNullableLong: () => number;
  • Converts object value into a long or returns null if conversion is not possible.

    Returns

    long value or null if conversion is not supported.

    See Also

    • [[LongConverter.toNullableLong]]

method getAsNullableString

getAsNullableString: () => string;
  • Converts object value into a string or returns null if conversion is not possible.

    Returns

    string value or null if conversion is not supported.

    See Also

    • [[StringConverter.toNullableString]]

method getAsNullableType

getAsNullableType: <T>(type: TypeCode) => T;
  • Converts object value into a value defined by specied typecode. If conversion is not possible it returns null.

    Parameter type

    the TypeCode that defined the type of the result

    Returns

    value defined by the typecode or null if conversion is not supported.

    See Also

    • [[TypeConverter.toNullableType]]

method getAsObject

getAsObject: () => any;
  • Gets the value stored in this object without any conversions

    Returns

    the object value.

method getAsString

getAsString: () => string;
  • Converts object value into a string or returns "" if conversion is not possible.

    Returns

    string value or "" if conversion is not supported.

    See Also

    • [[getAsStringWithDefault]]

method getAsStringWithDefault

getAsStringWithDefault: (defaultValue: string) => string;
  • Converts object value into a string or returns default value if conversion is not possible.

    Parameter defaultValue

    the default value.

    Returns

    string value or default if conversion is not supported.

    See Also

    • [[StringConverter.toStringWithDefault]]

method getAsType

getAsType: <T>(typeCode: TypeCode) => T;
  • Converts object value into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.

    Parameter typeCode

    the TypeCode that defined the type of the result

    Returns

    value defined by the typecode or type default value if conversion is not supported.

    See Also

    • [[getAsTypeWithDefault]]

method getAsTypeWithDefault

getAsTypeWithDefault: <T>(typeCode: TypeCode, defaultValue: T) => T;
  • Converts object value into a value defined by specied typecode. If conversion is not possible it returns default value.

    Parameter typeCode

    the TypeCode that defined the type of the result

    Parameter defaultValue

    the default value

    Returns

    value defined by the typecode or type default value if conversion is not supported.

    See Also

    • [[TypeConverter.toTypeWithDefault]]

method getTypeCode

getTypeCode: () => TypeCode;
  • Gets type code for the value stored in this object.

    Returns

    type code of the object value.

    See Also

    • [[TypeConverter.toTypeCode]]

method hashCode

hashCode: () => number;
  • Gets an object hash code which can be used to optimize storing and searching.

    Returns

    an object hash code.

method setAsObject

setAsObject: (value: any) => void;
  • Sets a new value for this object

    Parameter value

    the new object value.

method toString

toString: () => any;
  • Gets a string representation of the object.

    Returns

    a string representation of the object.

    See Also

    • [[StringConverter.toString]]

class AnyValueArray

class AnyValueArray extends Array<any> implements ICloneable {}
  • Cross-language implementation of dynamic object array what can hold values of any type. The stored values can be converted to different types using variety of accessor methods.

    ### Example ###

    let value1 = new AnyValueArray([1, "123.456", "2018-01-01"]);

    value1.getAsBoolean(0); // Result: true value1.getAsInteger(1); // Result: 123 value1.getAsFloat(1); // Result: 123.456 value1.getAsDateTime(2); // Result: new Date(2018,0,1)

    See Also

    • [[StringConverter]]

    • [[TypeConverter]]

    • [[BooleanConverter]]

    • [[IntegerConverter]]

    • [[LongConverter]]

    • [[DoubleConverter]]

    • [[FloatConverter]]

    • [[DateTimeConverter]]

    • [[ICloneable]]

constructor

constructor(values?: any[]);
  • Creates a new instance of the array and assigns its value.

    Parameter value

    (optional) values to initialize this array.

method append

append: (elements: any[]) => void;
  • Appends new elements to this array.

    Parameter elements

    a list of elements to be added.

method clear

clear: () => void;
  • Clears this array by removing all its elements.

method clone

clone: () => any;
  • Creates a binary clone of this object.

    Returns

    a clone of this object.

method contains

contains: (value: any) => boolean;
  • Checks if this array contains a value. The check uses direct comparison between elements and the specified value.

    Parameter value

    a value to be checked

    Returns

    true if this array contains the value or false otherwise.

method containsAsType

containsAsType: <T>(typeCode: TypeCode, value: any) => boolean;
  • Checks if this array contains a value. The check before comparison converts elements and the value to type specified by type code.

    Parameter typeCode

    a type code that defines a type to convert values before comparison

    Parameter value

    a value to be checked

    Returns

    true if this array contains the value or false otherwise.

    See Also

    • [[TypeConverter.toType]]

    • [[TypeConverter.toNullableType]]

method fromString

static fromString: (
values: string,
separator: string,
removeDuplicates?: boolean
) => AnyValueArray;
  • Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.

    Parameter values

    a string value to be split and assigned to AnyValueArray

    Parameter separator

    a separator to split the string

    Parameter removeDuplicates

    (optional) true to remove duplicated elements

    Returns

    a newly created AnyValueArray.

method fromValue

static fromValue: (value: any) => AnyValueArray;
  • Converts specified value into AnyValueArray.

    Parameter value

    value to be converted

    Returns

    a newly created AnyValueArray.

    See Also

    • [[ArrayConverter.toNullableArray]]

method fromValues

static fromValues: (...values: any[]) => AnyValueArray;
  • Creates a new AnyValueArray from a list of values

    Parameter values

    a list of values to initialize the created AnyValueArray

    Returns

    a newly created AnyValueArray.

method get

get: (index: number) => any;
  • Gets an array element specified by its index.

    Parameter index

    an index of the element to get.

    Returns

    the value of the array element.

method getAsArray

getAsArray: (index: number) => AnyValueArray;
  • Converts array element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.

    See Also

    • [[fromValue]]

method getAsArrayWithDefault

getAsArrayWithDefault: (
index: number,
defaultValue: AnyValueArray
) => AnyValueArray;
  • Converts array element into an AnyValueArray or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    AnyValueArray value of the element or default value if conversion is not supported.

    See Also

    • [[getAsNullableArray]]

method getAsBoolean

getAsBoolean: (index: number) => boolean;
  • Converts array element into a boolean or returns false if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    boolean value ot the element or false if conversion is not supported.

    See Also

    • [[getAsBooleanWithDefault]]

method getAsBooleanWithDefault

getAsBooleanWithDefault: (index: number, defaultValue: boolean) => boolean;
  • Converts array element into a boolean or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    boolean value ot the element or default value if conversion is not supported.

    See Also

    • [[BooleanConverter.toBooleanWithDefault]]

method getAsDateTime

getAsDateTime: (index: number) => Date;
  • Converts array element into a Date or returns the current date if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    Date value ot the element or the current date if conversion is not supported.

    See Also

    • [[getAsDateTimeWithDefault]]

method getAsDateTimeWithDefault

getAsDateTimeWithDefault: (index: number, defaultValue: Date) => Date;
  • Converts array element into a Date or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    Date value ot the element or default value if conversion is not supported.

    See Also

    • [[DateTimeConverter.toDateTimeWithDefault]]

method getAsDouble

getAsDouble: (index: number) => number;
  • Converts array element into a double or returns 0 if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    double value ot the element or 0 if conversion is not supported.

    See Also

    • [[getAsDoubleWithDefault]]

method getAsDoubleWithDefault

getAsDoubleWithDefault: (index: number, defaultValue: number) => number;
  • Converts array element into a double or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    double value ot the element or default value if conversion is not supported.

    See Also

    • [[DoubleConverter.toDoubleWithDefault]]

method getAsFloat

getAsFloat: (index: number) => number;
  • Converts array element into a float or returns 0 if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    float value ot the element or 0 if conversion is not supported.

    See Also

    • [[getAsFloatWithDefault]]

method getAsFloatWithDefault

getAsFloatWithDefault: (index: number, defaultValue: number) => number;
  • Converts array element into a float or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    float value ot the element or default value if conversion is not supported.

    See Also

    • [[FloatConverter.toFloatWithDefault]]

method getAsInteger

getAsInteger: (index: number) => number;
  • Converts array element into an integer or returns 0 if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    integer value ot the element or 0 if conversion is not supported.

    See Also

    • [[getAsIntegerWithDefault]]

method getAsIntegerWithDefault

getAsIntegerWithDefault: (index: number, defaultValue: number) => number;
  • Converts array element into an integer or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    integer value ot the element or default value if conversion is not supported.

    See Also

    • [[IntegerConverter.toIntegerWithDefault]]

method getAsLong

getAsLong: (index: number) => number;
  • Converts array element into a long or returns 0 if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    long value ot the element or 0 if conversion is not supported.

    See Also

    • [[getAsLongWithDefault]]

method getAsLongWithDefault

getAsLongWithDefault: (index: number, defaultValue: number) => number;
  • Converts array element into a long or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    long value ot the element or default value if conversion is not supported.

    See Also

    • [[LongConverter.toLongWithDefault]]

method getAsMap

getAsMap: (index: number) => AnyValueMap;
  • Converts array element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.

    See Also

    • [[AnyValueMap]]

    • [[AnyValueMap.fromValue]]

method getAsMapWithDefault

getAsMapWithDefault: (index: number, defaultValue: AnyValueMap) => AnyValueMap;
  • Converts array element into an AnyValueMap or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    AnyValueMap value of the element or default value if conversion is not supported.

    See Also

    • [[getAsNullableMap]]

method getAsNullableArray

getAsNullableArray: (index: number) => AnyValueArray;
  • Converts array element into an AnyValueArray or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    AnyValueArray value of the element or null if conversion is not supported.

    See Also

    • [[fromValue]]

method getAsNullableBoolean

getAsNullableBoolean: (index: number) => boolean;
  • Converts array element into a boolean or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    boolean value of the element or null if conversion is not supported.

    See Also

    • [[BooleanConverter.toNullableBoolean]]

method getAsNullableDateTime

getAsNullableDateTime: (index: number) => Date;
  • Converts array element into a Date or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    Date value of the element or null if conversion is not supported.

    See Also

    • [[DateTimeConverter.toNullableDateTime]]

method getAsNullableDouble

getAsNullableDouble: (index: number) => number;
  • Converts array element into a double or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    double value of the element or null if conversion is not supported.

    See Also

    • [[DoubleConverter.toNullableDouble]]

method getAsNullableFloat

getAsNullableFloat: (index: number) => number;
  • Converts array element into a float or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    float value of the element or null if conversion is not supported.

    See Also

    • [[FloatConverter.toNullableFloat]]

method getAsNullableInteger

getAsNullableInteger: (index: number) => number;
  • Converts array element into an integer or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    integer value of the element or null if conversion is not supported.

    See Also

    • [[IntegerConverter.toNullableInteger]]

method getAsNullableLong

getAsNullableLong: (index: number) => number;
  • Converts array element into a long or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    long value of the element or null if conversion is not supported.

    See Also

    • [[LongConverter.toNullableLong]]

method getAsNullableMap

getAsNullableMap: (index: number) => AnyValueMap;
  • Converts array element into an AnyValueMap or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    AnyValueMap value of the element or null if conversion is not supported.

    See Also

    • [[AnyValueMap]]

    • [[AnyValueMap.fromValue]]

method getAsNullableString

getAsNullableString: (index: number) => string;
  • Converts array element into a string or returns null if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    string value of the element or null if conversion is not supported.

    See Also

    • [[StringConverter.toNullableString]]

method getAsNullableType

getAsNullableType: <T>(type: TypeCode, index: number) => T;
  • Converts array element into a value defined by specied typecode. If conversion is not possible it returns null.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter index

    an index of element to get.

    Returns

    element value defined by the typecode or null if conversion is not supported.

    See Also

    • [[TypeConverter.toNullableType]]

method getAsObject

getAsObject: (index?: number) => any;
  • Gets the value stored in array element without any conversions. When element index is not defined it returns the entire array value.

    Parameter index

    (optional) an index of the element to get

    Returns

    the element value or value of the array when index is not defined.

method getAsString

getAsString: (index: number) => string;
  • Converts array element into a string or returns "" if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    string value ot the element or "" if conversion is not supported.

    See Also

    • [[getAsStringWithDefault]]

method getAsStringWithDefault

getAsStringWithDefault: (index: number, defaultValue: string) => string;
  • Converts array element into a string or returns default value if conversion is not possible.

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    string value ot the element or default value if conversion is not supported.

    See Also

    • [[StringConverter.toStringWithDefault]]

method getAsType

getAsType: <T>(type: TypeCode, index: number) => T;
  • Converts array element into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter index

    an index of element to get.

    Returns

    element value defined by the typecode or default if conversion is not supported.

    See Also

    • [[getAsTypeWithDefault]]

method getAsTypeWithDefault

getAsTypeWithDefault: <T>(type: TypeCode, index: number, defaultValue: T) => T;
  • Converts array element into a value defined by specied typecode. If conversion is not possible it returns default value.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter index

    an index of element to get.

    Parameter defaultValue

    the default value

    Returns

    element value defined by the typecode or default value if conversion is not supported.

    See Also

    • [[TypeConverter.toTypeWithDefault]]

method getAsValue

getAsValue: (index: number) => AnyValue;
  • Converts array element into an AnyValue or returns an empty AnyValue if conversion is not possible.

    Parameter index

    an index of element to get.

    Returns

    AnyValue value of the element or empty AnyValue if conversion is not supported.

    See Also

    • [[AnyValue]]

    • [[AnyValue.constructor]]

method put

put: (index: number, value: any) => void;
  • Puts a new value into array element specified by its index.

    Parameter index

    an index of the element to put.

    Parameter value

    a new value for array element.

method remove

remove: (index: number) => void;
  • Removes an array element specified by its index

    Parameter index

    an index of the element to remove.

method setAsObject

setAsObject: (index: any, value?: any) => void;
  • Sets a new value to array element specified by its index. When the index is not defined, it resets the entire array value. This method has double purpose because method overrides are not supported in JavaScript.

    Parameter index

    (optional) an index of the element to set

    Parameter value

    a new element or array value.

    See Also

    • [[ArrayConverter.toArray]]

method toString

toString: () => string;
  • Gets a string representation of the object. The result is a comma-separated list of string representations of individual elements as "value1,value2,value3"

    Returns

    a string representation of the object.

    See Also

    • [[StringConverter.toString]]

class AnyValueMap

class AnyValueMap implements ICloneable {}
  • Cross-language implementation of dynamic object map (dictionary) what can hold values of any type. The stored values can be converted to different types using variety of accessor methods.

    ### Example ###

    let value1 = new AnyValueMap({ key1: 1, key2: "123.456", key3: "2018-01-01" });

    value1.getAsBoolean("key1"); // Result: true value1.getAsInteger("key2"); // Result: 123 value1.getAsFloat("key2"); // Result: 123.456 value1.getAsDateTime("key3"); // Result: new Date(2018,0,1)

    See Also

    • [[StringConverter]]

    • [[TypeConverter]]

    • [[BooleanConverter]]

    • [[IntegerConverter]]

    • [[LongConverter]]

    • [[DoubleConverter]]

    • [[FloatConverter]]

    • [[DateTimeConverter]]

    • [[ICloneable]]

constructor

constructor(values?: any);
  • Creates a new instance of the map and assigns its value.

    Parameter value

    (optional) values to initialize this map.

method append

append: (map: any) => void;
  • Appends new elements to this map.

    Parameter map

    a map with elements to be added.

method clear

clear: () => any;
  • Clears this map by removing all its elements.

method clone

clone: () => any;
  • Creates a binary clone of this object.

    Returns

    a clone of this object.

method fromMaps

static fromMaps: (...maps: any[]) => AnyValueMap;
  • Creates a new AnyValueMap by merging two or more maps. Maps defined later in the list override values from previously defined maps.

    Parameter maps

    an array of maps to be merged

    Returns

    a newly created AnyValueMap.

method fromTuples

static fromTuples: (...tuples: any[]) => AnyValueMap;
  • Creates a new AnyValueMap from a list of key-value pairs called tuples.

    Parameter tuples

    a list of values where odd elements are keys and the following even elements are values

    Returns

    a newly created AnyValueArray.

    See Also

    • [[fromTuplesArray]]

method fromTuplesArray

static fromTuplesArray: (tuples: any[]) => AnyValueMap;
  • Creates a new AnyValueMap from a list of key-value pairs called tuples. The method is similar to [[fromTuples]] but tuples are passed as array instead of parameters.

    Parameter tuples

    a list of values where odd elements are keys and the following even elements are values

    Returns

    a newly created AnyValueArray.

method fromValue

static fromValue: (value: any) => AnyValueMap;
  • Converts specified value into AnyValueMap.

    Parameter value

    value to be converted

    Returns

    a newly created AnyValueMap.

    See Also

    • [[setAsObject]]

method get

get: (key: string) => any;
  • Gets a map element specified by its key.

    Parameter key

    a key of the element to get.

    Returns

    the value of the map element.

method getAsArray

getAsArray: (key: string) => AnyValueArray;
  • Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.

    See Also

    • [[AnyValueArray]]

    • [[AnyValueArray.fromValue]]

method getAsArrayWithDefault

getAsArrayWithDefault: (
key: string,
defaultValue: AnyValueArray
) => AnyValueArray;
  • Converts map element into an AnyValueArray or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    AnyValueArray value of the element or default value if conversion is not supported.

    See Also

    • [[AnyValueArray]]

    • [[getAsNullableArray]]

method getAsBoolean

getAsBoolean: (key: string) => boolean;
  • Converts map element into a boolean or returns false if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    boolean value of the element or false if conversion is not supported.

    See Also

    • [[getAsBooleanWithDefault]]

method getAsBooleanWithDefault

getAsBooleanWithDefault: (key: string, defaultValue: boolean) => boolean;
  • Converts map element into a boolean or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    boolean value of the element or default value if conversion is not supported.

    See Also

    • [[BooleanConverter.toBooleanWithDefault]]

method getAsDateTime

getAsDateTime: (key: string) => Date;
  • Converts map element into a Date or returns the current date if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    Date value of the element or the current date if conversion is not supported.

    See Also

    • [[getAsDateTimeWithDefault]]

method getAsDateTimeWithDefault

getAsDateTimeWithDefault: (key: string, defaultValue: Date) => Date;
  • Converts map element into a Date or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    Date value of the element or default value if conversion is not supported.

    See Also

    • [[DateTimeConverter.toDateTimeWithDefault]]

method getAsDouble

getAsDouble: (key: string) => number;
  • Converts map element into a double or returns 0 if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    double value of the element or 0 if conversion is not supported.

    See Also

    • [[getAsDoubleWithDefault]]

method getAsDoubleWithDefault

getAsDoubleWithDefault: (key: string, defaultValue: number) => number;
  • Converts map element into a double or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    double value of the element or default value if conversion is not supported.

    See Also

    • [[DoubleConverter.toDoubleWithDefault]]

method getAsFloat

getAsFloat: (key: string) => number;
  • Converts map element into a float or returns 0 if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    float value of the element or 0 if conversion is not supported.

    See Also

    • [[getAsFloatWithDefault]]

method getAsFloatWithDefault

getAsFloatWithDefault: (key: string, defaultValue: number) => number;
  • Converts map element into a flot or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    flot value of the element or default value if conversion is not supported.

    See Also

    • [[FloatConverter.toFloatWithDefault]]

method getAsInteger

getAsInteger: (key: string) => number;
  • Converts map element into an integer or returns 0 if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    integer value of the element or 0 if conversion is not supported.

    See Also

    • [[getAsIntegerWithDefault]]

method getAsIntegerWithDefault

getAsIntegerWithDefault: (key: string, defaultValue: number) => number;
  • Converts map element into an integer or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    integer value of the element or default value if conversion is not supported.

    See Also

    • [[IntegerConverter.toIntegerWithDefault]]

method getAsLong

getAsLong: (key: string) => number;
  • Converts map element into a long or returns 0 if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    long value of the element or 0 if conversion is not supported.

    See Also

    • [[getAsLongWithDefault]]

method getAsLongWithDefault

getAsLongWithDefault: (key: string, defaultValue: number) => number;
  • Converts map element into a long or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    long value of the element or default value if conversion is not supported.

    See Also

    • [[LongConverter.toLongWithDefault]]

method getAsMap

getAsMap: (key: string) => AnyValueMap;
  • Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.

    See Also

    • [[fromValue]]

method getAsMapWithDefault

getAsMapWithDefault: (key: string, defaultValue: AnyValueMap) => AnyValueMap;
  • Converts map element into an AnyValueMap or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    AnyValueMap value of the element or default value if conversion is not supported.

    See Also

    • [[getAsNullableMap]]

method getAsNullableArray

getAsNullableArray: (key: string) => AnyValueArray;
  • Converts map element into an AnyValueArray or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    AnyValueArray value of the element or null if conversion is not supported.

    See Also

    • [[AnyValueArray]]

    • [[AnyValueArray.fromValue]]

method getAsNullableBoolean

getAsNullableBoolean: (key: string) => boolean;
  • Converts map element into a boolean or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    boolean value of the element or null if conversion is not supported.

    See Also

    • [[BooleanConverter.toNullableBoolean]]

method getAsNullableDateTime

getAsNullableDateTime: (key: string) => Date;
  • Converts map element into a Date or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    Date value of the element or null if conversion is not supported.

    See Also

    • [[DateTimeConverter.toNullableDateTime]]

method getAsNullableDouble

getAsNullableDouble: (key: string) => number;
  • Converts map element into a double or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    double value of the element or null if conversion is not supported.

    See Also

    • [[DoubleConverter.toNullableDouble]]

method getAsNullableFloat

getAsNullableFloat: (key: string) => number;
  • Converts map element into a float or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    float value of the element or null if conversion is not supported.

    See Also

    • [[FloatConverter.toNullableFloat]]

method getAsNullableInteger

getAsNullableInteger: (key: string) => number;
  • Converts map element into an integer or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    integer value of the element or null if conversion is not supported.

    See Also

    • [[IntegerConverter.toNullableInteger]]

method getAsNullableLong

getAsNullableLong: (key: string) => number;
  • Converts map element into a long or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    long value of the element or null if conversion is not supported.

    See Also

    • [[LongConverter.toNullableLong]]

method getAsNullableMap

getAsNullableMap: (key: string) => AnyValueMap;
  • Converts map element into an AnyValueMap or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    AnyValueMap value of the element or null if conversion is not supported.

    See Also

    • [[fromValue]]

method getAsNullableString

getAsNullableString: (key: string) => string;
  • Converts map element into a string or returns null if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    string value of the element or null if conversion is not supported.

    See Also

    • [[StringConverter.toNullableString]]

method getAsNullableType

getAsNullableType: <T>(type: TypeCode, key: string) => T;
  • Converts map element into a value defined by specied typecode. If conversion is not possible it returns null.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter key

    a key of element to get.

    Returns

    element value defined by the typecode or null if conversion is not supported.

    See Also

    • [[TypeConverter.toNullableType]]

method getAsObject

getAsObject: (key?: string) => any;
  • Gets the value stored in map element without any conversions. When element key is not defined it returns the entire map value.

    Parameter key

    (optional) a key of the element to get

    Returns

    the element value or value of the map when index is not defined.

method getAsString

getAsString: (key: string) => string;
  • Converts map element into a string or returns "" if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    string value of the element or "" if conversion is not supported.

    See Also

    • [[getAsStringWithDefault]]

method getAsStringWithDefault

getAsStringWithDefault: (key: string, defaultValue: string) => string;
  • Converts map element into a string or returns default value if conversion is not possible.

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    string value of the element or default value if conversion is not supported.

    See Also

    • [[StringConverter.toStringWithDefault]]

method getAsType

getAsType: <T>(type: TypeCode, key: string) => T;
  • Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter key

    a key of element to get.

    Returns

    element value defined by the typecode or default if conversion is not supported.

    See Also

    • [[getAsTypeWithDefault]]

method getAsTypeWithDefault

getAsTypeWithDefault: <T>(type: TypeCode, key: string, defaultValue: T) => T;
  • Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value.

    Parameter type

    the TypeCode that defined the type of the result

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

    element value defined by the typecode or default value if conversion is not supported.

    See Also

    • [[TypeConverter.toTypeWithDefault]]

method getAsValue

getAsValue: (key: string) => AnyValue;
  • Converts map element into an AnyValue or returns an empty AnyValue if conversion is not possible.

    Parameter key

    a key of element to get.

    Returns

    AnyValue value of the element or empty AnyValue if conversion is not supported.

    See Also

    • [[AnyValue]]

    • [[AnyValue.constructor]]

method getKeys

getKeys: () => string[];
  • Gets keys of all elements stored in this map.

    Returns

    a list with all map keys.

method length

length: () => number;
  • Gets a number of elements stored in this map.

    Returns

    the number of elements in this map.

method put

put: (key: string, value: any) => any;
  • Puts a new value into map element specified by its key.

    Parameter key

    a key of the element to put.

    Parameter value

    a new value for map element.

method remove

remove: (key: string) => void;
  • Removes a map element specified by its key

    Parameter key

    a key of the element to remove.

method setAsObject

setAsObject: (key: any, value?: any) => void;
  • Sets a new value to map element specified by its index. When the index is not defined, it resets the entire map value. This method has double purpose because method overrides are not supported in JavaScript.

    Parameter key

    (optional) a key of the element to set

    Parameter value

    a new element or map value.

    See Also

    • [[MapConverter.toMap]]

method toString

toString: () => string;
  • Gets a string representation of the object. The result is a semicolon-separated list of key-value pairs as "key1=value1;key2=value2;key=value3"

    Returns

    a string representation of the object.

class ApplicationException

class ApplicationException extends Error {}
  • Defines a base class to defive various application exceptions.

    Most languages have own definition of base exception (error) types. However, this class is implemented symmetrically in all languages supported by PipServices toolkit. It allows to create portable implementations and support proper error propagation in microservices calls.

    Error propagation means that when microservice implemented in one language calls microservice(s) implemented in a different language(s), errors are returned throught the entire call chain and restored in their original (or close) type.

    Since number of potential exception types is endless, PipServices toolkit supports only 12 standard categories of exceptions defined in [[ErrorCategory]]. This [[ApplicationException]] class acts as a basis for all other 12 standard exception types.

    Most exceptions have just free-form message that describes occured error. That may not be sufficient to create meaninful error descriptions. The [[ApplicationException]] class proposes an extended error definition that has more standard fields:

    - message: is a human-readable error description - category: one of 12 standard error categories of errors - status: numeric HTTP status code for REST invocations - code: a unique error code, usually defined as "MY_ERROR_CODE" - correlation_id: a unique transaction id to trace execution through a call chain - details: map with error parameters that can help to recreate meaningful error description in other languages - stack_trace: a stack trace - cause: original error that is wrapped by this exception

    ApplicationException class is not serializable. To pass errors through the wire it is converted into [[ErrorDescription]] object and restored on receiving end into identical exception type.

    See Also

    • [[ErrorCategory]]

    • [[ErrorDescription]]

constructor

constructor(
category?: string,
correlation_id?: string,
code?: string,
message?: string
);
  • Creates a new instance of application exception and assigns its values.

    Parameter category

    (optional) a standard error category. Default: Unknown

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

property category

category: string;
  • Standard error category

property cause

cause: string;
  • Original error wrapped by this exception

property code

code: string;
  • A unique error code

property correlation_id

correlation_id: string;
  • A unique transaction id to trace execution throug call chain

property details

details: StringValueMap;
  • A map with additional details that can be used to restore error description in other languages

property message

message: string;
  • A human-readable error description (usually written in English)

property stack_trace

stack_trace: string;
  • Stack trace of the exception

property status

status: number;
  • HTTP status code associated with this error type

method getCauseString

getCauseString: () => string;
  • Gets original error wrapped by this exception as a string message.

    Returns

    an original error message.

method getStackTraceString

getStackTraceString: () => string;
  • Gets a stack trace where this exception occured.

    Returns

    a stack trace as a string.

method setCauseString

setCauseString: (value: string) => void;
  • Sets original error wrapped by this exception as a string message.

    Parameter value

    an original error message.

method setStackTraceString

setStackTraceString: (value: string) => void;
  • Sets a stack trace where this exception occured.

    Parameter value

    a stack trace as a string

method unwrapError

static unwrapError: (error: any) => any;
  • Unwraps original exception through wrapped exception objects.

    Many frameworks like Seneca or restify wrap original exception. That may result in propagating less specific errors and can hide causes of the errors.

    Parameter error

    an error object

    Returns

    an original error object

method withCause

withCause: (cause: Error) => ApplicationException;
  • Sets a original error wrapped by this exception

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter cause

    original error object

    Returns

    this exception object

method withCode

withCode: (code: string) => ApplicationException;
  • Sets a unique error code.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter code

    a unique error code

    Returns

    this exception object

method withCorrelationId

withCorrelationId: (correlationId: string) => ApplicationException;
  • Sets a correlation id which can be used to trace this error through a call chain.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter correlationId

    a unique transaction id to trace error through call chain

    Returns

    this exception object

method withDetails

withDetails: (key: string, value: any) => ApplicationException;
  • Sets a parameter for additional error details. This details can be used to restore error description in other languages.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter key

    a details parameter name

    Parameter value

    a details parameter name

    Returns

    this exception object

method withStackTrace

withStackTrace: (stackTrace: string) => ApplicationException;
  • Sets a stack trace for this error.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter stackTrace

    a stack trace where this error occured

    Returns

    this exception object

method withStatus

withStatus: (status: number) => ApplicationException;
  • Sets a HTTP status code which shall be returned by REST calls.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter status

    an HTTP error code.

    Returns

    this exception object

method wrap

wrap: (cause: any) => ApplicationException;
  • Wraps another exception into an application exception object.

    If original exception is of ApplicationException type it is returned without changes. Otherwise a new ApplicationException is created and original error is set as its cause.

    Parameter cause

    an original error object

    Returns

    an original or newly created ApplicationException

method wrapError

static wrapError: (
error: ApplicationException,
cause: any
) => ApplicationException;
  • Wraps another exception into specified application exception object.

    If original exception is of ApplicationException type it is returned without changes. Otherwise the original error is set as a cause to specified ApplicationException object.

    Parameter error

    an ApplicationException object to wrap the cause

    Parameter cause

    an original error object

    Returns

    an original or newly created ApplicationException

    See Also

    • [[wrap]]

class ApplicationExceptionFactory

class ApplicationExceptionFactory {}
  • Factory to recreate exceptions from [[ErrorDescription]] values passed through the wire.

    See Also

    • [[ErrorDescription]]

    • [[ApplicationException]]

method create

static create: (description: ErrorDescription) => ApplicationException;
  • Recreates ApplicationException object from serialized ErrorDescription.

    It tries to restore original exception type using type or error category fields.

    Parameter description

    a serialized error description received as a result of remote call

class ArrayConverter

class ArrayConverter {}
  • Converts arbitrary values into array objects.

    ### Example ###

    let value1 = ArrayConverter.toArray([1, 2]); // Result: [1, 2] let value2 = ArrayConverter.toArray(1); // Result: [1] let value2 = ArrayConverter.listToArray("1,2,3"); // Result: ["1", "2", "3"]

method listToArray

static listToArray: (value: any) => any[];
  • Converts value into array object with empty array as default. Strings with comma-delimited values are split into array of strings.

    Parameter value

    the list to convert.

    Returns

    array object or empty array when value is null

    See Also

    • [[toArray]]

method toArray

static toArray: (value: any) => any[];
  • Converts value into array object with empty array as default. Single values are converted into arrays with single element.

    Parameter value

    the value to convert.

    Returns

    array object or empty array when value is null.

    See Also

    • [[toNullableArray]]

method toArrayWithDefault

static toArrayWithDefault: (value: any, defaultValue: any[]) => any[];
  • Converts value into array object with specified default. Single values are converted into arrays with single element.

    Parameter value

    the value to convert.

    Parameter defaultValue

    default array object.

    Returns

    array object or default array when value is null.

    See Also

    • [[toNullableArray]]

method toNullableArray

static toNullableArray: (value: any) => any[];
  • Converts value into array object. Single values are converted into arrays with a single element.

    Parameter value

    the value to convert.

    Returns

    array object or null when value is null.

class ArraySchema

class ArraySchema extends Schema {}
  • Schema to validate arrays.

    ### Example ###

    let schema = new ArraySchema(TypeCode.String);

    schema.validate(["A", "B", "C"]); // Result: no errors schema.validate([1, 2, 3]); // Result: element type mismatch schema.validate("A"); // Result: type mismatch

constructor

constructor(valueType?: any, required?: boolean, rules?: IValidationRule[]);
  • Creates a new instance of validation schema and sets its values.

    Parameter valueType

    a type of array elements. Null means that elements may have any type.

    Parameter required

    (optional) true to always require non-null values.

    Parameter rules

    (optional) a list with validation rules.

    See Also

    • [[TypeCode]]

method getValueType

getValueType: () => any;
  • Gets the type of array elements. Null means that elements may have any type.

    Returns

    the type of array elements.

method performValidation

protected performValidation: (
path: string,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against the schema and configured validation rules.

    Parameter path

    a dot notation path to the value.

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

method setValueType

setValueType: (value: any) => void;
  • Sets the type of array elements. Null means that elements may have any type.

    Parameter value

    a type of array elements.

class AtLeastOneExistsRule

class AtLeastOneExistsRule implements IValidationRule {}
  • Validation rule that check that at least one of the object properties is not null.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new AtLeastOneExistsRule("field1", "field2"));

      schema.validate({ field1: 1, field2: "A" }); // Result: no errors schema.validate({ field1: 1 }); // Result: no errors schema.validate({ }); // Result: at least one of properties field1, field2 must exist

constructor

constructor(...properties: string[]);
  • Creates a new validation rule and sets its values

    Parameter properties

    a list of property names where at least one property must exist

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against this rule.

    Parameter path

    a dot notation path to the value.

    Parameter schema

    a schema this rule is called from

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

class BadRequestException

class BadRequestException extends ApplicationException {}
  • Errors due to improper user requests.

    For example: missing or incorrect parameters.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class BooleanConverter

class BooleanConverter {}
  • Converts arbitrary values to boolean values using extended conversion rules: - Numbers: <>0 are true, =0 are false - Strings: "true", "yes", "T", "Y", "1" are true; "false", "no", "F", "N" are false - DateTime: <>0 total milliseconds are true, =0 are false

    ### Example ###

    let value1 = BooleanConverter.toNullableBoolean(true); // true let value2 = BooleanConverter.toNullableBoolean("yes"); // true let value3 = BooleanConverter.toNullableBoolean(123); // true let value4 = BooleanConverter.toNullableBoolean({}); // null

method toBoolean

static toBoolean: (value: any) => boolean;
  • Converts value into boolean or returns false when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    boolean value or false when conversion is not supported.

    See Also

    • [[toBooleanWithDefault]]

method toBooleanWithDefault

static toBooleanWithDefault: (value: any, defaultValue?: boolean) => boolean;
  • Converts value into boolean or returns default value when conversion is not possible

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value

    Returns

    boolean value or default when conversion is not supported.

    See Also

    • [[toNullableBoolean]]

method toNullableBoolean

static toNullableBoolean: (value: any) => boolean;
  • Converts value into boolean or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    boolean value or null when convertion is not supported.

class Cleaner

class Cleaner {}
  • Helper class that cleans stored object state.

    See Also

    • [[ICleanable]]

method clear

static clear: (
correlationId: string,
components: any[],
callback?: (err: any) => void
) => void;
  • Clears state of multiple components.

    To be cleaned state components must implement [[ICleanable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter components

    the list of components that are to be cleaned.

    Parameter callback

    callback function that returns error or null no errors occured.

    See Also

    • [[clearOne]]

    • [[ICleanable]]

method clearOne

static clearOne: (
correlationId: string,
component: any,
callback?: (err: any) => void
) => void;
  • Clears state of specific component.

    To be cleaned state components must implement [[ICleanable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter component

    the component that is to be cleaned.

    Parameter callback

    callback function that returns error or null no errors occured.

    See Also

    • [[ICleanable]]

class Closer

class Closer {}
  • Helper class that closes previously opened components.

    [[IClosable]]

method close

static close: (
correlationId: string,
components: any[],
callback?: (err: any) => void
) => void;
  • Closes multiple components.

    To be closed components must implement [[ICloseable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter components

    the list of components that are to be closed.

    Parameter callback

    callback function that receives error or null no errors occured.

    See Also

    • [[closeOne]]

    • [[IClosable]]

method closeOne

static closeOne: (
correlationId: string,
component: any,
callback?: (err: any) => void
) => void;
  • Closes specific component.

    To be closed components must implement [[ICloseable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter component

    the component that is to be closed.

    Parameter callback

    callback function that receives error or null no errors occured.

    See Also

    • [[IClosable]]

class Command

class Command implements ICommand {}
  • Concrete implementation of [[ICommand ICommand]] interface. Command allows to call a method or function using Command pattern.

    ### Example ###

    let command = new Command("add", null, (correlationId, args, callback) => { let param1 = args.getAsFloat("param1"); let param2 = args.getAsFloat("param2"); let result = param1 + param2; callback(null, result); });

    command.execute( "123", Parameters.fromTuples( "param1", 2, "param2", 2 ), (err, result) => { if (err) console.error(err); else console.log("2 + 2 = " + result); } );

    // Console output: 2 + 2 = 4

    See Also

    • [[ICommand]]

    • [[CommandSet]]

constructor

constructor(name: string, schema: Schema, func: any);
  • Creates a new command object and assigns it's parameters.

    Parameter name

    the command name.

    Parameter schema

    the schema to validate command arguments.

    Parameter func

    the function to be executed by this command.

method execute

execute: (
correlationId: string,
args: Parameters,
callback: (err: any, result: any) => void
) => void;
  • Executes the command. Before execution it validates [[Parameters args]] using the defined schema. The command execution intercepts exceptions raised by the called function and returns them as an error in callback.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter args

    the parameters (arguments) to pass to this command for execution.

    Parameter callback

    function to be called when command is complete

    See Also

    • [[Parameters]]

method getName

getName: () => string;
  • Gets the command name.

    Returns

    the name of this command.

method validate

validate: (args: Parameters) => ValidationResult[];
  • Validates the command [[Parameters args]] before execution using the defined schema.

    Parameter args

    the parameters (arguments) to validate using this command's schema.

    Returns

    an array of ValidationResults or an empty array (if no schema is set).

    See Also

    • [[Parameters]]

    • [[ValidationResult]]

class CommandSet

class CommandSet {}
  • Contains a set of commands and events supported by a [[ICommandable commandable]] object. The CommandSet supports command interceptors to extend and the command call chain.

    CommandSets can be used as alternative commandable interface to a business object. It can be used to auto generate multiple external services for the business object without writing much code.

    See Also

    • [[Command]]

    • [[Event]]

    • [[ICommandable]]

      ### Example ###

      export class MyDataCommandSet extends CommandSet { private _controller: IMyDataController;

      constructor(controller: IMyDataController) { // Any data controller interface super(); this._controller = controller; this.addCommand(this.makeGetMyDataCommand()); }

      private makeGetMyDataCommand(): ICommand { return new Command( 'get_mydata', null, (correlationId: string, args: Parameters, callback: (err: any, result: any) => void) => { let param = args.getAsString('param'); this._controller.getMyData(correlationId, param, callback); } ); } }

constructor

constructor();
  • Creates an empty CommandSet object.

method addCommand

addCommand: (command: ICommand) => void;
  • Adds a [[ICommand command]] to this command set.

    Parameter command

    the command to add.

    See Also

    • [[ICommand]]

method addCommands

addCommands: (commands: ICommand[]) => void;
  • Adds multiple [[ICommand commands]] to this command set.

    Parameter commands

    the array of commands to add.

    See Also

    • [[ICommand]]

method addCommandSet

addCommandSet: (commandSet: CommandSet) => void;
  • Adds all of the commands and events from specified [[CommandSet command set]] into this one.

    Parameter commandSet

    the CommandSet to add.

method addEvent

addEvent: (event: IEvent) => void;
  • Adds an [[IEvent event]] to this command set.

    Parameter event

    the event to add.

    See Also

    • [[IEvent]]

method addEvents

addEvents: (events: IEvent[]) => void;
  • Adds multiple [[IEvent events]] to this command set.

    Parameter events

    the array of events to add.

    See Also

    • [[IEvent]]

method addInterceptor

addInterceptor: (interceptor: ICommandInterceptor) => void;
  • Adds a [[ICommandInterceptor command interceptor]] to this command set.

    Parameter interceptor

    the interceptor to add.

    See Also

    • [[ICommandInterceptor]]

method addListener

addListener: (listener: IEventListener) => void;
  • Adds a [[IEventListener listener]] to receive notifications on fired events.

    Parameter listener

    the listener to add.

    See Also

    • [[IEventListener]]

method execute

execute: (
correlationId: string,
commandName: string,
args: Parameters,
callback: (err: any, result: any) => void
) => void;
  • Executes a [[ICommand command]] specificed by its name.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter commandName

    the name of that command that is to be executed.

    Parameter args

    the parameters (arguments) to pass to the command for execution.

    Parameter callback

    the function that is to be called once execution is complete. If an exception is raised, then it will be called with the error (for example: a ValidationException can be thrown).

    See Also

    • [[ICommand]]

    • [[Parameters]]

method findCommand

findCommand: (commandName: string) => ICommand;
  • Searches for a command by its name.

    Parameter commandName

    the name of the command to search for.

    Returns

    the command, whose name matches the provided name.

    See Also

    • [[ICommand]]

method findEvent

findEvent: (eventName: string) => IEvent;
  • Searches for an event by its name in this command set.

    Parameter eventName

    the name of the event to search for.

    Returns

    the event, whose name matches the provided name.

    See Also

    • [[IEvent]]

method getCommands

getCommands: () => ICommand[];
  • Gets all commands registered in this command set.

    Returns

    a list of commands.

    See Also

    • [[ICommand]]

method getEvents

getEvents: () => IEvent[];
  • Gets all events registred in this command set.

    Returns

    a list of events.

    See Also

    • [[IEvent]]

method notify

notify: (correlationId: string, eventName: string, args: Parameters) => void;
  • Fires event specified by its name and notifies all registered [[IEventListener listeners]]

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter eventName

    the name of the event that is to be fired.

    Parameter args

    the event arguments (parameters).

method removeListener

removeListener: (listener: IEventListener) => void;
  • Removes previosly added [[IEventListener listener]].

    Parameter listener

    the listener to remove.

    See Also

    • [[IEventListener]]

method validate

validate: (commandName: string, args: Parameters) => ValidationResult[];
  • Validates [[Parameters args]] for command specified by its name using defined schema. If validation schema is not defined than the methods returns no errors. It returns validation error if the command is not found.

    Parameter commandName

    the name of the command for which the 'args' must be validated.

    Parameter args

    the parameters (arguments) to validate.

    Returns

    an array of ValidationResults. If no command is found by the given name, then the returned array of ValidationResults will contain a single entry, whose type will be ValidationResultType.Error.

    See Also

    • [[Command]]

    • [[Parameters]]

    • [[ValidationResult]]

class ConfigException

class ConfigException extends ApplicationException {}
  • Errors related to mistakes in the microservice's user-defined configurations.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class ConfigParams

class ConfigParams extends StringValueMap {}
  • Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods.

    The keys are case-sensitive, so it is recommended to use consistent C-style as: "my_param"

    Configuration parameters can be broken into sections and subsections using dot notation as: "section1.subsection1.param1". Using GetSection method all parameters from specified section can be extracted from a ConfigMap.

    The ConfigParams supports serialization from/to plain strings as: "key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z"

    ConfigParams are used to pass configurations to [[IConfigurable]] objects. They also serve as a basis for more concrete configurations such as [[https://pip-services3-node.github.io/pip-services3-components-node/classes/connect.connectionparams.html ConnectionParams]] or [[https://pip-services3-node.github.io/pip-services3-components-node/classes/auth.credentialparams.html CredentialParams]] (in the Pip.Services components package).

    See Also

    • [[IConfigurable]]

    • [[StringValueMap]]

      ### Example ###

      let config = ConfigParams.fromTuples( "section1.key1", "AAA", "section1.key2", 123, "section2.key1", true );

      config.getAsString("section1.key1"); // Result: AAA config.getAsInteger("section1.key1"); // Result: 0

      section1 = config.getSection("section1"); section1.toString(); // Result: key1=AAA;key2=123

constructor

constructor(values?: any);
  • Creates a new ConfigParams and fills it with values.

    Parameter values

    (optional) an object to be converted into key-value pairs to initialize this config map.

    See Also

    • [[StringValueMap.constructor]]

method addSection

addSection: (section: string, sectionParams: ConfigParams) => void;
  • Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix.

    Parameter section

    name of the section where add new parameters

    Parameter sectionParams

    new parameters to be added.

method fromString

static fromString: (line: string) => ConfigParams;
  • Creates a new ConfigParams object filled with key-value pairs serialized as a string.

    Parameter line

    a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"

    Returns

    a new ConfigParams object.

    See Also

    • [[StringValueMap.fromString]]

method fromTuples

static fromTuples: (...tuples: any[]) => ConfigParams;
  • Creates a new ConfigParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.

    Parameter tuples

    the tuples to fill a new ConfigParams object.

    Returns

    a new ConfigParams object.

    See Also

    • [[StringValueMap.fromTuplesArray]]

method fromValue

static fromValue: (value: any) => ConfigParams;
  • Creates a new ConfigParams object filled with key-value pairs from specified object.

    Parameter value

    an object with key-value pairs used to initialize a new ConfigParams.

    Returns

    a new ConfigParams object.

method getSection

getSection: (section: string) => ConfigParams;
  • Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys.

    Parameter section

    name of the section to retrieve configuration parameters from.

    Returns

    all configuration parameters that belong to the section named 'section'.

method getSectionNames

getSectionNames: () => string[];
  • Gets a list with all 1st level section names.

    Returns

    a list of section names stored in this ConfigMap.

method mergeConfigs

static mergeConfigs: (...configs: ConfigParams[]) => ConfigParams;
  • Merges two or more ConfigParams into one. The following ConfigParams override previously defined parameters.

    Parameter configs

    a list of ConfigParams objects to be merged.

    Returns

    a new ConfigParams object.

    See Also

    • [[StringValueMap.fromMaps]]

method override

override: (configParams: ConfigParams) => ConfigParams;
  • Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object.

    Parameter configParams

    ConfigMap with parameters to override the current values.

    Returns

    a new ConfigParams object.

    See Also

    • [[setDefaults]]

method setDefaults

setDefaults: (defaultConfigParams: ConfigParams) => ConfigParams;
  • Set default values from specified ConfigParams and returns a new ConfigParams object.

    Parameter defaultConfigParams

    ConfigMap with default parameter values.

    Returns

    a new ConfigParams object.

    See Also

    • [[override]]

class ConflictException

class ConflictException extends ApplicationException {}
  • Errors raised by conflicts between object versions that were posted by the user and those that are stored on the server.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class ConnectionException

class ConnectionException extends ApplicationException {}
  • Errors that occur during connections to remote services. They can be related to misconfiguration, network issues, or the remote service itself.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class DataPage

class DataPage<T> {}
  • Data transfer object that is used to pass results of paginated queries. It contains items of retrieved page and optional total number of items.

    Most often this object type is used to send responses to paginated queries. Pagination parameters are defined by [[PagingParams]] object. The skip parameter in the PagingParams there means how many items to skip. The takes parameter sets number of items to return in the page. And the optional total parameter tells to return total number of items in the query.

    Remember: not all implementations support the total parameter because its generation may lead to severe performance implications.

    See Also

    • [[PagingParams]]

      ### Example ###

      myDataClient.getDataByFilter( "123", FilterParams.fromTuples("completed": true), new PagingParams(0, 100, true), (err: any, page: DataPage) => { if (err == null) { console.log("Items: "); for (let item of page.Data) { console.log(item); } console.log("Total items: " + page.total); } }; );

constructor

constructor(data?: T[], total?: number);
  • Creates a new instance of data page and assigns its values.

    Parameter data

    a list of items from the retrieved page.

    Parameter total

    (optional) .

property data

data: T[];
  • The items of the retrieved page.

property total

total: number;
  • The total amount of items in a request.

class DateTimeConverter

class DateTimeConverter {}
  • Converts arbitrary values into Date values using extended conversion rules: - Strings: converted using ISO time format - Numbers: converted using milliseconds since unix epoch

    ### Example ###

    let value1 = DateTimeConverter.toNullableDateTime("ABC"); // Result: null let value2 = DateTimeConverter.toNullableDateTime("2018-01-01T11:30:00.0"); // Result: Date(2018,0,1,11,30) let value3 = DateTimeConverter.toNullableDateTime(123); // Result: Date(123)

method toDateTime

static toDateTime: (value: any) => Date;
  • Converts value into Date or returns current date when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    Date value or current date when conversion is not supported.

    See Also

    • [[toDateTimeWithDefault]]

method toDateTimeWithDefault

static toDateTimeWithDefault: (value: any, defaultValue?: Date) => Date;
  • Converts value into Date or returns default when conversion is not possible.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    Date value or default when conversion is not supported.

    See Also

    • [[toNullableDateTime]]

method toNullableDateTime

static toNullableDateTime: (value: any) => Date;
  • Converts value into Date or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    Date value or null when conversion is not supported.

class DependencyResolver

class DependencyResolver implements IReferenceable, IReconfigurable {}
  • Helper class for resolving component dependencies.

    The resolver is configured to resolve named dependencies by specific locator. During deployment the dependency locator can be changed.

    This mechanism can be used to clarify specific dependency among several alternatives. Typically components are configured to retrieve the first dependency that matches logical group, type and version. But if container contains more than one instance and resolution has to be specific about those instances, they can be given a unique name and dependency resolvers can be reconfigured to retrieve dependencies by their name.

    ### Configuration parameters ###

    dependencies: - [dependency name 1]: Dependency 1 locator (descriptor) - ... - [dependency name N]: Dependency N locator (descriptor)

    ### References ###

    References must match configured dependencies.

    ### Example ###

    class MyComponent: IConfigurable, IReferenceable { private _dependencyResolver: DependencyResolver = new DependencyResolver(); private _persistence: IMyPersistence; ...

    public constructor() { this._dependencyResolver.put("persistence", new Descriptor("mygroup", "persistence", "*", "*", "1.0")); }

    public configure(config: ConfigParams): void { this._dependencyResolver.configure(config); }

    public setReferences(references: IReferences): void { this._dependencyResolver.setReferences(references); this._persistence = this._dependencyResolver.getOneRequired("persistence"); } }

    // Create mycomponent and set specific dependency out of many let component = new MyComponent(); component.configure(ConfigParams.fromTuples( "dependencies.persistence", "mygroup:persistence:*:persistence2:1.0" // Override default persistence dependency )); component.setReferences(References.fromTuples( new Descriptor("mygroup","persistence","*","persistence1","1.0"), new MyPersistence(), new Descriptor("mygroup","persistence","*","persistence2","1.0"), new MyPersistence() // This dependency shall be set ));

    See Also

    • [[IReferences]]

constructor

constructor(config?: ConfigParams, references?: IReferences);
  • Creates a new instance of the dependency resolver.

    Parameter config

    (optional) default configuration where key is dependency name and value is locator (descriptor)

    Parameter references

    (optional) default component references

    See Also

    • [[ConfigParams]]

    • [[configure]]

    • [[IReferences]]

    • [[setReferences]]

method configure

configure: (config: ConfigParams) => void;
  • Configures the component with specified parameters.

    Parameter config

    configuration parameters to set.

    See Also

    • [[ConfigParams]]

method find

find: <T>(name: string, required: boolean) => T[];
  • Finds all matching dependencies by their name.

    Parameter name

    the dependency name to locate.

    Parameter required

    true to raise an exception when no dependencies are found.

    Returns

    a list of found dependencies

    Throws

    a [[ReferenceException]] of required is true and no dependencies found.

method fromTuples

static fromTuples: (...tuples: any[]) => DependencyResolver;
  • Creates a new DependencyResolver from a list of key-value pairs called tuples where key is dependency name and value the depedency locator (descriptor).

    Parameter tuples

    a list of values where odd elements are dependency name and the following even elements are dependency locator (descriptor)

    Returns

    a newly created DependencyResolver.

    See Also

    • [[fromTuplesArray]]

method getOneOptional

getOneOptional: <T>(name: string) => T;
  • Gets one optional dependency by its name.

    Parameter name

    the dependency name to locate.

    Returns

    a dependency reference or null of the dependency was not found

method getOneRequired

getOneRequired: <T>(name: string) => T;
  • Gets one required dependency by its name. At least one dependency must present. If the dependency was found it throws a [[ReferenceException]]

    Parameter name

    the dependency name to locate.

    Returns

    a dependency reference

    Throws

    a [[ReferenceException]] if dependency was not found.

method getOptional

getOptional: <T>(name: string) => T[];
  • Gets all optional dependencies by their name.

    Parameter name

    the dependency name to locate.

    Returns

    a list with found dependencies or empty list of no dependencies was found.

method getRequired

getRequired: <T>(name: string) => T[];
  • Gets all required dependencies by their name. At least one dependency must be present. If no dependencies was found it throws a [[ReferenceException]]

    Parameter name

    the dependency name to locate.

    Returns

    a list with found dependencies.

    Throws

    a [[ReferenceException]] if no dependencies were found.

method put

put: (name: string, locator: any) => void;
  • Adds a new dependency into this resolver.

    Parameter name

    the dependency's name.

    Parameter locator

    the locator to find the dependency by.

method setReferences

setReferences: (references: IReferences) => void;
  • Sets the component references. References must match configured dependencies.

    Parameter references

    references to set.

class Descriptor

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

constructor

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

    Parameter group

    a logical component group

    Parameter type

    a logical component type or contract

    Parameter kind

    a component implementation type

    Parameter name

    a unique component name

    Parameter version

    a component implementation version

method 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.

    Parameter value

    the value to match against this descriptor.

    Returns

    true if the value is matching descriptor and false otherwise.

    See Also

    • [[match]]

method exactMatch

exactMatch: (descriptor: Descriptor) => boolean;
  • Matches this descriptor to another descriptor by all fields. No exceptions are made.

    Parameter descriptor

    the descriptor to match this one against.

    Returns

    true if descriptors match and false otherwise.

    See Also

    • [[match]]

method fromString

static fromString: (value: String) => Descriptor;
  • Parses colon-separated list of descriptor fields and returns them as a Descriptor.

    Parameter value

    colon-separated descriptor fields to initialize Descriptor.

    Returns

    a newly created Descriptor.

    Throws

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

method getGroup

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

    Returns

    the component's logical group

method getKind

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

    Returns

    the component's implementation type.

method getName

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

    Returns

    the unique component's name.

method getType

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

    Returns

    the component's logical type.

method getVersion

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

    Returns

    the component's implementation version.

method isComplete

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

    Returns

    true if all descriptor fields are defined and false otherwise.

method match

match: (descriptor: Descriptor) => boolean;
  • Partially matches this descriptor to another descriptor. Fields that contain "*" or null are excluded from the match.

    Parameter descriptor

    the descriptor to match this one against.

    Returns

    true if descriptors match and false otherwise

    See Also

    • [[exactMatch]]

method 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

    a string representation of the object.

class DoubleConverter

class DoubleConverter {}
  • Converts arbitrary values into double using extended conversion rules: - Strings are converted to double values - DateTime: total number of milliseconds since unix epoсh - Boolean: 1 for true and 0 for false

    ### Example ###

    let value1 = DoubleConverter.toNullableDouble("ABC"); // Result: null let value2 = DoubleConverter.toNullableDouble("123.456"); // Result: 123.456 let value3 = DoubleConverter.toNullableDouble(true); // Result: 1 let value4 = DoubleConverter.toNullableDouble(new Date()); // Result: current milliseconds

method toDouble

static toDouble: (value: any) => number;
  • Converts value into doubles or returns 0 when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    double value or 0 when conversion is not supported.

    See Also

    • [[toDoubleWithDefault]]

method toDoubleWithDefault

static toDoubleWithDefault: (value: any, defaultValue?: number) => number;
  • Converts value into integer or returns default value when conversion is not possible.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    double value or default when conversion is not supported.

    See Also

    • [[toNullableDouble]]

method toNullableDouble

static toNullableDouble: (value: any) => number;
  • Converts value into doubles or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    double value or null when conversion is not supported.

class ErrorCategory

class ErrorCategory {}
  • Defines standard error categories to application exceptions supported by PipServices toolkit.

property BadRequest

static readonly BadRequest: string;
  • Errors due to incorrectly specified invocation parameters.

    For example: missing or incorrect parameters.

property Conflict

static readonly Conflict: string;
  • Errors raised by conflicts between object versions that were posted by the user and those that are stored on the server.

property FailedInvocation

static readonly FailedInvocation: string;
  • Errors caused by remote calls failed due to unidenfied reasons.

property FileError

static readonly FileError: string;
  • Errors in read/write local disk operations.

property Internal

static readonly Internal: string;
  • Internal errors caused by programming mistakes.

property InvalidState

static readonly InvalidState: string;
  • Errors caused by incorrect object state..

    For example: business calls when the component is not ready.

property Misconfiguration

static readonly Misconfiguration: string;
  • Errors related to mistakes in user-defined configurations.

property NoResponse

static readonly NoResponse: string;
  • Errors caused by remote calls timeouted and not returning results. It allows to clearly separate communication related problems from other application errors.

property NotFound

static readonly NotFound: string;
  • Errors caused by attempts to access missing objects.

property Unauthorized

static readonly Unauthorized: string;
  • Access errors caused by missing user identity (authentication error) or incorrect security permissions (authorization error).

property Unknown

static readonly Unknown: string;
  • Unknown or unexpected errors.

property Unsupported

static readonly Unsupported: string;
  • Errors caused by calls to unsupported or not yet implemented functionality.

class ErrorDescription

class ErrorDescription {}
  • Serializeable error description. It is use to pass information about errors between microservices implemented in different languages. On the receiving side [[ErrorDescription]] is used to recreate exception object close to its original type without missing additional details.

    See Also

    • [[ApplicationException]]

    • [[ApplicationExceptionFactory]]

property category

category: string;
  • Standard error category

property cause

cause: string;
  • Original error wrapped by this exception

property code

code: string;
  • A unique error code

property correlation_id

correlation_id: string;
  • A unique transaction id to trace execution throug call chain

property details

details: any;
  • A map with additional details that can be used to restore error description in other languages

property message

message: string;
  • A human-readable error description (usually written in English)

property stack_trace

stack_trace: string;
  • Stack trace of the exception

property status

status: number;
  • HTTP status code associated with this error type

property type

type: string;
  • Data type of the original error

class ErrorDescriptionFactory

class ErrorDescriptionFactory {}
  • Factory to create serializeable [[ErrorDescription]] from [[ApplicationException]] or from arbitrary errors.

    The ErrorDescriptions are used to pass errors through the wire between microservices implemented in different languages. They allow to restore exceptions on the receiving side close to the original type and preserve additional information.

    See Also

    • [[ErrorDescription]]

    • [[ApplicationException]]

method create

static create: (error: any) => ErrorDescription;
  • Creates a serializable ErrorDescription from error object.

    Parameter error

    an error object

    Returns

    a serializeable ErrorDescription object that describes the error.

class Event

class Event implements IEvent {}
  • Concrete implementation of [[IEvent IEvent]] interface. It allows to send asynchronous notifications to multiple subscribed listeners.

    See Also

    • [[IEvent]]

    • [[IEventListener]]

      ### Example ###

      let event = new Event("my_event");

      event.addListener(myListener);

      event.notify("123", Parameters.fromTuples( "param1", "ABC", "param2", 123 ));

constructor

constructor(name: string);
  • Creates a new event and assigns its name.

    Parameter name

    the name of the event that is to be created.

    Throws

    an Error if the name is null.

method addListener

addListener: (listener: IEventListener) => void;
  • Adds a listener to receive notifications when this event is fired.

    Parameter listener

    the listener reference to add.

method getListeners

getListeners: () => IEventListener[];
  • Gets all listeners registred in this event.

    Returns

    a list of listeners.

method getName

getName: () => string;
  • Gets the name of the event.

    Returns

    the name of this event.

method notify

notify: (correlationId: string, args: Parameters) => void;
  • Fires this event and notifies all registred listeners.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter args

    the parameters to raise this event with.

    Throws

    an [[InvocationException]] if the event fails to be raised.

method removeListener

removeListener: (listener: IEventListener) => void;
  • Removes a listener, so that it no longer receives notifications for this event.

    Parameter listener

    the listener reference to remove.

class ExcludedRule

class ExcludedRule implements IValidationRule {}
  • Validation rule to check that value is excluded from the list of constants.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new ExcludedRule(1, 2, 3));

      schema.validate(2); // Result: 2 must not be one of 1, 2, 3 schema.validate(10); // Result: no errors

constructor

constructor(...values: any[]);
  • Creates a new validation rule and sets its values.

    Parameter values

    a list of constants that value must be excluded from

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates the given value. None of the values set in this ExcludedRule object must exist in the value that is given for validation to pass.

    Parameter path

    the dot notation path to the value that is to be validated.

    Parameter schema

    (not used in this implementation).

    Parameter value

    the value that is to be validated.

    Parameter results

    the results of the validation.

class Executor

class Executor {}
  • Helper class that executes components.

    [[IExecutable]]

method execute

static execute: (
correlationId: string,
components: any[],
args: Parameters,
callback: (err: any, results: any[]) => void
) => void;
  • Executes multiple components.

    To be executed components must implement [[IExecutable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter components

    a list of components that are to be executed.

    Parameter args

    execution arguments.

    Parameter callback

    callback function that receives execution result or error.

    See Also

    • [[executeOne]]

    • [[IExecutable]]

    • [[Parameters]]

method executeOne

static executeOne: (
correlationId: string,
component: any,
args: Parameters,
callback: (err: any, result: any) => void
) => any;
  • Executes specific component.

    To be executed components must implement [[IExecutable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter component

    the component that is to be executed.

    Parameter args

    execution arguments.

    Parameter callback

    callback function that receives execution result or error.

    See Also

    • [[IExecutable]]

    • [[Parameters]]

class FileException

class FileException extends ApplicationException {}
  • Errors in read/write local disk operations.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class FilterParams

class FilterParams extends StringValueMap {}
  • Data transfer object used to pass filter parameters as simple key-value pairs.

    See Also

    • [[StringValueMap]]

      ### Example ###

      let filter = FilterParams.fromTuples( "type", "Type1", "from_create_time", new Date(2000, 0, 1), "to_create_time", new Date(), "completed", true ); let paging = new PagingParams(0, 100);

      myDataClient.getDataByFilter(filter, paging, (err, page) => {...});

constructor

constructor(map?: any);
  • Creates a new instance and initalizes it with elements from the specified map.

    Parameter map

    a map to initialize this instance.

method fromString

static fromString: (line: string) => FilterParams;
  • Parses semicolon-separated key-value pairs and returns them as a FilterParams.

    Parameter line

    semicolon-separated key-value list to initialize FilterParams.

    Returns

    a newly created FilterParams.

    See Also

    • [[StringValueMap.fromString]]

method fromTuples

static fromTuples: (...tuples: any[]) => FilterParams;
  • Creates a new FilterParams from a list of key-value pairs called tuples.

    Parameter tuples

    a list of values where odd elements are keys and the following even elements are values

    Returns

    a newly created FilterParams.

method fromValue

static fromValue: (value: any) => FilterParams;
  • Converts specified value into FilterParams.

    Parameter value

    value to be converted

    Returns

    a newly created FilterParams.

class FilterParamsSchema

class FilterParamsSchema extends MapSchema {}
  • Schema to validate [[FilterParams]].

    See Also

    • [[FilterParams]]

constructor

constructor();
  • Creates a new instance of validation schema.

class FixedRateTimer

class FixedRateTimer implements IClosable {}
  • Timer that is triggered in equal time intervals.

    It has summetric cross-language implementation and is often used by Pip.Services toolkit to perform periodic processing and cleanup in microservices.

    See Also

    • [[INotifiable]]

      ### Example ###

      class MyComponent { private timer: FixedRateTimer = new FixedRateTimer(() => { this.cleanup }, 60000); ... public open(correlationId: string, callback: (err: any) => void): void { ... timer.start(); ... }

      public open(correlationId: string, callback: (err: any) => void): void { ... timer.stop(); ... }

      private cleanup(): void { ... } ... }

constructor

constructor(taskOrCallback?: any, interval?: number, delay?: number);
  • Creates new instance of the timer and sets its values.

    Parameter taskOrCallback

    (optional) a Notifiable object or callback function to call when timer is triggered.

    Parameter interval

    (optional) an interval to trigger timer in milliseconds.

    Parameter delay

    (optional) a delay before the first triggering in milliseconds.

    See Also

    • [[setTask]]

    • [[setCallback]]

    • [[setInterval]]

    • [[setDelay]]

method close

close: (correlationId: string, callback?: (err: any) => void) => void;
  • Closes the timer.

    This is required by [[ICloseable]] interface, but besides that it is identical to stop().

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter callback

    callback function that receives error or null no errors occured.

    See Also

    • [[stop]]

method getCallback

getCallback: () => () => void;
  • Gets the callback function that is called when this timer is triggered.

    Returns

    the callback function or null if it is not set.

method getDelay

getDelay: () => number;
  • Gets initial delay before the timer is triggered for the first time.

    Returns

    the delay in milliseconds.

method getInterval

getInterval: () => number;
  • Gets periodic timer triggering interval.

    Returns

    the interval in milliseconds

method getTask

getTask: () => INotifiable;
  • Gets the INotifiable object that receives notifications from this timer.

    Returns

    the INotifiable object or null if it is not set.

method isStarted

isStarted: () => boolean;
  • Checks if the timer is started.

    Returns

    true if the timer is started and false if it is stopped.

method setCallback

setCallback: (value: () => void) => void;
  • Sets the callback function that is called when this timer is triggered.

    Parameter value

    the callback function to be called.

method setDelay

setDelay: (value: number) => void;
  • Sets initial delay before the timer is triggered for the first time.

    Parameter value

    a delay in milliseconds.

method setInterval

setInterval: (value: number) => void;
  • Sets periodic timer triggering interval.

    Parameter value

    an interval in milliseconds.

method setTask

setTask: (value: INotifiable) => void;
  • Sets a new INotifiable object to receive notifications from this timer.

    Parameter value

    a INotifiable object to be triggered.

method start

start: () => void;
  • Starts the timer.

    Initially the timer is triggered after delay. After that it is triggered after interval until it is stopped.

    See Also

    • [[stop]]

method stop

stop: () => void;
  • Stops the timer.

    See Also

    • [[start]]

class FloatConverter

class FloatConverter {}
  • Converts arbitrary values into float using extended conversion rules: - Strings are converted to float values - DateTime: total number of milliseconds since unix epoсh - Boolean: 1 for true and 0 for false

    ### Example ###

    let value1 = FloatConverter.toNullableFloat("ABC"); // Result: null let value2 = FloatConverter.toNullableFloat("123.456"); // Result: 123.456 let value3 = FloatConverter.toNullableFloat(true); // Result: 1 let value4 = FloatConverter.toNullableFloat(new Date()); // Result: current milliseconds

method toFloat

static toFloat: (value: any) => number;
  • Converts value into float or returns 0 when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    float value or 0 when conversion is not supported.

    See Also

    • [[DoubleConverter.toDouble]]

    • [[DoubleConverter.toDoubleWithDefault]]

method toFloatWithDefault

static toFloatWithDefault: (value: any, defaultValue: number) => number;
  • Converts value into float or returns default when conversion is not possible.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    float value or default value when conversion is not supported.

    See Also

    • [[DoubleConverter.toDoubleWithDefault]]

    • [[DoubleConverter.toNullableDouble]]

method toNullableFloat

static toNullableFloat: (value: any) => number;
  • Converts value into float or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    float value or null when conversion is not supported.

    See Also

    • [[DoubleConverter.toNullableDouble]]

class IdGenerator

class IdGenerator {}
  • Helper class to generate unique object IDs. It supports two types of IDs: long and short.

    Long IDs are string GUIDs. They are globally unique and 32-character long.

    ShortIDs are just 9-digit random numbers. They are not guaranteed be unique.

    ### Example ###

    IdGenerator.nextLong(); // Possible result: "234ab342c56a2b49c2ab42bf23ff991ac" IdGenerator.nextShort(); // Possible result: "23495247"

method nextLong

static nextLong: () => string;
  • Generates a globally unique 32-digit object ID. The value is a string representation of a GUID value.

    Returns

    a generated 32-digit object ID

method nextShort

static nextShort: () => string;
  • Generates a random 9-digit random ID (code).

    Remember: The returned value is not guaranteed to be unique.

    Returns

    a generated random 9-digit code

class IncludedRule

class IncludedRule implements IValidationRule {}
  • Validation rule to check that value is included into the list of constants.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new IncludedRule(1, 2, 3));

      schema.validate(2); // Result: no errors schema.validate(10); // Result: 10 must be one of 1, 2, 3

constructor

constructor(...values: any[]);
  • Creates a new validation rule and sets its values.

    Parameter values

    a list of constants that value must be included to

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against this rule.

    Parameter path

    a dot notation path to the value.

    Parameter schema

    a schema this rule is called from

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

class IntegerConverter

class IntegerConverter {}
  • Converts arbitrary values into integers using extended conversion rules: - Strings are converted to floats, then to integers - DateTime: total number of milliseconds since unix epoсh - Boolean: 1 for true and 0 for false

    ### Example ###

    let value1 = IntegerConverter.toNullableInteger("ABC"); // Result: null let value2 = IntegerConverter.toNullableInteger("123.456"); // Result: 123 let value3 = IntegerConverter.toNullableInteger(true); // Result: 1 let value4 = IntegerConverter.toNullableInteger(new Date()); // Result: current milliseconds

method toInteger

static toInteger: (value: any) => number;
  • Converts value into integer or returns 0 when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    integer value or 0 when conversion is not supported.

    See Also

    • [[LongConverter.toLong]]

    • [[LongConverter.toLongWithDefault]]

method toIntegerWithDefault

static toIntegerWithDefault: (value: any, defaultValue: number) => number;
  • Converts value into integer or returns default value when conversion is not possible.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    integer value or default when conversion is not supported.

    See Also

    • [[LongConverter.toLongWithDefault]]

    • [[LongConverter.toNullableLong]]

method toNullableInteger

static toNullableInteger: (value: any) => number;
  • Converts value into integer or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    integer value or null when conversion is not supported.

    See Also

    • [[LongConverter.toNullableLong]]

class InterceptedCommand

class InterceptedCommand implements ICommand {}
  • Implements a [[ICommand command]] wrapped by an interceptor. It allows to build command call chains. The interceptor can alter execution and delegate calls to a next command, which can be intercepted or concrete.

    See Also

    • [[ICommand]]

    • [[ICommandInterceptor]]

      ### Example ###

      export class CommandLogger implements ICommandInterceptor {

      public getName(command: ICommand): string { return command.getName(); }

      public execute(correlationId: string, command: ICommand, args: Parameters, callback: (err: any, result: any) => void): void { console.log("Executed command " + command.getName()); command.execute(correlationId, args, callback); }

      private validate(command: ICommand, args: Parameters): ValidationResult[] { return command.validate(args); } }

      let logger = new CommandLogger(); let loggedCommand = new InterceptedCommand(logger, command);

      // Each called command will output: Executed command <command name>

constructor

constructor(interceptor: ICommandInterceptor, next: ICommand);
  • Creates a new InterceptedCommand, which serves as a link in an execution chain. Contains information about the interceptor that is being used and the next command in the chain.

    Parameter interceptor

    the interceptor that is intercepting the command.

    Parameter next

    (link to) the next command in the command's execution chain.

method execute

execute: (
correlationId: string,
args: Parameters,
callback: (err: any, result: any) => void
) => void;
  • Executes the next command in the execution chain using the given [[Parameters parameters]] (arguments).

    Parameter correlationId

    unique transaction id to trace calls across components.

    Parameter args

    the parameters (arguments) to pass to the command for execution.

    Parameter callback

    the function that is to be called once execution is complete. If an exception is raised, then it will be called with the error.

    See Also

    • [[Parameters]]

method getName

getName: () => string;
  • Returns

    the name of the command that is being intercepted.

method validate

validate: (args: Parameters) => ValidationResult[];
  • Validates the [[Parameters parameters]] (arguments) that are to be passed to the command that is next in the execution chain.

    Parameter args

    the parameters (arguments) to validate for the next command.

    Returns

    an array of ValidationResults.

    See Also

    • [[Parameters]]

    • [[ValidationResult]]

class InternalException

class InternalException extends ApplicationException {}
  • Errors caused by programming mistakes.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class InvalidStateException

class InvalidStateException extends ApplicationException {}
  • Errors related to calling operations, which require the component to be in a specific state.

    For instance: business calls when the component is not ready.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class InvocationException

class InvocationException extends ApplicationException {}
  • Errors returned by remote services or by the network during call attempts.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class JsonConverter

class JsonConverter {}
  • Converts arbitrary values from and to JSON (JavaScript Object Notation) strings.

    ### Example ###

    let value1 = JsonConverter.fromJson("{"key":123}"); // Result: { key: 123 } let value2 = JsonConverter.toMap({ key: 123}); // Result: "{"key":123}"

    See Also

    • [[TypeCode]]

method fromJson

static fromJson: <T>(type: TypeCode, value: string) => T;
  • Converts JSON string into a value of type specified by a TypeCode.

    Parameter type

    the TypeCode for the data type into which 'value' is to be converted.

    Parameter value

    the JSON string to convert.

    Returns

    converted object value or null when value is null.

method toJson

static toJson: (value: any) => string;
  • Converts value into JSON string.

    Parameter value

    the value to convert.

    Returns

    JSON string or null when value is null.

method toMap

static toMap: (value: string) => any;
  • Converts JSON string into map object or returns empty map when conversion is not possible.

    Parameter value

    the JSON string to convert.

    Returns

    Map object value or empty object when conversion is not supported.

    See Also

    • [[toNullableMap]]

method toMapWithDefault

static toMapWithDefault: (value: string, defaultValue: any) => any;
  • Converts JSON string into map object or returns default value when conversion is not possible.

    Parameter value

    the JSON string to convert.

    Parameter defaultValue

    the default value.

    Returns

    Map object value or default when conversion is not supported.

    See Also

    • [[toNullableMap]]

method toNullableMap

static toNullableMap: (value: string) => any;
  • Converts JSON string into map object or returns null when conversion is not possible.

    Parameter value

    the JSON string to convert.

    Returns

    Map object value or null when conversion is not supported.

    See Also

    • [[MapConverter.toNullableMap]]

class LongConverter

class LongConverter {}
  • Converts arbitrary values into longs using extended conversion rules: - Strings are converted to floats, then to longs - DateTime: total number of milliseconds since unix epoсh - Boolean: 1 for true and 0 for false

    ### Example ###

    let value1 = LongConverter.toNullableLong("ABC"); // Result: null let value2 = LongConverter.toNullableLong("123.456"); // Result: 123 let value3 = LongConverter.toNullableLong(true); // Result: 1 let value4 = LongConverter.toNullableLong(new Date()); // Result: current milliseconds

method toLong

static toLong: (value: any) => number;
  • Converts value into long or returns 0 when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    long value or 0 when conversion is not supported.

    See Also

    • [[toLongWithDefault]]

method toLongWithDefault

static toLongWithDefault: (value: any, defaultValue: number) => number;
  • Converts value into integer or returns default when conversion is not possible.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    long value or default when conversion is not supported

    See Also

    • [[toNullableLong]]

method toNullableLong

static toNullableLong: (value: any) => number;
  • Converts value into long or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    long value or null when conversion is not supported.

class MapConverter

class MapConverter {}
  • Converts arbitrary values into map objects using extended conversion rules: - Objects: property names as keys, property values as values - Arrays: element indexes as keys, elements as values

    ### Example ###

    let value1 = MapConverted.toNullableMap("ABC"); // Result: null let value2 = MapConverted.toNullableMap({ key: 123 }); // Result: { key: 123 } let value3 = MapConverted.toNullableMap([1,2,3]); // Result: { "0": 1, "1": 2, "2": 3 }

method toMap

static toMap: (value: any) => any;
  • Converts value into map object or returns empty map when conversion is not possible

    Parameter value

    the value to convert.

    Returns

    map object or empty map when conversion is not supported.

    See Also

    • [[toNullableMap]]

method toMapWithDefault

static toMapWithDefault: (value: any, defaultValue: any) => any;
  • Converts value into map object or returns default when conversion is not possible

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    map object or emptu map when conversion is not supported.

    See Also

    • [[toNullableMap]]

method toNullableMap

static toNullableMap: (value: any) => any;
  • Converts value into map object or returns null when conversion is not possible.

    Parameter value

    the value to convert.

    Returns

    map object or null when conversion is not supported.

class MapSchema

class MapSchema extends Schema {}
  • Schema to validate maps.

    ### Example ###

    let schema = new MapSchema(TypeCode.String, TypeCode.Integer);

    schema.validate({ "key1": "A", "key2": "B" }); // Result: no errors schema.validate({ "key1": 1, "key2": 2 }); // Result: element type mismatch schema.validate([ 1, 2, 3 ]); // Result: type mismatch

constructor

constructor(
keyType?: any,
valueType?: any,
required?: boolean,
rules?: IValidationRule[]
);
  • Creates a new instance of validation schema and sets its values.

    Parameter keyType

    a type of map keys. Null means that keys may have any type.

    Parameter valueType

    a type of map values. Null means that values may have any type.

    Parameter required

    (optional) true to always require non-null values.

    Parameter rules

    (optional) a list with validation rules.

    See Also

    • [[IValidationRule]]

    • [[TypeCode]]

method getKeyType

getKeyType: () => any;
  • Gets the type of map keys. Null means that keys may have any type.

    Returns

    the type of map keys.

method getValueType

getValueType: () => any;
  • Gets the type of map values. Null means that values may have any type.

    Returns

    the type of map values.

method performValidation

protected performValidation: (
path: string,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against the schema and configured validation rules.

    Parameter path

    a dot notation path to the value.

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

method setKeyType

setKeyType: (value: any) => void;
  • Sets the type of map keys. Null means that keys may have any type.

    Parameter value

    a type of map keys.

method setValueType

setValueType: (value: any) => void;
  • Sets the type of map values. Null means that values may have any type.

    Parameter value

    a type of map values.

class MethodReflector

class MethodReflector {}
  • Helper class to perform method introspection and dynamic invocation.

    This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

    Because all languages have different casing and case sensitivity rules, this MethodReflector treats all method names as case insensitive.

    ### Example ###

    let myObj = new MyObject();

    let methods = MethodReflector.getMethodNames(); MethodReflector.hasMethod(myObj, "myMethod"); MethodReflector.invokeMethod(myObj, "myMethod", 123);

method getMethodNames

static getMethodNames: (obj: any) => string[];
  • Gets names of all methods implemented in specified object.

    Parameter obj

    an objec to introspect.

    Returns

    a list with method names.

method hasMethod

static hasMethod: (obj: any, name: string) => boolean;
  • Checks if object has a method with specified name..

    Parameter obj

    an object to introspect.

    Parameter name

    a name of the method to check.

    Returns

    true if the object has the method and false if it doesn't.

method invokeMethod

static invokeMethod: (obj: any, name: string, ...args: any[]) => any;
  • Invokes an object method by its name with specified parameters.

    Parameter obj

    an object to invoke.

    Parameter name

    a name of the method to invoke.

    Parameter args

    a list of method arguments.

    Returns

    the result of the method invocation or null if method returns void.

class MultiString

class MultiString {}
  • An object that contains string translations for multiple languages. Language keys use two-letter codes like: 'en', 'sp', 'de', 'ru', 'fr', 'pr'. When translation for specified language does not exists it defaults to English ('en'). When English does not exists it falls back to the first defined language.

    ### Example ###

    let values = MultiString.fromTuples( "en", "Hello World!", "ru", "Привет мир!" );

    let value1 = values.get('ru'); // Result: "Привет мир!" let value2 = values.get('pt'); // Result: "Hello World!"

constructor

constructor(map?: any);
  • Creates a new MultiString object and initializes it with values.

    Parameter map

    a map with language-text pairs.

method append

append: (map: any) => void;
  • Appends a map with language-translation pairs.

    Parameter map

    the map with language-translation pairs.

method clear

clear: () => any;
  • Clears all translations from this MultiString object.

method fromTuples

static fromTuples: (...tuples: any[]) => MultiString;
  • Creates a new MultiString object from language-translation pairs (tuples).

    Parameter tuples

    an array that contains language-translation tuples.

    Returns

    a MultiString Object.

    See Also

    • [[fromTuplesArray]]

method fromTuplesArray

static fromTuplesArray: (tuples: any[]) => MultiString;
  • Creates a new MultiString object from language-translation pairs (tuples) specified as array.

    Parameter tuples

    an array that contains language-translation tuples.

    Returns

    a MultiString Object.

method fromValue

static fromValue: (value: any) => MultiString;
  • Creates a new MultiString object from a value that contains language-translation pairs.

    Parameter value

    the value to initialize MultiString.

    Returns

    a MultiString object.

    See Also

    • [[StringValueMap]]

method get

get: (language: string) => string;
  • Gets a string translation by specified language. When language is not found it defaults to English ('en'). When English is not found it takes the first value.

    Parameter language

    a language two-symbol code.

    Returns

    a translation for the specified language or default translation.

method getLanguages

getLanguages: () => string[];
  • Gets all languages stored in this MultiString object,

    Returns

    a list with language codes.

method length

length: () => number;
  • Returns the number of translations stored in this MultiString object.

    Returns

    the number of translations.

method put

put: (language: string, value: any) => any;
  • Puts a new translation for the specified language.

    Parameter language

    a language two-symbol code.

    Parameter value

    a new translation for the specified language.

method remove

remove: (language: string) => void;
  • Removes translation for the specified language.

    Parameter language

    a language two-symbol code.

class NameResolver

class NameResolver {}
  • A helper class that allows to extract component name from configuration parameters. The name can be defined in "id", "name" parameters or inside a component descriptor.

    ### Example ###

    let config = ConfigParams.fromTuples( "descriptor", "myservice:connector:aws:connector1:1.0", "param1", "ABC", "param2", 123 );

    let name = NameResolver.resolve(config); // Result: connector1

method resolve

static resolve: (config: ConfigParams, defaultName?: string) => string;
  • Resolves a component name from configuration parameters. The name can be stored in "id", "name" fields or inside a component descriptor. If name cannot be determined it returns a defaultName.

    Parameter config

    configuration parameters that may contain a component name.

    Parameter defaultName

    (optional) a default component name.

    Returns

    resolved name or default name if the name cannot be determined.

class NotFoundException

class NotFoundException extends ApplicationException {}
  • Errors caused by attempts to access missing objects.

constructor

constructor(correlation_id?: string, code?: string, message?: string);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

    (optional) a unique transaction id to trace execution through call chain.

    Parameter code

    (optional) a unique error code. Default: "UNKNOWN"

    Parameter message

    (optional) a human-readable description of the error.

    See Also

    • [[ErrorCategory]]

class Notifier

class Notifier {}
  • Helper class that notifies components.

    [[INotifiable]]

method notify

static notify: (
correlationId: string,
components: any[],
args: Parameters
) => void;
  • Notifies multiple components.

    To be notified components must implement [[INotifiable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter components

    a list of components that are to be notified.

    Parameter args

    notification arguments.

    See Also

    • [[notifyOne]]

    • [[INotifiable]]

method notifyOne

static notifyOne: (
correlationId: string,
component: any,
args: Parameters
) => void;
  • Notifies specific component.

    To be notiied components must implement [[INotifiable]] interface. If they don't the call to this method has no effect.

    Parameter correlationId

    (optional) transaction id to trace execution through call chain.

    Parameter component

    the component that is to be notified.

    Parameter args

    notifiation arguments.

    See Also

    • [[INotifiable]]

class NotRule

class NotRule implements IValidationRule {}
  • Validation rule negate another rule. When embedded rule returns no errors, than this rule return an error. When embedded rule return errors, than the rule returns no errors.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new NotRule( new ValueComparisonRule("EQ", 1) ));

      schema.validate(1); // Result: error schema.validate(5); // Result: no error

constructor

constructor(rule: IValidationRule);
  • Creates a new validation rule and sets its values

    Parameter rule

    a rule to be negated.

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against this rule.

    Parameter path

    a dot notation path to the value.

    Parameter schema

    a schema this rule is called from

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

class ObjectComparator

class ObjectComparator {}
  • Helper class to perform comparison operations over arbitrary values.

    ### Example ###

    ObjectComparator.compare(2, "GT", 1); // Result: true ObjectComparator.areEqual("A", "B"); // Result: false

method areEqual

static areEqual: (value1: any, value2: any) => boolean;
  • Checks if two values are equal. The operation can be performed over values of any type.

    Parameter value1

    the first value to compare

    Parameter value2

    the second value to compare

    Returns

    true if values are equal and false otherwise

method areNotEqual

static areNotEqual: (value1: any, value2: any) => boolean;
  • Checks if two values are NOT equal The operation can be performed over values of any type.

    Parameter value1

    the first value to compare

    Parameter value2

    the second value to compare

    Returns

    true if values are NOT equal and false otherwise

method compare

static compare: (value1: any, operation: string, value2: any) => boolean;
  • Perform comparison operation over two arguments. The operation can be performed over values of any type.

    Parameter value1

    the first argument to compare

    Parameter operation

    the comparison operation: "==" ("=", "EQ"), "!= " ("<>", "NE"); "<"/">" ("LT"/"GT"), "<="/">=" ("LE"/"GE"); "LIKE".

    Parameter value2

    the second argument to compare

    Returns

    result of the comparison operation

method isGreater

static isGreater: (value1: any, value2: any) => boolean;
  • Checks if first value is greater than the second one. The operation can be performed over numbers or strings.

    Parameter value1

    the first value to compare

    Parameter value2

    the second value to compare

    Returns

    true if the first value is greater than second and false otherwise.

method isLess

static isLess: (value1: any, value2: any) => boolean;
  • Checks if first value is less than the second one. The operation can be performed over numbers or strings.

    Parameter value1

    the first value to compare

    Parameter value2

    the second value to compare

    Returns

    true if the first value is less than second and false otherwise.

method match

static match: (value: any, regexp: any) => boolean;
  • Checks if string matches a regular expression

    Parameter value

    a string value to match

    Parameter regexp

    a regular expression string

    Returns

    true if the value matches regular expression and false otherwise.

class ObjectReader

class ObjectReader {}
  • Helper class to perform property introspection and dynamic reading.

    In contrast to [[PropertyReflector]] which only introspects regular objects, this ObjectReader is also able to handle maps and arrays. For maps properties are key-pairs identified by string keys, For arrays properties are elements identified by integer index.

    This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

    Because all languages have different casing and case sensitivity rules, this ObjectReader treats all property names as case insensitive.

    See Also

    • [[PropertyReflector]]

      ### Example ###

      let myObj = new MyObject();

      let properties = ObjectReader.getPropertyNames(); ObjectReader.hasProperty(myObj, "myProperty"); let value = PropertyReflector.getProperty(myObj, "myProperty");

      let myMap = { key1: 123, key2: "ABC" }; ObjectReader.hasProperty(myMap, "key1"); let value = ObjectReader.getProperty(myMap, "key1");

      let myArray = [1, 2, 3] ObjectReader.hasProperty(myArrat, "0"); let value = ObjectReader.getProperty(myArray, "0");

method getProperties

static getProperties: (obj: any) => any;
  • Get values of all properties in specified object and returns them as a map.

    The object can be a user defined object, map or array. Returned properties correspondently are object properties, map key-pairs or array elements with their indexes.

    Parameter obj

    an object to get properties from.

    Returns

    a map, containing the names of the object's properties and their values.

method getProperty

static getProperty: (obj: any, name: string) => any;
  • Gets value of object property specified by its name.

    The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index.

    Parameter obj

    an object to read property from.

    Parameter name

    a name of the property to get.

    Returns

    the property value or null if property doesn't exist or introspection failed.

method getPropertyNames

static getPropertyNames: (obj: any) => string[];
  • Gets names of all properties implemented in specified object.

    The object can be a user defined object, map or array. Returned property name correspondently are object properties, map keys or array indexes.

    Parameter obj

    an objec to introspect.

    Returns

    a list with property names.

method getValue

static getValue: (obj: any) => any;
  • Gets a real object value. If object is a wrapper, it unwraps the value behind it. Otherwise it returns the same object value.

    Parameter obj

    an object to unwrap..

    Returns

    an actual (unwrapped) object value.

method hasProperty

static hasProperty: (obj: any, name: string) => boolean;
  • Checks if object has a property with specified name.

    The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index.

    Parameter obj

    an object to introspect.

    Parameter name

    a name of the property to check.

    Returns

    true if the object has the property and false if it doesn't.

class ObjectSchema

class ObjectSchema extends Schema {}
  • Schema to validate user defined objects.

    ### Example ###

    let schema = new ObjectSchema(false) .withOptionalProperty("id", TypeCode.String) .withRequiredProperty("name", TypeCode.String);

    schema.validate({ id: "1", name: "ABC" }); // Result: no errors schema.validate({ name: "ABC" }); // Result: no errors schema.validate({ id: 1, name: "ABC" }); // Result: id type mismatch schema.validate({ id: 1, _name: "ABC" }); // Result: name is missing, unexpected _name schema.validate("ABC"); // Result: type mismatch

constructor

constructor(
allowUndefined?: boolean,
required?: boolean,
rules?: IValidationRule[]
);
  • Creates a new validation schema and sets its values.

    Parameter allowUndefined

    true to allow properties undefines in the schema

    Parameter required

    (optional) true to always require non-null values.

    Parameter rules

    (optional) a list with validation rules.

    See Also

    • [[IValidationRule]]

property isUndefinedAllowed

isUndefinedAllowed: boolean;
  • Sets flag to allow undefined properties

    Parameter value

    true to allow undefined properties and false to disallow.

method allowUndefined

allowUndefined: (value: boolean) => ObjectSchema;
  • Sets flag to allow undefined properties

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter value

    true to allow undefined properties and false to disallow.

    Returns

    this validation schema.

method getProperties

getProperties: () => PropertySchema[];
  • Gets validation schemas for object properties.

    Returns

    the list of property validation schemas.

    See Also

    • [[PropertySchema]]

method performValidation

protected performValidation: (
path: string,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against the schema and configured validation rules.

    Parameter path

    a dot notation path to the value.

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

method setProperties

setProperties: (value: PropertySchema[]) => void;
  • Sets validation schemas for object properties.

    Parameter value

    a list of property validation schemas.

    See Also

    • [[PropertySchema]]

method withOptionalProperty

withOptionalProperty: (
name: string,
type?: any,
...rules: IValidationRule[]
) => ObjectSchema;
  • Adds a validation schema for an optional object property.

    Parameter name

    a property name.

    Parameter type

    (optional) a property schema or type.

    Parameter rules

    (optional) a list of property validation rules.

method withProperty

withProperty: (schema: PropertySchema) => ObjectSchema;
  • Adds a validation schema for an object property.

    This method returns reference to this exception to implement Builder pattern to chain additional calls.

    Parameter schema

    a property validation schema to be added.

    Returns

    this validation schema.

    See Also

    • [[PropertySchema]]

method withRequiredProperty

withRequiredProperty: (
name: string,
type?: any,
...rules: IValidationRule[]
) => ObjectSchema;
  • Adds a validation schema for a required object property.

    Parameter name

    a property name.

    Parameter type

    (optional) a property schema or type.

    Parameter rules

    (optional) a list of property validation rules.

class ObjectWriter

class ObjectWriter {}
  • Helper class to perform property introspection and dynamic writing.

    In contrast to [[PropertyReflector]] which only introspects regular objects, this ObjectWriter is also able to handle maps and arrays. For maps properties are key-pairs identified by string keys, For arrays properties are elements identified by integer index.

    This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

    Because all languages have different casing and case sensitivity rules, this ObjectWriter treats all property names as case insensitive.

    See Also

    • [[PropertyReflector]]

      ### Example ###

      let myObj = new MyObject();

      ObjectWriter.setProperty(myObj, "myProperty", 123);

      let myMap = { key1: 123, key2: "ABC" }; ObjectWriter.setProperty(myMap, "key1", "XYZ");

      let myArray = [1, 2, 3] ObjectWriter.setProperty(myArray, "0", 123);

method setProperties

static setProperties: (obj: any, values: any) => void;
  • Sets values of some (all) object properties.

    The object can be a user defined object, map or array. Property values correspondently are object properties, map key-pairs or array elements with their indexes.

    If some properties do not exist or introspection fails they are just silently skipped and no errors thrown.

    Parameter obj

    an object to write properties to.

    Parameter values

    a map, containing property names and their values.

    See Also

    • [[setProperty]]

method setProperty

static setProperty: (obj: any, name: string, value: any) => void;
  • Sets value of object property specified by its name.

    The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index.

    If the property does not exist or introspection fails this method doesn't do anything and doesn't any throw errors.

    Parameter obj

    an object to write property to.

    Parameter name

    a name of the property to set.

    Parameter value

    a new value for the property to set.

class OnlyOneExistsRule

class OnlyOneExistsRule implements IValidationRule {}
  • Validation rule that check that at exactly one of the object properties is not null.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new OnlyOneExistsRule("field1", "field2"));

      schema.validate({ field1: 1, field2: "A" }); // Result: only one of properties field1, field2 must exist schema.validate({ field1: 1 }); // Result: no errors schema.validate({ }); // Result: only one of properties field1, field2 must exist

constructor

constructor(...properties: string[]);
  • Creates a new validation rule and sets its values

    Parameter properties

    a list of property names where at only one property must exist

method validate

validate: (
path: string,
schema: Schema,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value against this rule.

    Parameter path

    a dot notation path to the value.

    Parameter schema

    a schema this rule is called from

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

class Opener

class Opener {}
  • Helper class that opens components.

    [[IOpenable]]

method isOpen

static isOpen: (components: any[]) => boolean;
  • Checks if all components are opened.

    To be checked components must implement [[IOpenable]] interface. If they don't the call to this method returns true.

    Parameter components

    a list of components that are to be checked.

    Returns

    true if all components are opened and false if at least one component is closed.

    See Also

    • [[isOpenOne]]

    • [[IOpenable]]

method isOpenOne

static isOpenOne: (component: any) => boolean;
  • Checks if specified component is opened.

    To be checked components must implement [[IOpenable]] interface. If they don't the call to this method returns true.

    Parameter component

    the component that is to be checked.

    Returns

    true if component is opened and false otherwise.

    See Also

    • [[IOpenable]]

method open

static