Skip to content

Hooks

Weacast core module provides a collection of common hooks to be used by plugins or client applications. They also rely on Feathers common hooks.

TIP

Hooks are the main way to introduce business logic into applications and plugins so we recommend to understand them well first before reading this.

Data model management

source

.marshall(hook)

Converts from server side types (e.g. moment dates) to basic JS types, which is usually required when writing to the database.

.unmarshall(hook)

Converts back to server side types (e.g. moment dates) from basic JS types, which is usually required when reading from the database.

Query management

source

.marshallQuery(hook)

Converts from client/server side types (e.g. strings or moment dates) to basic JS types, which is usually required when querying the database.

.marshallComparisonQuery(hook)

Converts from client/server side comparison types (e.g. numbers) to basic JS types, which is usually required when querying the database. Applies to $lt, $lte, $gt and $gte operators.

.marshallSpatialQuery(hook)

Converts from client/server side spatial types (e.g. coordinates or numbers) to basic JS types, which is usually required when querying the database. Applies to MongoDB geospatial operators.

.processForecastTime(hook)

Find the nearest forecast date/time corresponding to a requested date/time or date/time range.

.processData(hook)

Discard or retrieve forecast data when required depending on the query parameters.

Logging

core source

.log(hook)

  • Log error for each hook in error with error log level.
  • Log information for each hook ran with verbose (respectively debug for client) log level.
  • Log detailed information for each hook ran with debug (respectively trace for client) log level.

Events

source

.emit(hook)

Emit an event named {hook_type}Hook (e.g. beforeHook or afterHook) for each hook ran, the payload of the event being the hook object.

By type