@payloadcms/drizzle 4.0.0-internal.31ba7ee → 4.0.0-internal.3a6afb1

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 (148) hide show
  1. package/dist/exports/postgres.d.ts +4 -1
  2. package/dist/exports/postgres.d.ts.map +1 -1
  3. package/dist/exports/postgres.js +4 -1
  4. package/dist/exports/postgres.js.map +1 -1
  5. package/dist/exports/sqlite.d.ts +2 -1
  6. package/dist/exports/sqlite.d.ts.map +1 -1
  7. package/dist/exports/sqlite.js +2 -1
  8. package/dist/exports/sqlite.js.map +1 -1
  9. package/dist/find/buildPolymorphicJoinQuery.d.ts +3 -2
  10. package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -1
  11. package/dist/find/buildPolymorphicJoinQuery.js +16 -5
  12. package/dist/find/buildPolymorphicJoinQuery.js.map +1 -1
  13. package/dist/find/buildPolymorphicJoinWhere.js +2 -2
  14. package/dist/find/buildPolymorphicJoinWhere.js.map +1 -1
  15. package/dist/find/createPolymorphicJoinWherePlan.d.ts +2 -1
  16. package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -1
  17. package/dist/find/createPolymorphicJoinWherePlan.js +14 -5
  18. package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -1
  19. package/dist/find/traverseFields.d.ts.map +1 -1
  20. package/dist/find/traverseFields.js +1 -0
  21. package/dist/find/traverseFields.js.map +1 -1
  22. package/dist/index.d.ts +1 -8
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -8
  25. package/dist/index.js.map +1 -1
  26. package/dist/postgres/findDocumentLocks.d.ts +4 -0
  27. package/dist/postgres/findDocumentLocks.d.ts.map +1 -0
  28. package/dist/postgres/findDocumentLocks.js +22 -0
  29. package/dist/postgres/findDocumentLocks.js.map +1 -0
  30. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts +26 -0
  31. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.d.ts.map +1 -0
  32. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js +61 -0
  33. package/dist/postgres/predefinedMigrations/localize-status/getGeneratedColumnType.js.map +1 -0
  34. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts +13 -0
  35. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.d.ts.map +1 -0
  36. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js +17 -0
  37. package/dist/postgres/predefinedMigrations/localize-status/getMigrationDB.js.map +1 -0
  38. package/dist/postgres/predefinedMigrations/localize-status/index.d.ts.map +1 -1
  39. package/dist/postgres/predefinedMigrations/localize-status/index.js +73 -10
  40. package/dist/postgres/predefinedMigrations/localize-status/index.js.map +1 -1
  41. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts +35 -0
  42. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
  43. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js +185 -0
  44. package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
  45. package/dist/postgres/predefinedMigrations/v2-v3/index.js +1 -1
  46. package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
  47. package/dist/postgres/requireDrizzleKit.d.ts +4 -0
  48. package/dist/postgres/requireDrizzleKit.d.ts.map +1 -1
  49. package/dist/postgres/requireDrizzleKit.js +16 -10
  50. package/dist/postgres/requireDrizzleKit.js.map +1 -1
  51. package/dist/queries/buildOperatorConstraint.d.ts.map +1 -1
  52. package/dist/queries/buildOperatorConstraint.js +16 -0
  53. package/dist/queries/buildOperatorConstraint.js.map +1 -1
  54. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  55. package/dist/queries/getTableColumnFromPath.js +6 -1
  56. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  57. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  58. package/dist/queries/sanitizeQueryValue.js +6 -2
  59. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  60. package/dist/schema/build.d.ts.map +1 -1
  61. package/dist/schema/build.js +54 -5
  62. package/dist/schema/build.js.map +1 -1
  63. package/dist/schema/traverseFields.d.ts.map +1 -1
  64. package/dist/schema/traverseFields.js +71 -14
  65. package/dist/schema/traverseFields.js.map +1 -1
  66. package/dist/sqlite/createRequireDrizzleKit.d.ts +6 -0
  67. package/dist/sqlite/createRequireDrizzleKit.d.ts.map +1 -0
  68. package/dist/sqlite/createRequireDrizzleKit.js +15 -0
  69. package/dist/sqlite/createRequireDrizzleKit.js.map +1 -0
  70. package/dist/sqlite/execute.js.map +1 -1
  71. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts +15 -0
  72. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
  73. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js +114 -0
  74. package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
  75. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  76. package/dist/transactions/beginTransaction.js +13 -5
  77. package/dist/transactions/beginTransaction.js.map +1 -1
  78. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  79. package/dist/transactions/commitTransaction.js +2 -5
  80. package/dist/transactions/commitTransaction.js.map +1 -1
  81. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  82. package/dist/transform/read/traverseFields.js +11 -3
  83. package/dist/transform/read/traverseFields.js.map +1 -1
  84. package/dist/transform/write/array.d.ts +3 -2
  85. package/dist/transform/write/array.d.ts.map +1 -1
  86. package/dist/transform/write/array.js +2 -1
  87. package/dist/transform/write/array.js.map +1 -1
  88. package/dist/transform/write/blocks.d.ts +3 -2
  89. package/dist/transform/write/blocks.d.ts.map +1 -1
  90. package/dist/transform/write/blocks.js +5 -2
  91. package/dist/transform/write/blocks.js.map +1 -1
  92. package/dist/transform/write/index.d.ts.map +1 -1
  93. package/dist/transform/write/index.js +5 -1
  94. package/dist/transform/write/index.js.map +1 -1
  95. package/dist/transform/write/traverseFields.d.ts +2 -1
  96. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  97. package/dist/transform/write/traverseFields.js +31 -2
  98. package/dist/transform/write/traverseFields.js.map +1 -1
  99. package/dist/transform/write/types.d.ts +10 -0
  100. package/dist/transform/write/types.d.ts.map +1 -1
  101. package/dist/transform/write/types.js.map +1 -1
  102. package/dist/types.d.ts +2 -2
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js.map +1 -1
  105. package/dist/updateOne.d.ts.map +1 -1
  106. package/dist/updateOne.js +14 -1
  107. package/dist/updateOne.js.map +1 -1
  108. package/dist/upsertRow/deleteExistingRowsByPath.d.ts +6 -1
  109. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  110. package/dist/upsertRow/deleteExistingRowsByPath.js +21 -3
  111. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  112. package/dist/upsertRow/index.d.ts.map +1 -1
  113. package/dist/upsertRow/index.js +34 -10
  114. package/dist/upsertRow/index.js.map +1 -1
  115. package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
  116. package/dist/utilities/blocksToJsonMigrator.js +7 -18
  117. package/dist/utilities/blocksToJsonMigrator.js.map +1 -1
  118. package/dist/utilities/buildCreateMigration.js +1 -1
  119. package/dist/utilities/buildCreateMigration.js.map +1 -1
  120. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts +15 -0
  121. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts.map +1 -0
  122. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +110 -0
  123. package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -0
  124. package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
  125. package/dist/utilities/createSchemaGenerator.js +24 -13
  126. package/dist/utilities/createSchemaGenerator.js.map +1 -1
  127. package/dist/utilities/executeSchemaHooks.js +1 -1
  128. package/dist/utilities/executeSchemaHooks.js.map +1 -1
  129. package/dist/utilities/fitIdentifierLength.d.ts +25 -0
  130. package/dist/utilities/fitIdentifierLength.d.ts.map +1 -0
  131. package/dist/utilities/fitIdentifierLength.js +35 -0
  132. package/dist/utilities/fitIdentifierLength.js.map +1 -0
  133. package/dist/utilities/formatGeneratedFile.d.ts +10 -0
  134. package/dist/utilities/formatGeneratedFile.d.ts.map +1 -0
  135. package/dist/utilities/formatGeneratedFile.js +58 -0
  136. package/dist/utilities/formatGeneratedFile.js.map +1 -0
  137. package/dist/utilities/getSizesToVariantsRenames.d.ts +54 -0
  138. package/dist/utilities/getSizesToVariantsRenames.d.ts.map +1 -0
  139. package/dist/utilities/getSizesToVariantsRenames.js +252 -0
  140. package/dist/utilities/getSizesToVariantsRenames.js.map +1 -0
  141. package/dist/utilities/getTransaction.js.map +1 -1
  142. package/dist/utilities/pushDevSchema.js +1 -1
  143. package/dist/utilities/pushDevSchema.js.map +1 -1
  144. package/package.json +17 -19
  145. package/dist/sqlite/requireDrizzleKit.d.ts +0 -3
  146. package/dist/sqlite/requireDrizzleKit.d.ts.map +0 -1
  147. package/dist/sqlite/requireDrizzleKit.js +0 -12
  148. package/dist/sqlite/requireDrizzleKit.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport {\n fieldAffectsData,\n fieldIsVirtual,\n fieldShouldBeLocalized,\n optionIsObject,\n} from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { getArrayRelationName } from '../utilities/getArrayRelationName.js'\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport {\n InternalBlockTableNameIndex,\n setInternalBlockIndex,\n validateExistingBlockIsIdentical,\n} from '../utilities/validateExistingBlockIsIdentical.js'\nimport { buildTable } from './build.js'\nimport { idToUUID } from './idToUUID.js'\nimport { withDefault } from './withDefault.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n blocksTableNameMap: Record<string, number>\n columnPrefix?: string\n columns: Record<string, RawColumn>\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: FlattenedField[]\n forceLocalized?: boolean\n indexes: Record<string, RawIndex>\n localesColumns: Record<string, RawColumn>\n localesIndexes: Record<string, RawIndex>\n newTableName: string\n parentIsLocalized: boolean\n parentTableName: string\n relationships: Set<string>\n relationsToBuild: RelationMap\n rootRelationsToBuild?: RelationMap\n rootTableIDColType: IDType\n rootTableName: string\n setColumnID: SetColumnID\n uniqueRelationships: Set<string>\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedField: boolean\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n}\n\nexport const traverseFields = ({\n adapter,\n blocksTableNameMap,\n columnPrefix,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentIsLocalized,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const throwValidationError = true\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyNumberField = false\n\n let parentIDColType: IDType = 'integer'\n\n const idColumn = columns.id\n\n if (idColumn && ['numeric', 'text', 'uuid', 'varchar'].includes(idColumn.type)) {\n parentIDColType = idColumn.type as IDType\n }\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') {\n return\n }\n if (fieldIsVirtual(field)) {\n return\n }\n\n let targetTable = columns\n let targetIndexes = indexes\n\n const columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n const fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`\n\n const isFieldLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n // If field is localized,\n // add the column to the locale table instead of main table\n if (\n adapter.payload.config.localization &&\n (isFieldLocalized || forceLocalized) &&\n field.type !== 'array' &&\n (field.type !== 'blocks' || adapter.blocksAsJSON) &&\n (('hasMany' in field && field.hasMany !== true) || !('hasMany' in field))\n ) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index || ['relationship', 'upload'].includes(field.type)) &&\n !['array', 'blocks', 'group'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true) &&\n !('relationTo' in field && Array.isArray(field.relationTo))\n ) {\n const unique = disableUnique !== true && field.unique\n if (unique) {\n const constraintValue = `${fieldPrefix || ''}${field.name}`\n if (!adapter.fieldConstraints?.[rootTableName]) {\n adapter.fieldConstraints[rootTableName] = {}\n }\n adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue\n }\n\n const indexName = buildIndexName({ name: `${newTableName}_${columnName}`, adapter })\n\n targetIndexes[indexName] = {\n name: indexName,\n on: isFieldLocalized ? [fieldName, '_locale'] : fieldName,\n unique,\n }\n }\n\n switch (field.type) {\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const baseColumns: Record<string, RawColumn> = {\n _order: {\n name: '_order',\n type: 'integer',\n notNull: true,\n },\n _parentID: {\n name: '_parent_id',\n type: parentIDColType,\n notNull: true,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n _orderIdx: {\n name: `${arrayTableName}_order_idx`,\n on: ['_order'],\n },\n _parentIDIdx: {\n name: `${arrayTableName}_parent_id_idx`,\n on: '_parentID',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n _parentIDFk: {\n name: `${arrayTableName}_parent_id_fk`,\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: parentTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes._localeIdx = {\n name: `${arrayTableName}_locale_idx`,\n on: '_locale',\n }\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(field.flattenedFields) : field.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n setColumnID,\n tableName: arrayTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalized,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n const relationName = getArrayRelationName({\n field,\n path: fieldName,\n tableName: arrayTableName,\n })\n\n relationsToBuild.set(relationName, {\n type: 'many',\n // arrays have their own localized table, independent of the base table.\n localized: false,\n target: arrayTableName,\n })\n\n const arrayRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: arrayTableName,\n },\n ],\n references: ['id'],\n relationName,\n to: parentTableName,\n },\n }\n\n if (\n hasLocalesTable({\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n ) {\n arrayRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: `${arrayTableName}${adapter.localesSuffix}`,\n }\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const arrayWithLocalized = localized\n ? `${arrayTableName}${adapter.localesSuffix}`\n : arrayTableName\n\n arrayRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: arrayWithLocalized,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n\n if (type === 'many') {\n arrayRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n\n adapter.rawRelations[arrayTableName] = arrayRelations\n\n break\n }\n case 'blocks': {\n if (adapter.blocksAsJSON) {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'jsonb',\n },\n field,\n )\n break\n }\n\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((_block) => {\n const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block\n\n let blockTableName = createTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const isLocalizedBlockTable =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (typeof blocksTableNameMap[blockTableName] === 'undefined') {\n blocksTableNameMap[blockTableName] = 1\n } else if (\n !adapter.rawTables[blockTableName] ||\n !validateExistingBlockIsIdentical({\n block,\n localized: isLocalizedBlockTable,\n parentIsLocalized,\n table: adapter.rawTables[blockTableName],\n tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`],\n })\n ) {\n blocksTableNameMap[blockTableName]++\n setInternalBlockIndex(block, blocksTableNameMap[blockTableName])\n blockTableName = `${blockTableName}_${blocksTableNameMap[blockTableName]}`\n }\n let relationName = `_blocks_${block.slug}`\n if (typeof block[InternalBlockTableNameIndex] !== 'undefined') {\n relationName = `_blocks_${block.slug}_${block[InternalBlockTableNameIndex]}`\n }\n\n if (!adapter.rawTables[blockTableName]) {\n const baseColumns: Record<string, RawColumn> = {\n _order: {\n name: '_order',\n type: 'integer',\n notNull: true,\n },\n _parentID: {\n name: '_parent_id',\n type: rootTableIDColType,\n notNull: true,\n },\n _path: {\n name: '_path',\n type: 'text',\n notNull: true,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n _orderIdx: {\n name: `${blockTableName}_order_idx`,\n on: '_order',\n },\n _parentIDIdx: {\n name: `${blockTableName}_parent_id_idx`,\n on: ['_parentID'],\n },\n _pathIdx: {\n name: `${blockTableName}_path_idx`,\n on: '_path',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n _parentIdFk: {\n name: `${blockTableName}_parent_id_fk`,\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: rootTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n if (isLocalizedBlockTable) {\n baseColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes._localeIdx = {\n name: `${blockTableName}_locale_idx`,\n on: '_locale',\n }\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(block.flattenedFields) : block.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n setColumnID,\n tableName: blockTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalizedBlockTable,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n const blockRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: blockTableName,\n },\n ],\n references: ['id'],\n relationName,\n to: rootTableName,\n },\n }\n\n if (\n hasLocalesTable({\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n ) {\n blockRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: `${blockTableName}${adapter.localesSuffix}`,\n }\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const blockWithLocalized = localized\n ? `${blockTableName}${adapter.localesSuffix}`\n : blockTableName\n\n blockRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: blockWithLocalized,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n\n if (type === 'many') {\n blockRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n\n adapter.rawRelations[blockTableName] = blockRelations\n }\n\n // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks\n rootRelationsToBuild.set(relationName, {\n type: 'many',\n // blocks are not localized on the parent table\n localized: false,\n target: blockTableName,\n })\n })\n\n break\n }\n case 'checkbox': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'boolean',\n },\n field,\n )\n\n break\n }\n\n case 'code':\n case 'email':\n case 'slug':\n case 'textarea': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'varchar',\n },\n field,\n )\n\n break\n }\n\n case 'date': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'timestamp',\n mode: 'string',\n precision: 3,\n withTimezone: true,\n },\n field,\n )\n\n break\n }\n\n case 'group':\n case 'tab': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n blocksTableNameMap,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.flattenedFields,\n forceLocalized: isFieldLocalized || Boolean(forceLocalized),\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || isFieldLocalized,\n })\n\n if (groupHasLocalizedField) {\n hasLocalizedField = true\n }\n if (groupHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (groupHasManyTextField) {\n hasManyTextField = true\n }\n if (groupHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (groupHasManyNumberField) {\n hasManyNumberField = true\n }\n if (groupHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n case 'json':\n case 'richText': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'jsonb',\n },\n field,\n )\n\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyNumberField = true\n }\n\n if (field.index) {\n hasManyNumberField = 'index'\n } else if (!hasManyNumberField) {\n hasManyNumberField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany number fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'numeric',\n },\n field,\n )\n }\n\n break\n }\n\n case 'point': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'geometry',\n },\n field,\n )\n\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n })\n\n const options = field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n })\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const baseColumns: Record<string, RawColumn> = {\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: parentIDColType,\n notNull: true,\n },\n value: {\n name: 'value',\n type: 'enum',\n enumName: createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n }),\n options,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n orderIdx: {\n name: `${selectTableName}_order_idx`,\n on: 'order',\n },\n parentIdx: {\n name: `${selectTableName}_parent_idx`,\n on: 'parent',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: `${selectTableName}_parent_fk`,\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: parentTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes.localeIdx = {\n name: `${selectTableName}_locale_idx`,\n on: 'locale',\n }\n }\n\n if (field.index) {\n baseIndexes.value = {\n name: `${selectTableName}_value_idx`,\n on: 'value',\n }\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull,\n disableUnique,\n fields: [],\n parentIsLocalized: parentIsLocalized || field.localized,\n rootTableName,\n setColumnID,\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, {\n type: 'many',\n // selects have their own localized table, independent of the base table.\n localized: false,\n target: selectTableName,\n })\n\n adapter.rawRelations[selectTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: selectTableName,\n },\n ],\n references: ['id'],\n relationName: fieldName,\n to: parentTableName,\n },\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'enum',\n enumName,\n options,\n },\n field,\n )\n }\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => {\n relationships.add(relation)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(relation)\n }\n })\n } else if (field.hasMany) {\n relationships.add(field.relationTo)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(field.relationTo)\n }\n } else {\n // simple relationships get a column on the targetTable with a foreign key to the relationTo table\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo))\n\n // get the id type of the related collection\n let colType: IDType = isUUIDType(adapter.idType) ? 'uuid' : 'integer'\n const relatedCollectionCustomID = relationshipConfig.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (relatedCollectionCustomID?.type === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomID?.type === 'text') {\n colType = 'varchar'\n }\n\n // make the foreign key column for relationship using the correct id column type\n targetTable[fieldName] = {\n name: `${columnName}_id`,\n type: colType,\n reference: {\n name: 'id',\n onDelete: 'set null',\n table: tableName,\n },\n }\n\n // add relationship to table\n relationsToBuild.set(fieldName, {\n type: 'one',\n localized: adapter.payload.config.localization && (isFieldLocalized || forceLocalized),\n target: tableName,\n })\n\n // add notNull when not required\n if (!disableNotNull && field.required && !field.admin?.condition) {\n targetTable[fieldName].notNull = true\n }\n break\n }\n\n if (\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock\n ) {\n hasLocalizedRelationshipField = true\n }\n\n break\n\n case 'text': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyTextField = true\n }\n\n if (field.index) {\n hasManyTextField = 'index'\n } else if (!hasManyTextField) {\n hasManyTextField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany text fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'varchar',\n },\n field,\n )\n }\n break\n }\n\n default:\n break\n }\n\n const condition = field.admin && field.admin.condition\n\n if (\n !disableNotNull &&\n targetTable[fieldName] &&\n 'required' in field &&\n field.required &&\n !condition\n ) {\n targetTable[fieldName].notNull = true\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldIsVirtual","fieldShouldBeLocalized","optionIsObject","toSnakeCase","createTableName","buildIndexName","getArrayRelationName","hasLocalesTable","isUUIDType","InternalBlockTableNameIndex","setInternalBlockIndex","validateExistingBlockIsIdentical","buildTable","idToUUID","withDefault","traverseFields","adapter","blocksTableNameMap","columnPrefix","columns","disableNotNull","disableRelsTableUnique","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentIsLocalized","parentTableName","relationships","relationsToBuild","rootRelationsToBuild","rootTableIDColType","rootTableName","setColumnID","uniqueRelationships","versions","withinLocalizedArrayOrBlock","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","idColumn","id","includes","type","forEach","field","name","targetTable","targetIndexes","columnName","fieldName","replace","isFieldLocalized","payload","config","localization","blocksAsJSON","hasMany","unique","index","Array","isArray","relationTo","constraintValue","fieldConstraints","indexName","on","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","prefix","versionsCustomName","baseColumns","_order","notNull","_parentID","baseIndexes","_orderIdx","_parentIDIdx","baseForeignKeys","_parentIDFk","foreignColumns","table","onDelete","isLocalized","_locale","locale","_localeIdx","subHasLocalizedManyNumberField","subHasLocalizedManyTextField","subHasLocalizedRelationshipField","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","flattenedFields","localized","rootRelationships","rootUniqueRelationships","tableName","relationName","path","set","target","arrayRelations","references","to","_locales","localesSuffix","key","arrayWithLocalized","rawRelations","blocks","_block","block","blockTableName","isLocalizedBlockTable","rawTables","tableLocales","slug","_path","_pathIdx","_parentIdFk","blockRelations","blockWithLocalized","mode","precision","withTimezone","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","enumName","options","map","option","value","selectTableName","order","parent","orderIdx","parentIdx","parentFk","localeIdx","relation","add","relationshipConfig","collections","tableNameMap","get","colType","idType","relatedCollectionCustomID","find","reference","required"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,UAAS;AAC9C,SACEC,gBAAgB,EAChBC,cAAc,EACdC,sBAAsB,EACtBC,cAAc,QACT,iBAAgB;AACvB,OAAOC,iBAAiB,gBAAe;AAavC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SACEC,2BAA2B,EAC3BC,qBAAqB,EACrBC,gCAAgC,QAC3B,mDAAkD;AACzD,SAASC,UAAU,QAAQ,aAAY;AACvC,SAASC,QAAQ,QAAQ,gBAAe;AACxC,SAASC,WAAW,QAAQ,mBAAkB;AA2C9C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,kBAAkB,EAClBC,YAAY,EACZC,OAAO,EACPC,cAAc,EACdC,sBAAsB,EACt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EA;YAEF,KAAK;gBAAQ;oBACX,IAAIW,MAAMY,OAAO,EAAE;wBACjB,MAAM6B,cACJlB,QAAQhB,oBAAoB7C,QAAQ8C,OAAO,CAACC,MAAM,CAACC,YAAY,KAC/DxB,+BACAf;wBAEF,IAAIsE,aAAa;4BACflD,4BAA4B;wBAC9B;wBAEA,IAAIS,MAAMc,KAAK,EAAE;4BACfxB,mBAAmB;wBACrB,OAAO,IAAI,CAACA,kBAAkB;4BAC5BA,mBAAmB;wBACrB;wBAEA,IAAIU,MAAMa,MAAM,EAAE;4BAChB,MAAM,IAAIrE,qBACR;wBAEJ;oBACF,OAAO;wBACL0D,WAAW,CAACG,UAAU,GAAG7C,YACvB;4BACEyC,MAAMG;4BACNN,MAAM;wBACR,GACAE;oBAEJ;oBACA;gBACF;YAEA;gBACE;QACJ;QAEA,MAAMyB,YAAYzB,MAAMwB,KAAK,IAAIxB,MAAMwB,KAAK,CAACC,SAAS;QAEtD,IACE,CAAC3D,kBACDoC,WAAW,CAACG,UAAU,IACtB,cAAcL,SACdA,MAAMiH,QAAQ,IACd,CAACxF,WACD;YACAvB,WAAW,CAACG,UAAU,CAAC0B,OAAO,GAAG;QACnC;IACF;IAEA,OAAO;QACL3C;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport {\n fieldAffectsData,\n fieldIsVirtual,\n fieldShouldBeLocalized,\n optionIsObject,\n} from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type {\n DrizzleAdapter,\n IDType,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RelationMap,\n SetColumnID,\n} from '../types.js'\n\nimport { createTableName } from '../createTableName.js'\nimport { buildIndexName } from '../utilities/buildIndexName.js'\nimport { fitIdentifierLength } from '../utilities/fitIdentifierLength.js'\nimport { getArrayRelationName } from '../utilities/getArrayRelationName.js'\nimport { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { isUUIDType } from '../utilities/isUUIDType.js'\nimport {\n InternalBlockTableNameIndex,\n setInternalBlockIndex,\n validateExistingBlockIsIdentical,\n} from '../utilities/validateExistingBlockIsIdentical.js'\nimport { buildTable } from './build.js'\nimport { idToUUID } from './idToUUID.js'\nimport { withDefault } from './withDefault.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n blocksTableNameMap: Record<string, number>\n columnPrefix?: string\n columns: Record<string, RawColumn>\n disableNotNull: boolean\n disableRelsTableUnique?: boolean\n disableUnique?: boolean\n fieldPrefix?: string\n fields: FlattenedField[]\n forceLocalized?: boolean\n indexes: Record<string, RawIndex>\n localesColumns: Record<string, RawColumn>\n localesIndexes: Record<string, RawIndex>\n newTableName: string\n parentIsLocalized: boolean\n parentTableName: string\n relationships: Set<string>\n relationsToBuild: RelationMap\n rootRelationsToBuild?: RelationMap\n rootTableIDColType: IDType\n rootTableName: string\n setColumnID: SetColumnID\n uniqueRelationships: Set<string>\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedField: boolean\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n}\n\nexport const traverseFields = ({\n adapter,\n blocksTableNameMap,\n columnPrefix,\n columns,\n disableNotNull,\n disableRelsTableUnique,\n disableUnique = false,\n fieldPrefix,\n fields,\n forceLocalized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName,\n parentIsLocalized,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const throwValidationError = true\n let hasLocalizedField = false\n let hasLocalizedRelationshipField = false\n let hasManyTextField: 'index' | boolean = false\n let hasLocalizedManyTextField = false\n let hasManyNumberField: 'index' | boolean = false\n let hasLocalizedManyNumberField = false\n\n let parentIDColType: IDType = 'integer'\n\n const idColumn = columns.id\n\n if (idColumn && ['numeric', 'text', 'uuid', 'varchar'].includes(idColumn.type)) {\n parentIDColType = idColumn.type as IDType\n }\n\n fields.forEach((field) => {\n if ('name' in field && field.name === 'id') {\n return\n }\n if (fieldIsVirtual(field)) {\n return\n }\n\n let targetTable = columns\n let targetIndexes = indexes\n\n const columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(\n field.name,\n )}`\n const fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`\n\n const isFieldLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n // If field is localized,\n // add the column to the locale table instead of main table\n if (\n adapter.payload.config.localization &&\n (isFieldLocalized || forceLocalized) &&\n field.type !== 'array' &&\n (field.type !== 'blocks' || adapter.blocksAsJSON) &&\n (('hasMany' in field && field.hasMany !== true) || !('hasMany' in field))\n ) {\n hasLocalizedField = true\n targetTable = localesColumns\n targetIndexes = localesIndexes\n }\n\n if (\n (field.unique || field.index || ['relationship', 'upload'].includes(field.type)) &&\n !['array', 'blocks', 'group'].includes(field.type) &&\n !('hasMany' in field && field.hasMany === true) &&\n !('relationTo' in field && Array.isArray(field.relationTo))\n ) {\n const unique = disableUnique !== true && field.unique\n if (unique) {\n const constraintValue = `${fieldPrefix || ''}${field.name}`\n if (!adapter.fieldConstraints?.[rootTableName]) {\n adapter.fieldConstraints[rootTableName] = {}\n }\n adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue\n }\n\n const indexName = buildIndexName({ name: `${newTableName}_${columnName}`, adapter })\n\n targetIndexes[indexName] = {\n name: indexName,\n on: isFieldLocalized ? [fieldName, '_locale'] : fieldName,\n unique,\n }\n }\n\n switch (field.type) {\n case 'array': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const arrayTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const baseColumns: Record<string, RawColumn> = {\n _order: {\n name: '_order',\n type: 'integer',\n notNull: true,\n },\n _parentID: {\n name: '_parent_id',\n type: parentIDColType,\n notNull: true,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n _orderIdx: {\n name: fitIdentifierLength({ name: `${arrayTableName}_order`, adapter, suffix: '_idx' }),\n on: ['_order'],\n },\n _parentIDIdx: {\n name: fitIdentifierLength({\n name: `${arrayTableName}_parent_id`,\n adapter,\n suffix: '_idx',\n }),\n on: '_parentID',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n _parentIDFk: {\n name: fitIdentifierLength({\n name: `${arrayTableName}_parent_id`,\n adapter,\n suffix: '_fk',\n }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: parentTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes._localeIdx = {\n name: fitIdentifierLength({\n name: `${arrayTableName}_locale`,\n adapter,\n suffix: '_idx',\n }),\n on: '_locale',\n }\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(field.flattenedFields) : field.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n setColumnID,\n tableName: arrayTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalized,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n const relationName = getArrayRelationName({\n field,\n path: fieldName,\n tableName: arrayTableName,\n })\n\n relationsToBuild.set(relationName, {\n type: 'many',\n // arrays have their own localized table, independent of the base table.\n localized: false,\n target: arrayTableName,\n })\n\n const arrayRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: arrayTableName,\n },\n ],\n references: ['id'],\n relationName,\n to: parentTableName,\n },\n }\n\n if (\n hasLocalesTable({\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n ) {\n arrayRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: `${arrayTableName}${adapter.localesSuffix}`,\n }\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const arrayWithLocalized = localized\n ? `${arrayTableName}${adapter.localesSuffix}`\n : arrayTableName\n\n arrayRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: arrayWithLocalized,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n\n if (type === 'many') {\n arrayRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n\n adapter.rawRelations[arrayTableName] = arrayRelations\n\n break\n }\n case 'blocks': {\n if (adapter.blocksAsJSON) {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'jsonb',\n },\n field,\n )\n break\n }\n\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((_block) => {\n const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block\n\n let blockTableName = createTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const isLocalizedBlockTable =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (typeof blocksTableNameMap[blockTableName] === 'undefined') {\n blocksTableNameMap[blockTableName] = 1\n } else if (\n !adapter.rawTables[blockTableName] ||\n !validateExistingBlockIsIdentical({\n block,\n localized: isLocalizedBlockTable,\n parentIsLocalized,\n table: adapter.rawTables[blockTableName],\n tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`],\n })\n ) {\n blocksTableNameMap[blockTableName]++\n setInternalBlockIndex(block, blocksTableNameMap[blockTableName])\n blockTableName = `${blockTableName}_${blocksTableNameMap[blockTableName]}`\n }\n let relationName = `_blocks_${block.slug}`\n if (typeof block[InternalBlockTableNameIndex] !== 'undefined') {\n relationName = `_blocks_${block.slug}_${block[InternalBlockTableNameIndex]}`\n }\n\n if (!adapter.rawTables[blockTableName]) {\n const baseColumns: Record<string, RawColumn> = {\n _order: {\n name: '_order',\n type: 'integer',\n notNull: true,\n },\n _parentID: {\n name: '_parent_id',\n type: rootTableIDColType,\n notNull: true,\n },\n _path: {\n name: '_path',\n type: 'text',\n notNull: true,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n _orderIdx: {\n name: fitIdentifierLength({\n name: `${blockTableName}_order`,\n adapter,\n suffix: '_idx',\n }),\n on: '_order',\n },\n _parentIDIdx: {\n name: fitIdentifierLength({\n name: `${blockTableName}_parent_id`,\n adapter,\n suffix: '_idx',\n }),\n on: ['_parentID'],\n },\n _pathIdx: {\n name: fitIdentifierLength({\n name: `${blockTableName}_path`,\n adapter,\n suffix: '_idx',\n }),\n on: '_path',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n _parentIdFk: {\n name: fitIdentifierLength({\n name: `${blockTableName}_parent_id`,\n adapter,\n suffix: '_fk',\n }),\n columns: ['_parentID'],\n foreignColumns: [\n {\n name: 'id',\n table: rootTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n if (isLocalizedBlockTable) {\n baseColumns._locale = {\n name: '_locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes._localeIdx = {\n name: fitIdentifierLength({\n name: `${blockTableName}_locale`,\n adapter,\n suffix: '_idx',\n }),\n on: '_locale',\n }\n }\n\n const {\n hasLocalizedManyNumberField: subHasLocalizedManyNumberField,\n hasLocalizedManyTextField: subHasLocalizedManyTextField,\n hasLocalizedRelationshipField: subHasLocalizedRelationshipField,\n hasManyNumberField: subHasManyNumberField,\n hasManyTextField: subHasManyTextField,\n relationsToBuild: subRelationsToBuild,\n } = buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(block.flattenedFields) : block.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n setColumnID,\n tableName: blockTableName,\n versions,\n withinLocalizedArrayOrBlock: isLocalizedBlockTable,\n })\n\n if (subHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = subHasLocalizedManyNumberField\n }\n\n if (subHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = subHasLocalizedRelationshipField\n }\n\n if (subHasLocalizedManyTextField) {\n hasLocalizedManyTextField = subHasLocalizedManyTextField\n }\n\n if (subHasManyTextField) {\n if (!hasManyTextField || subHasManyTextField === 'index') {\n hasManyTextField = subHasManyTextField\n }\n }\n\n if (subHasManyNumberField) {\n if (!hasManyNumberField || subHasManyNumberField === 'index') {\n hasManyNumberField = subHasManyNumberField\n }\n }\n\n const blockRelations: Record<string, RawRelation> = {\n _parentID: {\n type: 'one',\n fields: [\n {\n name: '_parentID',\n table: blockTableName,\n },\n ],\n references: ['id'],\n relationName,\n to: rootTableName,\n },\n }\n\n if (\n hasLocalesTable({\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n ) {\n blockRelations._locales = {\n type: 'many',\n relationName: '_locales',\n to: `${blockTableName}${adapter.localesSuffix}`,\n }\n }\n\n subRelationsToBuild.forEach(({ type, localized, target }, key) => {\n if (type === 'one') {\n const blockWithLocalized = localized\n ? `${blockTableName}${adapter.localesSuffix}`\n : blockTableName\n\n blockRelations[key] = {\n type: 'one',\n fields: [\n {\n name: key,\n table: blockWithLocalized,\n },\n ],\n references: ['id'],\n relationName: key,\n to: target,\n }\n }\n\n if (type === 'many') {\n blockRelations[key] = {\n type: 'many',\n relationName: key,\n to: target,\n }\n }\n })\n\n adapter.rawRelations[blockTableName] = blockRelations\n }\n\n // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks\n rootRelationsToBuild.set(relationName, {\n type: 'many',\n // blocks are not localized on the parent table\n localized: false,\n target: blockTableName,\n })\n })\n\n break\n }\n case 'checkbox': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'boolean',\n },\n field,\n )\n\n break\n }\n\n case 'code':\n case 'email':\n case 'slug':\n case 'textarea': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'varchar',\n },\n field,\n )\n\n break\n }\n\n case 'date': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'timestamp',\n mode: 'string',\n precision: 3,\n withTimezone: true,\n },\n field,\n )\n\n break\n }\n\n case 'group':\n case 'tab': {\n const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n const {\n hasLocalizedField: groupHasLocalizedField,\n hasLocalizedManyNumberField: groupHasLocalizedManyNumberField,\n hasLocalizedManyTextField: groupHasLocalizedManyTextField,\n hasLocalizedRelationshipField: groupHasLocalizedRelationshipField,\n hasManyNumberField: groupHasManyNumberField,\n hasManyTextField: groupHasManyTextField,\n } = traverseFields({\n adapter,\n blocksTableNameMap,\n columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.flattenedFields,\n forceLocalized: isFieldLocalized || Boolean(forceLocalized),\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || isFieldLocalized,\n })\n\n if (groupHasLocalizedField) {\n hasLocalizedField = true\n }\n if (groupHasLocalizedRelationshipField) {\n hasLocalizedRelationshipField = true\n }\n if (groupHasManyTextField) {\n hasManyTextField = true\n }\n if (groupHasLocalizedManyTextField) {\n hasLocalizedManyTextField = true\n }\n if (groupHasManyNumberField) {\n hasManyNumberField = true\n }\n if (groupHasLocalizedManyNumberField) {\n hasLocalizedManyNumberField = true\n }\n break\n }\n\n case 'json':\n case 'richText': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'jsonb',\n },\n field,\n )\n\n break\n }\n\n case 'number': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyNumberField = true\n }\n\n if (field.index) {\n hasManyNumberField = 'index'\n } else if (!hasManyNumberField) {\n hasManyNumberField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany number fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'numeric',\n },\n field,\n )\n }\n\n break\n }\n\n case 'point': {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'geometry',\n },\n field,\n )\n\n break\n }\n\n case 'radio':\n case 'select': {\n const enumName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n })\n\n const options = field.options.map((option) => {\n if (optionIsObject(option)) {\n return option.value\n }\n\n return option\n })\n\n if (field.type === 'select' && field.hasMany) {\n const selectTableName = createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `${newTableName}_`,\n throwValidationError,\n versionsCustomName: versions,\n })\n\n const baseColumns: Record<string, RawColumn> = {\n order: {\n name: 'order',\n type: 'integer',\n notNull: true,\n },\n parent: {\n name: 'parent_id',\n type: parentIDColType,\n notNull: true,\n },\n value: {\n name: 'value',\n type: 'enum',\n enumName: createTableName({\n adapter,\n config: field,\n parentTableName: newTableName,\n prefix: `enum_${newTableName}_`,\n target: 'enumName',\n throwValidationError,\n }),\n options,\n },\n }\n\n const baseIndexes: Record<string, RawIndex> = {\n orderIdx: {\n name: fitIdentifierLength({\n name: `${selectTableName}_order`,\n adapter,\n suffix: '_idx',\n }),\n on: 'order',\n },\n parentIdx: {\n name: fitIdentifierLength({\n name: `${selectTableName}_parent`,\n adapter,\n suffix: '_idx',\n }),\n on: 'parent',\n },\n }\n\n const baseForeignKeys: Record<string, RawForeignKey> = {\n parentFk: {\n name: fitIdentifierLength({\n name: `${selectTableName}_parent`,\n adapter,\n suffix: '_fk',\n }),\n columns: ['parent'],\n foreignColumns: [\n {\n name: 'id',\n table: parentTableName,\n },\n ],\n onDelete: 'cascade',\n },\n }\n\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n baseColumns.locale = {\n name: 'locale',\n type: 'enum',\n locale: true,\n notNull: true,\n }\n\n baseIndexes.localeIdx = {\n name: fitIdentifierLength({\n name: `${selectTableName}_locale`,\n adapter,\n suffix: '_idx',\n }),\n on: 'locale',\n }\n }\n\n if (field.index) {\n baseIndexes.value = {\n name: fitIdentifierLength({\n name: `${selectTableName}_value`,\n adapter,\n suffix: '_idx',\n }),\n on: 'value',\n }\n }\n\n buildTable({\n adapter,\n baseColumns,\n baseForeignKeys,\n baseIndexes,\n blocksTableNameMap,\n disableNotNull,\n disableUnique,\n fields: [],\n parentIsLocalized: parentIsLocalized || field.localized,\n rootTableName,\n setColumnID,\n tableName: selectTableName,\n versions,\n })\n\n relationsToBuild.set(fieldName, {\n type: 'many',\n // selects have their own localized table, independent of the base table.\n localized: false,\n target: selectTableName,\n })\n\n adapter.rawRelations[selectTableName] = {\n parent: {\n type: 'one',\n fields: [\n {\n name: 'parent',\n table: selectTableName,\n },\n ],\n references: ['id'],\n relationName: fieldName,\n to: parentTableName,\n },\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'enum',\n enumName,\n options,\n },\n field,\n )\n }\n break\n }\n\n case 'relationship':\n case 'upload':\n if (Array.isArray(field.relationTo)) {\n field.relationTo.forEach((relation) => {\n relationships.add(relation)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(relation)\n }\n })\n } else if (field.hasMany) {\n relationships.add(field.relationTo)\n if (field.unique && !disableUnique && !disableRelsTableUnique) {\n uniqueRelationships.add(field.relationTo)\n }\n } else {\n // simple relationships get a column on the targetTable with a foreign key to the relationTo table\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo))\n\n // get the id type of the related collection\n let colType: IDType = isUUIDType(adapter.idType) ? 'uuid' : 'integer'\n const relatedCollectionCustomID = relationshipConfig.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (relatedCollectionCustomID?.type === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomID?.type === 'text') {\n colType = 'varchar'\n }\n\n // make the foreign key column for relationship using the correct id column type\n targetTable[fieldName] = {\n name: `${columnName}_id`,\n type: colType,\n reference: {\n name: 'id',\n onDelete: 'set null',\n table: tableName,\n },\n }\n\n // add relationship to table\n relationsToBuild.set(fieldName, {\n type: 'one',\n localized: adapter.payload.config.localization && (isFieldLocalized || forceLocalized),\n target: tableName,\n })\n\n // add notNull when not required\n if (!disableNotNull && field.required && !field.admin?.condition) {\n targetTable[fieldName].notNull = true\n }\n break\n }\n\n if (\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock\n ) {\n hasLocalizedRelationshipField = true\n }\n\n break\n\n case 'text': {\n if (field.hasMany) {\n const isLocalized =\n Boolean(isFieldLocalized && adapter.payload.config.localization) ||\n withinLocalizedArrayOrBlock ||\n forceLocalized\n\n if (isLocalized) {\n hasLocalizedManyTextField = true\n }\n\n if (field.index) {\n hasManyTextField = 'index'\n } else if (!hasManyTextField) {\n hasManyTextField = true\n }\n\n if (field.unique) {\n throw new InvalidConfiguration(\n 'Unique is not supported in Postgres for hasMany text fields.',\n )\n }\n } else {\n targetTable[fieldName] = withDefault(\n {\n name: columnName,\n type: 'varchar',\n },\n field,\n )\n }\n break\n }\n\n default:\n break\n }\n\n const condition = field.admin && field.admin.condition\n\n if (\n !disableNotNull &&\n targetTable[fieldName] &&\n 'required' in field &&\n field.required &&\n !condition\n ) {\n targetTable[fieldName].notNull = true\n }\n })\n\n return {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldIsVirtual","fieldShouldBeLocalized","optionIsObject","toSnakeCase","createTableName","buildIndexName","fitIdentifierLength","getArrayRelationName","hasLocalesTable","isUUIDType","InternalBlockTableNameIndex","setInternalBlockIndex","validateExistingBlockIsIdentical","buildTable","idToUUID","withDefault","traverseFields","adapter","blocksTableNameMap","columnPrefix","columns","disableNotNull","disableRelsTableUnique","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","parentIsLocalized","parentTableName","relationships","relationsToBuild","rootRelationsToBuild","rootTableIDColType","rootTableName","setColumnID","uniqueRelationships","versions","withinLocalizedArrayOrBlock","throwValidationError","hasLocalizedField","hasLocalizedRelationshipField","hasManyTextField","hasLocalizedManyTextField","hasManyNumberField","hasLocalizedManyNumberField","parentIDColType","idColumn","id","includes","type","forEach","field","name","targetTable","targetIndexes","columnName","fieldName","replace","isFieldLocalized","payload","config","localization","blocksAsJSON","hasMany","unique","index","Array","isArray","relationTo","constraintValue","fieldConstraints","indexName","on","disableNotNullFromHere","Boolean","admin","condition","arrayTableName","prefix","versionsCustomName","baseColumns","_order","notNull","_parentID","baseIndexes","_orderIdx","suffix","_parentIDIdx","baseForeignKeys","_parentIDFk","foreignColumns","table","onDelete","isLocalized","_locale","locale","_localeIdx","subHasLocalizedManyNumberField","subHasLocalizedManyTextField","subHasLocalizedRelationshipField","subHasManyNumberField","subHasManyTextField","subRelationsToBuild","flattenedFields","localized","rootRelationships","rootUniqueRelationships","tableName","relationName","path","set","target","arrayRelations","references","to","_locales","localesSuffix","key","arrayWithLocalized","rawRelations","blocks","_block","block","blockTableName","isLocalizedBlockTable","rawTables","tableLocales","slug","_path","_pathIdx","_parentIdFk","blockRelations","blockWithLocalized","mode","precision","withTimezone","groupHasLocalizedField","groupHasLocalizedManyNumberField","groupHasLocalizedManyTextField","groupHasLocalizedRelationshipField","groupHasManyNumberField","groupHasManyTextField","enumName","options","map","option","value","selectTableName","order","parent","orderIdx","parentIdx","parentFk","localeIdx","relation","add","relationshipConfig","collections","tableNameMap","get","colType","idType","relatedC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Q,IAAI,CAAClH,MAAMwB,KAAK,EAAEC,WAAW;wBAChEvB,WAAW,CAACG,UAAU,CAAC0B,OAAO,GAAG;oBACnC;oBACA;gBACF;gBAEA,IACER,QAAQhB,oBAAoB7C,QAAQ8C,OAAO,CAACC,MAAM,CAACC,YAAY,KAC/DxB,6BACA;oBACAG,gCAAgC;gBAClC;gBAEA;YAEF,KAAK;gBAAQ;oBACX,IAAIW,MAAMY,OAAO,EAAE;wBACjB,MAAM8B,cACJnB,QAAQhB,oBAAoB7C,QAAQ8C,OAAO,CAACC,MAAM,CAACC,YAAY,KAC/DxB,+BACAf;wBAEF,IAAIuE,aAAa;4BACfnD,4BAA4B;wBAC9B;wBAEA,IAAIS,MAAMc,KAAK,EAAE;4BACfxB,mBAAmB;wBACrB,OAAO,IAAI,CAACA,kBAAkB;4BAC5BA,mBAAmB;wBACrB;wBAEA,IAAIU,MAAMa,MAAM,EAAE;4BAChB,MAAM,IAAItE,qBACR;wBAEJ;oBACF,OAAO;wBACL2D,WAAW,CAACG,UAAU,GAAG7C,YACvB;4BACEyC,MAAMG;4BACNN,MAAM;wBACR,GACAE;oBAEJ;oBACA;gBACF;YAEA;gBACE;QACJ;QAEA,MAAMyB,YAAYzB,MAAMwB,KAAK,IAAIxB,MAAMwB,KAAK,CAACC,SAAS;QAEtD,IACE,CAAC3D,kBACDoC,WAAW,CAACG,UAAU,IACtB,cAAcL,SACdA,MAAMkH,QAAQ,IACd,CAACzF,WACD;YACAvB,WAAW,CAACG,UAAU,CAAC0B,OAAO,GAAG;QACnC;IACF;IAEA,OAAO;QACL3C;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
@@ -0,0 +1,6 @@
1
+ import type { RequireDrizzleKit } from '../types.js';
2
+ export declare const createRequireDrizzleKit: ({ from, }: {
3
+ /** Module URL of the adapter that owns the drizzle-kit dependency. */
4
+ from: string;
5
+ }) => RequireDrizzleKit;
6
+ //# sourceMappingURL=createRequireDrizzleKit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRequireDrizzleKit.d.ts","sourceRoot":"","sources":["../../src/sqlite/createRequireDrizzleKit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,eAAO,MAAM,uBAAuB,cAG/B;IACD,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAA;CACb,KAAG,iBAeH,CAAA"}
@@ -0,0 +1,15 @@
1
+ import nodeModule from 'node:module';
2
+ import { dynamicImport } from 'payload';
3
+ export const createRequireDrizzleKit = ({ from })=>async ()=>{
4
+ // Use the default import to preserve Node's loader instead of Webpack's createRequire transform.
5
+ const require = nodeModule.createRequire(from);
6
+ const { generateSQLiteDrizzleJson, generateSQLiteMigration, pushSQLiteSchema } = await dynamicImport(require.resolve('drizzle-kit/api'));
7
+ return {
8
+ generateDrizzleJson: generateSQLiteDrizzleJson,
9
+ generateMigration: generateSQLiteMigration,
10
+ // Drizzle Kit bundles separate ORM types; the owning adapter selects the matching dialect.
11
+ pushSchema: pushSQLiteSchema
12
+ };
13
+ };
14
+
15
+ //# sourceMappingURL=createRequireDrizzleKit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sqlite/createRequireDrizzleKit.ts"],"sourcesContent":["import type * as DrizzleKit from 'drizzle-kit/api'\n\nimport nodeModule from 'node:module'\nimport { dynamicImport } from 'payload'\n\nimport type { RequireDrizzleKit } from '../types.js'\n\nexport const createRequireDrizzleKit =\n ({\n from,\n }: {\n /** Module URL of the adapter that owns the drizzle-kit dependency. */\n from: string\n }): RequireDrizzleKit =>\n async () => {\n // Use the default import to preserve Node's loader instead of Webpack's createRequire transform.\n const require = nodeModule.createRequire(from)\n const { generateSQLiteDrizzleJson, generateSQLiteMigration, pushSQLiteSchema } =\n await dynamicImport<typeof DrizzleKit>(require.resolve('drizzle-kit/api'))\n\n return {\n generateDrizzleJson: generateSQLiteDrizzleJson,\n generateMigration: generateSQLiteMigration,\n // Drizzle Kit bundles separate ORM types; the owning adapter selects the matching dialect.\n pushSchema: pushSQLiteSchema as unknown as Awaited<\n ReturnType<RequireDrizzleKit>\n >['pushSchema'],\n }\n }\n"],"names":["nodeModule","dynamicImport","createRequireDrizzleKit","from","require","createRequire","generateSQLiteDrizzleJson","generateSQLiteMigration","pushSQLiteSchema","resolve","generateDrizzleJson","generateMigration","pushSchema"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,aAAa,QAAQ,UAAS;AAIvC,OAAO,MAAMC,0BACX,CAAC,EACCC,IAAI,EAIL,GACD;QACE,iGAAiG;QACjG,MAAMC,UAAUJ,WAAWK,aAAa,CAACF;QACzC,MAAM,EAAEG,yBAAyB,EAAEC,uBAAuB,EAAEC,gBAAgB,EAAE,GAC5E,MAAMP,cAAiCG,QAAQK,OAAO,CAAC;QAEzD,OAAO;YACLC,qBAAqBJ;YACrBK,mBAAmBJ;YACnB,2FAA2F;YAC3FK,YAAYJ;QAGd;IACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sqlite/execute.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { Execute } from './types.js'\n\nexport const execute: Execute<any> = function execute({ db, drizzle, raw, sql: statement }) {\n const executeFrom = (db ?? drizzle)\n\n if (raw) {\n const result = executeFrom.run(sql.raw(raw))\n return result\n } else {\n const result = executeFrom.run(statement)\n return result\n }\n}\n"],"names":["sql","execute","db","drizzle","raw","statement","executeFrom","result","run"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,UAAwB,SAASA,QAAQ,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,EAAEJ,KAAKK,SAAS,EAAE;IACxF,MAAMC,cAAeJ,MAAMC;IAE3B,IAAIC,KAAK;QACP,MAAMG,SAASD,YAAYE,GAAG,CAACR,IAAII,GAAG,CAACA;QACvC,OAAOG;IACT,OAAO;QACL,MAAMA,SAASD,YAAYE,GAAG,CAACH;QAC/B,OAAOE;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/sqlite/execute.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { Execute } from './types.js'\n\nexport const execute: Execute<any> = function execute({ db, drizzle, raw, sql: statement }) {\n const executeFrom = db ?? drizzle\n\n if (raw) {\n const result = executeFrom.run(sql.raw(raw))\n return result\n } else {\n const result = executeFrom.run(statement)\n return result\n }\n}\n"],"names":["sql","execute","db","drizzle","raw","statement","executeFrom","result","run"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,UAAwB,SAASA,QAAQ,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,EAAEJ,KAAKK,SAAS,EAAE;IACxF,MAAMC,cAAcJ,MAAMC;IAE1B,IAAIC,KAAK;QACP,MAAMG,SAASD,YAAYE,GAAG,CAACR,IAAII,GAAG,CAACA;QACvC,OAAOG;IACT,OAAO;QACL,MAAMA,SAASD,YAAYE,GAAG,CAACH;QAC/B,OAAOE;IACT;AACF,EAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Payload } from 'payload';
2
+ import type { SizesToVariantsDirection } from '../../../utilities/getSizesToVariantsRenames.js';
3
+ /**
4
+ * Moves every upload collection's stored image sizes between the legacy `sizes_*` columns and
5
+ * `variants_*` (main and versions tables), renaming each column in place so no data is copied.
6
+ * SQLite can't rename an index, so each index on a renamed column is dropped and recreated under
7
+ * the name the current schema expects. Skips columns that are already renamed, so it's safe to
8
+ * re-run.
9
+ */
10
+ export declare function migrateSqliteSizesToVariants({ db, direction, payload, }: {
11
+ db: any;
12
+ direction?: SizesToVariantsDirection;
13
+ payload: Payload;
14
+ }): Promise<void>;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sqlite/predefinedMigrations/sizes-to-variants/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAQ/F;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAAC,EACjD,EAAE,EACF,SAAgB,EAChB,OAAO,GACR,EAAE;IACD,EAAE,EAAE,GAAG,CAAA;IACP,SAAS,CAAC,EAAE,wBAAwB,CAAA;IACpC,OAAO,EAAE,OAAO,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8FhB"}
@@ -0,0 +1,114 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { assertNoSizesToVariantsColumnCollisions, getSizesToVariantsRenames, isGeneratedLegacyIndexName } from '../../../utilities/getSizesToVariantsRenames.js';
3
+ /**
4
+ * Moves every upload collection's stored image sizes between the legacy `sizes_*` columns and
5
+ * `variants_*` (main and versions tables), renaming each column in place so no data is copied.
6
+ * SQLite can't rename an index, so each index on a renamed column is dropped and recreated under
7
+ * the name the current schema expects. Skips columns that are already renamed, so it's safe to
8
+ * re-run.
9
+ */ export async function migrateSqliteSizesToVariants({ db, direction = 'up', payload }) {
10
+ const adapter = payload.db;
11
+ const plan = getSizesToVariantsRenames({
12
+ adapter,
13
+ direction
14
+ });
15
+ const plannedTables = [];
16
+ for (const tablePlan of plan){
17
+ const existingColumns = await getColumnNames({
18
+ db,
19
+ tableName: tablePlan.tableName
20
+ });
21
+ assertNoSizesToVariantsColumnCollisions({
22
+ columns: tablePlan.columns,
23
+ existingColumns,
24
+ tableName: tablePlan.tableName
25
+ });
26
+ plannedTables.push({
27
+ ...tablePlan,
28
+ existingColumns
29
+ });
30
+ }
31
+ for (const { columns, existingColumns, indexes, tableName } of plannedTables){
32
+ const columnsAfterRename = new Set(existingColumns);
33
+ let renamedCount = 0;
34
+ for (const { from, to } of columns){
35
+ if (!existingColumns.has(from) || existingColumns.has(to)) {
36
+ continue;
37
+ }
38
+ columnsAfterRename.delete(from);
39
+ columnsAfterRename.add(to);
40
+ await db.run(sql`
41
+ ALTER TABLE ${sql.identifier(tableName)}
42
+ RENAME COLUMN ${sql.identifier(from)} TO ${sql.identifier(to)}
43
+ `);
44
+ renamedCount++;
45
+ }
46
+ const existingIndexes = await getIndexes({
47
+ db,
48
+ tableName
49
+ });
50
+ for (const index of indexes){
51
+ if (!index.columns.every((column)=>columnsAfterRename.has(column))) {
52
+ continue;
53
+ }
54
+ const destinationIndex = existingIndexes.find(({ name })=>name === index.to);
55
+ const sourceIndex = destinationIndex ? undefined : index.from ? existingIndexes.find(({ name })=>name === index.from) : index.legacyNameBase ? existingIndexes.find(({ name, columns })=>columns.join(',') === index.columns.join(',') && isGeneratedLegacyIndexName({
56
+ indexName: name,
57
+ legacyNameBase: index.legacyNameBase
58
+ })) : undefined;
59
+ if (destinationIndex) {
60
+ if (destinationIndex.columns.join(',') !== index.columns.join(',') || destinationIndex.unique !== index.unique) {
61
+ throw new Error(`Cannot run the sizes-to-variants migration because index "${index.to}" on table "${tableName}" does not match the expected columns or uniqueness.`);
62
+ }
63
+ } else {
64
+ const unique = index.unique ? sql.raw('UNIQUE ') : sql.empty();
65
+ const columnList = sql.join(index.columns.map((column)=>sql.identifier(column)), sql.raw(', '));
66
+ await db.run(sql`
67
+ CREATE ${unique}INDEX ${sql.identifier(index.to)}
68
+ ON ${sql.identifier(tableName)} (${columnList})
69
+ `);
70
+ }
71
+ if (sourceIndex && sourceIndex.name !== index.to) {
72
+ await db.run(sql`DROP INDEX ${sql.identifier(sourceIndex.name)}`);
73
+ }
74
+ }
75
+ payload.logger.info({
76
+ msg: `sizes-to-variants (${direction}): renamed ${renamedCount} column(s) on "${tableName}"`
77
+ });
78
+ }
79
+ }
80
+ async function getColumnNames({ db, tableName }) {
81
+ const rows = await db.all(sql`SELECT name FROM pragma_table_info(${tableName})`);
82
+ return new Set(rows.map(({ name })=>name));
83
+ }
84
+ async function getIndexes({ db, tableName }) {
85
+ // `origin = 'c'` keeps only `CREATE INDEX` indexes, skipping SQLite's internal autoindexes.
86
+ const rows = await db.all(sql`
87
+ SELECT
88
+ il.name AS index_name,
89
+ il."unique" AS is_unique,
90
+ ii.name AS column_name,
91
+ ii.seqno AS seqno
92
+ FROM pragma_index_list(${tableName}) AS il
93
+ JOIN pragma_index_info(il.name) AS ii
94
+ WHERE il.origin = 'c'
95
+ ORDER BY il.name, ii.seqno
96
+ `);
97
+ const indexes = new Map();
98
+ for (const { column_name, index_name, is_unique } of rows){
99
+ const index = indexes.get(index_name) ?? {
100
+ columns: [],
101
+ unique: Boolean(is_unique)
102
+ };
103
+ index.columns.push(column_name);
104
+ indexes.set(index_name, index);
105
+ }
106
+ return [
107
+ ...indexes
108
+ ].map(([name, index])=>({
109
+ name,
110
+ ...index
111
+ }));
112
+ }
113
+
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/sqlite/predefinedMigrations/sizes-to-variants/index.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleAdapter } from '../../../types.js'\nimport type { SizesToVariantsDirection } from '../../../utilities/getSizesToVariantsRenames.js'\n\nimport {\n assertNoSizesToVariantsColumnCollisions,\n getSizesToVariantsRenames,\n isGeneratedLegacyIndexName,\n} from '../../../utilities/getSizesToVariantsRenames.js'\n\n/**\n * Moves every upload collection's stored image sizes between the legacy `sizes_*` columns and\n * `variants_*` (main and versions tables), renaming each column in place so no data is copied.\n * SQLite can't rename an index, so each index on a renamed column is dropped and recreated under\n * the name the current schema expects. Skips columns that are already renamed, so it's safe to\n * re-run.\n */\nexport async function migrateSqliteSizesToVariants({\n db,\n direction = 'up',\n payload,\n}: {\n db: any\n direction?: SizesToVariantsDirection\n payload: Payload\n}): Promise<void> {\n const adapter = payload.db as unknown as DrizzleAdapter\n const plan = getSizesToVariantsRenames({ adapter, direction })\n const plannedTables: Array<\n (typeof plan)[number] & {\n existingColumns: Set<string>\n }\n > = []\n\n for (const tablePlan of plan) {\n const existingColumns = await getColumnNames({ db, tableName: tablePlan.tableName })\n\n assertNoSizesToVariantsColumnCollisions({\n columns: tablePlan.columns,\n existingColumns,\n tableName: tablePlan.tableName,\n })\n\n plannedTables.push({ ...tablePlan, existingColumns })\n }\n\n for (const { columns, existingColumns, indexes, tableName } of plannedTables) {\n const columnsAfterRename = new Set(existingColumns)\n let renamedCount = 0\n\n for (const { from, to } of columns) {\n if (!existingColumns.has(from) || existingColumns.has(to)) {\n continue\n }\n\n columnsAfterRename.delete(from)\n columnsAfterRename.add(to)\n\n await db.run(sql`\n ALTER TABLE ${sql.identifier(tableName)}\n RENAME COLUMN ${sql.identifier(from)} TO ${sql.identifier(to)}\n `)\n renamedCount++\n }\n\n const existingIndexes = await getIndexes({ db, tableName })\n\n for (const index of indexes) {\n if (!index.columns.every((column) => columnsAfterRename.has(column))) {\n continue\n }\n\n const destinationIndex = existingIndexes.find(({ name }) => name === index.to)\n const sourceIndex = destinationIndex\n ? undefined\n : index.from\n ? existingIndexes.find(({ name }) => name === index.from)\n : index.legacyNameBase\n ? existingIndexes.find(\n ({ name, columns }) =>\n columns.join(',') === index.columns.join(',') &&\n isGeneratedLegacyIndexName({\n indexName: name,\n legacyNameBase: index.legacyNameBase,\n }),\n )\n : undefined\n\n if (destinationIndex) {\n if (\n destinationIndex.columns.join(',') !== index.columns.join(',') ||\n destinationIndex.unique !== index.unique\n ) {\n throw new Error(\n `Cannot run the sizes-to-variants migration because index \"${index.to}\" on table \"${tableName}\" does not match the expected columns or uniqueness.`,\n )\n }\n } else {\n const unique = index.unique ? sql.raw('UNIQUE ') : sql.empty()\n const columnList = sql.join(\n index.columns.map((column) => sql.identifier(column)),\n sql.raw(', '),\n )\n\n await db.run(sql`\n CREATE ${unique}INDEX ${sql.identifier(index.to)}\n ON ${sql.identifier(tableName)} (${columnList})\n `)\n }\n\n if (sourceIndex && sourceIndex.name !== index.to) {\n await db.run(sql`DROP INDEX ${sql.identifier(sourceIndex.name)}`)\n }\n }\n\n payload.logger.info({\n msg: `sizes-to-variants (${direction}): renamed ${renamedCount} column(s) on \"${tableName}\"`,\n })\n }\n}\n\nasync function getColumnNames({\n db,\n tableName,\n}: {\n db: any\n tableName: string\n}): Promise<Set<string>> {\n const rows: { name: string }[] = await db.all(\n sql`SELECT name FROM pragma_table_info(${tableName})`,\n )\n\n return new Set(rows.map(({ name }) => name))\n}\n\nasync function getIndexes({\n db,\n tableName,\n}: {\n db: any\n tableName: string\n}): Promise<{ columns: string[]; name: string; unique: boolean }[]> {\n // `origin = 'c'` keeps only `CREATE INDEX` indexes, skipping SQLite's internal autoindexes.\n const rows: { column_name: string; index_name: string; is_unique: number; seqno: number }[] =\n await db.all(sql`\n SELECT\n il.name AS index_name,\n il.\"unique\" AS is_unique,\n ii.name AS column_name,\n ii.seqno AS seqno\n FROM pragma_index_list(${tableName}) AS il\n JOIN pragma_index_info(il.name) AS ii\n WHERE il.origin = 'c'\n ORDER BY il.name, ii.seqno\n `)\n\n const indexes = new Map<string, { columns: string[]; unique: boolean }>()\n\n for (const { column_name, index_name, is_unique } of rows) {\n const index = indexes.get(index_name) ?? { columns: [], unique: Boolean(is_unique) }\n\n index.columns.push(column_name)\n indexes.set(index_name, index)\n }\n\n return [...indexes].map(([name, index]) => ({ name, ...index }))\n}\n"],"names":["sql","assertNoSizesToVariantsColumnCollisions","getSizesToVariantsRenames","isGeneratedLegacyIndexName","migrateSqliteSizesToVariants","db","direction","payload","adapter","plan","plannedTables","tablePlan","existingColumns","getColumnNames","tableName","columns","push","indexes","columnsAfterRename","Set","renamedCount","from","to","has","delete","add","run","identifier","existingIndexes","getIndexes","index","every","column","destinationIndex","find","name","sourceIndex","undefined","legacyNameBase","join","indexName","unique","Error","raw","empty","columnList","map","logger","info","msg","rows","all","Map","column_name","index_name","is_unique","get","Boolean","set"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SACEC,uCAAuC,EACvCC,yBAAyB,EACzBC,0BAA0B,QACrB,kDAAiD;AAExD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,CAAA;AAM/C,eAAO,MAAM,gBAAgB,EAAE,gBAgE9B,CAAA"}
1
+ {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,eAAO,MAAM,gBAAgB,EAAE,gBAwE9B,CAAA"}
@@ -8,6 +8,8 @@ export const beginTransaction = async function beginTransaction(options) {
8
8
  let transaction;
9
9
  let transactionReady;
10
10
  let transactionFailed;
11
+ let hasTransactionStarted = false;
12
+ const rollbackSignal = new Error('Payload transaction rollback requested');
11
13
  // Await initialization here
12
14
  // Prevent race conditions where the adapter may be
13
15
  // re-initializing, and `this.drizzle` is potentially undefined
@@ -25,20 +27,26 @@ export const beginTransaction = async function beginTransaction(options) {
25
27
  return done;
26
28
  };
27
29
  reject = ()=>{
28
- // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
29
- rej();
30
+ rej(rollbackSignal);
30
31
  return done;
31
32
  };
32
33
  transactionReady();
33
34
  });
34
35
  }, options || this.transactionOptions).catch((err)=>{
35
- // Connection failed before callback ran - reject instead of hanging forever
36
- transactionFailed(err);
36
+ if (!hasTransactionStarted) {
37
+ // Connection failed before callback ran - reject instead of hanging forever
38
+ transactionFailed(err);
39
+ } else if (err !== rollbackSignal) {
40
+ throw err;
41
+ }
37
42
  });
38
43
  // Need to wait until the transaction is ready
39
44
  // before binding its `resolve` and `reject` methods below
40
45
  await new Promise((res, rej)=>{
41
- transactionReady = res;
46
+ transactionReady = ()=>{
47
+ hasTransactionStarted = true;
48
+ res();
49
+ };
42
50
  transactionFailed = rej;
43
51
  });
44
52
  this.sessions[id] = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { BeginTransaction } from 'payload'\n\nimport { v4 as uuid } from 'uuid'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: DrizzleAdapter,\n options: DrizzleAdapter['transactionOptions'],\n) {\n let id\n try {\n id = uuid()\n\n let reject: () => Promise<void>\n let resolve: () => Promise<void>\n let transaction: DrizzleTransaction\n\n let transactionReady: () => void\n let transactionFailed: (err: unknown) => void\n\n // Await initialization here\n // Prevent race conditions where the adapter may be\n // re-initializing, and `this.drizzle` is potentially undefined\n await this.initializing\n\n // Drizzle only exposes a transactions API that is sufficient if you\n // can directly pass around the `tx` argument. But our operations are spread\n // over many files and we don't want to pass the `tx` around like that,\n // so instead, we \"lift\" up the `resolve` and `reject` methods\n // and will call them in our respective transaction methods\n const done = this.drizzle\n .transaction(async (tx) => {\n transaction = tx\n await new Promise<void>((res, rej) => {\n resolve = () => {\n res()\n return done\n }\n reject = () => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n rej()\n return done\n }\n transactionReady()\n })\n }, options || this.transactionOptions)\n .catch((err) => {\n // Connection failed before callback ran - reject instead of hanging forever\n transactionFailed(err)\n })\n\n // Need to wait until the transaction is ready\n // before binding its `resolve` and `reject` methods below\n await new Promise<void>((res, rej) => {\n transactionReady = res\n transactionFailed = rej\n })\n\n this.sessions[id] = {\n db: transaction,\n reject,\n resolve,\n }\n } catch (err) {\n this.payload.logger.error({ err, msg: `Error: cannot begin transaction: ${err.message}` })\n throw new Error(`Error: cannot begin transaction: ${err.message}`)\n }\n\n return id\n}\n"],"names":["v4","uuid","beginTransaction","options","id","reject","resolve","transaction","transactionReady","transactionFailed","initializing","done","drizzle","tx","Promise","res","rej","transactionOptions","catch","err","sessions","db","payload","logger","error","msg","message","Error"],"mappings":"AAEA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA6C;IAE7C,IAAIC;IACJ,IAAI;QACFA,KAAKH;QAEL,IAAII;QACJ,IAAIC;QACJ,IAAIC;QAEJ,IAAIC;QACJ,IAAIC;QAEJ,4BAA4B;QAC5B,mDAAmD;QACnD,+DAA+D;QAC/D,MAAM,IAAI,CAACC,YAAY;QAEvB,oEAAoE;QACpE,4EAA4E;QAC5E,uEAAuE;QACvE,8DAA8D;QAC9D,2DAA2D;QAC3D,MAAMC,OAAO,IAAI,CAACC,OAAO,CACtBL,WAAW,CAAC,OAAOM;YAClBN,cAAcM;YACd,MAAM,IAAIC,QAAc,CAACC,KAAKC;gBAC5BV,UAAU;oBACRS;oBACA,OAAOJ;gBACT;gBACAN,SAAS;oBACP,2EAA2E;oBAC3EW;oBACA,OAAOL;gBACT;gBACAH;YACF;QACF,GAAGL,WAAW,IAAI,CAACc,kBAAkB,EACpCC,KAAK,CAAC,CAACC;YACN,4EAA4E;YAC5EV,kBAAkBU;QACpB;QAEF,8CAA8C;QAC9C,0DAA0D;QAC1D,MAAM,IAAIL,QAAc,CAACC,KAAKC;YAC5BR,mBAAmBO;YACnBN,oBAAoBO;QACtB;QAEA,IAAI,CAACI,QAAQ,CAAChB,GAAG,GAAG;YAClBiB,IAAId;YACJF;YACAC;QACF;IACF,EAAE,OAAOa,KAAK;QACZ,IAAI,CAACG,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEL;YAAKM,KAAK,CAAC,iCAAiC,EAAEN,IAAIO,OAAO,EAAE;QAAC;QACxF,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAER,IAAIO,OAAO,EAAE;IACnE;IAEA,OAAOtB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { BeginTransaction } from 'payload'\n\nimport { v4 as uuid } from 'uuid'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: DrizzleAdapter,\n options: DrizzleAdapter['transactionOptions'],\n) {\n let id\n try {\n id = uuid()\n\n let reject: () => Promise<void>\n let resolve: () => Promise<void>\n let transaction: DrizzleTransaction\n\n let transactionReady: () => void\n let transactionFailed: (err: unknown) => void\n let hasTransactionStarted = false\n const rollbackSignal = new Error('Payload transaction rollback requested')\n\n // Await initialization here\n // Prevent race conditions where the adapter may be\n // re-initializing, and `this.drizzle` is potentially undefined\n await this.initializing\n\n // Drizzle only exposes a transactions API that is sufficient if you\n // can directly pass around the `tx` argument. But our operations are spread\n // over many files and we don't want to pass the `tx` around like that,\n // so instead, we \"lift\" up the `resolve` and `reject` methods\n // and will call them in our respective transaction methods\n const done = this.drizzle\n .transaction(async (tx) => {\n transaction = tx\n await new Promise<void>((res, rej) => {\n resolve = () => {\n res()\n return done\n }\n reject = () => {\n rej(rollbackSignal)\n return done\n }\n transactionReady()\n })\n }, options || this.transactionOptions)\n .catch((err) => {\n if (!hasTransactionStarted) {\n // Connection failed before callback ran - reject instead of hanging forever\n transactionFailed(err)\n } else if (err !== rollbackSignal) {\n throw err\n }\n })\n\n // Need to wait until the transaction is ready\n // before binding its `resolve` and `reject` methods below\n await new Promise<void>((res, rej) => {\n transactionReady = () => {\n hasTransactionStarted = true\n res()\n }\n transactionFailed = rej\n })\n\n this.sessions[id] = {\n db: transaction,\n reject,\n resolve,\n }\n } catch (err) {\n this.payload.logger.error({ err, msg: `Error: cannot begin transaction: ${err.message}` })\n throw new Error(`Error: cannot begin transaction: ${err.message}`)\n }\n\n return id\n}\n"],"names":["v4","uuid","beginTransaction","options","id","reject","resolve","transaction","transactionReady","transactionFailed","hasTransactionStarted","rollbackSignal","Error","initializing","done","drizzle","tx","Promise","res","rej","transactionOptions","catch","err","sessions","db","payload","logger","error","msg","message"],"mappings":"AAEA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA6C;IAE7C,IAAIC;IACJ,IAAI;QACFA,KAAKH;QAEL,IAAII;QACJ,IAAIC;QACJ,IAAIC;QAEJ,IAAIC;QACJ,IAAIC;QACJ,IAAIC,wBAAwB;QAC5B,MAAMC,iBAAiB,IAAIC,MAAM;QAEjC,4BAA4B;QAC5B,mDAAmD;QACnD,+DAA+D;QAC/D,MAAM,IAAI,CAACC,YAAY;QAEvB,oEAAoE;QACpE,4EAA4E;QAC5E,uEAAuE;QACvE,8DAA8D;QAC9D,2DAA2D;QAC3D,MAAMC,OAAO,IAAI,CAACC,OAAO,CACtBR,WAAW,CAAC,OAAOS;YAClBT,cAAcS;YACd,MAAM,IAAIC,QAAc,CAACC,KAAKC;gBAC5Bb,UAAU;oBACRY;oBACA,OAAOJ;gBACT;gBACAT,SAAS;oBACPc,IAAIR;oBACJ,OAAOG;gBACT;gBACAN;YACF;QACF,GAAGL,WAAW,IAAI,CAACiB,kBAAkB,EACpCC,KAAK,CAAC,CAACC;YACN,IAAI,CAACZ,uBAAuB;gBAC1B,4EAA4E;gBAC5ED,kBAAkBa;YACpB,OAAO,IAAIA,QAAQX,gBAAgB;gBACjC,MAAMW;YACR;QACF;QAEF,8CAA8C;QAC9C,0DAA0D;QAC1D,MAAM,IAAIL,QAAc,CAACC,KAAKC;YAC5BX,mBAAmB;gBACjBE,wBAAwB;gBACxBQ;YACF;YACAT,oBAAoBU;QACtB;QAEA,IAAI,CAACI,QAAQ,CAACnB,GAAG,GAAG;YAClBoB,IAAIjB;YACJF;YACAC;QACF;IACF,EAAE,OAAOgB,KAAK;QACZ,IAAI,CAACG,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEL;YAAKM,KAAK,CAAC,iCAAiC,EAAEN,IAAIO,OAAO,EAAE;QAAC;QACxF,MAAM,IAAIjB,MAAM,CAAC,iCAAiC,EAAEU,IAAIO,OAAO,EAAE;IACnE;IAEA,OAAOzB;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAqB/B,CAAA"}
1
+ {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAkB/B,CAAA"}
@@ -8,11 +8,8 @@ export const commitTransaction = async function commitTransaction(incomingID = '
8
8
  // Delete from registry FIRST to prevent race conditions
9
9
  // This ensures other operations can't retrieve this session while we're ending it
10
10
  delete this.sessions[transactionID];
11
- try {
12
- await session.resolve();
13
- } catch (_) {
14
- await session.reject();
15
- }
11
+ // Drizzle handles rollback if commit fails; preserve the error for the caller.
12
+ await session.resolve();
16
13
  };
17
14
 
18
15
  //# sourceMappingURL=commitTransaction.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n // if the session was deleted it has already been aborted\n if (!this.sessions[transactionID]) {\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're ending it\n delete this.sessions[transactionID]\n\n try {\n await session.resolve()\n } catch (_) {\n await session.reject()\n }\n}\n"],"names":["commitTransaction","incomingID","transactionID","Promise","sessions","session","resolve","_","reject"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBACjEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,yDAAyD;IACzD,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,MAAMG,UAAU,IAAI,CAACD,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,kFAAkF;IAClF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,IAAI;QACF,MAAMG,QAAQC,OAAO;IACvB,EAAE,OAAOC,GAAG;QACV,MAAMF,QAAQG,MAAM;IACtB;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(\n incomingID = '',\n) {\n const transactionID = incomingID instanceof Promise ? await incomingID : incomingID\n\n // if the session was deleted it has already been aborted\n if (!this.sessions[transactionID]) {\n return\n }\n\n const session = this.sessions[transactionID]\n\n // Delete from registry FIRST to prevent race conditions\n // This ensures other operations can't retrieve this session while we're ending it\n delete this.sessions[transactionID]\n\n // Drizzle handles rollback if commit fails; preserve the error for the caller.\n await session.resolve()\n}\n"],"names":["commitTransaction","incomingID","transactionID","Promise","sessions","session","resolve"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBACjEC,aAAa,EAAE;IAEf,MAAMC,gBAAgBD,sBAAsBE,UAAU,MAAMF,aAAaA;IAEzE,yDAAyD;IACzD,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,MAAMG,UAAU,IAAI,CAACD,QAAQ,CAACF,cAAc;IAE5C,wDAAwD;IACxD,kFAAkF;IAClF,OAAO,IAAI,CAACE,QAAQ,CAACF,cAAc;IAEnC,+EAA+E;IAC/E,MAAMG,QAAQC,OAAO;AACvB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/transform/read/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAQnE,KAAK,kBAAkB,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,cAAc,CAAA;IACvB;;OAEG;IACH,MAAM,EAAE,SAAS,CAAA;IACjB;;OAEG;IACH,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC;;OAEG;IACH,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAA;IACzB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;IAClD,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;IACxD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;IAChD,iBAAiB,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AAID,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,6NAmB7D,kBAAkB,KAAG,CAwnBvB,CAAA"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/transform/read/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB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AAID,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,6NAmB7D,kBAAkB,KAAG,CA+nBvB,CAAA"}
@@ -132,9 +132,15 @@ export const traverseFields = ({ adapter, blocks, config, currentTableName, data
132
132
  });
133
133
  Object.entries(result[field.name]).forEach(([locale, localizedBlocks])=>{
134
134
  result[field.name][locale] = localizedBlocks.map((row)=>{
135
- const block = adapter.payload.blocks[row.blockType] ?? field.blocks.find((block)=>typeof block !== 'string' && block.slug === row.blockType);
136
- const tableName = resolveBlockTableName(block, adapter.tableNameMap.get(`${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`));
135
+ const fieldBlock = field.blocks.find((block)=>typeof block === 'string' ? block === row.blockType : block.slug === row.blockType);
136
+ const registeredBlocks = adapter.payload.blocks;
137
+ const block = typeof fieldBlock === 'string' ? registeredBlocks[fieldBlock] : fieldBlock;
137
138
  if (block) {
139
+ const originalTableName = adapter.tableNameMap.get(`${topLevelTableName}_blocks_${toSnakeCase(block.slug)}`);
140
+ if (!originalTableName) {
141
+ return {};
142
+ }
143
+ const tableName = resolveBlockTableName(block, originalTableName);
138
144
  const blockResult = traverseFields({
139
145
  adapter,
140
146
  blocks,
@@ -184,7 +190,9 @@ export const traverseFields = ({ adapter, blocks, config, currentTableName, data
184
190
  if (typeof row.blockType !== 'string') {
185
191
  return acc;
186
192
  }
187
- const block = adapter.payload.blocks[row.blockType] ?? field.blocks.find((block)=>typeof block !== 'string' && block.slug === row.blockType);
193
+ const fieldBlock = field.blocks.find((block)=>typeof block === 'string' ? block === row.blockType : block.slug === row.blockType);
194
+ const registeredBlocks = adapter.payload.blocks;
195
+ const block = typeof fieldBlock === 'string' ? registeredBlocks[fieldBlock] : fieldBlock;
188
196
  if (block) {
189
197
  if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
190
198
  if (row._locale) {