@energyweb/node-red-contrib-green-proof-worker
Version:
## Peer dependencies
34 lines (33 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SourceValidator = void 0;
const input_message_1 = require("../input-message");
const node_1 = require("../node");
const InputMessage = input_message_1.InputMessages.UnitsChangedCompatibility();
const CORRECT_OUTPUT = 0;
const WRONG_OUTPUT = 1;
const SourceValidator = (api) => class SourceValidator extends node_1.Node {
constructor(config) {
super(api, config, InputMessage, {
validateMessage: false,
});
}
onInput(message) {
const parsed = InputMessage.safeParse(message);
if (parsed.success) {
/** See {@link InputMessages.UnitsChangedCompatibility} for more details on that */
const messageFixed = {
...message,
payload: {
type: ('txLog' in message.payload) ? input_message_1.MessageType.UnitsChanged : undefined,
...message.payload, // if message type exists it will overwrite whatever we are trying to set
}
};
this.sendBuilder(messageFixed).sendToOutput(CORRECT_OUTPUT);
}
else {
this.sendBuilder(message).sendToOutput(WRONG_OUTPUT);
}
}
};
exports.SourceValidator = SourceValidator;