UNPKG

@strapi/data-transfer

Version:

Data transfer capabilities for Strapi

36 lines (33 loc) 1.25 kB
'use strict'; /** * joinColumn relations (e.g. i18n `localizations`) store `document_id` on the * inverse side. Export emits that value as a string ref; restore must not run it * through the numeric id mapper. */ const isDocumentIdJoinColumnTarget = (strapi, link, side)=>{ if (side !== 'right') { return false; } const metadata = strapi.db?.metadata?.get(link.left.type); const attribute = metadata?.attributes?.[link.left.field]; if (!attribute || attribute.type !== 'relation') { return false; } if (!('joinColumn' in attribute) || !attribute.joinColumn) { return false; } return attribute.joinColumn.referencedColumn === 'document_id'; }; const resolveLinkRef = (strapi, link, side, mapID)=>{ const { type, ref } = side === 'left' ? link.left : link.right; if (isDocumentIdJoinColumnTarget(strapi, link, side)) { return ref; } const numericRef = typeof ref === 'number' ? ref : Number(ref); if (!Number.isFinite(numericRef)) { return undefined; } return mapID(type, numericRef); }; exports.isDocumentIdJoinColumnTarget = isDocumentIdJoinColumnTarget; exports.resolveLinkRef = resolveLinkRef; //# sourceMappingURL=resolve-link-ref.js.map