Data Hub Server Side Library

The /MarkLogic/data-hub-framework/dhf.xqy library module exposes functions to facilitate the interactions between MarkLogic Data Hub and your XQuery or JavaScript code.

To include the library,

site.data.dhflib.require.js
site.data.dhflib.require.xqy

DHF-LIB Functions

Run

Runs a given function as a plugin. This method provides tracing around your function. Tracing will catch uncaught exceptions and log them into the traces database.

declare function dhf:run($context as json:object, $func)
context
The context for this plugin.
func
The function to run.
What your function returns.
site.data.dhflib.run.js
site.data.dhflib.run.xqy
Run Writer

Runs a writer plugin. This function is needed to run a writer in update mode. All of the Data Hub plugins run in query-only mode and thus cannot persist data. Running your writer with this function allows you to persist data.

declare function dhf:run-writer($writer-function, $id as xs:string+, $envelope as item(), $options as map:map)
writer-function
The writer function to run. It must be an xdmp:function. See the examples below for more info.
id
The id for the current flow execution.
envelope
The envelope to write.
options
A map:map of options.
site.data.dhflib.runwriter.js
site.data.dhflib.runwriter.xqy
Make Envelope

Creates an envelope in the desired format (XML or JSON). If the data format is XML, then the namespace is http://marklogic.com/entity-services.

declare function dhf:make-envelope($content, $headers, $triples, $data-format) as document-node()
content
The content section of the envelope.
headers
The headers section of the envelope.
triples
The triples section of the envelope.
data-format
The format to use for making the envelope (xml|json).
An XML or JSON envelope (depending on data-format).
site.data.dhflib.makeenvelope.js
site.data.dhflib.makeenvelope.xqy
Make Legacy Envelope

Creates a legacy envelope in the desired format (XML or JSON). If the data format is XML then the namespace is http://marklogic.com/data-hub/envelope. This function is for users who upgraded from 1.x and have legacy envelopes already in production.

declare function dhf:make-legacy-envelope($content, $headers, $triples, $data-format) as document-node()
content
The content section of the envelope.
headers
The headers section of the envelope.
triples
The triples section of the envelope.
data-format
The format to use for making the envelope (xml|json).
An XML or JSON envelope (depending on data-format).
site.data.dhflib.makelegacyenvelope.js
site.data.dhflib.makelegacyenvelope.xqy
Context

Creates a generic context for use in any plugin. Contexts are passed to the Run function. A context defines information needed for proper tracing.

declare function dhf:context($label as xs:string) as json:object
label
The label to give this plugin for tracing.
A context object for use in the Run function.
site.data.dhflib.context.js
site.data.dhflib.context.xqy
Content Context

Creates a context for a content plugin. This is a convenience method for Context and merely uses the label "content".

declare function dhf:content-context([$raw-content]) as json:object
raw-content
(optional) The raw content passed into an input flow.
A context object for use in the Run function. This context object contains the label "content".
site.data.dhflib.contentcontext.js
site.data.dhflib.contentcontext.xqy
Headers Context

Creates a context for a headers plugin. This is a convenience method for Context and merely uses the label "headers".

declare function dhf:headers-context($content) as json:object
content
The output from the content plugin.
A context object for use in the Run function. This context object contains the label "headers".
site.data.dhflib.headercontext.js
site.data.dhflib.headercontext.xqy
Triples Context

Creates a context for a triples plugin. This is a convenience method for Context and merely uses the label "triples".

declare function dhf:triples-context($content, $headers) as json:object
content
The output from the content plugin.
headers
The output from the headers plugin.
A context object for use in the Run function. This context object contains the label "triples".
site.data.dhflib.triplescontext.js
site.data.dhflib.triplescontext.xqy
Writer Context

Creates a context for a writer plugin. This is a convenience method for Context and merely uses the label "writer".

declare function dhf:writer-context($envelope) as json:object
envelope
The envelope you constructed.
A context object for use in the Log Trace function. This context object contains the label "writer".
site.data.dhflib.writercontext.js
site.data.dhflib.writercontext.xqy
Add Trace Input

Adds a trace input to the context. You can add multiple trace inputs; however, each one must have a unique label. These inputs are later logged into traces.

declare function dhf:add-trace-input($context as json:object, $input-label as xs:string, $input) as json:object
context
The context.
input-label
The label for the input.
input
The input to add to the context.
Returns the specified context with the additional input.
site.data.dhflib.addtraceinput.js
site.data.dhflib.addtraceinput.xqy
Log Trace

Logs a trace, if tracing is enabled.

declare function dhf:log-trace($context as json:object)
context
The context.
site.data.dhflib.logtrace.js
site.data.dhflib.logtrace.xqy