Namespace: fastifyCloudEvents

(async) plugin~fastifyCloudEvents(fastifynon-null, optionsopt)

Plugin implementation.

Plugin implementation. Note that's an async function.
Parameters:
Name Type Attributes Default Description
fastify object Fastify instance
options object <optional>
{} plugin configuration options
  • baseNamespace (string, default `com.github.fastify.plugins.${pluginName}-v${pluginVersion}`) as base namespace for events generated,
  • cloudEventExtensions (object, default null) Extensions for events generated,
  • cloudEventOptions (object, default empty) Options for events generated,
  • idGenerator (function, default idMaker) to build ID for events generated,
  • includeHeaders (boolean, default false) flag to enable the add HTTP request Headers in events generated,
  • includeHttpAttributes (boolean, default false) flag to add some HTTP request attributes in events generated,
  • includeRedundantAttributes` (boolean, default false) flag to add some redundant attributes inside data in events generated,
  • onCloseCallback (function, no default) callback function for the 'onClose' hook,
  • onErrorCallback (function, no default) callback function for the 'onError' hook,
  • onReadyCallback (function, no default) callback function for the 'onReady' hook,
  • onRegisterCallback (function, no default) callback function for the 'onRegister' hook,
  • onRequestCallback (function, no default) callback function for the 'onRequest' hook,
  • onResponseCallback (function, no default) callback function for the 'onResponse' hook,
  • onRouteCallback (function, no default) callback function for the 'onRoute' hook,
  • onSendCallback (function, no default) callback function for the 'onSend' hook,
  • onTimeoutCallback (function, no default) callback function for the 'onTimeout' hook,
  • preHandlerCallback (function, no default) callback function for the 'preHandler' hook,
  • preParsingCallback (function, no default) callback function for the 'preParsing' hook,
  • preSerializationCallback (function, no default) callback function for the 'preSerialization' hook,
  • preValidationCallback (function, no default) callback function for the 'preValidation' hook,
  • serverUrl (string, default '/') used as base to calculate source URL in events generated,
  • serverUrlMode (string, default null so 'pluginAndRequestSimplified'; other values: 'pluginAndRequestUrl', 'pluginServerUrl','requestUrl') specify the way to calculate source URL in events generated,
  • See README - cloudevent.js - GitHub for more info.
  • For Hooks, see Hooks - Fastify reference - GitHub for more info.
Source:

Methods

(inner) serialize(eventnon-null, optionsopt) → {string}

Serialize the given CloudEvent in JSON format.

Serialize the given CloudEvent in JSON format.
Parameters:
Name Type Attributes Default Description
event object the CloudEvent to serialize
options object <optional>
{} optional serialization attributes:
  • encoder (function, no default) a function that takes data and returns encoded data as a string,
  • encodedData (string, no default) already encoded data (but consistency with the datacontenttype is not checked),
  • onlyValid (boolean, default false) to serialize only if it's a valid instance,
  • printDebugInfo (boolean, default false) to print some debug info to the console,
  • timezoneOffset (number, default 0) to apply a different timezone offset,
  • See CloudEvent and its static method serializeEvent for similar options.
Source:
Throws:
  • if event is undefined or null, or an option is undefined/null/wrong
    Type
    Error
  • if onlyValid is true, and the given event is not a valid CloudEvent instance
    Type
    Error
Returns:
the serialized event, as a string
Type
string

(inner) validate(eventnon-null, optionsopt) → {object}

Validate the given CloudEvent with the schema compiler already instanced.

Validate the given CloudEvent with the schema compiler already instanced.
Parameters:
Name Type Attributes Default Description
event object the CloudEvent to validate
options object <optional>
null Ajv validation options, see Options - AJV Validator
Source:
Throws:
if event is undefined or null
Type
Error
Returns:
object with validation results: 'valid' boolean and 'errors' as array of strings or null
Type
object