UNPKG

n8n

Version:

n8n Workflow Automation Tool

61 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createFailure = createFailure; exports.destinationKey = destinationKey; exports.dedupeCreationsByDestination = dedupeCreationsByDestination; exports.divergentOverwrites = divergentOverwrites; exports.computeVariableLimitFailure = computeVariableLimitFailure; function createFailure(requirement) { return { name: requirement.name, usedByWorkflows: [...new Set(requirement.usedByWorkflows)].sort(), }; } function destinationKey(destination) { return destination.projectId ? `project:${destination.projectId}:${destination.name}` : `global:${destination.name}`; } function dedupeCreationsByDestination(creations) { const byDestination = new Map(); for (const creation of creations) { const key = destinationKey(creation); const existing = byDestination.get(key); if (!existing) { byDestination.set(key, { ...creation, usedByWorkflows: [...creation.usedByWorkflows] }); continue; } existing.usedByWorkflows = [ ...new Set([...existing.usedByWorkflows, ...creation.usedByWorkflows]), ].sort(); } return [...byDestination.values()]; } function divergentOverwrites(overwrites) { const firstValueByRow = new Map(); const divergent = new Set(); for (const { variableId, value } of overwrites) { const seen = firstValueByRow.get(variableId); if (seen === undefined) firstValueByRow.set(variableId, value); else if (seen !== value) divergent.add(variableId); } return overwrites .filter(({ variableId }) => divergent.has(variableId)) .map(({ variableId, value, ...conflict }) => conflict); } function computeVariableLimitFailure(creations, quota) { if (quota === null || creations.length === 0) return undefined; if (creations.length <= quota.remaining) return undefined; return { limit: quota.limit, remaining: quota.remaining, requested: creations.length, names: [...new Set(creations.map((creation) => creation.name))].sort(), usedByWorkflows: [...new Set(creations.flatMap((creation) => creation.usedByWorkflows))].sort(), }; } //# sourceMappingURL=variable.types.js.map