@payloadcms/drizzle 3.24.0-canary.4c8cafd → 3.24.0-canary.58e9eb5

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.
Files changed (71) hide show
  1. package/dist/find/traverseFields.d.ts +2 -2
  2. package/dist/find/traverseFields.d.ts.map +1 -1
  3. package/dist/find/traverseFields.js +216 -89
  4. package/dist/find/traverseFields.js.map +1 -1
  5. package/dist/postgres/countDistinct.d.ts.map +1 -1
  6. package/dist/postgres/countDistinct.js +14 -13
  7. package/dist/postgres/countDistinct.js.map +1 -1
  8. package/dist/queries/buildAndOrConditions.d.ts +2 -1
  9. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  10. package/dist/queries/buildAndOrConditions.js +2 -1
  11. package/dist/queries/buildAndOrConditions.js.map +1 -1
  12. package/dist/queries/buildOrderBy.d.ts +2 -1
  13. package/dist/queries/buildOrderBy.d.ts.map +1 -1
  14. package/dist/queries/buildOrderBy.js +2 -1
  15. package/dist/queries/buildOrderBy.js.map +1 -1
  16. package/dist/queries/buildQuery.d.ts +2 -1
  17. package/dist/queries/buildQuery.d.ts.map +1 -1
  18. package/dist/queries/buildQuery.js +3 -1
  19. package/dist/queries/buildQuery.js.map +1 -1
  20. package/dist/queries/getTableColumnFromPath.d.ts +2 -1
  21. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  22. package/dist/queries/getTableColumnFromPath.js +52 -27
  23. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  24. package/dist/queries/parseParams.d.ts +2 -1
  25. package/dist/queries/parseParams.d.ts.map +1 -1
  26. package/dist/queries/parseParams.js +3 -1
  27. package/dist/queries/parseParams.js.map +1 -1
  28. package/dist/schema/build.d.ts +2 -1
  29. package/dist/schema/build.d.ts.map +1 -1
  30. package/dist/schema/build.js +2 -1
  31. package/dist/schema/build.js.map +1 -1
  32. package/dist/schema/buildRawSchema.d.ts.map +1 -1
  33. package/dist/schema/buildRawSchema.js +4 -0
  34. package/dist/schema/buildRawSchema.js.map +1 -1
  35. package/dist/schema/traverseFields.d.ts +2 -1
  36. package/dist/schema/traverseFields.d.ts.map +1 -1
  37. package/dist/schema/traverseFields.js +30 -15
  38. package/dist/schema/traverseFields.js.map +1 -1
  39. package/dist/transform/read/index.d.ts +2 -1
  40. package/dist/transform/read/index.d.ts.map +1 -1
  41. package/dist/transform/read/index.js +2 -1
  42. package/dist/transform/read/index.js.map +1 -1
  43. package/dist/transform/read/traverseFields.d.ts +2 -1
  44. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  45. package/dist/transform/read/traverseFields.js +33 -16
  46. package/dist/transform/read/traverseFields.js.map +1 -1
  47. package/dist/transform/write/array.d.ts +2 -1
  48. package/dist/transform/write/array.d.ts.map +1 -1
  49. package/dist/transform/write/array.js +7 -2
  50. package/dist/transform/write/array.js.map +1 -1
  51. package/dist/transform/write/blocks.d.ts +2 -1
  52. package/dist/transform/write/blocks.d.ts.map +1 -1
  53. package/dist/transform/write/blocks.js +7 -2
  54. package/dist/transform/write/blocks.js.map +1 -1
  55. package/dist/transform/write/index.d.ts +2 -1
  56. package/dist/transform/write/index.d.ts.map +1 -1
  57. package/dist/transform/write/index.js +2 -1
  58. package/dist/transform/write/index.js.map +1 -1
  59. package/dist/transform/write/traverseFields.d.ts +2 -1
  60. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  61. package/dist/transform/write/traverseFields.js +22 -12
  62. package/dist/transform/write/traverseFields.js.map +1 -1
  63. package/dist/utilities/hasLocalesTable.d.ts +7 -1
  64. package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
  65. package/dist/utilities/hasLocalesTable.js +14 -5
  66. package/dist/utilities/hasLocalesTable.js.map +1 -1
  67. package/dist/utilities/validateExistingBlockIsIdentical.d.ts +5 -1
  68. package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
  69. package/dist/utilities/validateExistingBlockIsIdentical.js +22 -7
  70. package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
  71. package/package.json +4 -4
@@ -1,10 +1,10 @@
1
- import { fieldIsVirtual } from 'payload/shared';
1
+ import { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared';
2
2
  import { transformHasManyNumber } from './hasManyNumber.js';
3
3
  import { transformHasManyText } from './hasManyText.js';
4
4
  import { transformRelationship } from './relationship.js';
5
5
  // Traverse fields recursively, transforming data
6
6
  // for each field type into required Payload shape
7
- export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
7
+ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, parentIsLocalized, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
8
8
  const sanitizedPath = path ? `${path}.` : path;
9
9
  const formatted = fields.reduce((result, field)=>{
10
10
  if (fieldIsVirtual(field)) {
@@ -17,9 +17,13 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
17
17
  if (fieldPrefix) {
18
18
  deletions.push(()=>delete table[fieldName]);
19
19
  }
20
+ const isLocalized = fieldShouldBeLocalized({
21
+ field,
22
+ parentIsLocalized
23
+ });
20
24
  if (field.type === 'array') {
21
25
  if (Array.isArray(fieldData)) {
22
- if (field.localized) {
26
+ if (isLocalized) {
23
27
  result[field.name] = fieldData.reduce((arrayResult, row)=>{
24
28
  if (typeof row._locale === 'string') {
25
29
  if (!arrayResult[row._locale]) {
@@ -41,6 +45,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
41
45
  fieldPrefix: '',
42
46
  fields: field.flattenedFields,
43
47
  numbers,
48
+ parentIsLocalized: parentIsLocalized || field.localized,
44
49
  path: `${sanitizedPath}${field.name}.${row._order - 1}`,
45
50
  relationships,
46
51
  table: row,
@@ -76,6 +81,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
76
81
  fieldPrefix: '',
77
82
  fields: field.flattenedFields,
78
83
  numbers,
84
+ parentIsLocalized: parentIsLocalized || field.localized,
79
85
  path: `${sanitizedPath}${field.name}.${i}`,
80
86
  relationships,
81
87
  table: row,
@@ -93,7 +99,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
93
99
  const blockFieldPath = `${sanitizedPath}${field.name}`;
94
100
  const blocksByPath = blocks[blockFieldPath];
95
101
  if (Array.isArray(blocksByPath)) {
96
- if (field.localized) {
102
+ if (isLocalized) {
97
103
  result[field.name] = {};
98
104
  blocksByPath.forEach((row)=>{
99
105
  if (row._uuid) {
@@ -121,6 +127,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
121
127
  fieldPrefix: '',
122
128
  fields: block.flattenedFields,
123
129
  numbers,
130
+ parentIsLocalized: parentIsLocalized || field.localized,
124
131
  path: `${blockFieldPath}.${row._order - 1}`,
125
132
  relationships,
126
133
  table: row,
@@ -176,6 +183,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
176
183
  fieldPrefix: '',
177
184
  fields: block.flattenedFields,
178
185
  numbers,
186
+ parentIsLocalized: parentIsLocalized || field.localized,
179
187
  path: `${blockFieldPath}.${i}`,
180
188
  relationships,
181
189
  table: row,
@@ -195,7 +203,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
195
203
  }
196
204
  if (field.type === 'relationship' || field.type === 'upload') {
197
205
  if (typeof field.relationTo === 'string' && !('hasMany' in field && field.hasMany)) {
198
- if (field.localized && config.localization && config.localization.locales && Array.isArray(table?._locales)) {
206
+ if (isLocalized && config.localization && config.localization.locales && Array.isArray(table?._locales)) {
199
207
  table._locales.forEach((localeRow)=>{
200
208
  result[field.name] = {
201
209
  [localeRow._locale]: localeRow[fieldName]
@@ -211,7 +219,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
211
219
  const relationPathMatch = relationships[`${sanitizedPath}${field.name}`];
212
220
  if (!relationPathMatch) {
213
221
  if ('hasMany' in field && field.hasMany) {
214
- if (field.localized && config.localization && config.localization.locales) {
222
+ if (isLocalized && config.localization && config.localization.locales) {
215
223
  result[field.name] = {
216
224
  [config.localization.defaultLocale]: []
217
225
  };
@@ -221,7 +229,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
221
229
  }
222
230
  return result;
223
231
  }
224
- if (field.localized) {
232
+ if (isLocalized) {
225
233
  result[field.name] = {};
226
234
  const relationsByLocale = {};
227
235
  relationPathMatch.forEach((row)=>{
@@ -259,7 +267,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
259
267
  }
260
268
  let fieldResult;
261
269
  if (Array.isArray(fieldData)) {
262
- if (field.localized && adapter.payload.config.localization) {
270
+ if (isLocalized && adapter.payload.config.localization) {
263
271
  fieldResult = fieldData.reduce((joinResult, row)=>{
264
272
  if (typeof row.locale === 'string') {
265
273
  joinResult[row.locale].docs.push(row.id);
@@ -280,9 +288,17 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
280
288
  } else {
281
289
  const hasNextPage = limit !== 0 && fieldData.length > limit;
282
290
  fieldResult = {
283
- docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(({ id })=>({
291
+ docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(({ id, relationTo })=>{
292
+ if (relationTo) {
293
+ return {
294
+ relationTo,
295
+ value: id
296
+ };
297
+ }
298
+ return {
284
299
  id
285
- })),
300
+ };
301
+ }),
286
302
  hasNextPage
287
303
  };
288
304
  }
@@ -295,7 +311,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
295
311
  if (!textPathMatch) {
296
312
  return result;
297
313
  }
298
- if (field.localized) {
314
+ if (isLocalized) {
299
315
  result[field.name] = {};
300
316
  const textsByLocale = {};
301
317
  textPathMatch.forEach((row)=>{
@@ -329,7 +345,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
329
345
  if (!numberPathMatch) {
330
346
  return result;
331
347
  }
332
- if (field.localized) {
348
+ if (isLocalized) {
333
349
  result[field.name] = {};
334
350
  const numbersByLocale = {};
335
351
  numberPathMatch.forEach((row)=>{
@@ -360,7 +376,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
360
376
  }
361
377
  if (field.type === 'select' && field.hasMany) {
362
378
  if (Array.isArray(fieldData)) {
363
- if (field.localized) {
379
+ if (isLocalized) {
364
380
  result[field.name] = fieldData.reduce((selectResult, row)=>{
365
381
  if (typeof row.locale === 'string') {
366
382
  if (!selectResult[row.locale]) {
@@ -380,7 +396,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
380
396
  }
381
397
  return result;
382
398
  }
383
- if (field.localized && Array.isArray(table._locales)) {
399
+ if (isLocalized && Array.isArray(table._locales)) {
384
400
  if (!table._locales.length && adapter.payload.config.localization) {
385
401
  adapter.payload.config.localization.localeCodes.forEach((_locale)=>table._locales.push({
386
402
  _locale
@@ -419,8 +435,8 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
419
435
  const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`;
420
436
  const groupData = {};
421
437
  const locale = table._locale;
422
- const refKey = field.localized && locale ? locale : field.name;
423
- if (field.localized && locale) {
438
+ const refKey = isLocalized && locale ? locale : field.name;
439
+ if (isLocalized && locale) {
424
440
  delete table._locale;
425
441
  }
426
442
  ref[refKey] = traverseFields({
@@ -432,6 +448,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
432
448
  fieldPrefix: groupFieldPrefix,
433
449
  fields: field.flattenedFields,
434
450
  numbers,
451
+ parentIsLocalized: parentIsLocalized || field.localized,
435
452
  path: `${sanitizedPath}${field.name}`,
436
453
  relationships,
437
454
  table,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/read/traverseFields.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, JoinQuery, SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual } from 'payload/shared'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { BlocksMap } from '../../utilities/createBlocksMap.js'\n\nimport { transformHasManyNumber } from './hasManyNumber.js'\nimport { transformHasManyText } from './hasManyText.js'\nimport { transformRelationship } from './relationship.js'\n\ntype TraverseFieldsArgs = {\n /**\n * The DB adapter\n */\n adapter: DrizzleAdapter\n /**\n * Pre-formatted blocks map\n */\n blocks: BlocksMap\n /**\n * The full Payload config\n */\n config: SanitizedConfig\n /**\n * The data reference to be mutated within this recursive function\n */\n dataRef: Record<string, unknown>\n /**\n * Data that needs to be removed from the result after all fields have populated\n */\n deletions: (() => void)[]\n /**\n * Column prefix can be built up by group and named tab fields\n */\n fieldPrefix: string\n /**\n * An array of Payload fields to traverse\n */\n fields: FlattenedField[]\n /**\n *\n */\n joinQuery?: JoinQuery\n /**\n * All hasMany number fields, as returned by Drizzle, keyed on an object by field path\n */\n numbers: Record<string, Record<string, unknown>[]>\n /**\n * The current field path (in dot notation), used to merge in relationships\n */\n path: string\n /**\n * All related documents, as returned by Drizzle, keyed on an object by field path\n */\n relationships: Record<string, Record<string, unknown>[]>\n /**\n * Data structure representing the nearest table from db\n */\n table: Record<string, unknown>\n /**\n * All hasMany text fields, as returned by Drizzle, keyed on an object by field path\n */\n texts: Record<string, Record<string, unknown>[]>\n /**\n * Set to a locale if this group of fields is within a localized array or block.\n */\n withinArrayOrBlockLocale?: string\n}\n\n// Traverse fields recursively, transforming data\n// for each field type into required Payload shape\nexport const traverseFields = <T extends Record<string, unknown>>({\n adapter,\n blocks,\n config,\n dataRef,\n deletions,\n fieldPrefix,\n fields,\n joinQuery,\n numbers,\n path,\n relationships,\n table,\n texts,\n withinArrayOrBlockLocale,\n}: TraverseFieldsArgs): T => {\n const sanitizedPath = path ? `${path}.` : path\n\n const formatted = fields.reduce((result, field) => {\n if (fieldIsVirtual(field)) {\n return result\n }\n\n const fieldName = `${fieldPrefix || ''}${field.name}`\n let fieldData = table[fieldName]\n const localizedFieldData = {}\n const valuesToTransform: {\n ref: Record<string, unknown>\n table: Record<string, unknown>\n }[] = []\n\n if (fieldPrefix) {\n deletions.push(() => delete table[fieldName])\n }\n\n if (field.type === 'array') {\n if (Array.isArray(fieldData)) {\n if (field.localized) {\n result[field.name] = fieldData.reduce((arrayResult, row) => {\n if (typeof row._locale === 'string') {\n if (!arrayResult[row._locale]) {\n arrayResult[row._locale] = []\n }\n const locale = row._locale\n const data = {}\n delete row._locale\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n const rowResult = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: data,\n deletions,\n fieldPrefix: '',\n fields: field.flattenedFields,\n numbers,\n path: `${sanitizedPath}${field.name}.${row._order - 1}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale: locale,\n })\n\n if ('_order' in rowResult) {\n delete rowResult._order\n }\n\n arrayResult[locale].push(rowResult)\n }\n\n return arrayResult\n }, {})\n } else {\n result[field.name] = fieldData.reduce((acc, row, i) => {\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n if ('_order' in row) {\n delete row._order\n }\n\n if (\n !withinArrayOrBlockLocale ||\n (withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale)\n ) {\n if (row._locale) {\n delete row._locale\n }\n\n acc.push(\n traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: field.flattenedFields,\n numbers,\n path: `${sanitizedPath}${field.name}.${i}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale,\n }),\n )\n }\n\n return acc\n }, [])\n }\n }\n\n return result\n }\n\n if (field.type === 'blocks') {\n const blockFieldPath = `${sanitizedPath}${field.name}`\n const blocksByPath = blocks[blockFieldPath]\n\n if (Array.isArray(blocksByPath)) {\n if (field.localized) {\n result[field.name] = {}\n\n blocksByPath.forEach((row) => {\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n if (typeof row._locale === 'string') {\n if (!result[field.name][row._locale]) {\n result[field.name][row._locale] = []\n }\n result[field.name][row._locale].push(row)\n delete row._locale\n }\n })\n\n Object.entries(result[field.name]).forEach(([locale, localizedBlocks]) => {\n result[field.name][locale] = localizedBlocks.map((row) => {\n const block =\n adapter.payload.blocks[row.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === row.blockType,\n ) as FlattenedBlock | undefined)\n\n if (block) {\n const blockResult = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: block.flattenedFields,\n numbers,\n path: `${blockFieldPath}.${row._order - 1}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale: locale,\n })\n\n delete blockResult._order\n return blockResult\n }\n\n return {}\n })\n })\n } else {\n // Add locale-specific index to have a proper blockFieldPath for current locale\n // because blocks can be in the same array for different locales!\n if (withinArrayOrBlockLocale && config.localization) {\n for (const locale of config.localization.localeCodes) {\n let localeIndex = 0\n\n for (let i = 0; i < blocksByPath.length; i++) {\n const row = blocksByPath[i]\n if (row._locale === locale) {\n row._index = localeIndex\n localeIndex++\n }\n }\n }\n }\n\n result[field.name] = blocksByPath.reduce((acc, row, i) => {\n delete row._order\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n if (typeof row.blockType !== 'string') {\n return acc\n }\n\n const block =\n adapter.payload.blocks[row.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === row.blockType,\n ) as FlattenedBlock | undefined)\n\n if (block) {\n if (\n !withinArrayOrBlockLocale ||\n (withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale)\n ) {\n if (row._locale) {\n delete row._locale\n }\n if (typeof row._index === 'number') {\n i = row._index\n delete row._index\n }\n\n acc.push(\n traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: block.flattenedFields,\n numbers,\n path: `${blockFieldPath}.${i}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale,\n }),\n )\n\n return acc\n }\n } else {\n acc.push({})\n }\n\n return acc\n }, [])\n }\n }\n\n return result\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (typeof field.relationTo === 'string' && !('hasMany' in field && field.hasMany)) {\n if (\n field.localized &&\n config.localization &&\n config.localization.locales &&\n Array.isArray(table?._locales)\n ) {\n table._locales.forEach((localeRow) => {\n result[field.name] = { [localeRow._locale]: localeRow[fieldName] }\n })\n } else {\n valuesToTransform.push({ ref: result, table })\n }\n } else {\n const relationPathMatch = relationships[`${sanitizedPath}${field.name}`]\n\n if (!relationPathMatch) {\n if ('hasMany' in field && field.hasMany) {\n if (field.localized && config.localization && config.localization.locales) {\n result[field.name] = {\n [config.localization.defaultLocale]: [],\n }\n } else {\n result[field.name] = []\n }\n }\n\n return result\n }\n\n if (field.localized) {\n result[field.name] = {}\n const relationsByLocale: Record<string, Record<string, unknown>[]> = {}\n\n relationPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!relationsByLocale[row.locale]) {\n relationsByLocale[row.locale] = []\n }\n relationsByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(relationsByLocale).forEach(([locale, relations]) => {\n transformRelationship({\n field,\n locale,\n ref: result,\n relations,\n })\n })\n } else {\n transformRelationship({\n field,\n ref: result,\n relations: relationPathMatch,\n withinArrayOrBlockLocale,\n })\n }\n return result\n }\n }\n\n if (field.type === 'join') {\n const { limit = field.defaultLimit ?? 10 } =\n joinQuery?.[`${fieldPrefix.replaceAll('_', '.')}${field.name}`] || {}\n\n // raw hasMany results from SQLite\n if (typeof fieldData === 'string') {\n fieldData = JSON.parse(fieldData)\n }\n\n let fieldResult:\n | { docs: unknown[]; hasNextPage: boolean }\n | Record<string, { docs: unknown[]; hasNextPage: boolean }>\n if (Array.isArray(fieldData)) {\n if (field.localized && adapter.payload.config.localization) {\n fieldResult = fieldData.reduce(\n (joinResult, row) => {\n if (typeof row.locale === 'string') {\n joinResult[row.locale].docs.push(row.id)\n }\n\n return joinResult\n },\n\n // initialize with defaults so empty won't be undefined\n adapter.payload.config.localization.localeCodes.reduce((acc, code) => {\n acc[code] = {\n docs: [],\n hasNextPage: false,\n }\n return acc\n }, {}),\n )\n Object.keys(fieldResult).forEach((locale) => {\n fieldResult[locale].hasNextPage = fieldResult[locale].docs.length > limit\n fieldResult[locale].docs = fieldResult[locale].docs.slice(0, limit)\n })\n } else {\n const hasNextPage = limit !== 0 && fieldData.length > limit\n fieldResult = {\n docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(({ id }) => ({\n id,\n })),\n hasNextPage,\n }\n }\n }\n\n result[field.name] = fieldResult\n return result\n }\n\n if (field.type === 'text' && field?.hasMany) {\n const textPathMatch = texts[`${sanitizedPath}${field.name}`]\n if (!textPathMatch) {\n return result\n }\n\n if (field.localized) {\n result[field.name] = {}\n const textsByLocale: Record<string, Record<string, unknown>[]> = {}\n\n textPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!textsByLocale[row.locale]) {\n textsByLocale[row.locale] = []\n }\n textsByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(textsByLocale).forEach(([locale, texts]) => {\n transformHasManyText({\n field,\n locale,\n ref: result,\n textRows: texts,\n })\n })\n } else {\n transformHasManyText({\n field,\n ref: result,\n textRows: textPathMatch,\n withinArrayOrBlockLocale,\n })\n }\n\n return result\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPathMatch = numbers[`${sanitizedPath}${field.name}`]\n if (!numberPathMatch) {\n return result\n }\n\n if (field.localized) {\n result[field.name] = {}\n const numbersByLocale: Record<string, Record<string, unknown>[]> = {}\n\n numberPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!numbersByLocale[row.locale]) {\n numbersByLocale[row.locale] = []\n }\n numbersByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(numbersByLocale).forEach(([locale, numbers]) => {\n transformHasManyNumber({\n field,\n locale,\n numberRows: numbers,\n ref: result,\n })\n })\n } else {\n transformHasManyNumber({\n field,\n numberRows: numberPathMatch,\n ref: result,\n withinArrayOrBlockLocale,\n })\n }\n\n return result\n }\n\n if (field.type === 'select' && field.hasMany) {\n if (Array.isArray(fieldData)) {\n if (field.localized) {\n result[field.name] = fieldData.reduce((selectResult, row) => {\n if (typeof row.locale === 'string') {\n if (!selectResult[row.locale]) {\n selectResult[row.locale] = []\n }\n selectResult[row.locale].push(row.value)\n }\n\n return selectResult\n }, {})\n } else {\n let selectData = fieldData\n if (withinArrayOrBlockLocale) {\n selectData = selectData.filter(({ locale }) => locale === withinArrayOrBlockLocale)\n }\n result[field.name] = selectData.map(({ value }) => value)\n }\n }\n return result\n }\n\n if (field.localized && Array.isArray(table._locales)) {\n if (!table._locales.length && adapter.payload.config.localization) {\n adapter.payload.config.localization.localeCodes.forEach((_locale) =>\n (table._locales as unknown[]).push({ _locale }),\n )\n }\n\n table._locales.forEach((localeRow) => {\n valuesToTransform.push({\n ref: localizedFieldData,\n table: {\n ...table,\n ...localeRow,\n },\n })\n })\n } else {\n valuesToTransform.push({ ref: result, table })\n }\n\n valuesToTransform.forEach(({ ref, table }) => {\n const fieldData = table[`${fieldPrefix || ''}${field.name}`]\n const locale = table?._locale\n let val = fieldData\n\n switch (field.type) {\n case 'date': {\n if (typeof fieldData === 'string') {\n val = new Date(fieldData).toISOString()\n }\n\n break\n }\n\n case 'group':\n case 'tab': {\n const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`\n const groupData = {}\n const locale = table._locale as string\n const refKey = field.localized && locale ? locale : field.name\n\n if (field.localized && locale) {\n delete table._locale\n }\n ref[refKey] = traverseFields<Record<string, unknown>>({\n adapter,\n blocks,\n config,\n dataRef: groupData as Record<string, unknown>,\n deletions,\n fieldPrefix: groupFieldPrefix,\n fields: field.flattenedFields,\n numbers,\n path: `${sanitizedPath}${field.name}`,\n relationships,\n table,\n texts,\n withinArrayOrBlockLocale: locale || withinArrayOrBlockLocale,\n })\n\n if ('_order' in ref) {\n delete ref._order\n }\n\n return\n }\n\n case 'number': {\n if (typeof fieldData === 'string') {\n val = Number.parseFloat(fieldData)\n }\n\n break\n }\n\n case 'point': {\n if (typeof fieldData === 'string') {\n val = JSON.parse(fieldData)\n }\n\n break\n }\n\n case 'relationship':\n case 'upload': {\n if (\n val &&\n typeof field.relationTo === 'string' &&\n adapter.payload.collections[field.relationTo].customIDType === 'number'\n ) {\n val = Number(val)\n }\n\n break\n }\n case 'text': {\n if (typeof fieldData === 'string') {\n val = String(fieldData)\n }\n\n break\n }\n\n default: {\n break\n }\n }\n if (typeof locale === 'string') {\n ref[locale] = val\n } else {\n result[field.name] = val\n }\n })\n\n if (Object.keys(localizedFieldData).length > 0) {\n result[field.name] = localizedFieldData\n }\n\n return result\n\n return result\n }, dataRef)\n\n if (Array.isArray(table._locales)) {\n deletions.push(() => delete table._locales)\n }\n\n return formatted as T\n}\n"],"names":["fieldIsVirtual","transformHasManyNumber","transformHasManyText","transformRelationship","traverseFields","adapter","blocks","config","dataRef","deletions","fieldPrefix","fields","joinQuery","numbers","path","relationships","table","texts","withinArrayOrBlockLocale","sanitizedPath","formatted","reduce","result","field","fieldName","name","fieldData","localizedFieldData","valuesToTransform","push","type","Array","isArray","localized","arrayResult","row","_locale","locale","data","_uuid","id","rowResult","flattenedFields","_order","acc","i","blockFieldPath","blocksByPath","forEach","Object","entries","localizedBlocks","map","block","payload","blockType","blockReferences","find","slug","blockResult","localization","localeCodes","localeIndex","length","_index","relationTo","hasMany","locales","_locales","localeRow","ref","relationPathMatch","defaultLocale","relationsByLocale","relations","limit","defaultLimit","replaceAll","JSON","parse","fieldResult","joinResult","docs","code","hasNextPage","keys","slice","textPathMatch","textsByLocale","textRows","numberPathMatch","numbersByLocale","numberRows","selectResult","value","selectData","filter","val","Date","toISOString","groupFieldPrefix","groupData","refKey","Number","parseFloat","collections","customIDType","String"],"mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAK/C,SAASC,sBAAsB,QAAQ,qBAAoB;AAC3D,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,IAAIuB,MAAMC,OAAO,CAAChB,MAAMoD,QAAQ,GAAG;QACjC3D,UAAUoB,IAAI,CAAC,IAAM,OAAOb,MAAMoD,QAAQ;IAC5C;IAEA,OAAOhD;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/transform/read/traverseFields.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, JoinQuery, SanitizedConfig } from 'payload'\n\nimport { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { BlocksMap } from '../../utilities/createBlocksMap.js'\n\nimport { transformHasManyNumber } from './hasManyNumber.js'\nimport { transformHasManyText } from './hasManyText.js'\nimport { transformRelationship } from './relationship.js'\n\ntype TraverseFieldsArgs = {\n /**\n * The DB adapter\n */\n adapter: DrizzleAdapter\n /**\n * Pre-formatted blocks map\n */\n blocks: BlocksMap\n /**\n * The full Payload config\n */\n config: SanitizedConfig\n /**\n * The data reference to be mutated within this recursive function\n */\n dataRef: Record<string, unknown>\n /**\n * Data that needs to be removed from the result after all fields have populated\n */\n deletions: (() => void)[]\n /**\n * Column prefix can be built up by group and named tab fields\n */\n fieldPrefix: string\n /**\n * An array of Payload fields to traverse\n */\n fields: FlattenedField[]\n /**\n *\n */\n joinQuery?: JoinQuery\n /**\n * All hasMany number fields, as returned by Drizzle, keyed on an object by field path\n */\n numbers: Record<string, Record<string, unknown>[]>\n parentIsLocalized: boolean\n /**\n * The current field path (in dot notation), used to merge in relationships\n */\n path: string\n /**\n * All related documents, as returned by Drizzle, keyed on an object by field path\n */\n relationships: Record<string, Record<string, unknown>[]>\n /**\n * Data structure representing the nearest table from db\n */\n table: Record<string, unknown>\n /**\n * All hasMany text fields, as returned by Drizzle, keyed on an object by field path\n */\n texts: Record<string, Record<string, unknown>[]>\n /**\n * Set to a locale if this group of fields is within a localized array or block.\n */\n withinArrayOrBlockLocale?: string\n}\n\n// Traverse fields recursively, transforming data\n// for each field type into required Payload shape\nexport const traverseFields = <T extends Record<string, unknown>>({\n adapter,\n blocks,\n config,\n dataRef,\n deletions,\n fieldPrefix,\n fields,\n joinQuery,\n numbers,\n parentIsLocalized,\n path,\n relationships,\n table,\n texts,\n withinArrayOrBlockLocale,\n}: TraverseFieldsArgs): T => {\n const sanitizedPath = path ? `${path}.` : path\n\n const formatted = fields.reduce((result, field) => {\n if (fieldIsVirtual(field)) {\n return result\n }\n\n const fieldName = `${fieldPrefix || ''}${field.name}`\n let fieldData = table[fieldName]\n const localizedFieldData = {}\n const valuesToTransform: {\n ref: Record<string, unknown>\n table: Record<string, unknown>\n }[] = []\n\n if (fieldPrefix) {\n deletions.push(() => delete table[fieldName])\n }\n\n const isLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n if (field.type === 'array') {\n if (Array.isArray(fieldData)) {\n if (isLocalized) {\n result[field.name] = fieldData.reduce((arrayResult, row) => {\n if (typeof row._locale === 'string') {\n if (!arrayResult[row._locale]) {\n arrayResult[row._locale] = []\n }\n const locale = row._locale\n const data = {}\n delete row._locale\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n const rowResult = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: data,\n deletions,\n fieldPrefix: '',\n fields: field.flattenedFields,\n numbers,\n parentIsLocalized: parentIsLocalized || field.localized,\n path: `${sanitizedPath}${field.name}.${row._order - 1}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale: locale,\n })\n\n if ('_order' in rowResult) {\n delete rowResult._order\n }\n\n arrayResult[locale].push(rowResult)\n }\n\n return arrayResult\n }, {})\n } else {\n result[field.name] = fieldData.reduce((acc, row, i) => {\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n if ('_order' in row) {\n delete row._order\n }\n\n if (\n !withinArrayOrBlockLocale ||\n (withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale)\n ) {\n if (row._locale) {\n delete row._locale\n }\n\n acc.push(\n traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: field.flattenedFields,\n numbers,\n parentIsLocalized: parentIsLocalized || field.localized,\n path: `${sanitizedPath}${field.name}.${i}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale,\n }),\n )\n }\n\n return acc\n }, [])\n }\n }\n\n return result\n }\n\n if (field.type === 'blocks') {\n const blockFieldPath = `${sanitizedPath}${field.name}`\n const blocksByPath = blocks[blockFieldPath]\n\n if (Array.isArray(blocksByPath)) {\n if (isLocalized) {\n result[field.name] = {}\n\n blocksByPath.forEach((row) => {\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n if (typeof row._locale === 'string') {\n if (!result[field.name][row._locale]) {\n result[field.name][row._locale] = []\n }\n result[field.name][row._locale].push(row)\n delete row._locale\n }\n })\n\n Object.entries(result[field.name]).forEach(([locale, localizedBlocks]) => {\n result[field.name][locale] = localizedBlocks.map((row) => {\n const block =\n adapter.payload.blocks[row.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === row.blockType,\n ) as FlattenedBlock | undefined)\n\n if (block) {\n const blockResult = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: block.flattenedFields,\n numbers,\n parentIsLocalized: parentIsLocalized || field.localized,\n path: `${blockFieldPath}.${row._order - 1}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale: locale,\n })\n\n delete blockResult._order\n return blockResult\n }\n\n return {}\n })\n })\n } else {\n // Add locale-specific index to have a proper blockFieldPath for current locale\n // because blocks can be in the same array for different locales!\n if (withinArrayOrBlockLocale && config.localization) {\n for (const locale of config.localization.localeCodes) {\n let localeIndex = 0\n\n for (let i = 0; i < blocksByPath.length; i++) {\n const row = blocksByPath[i]\n if (row._locale === locale) {\n row._index = localeIndex\n localeIndex++\n }\n }\n }\n }\n\n result[field.name] = blocksByPath.reduce((acc, row, i) => {\n delete row._order\n if (row._uuid) {\n row.id = row._uuid\n delete row._uuid\n }\n\n if (typeof row.blockType !== 'string') {\n return acc\n }\n\n const block =\n adapter.payload.blocks[row.blockType] ??\n ((field.blockReferences ?? field.blocks).find(\n (block) => typeof block !== 'string' && block.slug === row.blockType,\n ) as FlattenedBlock | undefined)\n\n if (block) {\n if (\n !withinArrayOrBlockLocale ||\n (withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale)\n ) {\n if (row._locale) {\n delete row._locale\n }\n if (typeof row._index === 'number') {\n i = row._index\n delete row._index\n }\n\n acc.push(\n traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: row,\n deletions,\n fieldPrefix: '',\n fields: block.flattenedFields,\n numbers,\n parentIsLocalized: parentIsLocalized || field.localized,\n path: `${blockFieldPath}.${i}`,\n relationships,\n table: row,\n texts,\n withinArrayOrBlockLocale,\n }),\n )\n\n return acc\n }\n } else {\n acc.push({})\n }\n\n return acc\n }, [])\n }\n }\n\n return result\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (typeof field.relationTo === 'string' && !('hasMany' in field && field.hasMany)) {\n if (\n isLocalized &&\n config.localization &&\n config.localization.locales &&\n Array.isArray(table?._locales)\n ) {\n table._locales.forEach((localeRow) => {\n result[field.name] = { [localeRow._locale]: localeRow[fieldName] }\n })\n } else {\n valuesToTransform.push({ ref: result, table })\n }\n } else {\n const relationPathMatch = relationships[`${sanitizedPath}${field.name}`]\n\n if (!relationPathMatch) {\n if ('hasMany' in field && field.hasMany) {\n if (isLocalized && config.localization && config.localization.locales) {\n result[field.name] = {\n [config.localization.defaultLocale]: [],\n }\n } else {\n result[field.name] = []\n }\n }\n\n return result\n }\n\n if (isLocalized) {\n result[field.name] = {}\n const relationsByLocale: Record<string, Record<string, unknown>[]> = {}\n\n relationPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!relationsByLocale[row.locale]) {\n relationsByLocale[row.locale] = []\n }\n relationsByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(relationsByLocale).forEach(([locale, relations]) => {\n transformRelationship({\n field,\n locale,\n ref: result,\n relations,\n })\n })\n } else {\n transformRelationship({\n field,\n ref: result,\n relations: relationPathMatch,\n withinArrayOrBlockLocale,\n })\n }\n return result\n }\n }\n\n if (field.type === 'join') {\n const { limit = field.defaultLimit ?? 10 } =\n joinQuery?.[`${fieldPrefix.replaceAll('_', '.')}${field.name}`] || {}\n\n // raw hasMany results from SQLite\n if (typeof fieldData === 'string') {\n fieldData = JSON.parse(fieldData)\n }\n\n let fieldResult:\n | { docs: unknown[]; hasNextPage: boolean }\n | Record<string, { docs: unknown[]; hasNextPage: boolean }>\n if (Array.isArray(fieldData)) {\n if (isLocalized && adapter.payload.config.localization) {\n fieldResult = fieldData.reduce(\n (joinResult, row) => {\n if (typeof row.locale === 'string') {\n joinResult[row.locale].docs.push(row.id)\n }\n\n return joinResult\n },\n\n // initialize with defaults so empty won't be undefined\n adapter.payload.config.localization.localeCodes.reduce((acc, code) => {\n acc[code] = {\n docs: [],\n hasNextPage: false,\n }\n return acc\n }, {}),\n )\n Object.keys(fieldResult).forEach((locale) => {\n fieldResult[locale].hasNextPage = fieldResult[locale].docs.length > limit\n fieldResult[locale].docs = fieldResult[locale].docs.slice(0, limit)\n })\n } else {\n const hasNextPage = limit !== 0 && fieldData.length > limit\n fieldResult = {\n docs: (hasNextPage ? fieldData.slice(0, limit) : fieldData).map(\n ({ id, relationTo }) => {\n if (relationTo) {\n return { relationTo, value: id }\n }\n return { id }\n },\n ),\n hasNextPage,\n }\n }\n }\n\n result[field.name] = fieldResult\n return result\n }\n\n if (field.type === 'text' && field?.hasMany) {\n const textPathMatch = texts[`${sanitizedPath}${field.name}`]\n if (!textPathMatch) {\n return result\n }\n\n if (isLocalized) {\n result[field.name] = {}\n const textsByLocale: Record<string, Record<string, unknown>[]> = {}\n\n textPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!textsByLocale[row.locale]) {\n textsByLocale[row.locale] = []\n }\n textsByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(textsByLocale).forEach(([locale, texts]) => {\n transformHasManyText({\n field,\n locale,\n ref: result,\n textRows: texts,\n })\n })\n } else {\n transformHasManyText({\n field,\n ref: result,\n textRows: textPathMatch,\n withinArrayOrBlockLocale,\n })\n }\n\n return result\n }\n\n if (field.type === 'number' && field.hasMany) {\n const numberPathMatch = numbers[`${sanitizedPath}${field.name}`]\n if (!numberPathMatch) {\n return result\n }\n\n if (isLocalized) {\n result[field.name] = {}\n const numbersByLocale: Record<string, Record<string, unknown>[]> = {}\n\n numberPathMatch.forEach((row) => {\n if (typeof row.locale === 'string') {\n if (!numbersByLocale[row.locale]) {\n numbersByLocale[row.locale] = []\n }\n numbersByLocale[row.locale].push(row)\n }\n })\n\n Object.entries(numbersByLocale).forEach(([locale, numbers]) => {\n transformHasManyNumber({\n field,\n locale,\n numberRows: numbers,\n ref: result,\n })\n })\n } else {\n transformHasManyNumber({\n field,\n numberRows: numberPathMatch,\n ref: result,\n withinArrayOrBlockLocale,\n })\n }\n\n return result\n }\n\n if (field.type === 'select' && field.hasMany) {\n if (Array.isArray(fieldData)) {\n if (isLocalized) {\n result[field.name] = fieldData.reduce((selectResult, row) => {\n if (typeof row.locale === 'string') {\n if (!selectResult[row.locale]) {\n selectResult[row.locale] = []\n }\n selectResult[row.locale].push(row.value)\n }\n\n return selectResult\n }, {})\n } else {\n let selectData = fieldData\n if (withinArrayOrBlockLocale) {\n selectData = selectData.filter(({ locale }) => locale === withinArrayOrBlockLocale)\n }\n result[field.name] = selectData.map(({ value }) => value)\n }\n }\n return result\n }\n\n if (isLocalized && Array.isArray(table._locales)) {\n if (!table._locales.length && adapter.payload.config.localization) {\n adapter.payload.config.localization.localeCodes.forEach((_locale) =>\n (table._locales as unknown[]).push({ _locale }),\n )\n }\n\n table._locales.forEach((localeRow) => {\n valuesToTransform.push({\n ref: localizedFieldData,\n table: {\n ...table,\n ...localeRow,\n },\n })\n })\n } else {\n valuesToTransform.push({ ref: result, table })\n }\n\n valuesToTransform.forEach(({ ref, table }) => {\n const fieldData = table[`${fieldPrefix || ''}${field.name}`]\n const locale = table?._locale\n let val = fieldData\n\n switch (field.type) {\n case 'date': {\n if (typeof fieldData === 'string') {\n val = new Date(fieldData).toISOString()\n }\n\n break\n }\n\n case 'group':\n case 'tab': {\n const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`\n const groupData = {}\n const locale = table._locale as string\n const refKey = isLocalized && locale ? locale : field.name\n\n if (isLocalized && locale) {\n delete table._locale\n }\n ref[refKey] = traverseFields<Record<string, unknown>>({\n adapter,\n blocks,\n config,\n dataRef: groupData as Record<string, unknown>,\n deletions,\n fieldPrefix: groupFieldPrefix,\n fields: field.flattenedFields,\n numbers,\n parentIsLocalized: parentIsLocalized || field.localized,\n path: `${sanitizedPath}${field.name}`,\n relationships,\n table,\n texts,\n withinArrayOrBlockLocale: locale || withinArrayOrBlockLocale,\n })\n\n if ('_order' in ref) {\n delete ref._order\n }\n\n return\n }\n\n case 'number': {\n if (typeof fieldData === 'string') {\n val = Number.parseFloat(fieldData)\n }\n\n break\n }\n\n case 'point': {\n if (typeof fieldData === 'string') {\n val = JSON.parse(fieldData)\n }\n\n break\n }\n\n case 'relationship':\n case 'upload': {\n if (\n val &&\n typeof field.relationTo === 'string' &&\n adapter.payload.collections[field.relationTo].customIDType === 'number'\n ) {\n val = Number(val)\n }\n\n break\n }\n case 'text': {\n if (typeof fieldData === 'string') {\n val = String(fieldData)\n }\n\n break\n }\n\n default: {\n break\n }\n }\n if (typeof locale === 'string') {\n ref[locale] = val\n } else {\n result[field.name] = val\n }\n })\n\n if (Object.keys(localizedFieldData).length > 0) {\n result[field.name] = localizedFieldData\n }\n\n return result\n\n return result\n }, dataRef)\n\n if (Array.isArray(table._locales)) {\n deletions.push(() => delete table._locales)\n }\n\n return formatted as T\n}\n"],"names":["fieldIsVirtual","fieldShouldBeLocalized","transformHasManyNumber","transformHasManyText","transformRelationship","traverseFields","adapter","blocks","config","dataRef","deletions","fieldPrefix","fields","joinQuery","numbers","parentIsLocalized","path","relationships","table","texts","withinArrayOrBlockLocale","sanitizedPath","formatted","reduce","result","field","fieldName","name","fieldData","localizedFieldData","valuesToTransform","push","isLocalized","type","Array","isArray","arrayResult","row","_locale","locale","data","_uuid","id","rowResult","flattenedFields","localized","_order","acc","i","blockFieldPath","blocksByPath","forEach","Object","entries","localizedBlocks","map","block","payload","blockType","blockReferences","find","slug","blockResult","localization","localeCodes","localeIndex","length","_index","relationTo","hasMany","locales","_locales","localeRow","ref","relationPathMatch","defaultLocale","relationsByLocale","relations","limit","defaultLimit","replaceAll","JSON","parse","fieldResult","joinResult","docs","code","hasNextPage","keys","slice","value","textPathMatch","textsByLocale","textRows","numberPathMatch","numbersByLocale","numberRows","selectResult","selectData","filter","val","Date","toISOString","groupFieldPrefix","groupData","refKey","Number","parseFloat","collections","customIDType","String"],"mappings":"AAEA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAgB;AAKvE,SAASC,sBAAsB,QAAQ,qBAAoB;AAC3D,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,SAASC,qBAAqB,QAAQ,oBAAmB;AA8DzD,iDAAiD;AACjD,kDAAkD;AAClD,OAAO,MAAMC,iBAAiB,CAAoC,EAChEC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,WAAW,EACXC,MAAM,EACNC,SAAS,EACTC,OAAO,EACPC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,KAAK,EACLC,KAAK,EACLC,wBAAwB,EACL;IACnB,MAAMC,gBAAgBL,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAGA;IAE1C,MAAMM,YAAYV,OAAOW,MAAM,CAAC,CAACC,QAAQC;QACvC,IAAIzB,eAAeyB,QAAQ;YACzB,OAAOD;QACT;QAEA,MAAME,YAAY,GAAGf,eAAe,KAAKc,MAAME,IAAI,EAAE;QACrD,IAAIC,YAAYV,KAAK,CAACQ,UAAU;QACh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wBAEA;oBACF;gBAEA,KAAK;oBAAU;wBACb,IAAI,OAAOlB,cAAc,UAAU;4BACjCwE,MAAMM,OAAOC,UAAU,CAAC/E;wBAC1B;wBAEA;oBACF;gBAEA,KAAK;oBAAS;wBACZ,IAAI,OAAOA,cAAc,UAAU;4BACjCwE,MAAMnB,KAAKC,KAAK,CAACtD;wBACnB;wBAEA;oBACF;gBAEA,KAAK;gBACL,KAAK;oBAAU;wBACb,IACEwE,OACA,OAAO3E,MAAM2C,UAAU,KAAK,YAC5B9D,QAAQmD,OAAO,CAACmD,WAAW,CAACnF,MAAM2C,UAAU,CAAC,CAACyC,YAAY,KAAK,UAC/D;4BACAT,MAAMM,OAAON;wBACf;wBAEA;oBACF;gBACA,KAAK;oBAAQ;wBACX,IAAI,OAAOxE,cAAc,UAAU;4BACjCwE,MAAMU,OAAOlF;wBACf;wBAEA;oBACF;gBAEA;oBAAS;wBACP;oBACF;YACF;YACA,IAAI,OAAOW,WAAW,UAAU;gBAC9BkC,GAAG,CAAClC,OAAO,GAAG6D;YAChB,OAAO;gBACL5E,MAAM,CAACC,MAAME,IAAI,CAAC,GAAGyE;YACvB;QACF;QAEA,IAAIhD,OAAOoC,IAAI,CAAC3D,oBAAoBqC,MAAM,GAAG,GAAG;YAC9C1C,MAAM,CAACC,MAAME,IAAI,CAAC,GAAGE;QACvB;QAEA,OAAOL;QAEP,OAAOA;IACT,GAAGf;IAEH,IAAIyB,MAAMC,OAAO,CAACjB,MAAMqD,QAAQ,GAAG;QACjC7D,UAAUqB,IAAI,CAAC,IAAM,OAAOb,MAAMqD,QAAQ;IAC5C;IAEA,OAAOjD;AACT,EAAC"}
@@ -13,6 +13,7 @@ type Args = {
13
13
  field: FlattenedArrayField;
14
14
  locale?: string;
15
15
  numbers: Record<string, unknown>[];
16
+ parentIsLocalized: boolean;
16
17
  path: string;
17
18
  relationships: Record<string, unknown>[];
18
19
  relationshipsToDelete: RelationshipToDelete[];
@@ -26,6 +27,6 @@ type Args = {
26
27
  */
27
28
  withinArrayOrBlockLocale?: string;
28
29
  };
29
- export declare const transformArray: ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => ArrayRowToInsert[];
30
+ export declare const transformArray: ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, parentIsLocalized, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => ArrayRowToInsert[];
30
31
  export {};
31
32
  //# sourceMappingURL=array.d.ts.map
@@ -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;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAK1F,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,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,EAA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ACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAChC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,cAAc,+MAiBxB,IAAI,uBAoEN,CAAA"}
@@ -1,6 +1,7 @@
1
+ import { fieldShouldBeLocalized } from 'payload/shared';
1
2
  import { isArrayOfRows } from '../../utilities/isArrayOfRows.js';
2
3
  import { traverseFields } from './traverseFields.js';
3
- export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
4
+ export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, parentIsLocalized, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
4
5
  const newRows = [];
5
6
  const hasUUID = adapter.tables[arrayTableName]._uuid;
6
7
  if (isArrayOfRows(data)) {
@@ -26,7 +27,10 @@ export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks,
26
27
  _locale: locale
27
28
  };
28
29
  }
29
- if (field.localized) {
30
+ if (fieldShouldBeLocalized({
31
+ field,
32
+ parentIsLocalized
33
+ }) && locale) {
30
34
  newRow.row._locale = locale;
31
35
  }
32
36
  if (withinArrayOrBlockLocale) {
@@ -45,6 +49,7 @@ export const transformArray = ({ adapter, arrayTableName, baseTableName, blocks,
45
49
  insideArrayOrBlock: true,
46
50
  locales: newRow.locales,
47
51
  numbers,
52
+ parentIsLocalized: parentIsLocalized || field.localized,
48
53
  parentTableName: arrayTableName,
49
54
  path: `${path || ''}${field.name}.${i}.`,
50
55
  relationships,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/array.ts"],"sourcesContent":["import type { FlattenedArrayField } from 'payload'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } 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 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 /**\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 path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\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 (field.localized) {\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 parentTableName: arrayTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n withinArrayOrBlockLocale,\n })\n\n newRows.push(newRow)\n })\n }\n\n return newRows\n}\n"],"names":["isArrayOfRows","traverseFields","transformArray","adapter","arrayTableName","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","withinArrayOrBlockLocale","newRows","hasUUID","tables","_uuid","forEach","arrayRow","i","newRow","arrays","locales","row","_order","id","_locale","localized","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","parentTableName","name","push"],"mappings":"AAKA,SAASA,aAAa,QAAQ,mCAAkC;AAChE,SAASC,cAAc,QAAQ,sBAAqB;AA4BpD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,wBAAwB,EACnB;IACL,MAAMC,UAA8B,EAAE;IAEtC,MAAMC,UAAUhB,QAAQiB,MAAM,CAAChB,eAAe,CAACiB,KAAK;IAEpD,IAAIrB,cAAcQ,OAAO;QACvBA,KAAKc,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,IAAIpB,QAAQ;gBACVe,OAAOE,OAAO,CAACjB,OAAO,GAAG;oBACvBqB,SAASrB;gBACX;YACF;YAEA,IAAID,MAAMuB,SAAS,EAAE;gBACnBP,OAAOG,GAAG,CAACG,OAAO,GAAGrB;YACvB;YAEA,IAAIO,0BAA0B;gBAC5BQ,OAAOG,GAAG,CAACG,OAAO,GAAGd;YACvB;YAEAhB,eAAe;gBACbE;gBACAuB,QAAQD,OAAOC,MAAM;gBACrBrB;gBACAC;gBACAC;gBACA0B,cAAc;gBACdzB,MAAMe;gBACNW,aAAa;gBACbC,QAAQ1B,MAAM2B,eAAe;gBAC7BC,oBAAoB;gBACpBV,SAASF,OAAOE,OAAO;gBACvBhB;gBACA2B,iBAAiBlC;gBACjBQ,MAAM,GAAGA,QAAQ,KAAKH,MAAM8B,IAAI,CAAC,CAAC,EAAEf,EAAE,CAAC,CAAC;gBACxCX;gBACAC;gBACAc,KAAKH,OAAOG,GAAG;gBACfb;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 { ArrayRowToInsert, BlockRowToInsert, RelationshipToDelete } 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 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 /**\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 parentIsLocalized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\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 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 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","parentIsLocalized","path","relationships","relationshipsToDelete","selects","texts","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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oBAAoB;gBACpBT,SAASF,OAAOE,OAAO;gBACvBjB;gBACAC,mBAAmBA,qBAAqBH,MAAM6B,SAAS;gBACvDC,iBAAiBnC;gBACjBS,MAAM,GAAGA,QAAQ,KAAKJ,MAAM+B,IAAI,CAAC,CAAC,EAAEf,EAAE,CAAC,CAAC;gBACxCX;gBACAC;gBACAc,KAAKH,OAAOG,GAAG;gBACfb;gBACAC;gBACAC;YACF;YAEAC,QAAQsB,IAAI,CAACf;QACf;IACF;IAEA,OAAOP;AACT,EAAC"}
@@ -12,6 +12,7 @@ type Args = {
12
12
  field: FlattenedBlocksField;
13
13
  locale?: string;
14
14
  numbers: Record<string, unknown>[];
15
+ parentIsLocalized: boolean;
15
16
  path: string;
16
17
  relationships: Record<string, unknown>[];
17
18
  relationshipsToDelete: RelationshipToDelete[];
@@ -25,6 +26,6 @@ type Args = {
25
26
  */
26
27
  withinArrayOrBlockLocale?: string;
27
28
  };
28
- export declare const transformBlocks: ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
29
+ export declare const transformBlocks: ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, parentIsLocalized, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
29
30
  export {};
30
31
  //# sourceMappingURL=blocks.d.ts.map
@@ -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;AAInE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAIxE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,M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AAC,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,CAAC,EAAE,CAAA;IAClC,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;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AACD,eAAO,MAAM,eAAe,+LAgBzB,IAAI,SA6EN,CAAA"}
@@ -1,6 +1,7 @@
1
+ import { fieldShouldBeLocalized } from 'payload/shared';
1
2
  import toSnakeCase from 'to-snake-case';
2
3
  import { traverseFields } from './traverseFields.js';
3
- export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
4
+ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete, data, field, locale, numbers, parentIsLocalized, path, relationships, relationshipsToDelete, selects, texts, withinArrayOrBlockLocale })=>{
4
5
  data.forEach((blockRow, i)=>{
5
6
  if (typeof blockRow.blockType !== 'string') {
6
7
  return;
@@ -21,7 +22,10 @@ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete
21
22
  _path: `${path}${field.name}`
22
23
  }
23
24
  };
24
- if (field.localized && locale) {
25
+ if (fieldShouldBeLocalized({
26
+ field,
27
+ parentIsLocalized
28
+ }) && locale) {
25
29
  newRow.row._locale = locale;
26
30
  }
27
31
  if (withinArrayOrBlockLocale) {
@@ -51,6 +55,7 @@ export const transformBlocks = ({ adapter, baseTableName, blocks, blocksToDelete
51
55
  insideArrayOrBlock: true,
52
56
  locales: newRow.locales,
53
57
  numbers,
58
+ parentIsLocalized: parentIsLocalized || field.localized,
54
59
  parentTableName: blockTableName,
55
60
  path: `${path || ''}${field.name}.${i}.`,
56
61
  relationships,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transform/write/blocks.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedBlocksField } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from '../../types.js'\nimport type { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\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 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 /**\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 path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\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 if (!blocks[blockType]) {\n blocks[blockType] = []\n }\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 (field.localized && locale) {\n newRow.row._locale = locale\n }\n if (withinArrayOrBlockLocale) {\n newRow.row._locale = withinArrayOrBlockLocale\n }\n\n const blockTableName = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)\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 parentTableName: blockTableName,\n path: `${path || ''}${field.name}.${i}.`,\n relationships,\n relationshipsToDelete,\n row: newRow.row,\n selects,\n texts,\n withinArrayOrBlockLocale,\n })\n\n blocks[blockType].push(newRow)\n })\n}\n"],"names":["toSnakeCase","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","path","relationships","relationshipsToDelete","selects","texts","withinArrayOrBlockLocale","forEach","blockRow","i","blockType","matchedBlock","payload","blockReferences","find","block","slug","newRow","arrays","locales","row","_order","_path","name","localized","_locale","blockTableName","tableNameMap","get","hasUUID","tables","_uuid","id","columnPrefix","fieldPrefix","fields","flattenedFields","insideArrayOrBlock","parentTableName","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAKvC,SAASC,cAAc,QAAQ,sBAAqB;AA0BpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc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AAE;YAC9B,OAAOxB,SAASwB,EAAE;QACpB;QAEAzC,eAAe;YACbE;YACAyB,QAAQD,OAAOC,MAAM;YACrBxB;YACAC;YACAC;YACAqC,cAAc;YACdpC,MAAMW;YACN0B,aAAa;YACbC,QAAQxB,aAAayB,eAAe;YACpCC,oBAAoB;YACpBlB,SAASF,OAAOE,OAAO;YACvBnB;YACAsC,iBAAiBZ;YACjBzB,MAAM,GAAGA,QAAQ,KAAKH,MAAMyB,IAAI,CAAC,CAAC,EAAEd,EAAE,CAAC,CAAC;YACxCP;YACAC;YACAiB,KAAKH,OAAOG,GAAG;YACfhB;YACAC;YACAC;QACF;QAEAX,MAAM,CAACe,UAAU,CAAC6B,IAAI,CAACtB;IACzB;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 { BlockRowToInsert, RelationshipToDelete } from './types.js'\n\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 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 /**\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 parentIsLocalized,\n path,\n relationships,\n relationshipsToDelete,\n selects,\n texts,\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 if (!blocks[blockType]) {\n blocks[blockType] = []\n }\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 = adapter.tableNameMap.get(`${baseTableName}_blocks_${blockType}`)\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 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 withinArrayOrBlockLocale,\n })\n\n blocks[blockType].push(newRow)\n })\n}\n"],"names":["fieldShouldBeLocalized","toSnakeCase","traverseFields","transformBlocks","adapter","baseTableName","blocks","blocksToDelete","data","field","locale","numbers","parentIsLocalized","path","relationships","relationshipsToDelete","selects","texts","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;AAKvC,SAASC,cAAc,QAAQ,sBAAqB;AA2BpD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,OAAO,EACPC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,iBAAiB,EACjBC,IAAI,EACJC,aAAa,EACbC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,wBAAwB,EACnB;IACLV,KAAKW,OAAO,CAAC,CAACC,UAAUC;QACtB,IAAI,OAAOD,SAASE,SAAS,KAAK,UAAU;YAC1C;QACF;QAEA,MAAMC,eACJnB,QAAQoB,OAAO,CAAClB,MAAM,CAACc,SAASE,SAAS,CAAC,IACzC,AAACb,CAAAA,MAAMgB,eAAe,IAAIhB,MAAMH,MAAM,AAAD,EAAGoB,IAAI,CAC3C,CAACC,QAAU,OAAOA,UAAU,YAAYA,MAAMC,IAAI,KAAKR,SAASE,SAAS;QAG7E,IAAI,CAACC,cAAc;YACjB;QACF;QACA,MAAMD,YAAYrB,YAAYmB,SAASE,SAAS;QAEhD,IAAI,CAAChB,MAAM,CAACgB,UAAU,EAAE;YACtBhB,MAAM,CAACgB,UAAU,GAAG,EAAE;QACxB;QAEA,MAAMO,SAA2B;YAC/BC,QAAQ,CAAC;YACTC,SAAS,CAAC;YACVC,KAAK;gBACHC,QAAQZ,IAAI;gBACZa,OAAO,GAAGrB,OAAOJ,MAAM0B,IAAI,EAAE;YAC/B;QACF;QAEA,IAAInC,uBAAuB;YAAES;YAAOG;QAAkB,MAAMF,QAAQ;YAClEmB,OAAOG,GAAG,CAACI,OAAO,GAAG1B;QACvB;QACA,IAAIQ,0BAA0B;YAC5BW,OAAOG,GAAG,CAACI,OAAO,GAAGlB;QACvB;QAEA,MAAMmB,iBAAiBjC,QAAQkC,YAAY,CAACC,GAAG,CAAC,GAAGlC,cAAc,QAAQ,EAAEiB,WAAW;QAEtF,MAAMkB,UAAUpC,QAAQqC,MAAM,CAACJ,eAAe,CAACK,KAAK;QAEpD,+CAA+C;QAC/C,sCAAsC;QACtC,4CAA4C;QAC5C,6CAA6C;QAC7C,+DAA+D;QAC/D,IAAIF,SAAS;YACXX,OAAOG,GAAG,CAACU,KAAK,GAAGtB,SAASuB,EAAE;YAC9B,OAAOvB,SAASuB,EAAE;QACpB;QAEAzC,eAAe;YACbE;YACA0B,QAAQD,OAAOC,MAAM;YACrBzB;YACAC;YACAC;YACAqC,cAAc;YACdpC,MAAMY;YACNyB,aAAa;YACbC,QAAQvB,aAAawB,eAAe;YACpCC,oBAAoB;YACpBjB,SAASF,OAAOE,OAAO;YACvBpB;YACAC,mBAAmBA,qBAAqBH,MAAMwC,SAAS;YACvDC,iBAAiBb;YACjBxB,MAAM,GAAGA,QAAQ,KAAKJ,MAAM0B,IAAI,CAAC,CAAC,EAAEd,EAAE,CAAC,CAAC;YACxCP;YACAC;YACAiB,KAAKH,OAAOG,GAAG;YACfhB;YACAC;YACAC;QACF;QAEAZ,MAAM,CAACgB,UAAU,CAAC6B,IAAI,CAACtB;IACzB;AACF,EAAC"}
@@ -5,9 +5,10 @@ type Args = {
5
5
  adapter: DrizzleAdapter;
6
6
  data: Record<string, unknown>;
7
7
  fields: FlattenedField[];
8
+ parentIsLocalized?: boolean;
8
9
  path?: string;
9
10
  tableName: string;
10
11
  };
11
- export declare const transformForWrite: ({ adapter, data, fields, path, tableName, }: Args) => RowToInsert;
12
+ export declare const transformForWrite: ({ adapter, data, fields, parentIsLocalized, path, tableName, }: Args) => RowToInsert;
12
13
  export {};
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -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,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,iBAAiB,gDAM3B,IAAI,KAAG,WAuCT,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,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,mEAO3B,IAAI,KAAG,WAwCT,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { traverseFields } from './traverseFields.js';
2
- export const transformForWrite = ({ adapter, data, fields, path = '', tableName })=>{
2
+ export const transformForWrite = ({ adapter, data, fields, parentIsLocalized, path = '', tableName })=>{
3
3
  // Split out the incoming data into rows to insert / delete
4
4
  const rowToInsert = {
5
5
  arrays: {},
@@ -27,6 +27,7 @@ export const transformForWrite = ({ adapter, data, fields, path = '', tableName
27
27
  fields,
28
28
  locales: rowToInsert.locales,
29
29
  numbers: rowToInsert.numbers,
30
+ parentIsLocalized,
30
31
  parentTableName: tableName,
31
32
  path,
32
33
  relationships: rowToInsert.relationships,
@@ -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 fields: FlattenedField[]\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\n fields,\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 relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\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 fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\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 })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","fields","path","tableName","rowToInsert","arrays","blocks","blocksToDelete","Set","locales","numbers","relationships","relationshipsToDelete","row","selects","texts","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAUpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,MAAM,EACNC,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,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;IACX;IAEA,mDAAmD;IACnD,oBAAoB;IACpBlB,eAAe;QACbE;QACAM,QAAQD,YAAYC,MAAM;QAC1BW,eAAeb;QACfG,QAAQF,YAAYE,MAAM;QAC1BC,gBAAgBH,YAAYG,cAAc;QAC1CU,cAAc;QACdjB;QACAkB,aAAa;QACbjB;QACAQ,SAASL,YAAYK,OAAO;QAC5BC,SAASN,YAAYM,OAAO;QAC5BS,iBAAiBhB;QACjBD;QACAS,eAAeP,YAAYO,aAAa;QACxCC,uBAAuBR,YAAYQ,qBAAqB;QACxDC,KAAKT,YAAYS,GAAG;QACpBC,SAASV,YAAYU,OAAO;QAC5BC,OAAOX,YAAYW,KAAK;IAC1B;IAEA,OAAOX;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 fields: FlattenedField[]\n parentIsLocalized?: boolean\n path?: string\n tableName: string\n}\n\nexport const transformForWrite = ({\n adapter,\n data,\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 relationships: [],\n relationshipsToDelete: [],\n row: {},\n selects: {},\n texts: [],\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 fieldPrefix: '',\n fields,\n locales: rowToInsert.locales,\n numbers: rowToInsert.numbers,\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 })\n\n return rowToInsert\n}\n"],"names":["traverseFields","transformForWrite","adapter","data","fields","parentIsLocalized","path","tableName","rowToInsert","arrays","blocks","blocksToDelete","Set","locales","numbers","relationships","relationshipsToDelete","row","selects","texts","baseTableName","columnPrefix","fieldPrefix","parentTableName"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAWpD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,OAAO,EACPC,IAAI,EACJC,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,eAAe,EAAE;QACjBC,uBAAuB,EAAE;QACzBC,KAAK,CAAC;QACNC,SAAS,CAAC;QACVC,OAAO,EAAE;IACX;IAEA,mDAAmD;IACnD,oBAAoB;IACpBnB,eAAe;QACbE;QACAO,QAAQD,YAAYC,MAAM;QAC1BW,eAAeb;QACfG,QAAQF,YAAYE,MAAM;QAC1BC,gBAAgBH,YAAYG,cAAc;QAC1CU,cAAc;QACdlB;QACAmB,aAAa;QACblB;QACAS,SAASL,YAAYK,OAAO;QAC5BC,SAASN,YAAYM,OAAO;QAC5BT;QACAkB,iBAAiBhB;QACjBD;QACAS,eAAeP,YAAYO,aAAa;QACxCC,uBAAuBR,YAAYQ,qBAAqB;QACxDC,KAAKT,YAAYS,GAAG;QACpBC,SAASV,YAAYU,OAAO;QAC5BC,OAAOX,YAAYW,KAAK;IAC1B;IAEA,OAAOX;AACT,EAAC"}
@@ -36,6 +36,7 @@ type Args = {
36
36
  [locale: string]: Record<string, unknown>;
37
37
  };
38
38
  numbers: Record<string, unknown>[];
39
+ parentIsLocalized: boolean;
39
40
  /**
40
41
  * This is the name of the parent table
41
42
  */
@@ -54,6 +55,6 @@ type Args = {
54
55
  */
55
56
  withinArrayOrBlockLocale?: string;
56
57
  };
57
- export declare const traverseFields: ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock, locales, numbers, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
58
+ export declare const traverseFields: ({ adapter, arrays, baseTableName, blocks, blocksToDelete, columnPrefix, data, existingLocales, fieldPrefix, fields, forcedLocale, insideArrayOrBlock, locales, numbers, parentIsLocalized, parentTableName, path, relationships, relationshipsToDelete, row, selects, texts, withinArrayOrBlockLocale, }: Args) => void;
58
59
  export {};
59
60
  //# sourceMappingURL=traverseFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/transform/write/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAU1F,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,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