{"version":3,"file":"CrudBrowserUtilities.mjs","names":["RESERVED_PATH_PARAMETERS","getPrimaryKeyValues","properties","entityValue","primaryKeyProperties","filter","property","extendedProperties","identifier","primaryKeyValues","reduce","keyValues","getPathObject","pathParameters","primaryKeyParameters","parameter","includes","name","pathObject","length","forEach","pkp","index","Array","isArray","key","Object","keys","find","toLowerCase","undefined","findTermByType","fieldType","term","getModelProperties","model","componentsObj","modelPropertiesObj","refKeys","reference","refString","lastIndex","lastIndexOf","referenceModel","substring","push","abstractModel","getEntityAttributes","catalog","entityName","catalogObjectList","ctlg","components","entity","catalogObject","catalogObjectName","nullable","modelProperty","getPathParametersObj","pathParametersDefinition","entityData","pathParametersObj","param"],"sources":["../../../src/utilities/maintenanceEngine/CrudBrowserUtilities.js"],"sourcesContent":["const RESERVED_PATH_PARAMETERS = ['version', 'udp-api-version'];\n\nexport const getPrimaryKeyValues = (properties, entityValue) => {\n  const primaryKeyProperties = properties?.filter(\n    (property) => property?.extendedProperties?.identifier\n  );\n  const primaryKeyValues = primaryKeyProperties?.reduce(\n    (keyValues, property) => {\n      if (entityValue && entityValue[property['name']] != null) {\n        keyValues[property['name']] = entityValue[property['name']];\n      }\n      return keyValues;\n    },\n    {}\n  );\n  return primaryKeyValues;\n};\n\n// primaryKeyValues: { [propertyName]: value } matched to path parameters by\n// name (case-insensitive), or an array matched by position.\nexport const getPathObject = (pathParameters, primaryKeyValues) => {\n  const primaryKeyParameters = pathParameters.filter(\n    (parameter) => !RESERVED_PATH_PARAMETERS.includes(parameter.name)\n  );\n\n  const pathObject = {};\n  if (primaryKeyParameters.length && primaryKeyValues) {\n    primaryKeyParameters.forEach((pkp, index) => {\n      if (Array.isArray(primaryKeyValues)) {\n        pathObject[`{${pkp.name}}`] = primaryKeyValues[index];\n        return;\n      }\n      const key = Object.keys(primaryKeyValues).find(\n        (name) => name.toLowerCase() === pkp.name.toLowerCase()\n      );\n      pathObject[`{${pkp.name}}`] =\n        key === undefined ? undefined : primaryKeyValues[key];\n    });\n  }\n  return pathObject;\n};\n\nexport const findTermByType = (fieldType, term) => {\n  if (fieldType.toLowerCase() === term) {\n    return fieldType.toLowerCase();\n  } else {\n    return '';\n  }\n};\n\nconst getModelProperties = (model, componentsObj) => {\n  let modelPropertiesObj = null;\n  if (model) {\n    modelPropertiesObj = model.properties;\n    if (!modelPropertiesObj) {\n      const refKeys = [];\n      if (model['allOf']?.length) {\n        model['allOf'].forEach((reference) => {\n          if (reference['$ref']) {\n            const refString = reference['$ref'];\n            if (refString) {\n              const lastIndex = refString.lastIndexOf('/');\n              const referenceModel = refString.substring(lastIndex + 1);\n              refKeys.push(referenceModel);\n            }\n          }\n        });\n      }\n      refKeys.forEach((key) => {\n        const abstractModel = componentsObj[key];\n        if (modelPropertiesObj && abstractModel?.properties) {\n          modelPropertiesObj = {\n            ...modelPropertiesObj,\n            ...abstractModel.properties\n          };\n        } else {\n          modelPropertiesObj = abstractModel?.properties;\n        }\n      });\n    }\n  }\n  return modelPropertiesObj;\n};\n\nexport const getEntityAttributes = (catalog, entityName) => {\n  if (!catalog) {\n    return [];\n  }\n  const catalogObjectList = catalog?.ctlg?.catalogObjectList;\n  const componentsObj = catalog?.ctlg?.components;\n  const entity = catalogObjectList?.find(\n    (catalogObject) => catalogObject.catalogObjectName === entityName\n  );\n\n  if (!!componentsObj && Object.keys(componentsObj).length) {\n    const model = componentsObj[entityName];\n    let modelPropertiesObj = getModelProperties(model, componentsObj);\n    if (entity?.properties?.length) {\n      entity.properties.forEach((property) => {\n        let nullable = true;\n        if (modelPropertiesObj) {\n          const modelProperty = modelPropertiesObj[property['name']];\n          if (modelProperty) {\n            nullable = modelProperty.nullable || false;\n          }\n        }\n        property['nullable'] = nullable;\n      });\n    }\n  }\n\n  return entity ? entity.properties : [];\n};\n\nexport const getPathParametersObj = (pathParametersDefinition, entityData) => {\n  if (!pathParametersDefinition || !entityData) return {};\n\n  const pathParametersObj = {};\n\n  for (let param of pathParametersDefinition) {\n    pathParametersObj[param.name] = entity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