@payloadcms/drizzle 3.54.0-internal.bdc84f3 → 3.55.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/transform/write/array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAIlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACb,MAAM,YAAY,CAAA;AAKnB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,mBAAmB,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAClC,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACxC,qBAAqB,EAAE,oBAAoB,EAAE,CAAA;IAC7C,OAAO,EAAE;QACP,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,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AAO,CAAC,EAAE,CAAA;IAChC,aAAa,EAAE,YAAY,EAAE,CAAA;IAC7B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,cAAc,+OAmBxB,IAAI,uBAwEN,CAAA"}
@@ -8,6 +8,7 @@ export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks,
8
8
  data.forEach((arrayRow, i)=>{
9
9
  const newRow = {
10
10
  arrays: {},
11
+ arraysToPush: {},
11
12
  locales: {},
12
13
  row: {
13
14
  _order: i + 1
@@ -39,6 +40,7 @@ export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks,
39
40
  traverseFields({
40
41
  adapter,
41
42
  arrays: newRow.arrays,
43
+ arraysToPush: newRow.arraysToPush,
42
44
  baseTableName,
43
45
  blocks,
44
46
  blocksToDelete,
@@ -1 +1 @@
1
- {"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 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 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 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","locales","row","_order","id","_locale","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","localized","parentTableName","name","push"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iBAAgB;AAWvD,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AA+BpD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,eAAe,EACfC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,aAAa,EACbC,wBAAwB,EACnB;IACL,MAAMC,UAA8B,EAAE;IAEtC,MAAMC,UAAUnB,QAAQoB,MAAM,CAACnB,eAAe,CAACoB,KAAK;IAEpD,IAAIxB,cAAcQ,OAAO;QACvBA,KAAKiB,OAAO,CAAC,CAACC,UAAUC;YACtB,MAAMC,SAA2B;gBAC/BC,QAAQ,CAAC;gBACTC,SAAS,CAAC;gBACVC,KAAK;oBACHC,QAAQL,IAAI;gBACd;YACF;YAEA,+CAA+C;YAC/C,sCAAsC;YACtC,4CAA4C;YAC5C,6CAA6C;YAC7C,+DAA+D;YAC/D,IAAIL,SAAS;gBACXM,OAAOG,GAAG,CAACP,KAAK,GAAGE,SAASO,EAAE;gBAC9B,OAAOP,SAASO,EAAE;YACpB;YAEA,IAAIvB,QAAQ;gBACVkB,OAAOE,OAAO,CAACpB,OAAO,GAAG;oBACvBwB,SAASxB;gBACX;YACF;YAEA,IAAIX,uBAAuB;gBAAEU;gBAAOI;YAAkB,MAAMH,QAAQ;gBAClEkB,OAAOG,GAAG,CAACG,OAAO,GAAGxB;YACvB;YAEA,IAAIU,0BAA0B;gBAC5BQ,OAAOG,GAAG,CAACG,OAAO,GAAGd;YACvB;YAEAnB,eAAe;gBACbE;gBACA0B,QAAQD,OAAOC,MAAM;gBACrBxB;gBACAC;gBACAC;gBACA4B,cAAc;gBACd3B,MAAMkB;gBACNU,aAAa;gBACbC,QAAQ5B,MAAM6B,eAAe;gBAC7BC,oBAAoB;gBACpBT,SAASF,OAAOE,OAAO;gBACvBnB;gBACAC;gBACAC,mBAAmBA,qBAAqBJ,MAAM+B,SAAS;gBACvDC,iBAAiBrC;gBACjBU,MAAM,GAAGA,QAAQ,KAAKL,MAAMiC,IAAI,CAAC,CAAC,EAAEf,EAAE,CAAC,CAAC;gBACxCZ;gBACAC;gBACAe,KAAKH,OAAOG,GAAG;gBACfd;gBACAC;gBACAC;gBACAC;YACF;YAEAC,QAAQsB,IAAI,CAACf;QACf;IACF;IAEA,OAAOP;AACT,EAAC"}
1
+ {"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 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","push"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iBAAgB;AAWvD,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AA+BpD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,eAAe,EACfC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,aAAa,EACbC,wBAAwB,EACnB;IACL,MAAMC,UAA8B,EAAE;IAEtC,MAAMC,UAAUnB,QAAQoB,MAAM,CAACnB,eAAe,CAACoB,KAAK;IAEpD,IAAIxB,cAAcQ,OAAO;QACvBA,KAAKiB,OAAO,CAAC,CAACC,UAAUC;YACtB,MAAMC,SAA2B;gBAC/BC,QAAQ,CAAC;gBACTC,cAAc,CAAC;gBACfC,SAAS,CAAC;gBACVC,KAAK;oBACHC,QAAQN,IAAI;gBACd;YACF;YAEA,+CAA+C;YAC/C,sCAAsC;YACtC,4CAA4C;YAC5C,6CAA6C;YAC7C,+DAA+D;YAC/D,IAAIL,SAAS;gBACXM,OAAOI,GAAG,CAACR,KAAK,GAAGE,SAASQ,EAAE;gBAC9B,OAAOR,SAASQ,EAAE;YACpB;YAEA,IAAIxB,QAAQ;gBACVkB,OAAOG,OAAO,CAACrB,OAAO,GAAG;oBACvByB,SAASzB;gBACX;YACF;YAEA,IAAIX,uBAAuB;gBAAEU;gBAAOI;YAAkB,MAAMH,QAAQ;gBAClEkB,OAAOI,GAAG,CAACG,OAAO,GAAGzB;YACvB;YAEA,IAAIU,0BAA0B;gBAC5BQ,OAAOI,GAAG,CAACG,OAAO,GAAGf;YACvB;YAEAnB,eAAe;gBACbE;gBACA0B,QAAQD,OAAOC,MAAM;gBACrBC,cAAcF,OAAOE,YAAY;gBACjCzB;gBACAC;gBACAC;gBACA6B,cAAc;gBACd5B,MAAMkB;gBACNW,aAAa;gBACbC,QAAQ7B,MAAM8B,eAAe;gBAC7BC,oBAAoB;gBACpBT,SAASH,OAAOG,OAAO;gBACvBpB;gBACAC;gBACAC,mBAAmBA,qBAAqBJ,MAAMgC,SAAS;gBACvDC,iBAAiBtC;gBACjBU,MAAM,GAAGA,QAAQ,KAAKL,MAAMkC,IAAI,CAAC,CAAC,EAAEhB,EAAE,CAAC,CAAC;gBACxCZ;gBACAC;gBACAgB,KAAKJ,OAAOI,GAAG;gBACff;gBACAC;gBACAC;gBACAC;YACF;YAEAC,QAAQuB,IAAI,CAAChB;QACf;IACF;IAEA,OAAOP;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/transform/write/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACb,MAAM,YAAY,CAAA;AAKnB,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,KAAK,EAAE,oBAAoB,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO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AAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAClC,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,iBAAiB,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACxC,qBAAqB,EAAE,oBAAoB,EAAE,CAAA;IAC7C,OAAO,EAAE;QACP,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAChC,aAAa,EAAE,YAAY,EAAE,CAAA;IAC7B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AACD,eAAO,MAAM,eAAe,+NAkBzB,IAAI,SAoFN,CAAA"}
@@ -14,6 +14,7 @@ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete
14
14
  const blockType = toSnakeCase(blockRow.blockType);
15
15
  const newRow = {
16
16
  arrays: {},
17
+ arraysToPush: {},
17
18
  locales: {},
18
19
  row: {
19
20
  _order: i + 1,
@@ -46,6 +47,7 @@ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete
46
47
  traverseFields({
47
48
  adapter,
48
49
  arrays: newRow.arrays,
50
+ arraysToPush: newRow.arraysToPush,
49
51
  baseTableName,
50
52
  blocks,
51
53
  blocksToDelete,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedBlocksField } from 'payload'\n\nimport { fieldShouldBeLocalized } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type {\n BlockRowToInsert,\n NumberToDelete,\n RelationshipToDelete,\n TextToDelete,\n} from './types.js'\n\nimport { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: FlattenedBlocksField\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}\nexport const transformBlocks = ({\n adapter,\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 data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') {\n return\n }\n\n const matchedBlock =\n adapter.payload.blocks[blockRow.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === blockRow.blockType,\n ) as FlattenedBlock | undefined)\n\n if (!matchedBlock) {\n return\n }\n const blockType = toSnakeCase(blockRow.blockType)\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (fieldShouldBeLocalized({ field, parentIsLocalized }) && locale) {\n newRow.row._locale = locale\n }\n if (withinArrayOrBlockLocale) {\n newRow.row._locale = withinArrayOrBlockLocale\n }\n\n const blockTableName = resolveBlockTableName(\n matchedBlock,\n adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`),\n )\n\n if (!blocks[blockTableName]) {\n blocks[blockTableName] = []\n }\n\n const hasUUID = adapter.tables[blockTableName]._uuid\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 = blockRow.id\n delete blockRow.id\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: blockRow,\n fieldPrefix: '',\n fields: matchedBlock.flattenedFields,\n insideArrayOrBlock: true,\n locales: newRow.locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n\n blocks[blockTableName].push(newRow)\n })\n}\n"],"names":["fieldShouldBeLocalized","toSnakeCase","resolveBlockTableName","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","numbersToDelete","parentIsLocalized","path","relationships","relationshipsToDelete","selects","texts","textsToDelete","withinArrayOrBlockLocale","forEach","blockRow","i","blockType","matchedBlock","payload","blockReferences","find","block","slug","newRow","arrays","locales","row","_order","_path","name","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","localized","parentTableName","push"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iBAAgB;AACvD,OAAOC,iBAAiB,gBAAe;AAUvC,SAASC,qBAAqB,QAAQ,sDAAqD;AAC3F,SAASC,cAAc,QAAQ,sBAAqB;AA6BpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,eAAe,EACfC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,a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D,OAAOC,MAAM;YACrB3B;YACAC;YACAC;YACAuC,cAAc;YACdtC,MAAMc;YACNyB,aAAa;YACbC,QAAQvB,aAAawB,eAAe;YACpCC,oBAAoB;YACpBjB,SAASF,OAAOE,OAAO;YACvBtB;YACAC;YACAC,mBAAmBA,qBAAqBJ,MAAM0C,SAAS;YACvDC,iBAAiBb;YACjBzB,MAAM,GAAGA,QAAQ,KAAKL,MAAM4B,IAAI,CAAC,CAAC,EAAEd,EAAE,CAAC,CAAC;YACxCR;YACAC;YACAkB,KAAKH,OAAOG,GAAG;YACfjB;YACAC;YACAC;YACAC;QACF;QAEAd,MAAM,CAACiC,eAAe,CAACc,IAAI,CAACtB;IAC9B;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedBlocksField } from 'payload'\n\nimport { fieldShouldBeLocalized } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type {\n BlockRowToInsert,\n NumberToDelete,\n RelationshipToDelete,\n TextToDelete,\n} from './types.js'\n\nimport { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n data: Record<string, unknown>[]\n field: FlattenedBlocksField\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}\nexport const transformBlocks = ({\n adapter,\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 data.forEach((blockRow, i) => {\n if (typeof blockRow.blockType !== 'string') {\n return\n }\n\n const matchedBlock =\n adapter.payload.blocks[blockRow.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === blockRow.blockType,\n ) as FlattenedBlock | undefined)\n\n if (!matchedBlock) {\n return\n }\n const blockType = toSnakeCase(blockRow.blockType)\n\n const newRow: BlockRowToInsert = {\n arrays: {},\n arraysToPush: {},\n locales: {},\n row: {\n _order: i + 1,\n _path: `${path}${field.name}`,\n },\n }\n\n if (fieldShouldBeLocalized({ field, parentIsLocalized }) && locale) {\n newRow.row._locale = locale\n }\n if (withinArrayOrBlockLocale) {\n newRow.row._locale = withinArrayOrBlockLocale\n }\n\n const blockTableName = resolveBlockTableName(\n matchedBlock,\n adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`),\n )\n\n if (!blocks[blockTableName]) {\n blocks[blockTableName] = []\n }\n\n const hasUUID = adapter.tables[blockTableName]._uuid\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 = blockRow.id\n delete blockRow.id\n }\n\n traverseFields({\n adapter,\n arrays: newRow.arrays,\n arraysToPush: newRow.arraysToPush,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: '',\n data: blockRow,\n fieldPrefix: '',\n fields: matchedBlock.flattenedFields,\n insideArrayOrBlock: true,\n locales: newRow.locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n\n blocks[blockTableName].push(newRow)\n })\n}\n"],"names":["fieldShouldBeLocalized","toSnakeCase","resolveBlockTableName","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","numbersToDelete","parentIsLocalized","path","relationships","relationshipsToDelete","selects","texts","textsToDelete","withinArrayOrBlockLocale","forEach","blockRow","i","blockType","matchedBlock","payload","blockReferences","find","block","slug","newRow","arrays","arraysToPush","locales","row","_order","_path","name","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","localized","parentTableName","push"],"mappings":"AAEA,SAASA,sBAAsB,QAAQ,iBAAgB;AACvD,OAAOC,iBAAiB,gBAAe;AAUvC,SAASC,qBAAqB,QAAQ,sDAAqD;AAC3F,SAASC,cAAc,QAAQ,sBAAqB;AA6BpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,eAAe,EACfC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,aAAa,EACbC,wBAAwB,EACnB;IACLZ,KAAKa,OAAO,CAAC,CAACC,UAAUC;QACtB,IAAI,OAAOD,SAASE,SAAS,KAAK,UAAU;YAC1C;QACF;QAEA,MAAMC,eACJrB,QAAQsB,OAAO,CAACpB,MAAM,CAACgB,SAASE,SAAS,CAAC,IACzC,AAACf,CAAAA,MAAMkB,eAAe,IAAIlB,MAAMH,MAAM,AAAD,EAAGsB,IAAI,CAC3C,CAACC,QAAU,OAAOA,UAAU,YAAYA,MAAMC,IAAI,KAAKR,SAASE,SAAS;QAG7E,IAAI,CAACC,cAAc;YACjB;QACF;QACA,MAAMD,YAAYxB,YAAYsB,SAASE,SAAS;QAEhD,MAAMO,SAA2B;YAC/BC,QAAQ,CAA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AAI,CAACvB;IAC9B;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transform/write/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAI7C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,iBAAiB,uFAQ3B,IAAI,KAAG,WA6CT,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transform/write/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAI7C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,iBAAiB,uFAQ3B,IAAI,KAAG,WA+CT,CAAA"}
@@ -3,6 +3,7 @@ export const transformForWrite = ({ adapter, data, enableAtomicWrites, fields, p
3
3
  // Split out the incoming data into rows to insert / delete
4
4
  const rowToInsert = {
5
5
  arrays: {},
6
+ arraysToPush: {},
6
7
  blocks: {},
7
8
  blocksToDelete: new Set(),
8
9
  locales: {},
@@ -20,6 +21,7 @@ export const transformForWrite = ({ adapter, data, enableAtomicWrites, fields, p
20
21
  traverseFields({
21
22
  adapter,
22
23
  arrays: rowToInsert.arrays,
24
+ arraysToPush: rowToInsert.arraysToPush,
23
25
  baseTableName: tableName,
24
26
  blocks: rowToInsert.blocks,
25
27
  blocksToDelete: rowToInsert.blocksToDelete,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/index.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { RowToInsert } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n data: Record<string, unknown>\n enableAtomicWrites?: boolean\n fields: FlattenedField[]\n parentIsLocalized?: boolean\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\n enableAtomicWrites,\n fields,\n parentIsLocalized,\n path = '',\n tableName,\n}: Args): RowToInsert => {\n // Split out the incoming data into rows to insert / delete\n const rowToInsert: RowToInsert = {\n arrays: {},\n blocks: {},\n blocksToDelete: new Set(),\n locales: {},\n numbers: [],\n numbersToDelete: [],\n relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\n textsToDelete: [],\n }\n\n // This function is responsible for building up the\n // above rowToInsert\n traverseFields({\n adapter,\n arrays: rowToInsert.arrays,\n baseTableName: tableName,\n blocks: rowToInsert.blocks,\n blocksToDelete: rowToInsert.blocksToDelete,\n columnPrefix: '',\n data,\n enableAtomicWrites,\n fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\n numbersToDelete: rowToInsert.numbersToDelete,\n parentIsLocalized,\n parentTableName: tableName,\n path,\n relationships: rowToInsert.relationships,\n relationshipsToDelete: rowToInsert.relationshipsToDelete,\n row: rowToInsert.row,\n selects: rowToInsert.selects,\n texts: rowToInsert.texts,\n textsToDelete: rowToInsert.textsToDelete,\n })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","enableAtomicWrites","fields","parentIsLocalized","path","tableName","rowToInsert","arrays","blocks","blocksToDelete","Set","locales","numbers","numbersToDelete","relationships","relationshipsToDelete","row","selects","texts","textsToDelete","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAYpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,kBAAkB,EAClBC,MAAM,EACNC,iBAAiB,EACjBC,OAAO,EAAE,EACTC,SAAS,EACJ;IACL,2DAA2D;IAC3D,MAAMC,cAA2B;QAC/BC,QAAQ,CAAC;QACTC,QAAQ,CAAC;QACTC,gBAAgB,IAAIC;QACpBC,SAAS,CAAC;QACVC,SAAS,EAAE;QACXC,iBAAiB,EAAE;QACnBC,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;QACTC,eAAe,EAAE;IACnB;IAEA,mDAAmD;IACnD,oBAAoB;IACpBtB,eAAe;QACbE;QACAQ,QAAQD,YAAYC,MAAM;QAC1Ba,eAAef;QACfG,QAAQF,YAAYE,MAAM;QAC1BC,gBAAgBH,YAAYG,cAAc;QAC1CY,cAAc;QACdrB;QACAC;QACAqB,aAAa;QACbpB;QACAS,SAASL,YAAYK,OAAO;QAC5BC,SAASN,YAAYM,OAAO;QAC5BC,iBAAiBP,YAAYO,eAAe;QAC5CV;QACAoB,iBAAiBlB;QACjBD;QACAU,eAAeR,YAAYQ,aAAa;QACxCC,uBAAuBT,YAAYS,qBAAqB;QACxDC,KAAKV,YAAYU,GAAG;QACpBC,SAASX,YAAYW,OAAO;QAC5BC,OAAOZ,YAAYY,KAAK;QACxBC,eAAeb,YAAYa,aAAa;IAC1C;IAEA,OAAOb;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/write/index.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { RowToInsert } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n data: Record<string, unknown>\n enableAtomicWrites?: boolean\n fields: FlattenedField[]\n parentIsLocalized?: boolean\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\n enableAtomicWrites,\n fields,\n parentIsLocalized,\n path = '',\n tableName,\n}: Args): RowToInsert => {\n // Split out the incoming data into rows to insert / delete\n const rowToInsert: RowToInsert = {\n arrays: {},\n arraysToPush: {},\n blocks: {},\n blocksToDelete: new Set(),\n locales: {},\n numbers: [],\n numbersToDelete: [],\n relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\n textsToDelete: [],\n }\n\n // This function is responsible for building up the\n // above rowToInsert\n traverseFields({\n adapter,\n arrays: rowToInsert.arrays,\n arraysToPush: rowToInsert.arraysToPush,\n baseTableName: tableName,\n blocks: rowToInsert.blocks,\n blocksToDelete: rowToInsert.blocksToDelete,\n columnPrefix: '',\n data,\n enableAtomicWrites,\n fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\n numbersToDelete: rowToInsert.numbersToDelete,\n parentIsLocalized,\n parentTableName: tableName,\n path,\n relationships: rowToInsert.relationships,\n relationshipsToDelete: rowToInsert.relationshipsToDelete,\n row: rowToInsert.row,\n selects: rowToInsert.selects,\n texts: rowToInsert.texts,\n textsToDelete: rowToInsert.textsToDelete,\n })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","enableAtomicWrites","fields","parentIsLocalized","path","tableName","rowToInsert","arrays","arraysToPush","blocks","blocksToDelete","Set","locales","numbers","numbersToDelete","relationships","relationshipsToDelete","row","selects","texts","textsToDelete","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAYpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,kBAAkB,EAClBC,MAAM,EACNC,iBAAiB,EACjBC,OAAO,EAAE,EACTC,SAAS,EACJ;IACL,2DAA2D;IAC3D,MAAMC,cAA2B;QAC/BC,QAAQ,CAAC;QACTC,cAAc,CAAC;QACfC,QAAQ,CAAC;QACTC,gBAAgB,IAAIC;QACpBC,SAAS,CAAC;QACVC,SAAS,EAAE;QACXC,iBAAiB,EAAE;QACnBC,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;QACTC,eAAe,EAAE;IACnB;IAEA,mDAAmD;IACnD,oBAAoB;IACpBvB,eAAe;QACbE;QACAQ,QAAQD,YAAYC,MAAM;QAC1BC,cAAcF,YAAYE,YAAY;QACtCa,eAAehB;QACfI,QAAQH,YAAYG,MAAM;QAC1BC,gBAAgBJ,YAAYI,cAAc;QAC1CY,cAAc;QACdtB;QACAC;QACAsB,aAAa;QACbrB;QACAU,SAASN,YAAYM,OAAO;QAC5BC,SAASP,YAAYO,OAAO;QAC5BC,iBAAiBR,YAAYQ,eAAe;QAC5CX;QACAqB,iBAAiBnB;QACjBD;QACAW,eAAeT,YAAYS,aAAa;QACxCC,uBAAuBV,YAAYU,qBAAqB;QACxDC,KAAKX,YAAYW,GAAG;QACpBC,SAASZ,YAAYY,OAAO;QAC5BC,OAAOb,YAAYa,KAAK;QACxBC,eAAed,YAAYc,aAAa;IAC1C;IAEA,OAAOd;AACT,EAAC"}
@@ -1,18 +1,22 @@
1
1
  import { type FlattenedField } from 'payload';
2
2
  import type { DrizzleAdapter } from '../../types.js';
3
- import type { ArrayRowToInsert, BlockRowToInsert, NumberToDelete, RelationshipToDelete, TextToDelete } from './types.js';
3
+ import type { NumberToDelete, RelationshipToDelete, RowToInsert, TextToDelete } from './types.js';
4
4
  type Args = {
5
5
  adapter: DrizzleAdapter;
6
- arrays: {
7
- [tableName: string]: ArrayRowToInsert[];
8
- };
6
+ /**
7
+ * This will delete the array table and then re-insert all the new array rows.
8
+ */
9
+ arrays: RowToInsert['arrays'];
10
+ /**
11
+ * Array rows to push to the existing array. This will simply create
12
+ * a new row in the array table.
13
+ */
14
+ arraysToPush: RowToInsert['arraysToPush'];
9
15
  /**
10
16
  * This is the name of the base table
11
17
  */
12
18
  baseTableName: string;
13
- blocks: {
14
- [blockType: string]: BlockRowToInsert[];
15
- };
19
+ blocks: RowToInsert['blocks'];
16
20
  blocksToDelete: Set<string>;
17
21
  /**
18
22
  * A snake-case field prefix, representing prior fields
@@ -58,6 +62,6 @@ type Args = {
58
62
  */
59
63
  withinArrayOrBlockLocale?: string;
60
64
  };
61
- export declare const traverseFields: ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, enableAtomicWrites, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock, locales, numbers, numbersToDelete, parentIsLocalized, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, textsToDelete, withinArrayOrBlockLocale, }: Args) => void;
65
+ export declare const traverseFields: ({ adapter, arrays, arraysToPush, baseTableName, blocks, blocksToDelete, columnPrefix, data, enableAtomicWrites, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock, locales, numbers, numbersToDelete, parentIsLocalized, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, textsToDelete, withinArrayOrBlockLocale, }: Args) => void;
62
66
  export {};
63
67
  //# sourceMappingURL=traverseFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/transform/write/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,EAA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AAA;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC3C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,EAAE;QACP,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC1C,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAClC,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACxC,qBAAqB,EAAE,oBAAoB,EAAE,CAAA;IAC7C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,EAAE;QACP,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAChC,aAAa,EAAE,YAAY,EAAE,CAAA;IAC7B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,cAAc,+WA4BxB,IAAI,SAghBN,CAAA"}
@@ -10,7 +10,7 @@ import { transformNumbers } from './numbers.js';
10
10
  import { transformRelationship } from './relationships.js';
11
11
  import { transformSelects } from './selects.js';
12
12
  import { transformTexts } from './texts.js';
13
- export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, enableAtomicWrites, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock = false, locales, numbers, numbersToDelete, parentIsLocalized, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, textsToDelete, withinArrayOrBlockLocale })=>{
13
+ export const traverseFields = ({ adapter, arrays, arraysToPush, baseTableName, blocks, blocksToDelete, columnPrefix, data, enableAtomicWrites, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock = false, locales, numbers, numbersToDelete, parentIsLocalized, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, textsToDelete, withinArrayOrBlockLocale })=>{
14
14
  if (row._uuid) {
15
15
  data._uuid = row._uuid;
16
16
  }
@@ -30,12 +30,21 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
30
30
  });
31
31
  if (field.type === 'array') {
32
32
  const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`);
33
- if (!arrays[arrayTableName]) {
34
- arrays[arrayTableName] = [];
35
- }
36
33
  if (isLocalized) {
37
- if (typeof data[field.name] === 'object' && data[field.name] !== null) {
38
- Object.entries(data[field.name]).forEach(([localeKey, localeData])=>{
34
+ let value = data[field.name];
35
+ let push = false;
36
+ if (typeof value === 'object' && '$push' in value) {
37
+ value = value.$push;
38
+ push = true;
39
+ }
40
+ if (typeof value === 'object' && value !== null) {
41
+ Object.entries(value).forEach(([localeKey, _localeData])=>{
42
+ let localeData = _localeData;
43
+ if (push && !Array.isArray(localeData)) {
44
+ localeData = [
45
+ localeData
46
+ ];
47
+ }
39
48
  if (Array.isArray(localeData)) {
40
49
  const newRows = transformArray({
41
50
  adapter,
@@ -57,18 +66,36 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
57
66
  textsToDelete,
58
67
  withinArrayOrBlockLocale: localeKey
59
68
  });
60
- arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);
69
+ if (push) {
70
+ if (!arraysToPush[arrayTableName]) {
71
+ arraysToPush[arrayTableName] = [];
72
+ }
73
+ arraysToPush[arrayTableName] = arraysToPush[arrayTableName].concat(newRows);
74
+ } else {
75
+ if (!arrays[arrayTableName]) {
76
+ arrays[arrayTableName] = [];
77
+ }
78
+ arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);
79
+ }
61
80
  }
62
81
  });
63
82
  }
64
83
  } else {
84
+ let value = data[field.name];
85
+ let push = false;
86
+ if (typeof value === 'object' && '$push' in value) {
87
+ value = Array.isArray(value.$push) ? value.$push : [
88
+ value.$push
89
+ ];
90
+ push = true;
91
+ }
65
92
  const newRows = transformArray({
66
93
  adapter,
67
94
  arrayTableName,
68
95
  baseTableName,
69
96
  blocks,
70
97
  blocksToDelete,
71
- data: data[field.name],
98
+ data: value,
72
99
  field,
73
100
  numbers,
74
101
  numbersToDelete,
@@ -81,7 +108,17 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
81
108
  textsToDelete,
82
109
  withinArrayOrBlockLocale
83
110
  });
84
- arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);
111
+ if (push) {
112
+ if (!arraysToPush[arrayTableName]) {
113
+ arraysToPush[arrayTableName] = [];
114
+ }
115
+ arraysToPush[arrayTableName] = arraysToPush[arrayTableName].concat(newRows);
116
+ } else {
117
+ if (!arrays[arrayTableName]) {
118
+ arrays[arrayTableName] = [];
119
+ }
120
+ arrays[arrayTableName] = arrays[arrayTableName].concat(newRows);
121
+ }
85
122
  }
86
123
  return;
87
124
  }
@@ -148,6 +185,7 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
148
185
  traverseFields({
149
186
  adapter,
150
187
  arrays,
188
+ arraysToPush,
151
189
  baseTableName,
152
190
  blocks,
153
191
  blocksToDelete,
@@ -181,6 +219,7 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
181
219
  traverseFields({
182
220
  adapter,
183
221
  arrays,
222
+ arraysToPush,
184
223
  baseTableName,
185
224
  blocks,
186
225
  blocksToDelete,
@@ -411,8 +450,8 @@ export const traverseFields = ({ adapter, arrays, baseTableName, blocks, blocksT
411
450
  valuesToTransform.forEach(({ localeKey, ref, value })=>{
412
451
  let formattedValue = value;
413
452
  if (field.type === 'date') {
414
- if (fieldName === 'updatedAt' && !formattedValue) {
415
- // let the db handle this
453
+ if (fieldName === 'updatedAt' && typeof formattedValue === 'undefined') {
454
+ // let the db handle this. If formattedValue is explicitly set to `null` we should not set it - this means we don't want to change the value of updatedAt.
416
455
  formattedValue = new Date().toISOString();
417
456
  } else {
418
457
  if (typeof value === 'number' && !Number.isNaN(value)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/traverseFields.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\nimport { APIError, type FlattenedField } from 'payload'\nimport { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\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 { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: {\n [blockType: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n enableAtomicWrites?: boolean\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: FlattenedField[]\n forcedLocale?: string\n /**\n * Tracks whether the current traversion context is from array or block.\n */\n insideArrayOrBlock?: boolean\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n numbersToDelete: NumberToDelete[]\n parentIsLocalized: boolean\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\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 traverseFields = ({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n enableAtomicWrites,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n insideArrayOrBlock = false,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n}: Args) => {\n if (row._uuid) {\n data._uuid = row._uuid\n }\n\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldIsVirtual(field)) {\n return\n }\n\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n\n const isLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n if (field.type === 'array') {\n const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n\n if (!arrays[arrayTableName]) {\n arrays[arrayTableName] = []\n }\n\n if (isLocalized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n })\n }\n } else {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: data[field.name],\n field,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n\n return\n }\n\n if (field.type === 'blocks' && !adapter.blocksAsJSON) {\n ;(field.blockReferences ?? field.blocks).forEach((block) => {\n const matchedBlock =\n typeof block === 'string'\n ? adapter.payload.config.blocks.find((each) => each.slug === block)\n : block\n\n blocksToDelete.add(\n resolveBlockTableName(\n matchedBlock,\n adapter.tableNameMap.get(`${baseTableName}_blocks_${toSnakeCase(matchedBlock.slug)}`),\n ),\n )\n })\n\n if (isLocalized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n }\n\n return\n }\n\n if (field.type === 'group' || field.type === 'tab') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (isLocalized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n // preserve array ID if there is\n localeData._uuid = data.id || data._uuid\n\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n enableAtomicWrites,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.flattenedFields,\n forcedLocale: localeKey,\n insideArrayOrBlock,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n })\n } else {\n // preserve array ID if there is\n const groupData = data[field.name] as Record<string, unknown>\n groupData._uuid = data.id || data._uuid\n\n traverseFields({\n adapter,\n arrays,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: groupData,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.flattenedFields,\n insideArrayOrBlock,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (\n isLocalized &&\n (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany))\n ) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n return\n } else if (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany)) {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n return\n } else {\n if (\n !isLocalized &&\n fieldData &&\n typeof fieldData === 'object' &&\n 'id' in fieldData &&\n fieldData?.id\n ) {\n fieldData = fieldData.id\n } else if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (typeof localeData === 'object') {\n if (localeData && 'id' in localeData && localeData?.id) {\n fieldData[localeKey] = localeData.id\n }\n } else {\n fieldData[localeKey] = localeData\n }\n })\n }\n }\n }\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n if (!localeData.length) {\n textsToDelete.push({ locale: localeKey, path: textPath })\n return\n }\n\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n if (!fieldData.length) {\n textsToDelete.push({ locale: withinArrayOrBlockLocale, path: textPath })\n return\n }\n\n transformTexts({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n if (!localeData.length) {\n numbersToDelete.push({ locale: localeKey, path: numberPath })\n return\n }\n\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n if (!fieldData.length) {\n numbersToDelete.push({ locale: withinArrayOrBlockLocale, path: numberPath })\n return\n }\n\n transformNumbers({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n if (!selects[selectTableName]) {\n selects[selectTableName] = []\n }\n\n if (isLocalized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: insideArrayOrBlock ? data._uuid || data.id : undefined,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: insideArrayOrBlock ? data._uuid || data.id : undefined,\n data: data[field.name],\n locale: withinArrayOrBlockLocale,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (isLocalized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) {\n locales[localeKey] = {}\n }\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) {\n locales[forcedLocale] = {}\n }\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n let formattedValue = value\n\n if (field.type === 'date') {\n if (fieldName === 'updatedAt' && !formattedValue) {\n // let the db handle this\n formattedValue = new Date().toISOString()\n } else {\n if (typeof value === 'number' && !Number.isNaN(value)) {\n formattedValue = new Date(value).toISOString()\n } else if (value instanceof Date) {\n formattedValue = value.toISOString()\n }\n }\n }\n\n if (typeof value !== 'undefined') {\n if (value && field.type === 'point' && adapter.name !== 'sqlite') {\n formattedValue = sql`ST_GeomFromGeoJSON(${JSON.stringify(value)})`\n }\n\n if (field.type === 'text' && value && typeof value !== 'string') {\n formattedValue = JSON.stringify(value)\n }\n\n if (\n field.type === 'number' &&\n value &&\n typeof value === 'object' &&\n '$inc' in value &&\n typeof value.$inc === 'number'\n ) {\n if (!enableAtomicWrites) {\n throw new APIError(\n 'The passed data must not contain any nested fields for atomic writes',\n )\n }\n\n formattedValue = sql.raw(`${columnName} + ${value.$inc}`)\n }\n }\n\n if (typeof formattedValue !== 'undefined') {\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n })\n}\n"],"names":["sql","APIError","fieldIsVirtual","fieldShouldBeLocalized","toSnakeCase","isArrayOfRows","resolveBlockTableName","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","baseTableName","blocks","blocksToDelete","columnPrefix","data","enableAtomicWrites","existingLocales","fieldPrefix","fields","forcedLocale","insideArrayOrBlock","locales","numbers","numbersToDelete","parentIsLocalized","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","textsToDelete","withinArrayOrBlockLocale","_uuid","forEach","field","columnName","fieldName","fieldData","name","isLocalized","type","arrayTableName","tableNameMap","get","Object","entries","localeKey","localeData","Array","isArray","newRows","locale","localized","concat","blocksAsJSON","blockReferences","block","matchedBlock","payload","config","find","each","slug","add","id","flattenedFields","groupData","relationshipPath","relationTo","hasMany","push","baseRow","length","textPath","numberPath","selectTableName","undefined","valuesToTransform","ref","value","formattedValue","Date","toISOString","Number","isNaN","JSON","stringify","$inc","raw"],"mappings":"AAAA,SAASA,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le-orm'\nimport { APIError, type FlattenedField } from 'payload'\nimport { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { NumberToDelete, RelationshipToDelete, RowToInsert, TextToDelete } from './types.js'\n\nimport { isArrayOfRows } from '../../utilities/isArrayOfRows.js'\nimport { resolveBlockTableName } from '../../utilities/validateExistingBlockIsIdentical.js'\nimport { transformArray } from './array.js'\nimport { transformBlocks } from './blocks.js'\nimport { transformNumbers } from './numbers.js'\nimport { transformRelationship } from './relationships.js'\nimport { transformSelects } from './selects.js'\nimport { transformTexts } from './texts.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n /**\n * This will delete the array table and then re-insert all the new array rows.\n */\n arrays: RowToInsert['arrays']\n /**\n * Array rows to push to the existing array. This will simply create\n * a new row in the array table.\n */\n arraysToPush: RowToInsert['arraysToPush']\n /**\n * This is the name of the base table\n */\n baseTableName: string\n blocks: RowToInsert['blocks']\n blocksToDelete: Set<string>\n /**\n * A snake-case field prefix, representing prior fields\n * Ex: my_group_my_named_tab_\n */\n columnPrefix: string\n data: Record<string, unknown>\n enableAtomicWrites?: boolean\n existingLocales?: Record<string, unknown>[]\n /**\n * A prefix that will retain camel-case formatting, representing prior fields\n * Ex: myGroup_myNamedTab_\n */\n fieldPrefix: string\n fields: FlattenedField[]\n forcedLocale?: string\n /**\n * Tracks whether the current traversion context is from array or block.\n */\n insideArrayOrBlock?: boolean\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n numbersToDelete: NumberToDelete[]\n parentIsLocalized: boolean\n /**\n * This is the name of the parent table\n */\n parentTableName: string\n path: string\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\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 traverseFields = ({\n adapter,\n arrays,\n arraysToPush,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix,\n data,\n enableAtomicWrites,\n existingLocales,\n fieldPrefix,\n fields,\n forcedLocale,\n insideArrayOrBlock = false,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized,\n parentTableName,\n path,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n}: Args) => {\n if (row._uuid) {\n data._uuid = row._uuid\n }\n\n fields.forEach((field) => {\n let columnName = ''\n let fieldName = ''\n let fieldData: unknown\n\n if (fieldIsVirtual(field)) {\n return\n }\n\n columnName = `${columnPrefix || ''}${toSnakeCase(field.name)}`\n fieldName = `${fieldPrefix || ''}${field.name}`\n fieldData = data[field.name]\n\n const isLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n if (field.type === 'array') {\n const arrayTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n\n if (isLocalized) {\n let value: {\n [locale: string]: unknown[]\n } = data[field.name] as any\n\n let push = false\n if (typeof value === 'object' && '$push' in value) {\n value = value.$push as any\n push = true\n }\n\n if (typeof value === 'object' && value !== null) {\n Object.entries(value).forEach(([localeKey, _localeData]) => {\n let localeData = _localeData\n if (push && !Array.isArray(localeData)) {\n localeData = [localeData]\n }\n\n if (Array.isArray(localeData)) {\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n\n if (push) {\n if (!arraysToPush[arrayTableName]) {\n arraysToPush[arrayTableName] = []\n }\n arraysToPush[arrayTableName] = arraysToPush[arrayTableName].concat(newRows)\n } else {\n if (!arrays[arrayTableName]) {\n arrays[arrayTableName] = []\n }\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n }\n })\n }\n } else {\n let value = data[field.name]\n let push = false\n if (typeof value === 'object' && '$push' in value) {\n value = Array.isArray(value.$push) ? value.$push : [value.$push]\n push = true\n }\n\n const newRows = transformArray({\n adapter,\n arrayTableName,\n baseTableName,\n blocks,\n blocksToDelete,\n data: value,\n field,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n\n if (push) {\n if (!arraysToPush[arrayTableName]) {\n arraysToPush[arrayTableName] = []\n }\n arraysToPush[arrayTableName] = arraysToPush[arrayTableName].concat(newRows)\n } else {\n if (!arrays[arrayTableName]) {\n arrays[arrayTableName] = []\n }\n arrays[arrayTableName] = arrays[arrayTableName].concat(newRows)\n }\n }\n\n return\n }\n\n if (field.type === 'blocks' && !adapter.blocksAsJSON) {\n ;(field.blockReferences ?? field.blocks).forEach((block) => {\n const matchedBlock =\n typeof block === 'string'\n ? adapter.payload.config.blocks.find((each) => each.slug === block)\n : block\n\n blocksToDelete.add(\n resolveBlockTableName(\n matchedBlock,\n adapter.tableNameMap.get(`${baseTableName}_blocks_${toSnakeCase(matchedBlock.slug)}`),\n ),\n )\n })\n\n if (isLocalized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: localeData,\n field,\n locale: localeKey,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n }\n })\n }\n } else if (isArrayOfRows(fieldData)) {\n transformBlocks({\n adapter,\n baseTableName,\n blocks,\n blocksToDelete,\n data: fieldData,\n field,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n }\n\n return\n }\n\n if (field.type === 'group' || field.type === 'tab') {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n if (isLocalized) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n // preserve array ID if there is\n localeData._uuid = data.id || data._uuid\n\n traverseFields({\n adapter,\n arrays,\n arraysToPush,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: localeData as Record<string, unknown>,\n enableAtomicWrites,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.flattenedFields,\n forcedLocale: localeKey,\n insideArrayOrBlock,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale: localeKey,\n })\n })\n } else {\n // preserve array ID if there is\n const groupData = data[field.name] as Record<string, unknown>\n groupData._uuid = data.id || data._uuid\n\n traverseFields({\n adapter,\n arrays,\n arraysToPush,\n baseTableName,\n blocks,\n blocksToDelete,\n columnPrefix: `${columnName}_`,\n data: groupData,\n existingLocales,\n fieldPrefix: `${fieldName}_`,\n fields: field.flattenedFields,\n insideArrayOrBlock,\n locales,\n numbers,\n numbersToDelete,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n path: `${path || ''}${field.name}.`,\n relationships,\n relationshipsToDelete,\n row,\n selects,\n texts,\n textsToDelete,\n withinArrayOrBlockLocale,\n })\n }\n }\n\n return\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n const relationshipPath = `${path || ''}${field.name}`\n\n if (\n isLocalized &&\n (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany))\n ) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (localeData === null) {\n relationshipsToDelete.push({\n locale: localeKey,\n path: relationshipPath,\n })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: localeKey,\n path: relationshipPath,\n },\n data: localeData,\n field,\n relationships,\n })\n })\n }\n return\n } else if (Array.isArray(field.relationTo) || ('hasMany' in field && field.hasMany)) {\n if (fieldData === null || (Array.isArray(fieldData) && fieldData.length === 0)) {\n relationshipsToDelete.push({ path: relationshipPath })\n return\n }\n\n transformRelationship({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: relationshipPath,\n },\n data: fieldData,\n field,\n relationships,\n })\n return\n } else {\n if (\n !isLocalized &&\n fieldData &&\n typeof fieldData === 'object' &&\n 'id' in fieldData &&\n fieldData?.id\n ) {\n fieldData = fieldData.id\n } else if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (typeof localeData === 'object') {\n if (localeData && 'id' in localeData && localeData?.id) {\n fieldData[localeKey] = localeData.id\n }\n } else {\n fieldData[localeKey] = localeData\n }\n })\n }\n }\n }\n }\n\n if (field.type === 'text' && field.hasMany) {\n const textPath = `${path || ''}${field.name}`\n\n if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n if (!localeData.length) {\n textsToDelete.push({ locale: localeKey, path: textPath })\n return\n }\n\n transformTexts({\n baseRow: {\n locale: localeKey,\n path: textPath,\n },\n data: localeData,\n texts,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n if (!fieldData.length) {\n textsToDelete.push({ locale: withinArrayOrBlockLocale, path: textPath })\n return\n }\n\n transformTexts({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: textPath,\n },\n data: fieldData,\n texts,\n })\n }\n\n return\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPath = `${path || ''}${field.name}`\n\n if (isLocalized) {\n if (typeof fieldData === 'object') {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n if (!localeData.length) {\n numbersToDelete.push({ locale: localeKey, path: numberPath })\n return\n }\n\n transformNumbers({\n baseRow: {\n locale: localeKey,\n path: numberPath,\n },\n data: localeData,\n numbers,\n })\n }\n })\n }\n } else if (Array.isArray(fieldData)) {\n if (!fieldData.length) {\n numbersToDelete.push({ locale: withinArrayOrBlockLocale, path: numberPath })\n return\n }\n\n transformNumbers({\n baseRow: {\n locale: withinArrayOrBlockLocale,\n path: numberPath,\n },\n data: fieldData,\n numbers,\n })\n }\n\n return\n }\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = adapter.tableNameMap.get(`${parentTableName}_${columnName}`)\n if (!selects[selectTableName]) {\n selects[selectTableName] = []\n }\n\n if (isLocalized) {\n if (typeof data[field.name] === 'object' && data[field.name] !== null) {\n Object.entries(data[field.name]).forEach(([localeKey, localeData]) => {\n if (Array.isArray(localeData)) {\n const newRows = transformSelects({\n id: insideArrayOrBlock ? data._uuid || data.id : undefined,\n data: localeData,\n locale: localeKey,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n })\n }\n } else if (Array.isArray(data[field.name])) {\n const newRows = transformSelects({\n id: insideArrayOrBlock ? data._uuid || data.id : undefined,\n data: data[field.name],\n locale: withinArrayOrBlockLocale,\n })\n\n selects[selectTableName] = selects[selectTableName].concat(newRows)\n }\n\n return\n }\n\n const valuesToTransform: { localeKey?: string; ref: unknown; value: unknown }[] = []\n\n if (isLocalized) {\n if (typeof fieldData === 'object' && fieldData !== null) {\n Object.entries(fieldData).forEach(([localeKey, localeData]) => {\n if (!locales[localeKey]) {\n locales[localeKey] = {}\n }\n\n valuesToTransform.push({\n localeKey,\n ref: locales,\n value: localeData,\n })\n })\n }\n } else {\n let ref = row\n\n if (forcedLocale) {\n if (!locales[forcedLocale]) {\n locales[forcedLocale] = {}\n }\n ref = locales[forcedLocale]\n }\n\n valuesToTransform.push({ ref, value: fieldData })\n }\n\n valuesToTransform.forEach(({ localeKey, ref, value }) => {\n let formattedValue = value\n\n if (field.type === 'date') {\n if (fieldName === 'updatedAt' && typeof formattedValue === 'undefined') {\n // let the db handle this. If formattedValue is explicitly set to `null` we should not set it - this means we don't want to change the value of updatedAt.\n formattedValue = new Date().toISOString()\n } else {\n if (typeof value === 'number' && !Number.isNaN(value)) {\n formattedValue = new Date(value).toISOString()\n } else if (value instanceof Date) {\n formattedValue = value.toISOString()\n }\n }\n }\n\n if (typeof value !== 'undefined') {\n if (value && field.type === 'point' && adapter.name !== 'sqlite') {\n formattedValue = sql`ST_GeomFromGeoJSON(${JSON.stringify(value)})`\n }\n\n if (field.type === 'text' && value && typeof value !== 'string') {\n formattedValue = JSON.stringify(value)\n }\n\n if (\n field.type === 'number' &&\n value &&\n typeof value === 'object' &&\n '$inc' in value &&\n typeof value.$inc === 'number'\n ) {\n if (!enableAtomicWrites) {\n throw new APIError(\n 'The passed data must not contain any nested fields for atomic writes',\n )\n }\n\n formattedValue = sql.raw(`${columnName} + ${value.$inc}`)\n }\n }\n\n if (typeof formattedValue !== 'undefined') {\n if (localeKey) {\n ref[localeKey][fieldName] = formattedValue\n } else {\n ref[fieldName] = formattedValue\n }\n }\n })\n })\n}\n"],"names":["sql","APIError","fieldIsVirtual","fieldShouldBeLocalized","toSnakeCase","isArrayOfRows","resolveBlockTableName","transformArray","transformBlocks","transformNumbers","transformRelationship","transformSelects","transformTexts","traverseFields","adapter","arrays","arraysToPush","baseTableName","blocks","blocksToDelete","columnPrefix","data","enableAtomicWrites","existingLocales","fieldPrefix","fields","forcedLocale","insideArrayOrBlock","locales","numbers","numbersToDelete","parentIsLocalized","parentTableName","path","relationships","relationshipsToDelete","row","selects","texts","textsToDelete","withinArrayOrBlockLocale","_uuid","forEach","field","columnName","fieldName","fieldData","name","isLocalized","type","arrayTableName","tableNameMap","get","value","push","$push","Object","entries","localeKey","_localeData","localeData","Array","isArray","newRows","locale","localized","concat","blocksAsJSON","blockReferences","block","matchedBlock","payload","config","find","each","slug","add","id","flattenedFields","groupData","relationshipPath","relationTo","hasMany","baseRow","length","textPath","numberPath","selectTableName","undefined","valuesToTransform","ref","formattedValue","Date","toISOString","Number","isNaN","JSON","stringify","$inc","raw"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,QAAQ,QAA6B,UAAS;AACvD,SAASC,cAAc,EAAEC,sBAAsB,QAAQ,iBAAgB;AACvE,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,qBAAqB,QAAQ,sDAAqD;AAC3F,SAASC,cAAc,QAAQ,aAAY;AAC3C,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,qBAAqB,QAAQ,qBAAoB;AAC1D,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,cAAc,QAAQ,aAAY;AAgE3C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,MAAM,EACNC,YAAY,EACZC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,YAAY,EACZC,IAAI,EACJC,kBAAkB,EAClBC,eAAe,EACfC,WAAW,EACXC,MAAM,EACNC,YAAY,EACZC,qBAAqB,KAAK,EAC1BC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,iBAAiB,EACjBC,eAAe,EACfC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,GAAG,EACHC,OAAO,EACPC,KAAK,EACLC,aAAa,EACbC,wBAAwB,EACnB;IACL,IAAIJ,IAAIK,KAAK,EAAE;QACbpB,KAAKoB,KAAK,GAAGL,IAAIK,KAAK;IACxB;IAEAhB,OAAOiB,OAAO,CAAC,CAACC;QACd,IAAIC,aAAa;QACjB,IAAIC,YAAY;QAChB,IAAIC;QAEJ,IAAI5C,eAAeyC,QAAQ;YACzB;QACF;QAEAC,aAAa,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J,cAAc,eAAe,OAAO8C,mBAAmB,aAAa;oBACtE,0JAA0J;oBAC1JA,iBAAiB,IAAIC,OAAOC,WAAW;gBACzC,OAAO;oBACL,IAAI,OAAOxC,UAAU,YAAY,CAACyC,OAAOC,KAAK,CAAC1C,QAAQ;wBACrDsC,iBAAiB,IAAIC,KAAKvC,OAAOwC,WAAW;oBAC9C,OAAO,IAAIxC,iBAAiBuC,MAAM;wBAChCD,iBAAiBtC,MAAMwC,WAAW;oBACpC;gBACF;YACF;YAEA,IAAI,OAAOxC,UAAU,aAAa;gBAChC,IAAIA,SAASV,MAAMM,IAAI,KAAK,WAAWnC,QAAQiC,IAAI,KAAK,UAAU;oBAChE4C,iBAAiB3F,GAAG,CAAC,mBAAmB,EAAEgG,KAAKC,SAAS,CAAC5C,OAAO,CAAC,CAAC;gBACpE;gBAEA,IAAIV,MAAMM,IAAI,KAAK,UAAUI,SAAS,OAAOA,UAAU,UAAU;oBAC/DsC,iBAAiBK,KAAKC,SAAS,CAAC5C;gBAClC;gBAEA,IACEV,MAAMM,IAAI,KAAK,YACfI,SACA,OAAOA,UAAU,YACjB,UAAUA,SACV,OAAOA,MAAM6C,IAAI,KAAK,UACtB;oBACA,IAAI,CAAC5E,oBAAoB;wBACvB,MAAM,IAAIrB,SACR;oBAEJ;oBAEA0F,iBAAiB3F,IAAImG,GAAG,CAAC,GAAGvD,WAAW,GAAG,EAAES,MAAM6C,IAAI,EAAE;gBAC1D;YACF;YAEA,IAAI,OAAOP,mBAAmB,aAAa;gBACzC,IAAIjC,WAAW;oBACbgC,GAAG,CAAChC,UAAU,CAACb,UAAU,GAAG8C;gBAC9B,OAAO;oBACLD,GAAG,CAAC7C,UAAU,GAAG8C;gBACnB;YACF;QACF;IACF;AACF,EAAC"}
@@ -2,6 +2,9 @@ export type ArrayRowToInsert = {
2
2
  arrays: {
3
3
  [tableName: string]: ArrayRowToInsert[];
4
4
  };
5
+ arraysToPush: {
6
+ [tableName: string]: ArrayRowToInsert[];
7
+ };
5
8
  locales: {
6
9
  [locale: string]: Record<string, unknown>;
7
10
  };
@@ -11,6 +14,9 @@ export type BlockRowToInsert = {
11
14
  arrays: {
12
15
  [tableName: string]: ArrayRowToInsert[];
13
16
  };
17
+ arraysToPush: {
18
+ [tableName: string]: ArrayRowToInsert[];
19
+ };
14
20
  locales: {
15
21
  [locale: string]: Record<string, unknown>;
16
22
  };
@@ -32,6 +38,9 @@ export type RowToInsert = {
32
38
  arrays: {
33
39
  [tableName: string]: ArrayRowToInsert[];
34
40
  };
41
+ arraysToPush: {
42
+ [tableName: string]: ArrayRowToInsert[];
43
+ };
35
44
  blocks: {
36
45
  [tableName: string]: BlockRowToInsert[];
37
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/transform/write/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,OAAO,EAAE;QACP,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC1C,CAAA;IACD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,OAAO,EAAE;QACP,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC1C,CAAA;IACD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM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G,gBAAgB,EAAE,CAAA;KACxC,CAAA;IACD,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,OAAO,EAAE;QACP,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC1C,CAAA;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAClC,eAAe,EAAE,cAAc,EAAE,CAAA;IACjC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACxC,qBAAqB,EAAE,oBAAoB,EAAE,CAAA;IAC7C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,EAAE;QACP,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAC/C,CAAA;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAChC,aAAa,EAAE,YAAY,EAAE,CAAA;CAC9B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/types.ts"],"sourcesContent":["export type ArrayRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type BlockRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type RelationshipToDelete = {\n locale?: string\n path: string\n}\n\nexport type TextToDelete = {\n locale?: string\n path: string\n}\n\nexport type NumberToDelete = {\n locale?: string\n path: string\n}\n\nexport type RowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n blocks: {\n [tableName: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n numbersToDelete: NumberToDelete[]\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n textsToDelete: TextToDelete[]\n}\n"],"names":[],"mappings":"AAmCA,WAqBC"}
1
+ {"version":3,"sources":["../../../src/transform/write/types.ts"],"sourcesContent":["export type ArrayRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n arraysToPush: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type BlockRowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n arraysToPush: {\n [tableName: string]: ArrayRowToInsert[]\n }\n locales: {\n [locale: string]: Record<string, unknown>\n }\n row: Record<string, unknown>\n}\n\nexport type RelationshipToDelete = {\n locale?: string\n path: string\n}\n\nexport type TextToDelete = {\n locale?: string\n path: string\n}\n\nexport type NumberToDelete = {\n locale?: string\n path: string\n}\n\nexport type RowToInsert = {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }\n arraysToPush: {\n [tableName: string]: ArrayRowToInsert[]\n }\n blocks: {\n [tableName: string]: BlockRowToInsert[]\n }\n blocksToDelete: Set<string>\n locales: {\n [locale: string]: Record<string, unknown>\n }\n numbers: Record<string, unknown>[]\n numbersToDelete: NumberToDelete[]\n relationships: Record<string, unknown>[]\n relationshipsToDelete: RelationshipToDelete[]\n row: Record<string, unknown>\n selects: {\n [tableName: string]: Record<string, unknown>[]\n }\n texts: Record<string, unknown>[]\n textsToDelete: TextToDelete[]\n}\n"],"names":[],"mappings":"AAyCA,WAwBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAWhD,eAAO,MAAM,UAAU,EAAE,UAkFxB,CAAA"}
1
+ {"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAWhD,eAAO,MAAM,UAAU,EAAE,UAsFxB,CAAA"}
@@ -4,7 +4,7 @@ import { upsertRow } from './upsertRow/index.js';
4
4
  import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js';
5
5
  import { getTransaction } from './utilities/getTransaction.js';
6
6
  export const updateJobs = async function updateMany({ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
7
- if (!data?.log?.length) {
7
+ if (!data?.log?.length && !(data.log && typeof data.log === 'object' && '$push' in data.log)) {
8
8
  delete data.log;
9
9
  }
10
10
  const whereToUse = id ? {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (!(data?.log as object[])?.length) {\n delete data.log\n }\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const db = await getTransaction(this, req)\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const result = await upsertRow({\n id,\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const job of jobs.docs) {\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getTransaction","updateJobs","updateMany","id","data","limit","limitArg","req","returning","sort","sortArg","where","whereArg","log","length","whereToUse","equals","db","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","result","adapter","ignoreResult","operation","jobs","collectionSlug","pagination","docs","results","job","updateData","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AACxF,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeC,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAMC,OAAO,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,IAAI,CAAER,MAAMS,KAAkBC,QAAQ;QACp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B,MAAMqC;YACNxB;YACAY,QAAQX,WAAWY,eAAe;YAClCG,cAAczB,cAAc;YAC5B0B,WAAW;YACX3B;YACAe;QACF;QAEAiB,QAAQG,IAAI,CAACX;IACf;IAEA,IAAIvB,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAO+B;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const db = await getTransaction(this, req)\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const result = await upsertRow({\n id,\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const job of jobs.docs) {\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getTransaction","updateJobs","updateMany","id","data","limit","limitArg","req","returning","sort","sortArg","where","whereArg","log","length","whereToUse","equals","db","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","result","adapter","ignoreResult","operation","jobs","collectionSlug","pagination","docs","results","job","updateData","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AACxF,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeC,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAMC,OAAO,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,IACE,CAAER,MAAMS,KAAkBC,UAC1B,CAAEV,CAAAA,KAAKS,GAAG,IAAI,OAAOT,KAAKS,GAAG,KAAK,YAAY,WAAWT,KAAKS,GAAG,AAAD,GAChE;QACA,OAAOT,KAAKS,GAAG;IACjB;IAEA,MAAME,aAAoBZ,KAAK;QAAEA,IAAI;YAAEa,QAAQb;QAAG;IAAE,IAAIS;IACxD,MAAMP,QAAQF,KAAK,IAAIG;IAEvB,MAAMW,KAAK,MAAMjB,eAAe,IAAI,EAAEO;IACtC,MAAMW,aAAa,IAAI,CAACC,OAAO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{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAUtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,yIAkB3E,IAAI,KAAG,OAAO,CAAC,CAAC,CAqiBlB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAUtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,yIAkB3E,IAAI,KAAG,OAAO,CAAC,CAAC,CAglBlB,CAAA"}
@@ -27,16 +27,43 @@ joinQuery: _joinQuery, operation, path = '', req, select, tableName, upsertTarge
27
27
  data,
28
28
  fields
29
29
  })) {
30
- const { row } = transformForWrite({
30
+ const transformedForWrite = transformForWrite({
31
31
  adapter,
32
32
  data,
33
33
  enableAtomicWrites: true,
34
34
  fields,
35
35
  tableName
36
36
  });
37
+ const { row } = transformedForWrite;
38
+ const { arraysToPush } = transformedForWrite;
37
39
  const drizzle = db;
40
+ // First, handle $push arrays
41
+ if (arraysToPush && Object.keys(arraysToPush)?.length) {
42
+ await insertArrays({
43
+ adapter,
44
+ arrays: [
45
+ arraysToPush
46
+ ],
47
+ db,
48
+ parentRows: [
49
+ insertedRow
50
+ ],
51
+ uuidMap: {}
52
+ });
53
+ }
54
+ // If row.updatedAt is not set, delete it to avoid triggering hasDataToUpdate. `updatedAt` may be explicitly set to null to
55
+ // disable triggering hasDataToUpdate.
56
+ if (typeof row.updatedAt === 'undefined' || row.updatedAt === null) {
57
+ delete row.updatedAt;
58
+ }
59
+ const hasDataToUpdate = row && Object.keys(row)?.length;
60
+ // Then, handle regular row update
38
61
  if (ignoreResult) {
39
- await drizzle.update(adapter.tables[tableName]).set(row).where(eq(adapter.tables[tableName].id, id));
62
+ if (hasDataToUpdate) {
63
+ // Only update row if there is something to update.
64
+ // Example: if the data only consists of a single $push, calling insertArrays is enough - we don't need to update the row.
65
+ await drizzle.update(adapter.tables[tableName]).set(row).where(eq(adapter.tables[tableName].id, id));
66
+ }
40
67
  return ignoreResult === 'idOnly' ? {
41
68
  id
42
69
  } : null;
@@ -51,6 +78,19 @@ joinQuery: _joinQuery, operation, path = '', req, select, tableName, upsertTarge
51
78
  });
52
79
  const findManyKeysLength = Object.keys(findManyArgs).length;
53
80
  const hasOnlyColumns = Object.keys(findManyArgs.columns || {}).length > 0;
81
+ if (!hasDataToUpdate) {
82
+ // Nothing to update => just fetch current row and return
83
+ findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id);
84
+ const doc = await db.query[tableName].findFirst(findManyArgs);
85
+ return transform({
86
+ adapter,
87
+ config: adapter.payload.config,
88
+ data: doc,
89
+ fields,
90
+ joinQuery: false,
91
+ tableName
92
+ });
93
+ }
54
94
  if (findManyKeysLength === 0 || hasOnlyColumns) {
55
95
  // Optimization - No need for joins => can simply use returning(). This is optimal for very simple collections
56
96
  // without complex fields that live in separate tables like blocks, arrays, relationships, etc.
@@ -366,10 +406,12 @@ joinQuery: _joinQuery, operation, path = '', req, select, tableName, upsertTarge
366
406
  await insertArrays({
367
407
  adapter,
368
408
  arrays: [
369
- rowToInsert.arrays
409
+ rowToInsert.arrays,
410
+ rowToInsert.arraysToPush
370
411
  ],
371
412
  db,
372
413
  parentRows: [
414
+ insertedRow,
373
415
  insertedRow
374
416
  ],
375
417
  uuidMap: arraysBlocksUUIDMap
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/index.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { SelectedFields } from 'drizzle-orm/sqlite-core'\nimport type { TypeWithID } from 'payload'\n\nimport { eq } from 'drizzle-orm'\nimport { ValidationError } from 'payload'\n\nimport type { BlockRowToInsert } from '../transform/write/types.js'\nimport type { Args } from './types.js'\n\nimport { buildFindManyArgs } from '../find/buildFindManyArgs.js'\nimport { transform } from '../transform/read/index.js'\nimport { transformForWrite } from '../transform/write/index.js'\nimport { deleteExistingArrayRows } from './deleteExistingArrayRows.js'\nimport { deleteExistingRowsByPath } from './deleteExistingRowsByPath.js'\nimport { insertArrays } from './insertArrays.js'\nimport { shouldUseOptimizedUpsertRow } from './shouldUseOptimizedUpsertRow.js'\n\n/**\n * If `id` is provided, it will update the row with that ID.\n * If `where` is provided, it will update the row that matches the `where`\n * If neither `id` nor `where` is provided, it will create a new row.\n *\n * adapter function replaces the entire row and does not support partial updates.\n */\nexport const upsertRow = async <T extends Record<string, unknown> | TypeWithID>({\n id,\n adapter,\n data,\n db,\n fields,\n ignoreResult,\n // TODO:\n // When we support joins for write operations (create/update) - pass collectionSlug to the buildFindManyArgs\n // Make a new argument in upsertRow.ts and pass the slug from every operation.\n joinQuery: _joinQuery,\n operation,\n path = '',\n req,\n select,\n tableName,\n upsertTarget,\n where,\n}: Args): Promise<T> => {\n if (operation === 'create' && !data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n let insertedRow: Record<string, unknown> = { id }\n if (id && shouldUseOptimizedUpsertRow({ data, fields })) {\n const { row } = transformForWrite({\n adapter,\n data,\n enableAtomicWrites: true,\n fields,\n tableName,\n })\n\n const drizzle = db as LibSQLDatabase\n\n if (ignoreResult) {\n await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n return ignoreResult === 'idOnly' ? ({ id } as T) : null\n }\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n joinQuery: false,\n select,\n tableName,\n })\n\n const findManyKeysLength = Object.keys(findManyArgs).length\n const hasOnlyColumns = Object.keys(findManyArgs.columns || {}).length > 0\n\n if (findManyKeysLength === 0 || hasOnlyColumns) {\n // Optimization - No need for joins => can simply use returning(). This is optimal for very simple collections\n // without complex fields that live in separate tables like blocks, arrays, relationships, etc.\n\n const selectedFields: SelectedFields = {}\n if (hasOnlyColumns) {\n for (const [column, enabled] of Object.entries(findManyArgs.columns)) {\n if (enabled) {\n selectedFields[column] = adapter.tables[tableName][column]\n }\n }\n }\n\n const docs = await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n .returning(Object.keys(selectedFields).length ? selectedFields : undefined)\n\n return transform<T>({\n adapter,\n config: adapter.payload.config,\n data: docs[0],\n fields,\n joinQuery: false,\n tableName,\n })\n }\n\n // DB Update that needs the result, potentially with joins => need to update first, then find. returning() does not work with joins.\n\n await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n return transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n joinQuery: false,\n tableName,\n })\n }\n // Split out the incoming data into the corresponding:\n // base row, locales, relationships, blocks, and arrays\n const rowToInsert = transformForWrite({\n adapter,\n data,\n enableAtomicWrites: false,\n fields,\n path,\n tableName,\n })\n\n // First, we insert the main row\n try {\n if (operation === 'update') {\n const target = upsertTarget || adapter.tables[tableName].id\n\n if (id) {\n rowToInsert.row.id = id\n ;[insertedRow] = await adapter.insert({\n db,\n onConflictDoUpdate: { set: rowToInsert.row, target },\n tableName,\n values: rowToInsert.row,\n })\n } else {\n ;[insertedRow] = await adapter.insert({\n db,\n onConflictDoUpdate: { set: rowToInsert.row, target, where },\n tableName,\n values: rowToInsert.row,\n })\n }\n } else {\n if (adapter.allowIDOnCreate && data.id) {\n rowToInsert.row.id = data.id\n }\n ;[insertedRow] = await adapter.insert({\n db,\n tableName,\n values: rowToInsert.row,\n })\n }\n\n const localesToInsert: Record<string, unknown>[] = []\n const relationsToInsert: Record<string, unknown>[] = []\n const textsToInsert: Record<string, unknown>[] = []\n const numbersToInsert: Record<string, unknown>[] = []\n const blocksToInsert: { [blockType: string]: BlockRowToInsert[] } = {}\n const selectsToInsert: { [selectTableName: string]: Record<string, unknown>[] } = {}\n\n // If there are locale rows with data, add the parent and locale to each\n if (Object.keys(rowToInsert.locales).length > 0) {\n Object.entries(rowToInsert.locales).forEach(([locale, localeRow]) => {\n localeRow._parentID = insertedRow.id\n localeRow._locale = locale\n localesToInsert.push(localeRow)\n })\n }\n\n // If there are relationships, add parent to each\n if (rowToInsert.relationships.length > 0) {\n rowToInsert.relationships.forEach((relation) => {\n relation.parent = insertedRow.id\n relationsToInsert.push(relation)\n })\n }\n\n // If there are texts, add parent to each\n if (rowToInsert.texts.length > 0) {\n rowToInsert.texts.forEach((textRow) => {\n textRow.parent = insertedRow.id\n textsToInsert.push(textRow)\n })\n }\n\n // If there are numbers, add parent to each\n if (rowToInsert.numbers.length > 0) {\n rowToInsert.numbers.forEach((numberRow) => {\n numberRow.parent = insertedRow.id\n numbersToInsert.push(numberRow)\n })\n }\n\n // If there are selects, add parent to each, and then\n // store by table name and rows\n if (Object.keys(rowToInsert.selects).length > 0) {\n Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows]) => {\n selectsToInsert[selectTableName] = []\n\n selectRows.forEach((row) => {\n if (typeof row.parent === 'undefined') {\n row.parent = insertedRow.id\n }\n\n selectsToInsert[selectTableName].push(row)\n })\n })\n }\n\n // If there are blocks, add parent to each, and then\n // store by table name and rows\n Object.keys(rowToInsert.blocks).forEach((tableName) => {\n rowToInsert.blocks[tableName].forEach((blockRow) => {\n blockRow.row._parentID = insertedRow.id\n if (!blocksToInsert[tableName]) {\n blocksToInsert[tableName] = []\n }\n if (blockRow.row.uuid) {\n delete blockRow.row.uuid\n }\n blocksToInsert[tableName].push(blockRow)\n })\n })\n\n // //////////////////////////////////\n // INSERT LOCALES\n // //////////////////////////////////\n\n if (localesToInsert.length > 0) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n const localeTable = adapter.tables[`${tableName}${adapter.localesSuffix}`]\n\n if (operation === 'update') {\n await adapter.deleteWhere({\n db,\n tableName: localeTableName,\n where: eq(localeTable._parentID, insertedRow.id),\n })\n }\n\n await adapter.insert({\n db,\n tableName: localeTableName,\n values: localesToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT RELATIONSHIPS\n // //////////////////////////////////\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...relationsToInsert, ...rowToInsert.relationshipsToDelete],\n tableName: relationshipsTableName,\n })\n }\n\n if (relationsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: relationshipsTableName,\n values: relationsToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT hasMany TEXTS\n // //////////////////////////////////\n\n const textsTableName = `${tableName}_texts`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...textsToInsert, ...rowToInsert.textsToDelete],\n tableName: textsTableName,\n })\n }\n\n if (textsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: textsTableName,\n values: textsToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT hasMany NUMBERS\n // //////////////////////////////////\n\n const numbersTableName = `${tableName}_numbers`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...numbersToInsert, ...rowToInsert.numbersToDelete],\n tableName: numbersTableName,\n })\n }\n\n if (numbersToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: numbersTableName,\n values: numbersToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT BLOCKS\n // //////////////////////////////////\n\n const insertedBlockRows: Record<string, Record<string, unknown>[]> = {}\n\n if (operation === 'update') {\n for (const tableName of rowToInsert.blocksToDelete) {\n const blockTable = adapter.tables[tableName]\n await adapter.deleteWhere({\n db,\n tableName,\n where: eq(blockTable._parentID, insertedRow.id),\n })\n }\n }\n\n // When versions are enabled, adapter is used to track mapping between blocks/arrays ObjectID to their numeric generated representation, then we use it for nested to arrays/blocks select hasMany in versions.\n const arraysBlocksUUIDMap: Record<string, number | string> = {}\n\n for (const [tableName, blockRows] of Object.entries(blocksToInsert)) {\n insertedBlockRows[tableName] = await adapter.insert({\n db,\n tableName,\n values: blockRows.map(({ row }) => row),\n })\n\n insertedBlockRows[tableName].forEach((row, i) => {\n blockRows[i].row = row\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n arraysBlocksUUIDMap[row._uuid] = row.id\n }\n })\n\n const blockLocaleIndexMap: number[] = []\n\n const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i) => {\n if (Object.entries(blockRow.locales).length > 0) {\n Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData]) => {\n if (Object.keys(blockLocaleData).length > 0) {\n blockLocaleData._parentID = blockRow.row.id\n blockLocaleData._locale = blockLocale\n acc.push(blockLocaleData)\n blockLocaleIndexMap.push(i)\n }\n })\n }\n\n return acc\n }, [])\n\n if (blockLocaleRowsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: blockLocaleRowsToInsert,\n })\n }\n\n await insertArrays({\n adapter,\n arrays: blockRows.map(({ arrays }) => arrays),\n db,\n parentRows: insertedBlockRows[tableName],\n uuidMap: arraysBlocksUUIDMap,\n })\n }\n\n // //////////////////////////////////\n // INSERT ARRAYS RECURSIVELY\n // //////////////////////////////////\n\n if (operation === 'update') {\n for (const arrayTableName of Object.keys(rowToInsert.arrays)) {\n await deleteExistingArrayRows({\n adapter,\n db,\n parentID: insertedRow.id,\n tableName: arrayTableName,\n })\n }\n }\n\n await insertArrays({\n adapter,\n arrays: [rowToInsert.arrays],\n db,\n parentRows: [insertedRow],\n uuidMap: arraysBlocksUUIDMap,\n })\n\n // //////////////////////////////////\n // INSERT hasMany SELECTS\n // //////////////////////////////////\n\n for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)) {\n const selectTable = adapter.tables[selectTableName]\n if (operation === 'update') {\n await adapter.deleteWhere({\n db,\n tableName: selectTableName,\n where: eq(selectTable.parent, insertedRow.id),\n })\n }\n\n if (Object.keys(arraysBlocksUUIDMap).length > 0) {\n tableRows.forEach((row: any) => {\n if (row.parent in arraysBlocksUUIDMap) {\n row.parent = arraysBlocksUUIDMap[row.parent]\n }\n })\n }\n\n if (tableRows.length) {\n await adapter.insert({\n db,\n tableName: selectTableName,\n values: tableRows,\n })\n }\n }\n\n // //////////////////////////////////\n // Error Handling\n // //////////////////////////////////\n } catch (caughtError) {\n // Unique constraint violation error\n // '23505' is the code for PostgreSQL, and 'SQLITE_CONSTRAINT_UNIQUE' is for SQLite\n\n let error = caughtError\n if (typeof caughtError === 'object' && 'cause' in caughtError) {\n error = caughtError.cause\n }\n\n if (error.code === '23505' || error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n let fieldName: null | string = null\n // We need to try and find the right constraint for the field but if we can't we fallback to a generic message\n if (error.code === '23505') {\n // For PostgreSQL, we can try to extract the field name from the error constraint\n if (adapter.fieldConstraints?.[tableName]?.[error.constraint]) {\n fieldName = adapter.fieldConstraints[tableName]?.[error.constraint]\n } else {\n const replacement = `${tableName}_`\n\n if (error.constraint.includes(replacement)) {\n const replacedConstraint = error.constraint.replace(replacement, '')\n\n if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {\n fieldName = adapter.fieldConstraints[tableName][replacedConstraint]\n }\n }\n }\n\n if (!fieldName) {\n // Last case scenario we extract the key and value from the detail on the error\n const detail = error.detail\n const regex = /Key \\(([^)]+)\\)=\\(([^)]+)\\)/\n const match: string[] = detail.match(regex)\n\n if (match && match[1]) {\n const key = match[1]\n\n fieldName = key\n }\n }\n } else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n /**\n * For SQLite, we can try to extract the field name from the error message\n * The message typically looks like:\n * \"UNIQUE constraint failed: table_name.field_name\"\n */\n const regex = /UNIQUE constraint failed: ([^.]+)\\.([^.]+)/\n const match: string[] = error.message.match(regex)\n\n if (match && match[2]) {\n if (adapter.fieldConstraints[tableName]) {\n fieldName = adapter.fieldConstraints[tableName][`${match[2]}_idx`]\n }\n\n if (!fieldName) {\n fieldName = match[2]\n }\n }\n }\n\n throw new ValidationError(\n {\n id,\n errors: [\n {\n message: req?.t ? req.t('error:valueMustBeUnique') : 'Value must be unique',\n path: fieldName,\n },\n ],\n req,\n },\n req?.t,\n )\n } else {\n throw error\n }\n }\n\n if (ignoreResult === 'idOnly') {\n return { id: insertedRow.id } as T\n }\n\n if (ignoreResult) {\n return data as T\n }\n\n // //////////////////////////////////\n // RETRIEVE NEWLY UPDATED ROW\n // //////////////////////////////////\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n joinQuery: false,\n select,\n tableName,\n })\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n // //////////////////////////////////\n // TRANSFORM DATA\n // //////////////////////////////////\n\n const result = transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n joinQuery: false,\n tableName,\n })\n\n return result\n}\n"],"names":["eq","ValidationError","buildFindManyArgs","transform","transformForWrite","deleteExistingArrayRows","deleteExistingRowsByPath","insertArrays","shouldUseOptimizedUpsertRow","upsertRow","id","adapter","data","db","fields","ignoreResult","joinQuery","_joinQuery","operation","path","req","select","tableName","upsertTarget","where","createdAt","Date","toISOString","insertedRow","row","enableAtomicWrites","drizzle","update","tables","set","findManyArgs","depth","findManyKeysLength","Object","keys","length","hasOnlyColumns","columns","selectedFields","column","enabled","entries","docs","returning","undefined","config","payload","doc","query","findFirst","rowToInsert","target","insert","onConflictDoUpdate","values","allowIDOnCreate","localesToInsert","relationsToInsert","textsToInsert","numbersToInsert","blocksToInsert","selectsToInsert","locales","forEach","locale","localeRow","_parentID","_locale","push","relationships","relation","parent","texts","textRow","numbers","numberRow","selects","selectTableName","selectRows","blocks","blockRow","uuid","localeTableName","localesSuffix","localeTable","deleteWhere","relationshipsTableName","relationshipsSuffix","localeColumnName","parentColumnName","parentID","pathColumnName","rows","relationshipsToDelete","textsTableName","textsToDelete","numbersTableName","numbersToDelete","insertedBlockRows","blocksToDelete","blockTable","arraysBlocksUUIDMap","blockRows","map","i","_uuid","blockLocaleIndexMap","blockLocaleRowsToInsert","reduce","acc","blockLocale","blockLocaleData","arrays","parentRows","uuidMap","arrayTableName","tableRows","selectTable","caughtError","error","cause","code","fieldName","fieldConstraints","constraint","replacement","includes","replacedConstraint","replace","detail","regex","match","key","message","errors","t","result"],"mappings":"AAIA,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,eAAe,QAAQ,UAAS;AAKzC,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,2BAA2B,QAAQ,mCAAkC;AAE9E;;;;;;CAMC,GACD,OAAO,MAAMC,YAAY,OAAuD,EAC9EC,EAAE,EACFC,OAAO,EACPC,IAAI,EACJC,EAAE,EACFC,MAAM,EACNC,YAAY,EACZ,QAAQ;AACR,4GAA4G;AAC5G,8EAA8E;AAC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AgB,CAAC1G,UAAU,EAAE;wBACvCyG,YAAYpH,QAAQqH,gBAAgB,CAAC1G,UAAU,CAAC,GAAGkH,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;oBACpE;oBAEA,IAAI,CAACT,WAAW;wBACdA,YAAYS,KAAK,CAAC,EAAE;oBACtB;gBACF;YACF;YAEA,MAAM,IAAIvI,gBACR;gBACES;gBACAiI,QAAQ;oBACN;wBACED,SAAStH,KAAKwH,IAAIxH,IAAIwH,CAAC,CAAC,6BAA6B;wBACrDzH,MAAM4G;oBACR;iBACD;gBACD3G;YACF,GACAA,KAAKwH;QAET,OAAO;YACL,MAAMhB;QACR;IACF;IAEA,IAAI7G,iBAAiB,UAAU;QAC7B,OAAO;YAAEL,IAAIkB,YAAYlB,EAAE;QAAC;IAC9B;IAEA,IAAIK,cAAc;QAChB,OAAOH;IACT;IAEA,qCAAqC;IACrC,6BAA6B;IAC7B,qCAAqC;IAErC,MAAMuB,eAAejC,kBAAkB;QACrCS;QACAyB,OAAO;QACPtB;QACAE,WAAW;QACXK;QACAC;IACF;IAEAa,aAAaX,KAAK,GAAGxB,GAAGW,QAAQsB,MAAM,CAACX,UAAU,CAACZ,EAAE,EAAEkB,YAAYlB,EAAE;IAEpE,MAAM0C,MAAM,MAAMvC,GAAGwC,KAAK,CAAC/B,UAAU,CAACgC,SAAS,CAACnB;IAEhD,qCAAqC;IACrC,iBAAiB;IACjB,qCAAqC;IAErC,MAAM0G,SAAS1I,UAAa;QAC1BQ;QACAuC,QAAQvC,QAAQwC,OAAO,CAACD,MAAM;QAC9BtC,MAAMwC;QACNtC;QACAE,WAAW;QACXM;IACF;IAEA,OAAOuH;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/index.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { SelectedFields } from 'drizzle-orm/sqlite-core'\nimport type { TypeWithID } from 'payload'\n\nimport { eq } from 'drizzle-orm'\nimport { ValidationError } from 'payload'\n\nimport type { BlockRowToInsert } from '../transform/write/types.js'\nimport type { Args } from './types.js'\n\nimport { buildFindManyArgs } from '../find/buildFindManyArgs.js'\nimport { transform } from '../transform/read/index.js'\nimport { transformForWrite } from '../transform/write/index.js'\nimport { deleteExistingArrayRows } from './deleteExistingArrayRows.js'\nimport { deleteExistingRowsByPath } from './deleteExistingRowsByPath.js'\nimport { insertArrays } from './insertArrays.js'\nimport { shouldUseOptimizedUpsertRow } from './shouldUseOptimizedUpsertRow.js'\n\n/**\n * If `id` is provided, it will update the row with that ID.\n * If `where` is provided, it will update the row that matches the `where`\n * If neither `id` nor `where` is provided, it will create a new row.\n *\n * adapter function replaces the entire row and does not support partial updates.\n */\nexport const upsertRow = async <T extends Record<string, unknown> | TypeWithID>({\n id,\n adapter,\n data,\n db,\n fields,\n ignoreResult,\n // TODO:\n // When we support joins for write operations (create/update) - pass collectionSlug to the buildFindManyArgs\n // Make a new argument in upsertRow.ts and pass the slug from every operation.\n joinQuery: _joinQuery,\n operation,\n path = '',\n req,\n select,\n tableName,\n upsertTarget,\n where,\n}: Args): Promise<T> => {\n if (operation === 'create' && !data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n let insertedRow: Record<string, unknown> = { id }\n if (id && shouldUseOptimizedUpsertRow({ data, fields })) {\n const transformedForWrite = transformForWrite({\n adapter,\n data,\n enableAtomicWrites: true,\n fields,\n tableName,\n })\n const { row } = transformedForWrite\n const { arraysToPush } = transformedForWrite\n\n const drizzle = db as LibSQLDatabase\n\n // First, handle $push arrays\n\n if (arraysToPush && Object.keys(arraysToPush)?.length) {\n await insertArrays({\n adapter,\n arrays: [arraysToPush],\n db,\n parentRows: [insertedRow],\n uuidMap: {},\n })\n }\n\n // If row.updatedAt is not set, delete it to avoid triggering hasDataToUpdate. `updatedAt` may be explicitly set to null to\n // disable triggering hasDataToUpdate.\n if (typeof row.updatedAt === 'undefined' || row.updatedAt === null) {\n delete row.updatedAt\n }\n\n const hasDataToUpdate = row && Object.keys(row)?.length\n\n // Then, handle regular row update\n if (ignoreResult) {\n if (hasDataToUpdate) {\n // Only update row if there is something to update.\n // Example: if the data only consists of a single $push, calling insertArrays is enough - we don't need to update the row.\n await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n }\n return ignoreResult === 'idOnly' ? ({ id } as T) : null\n }\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n joinQuery: false,\n select,\n tableName,\n })\n\n const findManyKeysLength = Object.keys(findManyArgs).length\n const hasOnlyColumns = Object.keys(findManyArgs.columns || {}).length > 0\n\n if (!hasDataToUpdate) {\n // Nothing to update => just fetch current row and return\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n return transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n joinQuery: false,\n tableName,\n })\n }\n\n if (findManyKeysLength === 0 || hasOnlyColumns) {\n // Optimization - No need for joins => can simply use returning(). This is optimal for very simple collections\n // without complex fields that live in separate tables like blocks, arrays, relationships, etc.\n\n const selectedFields: SelectedFields = {}\n if (hasOnlyColumns) {\n for (const [column, enabled] of Object.entries(findManyArgs.columns)) {\n if (enabled) {\n selectedFields[column] = adapter.tables[tableName][column]\n }\n }\n }\n\n const docs = await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n .returning(Object.keys(selectedFields).length ? selectedFields : undefined)\n\n return transform<T>({\n adapter,\n config: adapter.payload.config,\n data: docs[0],\n fields,\n joinQuery: false,\n tableName,\n })\n }\n\n // DB Update that needs the result, potentially with joins => need to update first, then find. returning() does not work with joins.\n\n await drizzle\n .update(adapter.tables[tableName])\n .set(row)\n .where(eq(adapter.tables[tableName].id, id))\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n return transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n joinQuery: false,\n tableName,\n })\n }\n // Split out the incoming data into the corresponding:\n // base row, locales, relationships, blocks, and arrays\n const rowToInsert = transformForWrite({\n adapter,\n data,\n enableAtomicWrites: false,\n fields,\n path,\n tableName,\n })\n\n // First, we insert the main row\n try {\n if (operation === 'update') {\n const target = upsertTarget || adapter.tables[tableName].id\n\n if (id) {\n rowToInsert.row.id = id\n ;[insertedRow] = await adapter.insert({\n db,\n onConflictDoUpdate: { set: rowToInsert.row, target },\n tableName,\n values: rowToInsert.row,\n })\n } else {\n ;[insertedRow] = await adapter.insert({\n db,\n onConflictDoUpdate: { set: rowToInsert.row, target, where },\n tableName,\n values: rowToInsert.row,\n })\n }\n } else {\n if (adapter.allowIDOnCreate && data.id) {\n rowToInsert.row.id = data.id\n }\n ;[insertedRow] = await adapter.insert({\n db,\n tableName,\n values: rowToInsert.row,\n })\n }\n\n const localesToInsert: Record<string, unknown>[] = []\n const relationsToInsert: Record<string, unknown>[] = []\n const textsToInsert: Record<string, unknown>[] = []\n const numbersToInsert: Record<string, unknown>[] = []\n const blocksToInsert: { [blockType: string]: BlockRowToInsert[] } = {}\n const selectsToInsert: { [selectTableName: string]: Record<string, unknown>[] } = {}\n\n // If there are locale rows with data, add the parent and locale to each\n if (Object.keys(rowToInsert.locales).length > 0) {\n Object.entries(rowToInsert.locales).forEach(([locale, localeRow]) => {\n localeRow._parentID = insertedRow.id\n localeRow._locale = locale\n localesToInsert.push(localeRow)\n })\n }\n\n // If there are relationships, add parent to each\n if (rowToInsert.relationships.length > 0) {\n rowToInsert.relationships.forEach((relation) => {\n relation.parent = insertedRow.id\n relationsToInsert.push(relation)\n })\n }\n\n // If there are texts, add parent to each\n if (rowToInsert.texts.length > 0) {\n rowToInsert.texts.forEach((textRow) => {\n textRow.parent = insertedRow.id\n textsToInsert.push(textRow)\n })\n }\n\n // If there are numbers, add parent to each\n if (rowToInsert.numbers.length > 0) {\n rowToInsert.numbers.forEach((numberRow) => {\n numberRow.parent = insertedRow.id\n numbersToInsert.push(numberRow)\n })\n }\n\n // If there are selects, add parent to each, and then\n // store by table name and rows\n if (Object.keys(rowToInsert.selects).length > 0) {\n Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows]) => {\n selectsToInsert[selectTableName] = []\n\n selectRows.forEach((row) => {\n if (typeof row.parent === 'undefined') {\n row.parent = insertedRow.id\n }\n\n selectsToInsert[selectTableName].push(row)\n })\n })\n }\n\n // If there are blocks, add parent to each, and then\n // store by table name and rows\n Object.keys(rowToInsert.blocks).forEach((tableName) => {\n rowToInsert.blocks[tableName].forEach((blockRow) => {\n blockRow.row._parentID = insertedRow.id\n if (!blocksToInsert[tableName]) {\n blocksToInsert[tableName] = []\n }\n if (blockRow.row.uuid) {\n delete blockRow.row.uuid\n }\n blocksToInsert[tableName].push(blockRow)\n })\n })\n\n // //////////////////////////////////\n // INSERT LOCALES\n // //////////////////////////////////\n\n if (localesToInsert.length > 0) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n const localeTable = adapter.tables[`${tableName}${adapter.localesSuffix}`]\n\n if (operation === 'update') {\n await adapter.deleteWhere({\n db,\n tableName: localeTableName,\n where: eq(localeTable._parentID, insertedRow.id),\n })\n }\n\n await adapter.insert({\n db,\n tableName: localeTableName,\n values: localesToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT RELATIONSHIPS\n // //////////////////////////////////\n\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...relationsToInsert, ...rowToInsert.relationshipsToDelete],\n tableName: relationshipsTableName,\n })\n }\n\n if (relationsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: relationshipsTableName,\n values: relationsToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT hasMany TEXTS\n // //////////////////////////////////\n\n const textsTableName = `${tableName}_texts`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...textsToInsert, ...rowToInsert.textsToDelete],\n tableName: textsTableName,\n })\n }\n\n if (textsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: textsTableName,\n values: textsToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT hasMany NUMBERS\n // //////////////////////////////////\n\n const numbersTableName = `${tableName}_numbers`\n\n if (operation === 'update') {\n await deleteExistingRowsByPath({\n adapter,\n db,\n localeColumnName: 'locale',\n parentColumnName: 'parent',\n parentID: insertedRow.id,\n pathColumnName: 'path',\n rows: [...numbersToInsert, ...rowToInsert.numbersToDelete],\n tableName: numbersTableName,\n })\n }\n\n if (numbersToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: numbersTableName,\n values: numbersToInsert,\n })\n }\n\n // //////////////////////////////////\n // INSERT BLOCKS\n // //////////////////////////////////\n\n const insertedBlockRows: Record<string, Record<string, unknown>[]> = {}\n\n if (operation === 'update') {\n for (const tableName of rowToInsert.blocksToDelete) {\n const blockTable = adapter.tables[tableName]\n await adapter.deleteWhere({\n db,\n tableName,\n where: eq(blockTable._parentID, insertedRow.id),\n })\n }\n }\n\n // When versions are enabled, adapter is used to track mapping between blocks/arrays ObjectID to their numeric generated representation, then we use it for nested to arrays/blocks select hasMany in versions.\n const arraysBlocksUUIDMap: Record<string, number | string> = {}\n\n for (const [tableName, blockRows] of Object.entries(blocksToInsert)) {\n insertedBlockRows[tableName] = await adapter.insert({\n db,\n tableName,\n values: blockRows.map(({ row }) => row),\n })\n\n insertedBlockRows[tableName].forEach((row, i) => {\n blockRows[i].row = row\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n arraysBlocksUUIDMap[row._uuid] = row.id\n }\n })\n\n const blockLocaleIndexMap: number[] = []\n\n const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i) => {\n if (Object.entries(blockRow.locales).length > 0) {\n Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData]) => {\n if (Object.keys(blockLocaleData).length > 0) {\n blockLocaleData._parentID = blockRow.row.id\n blockLocaleData._locale = blockLocale\n acc.push(blockLocaleData)\n blockLocaleIndexMap.push(i)\n }\n })\n }\n\n return acc\n }, [])\n\n if (blockLocaleRowsToInsert.length > 0) {\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: blockLocaleRowsToInsert,\n })\n }\n\n await insertArrays({\n adapter,\n arrays: blockRows.map(({ arrays }) => arrays),\n db,\n parentRows: insertedBlockRows[tableName],\n uuidMap: arraysBlocksUUIDMap,\n })\n }\n\n // //////////////////////////////////\n // INSERT ARRAYS RECURSIVELY\n // //////////////////////////////////\n\n if (operation === 'update') {\n for (const arrayTableName of Object.keys(rowToInsert.arrays)) {\n await deleteExistingArrayRows({\n adapter,\n db,\n parentID: insertedRow.id,\n tableName: arrayTableName,\n })\n }\n }\n\n await insertArrays({\n adapter,\n arrays: [rowToInsert.arrays, rowToInsert.arraysToPush],\n db,\n parentRows: [insertedRow, insertedRow],\n uuidMap: arraysBlocksUUIDMap,\n })\n\n // //////////////////////////////////\n // INSERT hasMany SELECTS\n // //////////////////////////////////\n\n for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)) {\n const selectTable = adapter.tables[selectTableName]\n if (operation === 'update') {\n await adapter.deleteWhere({\n db,\n tableName: selectTableName,\n where: eq(selectTable.parent, insertedRow.id),\n })\n }\n\n if (Object.keys(arraysBlocksUUIDMap).length > 0) {\n tableRows.forEach((row: any) => {\n if (row.parent in arraysBlocksUUIDMap) {\n row.parent = arraysBlocksUUIDMap[row.parent]\n }\n })\n }\n\n if (tableRows.length) {\n await adapter.insert({\n db,\n tableName: selectTableName,\n values: tableRows,\n })\n }\n }\n\n // //////////////////////////////////\n // Error Handling\n // //////////////////////////////////\n } catch (caughtError) {\n // Unique constraint violation error\n // '23505' is the code for PostgreSQL, and 'SQLITE_CONSTRAINT_UNIQUE' is for SQLite\n\n let error = caughtError\n if (typeof caughtError === 'object' && 'cause' in caughtError) {\n error = caughtError.cause\n }\n\n if (error.code === '23505' || error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n let fieldName: null | string = null\n // We need to try and find the right constraint for the field but if we can't we fallback to a generic message\n if (error.code === '23505') {\n // For PostgreSQL, we can try to extract the field name from the error constraint\n if (adapter.fieldConstraints?.[tableName]?.[error.constraint]) {\n fieldName = adapter.fieldConstraints[tableName]?.[error.constraint]\n } else {\n const replacement = `${tableName}_`\n\n if (error.constraint.includes(replacement)) {\n const replacedConstraint = error.constraint.replace(replacement, '')\n\n if (replacedConstraint && adapter.fieldConstraints[tableName]?.[replacedConstraint]) {\n fieldName = adapter.fieldConstraints[tableName][replacedConstraint]\n }\n }\n }\n\n if (!fieldName) {\n // Last case scenario we extract the key and value from the detail on the error\n const detail = error.detail\n const regex = /Key \\(([^)]+)\\)=\\(([^)]+)\\)/\n const match: string[] = detail.match(regex)\n\n if (match && match[1]) {\n const key = match[1]\n\n fieldName = key\n }\n }\n } else if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {\n /**\n * For SQLite, we can try to extract the field name from the error message\n * The message typically looks like:\n * \"UNIQUE constraint failed: table_name.field_name\"\n */\n const regex = /UNIQUE constraint failed: ([^.]+)\\.([^.]+)/\n const match: string[] = error.message.match(regex)\n\n if (match && match[2]) {\n if (adapter.fieldConstraints[tableName]) {\n fieldName = adapter.fieldConstraints[tableName][`${match[2]}_idx`]\n }\n\n if (!fieldName) {\n fieldName = match[2]\n }\n }\n }\n\n throw new ValidationError(\n {\n id,\n errors: [\n {\n message: req?.t ? req.t('error:valueMustBeUnique') : 'Value must be unique',\n path: fieldName,\n },\n ],\n req,\n },\n req?.t,\n )\n } else {\n throw error\n }\n }\n\n if (ignoreResult === 'idOnly') {\n return { id: insertedRow.id } as T\n }\n\n if (ignoreResult) {\n return data as T\n }\n\n // //////////////////////////////////\n // RETRIEVE NEWLY UPDATED ROW\n // //////////////////////////////////\n\n const findManyArgs = buildFindManyArgs({\n adapter,\n depth: 0,\n fields,\n joinQuery: false,\n select,\n tableName,\n })\n\n findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id)\n\n const doc = await db.query[tableName].findFirst(findManyArgs)\n\n // //////////////////////////////////\n // TRANSFORM DATA\n // //////////////////////////////////\n\n const result = transform<T>({\n adapter,\n config: adapter.payload.config,\n data: doc,\n fields,\n joinQuery: false,\n tableName,\n })\n\n return result\n}\n"],"names":["eq","ValidationError","buildFindManyArgs","transform","transformForWrite","deleteExistingArrayRows","deleteExistingRowsByPath","insertArrays","shouldUseOptimizedUpsertRow","upsertRow","id","adapter","data","db","fields","ignoreResult","joinQuery","_joinQuery","operation","path","req","select","tableName","upsertTarget","where","createdAt","Date","toISOString","insertedRow","transformedForWrite","enableAtomicWrites","row","arraysToPush","drizzle","Object","keys","length","arrays","parentRows","uuidMap","updatedAt","hasDataToUpdate","update","tables","set","findManyArgs","depth","findManyKeysLength","hasOnlyColumns","columns","doc","query","findFirst","config","payload","selectedFields","column","enabled","entries","docs","returning","undefined","rowToInsert","target","insert","onConflictDoUpdate","values","allowIDOnCreate","localesToInsert","relationsToInsert","textsToInsert","numbersToInsert","blocksToInsert","selectsToInsert","locales","forEach","locale","localeRow","_parentID","_locale","push","relationships","relation","parent","texts","textRow","numbers","numberRow","selects","selectTableName","selectRows","blocks","blockRow","uuid","localeTableName","localesSuffix","localeTable","deleteWhere","relationshipsTableName","relationshipsSuffix","localeColumnName","parentColumnName","parentID","pathColumnName","rows","relationshipsToDelete","textsTableName","textsToDelete","numbersTableName","numbersToDelete","insertedBlockRows","blocksToDelete","blockTable","arraysBlocksUUIDMap","blockRows","map","i","_uuid","blockLocaleIndexMap","blockLocaleRowsToInsert","reduce","acc","blockLocale","blockLocaleData","arrayTableName","tableRows","selectTable","caughtError","error","cause","code","fieldName","fieldConstraints","constraint","replacement","includes","replacedConstraint","replace","detail","regex","match","key","message","errors","t","result"],"mappings":"AAIA,SAASA,EAAE,QAAQ,cAAa;AAChC,SAASC,eAAe,QAAQ,UAAS;AAKzC,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,SAAS,QAAQ,6BAA4B;AACtD,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,2BAA2B,QAAQ,mCAAkC;AAE9E;;;;;;CAMC,GACD,OAAO,MAAMC,YAAY,OAAuD,EAC9EC,EAAE,EACFC,OAAO,EACPC,IAAI,EACJC,EAAE,EACFC,MAAM,EACNC,YAAY,EACZ,QAAQ;AACR,4GAA4G;AAC5G,8EAA8E;AAC9EC,WAAWC,UAAU,EACrBC,SAAS,EACTC,OAAO,EAAE,EACTC,GAAG,EACHC,MAAM,EACNC,SAAS,EACTC,YAAY,EACZC,KAAK,EACA;IACL,IAAIN,cAAc,YAAY,CAACN,KAAKa,SAAS,EAAE;QAC7Cb,KAAKa,SAAS,GAAG,IAAIC,OAAOC,WAAW;IACzC;IAEA,IAAIC,cAAuC;QAAElB;IAAG;IAChD,IAAIA,MAAMF,4BAA4B;QAAEI;QAAME;IAAO,IAAI;QACvD,MAAMe,sBAAsBzB,kBAAkB;YAC5CO;YACAC;YACAkB,oBAAoB;YACpBhB;YACAQ;QACF;QACA,MAAM,EAAES,GAAG,EAAE,GAAGF;QAChB,MAAM,EAAEG,YAAY,EAAE,GAAGH;QAEzB,MAAMI,UAAUpB;QAEhB,6BAA6B;QAE7B,IAAImB,gBAAgBE,OAAOC,IAAI,CAACH,eAAeI,QAAQ;YACrD,MAAM7B,aAAa;gBACjBI;gBACA0B,QAAQ;oBAACL;iBAAa;gBACtBnB;gBACAyB,YAAY;oBAACV;iBAAY;gBACzBW,SAAS,CAAC;Y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2C,OAAO,CAACD,MAAM;QAC9BzC,MAAMsC;QACNpC;QACAE,WAAW;QACXM;IACF;IAEA,OAAO2H;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAC1C,CAAA;AAYD,eAAO,MAAM,YAAY,kDAMtB,IAAI,KAAG,OAAO,CAAC,IAAI,CA6FrB,CAAA"}
1
+ {"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAC1C,CAAA;AAYD,eAAO,MAAM,YAAY,kDAMtB,IAAI,KAAG,OAAO,CAAC,IAAI,CAgGrB,CAAA"}
@@ -2,6 +2,9 @@ export const insertArrays = async ({ adapter, arrays, db, parentRows, uuidMap =
2
2
  // Maintain a map of flattened rows by table
3
3
  const rowsByTable = {};
4
4
  arrays.forEach((arraysByTable, parentRowIndex)=>{
5
+ if (!arraysByTable || Object.keys(arraysByTable).length === 0) {
6
+ return;
7
+ }
5
8
  Object.entries(arraysByTable).forEach(([tableName, arrayRows])=>{
6
9
  // If the table doesn't exist in map, initialize it
7
10
  if (!rowsByTable[tableName]) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows: { _uuid: string; id: number }[]) => {\n const { id } = rows.find((each) => each._uuid === arrayRow.row._uuid)\n return id\n }\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await adapter.insert({\n db,\n tableName,\n values: row.rows,\n })\n\n insertedRows.forEach((row) => {\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n uuidMap[row._uuid] = row.id\n }\n })\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: row.locales,\n })\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","uuidMap","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","keys","length","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","find","each","_uuid","insertedRows","insert","values","tables","localesSuffix","map","localeRow"],"mappings":"AAuBA,OAAO,MAAMA,eAAe,OAAO,EACjCC,OAAO,EACPC,MAAM,EACNC,EAAE,EACFC,UAAU,EACVC,UAAU,CAAC,CAAC,EACP;IACL,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCJ,OAAOK,OAAO,CAAC,CAACC,eAAeC;QAC7BC,OAAOC,OAAO,CAACH,eAAeD,OAAO,CAAC,CAAC,CAACK,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACP,WAAW,CAACM,UAAU,EAAE;gBAC3BN,WAAW,CAACM,UAAU,GAAG;oBACvBV,QAAQ,EAAE;oBACVY,SAAS,EAAE;oBACXC,MAAM,EAAE;gBACV;YACF;YAEA,MAAMC,WAAWZ,UAAU,CAACK,eAAe,CAACQ,EAAE;YAE9C,6CAA6C;YAC7C,sCAAsC;YACtCJ,UAAUN,OAAO,CAAC,CAACW;gBACjB,IAAIR,OAAOS,IAAI,CAACD,SAAShB,MAAM,EAAEkB,MAAM,GAAG,GAAG;oBAC3Cd,WAAW,CAACM,UAAU,CAACV,MAAM,CAACmB,IAAI,CAACH,SAAShB,MAAM;gBACpD;gBAEA,gDAAgD;gBAChDgB,SAASI,GAAG,CAACC,SAAS,GAAGP;gBACzBV,WAAW,CAACM,UAAU,CAACG,IAAI,CAACM,IAAI,CAACH,SAASI,GAAG;gBAE7CZ,OAAOC,OAAO,CAACO,SAASJ,OAAO,EAAEP,OAAO,CAAC,CAAC,CAACiB,gBAAgBC,mBAAmB;oBAC5EA,mBAAmBF,SAAS,GAAGL,SAASI,GAAG,CAACL,EAAE;oBAC9CQ,mBAAmBC,OAAO,GAAGF;oBAC7BlB,WAAW,CAACM,UAAU,CAACE,OAAO,CAACO,IAAI,CAACI;oBACpC,IAAI,CAACP,SAASI,GAAG,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,QAAQkC,aAAa,EAAE;gBACjDF,QAAQX,IAAIR,OAAO;YACrB;QACF;QAEA,0DAA0D;QAC1D,IAAIQ,IAAIpB,MAAM,CAACkB,MAAM,GAAG,GAAG;YACzB,MAAMpB,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAY2B;YACd;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n if (!arraysByTable || Object.keys(arraysByTable).length === 0) {\n return\n }\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows: { _uuid: string; id: number }[]) => {\n const { id } = rows.find((each) => each._uuid === arrayRow.row._uuid)\n return id\n }\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await adapter.insert({\n db,\n tableName,\n values: row.rows,\n })\n\n insertedRows.forEach((row) => {\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n uuidMap[row._uuid] = row.id\n }\n })\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: row.locales,\n })\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","uuidMap","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","keys","length","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","find","each","_uuid","insertedRows","insert","values","tables","localesSuffix","map","localeRow"],"mappings":"AAuBA,OAAO,MAAMA,eAAe,OAAO,EACjCC,OAAO,EACPC,MAAM,EACNC,EAAE,EACFC,UA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ACzB,MAAMZ,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAY2B;YACd;QACF;IACF;AACF,EAAC"}
@@ -6,5 +6,5 @@ import type { FlattenedField } from 'payload';
6
6
  export declare const shouldUseOptimizedUpsertRow: ({ data, fields, }: {
7
7
  data: Record<string, unknown>;
8
8
  fields: FlattenedField[];
9
- }) => boolean;
9
+ }) => any;
10
10
  //# sourceMappingURL=shouldUseOptimizedUpsertRow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shouldUseOptimizedUpsertRow.d.ts","sourceRoot":"","sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,sBAGrC;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,YAuCA,CAAA"}
1
+ {"version":3,"file":"shouldUseOptimizedUpsertRow.d.ts","sourceRoot":"","sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,sBAGrC;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,QAiDA,CAAA"}
@@ -8,7 +8,17 @@
8
8
  if (!field) {
9
9
  continue;
10
10
  }
11
- if (field.type === 'array' || field.type === 'blocks' || (field.type === 'text' || field.type === 'relationship' || field.type === 'upload' || field.type === 'select' || field.type === 'number') && field.hasMany || (field.type === 'relationship' || field.type === 'upload') && Array.isArray(field.relationTo) || field.localized) {
11
+ if (field.type === 'blocks' || (field.type === 'text' || field.type === 'relationship' || field.type === 'upload' || field.type === 'select' || field.type === 'number') && field.hasMany || (field.type === 'relationship' || field.type === 'upload') && Array.isArray(field.relationTo) || field.localized) {
12
+ return false;
13
+ }
14
+ if (field.type === 'array') {
15
+ if (typeof value === 'object' && '$push' in value && value.$push) {
16
+ return shouldUseOptimizedUpsertRow({
17
+ // Only check first row - this function cares about field definitions. Each array row will have the same field definitions.
18
+ data: Array.isArray(value.$push) ? value.$push?.[0] : value.$push,
19
+ fields: field.flattenedFields
20
+ });
21
+ }
12
22
  return false;
13
23
  }
14
24
  if ((field.type === 'group' || field.type === 'tab') && value && typeof value === 'object' && !shouldUseOptimizedUpsertRow({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\n/**\n * Checks whether we should use the upsertRow function for the passed data and otherwise use a simple SQL SET call.\n * We need to use upsertRow only when the data has arrays, blocks, hasMany select/text/number, localized fields, complex relationships.\n */\nexport const shouldUseOptimizedUpsertRow = ({\n data,\n fields,\n}: {\n data: Record<string, unknown>\n fields: FlattenedField[]\n}) => {\n for (const key in data) {\n const value = data[key]\n const field = fields.find((each) => each.name === key)\n\n if (!field) {\n continue\n }\n\n if (\n field.type === 'array' ||\n field.type === 'blocks' ||\n ((field.type === 'text' ||\n field.type === 'relationship' ||\n field.type === 'upload' ||\n field.type === 'select' ||\n field.type === 'number') &&\n field.hasMany) ||\n ((field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)) ||\n field.localized\n ) {\n return false\n }\n\n if (\n (field.type === 'group' || field.type === 'tab') &&\n value &&\n typeof value === 'object' &&\n !shouldUseOptimizedUpsertRow({\n data: value as Record<string, unknown>,\n fields: field.flattenedFields,\n })\n ) {\n return false\n }\n }\n\n return true\n}\n"],"names":["shouldUseOptimizedUpsertRow","data","fields","key","value","field","find","each","name","type","hasMany","Array","isArray","relationTo","localized","flattenedFields"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,8BAA8B,CAAC,EAC1CC,IAAI,EACJC,MAAM,EAIP;IACC,IAAK,MAAMC,OAAOF,KAAM;QACtB,MAAMG,QAAQH,IAAI,CAACE,IAAI;QACvB,MAAME,QAAQH,OAAOI,IAAI,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAKL;QAElD,IAAI,CAACE,OAAO;YACV;QACF;QAEA,IACEA,MAAMI,IAAI,KAAK,WACfJ,MAAMI,IAAI,KAAK,YACd,AAACJ,CAAAA,MAAMI,IAAI,KAAK,UACfJ,MAAMI,IAAI,KAAK,kBACfJ,MAAMI,IAAI,KAAK,YACfJ,MAAMI,IAAI,KAAK,YACfJ,MAAMI,IAAI,KAAK,QAAO,KACtBJ,MAAMK,OAAO,IACd,AAACL,CAAAA,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,IAAI,KAAK,QAAO,KACvDE,MAAMC,OAAO,CAACP,MAAMQ,UAAU,KAChCR,MAAMS,SAAS,EACf;YACA,OAAO;QACT;QAEA,IACE,AAACT,CAAAA,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,KAAI,KAC9CL,SACA,OAAOA,UAAU,YACjB,CAACJ,4BAA4B;YAC3BC,MAAMG;YACNF,QAAQG,MAAMU,eAAe;QAC/B,IACA;YACA,OAAO;QACT;IACF;IAEA,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\n/**\n * Checks whether we should use the upsertRow function for the passed data and otherwise use a simple SQL SET call.\n * We need to use upsertRow only when the data has arrays, blocks, hasMany select/text/number, localized fields, complex relationships.\n */\nexport const shouldUseOptimizedUpsertRow = ({\n data,\n fields,\n}: {\n data: Record<string, unknown>\n fields: FlattenedField[]\n}) => {\n for (const key in data) {\n const value = data[key]\n const field = fields.find((each) => each.name === key)\n\n if (!field) {\n continue\n }\n\n if (\n field.type === 'blocks' ||\n ((field.type === 'text' ||\n field.type === 'relationship' ||\n field.type === 'upload' ||\n field.type === 'select' ||\n field.type === 'number') &&\n field.hasMany) ||\n ((field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)) ||\n field.localized\n ) {\n return false\n }\n\n if (field.type === 'array') {\n if (typeof value === 'object' && '$push' in value && value.$push) {\n return shouldUseOptimizedUpsertRow({\n // Only check first row - this function cares about field definitions. Each array row will have the same field definitions.\n data: Array.isArray(value.$push) ? value.$push?.[0] : value.$push,\n fields: field.flattenedFields,\n })\n }\n return false\n }\n\n if (\n (field.type === 'group' || field.type === 'tab') &&\n value &&\n typeof value === 'object' &&\n !shouldUseOptimizedUpsertRow({\n data: value as Record<string, unknown>,\n fields: field.flattenedFields,\n })\n ) {\n return false\n }\n }\n\n return true\n}\n"],"names":["shouldUseOptimizedUpsertRow","data","fields","key","value","field","find","each","name","type","hasMany","Array","isArray","relationTo","localized","$push","flattenedFields"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,8BAA8B,CAAC,EAC1CC,IAAI,EACJC,MAAM,EAIP;IACC,IAAK,MAAMC,OAAOF,KAAM;QACtB,MAAMG,QAAQH,IAAI,CAACE,IAAI;QACvB,MAAME,QAAQH,OAAOI,IAAI,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAKL;QAElD,IAAI,CAACE,OAAO;YACV;QACF;QAEA,IACEA,MAAMI,IAAI,KAAK,YACd,AAACJ,CAAAA,MAAMI,IAAI,KAAK,UACfJ,MAAMI,IAAI,KAAK,kBACfJ,MAAMI,IAAI,KAAK,YACfJ,MAAMI,IAAI,KAAK,YACfJ,MAAMI,IAAI,KAAK,QAAO,KACtBJ,MAAMK,OAAO,IACd,AAACL,CAAAA,MAAMI,IAAI,KAAK,kBAAkBJ,MAAMI,IAAI,KAAK,QAAO,KACvDE,MAAMC,OAAO,CAACP,MAAMQ,UAAU,KAChCR,MAAMS,SAAS,EACf;YACA,OAAO;QACT;QAEA,IAAIT,MAAMI,IAAI,KAAK,SAAS;YAC1B,IAAI,OAAOL,UAAU,YAAY,WAAWA,SAASA,MAAMW,KAAK,EAAE;gBAChE,OAAOf,4BAA4B;oBACjC,2HAA2H;oBAC3HC,MAAMU,MAAMC,OAAO,CAACR,MAAMW,KAAK,IAAIX,MAAMW,KAAK,EAAE,CAAC,EAAE,GAAGX,MAAMW,KAAK;oBACjEb,QAAQG,MAAMW,eAAe;gBAC/B;YACF;YACA,OAAO;QACT;QAEA,IACE,AAACX,CAAAA,MAAMI,IAAI,KAAK,WAAWJ,MAAMI,IAAI,KAAK,KAAI,KAC9CL,SACA,OAAOA,UAAU,YACjB,CAACJ,4BAA4B;YAC3BC,MAAMG;YACNF,QAAQG,MAAMW,eAAe;QAC/B,IACA;YACA,OAAO;QACT;IACF;IAEA,OAAO;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "3.54.0-internal.bdc84f3",
3
+ "version": "3.55.0-canary.0",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -55,10 +55,10 @@
55
55
  "@types/pg": "8.10.2",
56
56
  "@types/to-snake-case": "1.0.0",
57
57
  "@payloadcms/eslint-config": "3.28.0",
58
- "payload": "3.54.0-internal.bdc84f3"
58
+ "payload": "3.55.0-canary.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "3.54.0-internal.bdc84f3"
61
+ "payload": "3.55.0-canary.0"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:swc && pnpm build:types",