Writing scripts for the JavaScript transformation module#
Entry Point#
Your script requires one global function with the following name and signature:
input
is the data content from the pipe payload, usually passed as JSON object or array (default).
Parameters from the Pipe#
The property params
JSON object of the pipe segment configuration will be passed to the script under the same name.
Convenient Helpers#
There are some predefined helper objects and functions that you can use in your scripts.
See script.js for example usage.
if you're working in a DCAT-AP context, you should consider using mapSingle*
for all properties with a cardinality of
one and for properties with cardinality greater all other helper functions.
DCAT-AP Context Object(s)#
The module provides an object that just includes a JSON-LD DCAT-AP @context
object that you can use as starting point
for your generating code.
dcatapContext
-> DCAT-AP 3.0.0 JSON LD context definitions (slightly fixed)
Mapping Functions#
piveau.mapLiteral(source, target, lang)
Returning a JSON-LD literal with the value of source and optionally a language attribute. If target exists, it will
add it as an additional triple (returning an array, which includes all previous values). If source is undefined, null
or blank, the method returns undefined
.
piveau.mapTypedLiteral(source, target, type)
Returning a JSON-LD typed literal with the value of source and optionally with the given type. If target exists, it will
add it as an additional triple (returning an array, which includes all previous values). If source is undefined, null
or blank, the method returns undefined
.
piveau.mapReference(source, target, type)
Returning a JSON-LD uriRef with the value of source and optionally with the given type. If target exists, it will
add it as an additional triple (returning an array, which includes all previous values). If source is undefined, null
or blank, the method returns undefined
.
piveau.mapSingleLiteral(source, lang)
Returning a JSON-LD literal with the value of source and optionally with the given language. If source is undefined, null
or blank, the method returns undefined
.
piveau.mapSingleTypedLiteral(source, type)
Returning a JSON-LD typed literal with the value of source and optionally with the given type. If source is undefined, null
or blank, the method returns undefined
.
piveau.mapSingleReference(source, type)
Returning a JSON-LD typed uriRef with the value of source and optionally with the given type. If source is undefined, null
or blank, the method returns undefined
.
Debugging Scripts#
Start your transforming function with debugger
keyword. This is the entry point for your debugging session, therefore
it is recommended to put it at the beginning of your script.
PiveauScriptEngineTest.debugScript()
method to start a script debugging session with a given script and input.
When you start the test, the console output provides you with a chrome URL which you need to open in your Chrome browser.
Usually it looks like this:
Copy this URL into your Chrome browsers address field and enter. Et voilà