UNPKG

@jadl/cmd

Version:
48 lines (47 loc) 1.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeekInteractions = void 0; const deep_equal_1 = __importDefault(require("deep-equal")); const INTERACTION_CHANGED_PROPS = [ 'name', 'type', 'description', 'options', 'default_member_permissions', 'description_localizations' ]; const SeekInteractions = (oldInteractions, newInteractions) => { const interactions = { added: [], updated: [], deleted: [] }; const mutuals = newInteractions.filter((newInt) => oldInteractions.some((oldInt) => oldInt.name === newInt.name)); oldInteractions.forEach((int) => { if (!mutuals.some((x) => x.name === int.name)) interactions.deleted.push(int); }); newInteractions.forEach((int) => { if (!mutuals.some((x) => x.name === int.name)) interactions.added.push(int); }); mutuals.forEach((newInteraction) => { const oldInteraction = oldInteractions.find((x) => x.name === newInteraction.name); if (!oldInteraction) return; let cleanObject = {}; INTERACTION_CHANGED_PROPS.forEach((x) => { cleanObject[x] = oldInteraction[x]; if (!Object.keys(newInteraction).includes(x)) newInteraction[x] = undefined; }); if (!(0, deep_equal_1.default)(cleanObject, newInteraction)) { interactions.updated.push({ ...newInteraction, id: oldInteraction.id }); } }); return interactions; }; exports.SeekInteractions = SeekInteractions;