Class: ListDefBuilder

olympe.dc. ListDefBuilder

This is a helper class to make ListDef creation a lot easier.

Example:

const builder = new olympe.dc.ListDefBuilder(manager, tag);
builder.follow(relation).not().instanceOf(models);
const list = builder.build();

new ListDefBuilder(baseTag [, valueType])

Creates an instance of ListDefBuilder.

Parameters:
Name Type Argument Default Description
baseTag olympe.dc.InstanceTag

Starting instance tag.

valueType function <optional>
olympe.dc.CloudObject

Type of the values, must be a sub-class of olympe.dc.CloudObject.

Methods


and()

Creates an And predicate with the previous and next filtering predicate pushed on the internal transformers stack.

Example:

list = list.hastTag(tag).and().hasRelated(rel);
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

build()

Generates a ListDef based on the settings of this builder.

Returns:

The generated ListDef.

Type
olympe.dc.ListDef

contains(property, value [, caseSensitive] [, relations])

Adds a filter transformer that checks whether a specific property contains a given string.

Parameters:
Name Type Argument Default Description
property olympe.dc.registry.Property | string

The property to filter on.

value string | olympe.df.OString

The string to match the property with.

caseSensitive olympe.df.POBoolean | boolean <optional>
false

true if the match has to be case sensitive.

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

distinct()

Filters out duplicate instances.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

dump()

Generate a text representation of the ListDef being built. Warning: a call to this method will execute the query and cause the subscription to be retrieved.

Returns:
Type
string

equalsTo(property, value [, relations])

Adds a filter transformer that matches a specific property with a given value.

Parameters:
Name Type Argument Description
property olympe.dc.registry.Property | string

The property to filter on.

value *

The value to match the property with.

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

excludeInstances(instances)

Adds a filter transformer that exclude the instances having a the specified tag, or whose tag is in the specified array

Parameters:
Name Type Description
instances Array.<olympe.dc.InstanceTag>

The instance(s) to exclude.

Returns:

This ListDefBuilder

Type
olympe.dc.ListDefBuilder

filter(predicateFunction)

Adds a filter transformer that matches the specified custom predicate. The predicate function given returns a boolean: whether the instance must be part of the list or not.

Parameters:
Name Type Description
predicateFunction olympe.dc.ListDefBuilder.AnonymousPredicate

The predicate function.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

follow(relation)

Adds a transformer that follows the given relation.

Parameters:
Name Type Description
relation olympe.dc.registry.Relation

The relation to follow.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

followEvery(relations)

Adds a transformer that follows the given relations in parallel instead of successively.

Parameters:
Name Type Description
relations Array.<olympe.dc.registry.Relation>

The relations to follow.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

followRecursive(relation [, minHops] [, maxHops])

Adds a transformer that follows a relation recursively. A simple 'follow' will stop after the first relation, while 'followRecursive` will continue to follow the same relation on the next instances, recursively.

For instance if we have the following graph: (A) -[Children]-> (B) -[Children]-> (C) \ -[Children]-> (D) -[Children]-> (F) -[Children]-> (E)

A.follow(Children) will return B & E while A.followRecursive(Children) will return B, C, D, E & F.

Parameters:
Name Type Argument Default Description
relation olympe.dc.registry.Relation

The relation to follow.

minHops olympe.dc.transformers.RecursiveRule | number <optional>
olympe.dc.transformers.RecursiveRule.FIRST

The minimal number of times the relation is followed.

maxHops olympe.dc.transformers.RecursiveRule | number <optional>
olympe.dc.transformers.RecursiveRule.INFINITE

The maximal number of time the relation can be followed.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

followSuccessive(relations)

Adds transformers that successively follow the given set of relations.

Parameters:
Name Type Description
relations Array.<olympe.dc.registry.Relation>

The set of relations to follow.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

greaterThan(property, value [, relations])

Adds a filter transformer that checks for numerical properties being greater than the given value.

Parameters:
Name Type Argument Description
property olympe.dc.registry.Property | string

The numerical property.

value olympe.df.PONumber | number

The value to compare.

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

hasRelated(relations [, tag])

Adds a filter that only accepts instances connected via at least one of the given relations. Optionally, enforce the instance the relation(s) connect(s) to.

Parameters:
Name Type Argument Description
relations Array.<(olympe.dc.registry.Relation|olympe.dc.transformers.RecursiveRelated)>

The relation(s) to filter on.

tag olympe.dc.InstanceTag <optional>

Tag of a related instance. If provided, the tested and related instances must connect through all relations provided above.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

hasTag(tag)

Adds a filter that only accepts instances having the given tag.

Parameters:
Name Type Description
tag olympe.dc.InstanceTag

The tag to filter on.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

instanceOf(models)

Add a filter transformer that checks if entries are instances of specific models.

This will filter out any entry that is not an instance of one of the specified models, following recursively model extensions

Parameters:
Name Type Description
models Array.<olympe.dc.InstanceTag>

The models to check for.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

instances()

Adds a transformer that returns all the instances of a model.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

limit(start, count)

Limit the list to the specified range of ranks.

Parameters:
Name Type Description
start olympe.df.PONumber | number

Starting rank of the range.

count olympe.df.PONumber | number

Size of the range.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

matchRegex(property, expression [, caseSensitive] [, relations])

Adds a filter transformer that checks whether a string property matches a specified regular expression.

Parameters:
Name Type Argument Default Description
property olympe.dc.registry.Property | string

The string property.

expression olympe.df.POString | string

The regular expression to match.

caseSensitive olympe.df.POBoolean | boolean <optional>
true

true if that matching has to be case sensitive.

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

not()

Negates the next filtering predicate (.equals(...), .contains(...), ...) pushed on the internal transformers stack.

Example:

list = list.not().hasTag(tag);
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

or()

Creates an Or predicate with the previous and next filtering predicate pushed on the internal transformers stack.

Example:

list = list.hastTag(tag).or().hasRelated(rel);
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

setValueType(valueType)

Sets the type of the values returned by this query.

Parameters:
Name Type Description
valueType function

The type of the values, must be a subclass of olympe.dc.CloudObject.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

smallerThan(property, value [, relations])

Adds a filter transformer that checks for numerical properties being smaller than the given value.

Parameters:
Name Type Argument Description
property olympe.dc.registry.Property | string

The numerical property.

value olympe.df.PONumber | number

The value to compare.

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property.

See:
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

sort(valueGetter, comparator [, order])

Sort by an anonymous comparing function.

Parameters:
Name Type Argument Default Description
valueGetter olympe.dc.ListDefBuilder.AnonymousComparedValueGetter

The callback to retrieve the value (of type T) to compare from the instance.

comparator olympe.dc.ListDefBuilder.AnonymousComparator

The function to use to compare 2 values (of type T).

order olympe.dc.transformers.SortRule <optional>
olympe.dc.transformers.SortRule.ASCENDING

Order of the sort (ascending or descending).

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

sortBy(property [, order] [, relations])

Sort the list by the given primitive property. The property can be of type String, Number or DateTime.

Parameters:
Name Type Argument Default Description
property olympe.dc.registry.Property | string

The property to base the sort on.

order olympe.dc.transformers.SortRule <optional>
olympe.dc.transformers.SortRule.ASCENDING

Order of the sort (ascending or descending).

relations Array.<!olympe.dc.registry.Relation> <optional>

Relations to follow to retrieve the property.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

transform(transformers)

Adds transformers to this ListDefBuilder.

Parameters:
Name Type Description
transformers Array.<olympe.dc.Transformer>

The transformers to add.

Throws:

If any of the transformers is invalid.

Type
ListDefBuilderError
Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

union(listDef)

Creates a new ListDef which is the union of this one and the specified one.

Parameters:
Name Type Description
listDef olympe.dc.ListDef

The ListDef to merge with this one.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

unionWithSingle(tag)

Creates a new ListDef which is the union of this one and the specified one (containing a single element).

Parameters:
Name Type Description
tag olympe.dc.InstanceTag

Starting instance tag.

Returns:

This ListDefBuilder.

Type
olympe.dc.ListDefBuilder

Type Definitions


AnonymousComparator(leftValue, rightValue)

Definition of the comparator function passed to sort(). It should return:

  • -1 if the leftValue should be listed before the rightValue
  • +1 if the rightValue should be listed before the leftValue
  • 0 if it cannot be decided

WARNING: it's not allowed to return a Proxy!

Parameters:
Name Type Description
leftValue ?
rightValue ?
Returns:
Type
number

AnonymousComparedValueGetter(instance)

Definition of the valueGetter function passed to sort() WARNING: it's not allowed to return a Proxy!

Parameters:
Name Type Description
instance olympe.dc.CloudObject
Returns:
Type
*

AnonymousPredicate(instance)

Definition of the function passed to filter()

Parameters:
Name Type Description
instance olympe.dc.CloudObject
Returns:
Type
olympe.df.POBoolean