This module helps to extract and aggregate information from a tableaux database.
Use npm run prepublish
to compile and test the code. This should be done before push and tag of a new version.
Use npm run test
to run all tests once. npm run test:watch
runs the tests while watching for changes.
The aggregator module includes many functions that can be used in a chain of promises. It provides a way to easily fork an aggregation process and use this to pull data from GRUD (tableaux) and reference it.
The easiest way to show how this works is by example. Imagine the following code
const GOOD_RATING_THRESHOLD = 4;
export default function start(step, progress, options) {
return getEntitiesOfTable("songs", {pimUrl: "http://localhost:8080"})
.then(step("Filter all songs with a good rating"))
.then(filter({
path: ["songs", "album"],
predicate: album => album.rating > GOOD_RATING_THRESHOLD
}))
.then(step("Printing complete duration of all good songs"))
.then(tablesCaintainingSongsWithGoodAlbummRatings => {
const tables = referencer()(tablesCaintainingSongsWithGoodAlbummRatings);
const songs = tables.songs;
const summedDuration = songs.reduce((duration, song) => duration + song.duration);
console.log("Duration of all songs with rating >", GOOD_RATING_THRESHOLD, " =", summedDuration);
});
}
aggregatorFile
(string
, required) is the file that should be spawn into a process. It consists of an exported default functionstart(step, progress[, options])
, which will be called with these parameters:step
is a function for promise chains that will count the current steps and sends a debug message as soon as the aggregator runs over this step. Theprogress
function is used for longer running "inner" processes, like minification of images. This function can be passed to some of the helper functions used in the promise chains.options
is a JSON object that was passed to thestart
function. This can be used to provide variables from the outer process to the forked one.progress
is a function that will be called with an object three properties:steps
- the number of all counted steps.currentStep
- the current step. Usesteps
andcurrentStep
to calculate the percentage of your progress.message
- An optional message of the current step.error
- Usuallyfalse
, but if there was an error during aggregation, you can make the outer process aware of it.
timeoutToResendStatus
(number, defaults to2000
) is a number in milliseconds when the aggregator should resend the latest status to theprogress
function. This helps to prevent the closing of a channel if an aggregator takes too long to respond with a new progress.- All other keys in the argument passed to start will be sent to the newly spawned aggregation process. The options will be serialized to JSON and back, therefore it is not possible to pass functions.
tableName
is the entry point for downloading all entities that are (recursively) linked.options
is an object consisting of the following options:pimUrl
,String
(required) - The URL pointing to the GRUD instance.disableFollow
,Array[String]
(optional) - Defaults to empty array. An array of column names that will not be followed.maxEntriesPerRequest
,Integer
(optional) - Defaults to 500. An integer greater than 0 to limit the amount of work on each request done by the Grud instance. Higher values make less requests but may run into timeouts if the Grud instance is not able to handle as much data.headers
,Object
(optional) - Defaults to {}. An object with key values pairs for http headers to set on every request.
This function filters all entities in the promise chain matching a specific condition.
options
is an object containing:excludeBacklinks
(Boolean
, optional) - Defaults to false. This option will exclude all backlinks from another table, meaning if a cyclic link occurs, this link will not add new entities to the filtered table. Most of the time you will want to usefilterBacklinks
instead of removing all columns containing a link to the first table.filterBacklinks
(Boolean
, optional) - Defaults to false. This option will exclude all backlinks from another table if the entity is not already in the first table. You want to use this option when you want to keep links to the first table but remove all links to entities that do not match your initialpredicate
.ignoreMissing
(Boolean
, optional) - Defaults to false. If a table is missing, thefilter
method usually emits aconsole.warn
warning. This warning can be disabled by settingignoreMissing
totrue
.path
(Array[String]
, reguired) - The path to follow for thepredicate
.predicate
((object) => Boolean
, required) - This function checksobject
for a specified condition.
To remove columns from the resulting GrudTables.
options
is an object containing:paths
(Array[Array[String]]
, optional) - The paths contain the names of the table and column to kick. For example:
[
['tableA', 'columnInTableA'],
['tableB', 'columnInTableB']
]
predicate
((GrudColumn, GrudTable) => Boolean
, optional) - A function to check if this column should be excluded in the result.preserveConcats
(Boolean
, optional, defaults totrue
) - To remove all concat columns, set the flag tofalse
.
This function can be called in the promise chain or used in client code to denormalize the entities. Use it to simplify following links.
options
may containwithLanguages
(Boolean
, optional, defaults tofalse
), this assumes that the first level are languages and not tables. When usingtablesToLanguages
, this needs to be set, otherwise it can not correctly denormalize the entities. If set tofalse
, all multi-language columns will still contain objects with te values for all languages.
This function separates the tables into languages set in the fallbacks
object.
fallbacks
is an object containing language keys as keys and anArray[LanguageKey]
to define fallback languages to use if the selected language is not set.options
may containfallbackOnly
(Boolean
, optional, defaults tofalse
), this assumes the fallback array as the single source of truth, meaning the key in thefallbacks
options are not used as default language, but the first element in the provided array for each key. If you turn this option on, you need to have at least one language set in each array or the call totablesToLanguages
will result in an error.fallbackOnEmptyString
(Boolean
, optional, defaults totrue
), will trim texts (based on the column kind) and use the fallback languages if the trimmed text is empty.
See CHANGELOG.md.
Copyright 2016-present Campudus GmbH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.