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
1 line
5.5 KiB
Plaintext
1 line
5.5 KiB
Plaintext
{"version":3,"sources":["../../../src/transform/write/array.ts"],"sourcesContent":["import type { FlattenedArrayField } from 'payload'\n\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type {\n ArrayRowToInsert,\n BlockRowToInsert,\n NumberToDelete,\n RelationshipToDelete,\n TextToDelete,\n} from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrayTableName: string\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: unknown\n field: FlattenedArrayField\n locale?: string\n numbers: Record<string, unknown>[]\n numbersToDelete: NumberToDelete[]\n parentIsLocalized: boolean\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n textsToDelete: TextToDelete[]\n /**\n * Set to a locale code if this set of fields is traversed within a\n * localized array or block field\n */\n withinArrayOrBlockLocale?: string\n}\n\nexport const transformArray = ({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data,\n field,\n locale,\n numbers,\n numbersToDelete,\n parentIsLocalized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n}: Args) => {\n const newRows: ArrayRowToInsert[] = []\n\n const hasUUID = adapter.tables[arrayTableName]._uuid\n\n if (isArrayOfRows(data)) {\n data.forEach((arrayRow, i) => {\n const newRow: ArrayRowToInsert = {\n arrays: {},\n arraysToPush: {},\n locales: {},\n row: {\n _order: i + 1,\n },\n }\n\n // If we have declared a _uuid field on arrays,\n // that means the ID has to be unique,\n // and our ids within arrays are not unique.\n // So move the ID to a uuid field for storage\n // and allow the database to generate a serial id automatically\n if (hasUUID) {\n newRow.row._uuid = arrayRow.id\n delete arrayRow.id\n }\n\n if (locale) {\n newRow.locales[locale] = {\n _locale: locale,\n }\n }\n\n if (fieldShouldBeLocalized({ field, parentIsLocalized }) && locale) {\n newRow.row._locale = locale\n }\n\n if (withinArrayOrBlockLocale) {\n newRow.row._locale = withinArrayOrBlockLocale\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n arraysToPush: newRow.arraysToPush,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: arrayRow,\n fieldPrefix: '',\n fields: field.flattenedFields,\n insideArrayOrBlock: true,\n locales: newRow.locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName: arrayTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToAppend: [],\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["fieldShouldBeLocalized","isArrayOfRows","traverseFields","transformArray","adapter","arrayTableName","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","numbersToDelete","parentIsLocalized","path","relationships","relationshipsToDelete","selects","texts","textsToDelete","withinArrayOrBlockLocale","newRows","hasUUID","tables","_uuid","forEach","arrayRow","i","newRow","arrays","arraysToPush","locales","row","_order","id","_locale","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","localized","parentTableName","name","relationshipsToAppend","push"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iBAAgB;AAWvD,SAASC,aAAa,QAAQ,mCA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