From 05a2d55cf7339bcc3851f5abf772e1c72a3acbae Mon Sep 17 00:00:00 2001 From: Dan Jones <dan.jones@noc.ac.uk> Date: Fri, 3 Mar 2023 16:56:39 +0000 Subject: [PATCH] feat: add stub function to handle reveived invalid Adapter implementations can override receivedInvalid to log or report on messages that don't pass validation --- dist/adapter.esm.js | 4 +++- dist/adapter.js | 4 +++- dist/protocol.esm.js | 12 ++++++++++++ dist/protocol.js | 12 ++++++++++++ src/adapter/index.js | 4 +++- src/protocol/index.js | 12 ++++++++++++ 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index cfb0379..21ced71 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -101,7 +101,9 @@ class Adapter { if (validation.valid) { const type = this.protocol.getType(parsed); this.protocol.decode(type, parsed); - } + } else { + this.protocol.receivedInvalid(parsed, validation); + } }); return response; }) diff --git a/dist/adapter.js b/dist/adapter.js index a20309e..5eb10e8 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -103,7 +103,9 @@ class Adapter { if (validation.valid) { const type = this.protocol.getType(parsed); this.protocol.decode(type, parsed); - } + } else { + this.protocol.receivedInvalid(parsed, validation); + } }); return response; }) diff --git a/dist/protocol.esm.js b/dist/protocol.esm.js index 12070d6..2cb93de 100644 --- a/dist/protocol.esm.js +++ b/dist/protocol.esm.js @@ -80,6 +80,18 @@ class GenericProtocol { return message; } + + /** + * Invoked on receiving an invalid message from the backbone + * + * @param {object} message + * @param {object} validation + * @returns {*} + */ + receivedInvalid(message, validation) { + return message; + } + /** * Optionally invoked before delivering a message to the backbone * diff --git a/dist/protocol.js b/dist/protocol.js index 7242ff8..e7099c9 100644 --- a/dist/protocol.js +++ b/dist/protocol.js @@ -82,6 +82,18 @@ class GenericProtocol { return message; } + + /** + * Invoked on receiving an invalid message from the backbone + * + * @param {object} message + * @param {object} validation + * @returns {*} + */ + receivedInvalid(message, validation) { + return message; + } + /** * Optionally invoked before delivering a message to the backbone * diff --git a/src/adapter/index.js b/src/adapter/index.js index 3d48d0e..8489f83 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -101,7 +101,9 @@ export class Adapter { if (validation.valid) { const type = this.protocol.getType(parsed); this.protocol.decode(type, parsed); - } + } else { + this.protocol.receivedInvalid(parsed, validation); + } }); return response; }) diff --git a/src/protocol/index.js b/src/protocol/index.js index 1d7f69f..dcc87cd 100644 --- a/src/protocol/index.js +++ b/src/protocol/index.js @@ -80,6 +80,18 @@ export class GenericProtocol { return message; } + + /** + * Invoked on receiving an invalid message from the backbone + * + * @param {object} message + * @param {object} validation + * @returns {*} + */ + receivedInvalid(message, validation) { + return message; + } + /** * Optionally invoked before delivering a message to the backbone * -- GitLab