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 open: (
correlationId: string,
components: any[],
callback?: (err: any) => void
) => void;
  • Opens multiple components.

    To be opened components must implement [[IOpenable]] 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 returns error or null no errors occured.

    See Also

    • [[openOne]]

    • [[IOpenable]]

method openOne

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

    To be opened components must implement [[IOpenable]] 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 opened.

    Parameter callback

    callback function that returns error or null no errors occured.

    See Also

    • [[IOpenable]]

class OptionResolver

class OptionResolver {}
  • A helper class to parameters from "options" configuration section.

    ### Example ###

    let config = ConfigParams.fromTuples( ... "options.param1", "ABC", "options.param2", 123 );

    let options = OptionsResolver.resolve(config); // Result: param1=ABC;param2=123

method resolve

static resolve: (
config: ConfigParams,
configAsDefault?: boolean
) => ConfigParams;
  • Resolves an "options" configuration section from component configuration parameters.

    Parameter config

    configuration parameters

    Parameter configAsDefault

    (optional) When set true the method returns the entire parameter set when "options" section is not found. Default: false

    Returns

    configuration parameters from "options" section

class OrRule

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

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new Schema() .withRule(new OrRule( new ValueComparisonRule("LT", 1), new ValueComparisonRule("GT", 10) ));

      schema.validate(0); // Result: no error schema.validate(5); // Result: 5 must be less than 1 or 5 must be more than 10 schema.validate(20); // Result: no error

constructor

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

    Parameter rules

    a list of rules to join with OR 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 PagingParams

class PagingParams {}
  • Data transfer object to pass paging parameters for queries.

    The page is defined by two parameters: - the skip parameter defines number of items to skip. - the take parameter sets how many items to return in a page. - additionally, 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.

    ### Example ###

    let filter = FilterParams.fromTuples("type", "Type1"); let paging = new PagingParams(0, 100);

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

constructor

constructor(skip?: any, take?: any, total?: any);
  • Creates a new instance and sets its values.

    Parameter skip

    the number of items to skip.

    Parameter take

    the number of items to return.

    Parameter total

    true to return the total number of items.

property skip

skip: number;
  • The number of items to skip.

property take

take: number;
  • The number of items to return.

property total

total: boolean;
  • The flag to return the total number of items.

method fromMap

static fromMap: (map: any) => PagingParams;
  • Creates a new PagingParams and sets it parameters from the specified map

    Parameter map

    a AnyValueMap or StringValueMap to initialize this PagingParams

    Returns

    a newly created PagingParams.

method fromTuples

static fromTuples: (...tuples: any[]) => PagingParams;
  • Creates a new PagingParams 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 PagingParams.

method fromValue

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

    Parameter value

    value to be converted

    Returns

    a newly created PagingParams.

method getSkip

getSkip: (minSkip: number) => number;
  • Gets the number of items to skip.

    Parameter minSkip

    the minimum number of items to skip.

    Returns

    the number of items to skip.

method getTake

getTake: (maxTake: number) => number;
  • Gets the number of items to return in a page.

    Parameter maxTake

    the maximum number of items to return.

    Returns

    the number of items to return.

class PagingParamsSchema

class PagingParamsSchema extends ObjectSchema {}
  • Schema to validate [[PagingParams]].

    See Also

    • [[PagingParams]]

constructor

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

class Parameters

class Parameters extends AnyValueMap {}
  • Contains map with execution parameters.

    In general, this map may contain non-serializable values. And in contrast with other maps, its getters and setters support dot notation and able to access properties in the entire object graph.

    This class is often use to pass execution and notification arguments, and parameterize classes before execution.

    See Also

    • [[IParameterized]]

    • [[AnyValueMap]]

constructor

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

    Parameter value

    (optional) values to initialize this map.

method assignTo

assignTo: (value: any) => void;
  • Assigns (copies over) properties from the specified value to this map.

    Parameter value

    value whose properties shall be copied over.

method containsKey

containsKey: (key: string) => boolean;
  • Checks if this map contains an element with specified key.

    The key can be defined using dot notation and allows to recursively access elements of elements.

    Parameter key

    a key to be checked

    Returns

    true if this map contains the key or false otherwise.

method fromConfig

static fromConfig: (config: ConfigParams) => Parameters;
  • Creates new Parameters from ConfigMap object.

    Parameter config

    a ConfigParams that contain parameters.

    Returns

    a new Parameters object.

    See Also

    • [[ConfigParams]]

method fromJson

static fromJson: (json: string) => Parameters;
  • Creates new Parameters from JSON object.

    Parameter json

    a JSON string containing parameters.

    Returns

    a new Parameters object.

    See Also

    • [[JsonConverter.toNullableMap]]

method fromTuples

static fromTuples: (...tuples: any[]) => Parameters;
  • Creates a new Parameters 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 Parameters object.

    Returns

    a new Parameters object.

    See Also

    • [[AnyValueMap.fromTuplesArray]]

method fromValue

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

    Parameter value

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

    Returns

    a new Parameters object.

method get

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

    The key can be defined using dot notation and allows to recursively access elements of elements.

    Parameter key

    a key of the element to get.

    Returns

    the value of the map element.

method getAsNullableParameters

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

    Parameter key

    a key of element to get.

    Returns

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

method getAsParameters

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

    Parameter key

    a key of element to get.

    Returns

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

method getAsParametersWithDefault

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

    Parameter key

    a key of element to get.

    Parameter defaultValue

    the default value

    Returns

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

method mergeParams

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

    Parameter configs

    a list of Parameters objects to be merged.

    Returns

    a new Parameters object.

    See Also

    • [[AnyValueMap.fromMaps]]

method omit

omit: (...paths: string[]) => Parameters;
  • Omits selected parameters from this Parameters and returns the rest as a new Parameters object.

    Parameter paths

    keys to be omitted from copying over to new Parameters.

    Returns

    a new Parameters object.

method override

override: (parameters: Parameters, recursive?: boolean) => Parameters;
  • Overrides parameters with new values from specified Parameters and returns a new Parameters object.

    Parameter parameters

    Parameters with parameters to override the current values.

    Parameter recursive

    (optional) true to perform deep copy, and false for shallow copy. Default: false

    Returns

    a new Parameters object.

    See Also

    • [[setDefaults]]

method pick

pick: (...paths: string[]) => Parameters;
  • Picks select parameters from this Parameters and returns them as a new Parameters object.

    Parameter paths

    keys to be picked and copied over to new Parameters.

    Returns

    a new Parameters object.

method put

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

    The key can be defined using dot notation and allows to recursively access elements of elements.

    Parameter key

    a key of the element to put.

    Parameter value

    a new value for map element.

method setDefaults

setDefaults: (defaultParameters: Parameters, recursive?: boolean) => Parameters;
  • Set default values from specified Parameters and returns a new Parameters object.

    Parameter defaultParameters

    Parameters with default parameter values.

    Parameter recursive

    (optional) true to perform deep copy, and false for shallow copy. Default: false

    Returns

    a new Parameters object.

    See Also

    • [[override]]

method toJson

toJson: () => string;
  • Converts this map to JSON object.

    Returns

    a JSON representation of this map.

class ProjectionParams

class ProjectionParams extends Array<string> {}
  • Defines projection parameters with list if fields to include into query results.

    The parameters support two formats: dot format and nested format.

    The dot format is the standard way to define included fields and subfields using dot object notation: "field1,field2.field21,field2.field22.field221".

    As alternative the nested format offers a more compact representation: "field1,field2(field21,field22(field221))".

    ### Example ###

    let filter = FilterParams.fromTuples("type", "Type1"); let paging = new PagingParams(0, 100); let projection = ProjectionParams.fromString("field1,field2(field21,field22)")

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

constructor

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

    Parameter value

    (optional) values to initialize this object.

method fromString

static fromString: (...values: string[]) => ProjectionParams;
  • Parses comma-separated list of projection fields.

    Parameter values

    one or more comma-separated lists of projection fields

    Returns

    a newly created ProjectionParams.

method fromValue

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

    Parameter value

    value to be converted

    Returns

    a newly created ProjectionParams.

    See Also

    • [[AnyValueArray.fromValue]]

method toString

toString: () => string;
  • Gets a string representation of the object. The result is a comma-separated list of projection fields "field1,field2.field21,field2.field22.field221"

    Returns

    a string representation of the object.

class ProjectionParamsSchema

class ProjectionParamsSchema extends ArraySchema {}
  • Schema to validate [[ProjectionParams]]

    See Also

    • [[ProjectionParams]]

constructor

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

class PropertiesComparisonRule

class PropertiesComparisonRule implements IValidationRule {}
  • Validation rule that compares two object properties.

    See Also

    • [[IValidationRule]]

      ### Example ###

      let schema = new ObjectSchema() .withRule(new PropertyComparisonRule("field1", "NE", "field2"));

      schema.validate({ field1: 1, field2: 2 }); // Result: no errors schema.validate({ field1: 1, field2: 1 }); // Result: field1 shall not be equal to field2 schema.validate({}); // Result: no errors

constructor

constructor(property1: string, operation: string, property2: string);
  • Creates a new validation rule and sets its arguments.

    Parameter property1

    a name of the first property to compare.

    Parameter operation

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

    Parameter property2

    a name of the second property to compare.

    See Also

    • [[ObjectComparator.compare]]

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 PropertyReflector

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

    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 PropertyReflector treats all property names as case insensitive.

    ### Example ###

    let myObj = new MyObject();

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

method getProperties

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

    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.

    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.

    Parameter obj

    an objec to introspect.

    Returns

    a list with property names.

method hasProperty

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

    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.

method setProperties

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

    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.

    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 PropertySchema

class PropertySchema extends Schema {}
  • Schema to validate object properties

    See Also

    • [[ObjectSchema]]

      ### Example ###

      let schema = new ObjectSchema() .withProperty(new PropertySchema("id", 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

constructor

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

    Parameter name

    (optional) a property name

    Parameter type

    (optional) a property type

    Parameter required

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

    Parameter rules

    (optional) a list with validation rules.

    See Also

    • [[IValidationRule]]

    • [[TypeCode]]

method getName

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

    Returns

    the property name.

method getType

getType: () => any;
  • Gets the property type.

    Returns

    the property type.

method performValidation

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 setName

setName: (value: string) => void;
  • Sets the property name.

    Parameter value

    a new property name.

method setType

setType: (value: any) => void;
  • Sets a new property type. The type can be defined as type, type name or [[TypeCode]]

    Parameter value

    a new property type.

class RandomArray

class RandomArray {}
  • Random generator for array objects.

    ### Example ###

    let value1 = RandomArray.pick([1, 2, 3, 4]); // Possible result: 3

method pick

static pick: <T>(values: T[]) => T;
  • Picks a random element from specified array.

    Parameter values

    an array of any type

    Returns

    a randomly picked item.

class RandomBoolean

class RandomBoolean {}
  • Random generator for boolean values.

    ### Example ###

    let value1 = RandomBoolean.nextBoolean(); // Possible result: true let value2 = RandomBoolean.chance(1,3); // Possible result: false

method chance

static chance: (chance: number, maxChances: number) => boolean;
  • Calculates "chance" out of "max chances". Example: 1 chance out of 3 chances (or 33.3%)

    Parameter chance

    a chance proportional to maxChances.

    Parameter maxChances

    a maximum number of chances

method nextBoolean

static nextBoolean: () => boolean;
  • Generates a random boolean value.

    Returns

    a random boolean.

class RandomDateTime

class RandomDateTime {}
  • Random generator for Date time values.

    ### Example ###

    let value1 = RandomDateTime.nextDate(new Date(2010,0,1)); // Possible result: 2008-01-03 let value2 = RandomDateTime.nextDateTime(new Date(2017,0.1));// Possible result: 2007-03-11 11:20:32 let value3 = RandomDateTime.updateDateTime(new Date(2010,1,2));// Possible result: 2010-02-05 11:33:23

method nextDate

static nextDate: (min: Date, max?: Date) => Date;
  • Generates a random Date in the range ['minYear', 'maxYear']. This method generate dates without time (or time set to 00:00:00)

    Parameter min

    (optional) minimum range value

    Parameter max

    max range value

    Returns

    a random Date value.

method nextDateTime

static nextDateTime: (min: Date, max?: Date) => Date;
  • Generates a random Date and time in the range ['minYear', 'maxYear']. This method generate dates without time (or time set to 00:00:00)

    Parameter min

    (optional) minimum range value

    Parameter max

    max range value

    Returns

    a random Date and time value.

method updateDateTime

static updateDateTime: (value: Date, range?: number) => Date;
  • Updates (drifts) a Date value within specified range defined

    Parameter value

    a Date value to drift.

    Parameter range

    (optional) a range in milliseconds. Default: 10 days

class RandomDouble

class RandomDouble {}
  • Random generator for double values.

    ### Example ###

    let value1 = RandomDouble.nextDouble(5, 10); // Possible result: 7.3 let value2 = RandomDouble.nextDouble(10); // Possible result: 3.7 let value3 = RandomDouble.updateDouble(10, 3); // Possible result: 9.2

method nextDouble

static nextDouble: (min: number, max?: number) => number;
  • Generates a random double value in the range ['minYear', 'maxYear'].

    Parameter min

    (optional) minimum range value

    Parameter max

    max range value

    Returns

    a random double value.

method updateDouble

static updateDouble: (value: number, range?: number) => number;
  • Updates (drifts) a double value within specified range defined

    Parameter value

    a double value to drift.

    Parameter range

    (optional) a range. Default: 10% of the value

class RandomFloat

class RandomFloat {}
  • Random generator for float values.

    ### Example ###

    let value1 = RandomFloat.nextFloat(5, 10); // Possible result: 7.3 let value2 = RandomFloat.nextFloat(10); // Possible result: 3.7 let value3 = RandomFloat.updateFloat(10, 3); // Possible result: 9.2

method nextFloat

static nextFloat: (min: number, max?: number) => number;
  • Generates a float in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].

    Parameter min

    minimum value of the float that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.

    Parameter max

    (optional) maximum value of the float that will be generated. Defaults to 'min' if omitted.

    Returns

    generated random float value.

method updateFloat

static updateFloat: (value: number, range?: number) => number;
  • Updates (drifts) a float value within specified range defined

    Parameter value

    a float value to drift.

    Parameter range

    (optional) a range. Default: 10% of the value

class RandomInteger

class RandomInteger {}
  • Random generator for integer values.

    ### Example ###

    let value1 = RandomInteger.nextInteger(5, 10); // Possible result: 7 let value2 = RandomInteger.nextInteger(10); // Possible result: 3 let value3 = RandomInteger.updateInteger(10, 3); // Possible result: 9

method nextInteger

static nextInteger: (min: number, max?: number) => number;
  • Generates a integer in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].

    Parameter min

    minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.

    Parameter max

    (optional) maximum value of the float that will be generated. Defaults to 'min' if omitted.

    Returns

    generated random integer value.

method sequence

static sequence: (min: number, max?: number) => number[];
  • Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]

    Parameter min

    minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.

    Parameter max

    (optional) maximum value of the float that will be generated. Defaults to 'min' if omitted.

    Returns

    generated array of integers.

method updateInteger

static updateInteger: (value: number, range?: number) => number;
  • Updates (drifts) a integer value within specified range defined

    Parameter value

    a integer value to drift.

    Parameter range

    (optional) a range. Default: 10% of the value

class RandomString

class RandomString {}
  • Random generator for string values.

    ### Example ###

    let value1 = RandomString.pickChar("ABC"); // Possible result: "C" let value2 = RandomString.pick(["A","B","C"]); // Possible result: "gBW"

method distort

static distort: (value: string) => string;
  • Distorts a string by randomly replacing characters in it.

    Parameter value

    a string to distort.

    Returns

    a distored string.

method nextAlphaChar

static nextAlphaChar: () => string;
  • Generates random alpha characted [A-Za-z]

    Returns

    a random characted.

method nextString

static nextString: (minLength: number, maxLength: number) => string;
  • Generates a random string, consisting of upper and lower case letters (of the English alphabet), digits (0-9), and symbols ("_,.:-/.[].{},#-!,$=%.+^.&*-() ").

    Parameter minLength

    (optional) minimum string length.

    Parameter maxLength

    maximum string length.

    Returns

    a random string.

method pick

static pick: (values: string[]) => string;
  • Picks a random string from an array of string.

    Parameter values

    strings to pick from.

    Returns

    a randomly picked string.

method pickChar

static pickChar: (values: string) => string;
  • Picks a random character from a string.

    Parameter values

    a string to pick a char from

    Returns

    a randomly picked char.

class RandomText

class RandomText {}
  • Random generator for various text values like names, addresses or phone numbers.

    ### Example ###

    let value1 = RandomText.name(); // Possible result: "Segio" let value2 = RandomText.verb(); // Possible result: "Run" let value3 = RandomText.Text(50); // Possible result: "Run jorge. Red high scream?"

method adjective

static adjective: () => string;
  • Generates a random adjective. The result value is capitalized.

    Returns

    a random adjective.

method color

static color: () => string;
  • Generates a random color name. The result value is capitalized.

    Returns

    a random color name.

method email

static email: () => string;
  • Generates a random email address.

    Returns

    a random email address.

method fullName

static fullName: () => string;
  • Generates a random person's name which has the following structure <optional prefix> <first name> <second name> <optional suffix>

    Returns

    a random name.

method noun

static noun: () => string;
  • Generates a random noun. The result value is capitalized.

    Returns

    a random noun.

method phone

static phone: () => string;
  • Generates a random phone number. The phone number has the format: (XXX) XXX-YYYY

    Returns

    a random phone number.

method phrase

static phrase: (minLength: number, maxLength?: number) => string;
  • Generates a random phrase which consists of few words separated by spaces. The first word is capitalized, others are not.

    Parameter minLength

    (optional) minimum string length.

    Parameter maxLength

    maximum string length.

    Returns

    a random phrase.

method text

static text: (minLength: number, maxLength?: number) => string;
  • Generates a random text, consisting of first names, last names, colors, stuffs, adjectives, verbs, and punctuation marks.

    Parameter minLength

    minimum amount of words to generate. Text will contain 'minSize' words if 'maxSize' is omitted.

    Parameter maxLength

    (optional) maximum amount of words to generate.

    Returns

    a random text.

method verb

static verb: () => string;
  • Generates a random verb. The result value is capitalized.

    Returns

    a random verb.

method word

static word: () => string;
  • Generates a random word from available first names, last names, colors, stuffs, adjectives, or verbs.

    Returns

    a random word.

method words

static words: (min: number, max?: number) => string;
  • Generates a random text that consists of random number of random words separated by spaces.

    Parameter min

    (optional) a minimum number of words.

    Parameter max

    a maximum number of words.

    Returns

    a random text.

class RecursiveMapConverter

class RecursiveMapConverter {}
  • Converts arbitrary values into map objects using extended conversion rules. This class is similar to [[MapConverter]], but is recursively converts all values stored in objects and arrays.

    ### Example ###

    let value1 = RecursiveMapConverted.toNullableMap("ABC"); // Result: null let value2 = RecursiveMapConverted.toNullableMap({ key: 123 }); // Result: { key: 123 } let value3 = RecursiveMapConverted.toNullableMap([1,[2,3]); // Result: { "0": 1, { "0": 2, "1": 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 RecursiveObjectReader

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

    It is similar to [[ObjectReader]] but reads properties recursively through the entire object graph. Nested property names are defined using dot notation as "object.subobject.property"

    See Also

    • [[PropertyReflector]]

    • [[ObjectReader]]

method getProperties

static getProperties: (obj: any) => any;
  • Get values of all properties in specified object and its subobjects 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;
  • Recursively gets value of object or its subobjects 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[];
  • Recursively gets names of all properties implemented in specified object and its subobjects.

    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 hasProperty

static hasProperty: (obj: any, name: string) => boolean;
  • Checks recursively if object or its subobjects 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 RecursiveObjectWriter

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

    It is similar to [[ObjectWriter]] but writes properties recursively through the entire object graph. Nested property names are defined using dot notation as "object.subobject.property"

    See Also

    • [[PropertyReflector]]

    • [[ObjectWriter]]

method copyProperties

static copyProperties: (dest: any, src: any) => void;
  • Copies content of one object to another object by recursively reading all properties from source object and then recursively writing them to destination object.

    Parameter dest

    a destination object to write properties to.

    Parameter src

    a source object to read properties from

method setProperties

static setProperties: (obj: any, values: any) => void;
  • Recursively sets values of some (all) object and its subobjects 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;
  • Recursively sets value of object and its subobjects 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 Reference

class Reference {}
  • Contains a reference to a component and locator to find it. It is used by [[References]] to store registered component references.

constructor

constructor(locator: any, component: any);
  • Create a new instance of the reference object and assigns its values.

    Parameter locator

    a locator to find the reference.

    Parameter reference

    a reference to component.

method getComponent

getComponent: () => any;
  • Gets the stored component reference.

    the component's references.

method getLocator

getLocator: () => any;
  • Gets the stored component locator.

    the component's locator.

method match

match: (locator: any) => boolean;
  • Matches locator to this reference locator.

    Descriptors are matched using equal method. All other locator types are matched using direct comparison.

    Parameter locator

    the locator to match. true if locators are matching and false it they don't.

    See Also

    • [[Descriptor]]

class ReferenceException

class ReferenceException extends InternalException {}
  • Error when required component dependency cannot be found.

constructor

constructor(correlationId: string, locator: any);
  • Creates an error instance and assigns its values.

    Parameter correlation_id

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

    Parameter locator

    the locator to find reference to dependent component.

class Referencer

class Referencer {}
  • Helper class that sets and unsets references to components.

    See Also

    • [[IReferenceable]]

    • [[IUnreferenceable]]

method setReferences

static setReferences: (references: IReferences, components: any[]) => void;
  • Sets references to multiple components.

    To set references components must implement [[IReferenceable]] interface. If they don't the call to this method has no effect.

    Parameter references

    the references to be set.

    Parameter components

    a list of components to set the references to.

    See Also

    • [[IReferenceable]]

method setReferencesForOne

static setReferencesForOne: (references: IReferences, component: any) => void;
  • Sets references to specific component.

    To set references components must implement [[IReferenceable]] interface. If they don't the call to this method has no effect.

    Parameter references

    the references to be set.

    Parameter component

    the component to set references to.

    See Also

    • [[IReferenceable]]

method unsetReferences

static unsetReferences: (components: any[]) => void;
  • Unsets references in multiple components.

    To unset references components must implement [[IUnreferenceable]] interface. If they don't the call to this method has no effect.

    Parameter components

    the list of components, whose references must be cleared.

    See Also

    • [[IUnreferenceable]]

method unsetReferencesForOne

static unsetReferencesForOne: (component: any) => void;
  • Unsets references in specific component.

    To unset references components must implement [[IUnreferenceable]] interface. If they don't the call to this method has no effect.

    Parameter component

    the component to unset references.

    See Also

    • [[IUnreferenceable]]

class References

class References implements IReferences {}
  • The most basic implementation of [[IReferences]] to store and locate component references.

    See Also

    • [[IReferences]]

      ### Example ###

      export class MyController implements IReferenceable { public _persistence: IMyPersistence; ... public setReferences(references: IReferences): void { this._persistence = references.getOneRequired( new Descriptor("mygroup", "persistence", "*", "*", "1.0") ); } ... }

      let persistence = new MyMongoDbPersistence();

      let controller = new MyController();

      let references = References.fromTuples( new Descriptor("mygroup", "persistence", "mongodb", "default", "1.0"), persistence, new Descriptor("mygroup", "controller", "default", "default", "1.0"), controller ); controller.setReferences(references);

constructor

constructor(tuples?: any[]);
  • Creates a new instance of references and initializes it with references.

    Parameter tuples

    (optional) a list of values where odd elements are locators and the following even elements are component references

method find

find: <T>(locator: any, required: boolean) => T[];
  • Gets all component references that match specified locator.

    Parameter locator

    the locator to find a reference by.

    Parameter required

    forces to raise an exception if no reference is found.

    Returns

    a list with matching component references.

    Throws

    a [[ReferenceException]] when required is set to true but no references found.

method fromTuples

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

    Parameter tuples

    a list of values where odd elements are locators and the following even elements are component references

    Returns

    a newly created References.

    See Also

    • [[fromTuplesArray]]

method getAll

getAll: () => any[];
  • Gets all component references registered in this reference map.

    Returns

    a list with component references.

method getAllLocators

getAllLocators: () => any[];
  • Gets locators for all registered component references in this reference map.

    Returns

    a list with component locators.

method getOneOptional

getOneOptional: <T>(locator: any) => T;
  • Gets an optional component reference that matches specified locator.

    Parameter locator

    the locator to find references by.

    Returns

    a matching component reference or null if nothing was found.

method getOneRequired

getOneRequired: <T>(locator: any) => T;
  • Gets a required component reference that matches specified locator.

    Parameter locator

    the locator to find a reference by.

    Returns

    a matching component reference.

    Throws

    a [[ReferenceException]] when no references found.

method getOptional

getOptional: <T>(locator: any) => T[];
  • Gets all component references that match specified locator.

    Parameter locator

    the locator to find references by.

    Returns

    a list with matching component references or empty list if nothing was found.

method getRequired

getRequired: <T>(locator: any) => T[];
  • Gets all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error.

    Parameter locator

    the locator to find references by.

    Returns

    a list with matching component references.

    Throws

    a [[ReferenceException]] when no references found.

method put

put: (locator: any, component: any) => void;
  • Puts a new reference into this reference map.

    Parameter locator

    a locator to find the reference by.

    Parameter component

    a component reference to be added.

method remove

remove: (locator: any) => any;
  • Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use [[removeAll]] method instead.

    Parameter locator

    a locator to remove reference

    Returns

    the removed component reference.

    See Also

    • [[removeAll]]

method removeAll

removeAll: (locator: any) => any[];
  • Removes all component references that match the specified locator.

    Parameter locator

    the locator to remove references by.

    Returns

    a list, containing all removed references.

class Schema

class Schema {}
  • Basic schema that validates values against a set of validation rules.

    This schema is used as a basis for specific schemas to validate objects, project properties, arrays and maps.

    See Also

    • [[ObjectSchema]]

    • [[PropertySchema]]

    • [[ArraySchema]]

    • [[MapSchema]]

constructor

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

    Parameter required

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

    Parameter rules

    (optional) a list with validation rules.

    See Also

    • [[IValidationRule]]

method getRules

getRules: () => IValidationRule[];
  • Gets validation rules to check values against.

    Returns

    a list with validation rules.

method isRequired

isRequired: () => boolean;
  • Gets a flag that always requires non-null values. For null values it raises a validation error.

    Returns

    true to always require non-null values and false to allow null values.

method makeOptional

makeOptional: () => Schema;
  • Makes validated values optional. Validation for null values will be skipped.

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

    Returns

    this validation schema

    See Also

    • [[makeRequired]]

method makeRequired

makeRequired: () => Schema;
  • Makes validated values always required (non-null). For null values the schema will raise errors.

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

    Returns

    this validation schema

    See Also

    • [[makeOptional]]

method performTypeValidation

protected performTypeValidation: (
path: string,
type: any,
value: any,
results: ValidationResult[]
) => void;
  • Validates a given value to match specified type. The type can be defined as a Schema, type, a type name or [[TypeCode]] When type is a Schema, it executes validation recursively against that Schema.

    Parameter path

    a dot notation path to the value.

    Parameter type

    a type to match the value type

    Parameter value

    a value to be validated.

    Parameter results

    a list with validation results to add new results.

    See Also

    • [[performValidation]]

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 setRequired

setRequired: (value: boolean) => void;
  • Sets a flag that always requires non-null values.

    Parameter value

    true to always require non-null values and false to allow null values.

method setRules

setRules: (value: IValidationRule[]) => void;
  • Sets validation rules to check values against.

    Parameter value

    a list with validation rules.

method validate

validate: (value: any) => ValidationResult[];
  • Validates the given value and results validation results.

    Parameter value

    a value to be validated.

    Returns

    a list with validation results.

    See Also

    • [[ValidationResult]]

method validateAndReturnException

validateAndReturnException: (
correlationId: string,
value: any,
strict?: boolean
) => ValidationException;
  • Validates the given value and returns a [[ValidationException]] if errors were found.

    Parameter correlationId

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

    Parameter value

    a value to be validated.

    Parameter strict

    true to treat warnings as errors.

method validateAndThrowException

validateAndThrowException: (
correlationId: string,
value: any,
strict?: boolean
) => void;
  • Validates the given value and throws a [[ValidationException]] if errors were found.

    Parameter correlationId

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

    Parameter value

    a value to be validated.

    Parameter strict

    true to treat warnings as errors.

    See Also

    • [[ValidationException.throwExceptionIfNeeded]]

method withRule

withRule: (rule: IValidationRule) => Schema;
  • Adds validation rule to this schema.

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

    Parameter rule

    a validation rule to be added.

    Returns

    this validation schema.

class SortField

class SortField {}
  • Defines a field name and order used to sort query results.

    See Also

    • [[SortParams]]

      ### Example ###

      let filter = FilterParams.fromTuples("type", "Type1"); let paging = new PagingParams(0, 100); let sorting = new SortingParams(new SortField("create_time", true));

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

constructor

constructor(name?: string, ascending?: boolean);
  • Creates a new instance and assigns its values.

    Parameter name

    the name of the field to sort by.

    Parameter ascending

    true to sort in ascending order, and false to sort in descending order.

property ascending

ascending: boolean;
  • The flag to define sorting order. True to sort ascending, false to sort descending

property name

name: string;
  • The field name to sort by

class SortParams

class SortParams extends Array<SortField> {}
  • Defines a field name and order used to sort query results.

    See Also

    • [[SortField]]

      ### Example ###

      let filter = FilterParams.fromTuples("type", "Type1"); let paging = new PagingParams(0, 100); let sorting = new SortingParams(new SortField("create_time", true));

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

constructor

constructor(...fields: SortField[]);
  • Creates a new instance and initializes it with specified sort fields.

    Parameter fields

    a list of fields to sort by.

class StringConverter

class StringConverter {}
  • Converts arbitrary values into strings using extended conversion rules: - Numbers: are converted with '.' as decimal point - DateTime: using ISO format - Boolean: "true" for true and "false" for false - Arrays: as comma-separated list - Other objects: using toString() method

    ### Example ###

    let value1 = StringConverter.ToString(123.456); // Result: "123.456" let value2 = StringConverter.ToString(true); // Result: "true" let value3 = StringConverter.ToString(new Date(2018,0,1)); // Result: "2018-01-01T00:00:00.00" let value4 = StringConverter.ToString([1,2,3]); // Result: "1,2,3"

method toNullableString

static toNullableString: (value: any) => string;
  • Converts value into string or returns null when value is null.

    Parameter value

    the value to convert.

    Returns

    string value or null when value is null.

method toString

static toString: (value: any) => string;
  • Converts value into string or returns "" when value is null.

    Parameter value

    the value to convert.

    Returns

    string value or "" when value is null.

    See Also

    • [[toStringWithDefault]]

method toStringWithDefault

static toStringWithDefault: (value: any, defaultValue: string) => string;
  • Converts value into string or returns default when value is null.

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value.

    Returns

    string value or default when value is null.

    See Also

    • [[toNullableString]]

class StringValueMap

class StringValueMap {}
  • Cross-language implementation of a map (dictionary) where all keys and values are strings. The stored values can be converted to different types using variety of accessor methods.

    The string map is highly versatile. It can be converted into many formats, stored and sent over the wire.

    This class is widely used in Pip.Services as a basis for variety of classes, such as [[ConfigParams]], [[https://pip-services3-node.github.io/pip-services3-components-node/classes/connect.connectionparams.html ConnectionParams]], [[https://pip-services3-node.github.io/pip-services3-components-node/classes/auth.credentialparams.html CredentialParams]] and others.

    ### Example ###

    let value1 = StringValueMap.fromString("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]]

constructor

constructor(map?: 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[]) => StringValueMap;
  • 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 fromString

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

    Parameter line

    semicolon-separated key-value list to initialize StringValueMap.

    Returns

    a newly created StringValueMap.

method fromTuples

static fromTuples: (...tuples: any[]) => StringValueMap;
  • Creates a new StringValueMap 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 StringValueMap.

    See Also

    • [[fromTuplesArray]]

method fromTuplesArray

static fromTuplesArray: (tuples: any[]) => StringValueMap;
  • Creates a new StringValueMap 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 StringValueMap.

method fromValue

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

    Parameter value

    value to be converted

    Returns

    a newly created StringValueMap.

    See Also

    • [[setAsObject]]

method get

get: (key: string) => string;
  • 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 TagsProcessor

class TagsProcessor {}
  • Helper class to extract and process search tags from objects. The search tags can be kept individually or embedded as hash tags inside text like "This text has #hash_tag that can be used for search."

method compressTag

static compressTag: (tag: string) => string;
  • Compress a tag by removing special symbols like spaces, '_' and '#' and converting the tag to lower case. When tags are compressed they can be matched in search queries.

    Parameter tag

    the tag to compress. a compressed tag.

method compressTagList

static compressTagList: (tagList: string) => string[];
  • Compresses a comma-separated list of tags.

    Parameter tagList

    a comma-separated list of tags to compress. a list with compressed tags.

method compressTags

static compressTags: (tags: string[]) => string[];
  • Compresses a list of tags.

    Parameter tags

    the tags to compress. a list with normalized tags.

method equalTags

static equalTags: (tag1: string, tag2: string) => boolean;
  • Compares two tags using their compressed form.

    Parameter tag1

    the first tag.

    Parameter tag2

    the second tag. true if the tags are equal and false otherwise.

method extractHashTags

static extractHashTags: (text: string) => string[];
  • Extracts hash tags from a text.

    Parameter text

    a text that contains hash tags a list with extracted and compressed tags.

method extractHashTagsFromValue

static extractHashTagsFromValue: (
obj: any,
...searchFields: string[]
) => string[];
  • Extracts hash tags from selected fields in an object.

    Parameter obj

    an object which contains hash tags.

    Parameter searchFields

    a list of fields in the objects where to extract tags a list of extracted and compressed tags.

method normalizeTag

static normalizeTag: (tag: string) => string;
  • Normalizes a tag by replacing special symbols like '_' and '#' with spaces. When tags are normalized then can be presented to user in similar shape and form.

    Parameter tag

    the tag to normalize. a normalized tag.

method normalizeTagList

static normalizeTagList: (tagList: string) => string[];
  • Normalizes a comma-separated list of tags.

    Parameter tagList

    a comma-separated list of tags to normalize. a list with normalized tags.

method normalizeTags

static normalizeTags: (tags: string[]) => string[];
  • Normalizes a list of tags.

    Parameter tags

    the tags to normalize. a list with normalized tags.

class TypeConverter

class TypeConverter {}
  • Converts arbitrary values into objects specific by TypeCodes. For each TypeCode this class calls corresponding converter which applies extended conversion rules to convert the values.

    See Also

    • [[TypeCode]]

      ### Example ###

      let value1 = TypeConverter.toType(TypeCode.Integer, "123.456"); // Result: 123 let value2 = TypeConverter.toType(TypeCode.DateTime, 123); // Result: Date(123) let value3 = TypeConverter.toType(TypeCode.Boolean, "F"); // Result: false

method toNullableType

static toNullableType: <T>(type: TypeCode, value: any) => T;
  • Converts value into an object type specified by Type Code or returns null when conversion is not possible.

    Parameter type

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

    Parameter value

    the value to convert.

    Returns

    object value of type corresponding to TypeCode, or null when conversion is not supported.

    See Also

    • [[toTypeCode]]

method toString

static toString: (type: TypeCode) => string;
  • Converts a TypeCode into its string name.

    Parameter type

    the TypeCode to convert into a string.

    Returns

    the name of the TypeCode passed as a string value.

method toType

static toType: <T>(type: TypeCode, value: any) => T;
  • Converts value into an object type specified by Type Code or returns type default when conversion is not possible.

    Parameter type

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

    Parameter value

    the value to convert.

    Returns

    object value of type corresponding to TypeCode, or type default when conversion is not supported.

    See Also

    • [[toNullableType]]

    • [[toTypeCode]]

method toTypeCode

static toTypeCode: (value: any) => TypeCode;
  • Gets TypeCode for specific value.

    Parameter value

    value whose TypeCode is to be resolved.

    Returns

    the TypeCode that corresponds to the passed object's type.

method toTypeWithDefault

static toTypeWithDefault: <T>(type: TypeCode, value: any, defaultValue: T) => T;
  • Converts value into an object type specified by Type Code or returns default value when conversion is not possible.

    Parameter type

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

    Parameter value

    the value to convert.

    Parameter defaultValue

    the default value to return if conversion is not possible (returns null).

    Returns

    object value of type corresponding to TypeCode, or default value when conversion is not supported.

    See Also

    • [[toNullableType]]

    • [[toTypeCode]]

class TypeDescriptor

class TypeDescriptor {}
  • Descriptor that points to specific object type by it's name and optional library (or module) where this type is defined.

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

constructor

constructor(name: string, library: string);
  • Creates a new instance of the type descriptor and sets its values.

    Parameter name

    a name of the object type.

    Parameter library

    a library or module where this object type is implemented.

method equals

equals: (value: any) => boolean;
  • Compares this descriptor to a value. If the value is also a TypeDescriptor it compares their name and library fields. Otherwise this method returns false.

    Parameter value

    a value to compare.

    Returns

    true if value is identical TypeDescriptor and false otherwise.

method fromString

static fromString: (value: string) => TypeDescriptor;
  • Parses a string to get descriptor fields and returns them as a Descriptor. The string must have format name[,library]

    Parameter value

    a string to parse.

    Returns

    a newly created Descriptor.

    Throws

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

    See Also

    • [[toString]]

method getLibrary

getLibrary: () => string;
  • Gets the name of the library or module where the object type is defined.

    Returns

    the name of the library or module.

method getName

getName: () => string;
  • Get the name of the object type.

    Returns

    the name of the object type.

method toString

toString: () => string;
  • Gets a string representation of the object. The result has format name[,library]

    Returns

    a string representation of the object.

    See Also

    • [[fromString]]

class TypeMatcher

class TypeMatcher {}
  • Helper class matches value types for equality.

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

    See Also

    • [[TypeCode]]

method matchType

static matchType: (
expectedType: any,
actualType: TypeCode,
actualValue?: any
) => boolean;
  • Matches expected type to an actual type. The types can be specified as types, type names or [[TypeCode]].

    Parameter expectedType

    an expected type to match.

    Parameter actualType

    an actual type to match.

    Parameter actualValue

    an optional value to match its type to the expected one.

    Returns

    true if types are matching and false if they don't.

    See Also

    • [[matchTypeByName]]

    • [[matchTypeByName]] (for matching by types' string names)

method matchTypeByName

static matchTypeByName: (
expectedType: string,
actualType: TypeCode,
actualValue?: any
) => boolean;
  • Matches expected type to an actual type.

    Parameter expectedType

    an expected type name to match.

    Parameter actualType

    an actual type to match defined by type code.

    Parameter actualValue

    an optional value to match its type to the expected one.

    Returns

    true if types are matching and false if they don't.

method matchValueType

static matchValueType: (expectedType: any, actualValue: any) => boolean;
  • Matches expected type to a type of a value. The expected type can be specified by a type, type name or [[TypeCode]].

    Parameter expectedType

    an expected type to match.

    Parameter actualValue

    a value to match its type to the expected one.

    Returns

    true if types are matching and false if they don't.

    See Also

    • [[matchType]]

    • [[matchValueTypeByName]] (for matching by types' string names)

method matchValueTypeByName

static matchValueTypeByName: (expectedType: string, actualValue: any) => boolean;
  • Matches expected type to a type of a value.

    Parameter expectedType

    an expected type name to match.

    Parameter actualValue

    a value to match its type to the expected one.

    Returns

    true if types are matching and false if they don't.

class TypeReflector

class TypeReflector {}
  • Helper class to perform object type introspection and object instantiation.

    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 TypeReflector treats all type names as case insensitive.

    See Also

    • [[TypeDescriptor]]

      ### Example ###

      let descriptor = new TypeDescriptor("MyObject", "mylibrary"); Typeeflector.getTypeByDescriptor(descriptor); let myObj = TypeReflector.createInstanceByDescriptor(descriptor);

      TypeDescriptor.isPrimitive(myObject); // Result: false TypeDescriptor.isPrimitive(123); // Result: true

method createInstance

static createInstance: (name: string, library: string, ...args: any[]) => any;
  • Creates an instance of an object type specified by its name and library where it is defined.

    Parameter name

    an object type name.

    Parameter library

    a library (module) where object type is defined.

    Parameter args

    arguments for the object constructor.

    Returns

    the created object instance.

    See Also

    • [[getType]]

    • [[createInstanceByType]]

method createInstanceByDescriptor

static createInstanceByDescriptor: (
descriptor: TypeDescriptor,
...args: any[]
) => any;
  • Creates an instance of an object type specified by type descriptor.

    Parameter descriptor

    a type descriptor that points to an object type

    Parameter args

    arguments for the object constructor.

    Returns

    the created object instance.

    See Also

    • [[createInstance]]

    • [[TypeDescriptor]]

method createInstanceByType

static createInstanceByType: (type: any, ...args: any[]) => any;
  • Creates an instance of an object type.

    Parameter type

    an object type (factory function) to create.

    Parameter args

    arguments for the object constructor.

    Returns

    the created object instance.

method getType

static getType: (name: string, library: string) => any;
  • Gets object type by its name and library where it is defined.

    Parameter name

    an object type name.

    Parameter library

    a library where the type is defined

    Returns

    the object type or null is the type wasn't found.

method getTypeByDescriptor

static getTypeByDescriptor: (descriptor: TypeDescriptor) => any;
  • Gets object type by type descriptor.

    Parameter descriptor

    a type descriptor that points to an object type

    Returns

    the object type or null is the type wasn't found.

    See Also

    • [[getType]]

    • [[TypeDescriptor]]

method isPrimitive

static isPrimitive: (value: any) => boolean;
  • Checks if value has primitive type.

    Primitive types are: numbers, strings, booleans, date and time. Complex (non-primitive types are): objects, maps and arrays

    Parameter value

    a value to check

    Returns

    true if the value has primitive type and false if value type is complex.

    See Also

    • [[TypeConverter.toTypeCode]]

    • [[TypeCode]]

class UnauthorizedException

class UnauthorizedException extends ApplicationException {}
  • Access errors caused by missing user identity (authentication error) or incorrect security permissions (authorization error).

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 UnknownException

class UnknownException extends ApplicationException {}
  • Unknown or unexpected errors.

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 UnsupportedException

class UnsupportedException extends ApplicationException {}
  • Errors caused by calls to unsupported or not yet implemented functionality.

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 ValidationException

class ValidationException extends BadRequestException {}
  • Errors in schema validation.

    Validation errors are usually generated based in [[ValidationResult]]. If using strict mode, warnings will also raise validation exceptions.

    See Also

    • [[BadRequestException]]

    • [[ValidationResult]]

constructor

constructor(
correlationId: string,
message?: string,
results?: ValidationResult[]
);
  • Creates a new instance of validation 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 results

    (optional) a list of validation results

    Parameter message

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

    See Also

    • [[ValidationResult]]

method composeMessage

static composeMessage: (results: ValidationResult[]) => string;
  • Composes human readable error message based on validation results.

    Parameter results

    a list of validation results.

    Returns

    a composed error message.

    See Also

    • [[ValidationResult]]

method fromResults

static fromResults: (
correlationId: string,
results: ValidationResult[],
strict: boolean
) => ValidationException;
  • Creates a new ValidationException based on errors in validation results. If validation results have no errors, than null is returned.

    Parameter correlationId

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

    Parameter results

    list of validation results that may contain errors

    Parameter strict

    true to treat warnings as errors.

    Returns

    a newly created ValidationException or null if no errors in found.

    See Also

    • [[ValidationResult]]

method throwExceptionIfNeeded

static throwExceptionIfNeeded: (
correlationId: string,
results: ValidationResult[],
strict: boolean
) => void;
  • Throws ValidationException based on errors in validation results. If validation results have no errors, than no exception is thrown.

    Parameter correlationId

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

    Parameter results

    list of validation results that may contain errors

    Parameter strict

    true to treat warnings as errors.

    See Also

    • [[ValidationResult]]

    • [[ValidationException]]

class ValidationResult

class ValidationResult {}
  • Result generated by schema validation

constructor

constructor(
path?: string,
type?: ValidationResultType,
code?: string,
message?: string,
expected?: any,
actual?: any
);
  • Creates a new instance of validation ressult and sets its values.

    Parameter path

    a dot notation path of the validated element.

    Parameter type

    a type of the validation result: Information, Warning, or Error.

    Parameter code

    an error code.

    Parameter message

    a human readable message.

    Parameter expected

    an value expected by schema validation.

    Parameter actual

    an actual value found by schema validation.

    See Also

    • [[ValidationResultType]]

method getActual

getActual: () => any;
  • Gets the actual value found by schema validation.

    Returns

    the actual value.

method getCode

getCode: () => string;
  • Gets the error code.

    Returns

    the error code

method getExpected

getExpected: () => any;
  • Gets the value expected by schema validation.

    Returns

    the expected value.

method getMessage

getMessage: () => string;
  • Gets the human readable message.

    Returns

    the result message.

method getPath

getPath: () => string;
  • Gets dot notation path of the validated element.

    Returns

    the path of the validated element.

method getType

getType: () => ValidationResultType;
  • Gets the type of the validation result: Information, Warning, or Error.

    Returns

    the type of the validation result.

    See Also

    • [[ValidationResultType]]

method toJSON

toJSON: () => {
path: string;
type: ValidationResultType;
code: string;
message: string;
expected: any;
actual: any;
};

    class ValueComparisonRule

    class ValueComparisonRule implements IValidationRule {}
    • Validation rule that compares value to a constant.

      See Also

      • [[IValidationRule]]

        ### Example ###

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

        schema.validate(1); // Result: no errors schema.validate(2); // Result: 2 is not equal to 1

    constructor

    constructor(operation: string, value: any);
    • Creates a new validation rule and sets its values.

      Parameter operation

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

      Parameter value

      a constant value to compare 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.

    Interfaces

    interface IChangeable

    interface IChangeable {}
    • Interface for data objects that contain their latest change time.

      ### Example ###

      export class MyData implements IStringIdentifiable, IChangeable { public id: string; public field1: string; public field2: number; public change_time: Date; ... }

    property change_time

    change_time: Date;
    • The UTC time at which the object was last changed (created or updated).

    interface ICleanable

    interface ICleanable {}
    • Interface for components that should clean their state.

      Cleaning state most often is used during testing. But there may be situations when it can be done in production.

      See Also

      • [[Cleaner]]

        ### Example ###

        class MyObjectWithState implements ICleanable { private _state: any = {}; ... public clear(correlationId: string): void { this._state = {}; } }

    method clear

    clear: (correlationId: string, callback?: (err: any) => void) => void;
    • Clears component state.

      Parameter correlationId

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

      Parameter callback

      callback function that receives error or null no errors occured.

    interface ICloneable

    interface ICloneable {}
    • Interface for data objects that are able to create their full binary copy.

      ### Example ###

      export class MyClass implements IMyClass, ICloneable { constructor() { };

      public clone(): any { var cloneObj = new (this.constructor());

      // Copy every attribute from this to cloneObj here. ...

      return cloneObj; } }

    method clone

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

      Returns

      a clone of this object.

    interface IClosable

    interface IClosable {}
    • Interface for components that require explicit closure.

      For components that require opening as well as closing use [[IOpenable]] interface instead.

      See Also

      • [[IOpenable]]

      • [[Closer]]

        ### Example ###

        class MyConnector implements ICloseable { private _client: any = null;

        ... // The _client can be lazy created

        public close(correlationId: string, callback: (err: any) => void): void { if (this._client != null) { this._client.close(); this._client = null; } callback(null); } }

    method close

    close: (correlationId: string, callback?: (err: any) => void) => void;
    • Closes component and frees used resources.

      Parameter correlationId

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

      Parameter callback

      callback function that receives error or null no errors occured.

    interface ICommand

    interface ICommand extends IExecutable {}
    • An interface for Commands, which are part of the Command design pattern. Each command wraps a method or function and allows to call them in uniform and safe manner.

      See Also

      • [[Command]]

      • [[IExecutable]]

      • [[ICommandInterceptor]]

      • [[InterceptedCommand]]

    method getName

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

      Returns

      the command name.

    method validate

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

      Parameter args

      the parameters (arguments) to validate.

      Returns

      an array of ValidationResults.

      See Also

      • [[Parameters]]

      • [[ValidationResult]]

    interface ICommandable

    interface ICommandable {}
    • An interface for commandable objects, which are part of the command design pattern. The commandable object exposes its functonality as commands and events groupped into a [[CommandSet CommandSet]].

      This interface is typically implemented by controllers and is used to auto generate external interfaces.

      See Also

      • [[CommandSet]]

        ### Example ###

        export class MyDataController implements ICommandable, IMyDataController { private _commandSet : MyDataCommandSet;

        public getCommandSet(): CommandSet { if (this._commandSet == null) this._commandSet = new MyDataCommandSet(this); return this._commandSet; }

        ... }

      • [[CommandSet]] examples

    method getCommandSet

    getCommandSet: () => CommandSet;
    • Gets a command set with all supported commands and events.

      Returns

      a command set with commands and events.

      See Also

      • [[CommandSet]]

    interface ICommandInterceptor

    interface ICommandInterceptor {}
    • An interface for stackable command intercepters, which can extend and modify the command call chain.

      This mechanism can be used for authentication, logging, and other functions.

      See Also

      • [[ICommand]]

      • [[InterceptedCommand]]

    method execute

    execute: (
    correlationId: string,
    command: ICommand,
    args: Parameters,
    callback: (err: any, result: any) => void
    ) => void;
    • Executes the wrapped command with specified arguments.

      The interceptor can use this method to intercept and alter the command execution. Otherwise it shall just delete the call to the wrapped command.

      Parameter correlationId

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

      Parameter command

      the next command in the call chain 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.

      See Also

      • [[Parameters]]

    method getName

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

      The interceptor can use this method to override the command name. Otherwise it shall just delegate the call to the wrapped command.

      Parameter command

      the next command in the call chain.

      Returns

      the name of the wrapped command.

    method validate

    validate: (command: ICommand, args: Parameters) => ValidationResult[];
    • Validates arguments of the wrapped command before its execution.

      The interceptor can use this method to intercept and alter validation of the command arguments. Otherwise it shall just delegate the call to the wrapped command.

      Parameter command

      the next command in the call chain to be validated against.

      Parameter args

      the parameters (arguments) to validate.

      Returns

      an array of ValidationResults.

      See Also

      • [[Parameters]]

      • [[ValidationResult]]

    interface IConfigurable

    interface IConfigurable {}
    • An interface to set configuration parameters to an object.

      It can be added to any existing class by implementing a single configure() method.

      If you need to emphasis the fact that configure() method can be called multiple times to change object configuration in runtime, use [[IReconfigurable]] interface instead.

      See Also

      • [[ConfigParams]]

        ### Example ###

        export class MyClass implements IConfigurable { private _myParam: string = "default value";

        public configure(config: ConfigParams): void { this._myParam = config.getAsStringWithDefault("options.param", myParam); ... } }

    method configure

    configure: (config: ConfigParams) => void;
    • Configures component by passing configuration parameters.

      Parameter config

      configuration parameters to be set.

    interface IEvent

    interface IEvent extends INotifiable {}
    • An interface for Events, which are part of the Command design pattern. Events allows to send asynchronious notifications to multiple subscribed listeners.

      See Also

      • [[IEventListener]]

    method addListener

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

      Parameter listener

      the listener reference to add.

    method getListeners

    getListeners: () => IEventListener[];
    • Gets all subscribed listeners.

      Returns

      a list of listeners.

    method getName

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

      Returns

      the name of the event.

    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.

    interface IEventListener

    interface IEventListener {}
    • An interface for listener objects that receive notifications on fired events.

      See Also

      • [[IEvent]]

      • [[Event]]

        ### Example ###

        export class MyListener implements IEventListener { private onEvent(correlationId: string, event: IEvent, args: Parameters): void { console.log("Fired event " + event.getName()); } }

        let event = new Event("myevent"); event.addListener(new MyListener()); event.notify("123", Parameters.fromTuples("param1", "ABC"));

        // Console output: Fired event myevent

    method onEvent

    onEvent: (correlationId: string, event: IEvent, args: Parameters) => void;
    • A method called when events this listener is subscrubed to are fired.

      Parameter event

      a fired evemt

      Parameter correlationId

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

      Parameter args

      event arguments.

    interface IExecutable

    interface IExecutable {}
    • Interface for components that can be called to execute work.

      See Also

      • [[Executor]]

      • [[INotifiable]]

      • [[Parameters]]

        ### Example ###

        class EchoComponent implements IExecutable { ... public execute(correlationId: string, args: Parameters, callback: (err: any, result: any) => void): void { let result = args.getAsObject("message"); callback(null, result); } }

        let echo = new EchoComponent(); let message = "Test"; echo.execute("123", Parameters.fromTuples("message", message), (err, result) => { console.log("Request: " + message + " Response: " + result); } );

    method execute

    execute: (
    correlationId: string,
    args: Parameters,
    callback: (err: any, result: any) => void
    ) => void;
    • Executes component with arguments and receives execution result.

      Parameter correlationId

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

      Parameter args

      execution arguments.

      Parameter callback

      callback function that receives execution result or error.

    interface IIdentifiable

    interface IIdentifiable<K> {}
    • Generic interface for data objects that can be uniquely identified by an id.

      The type specified in the interface defines the type of id field.

      ### Example ###

      export class MyData implements IIdentifiable { public id: string; public field1: string; public field2: number; ... }

    property id

    id: K;
    • The unique object identifier of type K.

    interface INamed

    interface INamed {}
    • Interface for data objects that have human-readable names.

      ### Example ###

      export class MyData implements IStringIdentifiable, INamed { public id: string; public name: string; public field1: string; public field2: number; ... }

    property name

    name: string;
    • The object's humand-readable name.

    interface INotifiable

    interface INotifiable {}
    • Interface for components that can be asynchronously notified. The notification may include optional argument that describe the occured event.

      See Also

      • [[Notifier]]

      • [[IExecutable]]

        ### Example ###

        class MyComponent implements INotifable { ... public notify(correlationId: string, args: Parameters): void { console.log("Occured event " + args.getAsString("event")); } }

        let myComponent = new MyComponent();

        myComponent.notify("123", Parameters.fromTuples("event", "Test Event"));

    method notify

    notify: (correlationId: string, args: Parameters) => void;
    • Notifies the component about occured event.

      Parameter correlationId

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

      Parameter args

      notification arguments.

    interface IOpenable

    interface IOpenable extends IClosable {}
    • Interface for components that require explicit opening and closing.

      For components that perform opening on demand consider using [[IClosable]] interface instead.

      See Also

      • [[IOpenable]]

      • [[Opener]]

        ### Example ###

        class MyPersistence implements IOpenable { private _client: any; ... public isOpen(): boolean { return this._client != null; }

        public open(correlationId: string, callback: (err: any) => void): void { if (this.isOpen()) { callback(null); return; } ... }

        public close(correlationId: string, callback: (err: any) => void): void { if (this._client != null) { this._client.close(); this._client = null; } callback(null); }

        ... }

    method isOpen

    isOpen: () => boolean;
    • Checks if the component is opened.

      Returns

      true if the component has been opened and false otherwise.

    method open

    open: (correlationId: string, callback?: (err: any) => void) => void;
    • Opens the component.

      Parameter correlationId

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

      Parameter callback

      callback function that receives error or null no errors occured.

    interface IParameterized

    interface IParameterized {}
    • Interface for components that require execution parameters.

      See Also

      • [[IConfigurable]]

    method setParameters

    setParameters: (parameters: Parameters) => void;
    • Sets execution parameters.

      Parameter parameters

      execution parameters.

    interface IReconfigurable

    interface IReconfigurable extends IConfigurable {}
    • An interface to set configuration parameters to an object.

      It is similar to [[IConfigurable]] interface, but emphasises the fact that configure() method can be called more than once to change object configuration in runtime.

      See Also

      • [[IConfigurable]]

    interface IReferenceable

    interface IReferenceable {}
    • Interface for components that depends on other components.

      If component requires explicit notification to unset references it shall additionally implement [[IUnreferenceable]] interface.

      See Also

      • [[IReferences]]

      • [[IUnreferenceable]]

      • [[Referencer]]

        ### Example ###

        export class MyController implements IReferenceable { public _persistence: IMyPersistence; ... public setReferences(references: IReferences): void { this._persistence = references.getOneRequired( new Descriptor("mygroup", "persistence", "*", "*", "1.0") ); } ... }

    method setReferences

    setReferences: (references: IReferences) => void;
    • Sets references to dependent components.

      Parameter references

      references to locate the component dependencies.

      See Also

      • [[IReferences]]

    interface IReferences

    interface IReferences {}
    • Interface for a map that holds component references and passes them to components to establish dependencies with each other.

      Together with [[IReferenceable]] and [[IUnreferenceable]] interfaces it implements a Locator pattern that is used by PipServices toolkit for Inversion of Control to assign external dependencies to components.

      The IReferences object is a simple map, where keys are locators and values are component references. It allows to add, remove and find components by their locators. Locators can be any values like integers, strings or component types. But most often PipServices toolkit uses [[Descriptor]] as locators that match by 5 fields: group, type, kind, name and version.

      See Also

      • [[Descriptor]]

      • [[References]]

        ### Example ###

        export class MyController implements IReferenceable { public _persistence: IMyPersistence; ... public setReferences(references: IReferences): void { this._persistence = references.getOneRequired( new Descriptor("mygroup", "persistence", "*", "*", "1.0") ); } ... }

        let persistence = new MyMongoDbPersistence();

        let controller = new MyController();

        let references = References.fromTuples( new Descriptor("mygroup", "persistence", "mongodb", "default", "1.0"), persistence, new Descriptor("mygroup", "controller", "default", "default", "1.0"), controller ); controller.setReferences(references);

    method find

    find: <T>(locator: any, required: boolean) => T[];
    • Gets all component references that match specified locator.

      Parameter locator

      the locator to find a reference by.

      Parameter required

      forces to raise an exception if no reference is found.

      Returns

      a list with matching component references.

      Throws

      a [[ReferenceException]] when required is set to true but no references found.

    method getAll

    getAll: () => any[];
    • Gets all component references registered in this reference map.

      Returns

      a list with component references.

    method getAllLocators

    getAllLocators: () => any[];
    • Gets locators for all registered component references in this reference map.

      Returns

      a list with component locators.

    method getOneOptional

    getOneOptional: <T>(locator: any) => T;
    • Gets an optional component reference that matches specified locator.

      Parameter locator

      the locator to find references by.

      Returns

      a matching component reference or null if nothing was found.

    method getOneRequired

    getOneRequired: <T>(locator: any) => T;
    • Gets a required component reference that matches specified locator.

      Parameter locator

      the locator to find a reference by.

      Returns

      a matching component reference.

      Throws

      a [[ReferenceException]] when no references found.

    method getOptional

    getOptional: <T>(locator: any) => T[];
    • Gets all component references that match specified locator.

      Parameter locator

      the locator to find references by.

      Returns

      a list with matching component references or empty list if nothing was found.

    method getRequired

    getRequired: <T>(locator: any) => T[];
    • Gets all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error.

      Parameter locator

      the locator to find references by.

      Returns

      a list with matching component references.

      Throws

      a [[ReferenceException]] when no references found.

    method put

    put: (locator: any, component: any) => any;
    • Puts a new reference into this reference map.

      Parameter locator

      a locator to find the reference by.

      Parameter component

      a component reference to be added.

    method remove

    remove: (locator: any) => any;
    • Removes a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use [[removeAll]] method instead.

      Parameter locator

      a locator to remove reference

      Returns

      the removed component reference.

      See Also

      • [[removeAll]]

    method removeAll

    removeAll: (locator: any) => any[];
    • Removes all component references that match the specified locator.

      Parameter locator

      the locator to remove references by.

      Returns

      a list, containing all removed references.

    interface IStringIdentifiable

    interface IStringIdentifiable extends IIdentifiable<string> {}
    • Interface for data objects that can be uniquely identifed by a string id.

      The interface extends [[IIdentifiable]] to hardcode id type to string.

      It is a common pattern to use a string GUID as the id, generated by [[IdGenerator]].

      See Also

      • [[IIdentifiable]]

      • [[IdGenerator]]

        ### Example ###

        export class MyData implements IStringIdentifiable { public id: string; public field1: string; public field2: number; ... }

    property id

    id: string;
    • The object's unique string id.

    interface ITrackable

    interface ITrackable extends IChangeable {}
    • Interface for data objects that can track their changes, including logical deletion.

      See Also

      • [[IChangeable]]

        ### Example ###

        export class MyData implements IStringIdentifiable, ITrackable { public id: string; public field1: string; public field2: number; ... public change_time: Date; public create_time: Date; public deleted: boolean; }

    property change_time

    change_time: Date;
    • The UTC time at which the object was last changed (created, updated, or deleted).

    property create_time

    create_time: Date;
    • The UTC time at which the object was created.

    property deleted

    deleted?: boolean;
    • The logical deletion flag. True when object is deleted and null or false otherwise

    interface IUnreferenceable

    interface IUnreferenceable {}
    • Interface for components that require explicit clearing of references to dependent components.

      See Also

      • [[IReferences]]

      • [[IReferenceable]]

        ### Example ###

        export class MyController implements IReferenceable, IUnreferenceable { public _persistence: IMyPersistence; ... public setReferences(references: IReferences): void { this._persistence = references.getOneRequired( new Descriptor("mygroup", "persistence", "*", "*", "1.0") ); }

        public unsetReferences(): void { this._persistence = null; } ... }

    method unsetReferences

    unsetReferences: () => void;
    • Unsets (clears) previously set references to dependent components.

    interface IValidationRule

    interface IValidationRule {}
    • Interface for validation rules.

      Validation rule can validate one or multiple values against complex rules like: value is in range, one property is less than another property, enforce enumerated values and more.

      This interface allows to implement custom rules.

    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.

    interface IVersioned

    interface IVersioned {}
    • Interface for data objects that can be versioned.

      Versioning is often used as optimistic concurrency mechanism.

      The version doesn't have to be a number, but it is recommended to use sequential values to determine if one object has newer or older version than another one.

      It is a common pattern to use the time of change as the object version.

      ### Example ###

      export class MyData implements IStringIdentifiable, IVersioned { public id: string; public field1: string; public field2: number; public version: string; ... }

      public updateData(correlationId: string, item: MyData): void { ... if (item.version < oldItem.version) { throw new ConcurrencyException(null, "VERSION_CONFLICT", "The change has older version stored value"); } ... }

    property version

    version: string;
    • The object's version.

    Enums

    enum TypeCode

    enum TypeCode {
    Unknown = 0,
    String = 1,
    Boolean = 2,
    Integer = 3,
    Long = 4,
    Float = 5,
    Double = 6,
    DateTime = 7,
    Duration = 8,
    Object = 9,
    Enum = 10,
    Array = 11,
    Map = 12,
    }
    • Codes for the data types that can be converted using [[TypeConverter]].

      See Also

      • [[TypeConverter]]

    member Array

    Array = 11

      member Boolean

      Boolean = 2

        member DateTime

        DateTime = 7

          member Double

          Double = 6

            member Duration

            Duration = 8

              member Enum

              Enum = 10

                member Float

                Float = 5

                  member Integer

                  Integer = 3

                    member Long

                    Long = 4

                      member Map

                      Map = 12

                        member Object

                        Object = 9

                          member String

                          String = 1

                            member Unknown

                            Unknown = 0

                              enum ValidationResultType

                              enum ValidationResultType {
                              Information = 0,
                              Warning = 1,
                              Error = 2,
                              }
                              • Types of validation results generated by validation schemas.

                                See Also

                                • [[ValidationResult]]

                              member Error

                              Error = 2
                              • Validation error.

                              member Information

                              Information = 0
                              • General information (not an error).

                              member Warning

                              Warning = 1
                              • Warning about something suspecious. In strict mode is treated as error

                              Package Files (126)

                              Dependencies (3)

                              Dev Dependencies (9)

                              Peer Dependencies (0)

                              No peer dependencies.

                              Badge

                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/pip-services3-commons-node.

                              • Markdown
                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/pip-services3-commons-node)
                              • HTML
                                <a href="https://www.jsdocs.io/package/pip-services3-commons-node"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>