{"version":3,"file":"throw-restricted-fields.mjs","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isString } from 'lodash';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n  ({ key, path: { attribute: path } }) => {\n    // all fields\n    if (restrictedFields === null) {\n      throwInvalidKey({ key, path });\n    }\n\n    // Throw on invalid formats\n    if (!(Array.isArray(restrictedFields) && restrictedFields.every(isString))) {\n      throw new TypeError(\n        `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n      );\n    }\n\n    // if an exact match was found\n    if (restrictedFields.includes(path as string)) {\n      throwInvalidKey({ key, path });\n    }\n\n    // nested matches\n    const isRestrictedNested = restrictedFields.some((allowedPath) =>\n      path?.toString().startsWith(`${allowedPath}.`)\n    );\n    if (isRestrictedNested) {\n      throwInvalidKey({ key, path });\n    }\n  };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","Array","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;AAIA,4BAAe,CAAA,CAACA,gBAAAA,GAAoC,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAAA,EAAM,EAAEC,SAAAA,EAAWD,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAA,EAAM;YAC7BI,eAAAA,CAAgB;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B,QAAA;;QAGA,IAAI,EAAEG,KAAAA,CAAMC,OAAO,CAACN,qBAAqBA,gBAAAA,CAAiBO,KAAK,CAACC,QAAAA,CAAQ,CAAA,EAAI;YAC1E,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOT,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF,QAAA;;QAGA,IAAIA,gBAAAA,CAAiBU,QAAQ,CAACR,IAAAA,CAAAA,EAAiB;YAC7CE,eAAAA,CAAgB;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B,QAAA;;AAGA,QAAA,MAAMS,kBAAAA,GAAqBX,gBAAAA,CAAiBY,IAAI,CAAC,CAACC,WAAAA,GAChDX,IAAAA,EAAMY,QAAAA,EAAAA,CAAWC,UAAAA,CAAW,CAAA,EAAGF,WAAAA,CAAY,CAAC,CAAC,CAAA,CAAA;AAE/C,QAAA,IAAIF,kBAAAA,EAAoB;YACtBP,eAAAA,CAAgB;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B,QAAA;AACF,IAAA,CAAA;;;;"}