{"version":3,"file":"transforms.mjs","sources":["../../../../src/services/document-service/attributes/transforms.ts"],"sourcesContent":["import { getOr, toNumber, isString } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\nimport bcrypt from 'bcryptjs';\n\ntype Transforms = {\n  [TKind in Schema.Attribute.Kind]?: (\n    value: unknown,\n    context: {\n      attribute: Schema.Attribute.AnyAttribute;\n      attributeName: string;\n    }\n  ) => any;\n};\n\nconst transforms: Transforms = {\n  password(value, context) {\n    const { attribute } = context;\n\n    if (attribute.type !== 'password') {\n      throw new Error('Invalid attribute type');\n    }\n\n    if (!isString(value) && !(value instanceof Buffer)) {\n      return value;\n    }\n\n    const rounds = toNumber(getOr(10, 'encryption.rounds', attribute));\n\n    return bcrypt.hashSync(value.toString(), rounds);\n  },\n};\n\nexport default transforms;\n"],"names":[],"mappings":";;AAcA,MAAM,aAAyB;AAAA,EAC7B,SAAS,OAAO,SAAS;AACjB,UAAA,EAAE,UAAc,IAAA;AAElB,QAAA,UAAU,SAAS,YAAY;AAC3B,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,QAAI,CAAC,SAAS,KAAK,KAAK,EAAE,iBAAiB,SAAS;AAC3C,aAAA;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,MAAM,IAAI,qBAAqB,SAAS,CAAC;AAEjE,WAAO,OAAO,SAAS,MAAM,YAAY,MAAM;AAAA,EACjD;AACF;"}