{"version":3,"file":"RegistrationConflicts.mjs","names":[],"sources":["../../src/view/RegistrationConflicts.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { InstrumentSelectorCriteria } from './InstrumentSelector';\nimport type { InstrumentDescriptor } from '../InstrumentDescriptor';\n\nexport function getIncompatibilityDetails(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n) {\n  let incompatibility = '';\n  if (existing.unit !== otherDescriptor.unit) {\n    incompatibility += `\\t- Unit '${existing.unit}' does not match '${otherDescriptor.unit}'\\n`;\n  }\n  if (existing.type !== otherDescriptor.type) {\n    incompatibility += `\\t- Type '${existing.type}' does not match '${otherDescriptor.type}'\\n`;\n  }\n  if (existing.valueType !== otherDescriptor.valueType) {\n    incompatibility += `\\t- Value Type '${existing.valueType}' does not match '${otherDescriptor.valueType}'\\n`;\n  }\n  if (existing.description !== otherDescriptor.description) {\n    incompatibility += `\\t- Description '${existing.description}' does not match '${otherDescriptor.description}'\\n`;\n  }\n\n  return incompatibility;\n}\n\nexport function getValueTypeConflictResolutionRecipe(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n) {\n  return `\\t- use valueType '${existing.valueType}' on instrument creation or use an instrument name other than '${otherDescriptor.name}'`;\n}\n\nexport function getUnitConflictResolutionRecipe(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n) {\n  return `\\t- use unit '${existing.unit}' on instrument creation or use an instrument name other than '${otherDescriptor.name}'`;\n}\n\nexport function getTypeConflictResolutionRecipe(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n) {\n  const selector: InstrumentSelectorCriteria = {\n    name: otherDescriptor.name,\n    type: otherDescriptor.type,\n    unit: otherDescriptor.unit,\n  };\n\n  const selectorString = JSON.stringify(selector);\n\n  return `\\t- create a new view with a name other than '${existing.name}' and InstrumentSelector '${selectorString}'`;\n}\n\nexport function getDescriptionResolutionRecipe(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n): string {\n  const selector: InstrumentSelectorCriteria = {\n    name: otherDescriptor.name,\n    type: otherDescriptor.type,\n    unit: otherDescriptor.unit,\n  };\n\n  const selectorString = JSON.stringify(selector);\n\n  return `\\t- create a new view with a name other than '${existing.name}' and InstrumentSelector '${selectorString}'\n    \\t- OR - create a new view with the name ${existing.name} and description '${existing.description}' and InstrumentSelector ${selectorString}\n    \\t- OR - create a new view with the name ${otherDescriptor.name} and description '${existing.description}' and InstrumentSelector ${selectorString}`;\n}\n\nexport function getConflictResolutionRecipe(\n  existing: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n): string {\n  // Conflicts that cannot be solved via views.\n  if (existing.valueType !== otherDescriptor.valueType) {\n    return getValueTypeConflictResolutionRecipe(existing, otherDescriptor);\n  }\n\n  if (existing.unit !== otherDescriptor.unit) {\n    return getUnitConflictResolutionRecipe(existing, otherDescriptor);\n  }\n\n  // Conflicts that can be solved via views.\n  if (existing.type !== otherDescriptor.type) {\n    // this will automatically solve possible description conflicts.\n    return getTypeConflictResolutionRecipe(existing, otherDescriptor);\n  }\n\n  if (existing.description !== otherDescriptor.description) {\n    return getDescriptionResolutionRecipe(existing, otherDescriptor);\n  }\n\n  return '';\n}\n"],"mappings":";AAQA,SAAgB,0BACd,UACA,iBACA;CACA,IAAI,kBAAkB;CACtB,IAAI,SAAS,SAAS,gBAAgB,MACpC,mBAAmB,aAAa,SAAS,KAAK,oBAAoB,gBAAgB,KAAK;CAEzF,IAAI,SAAS,SAAS,gBAAgB,MACpC,mBAAmB,aAAa,SAAS,KAAK,oBAAoB,gBAAgB,KAAK;CAEzF,IAAI,SAAS,cAAc,gBAAgB,WACzC,mBAAmB,mBAAmB,SAAS,UAAU,oBAAoB,gBAAgB,UAAU;CAEzG,IAAI,SAAS,gBAAgB,gBAAgB,aAC3C,mBAAmB,oBAAoB,SAAS,YAAY,oBAAoB,gBAAgB,YAAY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