{"version":3,"file":"index.mjs","sources":["../../../../src/services/document-service/attributes/index.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID, Modules, Schema } from '@strapi/types';\n\nimport transforms from './transforms';\n\n// aliasing the type to make it easier to read\ntype Data = Modules.Documents.Params.Data.Input<UID.Schema>;\n\nconst applyTransforms = curry((schema: Schema.Schema, data: Data) => {\n  const attributeNames = Object.keys(data) as Array<keyof typeof data & string>;\n\n  for (const attributeName of attributeNames) {\n    const value = data[attributeName];\n\n    const attribute = schema.attributes[attributeName];\n\n    if (!attribute) {\n      continue;\n    }\n\n    const transform = transforms[attribute.type];\n\n    if (transform) {\n      const attributeContext = { attributeName, attribute };\n\n      data[attributeName] = transform(value, attributeContext);\n    }\n  }\n\n  return data;\n});\n\nexport { applyTransforms };\n"],"names":["applyTransforms","curry","schema","data","attributeNames","Object","keys","attributeName","value","attribute","attributes","transform","transforms","type","attributeContext"],"mappings":";;;AASA,MAAMA,eAAAA,GAAkBC,KAAAA,CAAM,CAACC,MAAAA,EAAuBC,IAAAA,GAAAA;IACpD,MAAMC,cAAAA,GAAiBC,MAAAA,CAAOC,IAAI,CAACH,IAAAA,CAAAA;IAEnC,KAAK,MAAMI,iBAAiBH,cAAAA,CAAgB;QAC1C,MAAMI,KAAAA,GAAQL,IAAI,CAACI,aAAAA,CAAc;AAEjC,QAAA,MAAME,SAAAA,GAAYP,MAAAA,CAAOQ,UAAU,CAACH,aAAAA,CAAc;AAElD,QAAA,IAAI,CAACE,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;AAEA,QAAA,MAAME,SAAAA,GAAYC,UAAU,CAACH,SAAAA,CAAUI,IAAI,CAAC;AAE5C,QAAA,IAAIF,SAAAA,EAAW;AACb,YAAA,MAAMG,gBAAAA,GAAmB;AAAEP,gBAAAA,aAAAA;AAAeE,gBAAAA;AAAU,aAAA;AAEpDN,YAAAA,IAAI,CAACI,aAAAA,CAAc,GAAGI,SAAAA,CAAUH,KAAAA,EAAOM,gBAAAA,CAAAA;AACzC,QAAA;AACF,IAAA;IAEA,OAAOX,IAAAA;AACT,CAAA;;;;"}