@payloadcms/drizzle 3.23.0 → 3.24.0-canary.05013b2
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.
- package/dist/find/traverseFields.d.ts +2 -2
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +19 -10
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/postgres/countDistinct.d.ts.map +1 -1
- package/dist/postgres/countDistinct.js +14 -13
- package/dist/postgres/countDistinct.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +4 -2
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js +4 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +2 -1
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +2 -1
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -1
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +3 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +2 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +27 -14
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/schema/build.d.ts +2 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +2 -1
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/buildRawSchema.d.ts.map +1 -1
- package/dist/schema/buildRawSchema.js +4 -0
- package/dist/schema/buildRawSchema.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +2 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +32 -16
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/transform/read/index.d.ts +2 -1
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/index.js +2 -1
- package/dist/transform/read/index.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts +2 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +28 -16
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/array.d.ts +2 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/array.js +7 -2
- package/dist/transform/write/array.js.map +1 -1
- package/dist/transform/write/blocks.d.ts +2 -1
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/blocks.js +8 -3
- package/dist/transform/write/blocks.js.map +1 -1
- package/dist/transform/write/index.d.ts +2 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/index.js +2 -1
- package/dist/transform/write/index.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts +2 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +25 -14
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/utilities/hasLocalesTable.d.ts +7 -1
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.js +14 -5
- package/dist/utilities/hasLocalesTable.js.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +5 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js +22 -7
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/traverseFields.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nimport { InvalidConfiguration } from 'payload'\nimport { fieldAffectsData, fieldIsVirtual, optionIsObject } 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 { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { validateExistingBlockIsIdentical } 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 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 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 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 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 // If field is localized,\n // add the column to the locale table instead of main table\n if (\n adapter.payload.config.localization &&\n (field.localized || forceLocalized) &&\n field.type !== 'array' &&\n field.type !== 'blocks' &&\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: field.localized ? [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(field.localized && 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 disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(field.flattenedFields) : field.flattenedFields,\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 relationsToBuild.set(fieldName, {\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: fieldName,\n to: parentTableName,\n },\n }\n\n if (hasLocalesTable(field.fields)) {\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 const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n field.blocks.forEach((block) => {\n const blockTableName = createTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n versionsCustomName: versions,\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 const isLocalized =\n Boolean(field.localized && 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: `${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 disableNotNull: disableNotNullFromHere,\n disableRelsTableUnique: true,\n disableUnique,\n fields: disableUnique ? idToUUID(block.flattenedFields) : block.flattenedFields,\n rootRelationships: relationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n rootUniqueRelationships: uniqueRelationships,\n setColumnID,\n tableName: blockTableName,\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\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: `_blocks_${block.slug}`,\n to: rootTableName,\n },\n }\n\n if (hasLocalesTable(block.fields)) {\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 } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n rootTableName,\n table: adapter.rawTables[blockTableName],\n tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`],\n })\n }\n // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks\n rootRelationsToBuild.set(`_blocks_${block.slug}`, {\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 '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 columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.flattenedFields,\n forceLocalized: field.localized,\n indexes,\n localesColumns,\n localesIndexes,\n newTableName: `${parentTableName}_${columnName}`,\n parentTableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName,\n setColumnID,\n uniqueRelationships,\n versions,\n withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || field.localized,\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(field.localized && 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(field.localized && 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 disableNotNull,\n disableUnique,\n fields: [],\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 = adapter.idType === 'uuid' ? '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 && (field.localized || 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(field.localized && 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(field.localized && 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","optionIsObject","toSnakeCase","createTableName","buildIndexName","hasLocalesTable","validateExistingBlockIsIdentical","buildTable","idToUUID","withDefault","traverseFields","adapter","columnPrefix","columns","disableNotNull","disableRelsTableUnique","disableUnique","fieldPrefix","fields","forceLocalized","indexes","localesColumns","localesIndexes","newTableName","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","payload","config","localization","localized","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","rootRelationships","rootUniqueRelationships","tableName","set","target","arrayRelations","references","relationName","to","_locales","localesSuffix","key","arrayWithLocalized","rawRelations","blocks","block","blockTableName","rawTables","_path","_pathIdx","_parentIdFk","blockRelations","slug","blockWithLocalized","process","env","NODE_ENV","tableLocales","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,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,cAAc,QAAQ,iBAAgB;AACjF,OAAOC,iBAAiB,gBAAe;AAavC,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,gCAAgC,QAAQ,mDAAkD;AACnG,SAASC,UAAU,QAAQ,aAAY;AACvC,SAASC,QAAQ,QAAQ,gBAAe;AACxC,SAASC,WAAW,QAAQ,mBAAkB;AAyC9C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,cAAc,EACdC,sBAAsB,EACtBC,gBAAgB,KAAK,EACrBC,WAAW,EACXC,MAAM,EACNC,cAAc,EACdC,OAAO,EACPC,cAAc,EACdC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,gBAAgB,EAChBC,oBAAoB,EACpBC,kBAAkB,EAClBC,aAAa,EACbC,WAAW,EACXC,mBAAmB,EACnBC,QAAQ,EACRC,2BAA2B,EACtB;IACL,MAAMC,uBAAuB;IAC7B,IAAIC,oBAAoB;IACxB,IAAIC,gCAAgC;IACpC,IAAIC,mBAAsC;IAC1C,IAAIC,4BAA4B;IAChC,IAAIC,qBAAwC;IAC5C,IAAIC,8BAA8B;IAElC,IAAIC,kBAA0B;IAE9B,MAAMC,WAAW7B,QAAQ8B,EAAE;IAE3B,IAAID,YAAY;QAAC;QAAW;QAAQ;QAAQ;KAAU,CAACE,QAAQ,CAACF,SAASG,IAAI,GAAG;QAC9EJ,kBAAkBC,SAASG,IAAI;IACjC;IAEA3B,OAAO4B,OAAO,CAAC,CAACC;QACd,IAAI,UAAUA,SAASA,MAAMC,IAAI,KAAK,MAAM;YAC1C;QACF;QACA,IAAIhD,eAAe+C,QAAQ;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ACA;gBACF;YAEA;gBACE;QACJ;QAEA,MAAMwB,YAAYxB,MAAMuB,KAAK,IAAIvB,MAAMuB,KAAK,CAACC,SAAS;QAEtD,IACE,CAACzD,kBACDmC,WAAW,CAACG,UAAU,IACtB,cAAcL,SACdA,MAAM+G,QAAQ,IACd,CAACvF,WACD;YACAtB,WAAW,CAACG,UAAU,CAACyB,OAAO,GAAG;QACnC;IACF;IAEA,OAAO;QACL1C;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 { hasLocalesTable } from '../utilities/hasLocalesTable.js'\nimport { validateExistingBlockIsIdentical } 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 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 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' &&\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 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 relationsToBuild.set(fieldName, {\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: fieldName,\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 const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull\n\n ;(field.blockReferences ?? field.blocks).forEach((_block) => {\n const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block\n\n const blockTableName = createTableName({\n adapter,\n config: block,\n parentTableName: rootTableName,\n prefix: `${rootTableName}_blocks_`,\n throwValidationError,\n versionsCustomName: versions,\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 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: `${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 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: 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\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: `_blocks_${block.slug}`,\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 } else if (process.env.NODE_ENV !== 'production' && !versions) {\n validateExistingBlockIsIdentical({\n block,\n localized: field.localized,\n parentIsLocalized: parentIsLocalized || field.localized,\n rootTableName,\n table: adapter.rawTables[blockTableName],\n tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`],\n })\n }\n // blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks\n rootRelationsToBuild.set(`_blocks_${block.slug}`, {\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 '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 columnPrefix: `${columnName}_`,\n columns,\n disableNotNull: disableNotNullFromHere,\n disableUnique,\n fieldPrefix: `${fieldName}.`,\n fields: field.flattenedFields,\n forceLocalized: isFieldLocalized,\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 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 = adapter.idType === 'uuid' ? '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","hasLocalesTable","validateExistingBlockIsIdentical","buildTable","idToUUID","withDefault","traverseFields","adapter","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","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","set","target","arrayRelations","references","relationName","to","_locales","localesSuffix","key","arrayWithLocalized","rawRelations","blockReferences","blocks","_block","block","blockTableName","rawTables","_path","_pathIdx","_parentIdFk","blockRelations","slug","blockWithLocalized","process","env","NODE_ENV","tableLocales","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,eAAe,QAAQ,kCAAiC;AACjE,SAASC,gCAAgC,QAAQ,mDAAkD;AACnG,SAASC,UAAU,QAAQ,aAAY;AACvC,SAASC,QAAQ,QAAQ,gBAAe;AACxC,SAASC,WAAW,QAAQ,mBAAkB;AA0C9C,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,cAAc,EACdC,sBAAsB,EACtBC,gBAAgB,KAAK,EACrBC,WAAW,EACXC,MAA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B,cAAcL,SACdA,MAAMkH,QAAQ,IACd,CAAC1F,WACD;YACAtB,WAAW,CAACG,UAAU,CAACyB,OAAO,GAAG;QACnC;IACF;IAEA,OAAO;QACL1C;QACAK;QACAF;QACAF;QACAG;QACAF;IACF;AACF,EAAC"}
|
|
@@ -8,7 +8,8 @@ type TransformArgs = {
|
|
|
8
8
|
fields: FlattenedField[];
|
|
9
9
|
joinQuery?: JoinQuery;
|
|
10
10
|
locale?: string;
|
|
11
|
+
parentIsLocalized?: boolean;
|
|
11
12
|
};
|
|
12
|
-
export declare const transform: <T extends Record<string, unknown> | TypeWithID>({ adapter, config, data, fields, joinQuery, }: TransformArgs) => T;
|
|
13
|
+
export declare const transform: <T extends Record<string, unknown> | TypeWithID>({ adapter, config, data, fields, joinQuery, parentIsLocalized, }: TransformArgs) => T;
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transform/read/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAErF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAMpD,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC/B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transform/read/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAErF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAMpD,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC/B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAID,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,oEAOrE,aAAa,KAAG,CA6ClB,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { createPathMap } from '../../utilities/createRelationshipMap.js';
|
|
|
3
3
|
import { traverseFields } from './traverseFields.js';
|
|
4
4
|
// This is the entry point to transform Drizzle output data
|
|
5
5
|
// into the shape Payload expects based on field schema
|
|
6
|
-
export const transform = ({ adapter, config, data, fields, joinQuery })=>{
|
|
6
|
+
export const transform = ({ adapter, config, data, fields, joinQuery, parentIsLocalized })=>{
|
|
7
7
|
let relationships = {};
|
|
8
8
|
let texts = {};
|
|
9
9
|
let numbers = {};
|
|
@@ -33,6 +33,7 @@ export const transform = ({ adapter, config, data, fields, joinQuery })=>{
|
|
|
33
33
|
fields,
|
|
34
34
|
joinQuery,
|
|
35
35
|
numbers,
|
|
36
|
+
parentIsLocalized,
|
|
36
37
|
path: '',
|
|
37
38
|
relationships,
|
|
38
39
|
table: data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/transform/read/index.ts"],"sourcesContent":["import type { FlattenedField, JoinQuery, SanitizedConfig, TypeWithID } from 'payload'\n\nimport type { DrizzleAdapter } from '../../types.js'\n\nimport { createBlocksMap } from '../../utilities/createBlocksMap.js'\nimport { createPathMap } from '../../utilities/createRelationshipMap.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype TransformArgs = {\n adapter: DrizzleAdapter\n config: SanitizedConfig\n data: Record<string, unknown>\n fallbackLocale?: false | string\n fields: FlattenedField[]\n joinQuery?: JoinQuery\n locale?: string\n}\n\n// This is the entry point to transform Drizzle output data\n// into the shape Payload expects based on field schema\nexport const transform = <T extends Record<string, unknown> | TypeWithID>({\n adapter,\n config,\n data,\n fields,\n joinQuery,\n}: TransformArgs): T => {\n let relationships: Record<string, Record<string, unknown>[]> = {}\n let texts: Record<string, Record<string, unknown>[]> = {}\n let numbers: Record<string, Record<string, unknown>[]> = {}\n\n if ('_rels' in data) {\n relationships = createPathMap(data._rels)\n delete data._rels\n }\n\n if ('_texts' in data) {\n texts = createPathMap(data._texts)\n delete data._texts\n }\n\n if ('_numbers' in data) {\n numbers = createPathMap(data._numbers)\n delete data._numbers\n }\n\n const blocks = createBlocksMap(data)\n const deletions = []\n\n const result = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: {\n id: data.id,\n },\n deletions,\n fieldPrefix: '',\n fields,\n joinQuery,\n numbers,\n path: '',\n relationships,\n table: data,\n texts,\n })\n\n deletions.forEach((deletion) => deletion())\n\n return result\n}\n"],"names":["createBlocksMap","createPathMap","traverseFields","transform","adapter","config","data","fields","joinQuery","relationships","texts","numbers","_rels","_texts","_numbers","blocks","deletions","result","dataRef","id","fieldPrefix","path","table","forEach","deletion"],"mappings":"AAIA,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,2CAA0C;AACxE,SAASC,cAAc,QAAQ,sBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../../src/transform/read/index.ts"],"sourcesContent":["import type { FlattenedField, JoinQuery, SanitizedConfig, TypeWithID } from 'payload'\n\nimport type { DrizzleAdapter } from '../../types.js'\n\nimport { createBlocksMap } from '../../utilities/createBlocksMap.js'\nimport { createPathMap } from '../../utilities/createRelationshipMap.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype TransformArgs = {\n adapter: DrizzleAdapter\n config: SanitizedConfig\n data: Record<string, unknown>\n fallbackLocale?: false | string\n fields: FlattenedField[]\n joinQuery?: JoinQuery\n locale?: string\n parentIsLocalized?: boolean\n}\n\n// This is the entry point to transform Drizzle output data\n// into the shape Payload expects based on field schema\nexport const transform = <T extends Record<string, unknown> | TypeWithID>({\n adapter,\n config,\n data,\n fields,\n joinQuery,\n parentIsLocalized,\n}: TransformArgs): T => {\n let relationships: Record<string, Record<string, unknown>[]> = {}\n let texts: Record<string, Record<string, unknown>[]> = {}\n let numbers: Record<string, Record<string, unknown>[]> = {}\n\n if ('_rels' in data) {\n relationships = createPathMap(data._rels)\n delete data._rels\n }\n\n if ('_texts' in data) {\n texts = createPathMap(data._texts)\n delete data._texts\n }\n\n if ('_numbers' in data) {\n numbers = createPathMap(data._numbers)\n delete data._numbers\n }\n\n const blocks = createBlocksMap(data)\n const deletions = []\n\n const result = traverseFields<T>({\n adapter,\n blocks,\n config,\n dataRef: {\n id: data.id,\n },\n deletions,\n fieldPrefix: '',\n fields,\n joinQuery,\n numbers,\n parentIsLocalized,\n path: '',\n relationships,\n table: data,\n texts,\n })\n\n deletions.forEach((deletion) => deletion())\n\n return result\n}\n"],"names":["createBlocksMap","createPathMap","traverseFields","transform","adapter","config","data","fields","joinQuery","parentIsLocalized","relationships","texts","numbers","_rels","_texts","_numbers","blocks","deletions","result","dataRef","id","fieldPrefix","path","table","forEach","deletion"],"mappings":"AAIA,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,2CAA0C;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AAapD,2DAA2D;AAC3D,uDAAuD;AACvD,OAAO,MAAMC,YAAY,CAAiD,EACxEC,OAAO,EACPC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,SAAS,EACTC,iBAAiB,EACH;IACd,IAAIC,gBAA2D,CAAC;IAChE,IAAIC,QAAmD,CAAC;IACxD,IAAIC,UAAqD,CAAC;IAE1D,IAAI,WAAWN,MAAM;QACnBI,gBAAgBT,cAAcK,KAAKO,KAAK;QACxC,OAAOP,KAAKO,KAAK;IACnB;IAEA,IAAI,YAAYP,MAAM;QACpBK,QAAQV,cAAcK,KAAKQ,MAAM;QACjC,OAAOR,KAAKQ,MAAM;IACpB;IAEA,IAAI,cAAcR,MAAM;QACtBM,UAAUX,cAAcK,KAAKS,QAAQ;QACrC,OAAOT,KAAKS,QAAQ;IACtB;IAEA,MAAMC,SAAShB,gBAAgBM;IAC/B,MAAMW,YAAY,EAAE;IAEpB,MAAMC,SAAShB,eAAkB;QAC/BE;QACAY;QACAX;QACAc,SAAS;YACPC,IAAId,KAAKc,EAAE;QACb;QACAH;QACAI,aAAa;QACbd;QACAC;QACAI;QACAH;QACAa,MAAM;QACNZ;QACAa,OAAOjB;QACPK;IACF;IAEAM,UAAUO,OAAO,CAAC,CAACC,WAAaA;IAEhC,OAAOP;AACT,EAAC"}
|
|
@@ -38,6 +38,7 @@ type TraverseFieldsArgs = {
|
|
|
38
38
|
* All hasMany number fields, as returned by Drizzle, keyed on an object by field path
|
|
39
39
|
*/
|
|
40
40
|
numbers: Record<string, Record<string, unknown>[]>;
|
|
41
|
+
parentIsLocalized: boolean;
|
|
41
42
|
/**
|
|
42
43
|
* The current field path (in dot notation), used to merge in relationships
|
|
43
44
|
*/
|
|
@@ -59,6 +60,6 @@ type TraverseFieldsArgs = {
|
|
|
59
60
|
*/
|
|
60
61
|
withinArrayOrBlockLocale?: string;
|
|
61
62
|
};
|
|
62
|
-
export declare const traverseFields: <T extends Record<string, unknown>>({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, path, relationships, table, texts, withinArrayOrBlockLocale, }: TraverseFieldsArgs) => T;
|
|
63
|
+
export declare const traverseFields: <T extends Record<string, unknown>>({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, parentIsLocalized, path, relationships, table, texts, withinArrayOrBlockLocale, }: TraverseFieldsArgs) => T;
|
|
63
64
|
export {};
|
|
64
65
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/transform/read/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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;AAIzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAMnE,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;;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;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;IAChD;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC,CAAA;AAID,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,6KAgB7D,kBAAkB,KAAG,CAglBvB,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { fieldIsVirtual } from 'payload/shared';
|
|
1
|
+
import { fieldIsVirtual, fieldShouldBeLocalized } from 'payload/shared';
|
|
2
2
|
import { transformHasManyNumber } from './hasManyNumber.js';
|
|
3
3
|
import { transformHasManyText } from './hasManyText.js';
|
|
4
4
|
import { transformRelationship } from './relationship.js';
|
|
5
5
|
// Traverse fields recursively, transforming data
|
|
6
6
|
// for each field type into required Payload shape
|
|
7
|
-
export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
|
|
7
|
+
export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fieldPrefix, fields, joinQuery, numbers, parentIsLocalized, path, relationships, table, texts, withinArrayOrBlockLocale })=>{
|
|
8
8
|
const sanitizedPath = path ? `${path}.` : path;
|
|
9
9
|
const formatted = fields.reduce((result, field)=>{
|
|
10
10
|
if (fieldIsVirtual(field)) {
|
|
@@ -17,9 +17,13 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
17
17
|
if (fieldPrefix) {
|
|
18
18
|
deletions.push(()=>delete table[fieldName]);
|
|
19
19
|
}
|
|
20
|
+
const isLocalized = fieldShouldBeLocalized({
|
|
21
|
+
field,
|
|
22
|
+
parentIsLocalized
|
|
23
|
+
});
|
|
20
24
|
if (field.type === 'array') {
|
|
21
25
|
if (Array.isArray(fieldData)) {
|
|
22
|
-
if (
|
|
26
|
+
if (isLocalized) {
|
|
23
27
|
result[field.name] = fieldData.reduce((arrayResult, row)=>{
|
|
24
28
|
if (typeof row._locale === 'string') {
|
|
25
29
|
if (!arrayResult[row._locale]) {
|
|
@@ -41,6 +45,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
41
45
|
fieldPrefix: '',
|
|
42
46
|
fields: field.flattenedFields,
|
|
43
47
|
numbers,
|
|
48
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
44
49
|
path: `${sanitizedPath}${field.name}.${row._order - 1}`,
|
|
45
50
|
relationships,
|
|
46
51
|
table: row,
|
|
@@ -76,6 +81,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
76
81
|
fieldPrefix: '',
|
|
77
82
|
fields: field.flattenedFields,
|
|
78
83
|
numbers,
|
|
84
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
79
85
|
path: `${sanitizedPath}${field.name}.${i}`,
|
|
80
86
|
relationships,
|
|
81
87
|
table: row,
|
|
@@ -93,7 +99,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
93
99
|
const blockFieldPath = `${sanitizedPath}${field.name}`;
|
|
94
100
|
const blocksByPath = blocks[blockFieldPath];
|
|
95
101
|
if (Array.isArray(blocksByPath)) {
|
|
96
|
-
if (
|
|
102
|
+
if (isLocalized) {
|
|
97
103
|
result[field.name] = {};
|
|
98
104
|
blocksByPath.forEach((row)=>{
|
|
99
105
|
if (row._uuid) {
|
|
@@ -110,7 +116,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
110
116
|
});
|
|
111
117
|
Object.entries(result[field.name]).forEach(([locale, localizedBlocks])=>{
|
|
112
118
|
result[field.name][locale] = localizedBlocks.map((row)=>{
|
|
113
|
-
const block = field.blocks.find((
|
|
119
|
+
const block = adapter.payload.blocks[row.blockType] ?? (field.blockReferences ?? field.blocks).find((block)=>typeof block !== 'string' && block.slug === row.blockType);
|
|
114
120
|
if (block) {
|
|
115
121
|
const blockResult = traverseFields({
|
|
116
122
|
adapter,
|
|
@@ -121,6 +127,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
121
127
|
fieldPrefix: '',
|
|
122
128
|
fields: block.flattenedFields,
|
|
123
129
|
numbers,
|
|
130
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
124
131
|
path: `${blockFieldPath}.${row._order - 1}`,
|
|
125
132
|
relationships,
|
|
126
133
|
table: row,
|
|
@@ -154,7 +161,10 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
154
161
|
row.id = row._uuid;
|
|
155
162
|
delete row._uuid;
|
|
156
163
|
}
|
|
157
|
-
|
|
164
|
+
if (typeof row.blockType !== 'string') {
|
|
165
|
+
return acc;
|
|
166
|
+
}
|
|
167
|
+
const block = adapter.payload.blocks[row.blockType] ?? (field.blockReferences ?? field.blocks).find((block)=>typeof block !== 'string' && block.slug === row.blockType);
|
|
158
168
|
if (block) {
|
|
159
169
|
if (!withinArrayOrBlockLocale || withinArrayOrBlockLocale && withinArrayOrBlockLocale === row._locale) {
|
|
160
170
|
if (row._locale) {
|
|
@@ -173,6 +183,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
173
183
|
fieldPrefix: '',
|
|
174
184
|
fields: block.flattenedFields,
|
|
175
185
|
numbers,
|
|
186
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
176
187
|
path: `${blockFieldPath}.${i}`,
|
|
177
188
|
relationships,
|
|
178
189
|
table: row,
|
|
@@ -192,7 +203,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
192
203
|
}
|
|
193
204
|
if (field.type === 'relationship' || field.type === 'upload') {
|
|
194
205
|
if (typeof field.relationTo === 'string' && !('hasMany' in field && field.hasMany)) {
|
|
195
|
-
if (
|
|
206
|
+
if (isLocalized && config.localization && config.localization.locales && Array.isArray(table?._locales)) {
|
|
196
207
|
table._locales.forEach((localeRow)=>{
|
|
197
208
|
result[field.name] = {
|
|
198
209
|
[localeRow._locale]: localeRow[fieldName]
|
|
@@ -208,7 +219,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
208
219
|
const relationPathMatch = relationships[`${sanitizedPath}${field.name}`];
|
|
209
220
|
if (!relationPathMatch) {
|
|
210
221
|
if ('hasMany' in field && field.hasMany) {
|
|
211
|
-
if (
|
|
222
|
+
if (isLocalized && config.localization && config.localization.locales) {
|
|
212
223
|
result[field.name] = {
|
|
213
224
|
[config.localization.defaultLocale]: []
|
|
214
225
|
};
|
|
@@ -218,7 +229,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
218
229
|
}
|
|
219
230
|
return result;
|
|
220
231
|
}
|
|
221
|
-
if (
|
|
232
|
+
if (isLocalized) {
|
|
222
233
|
result[field.name] = {};
|
|
223
234
|
const relationsByLocale = {};
|
|
224
235
|
relationPathMatch.forEach((row)=>{
|
|
@@ -256,7 +267,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
256
267
|
}
|
|
257
268
|
let fieldResult;
|
|
258
269
|
if (Array.isArray(fieldData)) {
|
|
259
|
-
if (
|
|
270
|
+
if (isLocalized && adapter.payload.config.localization) {
|
|
260
271
|
fieldResult = fieldData.reduce((joinResult, row)=>{
|
|
261
272
|
if (typeof row.locale === 'string') {
|
|
262
273
|
joinResult[row.locale].docs.push(row.id);
|
|
@@ -292,7 +303,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
292
303
|
if (!textPathMatch) {
|
|
293
304
|
return result;
|
|
294
305
|
}
|
|
295
|
-
if (
|
|
306
|
+
if (isLocalized) {
|
|
296
307
|
result[field.name] = {};
|
|
297
308
|
const textsByLocale = {};
|
|
298
309
|
textPathMatch.forEach((row)=>{
|
|
@@ -326,7 +337,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
326
337
|
if (!numberPathMatch) {
|
|
327
338
|
return result;
|
|
328
339
|
}
|
|
329
|
-
if (
|
|
340
|
+
if (isLocalized) {
|
|
330
341
|
result[field.name] = {};
|
|
331
342
|
const numbersByLocale = {};
|
|
332
343
|
numberPathMatch.forEach((row)=>{
|
|
@@ -357,7 +368,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
357
368
|
}
|
|
358
369
|
if (field.type === 'select' && field.hasMany) {
|
|
359
370
|
if (Array.isArray(fieldData)) {
|
|
360
|
-
if (
|
|
371
|
+
if (isLocalized) {
|
|
361
372
|
result[field.name] = fieldData.reduce((selectResult, row)=>{
|
|
362
373
|
if (typeof row.locale === 'string') {
|
|
363
374
|
if (!selectResult[row.locale]) {
|
|
@@ -377,7 +388,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
377
388
|
}
|
|
378
389
|
return result;
|
|
379
390
|
}
|
|
380
|
-
if (
|
|
391
|
+
if (isLocalized && Array.isArray(table._locales)) {
|
|
381
392
|
if (!table._locales.length && adapter.payload.config.localization) {
|
|
382
393
|
adapter.payload.config.localization.localeCodes.forEach((_locale)=>table._locales.push({
|
|
383
394
|
_locale
|
|
@@ -416,8 +427,8 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
416
427
|
const groupFieldPrefix = `${fieldPrefix || ''}${field.name}_`;
|
|
417
428
|
const groupData = {};
|
|
418
429
|
const locale = table._locale;
|
|
419
|
-
const refKey =
|
|
420
|
-
if (
|
|
430
|
+
const refKey = isLocalized && locale ? locale : field.name;
|
|
431
|
+
if (isLocalized && locale) {
|
|
421
432
|
delete table._locale;
|
|
422
433
|
}
|
|
423
434
|
ref[refKey] = traverseFields({
|
|
@@ -429,6 +440,7 @@ export const traverseFields = ({ adapter, blocks, config, dataRef, deletions, fi
|
|
|
429
440
|
fieldPrefix: groupFieldPrefix,
|
|
430
441
|
fields: field.flattenedFields,
|
|
431
442
|
numbers,
|
|
443
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
432
444
|
path: `${sanitizedPath}${field.name}`,
|
|
433
445
|
relationships,
|
|
434
446
|
table,
|