daf-message-handler
Advanced tools
Comparing version 7.0.0-beta.55 to 7.0.0-beta.56
@@ -11,29 +11,2 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -46,22 +19,17 @@ exports.AbstractMessageHandler = exports.unsupportedMessageTypeError = void 0; | ||
*/ | ||
var AbstractMessageHandler = /** @class */ (function () { | ||
function AbstractMessageHandler() { | ||
} | ||
AbstractMessageHandler.prototype.setNext = function (messageHandler) { | ||
class AbstractMessageHandler { | ||
setNext(messageHandler) { | ||
this.nextMessageHandler = messageHandler; | ||
return messageHandler; | ||
}; | ||
AbstractMessageHandler.prototype.handle = function (message, context) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (this.nextMessageHandler) { | ||
return [2 /*return*/, this.nextMessageHandler.handle(message, context)]; | ||
} | ||
return [2 /*return*/, Promise.reject(exports.unsupportedMessageTypeError)]; | ||
}); | ||
} | ||
handle(message, context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.nextMessageHandler) { | ||
return this.nextMessageHandler.handle(message, context); | ||
} | ||
return Promise.reject(exports.unsupportedMessageTypeError); | ||
}); | ||
}; | ||
return AbstractMessageHandler; | ||
}()); | ||
} | ||
} | ||
exports.AbstractMessageHandler = AbstractMessageHandler; | ||
//# sourceMappingURL=abstract-message-handler.js.map |
@@ -11,40 +11,2 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -55,6 +17,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.MessageHandler = exports.EventTypes = void 0; | ||
var daf_core_1 = require("daf-core"); | ||
var message_1 = require("./message"); | ||
var debug_1 = __importDefault(require("debug")); | ||
var debug = debug_1.default('daf:message-handler'); | ||
const daf_core_1 = require("daf-core"); | ||
const message_1 = require("./message"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const debug = debug_1.default('daf:message-handler'); | ||
exports.EventTypes = { | ||
@@ -68,28 +30,17 @@ validatedMessage: 'validatedMessage', | ||
*/ | ||
var MessageHandler = /** @class */ (function () { | ||
function MessageHandler(options) { | ||
var e_1, _a; | ||
class MessageHandler { | ||
constructor(options) { | ||
this.schema = daf_core_1.schema.IMessageHandler; | ||
try { | ||
for (var _b = __values(options.messageHandlers), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var messageHandler = _c.value; | ||
if (!this.messageHandler) { | ||
this.messageHandler = messageHandler; | ||
for (const messageHandler of options.messageHandlers) { | ||
if (!this.messageHandler) { | ||
this.messageHandler = messageHandler; | ||
} | ||
else { | ||
let lastHandler = this.messageHandler; | ||
while (lastHandler.nextMessageHandler !== undefined) { | ||
lastHandler = lastHandler.nextMessageHandler; | ||
} | ||
else { | ||
var lastHandler = this.messageHandler; | ||
while (lastHandler.nextMessageHandler !== undefined) { | ||
lastHandler = lastHandler.nextMessageHandler; | ||
} | ||
lastHandler.setNext(messageHandler); | ||
} | ||
lastHandler.setNext(messageHandler); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
this.handleMessage = this.handleMessage.bind(this); | ||
@@ -101,45 +52,32 @@ this.methods = { | ||
/** {@inheritDoc daf-core#IMessageHandler.handleMessage} */ | ||
MessageHandler.prototype.handleMessage = function (args, context) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var raw, metaData, save, message, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
raw = args.raw, metaData = args.metaData, save = args.save; | ||
debug('%o', { raw: raw, metaData: metaData, save: save }); | ||
if (!this.messageHandler) { | ||
return [2 /*return*/, Promise.reject('Message handler not provided')]; | ||
} | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 5, , 6]); | ||
return [4 /*yield*/, this.messageHandler.handle(new message_1.Message({ raw: raw, metaData: metaData }), context)]; | ||
case 2: | ||
message = _a.sent(); | ||
if (message.isValid()) { | ||
debug('Emitting event', exports.EventTypes.validatedMessage); | ||
context.agent.emit(exports.EventTypes.validatedMessage, message); | ||
} | ||
debug('Validated message %o', message); | ||
if (!save) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, context.agent.dataStoreSaveMessage({ message: message })]; | ||
case 3: | ||
_a.sent(); | ||
debug('Emitting event', exports.EventTypes.savedMessage); | ||
context.agent.emit(exports.EventTypes.savedMessage, message); | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, message]; | ||
case 5: | ||
error_1 = _a.sent(); | ||
debug('Error', error_1); | ||
context.agent.emit(exports.EventTypes.error, error_1); | ||
return [2 /*return*/, Promise.reject(error_1)]; | ||
case 6: return [2 /*return*/]; | ||
handleMessage(args, context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { raw, metaData, save } = args; | ||
debug('%o', { raw, metaData, save }); | ||
if (!this.messageHandler) { | ||
return Promise.reject('Message handler not provided'); | ||
} | ||
try { | ||
const message = yield this.messageHandler.handle(new message_1.Message({ raw, metaData }), context); | ||
if (message.isValid()) { | ||
debug('Emitting event', exports.EventTypes.validatedMessage); | ||
context.agent.emit(exports.EventTypes.validatedMessage, message); | ||
} | ||
}); | ||
debug('Validated message %o', message); | ||
if (save) { | ||
yield context.agent.dataStoreSaveMessage({ message }); | ||
debug('Emitting event', exports.EventTypes.savedMessage); | ||
context.agent.emit(exports.EventTypes.savedMessage, message); | ||
} | ||
return message; | ||
} | ||
catch (error) { | ||
debug('Error', error); | ||
context.agent.emit(exports.EventTypes.error, error); | ||
return Promise.reject(error); | ||
} | ||
}); | ||
}; | ||
return MessageHandler; | ||
}()); | ||
} | ||
} | ||
exports.MessageHandler = MessageHandler; | ||
//# sourceMappingURL=message-handler.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Message = void 0; | ||
var Message = /** @class */ (function () { | ||
function Message(data) { | ||
class Message { | ||
constructor(data) { | ||
if (data === null || data === void 0 ? void 0 : data.raw) { | ||
@@ -13,3 +13,3 @@ this.raw = data.raw; | ||
} | ||
Message.prototype.addMetaData = function (meta) { | ||
addMetaData(meta) { | ||
if (this.metaData) { | ||
@@ -21,4 +21,4 @@ this.metaData.push(meta); | ||
} | ||
}; | ||
Message.prototype.getLastMetaData = function () { | ||
} | ||
getLastMetaData() { | ||
if (this.metaData !== undefined && this.metaData.length > 0) { | ||
@@ -30,4 +30,4 @@ return this.metaData[this.metaData.length - 1]; | ||
} | ||
}; | ||
Message.prototype.isValid = function () { | ||
} | ||
isValid() { | ||
if (this.type === null || this.type === '') { | ||
@@ -40,6 +40,5 @@ return false; | ||
return true; | ||
}; | ||
return Message; | ||
}()); | ||
} | ||
} | ||
exports.Message = Message; | ||
//# sourceMappingURL=message.js.map |
@@ -6,2 +6,10 @@ # Change Log | ||
# [7.0.0-beta.56](https://github.com/uport-project/daf/compare/v7.0.0-beta.55...v7.0.0-beta.56) (2020-12-09) | ||
**Note:** Version bump only for package daf-message-handler | ||
# [7.0.0-beta.55](https://github.com/uport-project/daf/compare/v7.0.0-beta.54...v7.0.0-beta.55) (2020-12-08) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "daf-message-handler", | ||
"description": "DAF Message Handler", | ||
"version": "7.0.0-beta.55", | ||
"version": "7.0.0-beta.56", | ||
"main": "build/index.js", | ||
@@ -12,3 +12,3 @@ "types": "build/index.d.ts", | ||
"dependencies": { | ||
"daf-core": "^7.0.0-beta.55" | ||
"daf-core": "^7.0.0-beta.56" | ||
}, | ||
@@ -28,3 +28,3 @@ "devDependencies": { | ||
"keywords": [], | ||
"gitHead": "247141ffc1a113812d485cfbe8aad951cff159c1" | ||
"gitHead": "73ab0e6b03b399040553653aeec588a677e5b98d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
41293
399
Updateddaf-core@^7.0.0-beta.56