Files
klz-cables.com/.pnpm-store/v10/files/8a/8b6eb475a5bd640913e5b4ca0e0eab8a31ac73ca47d47c63a6c37ec5799b1052f5e7d66eba751e5b7d99c53a87793faf66500ec3b5a34272cab583d6c17501
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

1 line
3.5 KiB
Plaintext

{"version":3,"file":"normalizeRelationshipValue.js","names":["normalizeRelationshipValue","value","relationTo","isPoly","Array","isArray","idValue","id"],"sources":["../../src/utilities/normalizeRelationshipValue.ts"],"sourcesContent":["/**\n * Normalizes relationship/upload field values by extracting IDs from nested objects\n * and returning them in the appropriate format based on whether the field is polymorphic.\n *\n * @param value - The value to normalize (can be a simple ID, or an object with relationTo and value)\n * @param relationTo - The relationTo config (string for monomorphic, array for polymorphic)\n * @returns The normalized value (simple ID for monomorphic, {relationTo, value} for polymorphic)\n *\n * @example\n * // Monomorphic field - returns simple ID\n * normalizeRelationshipValue('123', 'users') // '123'\n * normalizeRelationshipValue({ relationTo: 'users', value: '123' }, 'users') // '123'\n *\n * @example\n * // Polymorphic field - returns {relationTo, value}\n * normalizeRelationshipValue('123', ['users', 'posts']) // '123' (kept as-is, no relationTo to infer)\n * normalizeRelationshipValue({ relationTo: 'users', value: '123' }, ['users', 'posts'])\n * // { relationTo: 'users', value: '123' }\n *\n * @example\n * // Handles nested value objects (populated documents)\n * normalizeRelationshipValue(\n * { relationTo: 'users', value: { id: '123', name: 'John' } },\n * ['users', 'posts']\n * )\n * // { relationTo: 'users', value: '123' }\n */\nexport function normalizeRelationshipValue(value: any, relationTo: string | string[]): any {\n const isPoly = Array.isArray(relationTo)\n\n // If it's already a simple ID (string or number), return as-is for non-poly or wrap for poly\n if (typeof value === 'string' || typeof value === 'number') {\n return value\n }\n\n // If it's an object with relationTo and value\n if (value && typeof value === 'object' && 'relationTo' in value && 'value' in value) {\n // Extract the actual ID value, handling nested objects\n let idValue: any = value.value\n while (idValue && typeof idValue === 'object' && idValue !== null && 'value' in idValue) {\n idValue = idValue.value\n }\n\n // If the nested value is a populated document with an ID, extract it\n if (idValue && typeof idValue === 'object' && idValue !== null && 'id' in idValue) {\n idValue = idValue.id\n }\n\n // Return the normalized structure\n if (isPoly) {\n return { relationTo: value.relationTo, value: idValue }\n }\n return idValue\n }\n\n // If it's a populated document object (has id but no relationTo/value structure)\n if (value && typeof value === 'object' && 'id' in value) {\n return value.id\n }\n\n return value\n}\n"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BA,OAAO,SAASA,2BAA2BC,KAAU,EAAEC,UAA6B;EAClF,MAAMC,MAAA,GAASC,KAAA,CAAMC,OAAO,CAACH,UAAA;EAE7B;EACA,IAAI,OAAOD,KAAA,KAAU,YAAY,OAAOA,KAAA,KAAU,UAAU;IAC1D,OAAOA,KAAA;EACT;EAEA;EACA,IAAIA,KAAA,IAAS,OAAOA,KAAA,KAAU,YAAY,gBAAgBA,KAAA,IAAS,WAAWA,KAAA,EAAO;IACnF;IACA,IAAIK,OAAA,GAAeL,KAAA,CAAMA,KAAK;IAC9B,OAAOK,OAAA,IAAW,OAAOA,OAAA,KAAY,YAAYA,OAAA,KAAY,QAAQ,WAAWA,OAAA,EAAS;MACvFA,OAAA,GAAUA,OAAA,CAAQL,KAAK;IACzB;IAEA;IACA,IAAIK,OAAA,IAAW,OAAOA,OAAA,KAAY,YAAYA,OAAA,KAAY,QAAQ,QAAQA,OAAA,EAAS;MACjFA,OAAA,GAAUA,OAAA,CAAQC,EAAE;IACtB;IAEA;IACA,IAAIJ,MAAA,EAAQ;MACV,OAAO;QAAED,UAAA,EAAYD,KAAA,CAAMC,UAAU;QAAED,KAAA,EAAOK;MAAQ;IACxD;IACA,OAAOA,OAAA;EACT;EAEA;EACA,IAAIL,KAAA,IAAS,OAAOA,KAAA,KAAU,YAAY,QAAQA,KAAA,EAAO;IACvD,OAAOA,KAAA,CAAMM,EAAE;EACjB;EAEA,OAAON,KAAA;AACT","ignoreList":[]}