UNPKG

ssb-typescript

Version:

TypeScript type definitions for Secure Scuttlebutt

94 lines 5.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isBlogMsg = exports.isPublic = exports.isPrivate = exports.isAttendeeMsg = exports.isGatheringMsg = exports.isVoteMsg = exports.isContactMsg = exports.isAboutMsg = exports.isReplyPostMsg = exports.isRootPostMsg = exports.isPostMsg = exports.isIndirectReplyMsgToRoot = exports.isReplyMsgToRoot = exports.isRootMsg = exports.isMsg = void 0; function isMsg(msg) { return msg && msg.key && msg.value && typeof msg.value === 'object'; } exports.isMsg = isMsg; function isRootMsg(msg) { var _a, _b; return !((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.root); } exports.isRootMsg = isRootMsg; function isReplyMsgToRoot(rootKey) { return function (msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.root) === rootKey; }; } exports.isReplyMsgToRoot = isReplyMsgToRoot; function isIndirectReplyMsgToRoot(rootKey) { return function (msg) { var _a, _b, _c, _d, _e, _f; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.root) === rootKey || ((_d = (_c = msg === null || msg === void 0 ? void 0 : msg.value) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.branch) === rootKey || ((_f = (_e = msg === null || msg === void 0 ? void 0 : msg.value) === null || _e === void 0 ? void 0 : _e.content) === null || _f === void 0 ? void 0 : _f.fork) === rootKey; }; } exports.isIndirectReplyMsgToRoot = isIndirectReplyMsgToRoot; function isPostMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'post'; } exports.isPostMsg = isPostMsg; function isRootPostMsg(msg) { return isPostMsg(msg) && !msg.value.content.root; } exports.isRootPostMsg = isRootPostMsg; function isReplyPostMsg(msg) { return isPostMsg(msg) && !!msg.value.content.root; } exports.isReplyPostMsg = isReplyPostMsg; function isAboutMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'about'; } exports.isAboutMsg = isAboutMsg; function isContactMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'contact'; } exports.isContactMsg = isContactMsg; function isVoteMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'vote'; } exports.isVoteMsg = isVoteMsg; function isGatheringMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'gathering'; } exports.isGatheringMsg = isGatheringMsg; function isAttendeeMsg(msg) { var _a, _b; return (((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'about' && msg.value.content.about && msg.value.content.attendee && msg.value.content.attendee.link); } exports.isAttendeeMsg = isAttendeeMsg; function isPrivate(msg) { var _a, _b, _c; if ((_a = msg.meta) === null || _a === void 0 ? void 0 : _a.private) return true; if (msg.value.private) return true; if (Array.isArray((_b = msg.value.content) === null || _b === void 0 ? void 0 : _b.recps)) return true; return typeof ((_c = msg === null || msg === void 0 ? void 0 : msg.value) === null || _c === void 0 ? void 0 : _c.content) === 'string'; } exports.isPrivate = isPrivate; function isPublic(msg) { var _a, _b, _c; if ((_a = msg.meta) === null || _a === void 0 ? void 0 : _a.private) return false; if (msg.value.private) return false; if (Array.isArray((_b = msg.value.content) === null || _b === void 0 ? void 0 : _b.recps)) return false; return typeof ((_c = msg === null || msg === void 0 ? void 0 : msg.value) === null || _c === void 0 ? void 0 : _c.content) !== 'string'; } exports.isPublic = isPublic; function isBlogMsg(msg) { var _a, _b; return ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.value) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.type) === 'blog'; } exports.isBlogMsg = isBlogMsg; //# sourceMappingURL=utils.js.map